示例#1
0
  public static List<DefaultActionGroup> getCreateGroups(
      SNodeReference baseNode,
      Collection<RelationDescriptor> possibleTabs,
      @Nullable RelationDescriptor currentAspect,
      NodeChangeCallback callback) {
    List<DefaultActionGroup> groups = new ArrayList<DefaultActionGroup>();

    List<RelationDescriptor> tabs = new ArrayList<RelationDescriptor>(possibleTabs);
    Collections.sort(tabs, new RelationComparator());

    if (currentAspect != null) {
      tabs.remove(currentAspect);
      tabs.add(0, currentAspect);
    }

    for (final RelationDescriptor d : tabs) {
      List<SNode> nodes = d.getNodes(baseNode.resolve(MPSModuleRepository.getInstance()));
      if (!nodes.isEmpty() && d.isSingle()) continue;

      DefaultActionGroup group = getCreateGroup(baseNode, callback, d);
      if (group == null) continue;

      if (tabs.indexOf(d) == 0) {
        group.setPopup(false);
      }

      groups.add(group);
    }
    return groups;
  }
示例#2
0
  public static DefaultActionGroup getCreateGroup(
      SNodeReference baseNode, NodeChangeCallback callback, RelationDescriptor d) {
    List<SNode> concepts = d.getConcepts(baseNode.resolve(MPSModuleRepository.getInstance()));
    if (concepts.isEmpty()) return new DefaultActionGroup();

    DefaultActionGroup group = new DefaultActionGroup(d.getTitle(), true);
    for (final SNode concept : concepts) {
      group.add(new CreateAction(concept, d, baseNode, callback));
    }
    return group;
  }
示例#3
0
    @Override
    public void actionPerformed(AnActionEvent e) {
      final SNode[] created = new SNode[1];

      final Runnable r1 =
          new Runnable() {
            @Override
            public void run() {
              created[0] =
                  myDescriptor.createNode(
                      myBaseNode.resolve(MPSModuleRepository.getInstance()), myConcept);
            }
          };

      final Runnable r2 =
          new Runnable() {
            @Override
            public void run() {
              String mainPack =
                  SNodeAccessUtil.getProperty(
                      myBaseNode.resolve(MPSModuleRepository.getInstance()),
                      jetbrains.mps.smodel.SNode.PACK);
              SNodeAccessUtil.setProperty(created[0], jetbrains.mps.smodel.SNode.PACK, mainPack);
              myCallback.changeNode(created[0]);
            }
          };

      if (myDescriptor.commandOnCreate()) {
        ModelAccess.instance()
            .runWriteActionInCommand(
                new Runnable() {
                  @Override
                  public void run() {
                    r1.run();
                  }
                });
      } else {
        r1.run();
      }
      if (created[0] == null) return;
      ModelAccess.instance().runWriteActionInCommand(r2);
    }