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);
      }
    }
  }
Exemple #2
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);
  }
Exemple #3
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);
  }
Exemple #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);
  }
 @Override
 public void showPopup() {
   // todo leak via not shown dialog?
   ChooseByNamePopup popup =
       ChooseByNamePopup.createPopup(myProject, createChooseByNameModel(), getContext());
   popup.invoke(
       new ChooseByNamePopupComponent.Callback() {
         @Override
         public void elementChosen(Object element) {
           mySelectedClass = (T) element;
           ((Navigatable) element).navigate(true);
         }
       },
       getModalityState(),
       true);
 }
Exemple #6
0
  public void doExecute(AnActionEvent e, Map<String, Object> _params) {
    final Project project = e.getData(PlatformDataKeys.PROJECT);
    assert project != null;

    FeatureUsageTracker.getInstance().triggerFeatureUsed("goto.model");
    // PsiDocumentManager.getInstance(project).commitAllDocuments();

    BaseModelModel goToModelModel =
        new BaseModelModel(project) {
          public NavigationItem doGetNavigationItem(final SModelReference modelReference) {
            return new BaseModelItem(modelReference) {
              public void navigate(boolean requestFocus) {
                ProjectPane projectPane = ProjectPane.getInstance(project);
                SModelDescriptor md =
                    SModelRepository.getInstance().getModelDescriptor(modelReference);
                projectPane.selectModel(md, true);
              }
            };
          }

          public SModelReference[] find(IScope scope) {
            Condition<SModelDescriptor> cond =
                new Condition<SModelDescriptor>() {
                  public boolean met(SModelDescriptor modelDescriptor) {
                    boolean rightStereotype =
                        SModelStereotype.isUserModel(modelDescriptor)
                            || SModelStereotype.isStubModelStereotype(
                                modelDescriptor.getStereotype());
                    boolean hasModule = modelDescriptor.getModule() != null;
                    return rightStereotype && hasModule;
                  }
                };
            ConditionalIterable<SModelDescriptor> iter =
                new ConditionalIterable<SModelDescriptor>(scope.getModelDescriptors(), cond);
            List<SModelReference> result = new ArrayList<SModelReference>();
            for (SModelDescriptor md : iter) {
              result.add(md.getSModelReference());
            }
            return result.toArray(new SModelReference[result.size()]);
          }
        };
    ChooseByNamePopup popup = MpsPopupFactory.createPackagePopup(project, goToModelModel);
    popup.setShowListForEmptyPattern(true);
    popup.invoke(new NavigateCallback(), ModalityState.current(), true);
  }
  public void doExecute(AnActionEvent e, Map<String, Object> _params) {
    final Project project = e.getData(PlatformDataKeys.PROJECT);
    assert project != null;

    ChooseByNamePopup popup;

    if (!myUseCache) {
      BaseNodeModel baseNodeModel =
          new BaseNodeModel(project) {
            public SNode[] find(IScope scope) {
              final List<SNode> nodes = new ArrayList<SNode>();
              Iterable<SModelDescriptor> modelDescriptors = scope.getModelDescriptors();
              for (SModelDescriptor modelDescriptor : modelDescriptors) {
                if (!SModelStereotype.isUserModel(modelDescriptor)) continue;
                for (SNode node : modelDescriptor.getSModel().roots()) {
                  nodes.add(node);
                }
              }
              return nodes.toArray(new SNode[0]);
            }

            public boolean willOpenEditor() {
              return true;
            }
          };
      popup = MpsPopupFactory.createNodePopup(project, baseNodeModel);
    } else {
      MPSChooseSNodeDescriptor chooseSNodeResult =
          new MPSChooseSNodeDescriptor(project, new RootNodeNameIndex());
      popup = MpsPopupFactory.createNodePopup(project, chooseSNodeResult);
    }

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

          public void elementChosen(Object element) {
            ((NavigationItem) element).navigate(true);
          }
        },
        ModalityState.current(),
        true);
  }
  @Override
  protected void initUI(
      Callback callback, ModalityState modalityState, boolean allowMultipleSelection) {
    super.initUI(callback, modalityState, allowMultipleSelection);

    myTextFieldPanel.setBorder(null);

    myPanel = new JPanel(new GridBagLayout());

    myPanel.add(
        myTextFieldPanel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    myPanel.add(
        myListScrollPane,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1,
            1,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    myPanel.add(
        new JPanel(),
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            1,
            0.001,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    myTextFieldPanel.setOpaque(false);
  }
 @Override
 protected void doClose(boolean ok) {
   myChoosenElementsBackUp = super.getChosenElements();
   super.doClose(ok);
 }