package jetbrains.mps.ide.devkit.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 jetbrains.mps.nodeEditor.EditorComponent;
import jetbrains.mps.ide.editor.MPSEditorDataKeys;
import jetbrains.mps.internal.collections.runtime.MapSequence;
import jetbrains.mps.openapi.editor.cells.EditorCell;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.nodeEditor.NodeHighlightManager;
import jetbrains.mps.openapi.editor.message.EditorMessageOwner;
import jetbrains.mps.ide.actions.HighlightConstants;
import java.util.Set;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.internal.collections.runtime.SetSequence;
import org.jetbrains.mps.openapi.model.SNodeReference;
public class HighlightCellDependencies_Action extends BaseAction {
private static final Icon ICON = null;
public HighlightCellDependencies_Action() {
super("Highlighted Cell's Dependent Nodes", "", ICON);
this.setIsAlwaysVisible(false);
this.setExecuteOutsideCommand(false);
}
@Override
public boolean isDumbAware() {
return true;
}
@Override
protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) {
if (!(super.collectActionData(event, _params))) {
return false;
}
{
EditorComponent editorComponent = event.getData(MPSEditorDataKeys.EDITOR_COMPONENT);
if (editorComponent != null && editorComponent.isInvalid()) {
editorComponent = null;
}
MapSequence.fromMap(_params).put("editorComponent", editorComponent);
if (editorComponent == null) {
return false;
}
}
{
EditorCell p = event.getData(MPSEditorDataKeys.EDITOR_CELL);
MapSequence.fromMap(_params).put("editorCell", p);
if (p == null) {
return false;
}
}
return true;
}
@Override
public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) {
NodeHighlightManager highlightManager = ((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")).getHighlightManager();
EditorMessageOwner messageOwner = ((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")).getHighlightMessagesOwner();
highlightManager.mark(((EditorCell) MapSequence.fromMap(_params).get("editorCell")).getSNode(), HighlightConstants.NODE_COLOR, "node", messageOwner);
Set<SNode> nodes = ((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")).getNodesCellDependOn(((EditorCell) MapSequence.fromMap(_params).get("editorCell")));
if (nodes != null) {
for (SNode node : SetSequence.fromSet(nodes)) {
highlightManager.mark(node, HighlightConstants.DEPENDENCY_COLOR, "usage", messageOwner);
}
}
Set<SNodeReference> copyOfRefTargets = ((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")).getCopyOfRefTargetsCellDependsOn(((EditorCell) MapSequence.fromMap(_params).get("editorCell")));
if (copyOfRefTargets != null) {
for (SNodeReference nodePointer : SetSequence.fromSet(copyOfRefTargets)) {
SNode tgt = nodePointer.resolve(((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")).getEditorContext().getRepository());
if (tgt != null) {
highlightManager.mark(tgt, HighlightConstants.DEPENDENCY_COLOR, "usage", messageOwner);
}
}
}
highlightManager.repaintAndRebuildEditorMessages();
}
}