package jetbrains.mps.ide.devkit.actions; /*Generated by MPS */ import jetbrains.mps.workbench.action.BaseAction; import javax.swing.Icon; import org.jetbrains.annotations.NotNull; import com.intellij.openapi.actionSystem.AnActionEvent; import java.util.Map; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.ide.actions.MPSCommonDataKeys; import jetbrains.mps.extapi.model.TransientSModel; import org.jetbrains.mps.openapi.model.SNodeReference; import jetbrains.mps.textgen.trace.TracingUtil; import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.project.MPSProject; import jetbrains.mps.openapi.navigation.EditorNavigator; public class ShowOriginNode_Action extends BaseAction { private static final Icon ICON = null; public ShowOriginNode_Action() { super("Reveal Origin Node", "Navigate to node in original model selected transient node originates from", ICON); this.setIsAlwaysVisible(false); this.setExecuteOutsideCommand(true); } @Override public boolean isDumbAware() { return true; } @Override public void doUpdate(@NotNull AnActionEvent event, final Map<String, Object> _params) { if (SNodeOperations.getModel(event.getData(MPSCommonDataKeys.NODE)) instanceof TransientSModel) { SNodeReference originRef = TracingUtil.getInput(event.getData(MPSCommonDataKeys.NODE)); SNode origin = (originRef == null ? null : originRef.resolve(event.getData(MPSCommonDataKeys.MPS_PROJECT).getRepository())); // I'd like to have the action visible (although not necessarily enabled) for any transient node, hence can't use enable()/disable() event.getPresentation().setVisible(true); event.getPresentation().setEnabled(origin != null); } else { disable(event.getPresentation()); } } @Override protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { MPSProject p = event.getData(MPSCommonDataKeys.MPS_PROJECT); if (p == null) { return false; } } { SNode node = event.getData(MPSCommonDataKeys.NODE); if (node == null) { return false; } } return true; } @Override public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { new EditorNavigator(event.getData(MPSCommonDataKeys.MPS_PROJECT)).shallFocus(true).shallSelect(true).open(TracingUtil.getInput(event.getData(MPSCommonDataKeys.NODE))); } }