예제 #1
0
 public void relayout(boolean updateFolding) {
   assert SwingUtilities.isEventDispatchThread()
       : "LeftEditorHighlighter.relayout() should be executed in eventDispatchThread";
   SNode editedNode = myEditorComponent.getEditedNode();
   // additional check - during editor dispose process some Folding area painters can be removed
   // calling relayout()..
   if (myEditorComponent.isDisposed()
       || (editedNode != null && jetbrains.mps.util.SNodeOperations.isDisposed(editedNode))) {
     return;
   }
   if (myRightToLeft) {
     recalculateFoldingAreaWidth();
     updateSeparatorLinePosition();
     if (updateFolding) {
       for (AbstractFoldingAreaPainter painter : myFoldingAreaPainters) {
         painter.relayout();
       }
       // wee need to recalculateIconRenderersWidth only if one of collections was folded/unfolded
       recalculateIconRenderersWidth();
     }
     recalculateTextColumnWidth();
   } else {
     recalculateTextColumnWidth();
     if (updateFolding) {
       for (AbstractFoldingAreaPainter painter : myFoldingAreaPainters) {
         painter.relayout();
       }
       // wee need to recalculateIconRenderersWidth only if one of collections was folded/unfolded
       recalculateIconRenderersWidth();
     }
     recalculateFoldingAreaWidth();
     updateSeparatorLinePosition();
   }
   updatePreferredSize();
 }
예제 #2
0
 @Override
 public void execute(EditorContext context) {
   EditorComponent editorComponent = (EditorComponent) context.getEditorComponent();
   editorComponent.clearSelectionStack();
   editorComponent.changeSelection(
       CellFinderUtil.findLastSelectableLeaf(EditorCell_Collection.this));
 }
예제 #3
0
 public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) {
   try {
     EditorComponent component =
         ((EditorComponent)
             ((Editor) MapSequence.fromMap(_params).get("editor")).getCurrentEditorComponent());
     if (component == null) {
       return;
     }
     Set<String> enabledHints = component.getEnabledHints();
     ConceptEditorHintSettings settings = new ConceptEditorHintSettings();
     settings.putAll(
         ConceptEditorHintSettingsComponent.getInstance(
                 ((Project) MapSequence.fromMap(_params).get("project")))
             .getSettings());
     for (String lang : settings.getLanguagesNames()) {
       for (ConceptEditorHint hint : SetSequence.fromSet(settings.getHints(lang))) {
         settings.put(lang, hint, false);
       }
     }
     settings.updateSettings(enabledHints);
     final ConceptEditorHintPreferencesPage page = new ConceptEditorHintPreferencesPage(settings);
     DialogWrapper dialog =
         new HintsDialog(
             ((Project) MapSequence.fromMap(_params).get("project")), page, settings, component);
     dialog.show();
   } catch (Throwable t) {
     if (LOG.isEnabledFor(Priority.ERROR)) {
       LOG.error("User's action execute method failed. Action:" + "PushEditorHints", t);
     }
   }
 }
예제 #4
0
 /*package*/ static void runEditorComponentAction(
     EditorComponent editorComponent, CellActionType actionType) {
   EditorCellAction action = editorComponent.getComponentAction(CellActionType.UP);
   EditorContext editorContext = editorComponent.getEditorContext();
   if (action != null && action.canExecute(editorContext)) {
     action.execute(editorContext);
   }
 }
예제 #5
0
 @Nullable
 public Object getData(@NonNls String dataId) {
   if (dataId.equals(MPSEditorDataKeys.MPS_EDITOR.getName())) return BaseNodeEditor.this;
   Object data = BaseNodeEditor.this.getData(dataId);
   if (data != null) return data;
   EditorComponent ec = getCurrentEditorComponent();
   return ec == null ? null : ec.getData(dataId);
 }
  @Override
  public void clear(SNode node, EditorComponent editorComponent) {
    if (editorComponent.getNodeForTypechecking() == null) return;

    TypeContextManager.getInstance()
        .acquireTypecheckingContext(editorComponent.getNodeForTypechecking(), editorComponent);
    TypeContextManager.getInstance().releaseTypecheckingContext(editorComponent);
  }
예제 #7
0
 public static DiffButtonsPainter addTo(
     RootDifferenceDialog dialog,
     DiffEditor diffEditor,
     ChangeGroupLayout changeGroupLayout,
     boolean inspector) {
   EditorComponent editorComponent = diffEditor.getEditorComponent(inspector);
   DiffButtonsPainter painter = new DiffButtonsPainter(dialog, editorComponent, changeGroupLayout);
   editorComponent.getLeftEditorHighlighter().addFoldingAreaPainter(painter);
   return painter;
 }
예제 #8
0
 private void clearAllEditors() {
   List<EditorComponent> allEditorComponents =
       EditorComponentUtil.getAllEditorComponents(myFileEditorManager, true);
   for (EditorComponent component : allEditorComponents) {
     component.getLeftEditorHighlighter().removeAllIconRenderers(BreakpointIconRenderrer.TYPE);
     List<AdditionalPainter> additionalPainters = component.getAdditionalPainters();
     for (AdditionalPainter painter : additionalPainters) {
       if (painter instanceof BreakpointPainter) {
         component.removeAdditionalPainter(painter);
       }
     }
   }
 }
 @Override
 public void testMethodImpl() throws Exception {
   final Editor editor = TestBody.this.initEditor("6500338114639041775", "6500338114639041779");
   EditorComponent editorComponent = (EditorComponent) editor.getCurrentEditorComponent();
   BaseEditorTestBody.typeString(editorComponent, " ");
   BaseEditorTestBody.pressKeys(
       editorComponent, ListSequence.fromListAndArray(new ArrayList<String>(), "ctrl SPACE"));
   Assert.assertTrue(editorComponent.getNodeSubstituteChooser().isVisible());
   Assert.assertTrue(editorComponent.getNodeSubstituteChooser().isMenuEmpty());
   editorComponent.getNodeSubstituteChooser().setVisible(false);
   BaseEditorTestBody.pressKeys(
       editorComponent, ListSequence.fromListAndArray(new ArrayList<String>(), " ESCAPE"));
 }
예제 #10
0
 private void adjustSelectionToFoldingState(EditorComponent editorComponent) {
   if (isDescendantCellSelected(editorComponent)) {
     editorComponent.clearSelectionStack();
     jetbrains.mps.nodeEditor.cells.EditorCell editorCellToSelect =
         getFirstLeaf(CellConditions.SELECTABLE);
     if (editorCellToSelect != null) {
       editorComponent.changeSelection(editorCellToSelect);
       editorCellToSelect.home();
     } else {
       editorComponent.changeSelection(this);
       home();
     }
   }
 }
예제 #11
0
 @Override
 public void doDispose() {
   for (LanguageErrorsComponent comp : MapSequence.fromMap(myNodePointersToComponents).values()) {
     comp.dispose();
   }
   for (EditorComponent component : myEditorComponents) {
     component.removeDisposeListener(myDisposeListener);
   }
   SModelRepository.getInstance().removeModelRepositoryListener(myRepositoryListener);
   for (SModel modelDescriptor :
       SetSequence.fromSetWithValues(new HashSet<SModel>(), myListenedModels)) {
     removeModelListener(modelDescriptor);
   }
   super.doDispose();
 }
예제 #12
0
  @Override
  public EditorCell findCell(final EditorComponent editorComponent) {
    if (myCellId != null) {
      final EditorContext editorContext = editorComponent.getEditorContext();
      if (myNodeReference == null) return null;

      final EditorCell[] cell = new EditorCell[] {null};
      editorContext
          .getRepository()
          .getModelAccess()
          .runReadAction(
              new Runnable() {
                @Override
                public void run() {
                  cell[0] =
                      editorComponent.findCellWithId(
                          myNodeReference.resolve(editorContext.getRepository()), myCellId);
                }
              });
      return cell[0];
    } else if (myParentInfo != null) {
      EditorCell parentCell = myParentInfo.findCell(editorComponent);
      if (!(parentCell instanceof EditorCell_Collection)) {
        return null;
      }
      EditorCell_Collection parentCollection = (EditorCell_Collection) parentCell;
      if (myCellNumber >= parentCollection.getCellsCount()) {
        return null;
      }
      EditorCell editorCell = parentCollection.getChildAt(myCellNumber);
      // This editorCell should not have any cellId due to corresponding conditions in constructor
      return editorCell.getCellId() == null ? editorCell : null;
    }
    return null;
  }
예제 #13
0
  protected void showComponent(JComponent replace) {
    if (myEditorComponent != null) {
      myComponent.remove(myEditorComponent.getExternalComponent());
      myEditorComponent.dispose();
      myEditorComponent = null;
    }

    if (myReplace != null) {
      myComponent.remove(myReplace);
      myReplace = null;
    }

    myReplace = replace;
    myComponent.add(myReplace, BorderLayout.CENTER);
    myComponent.validate();
  }
예제 #14
0
  public LeftEditorHighlighter(@NotNull EditorComponent editorComponent, boolean rightToLeft) {
    setBackground(EditorSettings.getInstance().getLeftHighlighterBackgroundColor());
    myEditorComponent = editorComponent;
    myRightToLeft = rightToLeft;
    addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseExited(MouseEvent e) {
            mouseExitedFoldingArea(e);
            mouseExitedIconsArea(e);
          }

          @Override
          public void mouseEntered(MouseEvent e) {
            if (isInFoldingArea(e)) {
              mouseMovedInFoldingArea(e);
            } else if (isInTextArea(e)) {
              mouseMovedInTextArea(e);
            } else {
              mouseMovedInIconsArea(e);
            }
          }
        });
    addMouseMotionListener(
        new MouseMotionAdapter() {
          @Override
          public void mouseMoved(MouseEvent e) {
            if (isInFoldingArea(e)) {
              mouseExitedIconsArea(e);
              mouseMovedInFoldingArea(e);
            } else if (isInTextArea(e)) {
              mouseExitedFoldingArea(e);
              mouseExitedIconsArea(e);
              mouseMovedInTextArea(e);
            } else {
              mouseExitedFoldingArea(e);
              mouseMovedInIconsArea(e);
            }
          }
        });
    if (MPSToolTipManager.getInstance() != null) {
      MPSToolTipManager.getInstance().registerComponent(this);
    }
    editorComponent.addRebuildListener(
        new RebuildListener() {
          @Override
          public void editorRebuilt(EditorComponent editor) {
            assert SwingUtilities.isEventDispatchThread()
                : "LeftEditorHighlighter$RebuildListener should be called in eventDispatchThread";
            for (AbstractFoldingAreaPainter painter : myFoldingAreaPainters) {
              painter.editorRebuilt();
            }
          }
        });
    myBracketsPainter = new BracketsPainter(this, myRightToLeft);
    myFoldingButtonsPainter = new FoldingButtonsPainter(this);

    myFoldingAreaPainters.add(myBracketsPainter);
    myFoldingAreaPainters.add(myFoldingButtonsPainter);
  }
예제 #15
0
  private void paintBackgroundAndFoldingLine(Graphics g, Rectangle clipBounds) {
    Graphics2D g2d = (Graphics2D) g;
    g.setColor(getBackground());
    g.fillRect(
        clipBounds.x,
        clipBounds.y,
        Math.min(clipBounds.width, myFoldingLineX - clipBounds.x),
        clipBounds.height);
    g.setColor(getEditorComponent().getBackground());
    g.fillRect(
        Math.max(clipBounds.x, myFoldingLineX),
        clipBounds.y,
        clipBounds.width - Math.max(0, myFoldingLineX - clipBounds.x),
        clipBounds.height);

    // same as in EditorComponent.paint() method
    EditorCell deepestCell = myEditorComponent.getDeepestSelectedCell();
    if (deepestCell instanceof EditorCell_Label) {
      int selectedCellY = deepestCell.getY();
      int selectedCellHeight =
          deepestCell.getHeight() - deepestCell.getTopInset() - deepestCell.getBottomInset();
      if (g.hitClip(clipBounds.x, selectedCellY, clipBounds.width, selectedCellHeight)) {
        g.setColor(EditorSettings.getInstance().getCaretRowColor());
        g.fillRect(clipBounds.x, selectedCellY, clipBounds.width, selectedCellHeight);
        // Drawing folding line
        UIUtil.drawVDottedLine(
            g2d,
            myFoldingLineX,
            clipBounds.y,
            selectedCellY,
            getBackground(),
            EditorSettings.getInstance().getLeftHighlighterTearLineColor());
        UIUtil.drawVDottedLine(
            g2d,
            myFoldingLineX,
            selectedCellY,
            selectedCellY + selectedCellHeight,
            EditorSettings.getInstance().getCaretRowColor(),
            EditorSettings.getInstance().getLeftHighlighterTearLineColor());
        UIUtil.drawVDottedLine(
            g2d,
            myFoldingLineX,
            selectedCellY + selectedCellHeight,
            clipBounds.y + clipBounds.height,
            getBackground(),
            EditorSettings.getInstance().getLeftHighlighterTearLineColor());
        return;
      }
    }
    // Drawing folding line
    // COLORS: Remove hardcoded color
    UIUtil.drawVDottedLine(
        g2d,
        myFoldingLineX,
        clipBounds.y,
        clipBounds.y + clipBounds.height,
        getBackground(),
        Color.gray);
  }
예제 #16
0
 @Override
 public void editorWillBeDisposed(EditorComponent editorComponent) {
   SetSequence.fromSet(myEditorComponents).removeElement(editorComponent);
   SNodeReference sNodePointer = editorComponent.getEditedNodePointer();
   if (sNodePointer != null) {
     MapSequence.fromMap(myNodePointersToComponents).removeKey(sNodePointer);
   }
 }
예제 #17
0
 protected void showEditor() {
   if (myReplace != null) {
     myComponent.remove(myReplace);
     myReplace = null;
   }
   myEditorComponent = new NodeEditorComponent(myContext);
   myComponent.add(myEditorComponent.getExternalComponent(), BorderLayout.CENTER);
   myComponent.validate();
 }
예제 #18
0
 private void addUnfoldingListener() {
   if (myUnfoldCollectionMouseListener != null) {
     return;
   }
   final EditorComponent editorComponent = getEditor();
   editorComponent.addMouseListener(
       myUnfoldCollectionMouseListener =
           new MouseAdapter() {
             @Override
             public void mouseClicked(MouseEvent e) {
               if (GeometryUtil.contains(EditorCell_Collection.this, e.getX(), e.getY())) {
                 editorComponent.clearSelectionStack();
                 editorComponent.changeSelection(getFoldedCell());
                 unfold();
               }
             }
           });
 }
예제 #19
0
 private void updatePreferredSize() {
   int newWidth = myTextColumnWidth + myIconRenderersWidth + getFoldingAreaWidth();
   int newHeight = myEditorComponent.getPreferredSize().height;
   if (myWidth != newWidth || myHeight != newHeight) {
     myWidth = newWidth;
     myHeight = newHeight;
     firePreferredSizeChanged();
   }
 }
예제 #20
0
 private jetbrains.mps.openapi.editor.cells.EditorCell getAnchorCell(
     EditorMessageIconRenderer renderer) {
   SNode rendererNode = renderer.getNode();
   EditorCell nodeCell = myEditorComponent.findNodeCell(rendererNode);
   if (nodeCell == null) {
     // no cell for node?..
     return null;
   }
   return renderer.getAnchorCell(nodeCell);
 }
예제 #21
0
 @Nullable
 private static AnnotationColumn findAnnotationColumn(@NotNull EditorComponent editorComponent) {
   for (AbstractLeftColumn column :
       ListSequence.fromList(editorComponent.getLeftEditorHighlighter().getLeftColumns())) {
     if (column instanceof AnnotationColumn) {
       return ((AnnotationColumn) column);
     }
   }
   return null;
 }
예제 #22
0
 private void clearForModel(SModelReference modelReference) {
   Set<SNodeReference> sNodePointers2Remove = SetSequence.fromSet(new HashSet<SNodeReference>());
   for (SNodeReference sNodePointer :
       SetSequence.fromSetWithValues(
           new HashSet<SNodeReference>(),
           MapSequence.fromMap(myNodePointersToComponents).keySet())) {
     if (sNodePointer.getModelReference().equals(modelReference)) {
       MapSequence.fromMap(myNodePointersToComponents).get(sNodePointer).dispose();
       MapSequence.fromMap(myNodePointersToComponents).removeKey(sNodePointer);
       SetSequence.fromSet(sNodePointers2Remove).addElement(sNodePointer);
     }
   }
   for (EditorComponent component :
       SetSequence.fromSetWithValues(new HashSet<EditorComponent>(), myEditorComponents)) {
     if (SetSequence.fromSet(sNodePointers2Remove).contains(component.getEditedNodePointer())) {
       component.removeDisposeListener(myDisposeListener);
       SetSequence.fromSet(myEditorComponents).removeElement(component);
     }
   }
 }
예제 #23
0
 public TypeSystemStateTree(Project mpsProject, State state, EditorComponent editorComponent) {
   myProject = mpsProject;
   myState = state;
   myEditorComponent = editorComponent;
   this.myHighlightManager = editorComponent.getHighlightManager();
   this.myMessageOwner = new EditorMessageOwner() {};
   this.getSelectionModel()
       .addTreeSelectionListener(new TypeSystemStateTree.EditorMessageUpdater());
   this.rebuildNow();
   expandAll();
 }
예제 #24
0
 @Nullable
 public EditorState saveState(boolean full) {
   BaseEditorState result = new BaseEditorState();
   EditorContext editorContext = getEditorContext();
   if (editorContext != null) {
     result.myMemento = editorContext.createMemento(full);
     EditorComponent editorComponent = getCurrentEditorComponent();
     if (editorComponent instanceof NodeEditorComponent) {
       NodeEditorComponent nodeEditorComponent = (NodeEditorComponent) editorComponent;
       EditorComponent inspector = nodeEditorComponent.getInspector();
       if (inspector != null) {
         EditorContext inspectorContext = inspector.getEditorContext();
         if (inspectorContext != null) {
           result.myInspectorMemento = inspectorContext.createMemento(full);
         }
       }
     }
   }
   return result;
 }
예제 #25
0
  public List<INodeSubstituteAction> createActions() {
    if (myLinkDeclaration == null) {
      return Collections.emptyList();
    }
    EditorComponent editor = mySubstituteInfo.getEditorContext().getNodeEditorComponent();
    EditorCell referenceCell =
        editor.findNodeCellWithRole(
            mySourceNode,
            ((String)
                BehaviorManager.getInstance()
                    .invoke(
                        Object.class,
                        SNodeOperations.cast(
                            myLinkDeclaration,
                            "jetbrains.mps.lang.structure.structure.LinkDeclaration"),
                        "call_getGenuineRole_1213877254542",
                        new Class[] {SNode.class})));

    if (referenceCell != null
        && referenceCell.getContainingBigCell().getFirstLeaf() == referenceCell
        && ReferenceConceptUtil.getCharacteristicReference(
                SNodeOperations.getConceptDeclaration(mySourceNode))
            == myLinkDeclaration
        && SNodeOperations.getParent(mySourceNode) != null
        && ListSequence.fromList(SNodeOperations.getChildren(mySourceNode)).isEmpty()) {
      SNode parent = SNodeOperations.getParent(mySourceNode);
      String role = SNodeOperations.getContainingLinkRole(mySourceNode);
      SNode roleLink =
          SNodeOperations.cast(
              parent.getLinkDeclaration(role),
              "jetbrains.mps.lang.structure.structure.LinkDeclaration");
      return ModelActions.createChildSubstituteActions(
          parent,
          mySourceNode,
          SLinkOperations.getTarget(roleLink, "target", false),
          new DefaultChildNodeSetter(roleLink),
          mySubstituteInfo.getOperationContext());
    }
    return ModelActions.createReferentSubstituteActions(
        mySourceNode, myCurrentReferent, myLinkDeclaration, mySubstituteInfo.getOperationContext());
  }
예제 #26
0
 protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) {
   if (!(super.collectActionData(event, _params))) {
     return false;
   }
   {
     SNode node = event.getData(MPSCommonDataKeys.NODE);
     if (node != null) {}
     MapSequence.fromMap(_params).put("node", node);
   }
   if (MapSequence.fromMap(_params).get("node") == null) {
     return false;
   }
   MapSequence.fromMap(_params).put("frame", event.getData(MPSCommonDataKeys.FRAME));
   if (MapSequence.fromMap(_params).get("frame") == null) {
     return false;
   }
   MapSequence.fromMap(_params).put("ideaProject", event.getData(CommonDataKeys.PROJECT));
   if (MapSequence.fromMap(_params).get("ideaProject") == null) {
     return false;
   }
   MapSequence.fromMap(_params)
       .put("operationContext", event.getData(MPSCommonDataKeys.OPERATION_CONTEXT));
   if (MapSequence.fromMap(_params).get("operationContext") == null) {
     return false;
   }
   {
     EditorComponent editorComponent = event.getData(MPSEditorDataKeys.EDITOR_COMPONENT);
     if (editorComponent != null && editorComponent.isInvalid()) {
       editorComponent = null;
     }
     MapSequence.fromMap(_params).put("editorComponent", editorComponent);
   }
   if (MapSequence.fromMap(_params).get("editorComponent") == null) {
     return false;
   }
   MapSequence.fromMap(_params).put("project", event.getData(MPSCommonDataKeys.MPS_PROJECT));
   if (MapSequence.fromMap(_params).get("project") == null) {
     return false;
   }
   return true;
 }
예제 #27
0
 @Override
 public void clear(SNode node, EditorComponent component) {
   SNodeReference sNodePointer = component.getEditedNodePointer();
   if (sNodePointer == null) {
     return;
   }
   LanguageErrorsComponent errorsComponent =
       MapSequence.fromMap(myNodePointersToComponents).get(sNodePointer);
   if (errorsComponent == null) {
     return;
   }
   errorsComponent.clear();
 }
예제 #28
0
 @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("cell", p);
     if (p == null) {
       return false;
     }
   }
   {
     IOperationContext p = event.getData(MPSCommonDataKeys.OPERATION_CONTEXT);
     MapSequence.fromMap(_params).put("context", 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;
 }
예제 #29
0
 /*package*/ static EditorCell getEditorCellToInsert(EditorComponent editorComponent) {
   Selection selection = editorComponent.getSelectionManager().getSelection();
   // TODO: remove this limitation
   if (!(selection instanceof SingularSelection)) {
     return null;
   }
   Iterator<jetbrains.mps.nodeEditor.cells.EditorCell> iterator =
       selection.getSelectedCells().iterator();
   if (!(iterator.hasNext())) {
     return null;
   }
   EditorCell editorCell = iterator.next();
   return (editorCell instanceof EditorCell_Component ? null : editorCell);
 }
예제 #30
0
 private boolean isDescendantCellSelected(EditorComponent editorComponent) {
   EditorCell selectedCell = editorComponent.getDeepestSelectedCell();
   return selectedCell != null
       && CellFinderUtil.findParent(
               selectedCell,
               new Condition<jetbrains.mps.openapi.editor.cells.EditorCell_Collection>() {
                 @Override
                 public boolean met(
                     jetbrains.mps.openapi.editor.cells.EditorCell_Collection object) {
                   return object == EditorCell_Collection.this;
                 }
               })
           != null;
 }