示例#1
0
  public static void showCreateNewRootMenu(
      @NotNull jetbrains.mps.openapi.editor.EditorContext editorContext,
      @Nullable Setter<SNode> newRootHandler,
      @Nullable Condition<SConcept> conceptsFilter) {
    final EditorCell selectedCell = editorContext.getSelectedCell();
    int x = selectedCell.getX();
    int y = selectedCell.getY();
    if (selectedCell instanceof EditorCell_Label) {
      y += selectedCell.getHeight();
    }
    Component editorComponent = ((EditorContext) editorContext).getNodeEditorComponent();
    final DataContext dataContext = DataManager.getInstance().getDataContext(editorComponent, x, y);
    final SModel model = selectedCell.getSNode().getModel();

    if (conceptsFilter == null) {
      conceptsFilter = Condition.TRUE_CONDITION;
    }

    BaseGroup group = new BaseGroup("");
    Set<SLanguage> modelLanguages =
        new SLanguageHierarchy(SModelOperations.getAllLanguageImports(model)).getExtended();
    SLanguage[] languages = modelLanguages.toArray(new SLanguage[modelLanguages.size()]);
    Arrays.sort(languages, new ToStringComparator());
    for (SLanguage language : languages) {
      boolean hasChildren = false;
      for (SAbstractConcept ac : language.getConcepts()) {
        if (!(ac instanceof SConcept)) {
          continue;
        }
        final SConcept concept = (SConcept) ac;
        if (concept.isRootable() && conceptsFilter.met(concept)) {
          group.add(new AddNewRootAction(model, concept, newRootHandler));
          hasChildren = true;
        }
      }

      if (hasChildren) {
        group.addSeparator();
      }
    }

    ListPopup popup =
        JBPopupFactory.getInstance()
            .createActionGroupPopup(
                IdeBundle.message("title.popup.new.element"),
                group,
                dataContext,
                JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
                false);
    //    popup.showInBestPositionFor(dataContext);
    popup.show(new RelativePoint(editorComponent, new Point(x, y)));
  }
示例#2
0
 public void apply() {
   if (myNodesToApply.isEmpty()) {
     return;
   }
   SNode first = myNodesToApply.iterator().next();
   SModel model = first.getModel();
   if (model == null) {
     LOG.warning(
         "Checking node which is not attached to the model: "
             + first.getPresentation()
             + " "
             + first.getNodeId());
     return;
   }
   // XXX could I demand here that model has to be attached to a repository, so that I can use one
   // to obtain LanguageRegistry?
   for (SLanguage language : SModelOperations.getAllLanguageImports(model)) {
     LanguageRuntime languageRuntime = LanguageRegistry.getInstance().getLanguage(language);
     if (languageRuntime == null) {
       continue;
     }
     DataFlowAspectDescriptor aspect = languageRuntime.getAspect(DataFlowAspectDescriptor.class);
     if (aspect == null) {
       continue;
     }
     for (DataFlowConstructor rule : aspect.getConstructors(myAnalyzerId)) {
       myRules.add(rule);
     }
   }
   Set<SNode> descendants = new LinkedHashSet<SNode>();
   for (SNode myNodeToApply : myNodesToApply) {
     descendants.addAll(
         SNodeOperations.getNodeDescendants(
             myNodeToApply, null, false, new SAbstractConcept[] {}));
   }
   for (SNode descendant : descendants) {
     getRules(descendant).forEach(rule -> rule.performActions(myProgram, descendant));
   }
 }