library types

This commit is contained in:
nik
2010-10-20 12:23:24 +04:00
parent 13734c2cfe
commit e23ceb0916
36 changed files with 544 additions and 121 deletions
@@ -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());
}
@@ -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;
@@ -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;
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryRootsComponent">
<grid id="e9129" binding="myPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="6" vgap="-1">
<grid id="e9129" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="6" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="91" y="83" width="403" height="352"/>
@@ -11,7 +11,7 @@
<grid id="1f4da" layout-manager="GridLayoutManager" row-count="9" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="0" vgap="6">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@@ -90,7 +90,7 @@
<xy id="bc98" binding="myTreePanel" layout-manager="XYLayout" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="300" height="-1"/>
</grid>
</constraints>
@@ -104,6 +104,14 @@
</constraints>
<properties/>
</component>
<grid id="19827" binding="myPropertiesPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</form>
@@ -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();
}
}
@@ -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<Icon> icons = getCustomIcons(library, context);
if (icons.size() == 1) {
return icons.get(0);
@@ -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<Module> choosenModules = dlg.getChosenElements();
for (Module module : choosenModules) {
final List<Module> 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<AnAction> actions = new ArrayList<AnAction>();
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()]);
}
}
@@ -44,7 +44,7 @@ public class CreateNewLibraryDialog extends LibraryEditorDialogBase {
public CreateNewLibraryDialog(@NotNull JComponent parent, @Nullable Project project, @NotNull NewLibraryEditor libraryEditor,
@NotNull List<LibraryTable> 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) {
@@ -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;
@@ -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
@@ -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();
}
@@ -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;
}
@@ -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<DataKey, Object> myFileChooserUserData = new HashMap<DataKey, Object>();
private final Computable<LibraryEditor> myLibraryEditor;
private final Computable<LibraryEditor> myLibraryEditorComputable;
private LibraryRootsComponent(@Nullable Project project, @NotNull Computable<LibraryEditor> libraryEditor) {
public LibraryRootsComponent(@Nullable Project project, @NotNull LibraryEditor libraryEditor) {
this(project, new Computable.PredefinedValueComputable<LibraryEditor>(libraryEditor));
}
public LibraryRootsComponent(@Nullable Project project, @NotNull Computable<LibraryEditor> 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>(libraryEditor));
}
public static LibraryRootsComponent createComponent(final @Nullable Project project, @NotNull Computable<LibraryEditor> 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;
@@ -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<OrderRootType, LightFilePointer> myRoots;
private final Map<String, Boolean> myJarDirectories = new HashMap<String, Boolean>();
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<OrderRootType, LightFilePointer>();
}
@Override
@Nullable
public LibraryType getType() {
return myType;
}
@Override
public LibraryProperties getProperties() {
return myProperties;
}
@Override
public String getName() {
return myLibraryName;
@@ -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) {
@@ -349,6 +349,12 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i
return null;
}
public void onStructureUnselected() {
}
public void onStructureSelected() {
}
@Nullable
protected abstract AbstractAddGroup createAddAction();
@@ -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<Library, ExistingLibraryEditor> myLibrary2EditorMap = new HashMap<Library, ExistingLibraryEditor>();
private final Set<Library> myRemovedLibraries = new HashSet<Library>();
@@ -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;
@@ -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<Library> {
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<Lib
}
public JComponent createOptionsPanel() {
myLibraryEditor = LibraryRootsComponent.createComponent(myProject, new Computable<LibraryEditor>() {
myLibraryEditorComponent = new LibraryRootsComponent(myProject, new Computable<LibraryEditor>() {
@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<Lib
return myProjectStructureElement;
}
public void apply() throws ConfigurationException {
//do nothing
public void apply() {
applyProperties();
}
public void reset() {
//do nothing
resetProperties();
}
public void disposeUIResources() {
if (myLibraryEditor != null) {
Disposer.dispose(myLibraryEditor);
myLibraryEditor = null;
if (myLibraryEditorComponent != null) {
Disposer.dispose(myLibraryEditorComponent);
myLibraryEditorComponent = null;
}
}
@@ -140,6 +140,28 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
return myLibrary.getName();
}
public void onSelected() {
resetProperties();
}
public void onUnselected() {
applyProperties();
}
private void resetProperties() {
if (myLibraryEditorComponent != null) {
myLibraryEditorComponent.resetProperties();
myPropertiesLoaded = true;
}
}
private void applyProperties() {
if (myLibraryEditorComponent != null && myPropertiesLoaded) {
myLibraryEditorComponent.applyProperties();
myPropertiesLoaded = false;
}
}
public Icon getIcon() {
return LibraryPresentationManager.getInstance().getNamedLibraryIcon(myLibrary, myContext);
}