package jetbrains.mps.ide.actions; /*Generated by MPS */ import jetbrains.mps.workbench.action.BaseAction; import javax.swing.Icon; import com.intellij.openapi.actionSystem.AnActionEvent; import java.util.Map; import java.awt.Frame; import jetbrains.mps.internal.collections.runtime.MapSequence; import jetbrains.mps.nodeEditor.EditorComponent; import jetbrains.mps.ide.editor.MPSEditorDataKeys; import jetbrains.mps.openapi.editor.cells.EditorCell; import org.jetbrains.mps.openapi.model.SNode; import org.jetbrains.annotations.NotNull; import java.awt.Point; import javax.swing.SwingUtilities; import jetbrains.mps.smodel.ModelAccessHelper; import jetbrains.mps.util.Computable; import jetbrains.mps.nodeEditor.NodeInformationDialog; import com.intellij.openapi.application.ApplicationManager; public class ShowNodeInfo_Action extends BaseAction { private static final Icon ICON = null; public ShowNodeInfo_Action() { super("Show Node Info", "", ICON); this.setIsAlwaysVisible(false); this.setExecuteOutsideCommand(true); } @Override public boolean isDumbAware() { return true; } @Override protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { Frame p = event.getData(MPSCommonDataKeys.FRAME); MapSequence.fromMap(_params).put("frame", p); if (p == null) { return false; } } { EditorComponent editorComponent = event.getData(MPSEditorDataKeys.EDITOR_COMPONENT); if (editorComponent != null && editorComponent.isInvalid()) { editorComponent = null; } MapSequence.fromMap(_params).put("editor", editorComponent); if (editorComponent == null) { return false; } } { EditorCell p = event.getData(MPSEditorDataKeys.EDITOR_CELL); MapSequence.fromMap(_params).put("cell", p); if (p == null) { return false; } } { SNode p = event.getData(MPSCommonDataKeys.NODE); MapSequence.fromMap(_params).put("node", p); if (p == null) { return false; } } return true; } @Override public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { final Point point = new Point(((EditorCell) MapSequence.fromMap(_params).get("cell")).getX() + ((EditorCell) MapSequence.fromMap(_params).get("cell")).getWidth(), ((EditorCell) MapSequence.fromMap(_params).get("cell")).getY()); SwingUtilities.convertPointToScreen(point, ((EditorComponent) MapSequence.fromMap(_params).get("editor"))); // Displaying this action in .invokeLater call to let popup menu be disposed first ( <node> will be diposed immediately by corresponding events otherwise) final Frame frame = ((Frame) MapSequence.fromMap(_params).get("frame")); final SNode node = ((SNode) MapSequence.fromMap(_params).get("node")); final String text = new ModelAccessHelper(((EditorComponent) MapSequence.fromMap(_params).get("editor")).getEditorContext().getRepository()).runReadAction(new Computable<String>() { public String compute() { return NodeInformationDialog.createNodeInfo(node); } }); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { new NodeInformationDialog(((EditorComponent) MapSequence.fromMap(_params).get("editor")), frame, point, text).setVisible(true); } }); } }