Example #1
0
  public void saveChanges() {
    if (!(myModelDescriptor instanceof EditableSModel)) {
      return;
    }

    addNewModels();
    removeUnusedModels();
    updateUsedLanguages();
    addNewDevKits();
    removeUnusedDevKits();
    addNewEngagedOnGenerationLanguages();
    removeUnusedEngagedOnGenerationLanguages();
    if (myModelDescriptor instanceof GeneratableSModel) {
      GeneratableSModel dmd = (GeneratableSModel) myModelDescriptor;
      if (dmd.isDoNotGenerate() != myDoNotGenerate) {
        dmd.setDoNotGenerate(myDoNotGenerate);
      }
      if (dmd.isGenerateIntoModelFolder() != myGenerateIntoModelFolder) {
        dmd.setGenerateIntoModelFolder(myGenerateIntoModelFolder);
      }
    }

    if (!(myModelDescriptor.getSource() instanceof NullDataSource)) {
      ((EditableSModel) myModelDescriptor).save();
    }

    new MissingDependenciesFixer(myModelDescriptor).fixModuleDependencies();
    // change of model properties might affect generation status. This explicit call is needed
    // unless model dispatch proper change events (which it does not at the moment), and project
    // pane
    // got no other means to find out it needs to update generation status
    ModelGenerationStatusManager.getInstance()
        .invalidateData(Collections.singleton(myModelDescriptor));
  }
Example #2
0
 @Nullable
 private static FileStatus getModelFileStatus(
     @NotNull EditableSModel ed, @NotNull Project project) {
   DataSource ds = ed.getSource();
   IFile file = null;
   if (ds instanceof FileDataSource) {
     file = ((FileDataSource) ds).getFile();
   } else if (ds instanceof FilePerRootDataSource) {
     file = ((FilePerRootDataSource) ds).getFile(FilePerRootDataSource.HEADER_FILE);
   }
   VirtualFile vf = VirtualFileUtils.getVirtualFile(file);
   return (vf == null ? null : FileStatusManager.getInstance(project).getStatus(vf));
 }
Example #3
0
  protected void renameModels(String oldName, String newName, boolean moveModels) {
    // if module name is a prefix of it's model's name - rename the model, too
    for (SModel m : getModels()) {
      if (m.isReadOnly()
          || !m.getName().getNamespace().startsWith(oldName)
          || !(m instanceof EditableSModel)) {
        continue;
      }

      SModelName newModelName =
          new SModelName(
              newName + m.getName().getNamespace().substring(oldName.length()),
              m.getName().getSimpleName(),
              m.getName().getStereotype());
      ((EditableSModel) m).rename(newModelName.getValue(), moveModels);
    }
  }
 private SModule getModule(AbstractTreeNode selectedNode) {
   EditableSModel contextModel = getContextModel(selectedNode);
   return contextModel != null ? contextModel.getModule() : null;
 }
Example #5
0
  @Override
  public void actionPerformed(AnActionEvent e) {
    if (myModelDescriptor == null && myNewModel) {
      if (createPerRootModel(e)) return;
    }

    if (myModelDescriptor == null) return;

    if (myConceptFqNameToNodePointerMap.isEmpty()) {
      ImportHelper.addLanguageImport(
          myProject,
          myModelDescriptor.getModule(),
          myModelDescriptor.getModule().getModel(myModelDescriptor.getModelId()),
          null,
          new Runnable() {
            @Override
            public void run() {
              final ProjectView projectView = ProjectView.getInstance(myProject);
              projectView.refresh();
            }
          });
      return;
    }

    final CreateFromTemplateDialog dialog =
        new CreateFromTemplateDialog(myProject) {
          @Override
          protected void doOKAction() {
            final SNodeReference conceptPointer =
                myConceptFqNameToNodePointerMap.get(getKindCombo().getSelectedName());
            myOperationContext
                .getProject()
                .getModelAccess()
                .executeCommand(
                    new Runnable() {
                      @Override
                      public void run() {
                        SNode concept = conceptPointer.resolve(MPSModuleRepository.getInstance());
                        SModel model = myModelDescriptor;
                        SNode newNode = NodeFactoryManager.createNode(concept, null, null, model);
                        SNodeAccessUtil.setProperty(
                            newNode,
                            SNodeUtil.property_INamedConcept_name,
                            getNameField().getText());
                        model.addRootNode(newNode);
                        myModelDescriptor.save();
                      }
                    });
            super.doOKAction();
          }
        };
    dialog.setTitle(MPSBundle.message("create.new.root.dialog.title"));
    myOperationContext
        .getProject()
        .getModelAccess()
        .runReadAction(
            new Runnable() {
              @Override
              public void run() {
                for (Map.Entry<String, SNodeReference> entry :
                    myConceptFqNameToNodePointerMap.entrySet()) {
                  String conceptFqName = entry.getKey();
                  SNode concept = entry.getValue().resolve(MPSModuleRepository.getInstance());
                  dialog
                      .getKindCombo()
                      .addItem(
                          NodePresentationUtil.matchingText(concept),
                          IconManager.getIconForConceptFQName(conceptFqName),
                          conceptFqName);
                }
              }
            });
    dialog.show();
  }
Example #6
0
 void detachChangeListeners(SModelListener l1, SModelChangeListener l2) {
   assert myNeedEditableModel;
   assert myModel != null : "call createModel() first";
   ((SModelInternal) myModel).removeModelListener(l1);
   ((EditableSModel) myModel).removeChangeListener(l2);
 }
Example #7
0
 public void clearEditableChanged() {
   assert myNeedEditableModel;
   assert myModel != null : "call createModel() first";
   ((EditableSModel) myModel).setChanged(false);
 }