package jetbrains.mps.ide.actions; /*Generated by MPS */ import jetbrains.mps.workbench.action.BaseAction; import javax.swing.Icon; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnActionEvent; import java.util.Map; import jetbrains.mps.internal.collections.runtime.MapSequence; import org.jetbrains.annotations.NotNull; import org.jetbrains.mps.openapi.model.SModel; import jetbrains.mps.workbench.ActionPlace; import jetbrains.mps.project.MPSProject; import com.intellij.openapi.project.Project; import com.intellij.openapi.actionSystem.CommonDataKeys; import jetbrains.mps.ide.save.SaveRepositoryCommand; import jetbrains.mps.ide.ui.dialogs.properties.MPSPropertiesConfigurable; import jetbrains.mps.ide.ui.dialogs.properties.ModelPropertiesConfigurable; import com.intellij.openapi.options.ex.SingleConfigurableEditor; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; public class ModelProperties_Action extends BaseAction { private static final Icon ICON = AllIcons.General.Settings; public ModelProperties_Action() { super("Model Properties", "", ICON); this.setIsAlwaysVisible(false); this.setExecuteOutsideCommand(true); } @Override public boolean isDumbAware() { return true; } @Override public boolean isApplicable(AnActionEvent event, final Map<String, Object> _params) { return ((Integer) MapSequence.fromMap(_params).get("size")) == 1; } @Override public void doUpdate(@NotNull AnActionEvent event, final Map<String, Object> _params) { this.setEnabledState(event.getPresentation(), this.isApplicable(event, _params)); } @Override protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { SModel p = event.getData(MPSCommonDataKeys.CONTEXT_MODEL); MapSequence.fromMap(_params).put("model", p); if (p == null) { return false; } } { Integer p = event.getData(MPSCommonDataKeys.TREE_SELECTION_SIZE); MapSequence.fromMap(_params).put("size", p); if (p == null) { return false; } } { ActionPlace p = event.getData(MPSCommonDataKeys.PLACE); MapSequence.fromMap(_params).put("place", p); if (p == null) { return false; } } { MPSProject p = event.getData(MPSCommonDataKeys.MPS_PROJECT); MapSequence.fromMap(_params).put("project", p); if (p == null) { return false; } } { Project p = event.getData(CommonDataKeys.PROJECT); MapSequence.fromMap(_params).put("ideaProject", p); if (p == null) { return false; } } return true; } @Override public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { // see ModuleProperties_Action for reason to save all models prior to property change new SaveRepositoryCommand(((MPSProject) MapSequence.fromMap(_params).get("project")).getRepository()).execute(); MPSPropertiesConfigurable configurable = new ModelPropertiesConfigurable(((SModel) MapSequence.fromMap(_params).get("model")), ((MPSProject) MapSequence.fromMap(_params).get("project"))); final SingleConfigurableEditor configurableEditor = new SingleConfigurableEditor(((Project) MapSequence.fromMap(_params).get("ideaProject")), configurable, "#MPSPropertiesConfigurable"); configurable.setParentForCallBack(configurableEditor); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { configurableEditor.show(); } }, ModalityState.current()); } }