diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/EditLibraryDialog.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/EditLibraryDialog.java index e2849053078e..3192e9acaa26 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/EditLibraryDialog.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/EditLibraryDialog.java @@ -41,7 +41,8 @@ public class EditLibraryDialog extends DialogWrapper { super(parent, true); mySettings = settings; myLibraryEditor = libraryEditor; - myLibraryRootsComponent = LibraryRootsComponent.createComponent(libraryEditor); + myLibraryRootsComponent = new LibraryRootsComponent(null, libraryEditor); + myLibraryRootsComponent.resetProperties(); Disposer.register(getDisposable(), myLibraryRootsComponent); @@ -63,6 +64,7 @@ public class EditLibraryDialog extends DialogWrapper { @Override protected void doOKAction() { myLibraryEditor.setName(myNameAndLevelPanel.getLibraryName()); + myLibraryRootsComponent.applyProperties(); if (myLibraryEditor instanceof NewLibraryEditor) { mySettings.setNewLibraryLevel(myNameAndLevelPanel.getLibraryLevel()); } diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java index 9c95ff739ef4..4cbbc8a6dbfb 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java @@ -19,8 +19,8 @@ import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; -import com.intellij.openapi.roots.ui.configuration.ProjectStructureDialogCellAppearanceUtils; import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration; +import com.intellij.openapi.roots.ui.configuration.ProjectStructureDialogCellAppearanceUtils; import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor; import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor; import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; diff --git a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java index b3b49964aae7..ee766ef0384c 100644 --- a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java +++ b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java @@ -22,9 +22,9 @@ import com.intellij.ide.IdeBundle; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration; import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; import com.intellij.openapi.roots.ui.configuration.libraries.LibraryDownloadDescription; -import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration; import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor; import com.intellij.openapi.util.Condition; import com.intellij.openapi.vfs.VirtualFile; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form index 88a7a26bf53c..e394db950bef 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form @@ -1,6 +1,6 @@
- + @@ -11,7 +11,7 @@ - + @@ -90,7 +90,7 @@ - + @@ -104,6 +104,14 @@ + + + + + + + + diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java index 7adcb4b39c34..211cb7933cb3 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java @@ -340,12 +340,12 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se } public ActionCallback selectProjectGeneralSettings(final boolean requestFocus) { - Place place = new Place().putPath(CATEGORY, myProjectConfig); + Place place = createPlaceFor(myProjectConfig); return navigateTo(place, requestFocus); } public ActionCallback select(@Nullable final String moduleToSelect, String tab, final boolean requestFocus) { - Place place = new Place().putPath(CATEGORY, myModulesConfig); + Place place = createPlaceFor(myModulesConfig); if (moduleToSelect != null) { final Module module = ModuleManager.getInstance(myProject).findModuleByName(moduleToSelect); assert module != null; @@ -355,7 +355,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se } public ActionCallback select(@Nullable final Facet facetToSelect, final boolean requestFocus) { - Place place = new Place().putPath(CATEGORY, myModulesConfig); + Place place = createPlaceFor(myModulesConfig); if (facetToSelect != null) { place = place.putPath(ModuleStructureConfigurable.TREE_OBJECT, facetToSelect); } @@ -363,19 +363,19 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se } public ActionCallback select(@NotNull Sdk sdk, final boolean requestFocus) { - Place place = new Place().putPath(CATEGORY, myJdkListConfig); + Place place = createPlaceFor(myJdkListConfig); place.putPath(BaseStructureConfigurable.TREE_NAME, sdk.getName()); return navigateTo(place, requestFocus); } public ActionCallback selectProjectOrGlobalLibrary(@NotNull Library library, boolean requestFocus) { - Place place = new Place().putPath(CATEGORY, getConfigurableFor(library)); + Place place = createPlaceFor(getConfigurableFor(library)); place.putPath(BaseStructureConfigurable.TREE_NAME, library.getName()); return navigateTo(place, requestFocus); } public ActionCallback select(@Nullable Artifact artifact, boolean requestFocus) { - Place place = new Place().putPath(CATEGORY, myArtifactsStructureConfigurable); + Place place = createPlaceFor(myArtifactsStructureConfigurable); if (artifact != null) { place.putPath(BaseStructureConfigurable.TREE_NAME, artifact.getName()); } @@ -385,11 +385,11 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se public ActionCallback select(@NotNull LibraryOrderEntry libraryOrderEntry, final boolean requestFocus) { final Library lib = libraryOrderEntry.getLibrary(); if (lib == null || lib.getTable() == null) { - Place place = new Place().putPath(CATEGORY, myModulesConfig); + Place place = createPlaceFor(myModulesConfig); place.putPath(BaseStructureConfigurable.TREE_OBJECT, libraryOrderEntry.getOwnerModule()); return navigateTo(place, requestFocus); } - Place place = new Place().putPath(CATEGORY, getConfigurableFor(lib)); + Place place = createPlaceFor(getConfigurableFor(lib)); place.putPath(BaseStructureConfigurable.TREE_NAME, libraryOrderEntry.getLibraryName()); return navigateTo(place, requestFocus); } @@ -400,6 +400,9 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se JComponent detailsContent = myDetails.getTargetComponent(); if (mySelectedConfigurable != toSelect) { + if (mySelectedConfigurable instanceof BaseStructureConfigurable) { + ((BaseStructureConfigurable)mySelectedConfigurable).onStructureUnselected(); + } saveSideProportion(); removeSelected(); @@ -424,6 +427,10 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se if (toSelect instanceof DetailsComponent.Facade) { ((DetailsComponent.Facade)toSelect).getDetailsComponent().setBannerMinHeight(myToolbarComponent.getPreferredSize().height); } + + if (toSelect instanceof BaseStructureConfigurable) { + ((BaseStructureConfigurable)toSelect).onStructureSelected(); + } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/impl/LibraryPresentationManagerImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/impl/LibraryPresentationManagerImpl.java index e8e1e76f9cc1..b7aa1cb9d5ae 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/impl/LibraryPresentationManagerImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/impl/LibraryPresentationManagerImpl.java @@ -58,6 +58,10 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager { @Override public Icon getCustomIcon(@NotNull Library library, StructureConfigurableContext context) { + final LibraryType type = ((LibraryEx)library).getType(); + if (type != null) { + return type.getIcon(); + } final List icons = getCustomIcons(library, context); if (icons.size() == 1) { return icons.get(0); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java index bf9f876e832b..8d374c5ea6f1 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java @@ -22,17 +22,17 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable; import com.intellij.openapi.roots.ui.configuration.libraries.LibraryEditingUtil; import com.intellij.openapi.roots.ui.configuration.projectRoot.BaseLibrariesConfigurable; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel; import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable; -import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureLibraryTableModifiableModelProvider; -import com.intellij.openapi.ui.InputValidator; import com.intellij.openapi.ui.MasterDetailsComponent; -import com.intellij.openapi.ui.Messages; +import com.intellij.util.Icons; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; @@ -44,40 +44,21 @@ import java.util.List; * @author nik */ public class CreateNewLibraryAction extends AnAction { - private StructureLibraryTableModifiableModelProvider myModelProvider; - private Project myProject; + private final @Nullable LibraryType myType; + private BaseLibrariesConfigurable myLibrariesConfigurable; + private @Nullable Project myProject; - public CreateNewLibraryAction(String text, StructureLibraryTableModifiableModelProvider modelProvider, final Project project) { - super(text); - myModelProvider = modelProvider; + private CreateNewLibraryAction(@NotNull String text, @Nullable Icon icon, @Nullable LibraryType type, @NotNull BaseLibrariesConfigurable librariesConfigurable, final @Nullable Project project) { + super(text, null, icon); + myType = type; + myLibrariesConfigurable = librariesConfigurable; myProject = project; } @Override public void actionPerformed(AnActionEvent e) { - final LibrariesModifiableModel modifiableModel = myModelProvider.getModifiableModel(); - final String initial = LibraryEditingUtil.suggestNewLibraryName(modifiableModel); - final String prompt = ProjectBundle.message("library.name.prompt"); - final String title = ProjectBundle.message("library.create.library.action").replaceAll(String.valueOf(UIUtil.MNEMONIC), ""); - final Icon icon = Messages.getQuestionIcon(); - final String libraryName = Messages.showInputDialog(myProject, prompt, title, icon, initial, new InputValidator() { - public boolean checkInput(final String inputString) { - return true; - } - public boolean canClose(final String inputString) { - if (inputString.length() == 0) { - Messages.showErrorDialog(ProjectBundle.message("library.name.not.specified.error"), ProjectBundle.message("library.name.not.specified.title")); - return false; - } - if (LibraryEditingUtil.libraryAlreadyExists(modifiableModel, inputString)) { - Messages.showErrorDialog(ProjectBundle.message("library.name.already.exists.error", inputString), ProjectBundle.message("library.name.already.exists.title")); - return false; - } - return true; - } - }); - if (libraryName == null) return; - final Library library = modifiableModel.createLibrary(libraryName); + final LibrariesModifiableModel modifiableModel = myLibrariesConfigurable.getModelProvider().getModifiableModel(); + final Library library = modifiableModel.createLibrary(LibraryEditingUtil.suggestNewLibraryName(modifiableModel), myType); if (myProject != null){ final BaseLibrariesConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library); final ExistingLibraryEditor libraryEditor = modifiableModel.getLibraryEditor(library); @@ -105,10 +86,23 @@ public class CreateNewLibraryAction extends AnAction { .message("choose.modules.dialog.description", libraryToSelect.getName())); dlg.show(); if (dlg.isOK()) { - final List choosenModules = dlg.getChosenElements(); - for (Module module : choosenModules) { + final List chosenModules = dlg.getChosenElements(); + for (Module module : chosenModules) { rootConfigurable.addLibraryOrderEntry(module, libraryToSelect); } } } + + public static AnAction[] createActionOrGroup(@NotNull String text, @NotNull BaseLibrariesConfigurable librariesConfigurable, final @Nullable Project project) { + final LibraryType[] extensions = LibraryType.EP_NAME.getExtensions(); + if (extensions.length == 0) { + return new AnAction[]{new CreateNewLibraryAction(text, Icons.LIBRARY_ICON, null, librariesConfigurable, project)}; + } + List actions = new ArrayList(); + actions.add(new CreateNewLibraryAction("Java", Icons.LIBRARY_ICON, null, librariesConfigurable, project)); + for (LibraryType type : extensions) { + actions.add(new CreateNewLibraryAction(type.getCreateActionName(), type.getIcon(), type, librariesConfigurable, project)); + } + return actions.toArray(new AnAction[actions.size()]); + } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryDialog.java index 70ea48517781..3a01e7c716e5 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryDialog.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryDialog.java @@ -44,7 +44,7 @@ public class CreateNewLibraryDialog extends LibraryEditorDialogBase { public CreateNewLibraryDialog(@NotNull JComponent parent, @Nullable Project project, @NotNull NewLibraryEditor libraryEditor, @NotNull List libraryTables, int selectedTable) { - super(parent, LibraryRootsComponent.createComponent(project, libraryEditor)); + super(parent, new LibraryRootsComponent(project, libraryEditor)); myLibraryEditor = libraryEditor; final DefaultComboBoxModel model = new DefaultComboBoxModel(); for (LibraryTable table : libraryTables) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/EditExistingLibraryDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/EditExistingLibraryDialog.java index 3d3ef4e30027..5c5665f4a10b 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/EditExistingLibraryDialog.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/EditExistingLibraryDialog.java @@ -53,7 +53,7 @@ public class EditExistingLibraryDialog extends LibraryEditorDialogBase { private EditExistingLibraryDialog(Component parent, LibraryTable.ModifiableModel tableModifiableModel, @Nullable Project project, ExistingLibraryEditor libraryEditor, boolean commitChanges) { - super(parent, LibraryRootsComponent.createComponent(project, libraryEditor)); + super(parent, new LibraryRootsComponent(project, libraryEditor)); myTableModifiableModel = tableModifiableModel; myLibraryEditor = libraryEditor; myCommitChanges = commitChanges; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ExistingLibraryEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ExistingLibraryEditor.java index dec1cb510af3..6b0c1714db2d 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ExistingLibraryEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ExistingLibraryEditor.java @@ -17,18 +17,23 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor; import com.intellij.openapi.Disposable; import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.impl.libraries.LibraryEx; import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.libraries.LibraryProperties; +import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class ExistingLibraryEditor implements LibraryEditor, Disposable { private final Library myLibrary; private final LibraryEditorListener myListener; private String myLibraryName = null; + private LibraryProperties myLibraryProperties; private Library.ModifiableModel myModel = null; - public ExistingLibraryEditor(Library library, @Nullable LibraryEditorListener listener) { + public ExistingLibraryEditor(@NotNull Library library, @Nullable LibraryEditorListener listener) { myLibrary = library; myListener = listener; } @@ -45,6 +50,28 @@ public class ExistingLibraryEditor implements LibraryEditor, Disposable { return myLibrary.getName(); } + @Override + public LibraryType getType() { + return ((LibraryEx)myLibrary).getType(); + } + + @Override + public LibraryProperties getProperties() { + final LibraryType type = getType(); + if (type == null) return null; + + if (myLibraryProperties == null) { + myLibraryProperties = type.createDefaultProperties(); + //noinspection unchecked + myLibraryProperties.loadState(getOriginalProperties().getState()); + } + return myLibraryProperties; + } + + private LibraryProperties getOriginalProperties() { + return ((LibraryEx)myLibrary).getProperties(); + } + public void dispose() { if (myModel != null) { // dispose if wasn't committed @@ -105,9 +132,13 @@ public class ExistingLibraryEditor implements LibraryEditor, Disposable { public void commit() { if (myModel != null) { + if (myLibraryProperties != null) { + ((LibraryEx.ModifiableModelEx)myModel).setProperties(myLibraryProperties); + } myModel.commit(); myModel = null; myLibraryName = null; + myLibraryProperties = null; } } @@ -120,7 +151,10 @@ public class ExistingLibraryEditor implements LibraryEditor, Disposable { @Override public boolean hasChanges() { - return myModel != null && myModel.isChanged(); + if (myModel != null && myModel.isChanged()) { + return true; + } + return myLibraryProperties != null && !myLibraryProperties.equals(getOriginalProperties()); } @Override diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditor.java index 9eacf280a860..fb963d9cc85f 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditor.java @@ -16,7 +16,10 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor; import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.libraries.LibraryProperties; +import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.Nullable; /** * @author nik @@ -45,4 +48,9 @@ public interface LibraryEditor { boolean isJarDirectory(String url); boolean isValid(String url, OrderRootType orderRootType); + + LibraryProperties getProperties(); + + @Nullable + LibraryType getType(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorDialogBase.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorDialogBase.java index d99235ffaec7..a344d339f2f2 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorDialogBase.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorDialogBase.java @@ -40,6 +40,7 @@ public abstract class LibraryEditorDialogBase extends DialogWrapper { public LibraryEditorDialogBase(final Component parent, final LibraryRootsComponent libraryRootsComponent) { super(parent, true); myLibraryRootsComponent = libraryRootsComponent; + libraryRootsComponent.resetProperties(); setTitle(ProjectBundle.message("library.configure.title")); Disposer.register(getDisposable(), myLibraryRootsComponent); } @@ -83,6 +84,7 @@ public abstract class LibraryEditorDialogBase extends DialogWrapper { } myLibraryRootsComponent.renameLibrary(newName); } + myLibraryRootsComponent.applyProperties(); return true; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java index 824b1cb9e00f..5c3b8a121f23 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java @@ -31,8 +31,9 @@ import com.intellij.openapi.roots.AnnotationOrderRootType; import com.intellij.openapi.roots.JavadocOrderRootType; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.impl.libraries.LibraryImpl; -import com.intellij.openapi.roots.libraries.Library; -import com.intellij.openapi.roots.libraries.LibraryUtil; +import com.intellij.openapi.roots.libraries.*; +import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent; +import com.intellij.openapi.roots.libraries.ui.LibraryPropertiesEditor; import com.intellij.openapi.roots.ui.configuration.ModuleEditor; import com.intellij.openapi.roots.ui.configuration.PathUIUtils; import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager; @@ -74,7 +75,7 @@ import java.util.List; * @author Eugene Zhuravlev * Date: Jan 11, 2004 */ -public class LibraryRootsComponent implements Disposable { +public class LibraryRootsComponent implements Disposable, LibraryEditorComponent { static final UrlComparator ourUrlComparator = new UrlComparator(); private JPanel myPanel; @@ -88,6 +89,8 @@ public class LibraryRootsComponent implements Disposable { private JButton myAttachAnnotationsButton; private JButton myAttachMoreButton; private MultiLineLabel myPropertiesLabel; + private JPanel myPropertiesPanel; + private LibraryPropertiesEditor myPropertiesEditor; private Tree myTree; private LibraryTableTreeBuilder myTreeBuilder; private static final Icon INVALID_ITEM_ICON = IconLoader.getIcon("/nodes/ppInvalid.png"); @@ -97,14 +100,34 @@ public class LibraryRootsComponent implements Disposable { @Nullable private final Project myProject; private final Map myFileChooserUserData = new HashMap(); - private final Computable myLibraryEditor; + private final Computable myLibraryEditorComputable; - private LibraryRootsComponent(@Nullable Project project, @NotNull Computable libraryEditor) { + public LibraryRootsComponent(@Nullable Project project, @NotNull LibraryEditor libraryEditor) { + this(project, new Computable.PredefinedValueComputable(libraryEditor)); + } + + public LibraryRootsComponent(@Nullable Project project, @NotNull Computable libraryEditorComputable) { myProject = project; - myLibraryEditor = libraryEditor; + myLibraryEditorComputable = libraryEditorComputable; + final LibraryEditor editor = getLibraryEditor(); + final LibraryType type = editor.getType(); + if (type != null) { + //noinspection unchecked + myPropertiesEditor = type.createPropertiesEditor(this); + if (myPropertiesEditor != null) { + myPropertiesPanel.add(myPropertiesEditor.createComponent(), BorderLayout.CENTER); + } + } + init(new LibraryTreeStructure(this)); updateProperties(); } + @NotNull + @Override + public LibraryProperties getProperties() { + return getLibraryEditor().getProperties(); + } + private void updateProperties() { StringBuilder text = new StringBuilder(); for (String description : LibraryPresentationManager.getInstance().getDescriptions(getLibraryEditor().getFiles(OrderRootType.CLASSES))) { @@ -116,20 +139,6 @@ public class LibraryRootsComponent implements Disposable { myPropertiesLabel.setText(text.toString()); } - public static LibraryRootsComponent createComponent(final @Nullable Project project, @NotNull LibraryEditor libraryEditor) { - return createComponent(project, new Computable.PredefinedValueComputable(libraryEditor)); - } - - public static LibraryRootsComponent createComponent(final @Nullable Project project, @NotNull Computable libraryEditor) { - LibraryRootsComponent rootsComponent = new LibraryRootsComponent(project, libraryEditor); - rootsComponent.init(new LibraryTreeStructure(rootsComponent)); - return rootsComponent; - } - - public static LibraryRootsComponent createComponent(@NotNull LibraryEditor libraryEditor) { - return createComponent(null, libraryEditor); - } - private void init(AbstractTreeStructure treeStructure) { myTree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode())); myTree.setRootVisible(false); @@ -179,10 +188,13 @@ public class LibraryRootsComponent implements Disposable { } public LibraryEditor getLibraryEditor() { - return myLibraryEditor.compute(); + return myLibraryEditorComputable.compute(); } public boolean hasChanges() { + if (myPropertiesEditor != null && myPropertiesEditor.isModified()) { + return true; + } return getLibraryEditor().hasChanges(); } @@ -229,9 +241,24 @@ public class LibraryRootsComponent implements Disposable { } public void dispose() { + if (myPropertiesEditor != null) { + myPropertiesEditor.disposeUIResources(); + } myTreeBuilder = null; } + public void resetProperties() { + if (myPropertiesEditor != null) { + myPropertiesEditor.reset(); + } + } + + public void applyProperties() { + if (myPropertiesEditor != null && myPropertiesEditor.isModified()) { + myPropertiesEditor.apply(); + } + } + private abstract class AttachItemAction implements ActionListener { private final FileChooserDescriptor myDescriptor; private VirtualFile myLastChosen = null; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java index d4a48d5b0ff0..412e21d0584b 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java @@ -18,12 +18,15 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.impl.libraries.LibraryImpl; import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.libraries.LibraryProperties; +import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.roots.ui.LightFilePointer; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -34,11 +37,30 @@ public class NewLibraryEditor implements LibraryEditor { private String myLibraryName; private final MultiMap myRoots; private final Map myJarDirectories = new HashMap(); + private final LibraryType myType; + private LibraryProperties myProperties; public NewLibraryEditor() { + this(null, null); + } + + public NewLibraryEditor(LibraryType type, LibraryProperties properties) { + myType = type; + myProperties = properties; myRoots = new MultiMap(); } + @Override + @Nullable + public LibraryType getType() { + return myType; + } + + @Override + public LibraryProperties getProperties() { + return myProperties; + } + @Override public String getName() { return myLibraryName; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseLibrariesConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseLibrariesConfigurable.java index 9cba2c8bf01c..ee183fb8372c 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseLibrariesConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseLibrariesConfigurable.java @@ -34,6 +34,7 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.NamedConfigurable; import com.intellij.openapi.ui.TextFieldWithBrowseButton; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; @@ -86,8 +87,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl for (final LibrariesModifiableModel provider : myContext.myLevel2Providers.values()) { isModified |= provider.isChanged(); } - - return isModified; + return isModified || super.isModified(); } public void reset() { @@ -169,13 +169,9 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl protected AbstractAddGroup createAddAction() { return new AbstractAddGroup(getAddText()) { - { - setPopup(false); - } - @NotNull public AnAction[] getChildren(@Nullable final AnActionEvent e) { - return new AnAction[]{new CreateNewLibraryAction(getAddText(), getModelProvider(), myProject)}; + return CreateNewLibraryAction.createActionOrGroup(getAddText(), BaseLibrariesConfigurable.this, myProject); } }; } @@ -186,6 +182,32 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl public abstract BaseLibrariesConfigurable getOppositeGroup(); + @Override + protected void updateSelection(@Nullable NamedConfigurable configurable) { + boolean selectionChanged = !Comparing.equal(myCurrentConfigurable, configurable); + if (myCurrentConfigurable != null && selectionChanged) { + ((LibraryConfigurable)myCurrentConfigurable).onUnselected(); + } + super.updateSelection(configurable); + if (myCurrentConfigurable != null && selectionChanged) { + ((LibraryConfigurable)myCurrentConfigurable).onSelected(); + } + } + + @Override + public void onStructureUnselected() { + if (myCurrentConfigurable != null) { + ((LibraryConfigurable)myCurrentConfigurable).onUnselected(); + } + } + + @Override + public void onStructureSelected() { + if (myCurrentConfigurable != null) { + ((LibraryConfigurable)myCurrentConfigurable).onSelected(); + } + } + protected boolean removeLibrary(final Library library) { final LibraryTable table = library.getTable(); if (table != null) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java index ea570efe6f72..91f15189e5d4 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java @@ -349,6 +349,12 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i return null; } + public void onStructureUnselected() { + } + + public void onStructureSelected() { + } + @Nullable protected abstract AbstractAddGroup createAddAction(); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesModifiableModel.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesModifiableModel.java index bc28567ddda3..bacf018c7c16 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesModifiableModel.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesModifiableModel.java @@ -18,14 +18,17 @@ package com.intellij.openapi.roots.ui.configuration.projectRoot; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.impl.libraries.LibraryImpl; +import com.intellij.openapi.roots.impl.libraries.LibraryTableBase; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; +import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable; import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor; import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor; import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorListener; import com.intellij.openapi.util.Disposer; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -34,7 +37,7 @@ import java.util.*; * Date: 04-Jun-2006 */ -public class LibrariesModifiableModel implements LibraryTable.ModifiableModel { +public class LibrariesModifiableModel implements LibraryTableBase.ModifiableModelEx { private final Map myLibrary2EditorMap = new HashMap(); private final Set myRemovedLibraries = new HashSet(); @@ -50,8 +53,12 @@ public class LibrariesModifiableModel implements LibraryTable.ModifiableModel { } public Library createLibrary(String name) { - final Library library = getLibrariesModifiableModel().createLibrary(name); - //createLibraryEditor(library); + return createLibrary(name, null); + } + + public Library createLibrary(String name, @Nullable LibraryType type) { + final Library library = ((LibraryTableBase.ModifiableModelEx)getLibrariesModifiableModel()).createLibrary(name, type); + //createLibraryEditor(library); \ final BaseLibrariesConfigurable configurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library); configurable.createLibraryNode(library); return library; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibraryConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibraryConfigurable.java index 9630f79dc96a..f98a4eed68d0 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibraryConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibraryConfigurable.java @@ -16,7 +16,6 @@ package com.intellij.openapi.roots.ui.configuration.projectRoot; -import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.libraries.Library; @@ -38,13 +37,14 @@ import javax.swing.*; * Date: 02-Jun-2006 */ public class LibraryConfigurable extends ProjectStructureElementConfigurable { - private LibraryRootsComponent myLibraryEditor; + private LibraryRootsComponent myLibraryEditorComponent; private final Library myLibrary; private final StructureLibraryTableModifiableModelProvider myModel; private final StructureConfigurableContext myContext; private final Project myProject; private final LibraryProjectStructureElement myProjectStructureElement; private boolean myUpdatingName; + private boolean myPropertiesLoaded; protected LibraryConfigurable(final StructureLibraryTableModifiableModelProvider modelProvider, final Library library, @@ -59,23 +59,23 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable() { + myLibraryEditorComponent = new LibraryRootsComponent(myProject, new Computable() { @Override public LibraryEditor compute() { - return myModel.getModifiableModel().getLibraryEditor(myLibrary); + return getLibraryEditor(); } }); final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myProject).getContext(); - myLibraryEditor.addListener(new Runnable() { + myLibraryEditorComponent.addListener(new Runnable() { public void run() { context.getDaemonAnalyzer().queueUpdate(myProjectStructureElement); } }); - return myLibraryEditor.getComponent(); + return myLibraryEditorComponent.getComponent(); } public boolean isModified() { - return myLibraryEditor != null && myLibraryEditor.hasChanges(); + return myLibraryEditorComponent != null && myLibraryEditorComponent.hasChanges(); } @Override @@ -83,18 +83,18 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable type, RootModelImpl rootModel, ProjectRootManagerImpl projectRootManager) { super(rootModel, projectRootManager); - myLibrary = LibraryTableImplUtil.createModuleLevelLibrary(name, getRootModel()); + myLibrary = LibraryTableImplUtil.createModuleLevelLibrary(name, type, getRootModel()); doinit(); } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleLibraryTable.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleLibraryTable.java index 9c7965509bc4..69433ddc691f 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleLibraryTable.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleLibraryTable.java @@ -21,10 +21,12 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.LibraryOrderEntry; import com.intellij.openapi.roots.OrderEntry; +import com.intellij.openapi.roots.impl.libraries.LibraryTableBase; import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.roots.libraries.LibraryTablePresentation; +import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.util.Condition; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ConvertingIterator; @@ -39,7 +41,7 @@ import java.util.Iterator; /** * @author dsl */ -public class ModuleLibraryTable implements LibraryTable, LibraryTable.ModifiableModel { +public class ModuleLibraryTable implements LibraryTable, LibraryTableBase.ModifiableModelEx { private static final ModuleLibraryOrderEntryCondition MODULE_LIBRARY_ORDER_ENTRY_FILTER = new ModuleLibraryOrderEntryCondition(); private static final OrderEntryToLibraryConvertor ORDER_ENTRY_TO_LIBRARY_CONVERTOR = new OrderEntryToLibraryConvertor(); private final RootModelImpl myRootModel; @@ -72,13 +74,16 @@ public class ModuleLibraryTable implements LibraryTable, LibraryTable.Modifiable } public Library createLibrary() { - final ModuleLibraryOrderEntryImpl orderEntry = new ModuleLibraryOrderEntryImpl(myRootModel, myProjectRootManager); - myRootModel.addOrderEntry(orderEntry); - return orderEntry.getLibrary(); + return createLibrary(null); } public Library createLibrary(String name) { - final ModuleLibraryOrderEntryImpl orderEntry = new ModuleLibraryOrderEntryImpl(name, myRootModel, myProjectRootManager); + return createLibrary(name, null); + } + + @Override + public Library createLibrary(String name, @Nullable LibraryType type) { + final ModuleLibraryOrderEntryImpl orderEntry = new ModuleLibraryOrderEntryImpl(name, type, myRootModel, myProjectRootManager); myRootModel.addOrderEntry(orderEntry); return orderEntry.getLibrary(); } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryEx.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryEx.java index 3bcdb4830174..839ee0b2b79e 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryEx.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryEx.java @@ -19,6 +19,8 @@ package com.intellij.openapi.roots.impl.libraries; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.impl.RootModelImpl; import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.libraries.LibraryProperties; +import com.intellij.openapi.roots.libraries.LibraryType; /** * @author dsl @@ -30,7 +32,15 @@ public interface LibraryEx extends Library { boolean isDisposed(); + LibraryType getType(); + + LibraryProperties getProperties(); + interface ModifiableModelEx extends ModifiableModel { boolean allPathsValid(OrderRootType type); + + void setProperties(LibraryProperties properties); + + LibraryProperties getProperties(); } } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java index dbe49e5317ce..d3e6aa18ffad 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java @@ -93,10 +93,14 @@ public class LibraryImpl implements LibraryEx.ModifiableModelEx, LibraryEx { updateWatchedRoots(); } - LibraryImpl(String name, LibraryTable table, ModifiableRootModel rootModel) { + LibraryImpl(String name, final @Nullable LibraryType type, LibraryTable table, ModifiableRootModel rootModel) { myName = name; myLibraryTable = table; myRootModel = rootModel; + myType = type; + if (type != null) { + myProperties = type.createDefaultProperties(); + } myRoots = initRoots(); mySource = null; } @@ -105,6 +109,12 @@ public class LibraryImpl implements LibraryEx.ModifiableModelEx, LibraryEx { assert !from.isDisposed(); myRootModel = rootModel; myName = from.myName; + myType = from.myType; + if (from.myType != null && from.myProperties != null) { + myProperties = myType.createDefaultProperties(); + //noinspection unchecked + myProperties.loadState(from.myProperties.getState()); + } myRoots = initRoots(); mySource = newSource; myLibraryTable = from.myLibraryTable; @@ -204,6 +214,12 @@ public class LibraryImpl implements LibraryEx.ModifiableModelEx, LibraryEx { return true; } + @Override + public void setProperties(LibraryProperties properties) { + LOG.assertTrue(isWritable()); + myProperties = properties; + } + @NotNull public RootProvider getRootProvider() { return myRootProvider; @@ -241,9 +257,11 @@ public class LibraryImpl implements LibraryEx.ModifiableModelEx, LibraryEx { myProperties = myType.createDefaultProperties(); final Element propertiesElement = element.getChild(PROPERTIES_ELEMENT); - final Class stateClass = ReflectionUtil.getRawType(ReflectionUtil.resolveVariableInHierarchy(PersistentStateComponent.class.getTypeParameters()[0], myProperties.getClass())); - //noinspection unchecked - myProperties.loadState(XmlSerializer.deserialize(propertiesElement, stateClass)); + if (propertiesElement != null) { + final Class stateClass = ReflectionUtil.getRawType(ReflectionUtil.resolveVariableInHierarchy(PersistentStateComponent.class.getTypeParameters()[0], myProperties.getClass())); + //noinspection unchecked + myProperties.loadState(XmlSerializer.deserialize(propertiesElement, stateClass)); + } } private void readName(Element element) { @@ -318,6 +336,16 @@ public class LibraryImpl implements LibraryEx.ModifiableModelEx, LibraryEx { return mySource != null; } + @Override + public LibraryType getType() { + return myType; + } + + @Override + public LibraryProperties getProperties() { + return myProperties; + } + public void addRoot(@NotNull String url, @NotNull OrderRootType rootType) { LOG.assertTrue(isWritable()); assert !isDisposed(); @@ -436,6 +464,7 @@ public class LibraryImpl implements LibraryEx.ModifiableModelEx, LibraryEx { ((LibraryTableBase)myLibraryTable).fireLibraryRenamed(this); } } + myProperties = fromModel.myProperties; if (areRootsChanged(fromModel)) { disposeMyPointers(); copyRootsFrom(fromModel); @@ -580,6 +609,8 @@ public class LibraryImpl implements LibraryEx.ModifiableModelEx, LibraryEx { if (!myJarDirectories.equals(library.myJarDirectories)) return false; if (myName != null ? !myName.equals(library.myName) : library.myName != null) return false; if (myRoots != null ? !myRoots.equals(library.myRoots) : library.myRoots != null) return false; + if (myType != null ? !myType.equals(library.myType) : library.myType != null) return false; + if (myProperties != null ? !myProperties.equals(library.myProperties) : library.myProperties != null) return false; return true; } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryTableBase.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryTableBase.java index 8be96385eed4..ab579a6d437b 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryTableBase.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryTableBase.java @@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; +import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.util.*; import com.intellij.util.EventDispatcher; import com.intellij.util.containers.ContainerUtil; @@ -175,7 +176,11 @@ public abstract class LibraryTableBase implements PersistentStateComponent myLibraries = new ArrayList(); private boolean myWritable; @@ -207,7 +212,7 @@ public abstract class LibraryTableBase implements PersistentStateComponent type, + RootModelImpl rootModel) { + return new LibraryImpl(name, type, null, rootModel); } } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryTypeRegistryImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryTypeRegistryImpl.java new file mode 100644 index 000000000000..4ebe3f56f39e --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryTypeRegistryImpl.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.impl.libraries; + +import com.intellij.openapi.roots.libraries.LibraryType; +import com.intellij.openapi.roots.libraries.LibraryTypeRegistry; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author nik + */ +public class LibraryTypeRegistryImpl extends LibraryTypeRegistry { + + @Nullable + public LibraryType findTypeById(@NotNull String typeId) { + for (LibraryType type : LibraryType.EP_NAME.getExtensions()) { + if (type.getKind().getKindId().equals(typeId)) { + return type; + } + } + return null; + } +} diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/DummyLibraryProperties.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/DummyLibraryProperties.java index a3a798835b06..2c8065841a51 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/DummyLibraryProperties.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/DummyLibraryProperties.java @@ -29,4 +29,14 @@ public class DummyLibraryProperties extends LibraryProperties { @Override public void loadState(Object state) { } + + @Override + public boolean equals(Object obj) { + return obj instanceof DummyLibraryProperties; + } + + @Override + public int hashCode() { + return 0; + } } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryProperties.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryProperties.java index f627a0d3326f..3f6008551ef5 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryProperties.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryProperties.java @@ -21,4 +21,9 @@ import com.intellij.openapi.components.PersistentStateComponent; * @author nik */ public abstract class LibraryProperties implements PersistentStateComponent { + @Override + public abstract boolean equals(Object obj); + + @Override + public abstract int hashCode(); } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryType.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryType.java new file mode 100644 index 000000000000..e25b81fa6bea --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryType.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.libraries; + +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent; +import com.intellij.openapi.roots.libraries.ui.LibraryPropertiesEditor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author nik + */ +public abstract class LibraryType

extends LibraryPresentationProvider

{ + public static final ExtensionPointName> EP_NAME = ExtensionPointName.create("com.intellij.library.type"); + + protected LibraryType(@NotNull LibraryKind

libraryKind) { + super(libraryKind); + } + + @NotNull + public abstract String getCreateActionName(); + + @NotNull + public abstract P createDefaultProperties(); + + @Nullable + public abstract LibraryPropertiesEditor createPropertiesEditor(@NotNull LibraryEditorComponent

properties); +} diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryTypeRegistry.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryTypeRegistry.java new file mode 100644 index 000000000000..70074a9895aa --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryTypeRegistry.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.libraries; + +import com.intellij.openapi.components.ServiceManager; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author nik + */ +public abstract class LibraryTypeRegistry { + public static LibraryTypeRegistry getInstance() { + return ServiceManager.getService(LibraryTypeRegistry.class); + } + + @Nullable + public abstract LibraryType findTypeById(@NotNull String typeId); +} diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/LibraryEditorComponent.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/LibraryEditorComponent.java new file mode 100644 index 000000000000..5dbe42f8ae0f --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/LibraryEditorComponent.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.libraries.ui; + +import com.intellij.openapi.roots.libraries.LibraryProperties; +import org.jetbrains.annotations.NotNull; + +/** + * @author nik + */ +public interface LibraryEditorComponent

{ + @NotNull + P getProperties(); +} diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/LibraryPropertiesEditor.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/LibraryPropertiesEditor.java new file mode 100644 index 000000000000..601bff79236b --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/LibraryPropertiesEditor.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.libraries.ui; + +import com.intellij.openapi.options.UnnamedConfigurable; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author nik + */ +public abstract class LibraryPropertiesEditor implements UnnamedConfigurable { + @NotNull + public abstract JComponent createComponent(); + + @Override + public abstract void apply(); + + public void disposeUIResources() { + } +} diff --git a/platform/lang-impl/src/com/intellij/util/ui/classpath/SimpleClasspathPanel.java b/platform/lang-impl/src/com/intellij/util/ui/classpath/SimpleClasspathPanel.java index 23a7247ea746..58efc5cfa7d9 100644 --- a/platform/lang-impl/src/com/intellij/util/ui/classpath/SimpleClasspathPanel.java +++ b/platform/lang-impl/src/com/intellij/util/ui/classpath/SimpleClasspathPanel.java @@ -176,7 +176,7 @@ public class SimpleClasspathPanel extends JPanel { final ArrayList result = new ArrayList(); for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) { if (!existingFiles.add(file)) continue; - final Library newLibrary = LibraryTableImplUtil.createModuleLevelLibrary(null, null); + final Library newLibrary = LibraryTableImplUtil.createModuleLevelLibrary(null, null, null); Disposer.register(parentDisposable, newLibrary); final Library.ModifiableModel libModel = newLibrary.getModifiableModel(); libModel.addRoot(file, OrderRootType.CLASSES); @@ -387,7 +387,7 @@ public class SimpleClasspathPanel extends JPanel { } final List addedLibraries = new ArrayList(files.length); for (VirtualFile file : files) { - final Library library = LibraryTableImplUtil.createModuleLevelLibrary(null, null); + final Library library = LibraryTableImplUtil.createModuleLevelLibrary(null, null, null); Disposer.register(myParentDisposable, library); final Library.ModifiableModel libModel = library.getModifiableModel(); libModel.addRoot(file, OrderRootType.CLASSES); @@ -410,7 +410,7 @@ public class SimpleClasspathPanel extends JPanel { result.add(library); } else { - final Library newLibrary = LibraryTableImplUtil.createModuleLevelLibrary(null, null); + final Library newLibrary = LibraryTableImplUtil.createModuleLevelLibrary(null, null, null); Disposer.register(disposable, newLibrary); final Library.ModifiableModel libModel = newLibrary.getModifiableModel(); final String libName = classpathElement.getLibraryName(); diff --git a/platform/platform-resources-en/src/messages/ProjectBundle.properties b/platform/platform-resources-en/src/messages/ProjectBundle.properties index 2412db92b7d6..b60760cca9e6 100644 --- a/platform/platform-resources-en/src/messages/ProjectBundle.properties +++ b/platform/platform-resources-en/src/messages/ProjectBundle.properties @@ -211,12 +211,10 @@ module.toggle.sources.action.description=Mark directory as a Sources root library.classes.node=Classes library.javadocs.node=JavaDocs library.empty.item= -library.name.prompt=Library name: library.name.not.specified.error=Please enter library name library.name.not.specified.title=Library Name Not Specified library.name.already.exists.error=Library \"{0}\" already exists library.name.already.exists.title=Library Already Exists -library.create.library.action=Create &Library... classpath.add.new.library.action=New Library... classpath.add.simple.module.library.action=Single-Entry Module Library... classpath.add.library.action=Library... diff --git a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml index 40464eccfcfe..9a9ef3ebd0db 100644 --- a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml @@ -277,6 +277,7 @@ + diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index f8a66fb0c350..ff5b7a9cd749 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -116,6 +116,9 @@ + + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyLibraryProperties.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyLibraryProperties.java index df1b9d63fb71..8670170a90cd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyLibraryProperties.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyLibraryProperties.java @@ -16,6 +16,7 @@ package org.jetbrains.plugins.groovy.config; import com.intellij.openapi.roots.libraries.LibraryProperties; +import com.intellij.openapi.util.Comparing; import org.jetbrains.annotations.Nullable; /** @@ -41,4 +42,14 @@ public class GroovyLibraryProperties extends LibraryProperties