Exemplo n.º 1
0
  public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) {
    try {
      FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.goto.rootNode");

      Project project = event.getData(PlatformDataKeys.PROJECT);
      assert project != null;

      RootChooseModel chooseSNodeResult = new RootChooseModel(project, new RootNodeNameIndex());
      ChooseByNamePopup popup =
          MpsPopupFactory.createNodePopupWithParentAction(
              project, chooseSNodeResult, GoToRootNode_Action.this);

      popup.invoke(
          new ChooseByNamePopupComponent.Callback() {
            @Override
            public void onClose() {}

            @Override
            public void elementChosen(Object element) {
              ((NavigationItem) element).navigate(true);
            }
          },
          ModalityState.current(),
          true);
    } catch (Throwable t) {
      if (LOG.isEnabledFor(Level.ERROR)) {
        LOG.error("User's action execute method failed. Action:" + "GoToRootNode", t);
      }
    }
  }
Exemplo n.º 2
0
  public static void addModelImportByRoot(
      final Project project,
      final SModule contextModule,
      final SModel model,
      String initialText,
      @Nullable BaseAction parentAction,
      final ModelImportByRootCallback callback) {
    BaseMPSChooseModel goToNodeModel =
        new RootChooseModel(project, new RootNodeNameIndex()) {
          @Override
          public NavigationItem doGetNavigationItem(final NavigationTarget object) {
            return new RootNodeElement(object) {
              @Override
              public void navigate(boolean requestFocus) {
                ModelAccess.assertLegalRead();
                new AddModelItem(
                        project,
                        model,
                        object.getNodeReference().getModelReference(),
                        contextModule)
                    .navigate(requestFocus);
              }
            };
          }

          @Override
          @Nullable
          public String getPromptText() {
            return "Import model that contains root:";
          }
        };
    ChooseByNamePopup popup =
        MpsPopupFactory.createNodePopup(project, goToNodeModel, initialText, parentAction);

    popup.invoke(
        new ChooseByNamePopupComponent.Callback() {
          @Override
          public void onClose() {
            // if (GoToRootNodeAction.class.equals(myInAction)) myInAction = null;
          }

          @Override
          public void elementChosen(final Object element) {
            ModelAccess.instance()
                .runWriteAction(
                    new Runnable() {
                      @Override
                      public void run() {
                        NavigationItem navigationItem = (NavigationItem) element;
                        navigationItem.navigate(true);
                        callback.importForRootAdded(
                            navigationItem.getPresentation().getPresentableText());
                      }
                    });
          }
        },
        ModalityState.current(),
        true);
  }
Exemplo n.º 3
0
  public static void addModelImport(
      final Project project,
      final SModule module,
      final SModel model,
      @Nullable BaseAction parentAction) {
    BaseModelModel goToModelModel =
        new BaseModelModel(project) {
          @Override
          public NavigationItem doGetNavigationItem(final SModelReference modelReference) {
            return new AddModelItem(project, model, modelReference, module);
          }

          @Override
          public SModelReference[] find(SearchScope scope) {
            Condition<SModel> cond =
                new Condition<SModel>() {
                  @Override
                  public boolean met(SModel modelDescriptor) {
                    boolean rightStereotype =
                        SModelStereotype.isUserModel(modelDescriptor)
                            || SModelStereotype.isStubModelStereotype(
                                SModelStereotype.getStereotype(modelDescriptor));
                    boolean hasModule = modelDescriptor.getModule() != null;
                    return rightStereotype && hasModule;
                  }
                };
            ConditionalIterable<SModel> iter =
                new ConditionalIterable<SModel>(scope.getModels(), cond);
            List<SModelReference> filteredModelRefs = new ArrayList<SModelReference>();
            for (SModel md : iter) {
              filteredModelRefs.add(md.getReference());
            }
            return filteredModelRefs.toArray(new SModelReference[filteredModelRefs.size()]);
          }

          @Override
          @Nullable
          public String getPromptText() {
            return "Import model:";
          }
        };
    ChooseByNamePopup popup =
        MpsPopupFactory.createPackagePopup(project, goToModelModel, parentAction);

    popup.invoke(
        new ChooseByNamePopupComponent.Callback() {
          @Override
          public void onClose() {
            // if (GoToRootNodeAction.class.equals(myInAction)) myInAction = null;
          }

          @Override
          public void elementChosen(final Object element) {
            ((NavigationItem) element).navigate(true);
          }
        },
        ModalityState.current(),
        true);
  }
Exemplo n.º 4
0
  public static void addLanguageImport(
      final Project project,
      final SModule contextModule,
      final SModel model,
      @Nullable BaseAction parentAction,
      @Nullable final Runnable onClose) {
    BaseLanguageModel goToLanguageModel =
        new BaseLanguageModel(project) {
          @Override
          public NavigationItem doGetNavigationItem(SModuleReference ref) {
            return new AddLanguageItem(project, ref, contextModule, model);
          }

          @Override
          public SModuleReference[] find(SearchScope scope) {
            ArrayList<SModuleReference> res = new ArrayList<SModuleReference>();
            for (SModule m : scope.getModules()) {
              if (!(m instanceof Language)) continue;
              res.add(m.getModuleReference());
            }
            return res.toArray(new SModuleReference[res.size()]);
          }

          @Nullable
          @Override
          public String getPromptText() {
            return "Import language:";
          }
        };
    ChooseByNamePopup popup =
        MpsPopupFactory.createPackagePopup(project, goToLanguageModel, parentAction);

    popup.invoke(
        new ChooseByNamePopupComponent.Callback() {
          @Override
          public void onClose() {
            // if (GoToRootNodeAction.class.equals(myInAction)) myInAction = null;
            if (onClose != null) {
              onClose.run();
            }
          }

          @Override
          public void elementChosen(Object element) {
            ((NavigationItem) element).navigate(true);
          }
        },
        ModalityState.current(),
        true);
  }