コード例 #1
0
 public boolean isModified() {
   if (myModuleModel.isChanged()) {
     return true;
   }
   for (ModuleEditor moduleEditor : myModuleEditors.values()) {
     if (moduleEditor.isModified()) {
       return true;
     }
   }
   return myModified || myFacetsConfigurator.isModified();
 }
コード例 #2
0
 public void moduleRenamed(Module module, final String oldName, final String name) {
   ModuleEditor moduleEditor = myModuleEditors.get(module);
   if (moduleEditor != null) {
     moduleEditor.setModuleName(name);
     moduleEditor.updateCompilerOutputPathChanged(
         ProjectStructureConfigurable.getInstance(myProject)
             .getProjectConfig()
             .getCompilerOutputUrl(),
         name);
     myContext
         .getDaemonAnalyzer()
         .queueUpdate(new ModuleProjectStructureElement(myContext, module));
   }
 }
コード例 #3
0
  private ModuleEditor doCreateModuleEditor(final Module module) {
    final ModuleEditor moduleEditor =
        new HeaderHidingTabbedModuleEditor(myProject, this, module) {
          @Override
          public ProjectFacetsConfigurator getFacetsConfigurator() {
            return myFacetsConfigurator;
          }
        };

    myModuleEditors.put(moduleEditor.getModule(), moduleEditor);

    moduleEditor.addChangeListener(this);
    Disposer.register(
        moduleEditor,
        new Disposable() {
          @Override
          public void dispose() {
            moduleEditor.removeChangeListener(ModulesConfigurator.this);
          }
        });
    return moduleEditor;
  }
コード例 #4
0
  private boolean doRemoveModule(@NotNull ModuleEditor selectedEditor) {

    String question;
    if (myModuleEditors.size() == 1) {
      question = ProjectBundle.message("module.remove.last.confirmation");
    } else {
      question =
          ProjectBundle.message("module.remove.confirmation", selectedEditor.getModule().getName());
    }
    int result =
        Messages.showYesNoDialog(
            myProject,
            question,
            ProjectBundle.message("module.remove.confirmation.title"),
            Messages.getQuestionIcon());
    if (result != Messages.YES) {
      return false;
    }
    // do remove
    myModuleEditors.remove(selectedEditor.getModule());

    // destroyProcess removed module
    final Module moduleToRemove = selectedEditor.getModule();
    // remove all dependencies on the module that is about to be removed
    List<ModifiableRootModel> modifiableRootModels = new ArrayList<ModifiableRootModel>();
    for (final ModuleEditor moduleEditor : myModuleEditors.values()) {
      final ModifiableRootModel modifiableRootModel = moduleEditor.getModifiableRootModelProxy();
      modifiableRootModels.add(modifiableRootModel);
    }

    // destroyProcess editor
    ModuleDeleteProvider.removeModule(moduleToRemove, null, modifiableRootModels, myModuleModel);
    processModuleCountChanged();
    Disposer.dispose(selectedEditor);

    return true;
  }
コード例 #5
0
 public void processModuleCompilerOutputChanged(String baseUrl) {
   for (ModuleEditor moduleEditor : myModuleEditors.values()) {
     moduleEditor.updateCompilerOutputPathChanged(baseUrl, moduleEditor.getName());
   }
 }
コード例 #6
0
 private void processModuleCountChanged() {
   for (ModuleEditor moduleEditor : myModuleEditors.values()) {
     moduleEditor.moduleCountChanged();
   }
 }
コード例 #7
0
  public void apply() throws ConfigurationException {
    // validate content and source roots
    final Map<VirtualFile, String> contentRootToModuleNameMap = new HashMap<VirtualFile, String>();
    final Map<VirtualFile, VirtualFile> srcRootsToContentRootMap =
        new HashMap<VirtualFile, VirtualFile>();
    for (final ModuleEditor moduleEditor : myModuleEditors.values()) {
      final ModifiableRootModel rootModel = moduleEditor.getModifiableRootModel();
      final ContentEntry[] contents = rootModel.getContentEntries();
      for (ContentEntry contentEntry : contents) {
        final VirtualFile contentRoot = contentEntry.getFile();
        if (contentRoot == null) {
          continue;
        }
        final String moduleName = moduleEditor.getName();
        final String previousName = contentRootToModuleNameMap.put(contentRoot, moduleName);
        if (previousName != null && !previousName.equals(moduleName)) {
          throw new ConfigurationException(
              ProjectBundle.message(
                  "module.paths.validation.duplicate.content.error",
                  contentRoot.getPresentableUrl(),
                  previousName,
                  moduleName));
        }
        for (VirtualFile srcRoot : contentEntry.getSourceFolderFiles()) {
          final VirtualFile anotherContentRoot = srcRootsToContentRootMap.put(srcRoot, contentRoot);
          if (anotherContentRoot != null) {
            final String problematicModule;
            final String correctModule;
            if (VfsUtilCore.isAncestor(anotherContentRoot, contentRoot, true)) {
              problematicModule = contentRootToModuleNameMap.get(anotherContentRoot);
              correctModule = contentRootToModuleNameMap.get(contentRoot);
            } else {
              problematicModule = contentRootToModuleNameMap.get(contentRoot);
              correctModule = contentRootToModuleNameMap.get(anotherContentRoot);
            }
            throw new ConfigurationException(
                ProjectBundle.message(
                    "module.paths.validation.duplicate.source.root.error",
                    problematicModule,
                    srcRoot.getPresentableUrl(),
                    correctModule));
          }
        }
      }
    }
    // additional validation: directories marked as src roots must belong to the same module as
    // their corresponding content root
    for (Map.Entry<VirtualFile, VirtualFile> entry : srcRootsToContentRootMap.entrySet()) {
      final VirtualFile srcRoot = entry.getKey();
      final VirtualFile correspondingContent = entry.getValue();
      final String expectedModuleName = contentRootToModuleNameMap.get(correspondingContent);

      for (VirtualFile candidateContent = srcRoot;
          candidateContent != null && !candidateContent.equals(correspondingContent);
          candidateContent = candidateContent.getParent()) {
        final String moduleName = contentRootToModuleNameMap.get(candidateContent);
        if (moduleName != null && !moduleName.equals(expectedModuleName)) {
          throw new ConfigurationException(
              ProjectBundle.message(
                  "module.paths.validation.source.root.belongs.to.another.module.error",
                  srcRoot.getPresentableUrl(),
                  expectedModuleName,
                  moduleName));
        }
      }
    }

    final List<ModifiableRootModel> models =
        new ArrayList<ModifiableRootModel>(myModuleEditors.size());
    for (ModuleEditor moduleEditor : myModuleEditors.values()) {
      moduleEditor.canApply();
    }

    final Map<Sdk, Sdk> modifiedToOriginalMap = new HashMap<Sdk, Sdk>();
    final ProjectSdksModel projectJdksModel =
        ProjectStructureConfigurable.getInstance(myProject).getProjectJdksModel();
    for (Map.Entry<Sdk, Sdk> entry : projectJdksModel.getProjectSdks().entrySet()) {
      modifiedToOriginalMap.put(entry.getValue(), entry.getKey());
    }

    final Ref<ConfigurationException> exceptionRef = Ref.create();
    DumbService.getInstance(myProject)
        .allowStartingDumbModeInside(
            DumbModePermission.MAY_START_BACKGROUND,
            new Runnable() {
              public void run() {
                ApplicationManager.getApplication()
                    .runWriteAction(
                        new Runnable() {
                          @Override
                          public void run() {
                            try {
                              for (final ModuleEditor moduleEditor : myModuleEditors.values()) {
                                final ModifiableRootModel model = moduleEditor.apply();
                                if (model != null) {
                                  if (!model.isSdkInherited()) {
                                    // make sure the sdk is set to original SDK stored in the JDK
                                    // Table
                                    final Sdk modelSdk = model.getSdk();
                                    if (modelSdk != null) {
                                      final Sdk original = modifiedToOriginalMap.get(modelSdk);
                                      if (original != null) {
                                        model.setSdk(original);
                                      }
                                    }
                                  }
                                  models.add(model);
                                }
                              }
                              myFacetsConfigurator.applyEditors();
                            } catch (ConfigurationException e) {
                              exceptionRef.set(e);
                              return;
                            }

                            try {
                              final ModifiableRootModel[] rootModels =
                                  models.toArray(new ModifiableRootModel[models.size()]);
                              ModifiableModelCommitter.multiCommit(rootModels, myModuleModel);
                              myModuleModelCommitted = true;
                              myFacetsConfigurator.commitFacets();

                            } finally {
                              ModuleStructureConfigurable.getInstance(myProject)
                                  .getFacetEditorFacade()
                                  .clearMaps(false);

                              myFacetsConfigurator = createFacetsConfigurator();
                              myModuleModel =
                                  ModuleManager.getInstance(myProject).getModifiableModel();
                              myModuleModelCommitted = false;
                            }
                          }
                        });
              }
            });

    if (!exceptionRef.isNull()) {
      throw exceptionRef.get();
    }

    myModified = false;
  }