Пример #1
0
 @Override
 public void queryPlace(@NotNull final Place place) {
   final ModuleEditor editor = getModuleEditor();
   if (editor != null) {
     editor.queryPlace(place);
   }
 }
Пример #2
0
 @Override
 @Nullable
 @NonNls
 public String getHelpTopic() {
   final ModuleEditor moduleEditor = getModuleEditor();
   return moduleEditor != null ? moduleEditor.getHelpTopic() : null;
 }
 public boolean isModified() {
   if (myModuleModel.isChanged()) {
     return true;
   }
   for (ModuleEditor moduleEditor : myModuleEditors.values()) {
     if (moduleEditor.isModified()) {
       return true;
     }
   }
   return myModified || myFacetsConfigurator.isModified();
 }
Пример #4
0
  @NotNull
  private static JPanel createLayerConfigurationPanel(@NotNull final ModuleEditor moduleEditor) {
    BorderLayoutPanel panel = JBUI.Panels.simplePanel();

    ModifiableRootModel moduleRootModel = moduleEditor.getModifiableRootModelProxy();

    final MutableCollectionComboBoxModel<String> model =
        new MutableCollectionComboBoxModel<String>(
            new ArrayList<String>(moduleRootModel.getLayers().keySet()),
            moduleRootModel.getCurrentLayerName());

    final ComboBox comboBox = new ComboBox(model);
    comboBox.setEnabled(model.getSize() > 1);

    moduleEditor.addChangeListener(
        new ModuleEditor.ChangeListener() {
          @Override
          public void moduleStateChanged(ModifiableRootModel moduleRootModel) {
            model.update(new ArrayList<String>(moduleRootModel.getLayers().keySet()));
            model.setSelectedItem(moduleRootModel.getCurrentLayerName());
            model.update();

            comboBox.setEnabled(comboBox.getItemCount() > 1);
          }
        });

    comboBox.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
              moduleEditor
                  .getModifiableRootModelProxy()
                  .setCurrentLayer((String) comboBox.getSelectedItem());
            }
          }
        });

    DefaultActionGroup group = new DefaultActionGroup();
    group.add(new NewLayerAction(moduleEditor, false));
    group.add(new DeleteLayerAction(moduleEditor));
    group.add(new NewLayerAction(moduleEditor, true));

    ActionToolbar actionToolbar =
        ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
    JComponent toolbarComponent = actionToolbar.getComponent();
    toolbarComponent.setBorder(JBUI.Borders.empty());

    panel.addToLeft(LabeledComponent.left(comboBox, "Layer")).addToRight(toolbarComponent);
    return panel;
  }
 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));
   }
 }
  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;
  }
  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;
  }
 public void processModuleCompilerOutputChanged(String baseUrl) {
   for (ModuleEditor moduleEditor : myModuleEditors.values()) {
     moduleEditor.updateCompilerOutputPathChanged(baseUrl, moduleEditor.getName());
   }
 }
 private void processModuleCountChanged() {
   for (ModuleEditor moduleEditor : myModuleEditors.values()) {
     moduleEditor.moduleCountChanged();
   }
 }
  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;
  }