コード例 #1
0
ファイル: ImportHelper.java プロジェクト: huangchaoneng/MPS
  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);
  }
コード例 #2
0
ファイル: ImportHelper.java プロジェクト: huangchaoneng/MPS
  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);
  }