mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
separate dialogs for choosing existing library and adding a new one
This commit is contained in:
@@ -16,9 +16,7 @@
|
||||
package com.intellij.facet.impl.ui.libraries;
|
||||
|
||||
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.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
@@ -43,28 +41,7 @@ public class EditLibraryDialog extends DialogWrapper {
|
||||
mySettings = settings;
|
||||
final Library library = settings.getOrCreateLibrary();
|
||||
|
||||
myLibraryTableEditor = LibraryTableEditor.editLibrary(new LibraryTableModifiableModelProvider() {
|
||||
|
||||
@Override
|
||||
public LibraryTable.ModifiableModel getModifiableModel() {
|
||||
return library.getTable().getModifiableModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableLevel() {
|
||||
return library.getTable().getTableLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibraryTablePresentation getLibraryTablePresentation() {
|
||||
return library.getTable().getPresentation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLibraryTableEditable() {
|
||||
return false;
|
||||
}
|
||||
}, library);
|
||||
myLibraryTableEditor = LibraryTableEditor.editLibrary(new ExistingLibraryEditor(library, null));
|
||||
|
||||
Disposer.register(getDisposable(), myLibraryTableEditor);
|
||||
|
||||
|
||||
+10
-26
@@ -8,7 +8,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="1f4da" layout-manager="GridLayoutManager" row-count="11" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="0" vgap="6">
|
||||
<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="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@@ -16,17 +16,9 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="9f375" class="javax.swing.JButton" binding="myAddLibraryButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="module.libraries.add.button"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f673d" class="javax.swing.JButton" binding="myAttachClassesButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="module.libraries.attach.classes.button"/>
|
||||
@@ -34,12 +26,12 @@
|
||||
</component>
|
||||
<vspacer id="3da7">
|
||||
<constraints>
|
||||
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="86446" class="javax.swing.JButton" binding="myAttachSourcesButton">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="module.libraries.attach.sources.button"/>
|
||||
@@ -47,7 +39,7 @@
|
||||
</component>
|
||||
<component id="733a5" class="javax.swing.JButton" binding="myAttachJavadocsButton">
|
||||
<constraints>
|
||||
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="module.libraries.javadoc.attach.button"/>
|
||||
@@ -55,7 +47,7 @@
|
||||
</component>
|
||||
<component id="56f78" class="javax.swing.JButton" binding="myRemoveButton">
|
||||
<constraints>
|
||||
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="library.detach.action"/>
|
||||
@@ -63,23 +55,15 @@
|
||||
</component>
|
||||
<component id="47ce1" class="javax.swing.JButton" binding="myAttachUrlJavadocsButton">
|
||||
<constraints>
|
||||
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="module.libraries.javadoc.url.button"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="16495" class="javax.swing.JButton" binding="myRenameLibraryButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="module.libraries.rename.button"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3a1fb" class="javax.swing.JButton" binding="myAttachJarDirectoriesButton">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="module.libraries.attach.jar.directories.button"/>
|
||||
@@ -87,7 +71,7 @@
|
||||
</component>
|
||||
<component id="79b4b" class="javax.swing.JButton" binding="myAttachAnnotationsButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="attach.annotations.button"/>
|
||||
@@ -95,7 +79,7 @@
|
||||
</component>
|
||||
<component id="1134d" class="javax.swing.JButton" binding="myAttachMoreButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="module.libraries.attach.more.button"/>
|
||||
|
||||
-6
@@ -16,15 +16,9 @@
|
||||
package com.intellij.openapi.roots.ui.configuration;
|
||||
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablePresentation;
|
||||
|
||||
public interface LibraryTableModifiableModelProvider {
|
||||
|
||||
LibraryTable.ModifiableModel getModifiableModel();
|
||||
|
||||
String getTableLevel();
|
||||
|
||||
LibraryTablePresentation getLibraryTablePresentation();
|
||||
|
||||
boolean isLibraryTableEditable();
|
||||
}
|
||||
|
||||
@@ -409,7 +409,7 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private class LibraryTableInvocationHandler implements InvocationHandler {
|
||||
private class LibraryTableInvocationHandler implements InvocationHandler, ProxyDelegateAccessor {
|
||||
private final LibraryTable myDelegateTable;
|
||||
@NonNls private final Set<String> myCheckedNames = new HashSet<String>(Arrays.asList("removeLibrary" /*,"createLibrary"*/));
|
||||
|
||||
@@ -450,6 +450,10 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDelegate() {
|
||||
return myDelegateTable;
|
||||
}
|
||||
}
|
||||
|
||||
private class LibraryInvocationHandler implements InvocationHandler, ProxyDelegateAccessor {
|
||||
@@ -478,7 +482,7 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private class LibraryModifiableModelInvocationHandler implements InvocationHandler {
|
||||
private class LibraryModifiableModelInvocationHandler implements InvocationHandler, ProxyDelegateAccessor {
|
||||
private final Library.ModifiableModel myDelegateModel;
|
||||
|
||||
LibraryModifiableModelInvocationHandler(Library.ModifiableModel delegateModel) {
|
||||
@@ -499,9 +503,14 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDelegate() {
|
||||
return myDelegateModel;
|
||||
}
|
||||
}
|
||||
|
||||
private class LibraryTableModelInvocationHandler implements InvocationHandler {
|
||||
private class LibraryTableModelInvocationHandler implements InvocationHandler, ProxyDelegateAccessor {
|
||||
private final LibraryTable.ModifiableModel myDelegateModel;
|
||||
|
||||
LibraryTableModelInvocationHandler(LibraryTable.ModifiableModel delegateModel) {
|
||||
@@ -537,6 +546,11 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDelegate() {
|
||||
return myDelegateModel;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ProxyDelegateAccessor {
|
||||
|
||||
+1
-3
@@ -74,9 +74,7 @@ abstract class AddItemPopupAction<ItemType> extends ClasspathPanelAction {
|
||||
myClasspathPanel.addItems(toAdd);
|
||||
}
|
||||
finally {
|
||||
if (dialog instanceof ChooseNamedLibraryAction.MyChooserDialog) {
|
||||
Disposer.dispose(dialog);
|
||||
}
|
||||
Disposer.dispose(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-24
@@ -21,11 +21,10 @@ import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.util.Icons;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
@@ -33,15 +32,13 @@ import java.util.*;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class ChooseNamedLibraryAction extends AddItemPopupAction<Library> {
|
||||
private final LibraryTableModifiableModelProvider myLibraryTableModelProvider;
|
||||
class ChooseExistingLibraryAction extends AddItemPopupAction<Library> {
|
||||
private StructureConfigurableContext myContext;
|
||||
|
||||
public ChooseNamedLibraryAction(ClasspathPanel classpathPanel,
|
||||
final int index,
|
||||
final String title,
|
||||
final LibraryTableModifiableModelProvider libraryTable) {
|
||||
public ChooseExistingLibraryAction(ClasspathPanel classpathPanel, final int index, final String title,
|
||||
final StructureConfigurableContext context) {
|
||||
super(classpathPanel, index, title, Icons.LIBRARY_ICON);
|
||||
myLibraryTableModelProvider = libraryTable;
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -76,7 +73,7 @@ class ChooseNamedLibraryAction extends AddItemPopupAction<Library> {
|
||||
if (orderEntry instanceof LibraryOrderEntry && orderEntry.isValid()) {
|
||||
final LibraryImpl library = (LibraryImpl)((LibraryOrderEntry)orderEntry).getLibrary();
|
||||
if (library != null) {
|
||||
result.add(library.getSource());
|
||||
ContainerUtil.addIfNotNull(result, library.getSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,27 +81,21 @@ class ChooseNamedLibraryAction extends AddItemPopupAction<Library> {
|
||||
}
|
||||
|
||||
class MyChooserDialog implements ClasspathElementChooserDialog<Library> {
|
||||
private final LibraryTableEditor myEditor;
|
||||
private Library[] myLibraries;
|
||||
|
||||
MyChooserDialog(){
|
||||
myEditor = LibraryTableEditor.editLibraryTable(myLibraryTableModelProvider, myClasspathPanel.getProject());
|
||||
Disposer.register(this, myEditor);
|
||||
}
|
||||
private List<Library> mySelectedLibraries;
|
||||
|
||||
public List<Library> getChosenElements() {
|
||||
final List<Library> chosen = new ArrayList<Library>(Arrays.asList(myLibraries));
|
||||
chosen.removeAll(getAlreadyAddedLibraries());
|
||||
return chosen;
|
||||
return mySelectedLibraries;
|
||||
}
|
||||
|
||||
public void doChoose() {
|
||||
final Iterator iter = myLibraryTableModelProvider.getModifiableModel().getLibraryIterator();
|
||||
myLibraries = myEditor.openDialog(myClasspathPanel.getComponent(), iter.hasNext()? Collections.singleton((Library)iter.next()) : Collections.<Library>emptyList(), false);
|
||||
ProjectStructureChooseLibrariesDialog dialog = new ProjectStructureChooseLibrariesDialog(myClasspathPanel.getComponent(), myClasspathPanel.getProject(), myContext,
|
||||
getAlreadyAddedLibraries());
|
||||
dialog.show();
|
||||
mySelectedLibraries = dialog.getSelectedLibraries();
|
||||
}
|
||||
|
||||
public boolean isOK() {
|
||||
return myLibraries != null;
|
||||
return mySelectedLibraries != null && !mySelectedLibraries.isEmpty();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
+14
-31
@@ -27,14 +27,13 @@ import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.*;
|
||||
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.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
|
||||
import com.intellij.openapi.roots.ui.configuration.dependencyAnalysis.AnalyzeDependenciesDialog;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ChooseModulesDialog;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.EditExistingLibraryDialog;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.FindUsagesInProjectStructureActionBase;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
|
||||
@@ -65,8 +64,10 @@ import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.classpath.ClasspathPanel");
|
||||
@@ -381,25 +382,14 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
return moduleLibraryTable.getModifiableModel();
|
||||
}
|
||||
|
||||
public String getTableLevel() {
|
||||
return moduleLibraryTable.getTableLevel();
|
||||
}
|
||||
|
||||
public LibraryTablePresentation getLibraryTablePresentation() {
|
||||
return moduleLibraryTable.getPresentation();
|
||||
}
|
||||
|
||||
public boolean isLibraryTableEditable() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
provider = ProjectStructureConfigurable.getInstance(myState.getProject()).getContext().createModifiableModelProvider(table.getTableLevel(), false);
|
||||
provider = ProjectStructureConfigurable.getInstance(myState.getProject()).getContext().createModifiableModelProvider(table.getTableLevel());
|
||||
}
|
||||
final LibraryTableEditor editor = LibraryTableEditor.editLibrary(provider, library, myState.getProject());
|
||||
editor.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, getRootModel().getModule());
|
||||
editor.openDialog(ClasspathPanelImpl.this, Collections.singletonList(library), true);
|
||||
EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(ClasspathPanelImpl.this, provider, library, myState.getProject());
|
||||
dialog.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, getRootModel().getModule());
|
||||
dialog.show();
|
||||
myEntryTable.repaint();
|
||||
ModuleStructureConfigurable.getInstance(myState.getProject()).getTree().repaint();
|
||||
}
|
||||
@@ -488,11 +478,12 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
}
|
||||
|
||||
protected ClasspathElementChooserDialog<Library> createChooserDialog() {
|
||||
return new ChooseModuleLibrariesDialog(ClasspathPanelImpl.this, getRootModel().getModuleLibraryTable(), null);
|
||||
final LibraryTable.ModifiableModel moduleLibraryModel = getRootModel().getModuleLibraryTable().getModifiableModel();
|
||||
return new CreateSingleEntryModuleLibraryDialog(ClasspathPanelImpl.this, moduleLibraryModel);
|
||||
}
|
||||
});
|
||||
actions.add(
|
||||
new AddItemPopupAction<Library>(this, actionIndex++, ProjectBundle.message("classpath.add.module.library.action"), Icons.JAR_ICON) {
|
||||
new AddItemPopupAction<Library>(this, actionIndex++, ProjectBundle.message("classpath.add.new.library.action"), Icons.LIBRARY_ICON) {
|
||||
protected ClasspathTableItem createTableItem(final Library item) {
|
||||
final OrderEntry[] entries = getRootModel().getOrderEntries();
|
||||
for (OrderEntry entry : entries) {
|
||||
@@ -503,22 +494,14 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG.error("Unknown library " + item);
|
||||
return null;
|
||||
return ClasspathTableItem.createLibItem(getRootModel().addLibraryEntry(item));
|
||||
}
|
||||
|
||||
protected ClasspathElementChooserDialog<Library> createChooserDialog() {
|
||||
return new CreateModuleLibraryDialog(ClasspathPanelImpl.this, getRootModel().getModuleLibraryTable());
|
||||
return new CreateLibraryDialog(ClasspathPanelImpl.this.getProject(), getRootModel(), context, ClasspathPanelImpl.this.getComponent());
|
||||
}
|
||||
});
|
||||
actions.add(new ChooseNamedLibraryAction(this, actionIndex++, ProjectBundle.message("classpath.add.project.library.action"),
|
||||
context.getProjectLibrariesProvider(true)));
|
||||
actions.add(new ChooseNamedLibraryAction(this, actionIndex++, ProjectBundle.message("classpath.add.global.library.action"),
|
||||
context.getGlobalLibrariesProvider(true)));
|
||||
|
||||
for (final LibraryTableModifiableModelProvider provider : context.getCustomLibrariesProviders(true)) {
|
||||
actions.add(new ChooseNamedLibraryAction(this, actionIndex++, provider.getLibraryTablePresentation().getDisplayName(false) + "...", provider));
|
||||
}
|
||||
actions.add(new ChooseExistingLibraryAction(this, actionIndex++, ProjectBundle.message("classpath.add.existing.library.action"), context));
|
||||
|
||||
actions.add(new AddItemPopupAction<Module>(this, actionIndex, ProjectBundle.message("classpath.add.module.dependency.action"),
|
||||
StdModuleTypes.JAVA.getNodeIcon(false)) {
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.ui.configuration.classpath;
|
||||
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.DataKeys;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.CreateNewLibraryDialog;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class CreateLibraryDialog implements ClasspathElementChooserDialog<Library> {
|
||||
private boolean myIsOk;
|
||||
private final ModifiableRootModel myRootModel;
|
||||
private Library myChosenLibrary;
|
||||
private StructureConfigurableContext myContext;
|
||||
private final JComponent myParentComponent;
|
||||
private final Project myProject;
|
||||
|
||||
public CreateLibraryDialog(final Project project,
|
||||
final ModifiableRootModel rootModel,
|
||||
StructureConfigurableContext context, final JComponent parentComponent) {
|
||||
myRootModel = rootModel;
|
||||
myContext = context;
|
||||
myParentComponent = parentComponent;
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
public List<Library> getChosenElements() {
|
||||
return myChosenLibrary == null? Collections.<Library>emptyList() : Collections.singletonList(myChosenLibrary);
|
||||
}
|
||||
|
||||
public void doChoose() {
|
||||
final LibraryTablesRegistrar registrar = LibraryTablesRegistrar.getInstance();
|
||||
List<LibraryTable> tables = Arrays.asList(myRootModel.getModuleLibraryTable(),
|
||||
registrar.getLibraryTable(myProject),
|
||||
registrar.getLibraryTable());
|
||||
CreateNewLibraryDialog dialog = CreateNewLibraryDialog.createDialog(myParentComponent, myProject, this, tables, 1);
|
||||
final Module contextModule = DataKeys.MODULE_CONTEXT.getData(DataManager.getInstance().getDataContext(myParentComponent));
|
||||
dialog.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, contextModule);
|
||||
dialog.show();
|
||||
myIsOk = dialog.isOK();
|
||||
if (myIsOk) {
|
||||
myChosenLibrary = dialog.createLibrary(myContext.getModifiableLibraryTable(dialog.getSelectedTable()));
|
||||
}
|
||||
else {
|
||||
myChosenLibrary = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOK() {
|
||||
return myIsOk;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* 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.ui.configuration.classpath;
|
||||
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.DataKeys;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.module.Module;
|
||||
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.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class CreateModuleLibraryDialog implements ClasspathElementChooserDialog<Library> {
|
||||
private boolean myIsOk;
|
||||
private final ClasspathPanel myClasspathPanel;
|
||||
private final LibraryTable myLibraryTable;
|
||||
private Library myChosenLibrary;
|
||||
|
||||
public CreateModuleLibraryDialog(ClasspathPanel classpathPanel, final LibraryTable libraryTable) {
|
||||
myClasspathPanel = classpathPanel;
|
||||
myLibraryTable = libraryTable;
|
||||
}
|
||||
|
||||
public List<Library> getChosenElements() {
|
||||
return myChosenLibrary == null? Collections.<Library>emptyList() : Collections.singletonList(myChosenLibrary);
|
||||
}
|
||||
|
||||
public void doChoose() {
|
||||
final LibraryTable.ModifiableModel libraryModifiableModel = myLibraryTable.getModifiableModel();
|
||||
final LibraryTableModifiableModelProvider provider = new LibraryTableModifiableModelProvider() {
|
||||
public LibraryTable.ModifiableModel getModifiableModel() {
|
||||
return libraryModifiableModel;
|
||||
}
|
||||
|
||||
public String getTableLevel() {
|
||||
return myLibraryTable.getTableLevel();
|
||||
}
|
||||
|
||||
public LibraryTablePresentation getLibraryTablePresentation() {
|
||||
return myLibraryTable.getPresentation();
|
||||
}
|
||||
|
||||
public boolean isLibraryTableEditable() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
final Library library = myLibraryTable.createLibrary();
|
||||
final LibraryTableEditor editor = LibraryTableEditor.editLibrary(provider, library, myClasspathPanel.getProject());
|
||||
final Module contextModule = DataKeys.MODULE_CONTEXT.getData(DataManager.getInstance().getDataContext(myClasspathPanel.getComponent()));
|
||||
editor.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, contextModule);
|
||||
myIsOk = editor.openDialog(myClasspathPanel.getComponent(), Collections.singletonList(library), true) != null;
|
||||
if (myIsOk) {
|
||||
myChosenLibrary = library;
|
||||
}
|
||||
else {
|
||||
myChosenLibrary = null;
|
||||
libraryModifiableModel.removeLibrary(library);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOK() {
|
||||
return myIsOk;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
+28
-20
@@ -17,34 +17,33 @@ package com.intellij.openapi.roots.ui.configuration.classpath;
|
||||
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
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.ui.configuration.libraryEditor.LibraryFileChooser;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.List;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class ChooseModuleLibrariesDialog extends LibraryFileChooser implements ClasspathElementChooserDialog<Library> {
|
||||
private Pair<String, VirtualFile[]> myLastChosen;
|
||||
private final LibraryTable myLibraryTable;
|
||||
@Nullable private final VirtualFile myFileToSelect;
|
||||
class CreateSingleEntryModuleLibraryDialog implements ClasspathElementChooserDialog<Library> {
|
||||
private ClasspathPanel myClasspathPanel;
|
||||
private final LibraryTable.ModifiableModel myModuleLibrariesModel;
|
||||
private VirtualFile[] myChosenFiles;
|
||||
|
||||
public ChooseModuleLibrariesDialog(Component parent, final LibraryTable libraryTable, final VirtualFile fileToSelect) {
|
||||
super(createFileChooserDescriptor(parent), parent, false, null);
|
||||
myLibraryTable = libraryTable;
|
||||
myFileToSelect = fileToSelect;
|
||||
public CreateSingleEntryModuleLibraryDialog(ClasspathPanel classpathPanel,
|
||||
final LibraryTable.ModifiableModel moduleLibrariesModel) {
|
||||
myClasspathPanel = classpathPanel;
|
||||
myModuleLibrariesModel = moduleLibrariesModel;
|
||||
}
|
||||
|
||||
private static FileChooserDescriptor createFileChooserDescriptor(Component parent) {
|
||||
@@ -54,18 +53,17 @@ class ChooseModuleLibrariesDialog extends LibraryFileChooser implements Classpat
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public java.util.List<Library> getChosenElements() {
|
||||
if (myLastChosen == null) {
|
||||
public List<Library> getChosenElements() {
|
||||
if (myChosenFiles == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final VirtualFile[] files = filterAlreadyAdded(myLastChosen.getSecond());
|
||||
final VirtualFile[] files = filterAlreadyAdded(myChosenFiles);
|
||||
if (files.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final LibraryTable.ModifiableModel modifiableModel = myLibraryTable.getModifiableModel();
|
||||
final java.util.List<Library> addedLibraries = new ArrayList<Library>(files.length);
|
||||
final List<Library> addedLibraries = new ArrayList<Library>(files.length);
|
||||
for (VirtualFile file : files) {
|
||||
final Library library = modifiableModel.createLibrary(null);
|
||||
final Library library = myModuleLibrariesModel.createLibrary(null);
|
||||
final Library.ModifiableModel libModel = library.getModifiableModel();
|
||||
libModel.addRoot(file, OrderRootType.CLASSES);
|
||||
libModel.commit();
|
||||
@@ -80,7 +78,7 @@ class ChooseModuleLibrariesDialog extends LibraryFileChooser implements Classpat
|
||||
}
|
||||
final Set<VirtualFile> chosenFilesSet = new HashSet<VirtualFile>(Arrays.asList(files));
|
||||
final Set<VirtualFile> alreadyAdded = new HashSet<VirtualFile>();
|
||||
final Library[] libraries = myLibraryTable.getLibraries();
|
||||
final Library[] libraries = myModuleLibrariesModel.getLibraries();
|
||||
for (Library library : libraries) {
|
||||
ContainerUtil.addAll(alreadyAdded, library.getFiles(OrderRootType.CLASSES));
|
||||
}
|
||||
@@ -89,6 +87,16 @@ class ChooseModuleLibrariesDialog extends LibraryFileChooser implements Classpat
|
||||
}
|
||||
|
||||
public void doChoose() {
|
||||
myLastChosen = chooseNameAndFiles(myFileToSelect);
|
||||
final JComponent parent = myClasspathPanel.getComponent();
|
||||
myChosenFiles = FileChooser.chooseFiles(parent, createFileChooserDescriptor(parent));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOK() {
|
||||
return myChosenFiles != null && myChosenFiles.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.ui.configuration.classpath;
|
||||
|
||||
import com.intellij.ide.projectView.PresentationData;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.util.Icons;
|
||||
import com.intellij.util.ui.classpath.ChooseLibrariesFromTablesDialog;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ProjectStructureChooseLibrariesDialog extends ChooseLibrariesFromTablesDialog {
|
||||
private StructureConfigurableContext myContext;
|
||||
private Collection<Library> myAlreadyAddedLibraries;
|
||||
|
||||
public ProjectStructureChooseLibrariesDialog(JComponent parentComponent,
|
||||
@Nullable Project project,
|
||||
StructureConfigurableContext context,
|
||||
Collection<Library> alreadyAddedLibraries) {
|
||||
super(parentComponent, "Choose Libraries", project);
|
||||
myContext = context;
|
||||
myAlreadyAddedLibraries = alreadyAddedLibraries;
|
||||
init();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Library[] getLibraries(@NotNull LibraryTable table) {
|
||||
final LibrariesModifiableModel model = getLibrariesModifiableModel(table);
|
||||
if (model == null) return Library.EMPTY_ARRAY;
|
||||
return model.getLibraries();
|
||||
}
|
||||
|
||||
private LibrariesModifiableModel getLibrariesModifiableModel(LibraryTable table) {
|
||||
return myContext.myLevel2Providers.get(table.getTableLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean acceptsElement(Object element) {
|
||||
if (element instanceof Library) {
|
||||
final Library library = (Library)element;
|
||||
if (myAlreadyAddedLibraries.contains(library)) return false;
|
||||
if (library instanceof LibraryImpl) {
|
||||
final Library source = ((LibraryImpl)library).getSource();
|
||||
if (source != null && myAlreadyAddedLibraries.contains(source)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getLibraryName(@NotNull Library library) {
|
||||
final LibrariesModifiableModel model = getLibrariesModifiableModel(library.getTable());
|
||||
if (model != null) {
|
||||
if (model.hasLibraryEditor(library)) {
|
||||
return model.getLibraryEditor(library).getName();
|
||||
}
|
||||
}
|
||||
return library.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LibrariesTreeNodeBase<Library> createLibraryDescriptor(NodeDescriptor parentDescriptor,
|
||||
Library library) {
|
||||
final String libraryName = getLibraryName(library);
|
||||
return new LibraryEditorDescriptor(getProject(), parentDescriptor, library, libraryName);
|
||||
}
|
||||
|
||||
private static class LibraryEditorDescriptor extends LibrariesTreeNodeBase<Library> {
|
||||
protected LibraryEditorDescriptor(final Project project, final NodeDescriptor parentDescriptor, final Library element,
|
||||
String libraryName) {
|
||||
super(project, parentDescriptor, element);
|
||||
final PresentationData templatePresentation = getTemplatePresentation();
|
||||
templatePresentation.setIcons(Icons.LIBRARY_ICON);
|
||||
templatePresentation.addText(libraryName, SimpleTextAttributes.REGULAR_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.ide.util.treeView.AbstractTreeStructure;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class AbstractLibraryTreeStructure extends AbstractTreeStructure {
|
||||
protected NodeDescriptor myRootElementDescriptor;
|
||||
protected final LibraryTableEditor myParentEditor;
|
||||
|
||||
public AbstractLibraryTreeStructure(LibraryTableEditor parentElement) {
|
||||
myParentEditor = parentElement;
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
}
|
||||
|
||||
public boolean hasSomethingToCommit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Object[] buildItems(LibraryTableTreeContentElement parent, Library library, OrderRootType orderRootType) {
|
||||
ArrayList<ItemElement> items = new ArrayList<ItemElement>();
|
||||
final LibraryEditor libraryEditor = myParentEditor.getLibraryEditor(library);
|
||||
final String[] urls = libraryEditor.getUrls(orderRootType).clone();
|
||||
Arrays.sort(urls, LibraryTableEditor.ourUrlComparator);
|
||||
for (String url : urls) {
|
||||
items.add(new ItemElement(parent, library, url, orderRootType, libraryEditor.isJarDirectory(url), libraryEditor.isValid(url, orderRootType)));
|
||||
}
|
||||
return items.toArray();
|
||||
}
|
||||
|
||||
public Object getParentElement(Object element) {
|
||||
Object rootElement = getRootElement();
|
||||
if (element == rootElement) {
|
||||
return null;
|
||||
}
|
||||
if (element instanceof LibraryTableTreeContentElement) {
|
||||
return ((LibraryTableTreeContentElement)element).getParent();
|
||||
}
|
||||
return rootElement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NodeDescriptor createDescriptor(Object element, NodeDescriptor parentDescriptor) {
|
||||
if (element == getRootElement()) {
|
||||
return myRootElementDescriptor;
|
||||
}
|
||||
if (element instanceof LibraryTableTreeContentElement) {
|
||||
return ((LibraryTableTreeContentElement)element).createDescriptor(parentDescriptor, myParentEditor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
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.ui.configuration.ProjectStructureConfigurable;
|
||||
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.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class CreateNewLibraryAction extends AnAction {
|
||||
private StructureLibraryTableModifiableModelProvider myModelProvider;
|
||||
private Project myProject;
|
||||
|
||||
public CreateNewLibraryAction(String text, StructureLibraryTableModifiableModelProvider modelProvider, final Project project) {
|
||||
super(text);
|
||||
myModelProvider = modelProvider;
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final LibrariesModifiableModel modifiableModel = myModelProvider.getModifiableModel();
|
||||
final String initial = LibraryTableEditor.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 (LibraryTableEditor.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);
|
||||
if (myProject != null){
|
||||
final BaseLibrariesConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library);
|
||||
final ExistingLibraryEditor libraryEditor = modifiableModel.getLibraryEditor(library);
|
||||
if (libraryEditor.hasChanges()) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable(){
|
||||
public void run() {
|
||||
libraryEditor.commit(); //update lib node
|
||||
}
|
||||
});
|
||||
}
|
||||
final DefaultMutableTreeNode
|
||||
libraryNode = MasterDetailsComponent.findNodeByObject((TreeNode)rootConfigurable.getTree().getModel().getRoot(), library);
|
||||
rootConfigurable.selectNodeInTree(libraryNode);
|
||||
appendLibraryToModules(ModuleStructureConfigurable.getInstance(myProject), library);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendLibraryToModules(final ModuleStructureConfigurable rootConfigurable, final Library libraryToSelect) {
|
||||
final List<Module> modules = new ArrayList<Module>();
|
||||
ContainerUtil.addAll(modules, rootConfigurable.getModules());
|
||||
final ChooseModulesDialog dlg = new ChooseModulesDialog(myProject,
|
||||
modules, ProjectBundle.message("choose.modules.dialog.title"),
|
||||
ProjectBundle
|
||||
.message("choose.modules.dialog.description", libraryToSelect.getName()));
|
||||
dlg.show();
|
||||
if (dlg.isOK()) {
|
||||
final List<Module> choosenModules = dlg.getChosenElements();
|
||||
for (Module module : choosenModules) {
|
||||
rootConfigurable.addLibraryOrderEntry(module, libraryToSelect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class CreateNewLibraryDialog extends LibraryEditorDialogBase {
|
||||
private NewLibraryEditor myLibraryEditor;
|
||||
private ComboBox myLibraryLevelCombobox;
|
||||
|
||||
public static CreateNewLibraryDialog createDialog(JComponent parent, @Nullable Project project, @NotNull Disposable parentDisposable,
|
||||
@NotNull List<LibraryTable> libraryTables,
|
||||
int selectedTable) {
|
||||
NewLibraryEditor libraryEditor = new NewLibraryEditor();
|
||||
Disposer.register(parentDisposable, libraryEditor);
|
||||
return new CreateNewLibraryDialog(parent, project, libraryEditor, libraryTables, selectedTable);
|
||||
}
|
||||
|
||||
private CreateNewLibraryDialog(@NotNull JComponent parent, @Nullable Project project, @NotNull NewLibraryEditor libraryEditor,
|
||||
@NotNull List<LibraryTable> libraryTables, int selectedTable) {
|
||||
super(parent, LibraryTableEditor.editLibrary(project, libraryEditor));
|
||||
myLibraryEditor = libraryEditor;
|
||||
final DefaultComboBoxModel model = new DefaultComboBoxModel();
|
||||
for (LibraryTable table : libraryTables) {
|
||||
model.addElement(table);
|
||||
}
|
||||
myLibraryLevelCombobox = new ComboBox(model);
|
||||
myLibraryLevelCombobox.setSelectedIndex(selectedTable);
|
||||
myLibraryLevelCombobox.setRenderer(new DefaultListCellRenderer() {
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
if (value instanceof LibraryTable) {
|
||||
setText(((LibraryTable)value).getPresentation().getDisplayName(false));
|
||||
}
|
||||
return component;
|
||||
}
|
||||
});
|
||||
init();
|
||||
}
|
||||
|
||||
public LibraryTable getSelectedTable() {
|
||||
return (LibraryTable)myLibraryLevelCombobox.getSelectedItem();
|
||||
}
|
||||
|
||||
public Library createLibrary(final @NotNull LibraryTable.ModifiableModel modifiableModel) {
|
||||
final Library library = modifiableModel.createLibrary(myLibraryEditor.getName());
|
||||
final Library.ModifiableModel model = library.getModifiableModel();
|
||||
myLibraryEditor.apply(model);
|
||||
new WriteAction() {
|
||||
protected void run(final Result result) {
|
||||
model.commit();
|
||||
}
|
||||
}.execute();
|
||||
return library;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addNorthComponents(FormBuilder formBuilder) {
|
||||
formBuilder.addLabeledComponent("Level:", myLibraryLevelCombobox);
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class EditExistingLibraryDialog extends LibraryEditorDialogBase {
|
||||
private ExistingLibraryEditor myLibraryEditor;
|
||||
private boolean myCommitChanges;
|
||||
private LibraryTable.ModifiableModel myTableModifiableModel;
|
||||
|
||||
public static EditExistingLibraryDialog createDialog(Component parent,
|
||||
LibraryTableModifiableModelProvider modelProvider,
|
||||
Library library,
|
||||
@Nullable Project project) {
|
||||
LibraryTable.ModifiableModel modifiableModel = modelProvider.getModifiableModel();
|
||||
boolean commitChanges = false;
|
||||
ExistingLibraryEditor libraryEditor;
|
||||
if (modifiableModel instanceof LibrariesModifiableModel) {
|
||||
libraryEditor = ((LibrariesModifiableModel)modifiableModel).getLibraryEditor(library);
|
||||
}
|
||||
else {
|
||||
libraryEditor = new ExistingLibraryEditor(library, null);
|
||||
commitChanges = true;
|
||||
}
|
||||
return new EditExistingLibraryDialog(parent, modifiableModel, project, libraryEditor, commitChanges);
|
||||
}
|
||||
|
||||
private EditExistingLibraryDialog(Component parent,
|
||||
LibraryTable.ModifiableModel tableModifiableModel,
|
||||
@Nullable Project project, ExistingLibraryEditor libraryEditor, boolean commitChanges) {
|
||||
super(parent, LibraryTableEditor.editLibrary(project, libraryEditor));
|
||||
myTableModifiableModel = tableModifiableModel;
|
||||
myLibraryEditor = libraryEditor;
|
||||
myCommitChanges = commitChanges;
|
||||
if (commitChanges) {
|
||||
Disposer.register(getDisposable(), libraryEditor);
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean validateAndApply() {
|
||||
if (!super.validateAndApply()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (myCommitChanges) {
|
||||
myLibraryEditor.commit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LibraryTable.ModifiableModel getTableModifiableModel() {
|
||||
return myTableModifiableModel;
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ExistingLibraryEditor implements LibraryEditor {
|
||||
private final Library myLibrary;
|
||||
private final LibraryEditorListener myListener;
|
||||
private String myLibraryName = null;
|
||||
private Library.ModifiableModel myModel = null;
|
||||
|
||||
public ExistingLibraryEditor(Library library, @Nullable LibraryEditorListener listener) {
|
||||
myLibrary = library;
|
||||
myListener = listener;
|
||||
}
|
||||
|
||||
public Library getLibrary() {
|
||||
return myLibrary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (myLibraryName != null) {
|
||||
return myLibraryName;
|
||||
}
|
||||
return myLibrary.getName();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (myModel != null) {
|
||||
// dispose if wasn't committed
|
||||
Disposer.dispose(myModel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUrls(OrderRootType rootType) {
|
||||
if (myModel != null) {
|
||||
return myModel.getUrls(rootType);
|
||||
}
|
||||
return myLibrary.getUrls(rootType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFile[] getFiles(OrderRootType rootType) {
|
||||
if (myModel != null) {
|
||||
return myModel.getFiles(rootType);
|
||||
}
|
||||
return myLibrary.getFiles(rootType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
String oldName = getModel().getName();
|
||||
myLibraryName = name;
|
||||
getModel().setName(name);
|
||||
if (myListener != null) {
|
||||
myListener.libraryRenamed(myLibrary, oldName, name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRoot(VirtualFile file, OrderRootType rootType) {
|
||||
getModel().addRoot(file, rootType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addJarDirectory(VirtualFile file, boolean recursive) {
|
||||
getModel().addJarDirectory(file, recursive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoot(String url, OrderRootType rootType) {
|
||||
while (getModel().removeRoot(url, rootType)) ;
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
if (myModel != null) {
|
||||
myModel.commit();
|
||||
myModel = null;
|
||||
myLibraryName = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Library.ModifiableModel getModel() {
|
||||
if (myModel == null) {
|
||||
myModel = myLibrary.getModifiableModel();
|
||||
}
|
||||
return myModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChanges() {
|
||||
return myModel != null && myModel.isChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJarDirectory(String url) {
|
||||
if (myModel != null) {
|
||||
return myModel.isJarDirectory(url);
|
||||
}
|
||||
return myLibrary.isJarDirectory(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(final String url, final OrderRootType orderRootType) {
|
||||
if (myModel != null) {
|
||||
return myModel.isValid(url, orderRootType);
|
||||
}
|
||||
return myLibrary.isValid(url, orderRootType);
|
||||
}
|
||||
}
|
||||
+2
-10
@@ -17,20 +17,18 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
|
||||
|
||||
class ItemElement extends LibraryTableTreeContentElement {
|
||||
private final LibraryTableTreeContentElement myParent;
|
||||
private final Library myLibrary;
|
||||
private final String myUrl;
|
||||
private final OrderRootType myRootType;
|
||||
private final boolean myIsJarDirectory;
|
||||
private final boolean myValid;
|
||||
|
||||
public ItemElement(LibraryTableTreeContentElement parent, Library library, String url, OrderRootType rootType, final boolean isJarDirectory, boolean isValid) {
|
||||
public ItemElement(LibraryTableTreeContentElement parent, String url, OrderRootType rootType, final boolean isJarDirectory,
|
||||
boolean isValid) {
|
||||
myParent = parent;
|
||||
myLibrary = library;
|
||||
myUrl = url;
|
||||
myRootType = rootType;
|
||||
myIsJarDirectory = isJarDirectory;
|
||||
@@ -65,17 +63,12 @@ class ItemElement extends LibraryTableTreeContentElement {
|
||||
return myRootType;
|
||||
}
|
||||
|
||||
public Library getLibrary() {
|
||||
return myLibrary;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ItemElement)) return false;
|
||||
|
||||
final ItemElement itemElement = (ItemElement)o;
|
||||
|
||||
if (!myLibrary.equals(itemElement.myLibrary)) return false;
|
||||
if (!myParent.equals(itemElement.myParent)) return false;
|
||||
if (!myRootType.equals(itemElement.myRootType)) return false;
|
||||
if (!myUrl.equals(itemElement.myUrl)) return false;
|
||||
@@ -86,7 +79,6 @@ class ItemElement extends LibraryTableTreeContentElement {
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = myParent.hashCode();
|
||||
result = 29 * result + myLibrary.hashCode();
|
||||
result = 29 * result + myUrl.hashCode();
|
||||
result = 29 * result + myRootType.hashCode();
|
||||
return result;
|
||||
|
||||
+15
-101
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -17,115 +17,29 @@ 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.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LibraryEditor implements Disposable {
|
||||
private final Library myLibrary;
|
||||
private final LibraryEditorListener myListener;
|
||||
private String myLibraryName = null;
|
||||
private Library.ModifiableModel myModel = null;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public interface LibraryEditor extends Disposable {
|
||||
String getName();
|
||||
|
||||
public LibraryEditor(Library library, @NotNull LibraryEditorListener listener) {
|
||||
myLibrary = library;
|
||||
myListener = listener;
|
||||
}
|
||||
String[] getUrls(OrderRootType rootType);
|
||||
|
||||
public String getName() {
|
||||
if (myLibraryName != null) {
|
||||
return myLibraryName;
|
||||
}
|
||||
return myLibrary.getName();
|
||||
}
|
||||
VirtualFile[] getFiles(OrderRootType rootType);
|
||||
|
||||
public void dispose() {
|
||||
if (myModel != null) {
|
||||
// dispose if wasn't committed
|
||||
Disposer.dispose(myModel);
|
||||
}
|
||||
}
|
||||
void setName(String name);
|
||||
|
||||
public String[] getUrls(OrderRootType rootType) {
|
||||
if (myModel != null) {
|
||||
return myModel.getUrls(rootType);
|
||||
}
|
||||
return myLibrary.getUrls(rootType);
|
||||
}
|
||||
void addRoot(VirtualFile file, OrderRootType rootType);
|
||||
|
||||
public VirtualFile[] getFiles(OrderRootType rootType) {
|
||||
if (myModel != null) {
|
||||
return myModel.getFiles(rootType);
|
||||
}
|
||||
return myLibrary.getFiles(rootType);
|
||||
}
|
||||
void addJarDirectory(VirtualFile file, boolean recursive);
|
||||
|
||||
public void setName(String name) {
|
||||
String oldName = getModel().getName();
|
||||
myLibraryName = name;
|
||||
getModel().setName(name);
|
||||
myListener.libraryRenamed(myLibrary, oldName, name);
|
||||
}
|
||||
void removeRoot(String url, OrderRootType rootType);
|
||||
|
||||
public void addRoot(String url, OrderRootType rootType) {
|
||||
getModel().addRoot(url, rootType);
|
||||
}
|
||||
boolean hasChanges();
|
||||
|
||||
public void addRoot(VirtualFile file, OrderRootType rootType) {
|
||||
getModel().addRoot(file, rootType);
|
||||
}
|
||||
boolean isJarDirectory(String url);
|
||||
|
||||
public void addJarDirectory(String url, boolean recursive) {
|
||||
getModel().addJarDirectory(url, recursive);
|
||||
}
|
||||
|
||||
public void addJarDirectory(VirtualFile file, boolean recursive) {
|
||||
getModel().addJarDirectory(file, recursive);
|
||||
}
|
||||
|
||||
public void removeRoot(String url, OrderRootType rootType) {
|
||||
while (getModel().removeRoot(url, rootType)) ;
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
if (myModel != null) {
|
||||
myModel.commit();
|
||||
myModel = null;
|
||||
myLibraryName = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Library.ModifiableModel getModel() {
|
||||
if (myModel == null) {
|
||||
myModel = myLibrary.getModifiableModel();
|
||||
}
|
||||
return myModel;
|
||||
}
|
||||
|
||||
public boolean hasChanges() {
|
||||
return myModel != null && myModel.isChanged();
|
||||
}
|
||||
|
||||
public boolean isJarDirectory(String url) {
|
||||
if (myModel != null) {
|
||||
return myModel.isJarDirectory(url);
|
||||
}
|
||||
return myLibrary.isJarDirectory(url);
|
||||
}
|
||||
|
||||
public boolean allPathsValid(OrderRootType orderRootType) {
|
||||
if (myModel != null) {
|
||||
return ((LibraryEx.ModifiableModelEx)myModel).allPathsValid(orderRootType);
|
||||
}
|
||||
return ((LibraryEx)myLibrary).allPathsValid(orderRootType);
|
||||
}
|
||||
|
||||
public boolean isValid(final String url, final OrderRootType orderRootType) {
|
||||
if (myModel != null) {
|
||||
return myModel.isValid(url, orderRootType);
|
||||
}
|
||||
return myLibrary.isValid(url, orderRootType);
|
||||
}
|
||||
boolean isValid(String url, OrderRootType orderRootType);
|
||||
}
|
||||
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataKey;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.impl.ModuleLibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class LibraryEditorDialogBase extends DialogWrapper {
|
||||
private JTextField myNameField;
|
||||
private LibraryTableEditor myLibraryTableEditor;
|
||||
|
||||
public LibraryEditorDialogBase(final Component parent, final LibraryTableEditor libraryTableEditor) {
|
||||
super(parent, true);
|
||||
myLibraryTableEditor = libraryTableEditor;
|
||||
setTitle(ProjectBundle.message("library.configure.title"));
|
||||
Disposer.register(getDisposable(), myLibraryTableEditor);
|
||||
}
|
||||
|
||||
public <T> void addFileChooserContext(DataKey<T> key, T value) {
|
||||
myLibraryTableEditor.addFileChooserContext(key, value);
|
||||
}
|
||||
|
||||
protected String getDimensionServiceKey() {
|
||||
return "#com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorDialog";
|
||||
}
|
||||
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myNameField;
|
||||
}
|
||||
|
||||
protected final void doOKAction() {
|
||||
if (!validateAndApply()) {
|
||||
return;
|
||||
}
|
||||
super.doOKAction();
|
||||
}
|
||||
|
||||
protected boolean validateAndApply() {
|
||||
final String currentName = myLibraryTableEditor.getLibraryEditor().getName();
|
||||
String newName = myNameField.getText().trim();
|
||||
if (newName.length() == 0) {
|
||||
newName = null;
|
||||
}
|
||||
if (!Comparing.equal(newName, currentName)) {
|
||||
final LibraryTable.ModifiableModel tableModifiableModel = getTableModifiableModel();
|
||||
if (tableModifiableModel != null && !(tableModifiableModel instanceof ModuleLibraryTable)) {
|
||||
if (newName == null) {
|
||||
Messages.showErrorDialog(ProjectBundle.message("library.name.not.specified.error", newName), ProjectBundle.message("library.name.not.specified.title"));
|
||||
return false;
|
||||
}
|
||||
if (LibraryTableEditor.libraryAlreadyExists(tableModifiableModel, newName)) {
|
||||
Messages.showErrorDialog(ProjectBundle.message("library.name.already.exists.error", newName), ProjectBundle.message("library.name.already.exists.title"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
myLibraryTableEditor.renameLibrary(newName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected LibraryTable.ModifiableModel getTableModifiableModel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected JComponent createNorthPanel() {
|
||||
FormBuilder formBuilder = new FormBuilder();
|
||||
String currentName = myLibraryTableEditor.getLibraryEditor().getName();
|
||||
myNameField = new JTextField(currentName);
|
||||
formBuilder.addLabeledComponent("&Name:", myNameField);
|
||||
addNorthComponents(formBuilder);
|
||||
myNameField.selectAll();
|
||||
|
||||
final JPanel panel = formBuilder.getPanel();
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
|
||||
return panel;
|
||||
}
|
||||
|
||||
protected void addNorthComponents(FormBuilder formBuilder) {
|
||||
}
|
||||
|
||||
protected JComponent createCenterPanel() {
|
||||
return myLibraryTableEditor.getComponent();
|
||||
}
|
||||
}
|
||||
+4
-22
@@ -17,25 +17,18 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
|
||||
public class LibraryElement extends LibraryTableTreeContentElement {
|
||||
private final Library myLibrary;
|
||||
private final LibraryTableEditor myParentEditor;
|
||||
private final boolean myHasInvalidPaths;
|
||||
|
||||
public LibraryElement(Library library, LibraryTableEditor parentEditor, final boolean hasInvalidPaths) {
|
||||
myLibrary = library;
|
||||
public LibraryElement(LibraryTableEditor parentEditor, final boolean hasInvalidPaths) {
|
||||
myParentEditor = parentEditor;
|
||||
myHasInvalidPaths = hasInvalidPaths;
|
||||
}
|
||||
|
||||
public Library getLibrary() {
|
||||
return myLibrary;
|
||||
}
|
||||
|
||||
public boolean isAnonymous() {
|
||||
final String name = myParentEditor.getLibraryEditor(myLibrary).getName();
|
||||
final String name = myParentEditor.getLibraryEditor().getName();
|
||||
return name == null;
|
||||
}
|
||||
|
||||
@@ -45,22 +38,11 @@ public class LibraryElement extends LibraryTableTreeContentElement {
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof LibraryElement)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final LibraryElement libraryElement = (LibraryElement)o;
|
||||
|
||||
|
||||
if (!myLibrary.equals(libraryElement.myLibrary)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return o instanceof LibraryElement;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return myLibrary.hashCode();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public LibraryTableTreeContentElement getParent() {
|
||||
|
||||
+1
-3
@@ -18,7 +18,6 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Icons;
|
||||
|
||||
@@ -37,10 +36,9 @@ class LibraryElementDescriptor extends NodeDescriptor<LibraryElement> {
|
||||
}
|
||||
|
||||
public boolean update() {
|
||||
final Library library = myElement.getLibrary();
|
||||
final String name;
|
||||
final Icon icon;
|
||||
final LibraryEditor libraryEditor = myParentEditor.getLibraryEditor(library);
|
||||
final LibraryEditor libraryEditor = myParentEditor.getLibraryEditor();
|
||||
if (myElement.isAnonymous()) {
|
||||
final VirtualFile[] files = libraryEditor.getFiles(OrderRootType.CLASSES);
|
||||
if (files.length > 0) {
|
||||
|
||||
-170
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.ex.FileChooserDialogImpl;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.FieldPanel;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import java.awt.*;
|
||||
|
||||
public class LibraryFileChooser extends FileChooserDialogImpl {
|
||||
private JTextField myNameField;
|
||||
private final boolean myInputName;
|
||||
private final LibraryTableEditor myParentEditor;
|
||||
private boolean myNameChangedByUser = false;
|
||||
|
||||
public LibraryFileChooser(FileChooserDescriptor chooserDescriptor,
|
||||
Component parent,
|
||||
boolean inputName,
|
||||
LibraryTableEditor parentEditor) {
|
||||
super(chooserDescriptor, parent);
|
||||
myInputName = inputName;
|
||||
myParentEditor = parentEditor;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (myNameField != null) {
|
||||
final String name = myNameField.getText().trim();
|
||||
return name.length() > 0 ? name : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setName(String name) {
|
||||
if (myNameField != null) {
|
||||
final boolean savedValue = myNameChangedByUser;
|
||||
try {
|
||||
myNameField.setText(name);
|
||||
}
|
||||
finally {
|
||||
myNameChangedByUser = savedValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myInputName ? myNameField : super.getPreferredFocusedComponent();
|
||||
}
|
||||
|
||||
protected JComponent createCenterPanel() {
|
||||
final JComponent centerPanel = super.createCenterPanel();
|
||||
if (!myInputName) {
|
||||
return centerPanel;
|
||||
}
|
||||
|
||||
final JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.add(centerPanel, BorderLayout.CENTER);
|
||||
|
||||
final FieldPanel fieldPanel = FieldPanel.create(ProjectBundle.message("library.name.prompt"), null);
|
||||
fieldPanel.getFieldLabel().setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
|
||||
myNameField = fieldPanel.getTextField();
|
||||
myNameField.getDocument().addDocumentListener(new DocumentListener() {
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
myNameChangedByUser = true;
|
||||
}
|
||||
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
myNameChangedByUser = true;
|
||||
}
|
||||
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
myNameChangedByUser = true;
|
||||
}
|
||||
});
|
||||
panel.add(fieldPanel, BorderLayout.NORTH);
|
||||
|
||||
myFileSystemTree.getTree().addTreeSelectionListener(new TreeSelectionListener() {
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
if (myNameField == null || myNameChangedByUser) {
|
||||
return;
|
||||
}
|
||||
final VirtualFile[] selectedFiles = getSelectedFiles();
|
||||
setName(selectedFiles.length == 1 ? selectedFiles[0].getNameWithoutExtension() : "");
|
||||
}
|
||||
});
|
||||
return panel;
|
||||
}
|
||||
|
||||
protected void doOKAction() {
|
||||
if (!validateData()) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.doOKAction();
|
||||
}
|
||||
|
||||
private boolean validateData() {
|
||||
JComponent componentToFocus = null;
|
||||
try {
|
||||
final VirtualFile[] chosenFiles = getSelectedFiles();
|
||||
if (chosenFiles != null && chosenFiles.length > 0) {
|
||||
if (myInputName) {
|
||||
final String name = getName();
|
||||
if (name == null) {
|
||||
Messages.showErrorDialog(myNameField, ProjectBundle.message("library.name.not.specified.error"),
|
||||
ProjectBundle.message("library.name.not.specified.title"));
|
||||
componentToFocus = myNameField;
|
||||
return false;
|
||||
}
|
||||
if (myParentEditor.libraryAlreadyExists(name)) {
|
||||
Messages.showErrorDialog(myNameField, ProjectBundle.message("library.name.already.exists.error", name),
|
||||
ProjectBundle.message("library.name.already.exists.title"));
|
||||
componentToFocus = myNameField;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Messages.showErrorDialog(ProjectBundle.message("library.files.not.selected.error"),
|
||||
ProjectBundle.message("library.files.not.selected.title"));
|
||||
componentToFocus = myFileSystemTree.getTree();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
finally {
|
||||
if (componentToFocus != null) {
|
||||
final JComponent _componentToFocus = componentToFocus;
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
_componentToFocus.requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Pair<String, VirtualFile[]> chooseNameAndFiles(@Nullable VirtualFile toSelect) {
|
||||
VirtualFile[] chosenFiles = choose(toSelect, null);
|
||||
return new Pair<String, VirtualFile[]>(getName(), chosenFiles);
|
||||
}
|
||||
|
||||
public Pair<String, VirtualFile[]> chooseNameAndFiles() {
|
||||
return chooseNameAndFiles(null);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.ui.configuration.libraryEditor;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class LibraryRootsData {
|
||||
|
||||
|
||||
}
|
||||
+92
-502
@@ -21,7 +21,6 @@ import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.DataKey;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -32,27 +31,22 @@ 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.impl.libraries.LibraryTableImplUtil;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.roots.libraries.LibraryUtil;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModuleEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.PathUIUtils;
|
||||
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
|
||||
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.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.InputValidator;
|
||||
import com.intellij.openapi.ui.MasterDetailsComponent;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.ui.popup.ListPopup;
|
||||
import com.intellij.openapi.ui.popup.PopupStep;
|
||||
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.NullableComputable;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import com.intellij.openapi.vfs.ex.http.HttpFileSystem;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
@@ -61,7 +55,6 @@ import com.intellij.ui.treeStructure.Tree;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
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;
|
||||
|
||||
@@ -70,7 +63,6 @@ import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -85,13 +77,11 @@ import java.util.List;
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: Jan 11, 2004
|
||||
*/
|
||||
public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
public class LibraryTableEditor implements Disposable {
|
||||
static final UrlComparator ourUrlComparator = new UrlComparator();
|
||||
|
||||
private JPanel myPanel;
|
||||
private JButton myAddLibraryButton;
|
||||
private JButton myRemoveButton;
|
||||
private JButton myRenameLibraryButton;
|
||||
private JButton myAttachClassesButton;
|
||||
private JButton myAttachJarDirectoriesButton;
|
||||
private JButton myAttachSourcesButton;
|
||||
@@ -101,57 +91,46 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
private JButton myAttachAnnotationsButton;
|
||||
private JButton myAttachMoreButton;
|
||||
private Tree myTree;
|
||||
private final Map<Library, LibraryEditor> myLibraryToEditorMap = new HashMap<Library, LibraryEditor>();
|
||||
|
||||
private final LibraryTableModifiableModelProvider myLibraryTableProvider;
|
||||
private final boolean myEditingModuleLibraries;
|
||||
private LibraryTableTreeBuilder myTreeBuilder;
|
||||
private LibraryTable.ModifiableModel myTableModifiableModel;
|
||||
private static final Icon INVALID_ITEM_ICON = IconLoader.getIcon("/nodes/ppInvalid.png");
|
||||
private static final Icon JAR_DIRECTORY_ICON = IconLoader.getIcon("/nodes/jarDirectory.png");
|
||||
|
||||
private final Collection<Runnable> myListeners = new ArrayList<Runnable>();
|
||||
private final List<LibraryEditorListener> myLibraryEditorListeners = new ArrayList<LibraryEditorListener>();
|
||||
@Nullable private final Project myProject;
|
||||
|
||||
private final Map<DataKey, Object> myFileChooserUserData = new HashMap<DataKey, Object>();
|
||||
private final LibraryEditor myLibraryEditor;
|
||||
|
||||
private LibraryTableEditor(LibraryTableModifiableModelProvider provider, Project project){
|
||||
private LibraryTableEditor(Project project,
|
||||
LibraryEditor libraryEditor){
|
||||
myProject = project;
|
||||
myLibraryTableProvider = provider;
|
||||
myTableModifiableModel = myLibraryTableProvider.getModifiableModel();
|
||||
final String tableLevel = provider.getTableLevel();
|
||||
myEditingModuleLibraries = LibraryTableImplUtil.MODULE_LEVEL.equals(tableLevel);
|
||||
if (!provider.isLibraryTableEditable()) {
|
||||
myAddLibraryButton.setVisible(false);
|
||||
myRenameLibraryButton.setVisible(false);
|
||||
myLibraryEditor = libraryEditor;
|
||||
}
|
||||
|
||||
public static LibraryTableEditor editLibrary(final @Nullable Project project, @NotNull LibraryEditor libraryEditor) {
|
||||
LibraryTableEditor tableEditor = new LibraryTableEditor(project, libraryEditor);
|
||||
tableEditor.init(new LibraryTreeStructure(tableEditor));
|
||||
if (project != null) {
|
||||
Disposer.register(project, tableEditor);
|
||||
}
|
||||
}
|
||||
|
||||
public static LibraryTableEditor editLibraryTable(LibraryTableModifiableModelProvider provider, Project project) {
|
||||
LibraryTableEditor result = new LibraryTableEditor(provider,project);
|
||||
result.init(new LibraryTableTreeStructure(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static LibraryTableEditor editLibrary(final LibraryTableModifiableModelProvider provider,
|
||||
final Library library,
|
||||
final Project project) {
|
||||
LibraryTableEditor tableEditor = new LibraryTableEditor(provider,project);
|
||||
tableEditor.init(new LibraryTreeStructure(tableEditor, library));
|
||||
Disposer.register(project, tableEditor);
|
||||
return tableEditor;
|
||||
}
|
||||
|
||||
public static LibraryTableEditor editLibrary(LibraryTableModifiableModelProvider provider, Library library) {
|
||||
LibraryTableEditor result = new LibraryTableEditor(provider,null);
|
||||
result.init(new LibraryTreeStructure(result, library));
|
||||
return result;
|
||||
public static LibraryTableEditor editLibrary(@NotNull LibraryEditor libraryEditor) {
|
||||
return editLibrary(null, libraryEditor);
|
||||
}
|
||||
|
||||
private static boolean libraryAlreadyExists(LibraryTable.ModifiableModel table, String libraryName) {
|
||||
public static boolean libraryAlreadyExists(LibraryTable.ModifiableModel table, String libraryName) {
|
||||
for (Iterator<Library> it = table.getLibraryIterator(); it.hasNext(); ) {
|
||||
if (libraryName.equals(it.next().getName())) {
|
||||
final Library library = it.next();
|
||||
final String libName;
|
||||
if (table instanceof LibrariesModifiableModel){
|
||||
libName = ((LibrariesModifiableModel)table).getLibraryEditor(library).getName();
|
||||
}
|
||||
else {
|
||||
libName = library.getName();
|
||||
}
|
||||
if (libraryName.equals(libName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -177,16 +156,7 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
myTreePanel.setLayout(new BorderLayout());
|
||||
myTreePanel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER);
|
||||
|
||||
myAddLibraryButton.setText(myEditingModuleLibraries? ProjectBundle.message("library.add.jar.directory.action") :
|
||||
ProjectBundle.message("library.create.library.action"));
|
||||
myAddLibraryButton.addActionListener(new AddLibraryAction());
|
||||
myRemoveButton.addActionListener(new RemoveAction());
|
||||
if (myEditingModuleLibraries) {
|
||||
myRenameLibraryButton.setVisible(false);
|
||||
}
|
||||
else if (myRenameLibraryButton.isVisible()){
|
||||
myRenameLibraryButton.addActionListener(new RenameLibraryAction());
|
||||
}
|
||||
myAttachClassesButton.addActionListener(new AttachClassesAction());
|
||||
myAttachJarDirectoriesButton.addActionListener(new AttachJarDirectoriesAction());
|
||||
myAttachSourcesButton.addActionListener(new AttachSourcesAction());
|
||||
@@ -195,107 +165,39 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
myAttachAnnotationsButton.addActionListener(new AttachAnnotationsAction());
|
||||
|
||||
final LibraryTableAttachHandler[] handlers = LibraryTableAttachHandler.EP_NAME.getExtensions();
|
||||
if (handlers.length == 0 || myProject == null) myAttachMoreButton.setVisible(false);
|
||||
else if (handlers.length == 1) {
|
||||
myAttachMoreButton.setText(handlers[0].getLongName());
|
||||
final LibraryEditor libraryEditor = getLibraryEditor();
|
||||
if (handlers.length == 0 || myProject == null || !(libraryEditor instanceof ExistingLibraryEditor)) {
|
||||
myAttachMoreButton.setVisible(false);
|
||||
}
|
||||
else {
|
||||
myAttachMoreButton.addActionListener(new AttachMoreAction(handlers, (ExistingLibraryEditor)libraryEditor));
|
||||
if (handlers.length == 1) {
|
||||
myAttachMoreButton.setText(handlers[0].getLongName());
|
||||
}
|
||||
}
|
||||
myAttachMoreButton.addActionListener(new AttachMoreAction(handlers));
|
||||
|
||||
treeSelectionListener.updateButtons();
|
||||
|
||||
Disposer.register(this, myTreeBuilder);
|
||||
}
|
||||
|
||||
public Tree getTree() {
|
||||
return myTree;
|
||||
}
|
||||
|
||||
public JComponent getComponent() {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
public void selectLibrary(Library library, boolean expand) {
|
||||
LibraryTableTreeContentElement element = new LibraryElement(library, this, false);
|
||||
myTreeBuilder.updateAndSelect(element);
|
||||
}
|
||||
|
||||
public <T> void addFileChooserContext(DataKey<T> key, T value) {
|
||||
myFileChooserUserData.put(key, value);
|
||||
}
|
||||
|
||||
public LibraryEditor getLibraryEditor(Library library) {
|
||||
if (myTableModifiableModel instanceof LibrariesModifiableModel){
|
||||
return ((LibrariesModifiableModel)myTableModifiableModel).getLibraryEditor(library);
|
||||
}
|
||||
LibraryEditor libraryEditor = myLibraryToEditorMap.get(library);
|
||||
if (libraryEditor == null) {
|
||||
libraryEditor = new LibraryEditor(library, this);
|
||||
myLibraryToEditorMap.put(library, libraryEditor);
|
||||
}
|
||||
return libraryEditor;
|
||||
}
|
||||
|
||||
private void removeLibrary(Library library) {
|
||||
final LibraryEditor libraryEditor = myLibraryToEditorMap.remove(library);
|
||||
if (libraryEditor != null) Disposer.dispose(libraryEditor);
|
||||
myTableModifiableModel.removeLibrary(library);
|
||||
if (myProject != null){
|
||||
ModuleStructureConfigurable.getInstance(myProject).fireItemsChangeListener(library);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should call this method in order to commit all the changes that were done by the editor
|
||||
*/
|
||||
public void commitChanges() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
for (LibraryEditor libraryEditor : myLibraryToEditorMap.values()) {
|
||||
libraryEditor.commit();
|
||||
Disposer.dispose(libraryEditor);
|
||||
}
|
||||
myTableModifiableModel.commit();
|
||||
}
|
||||
});
|
||||
myTableModifiableModel = myLibraryTableProvider.getModifiableModel();
|
||||
myLibraryToEditorMap.clear();
|
||||
}
|
||||
|
||||
public void cancelChanges() {
|
||||
for (LibraryEditor libraryEditor : new ArrayList<LibraryEditor>(myLibraryToEditorMap.values())) {
|
||||
Disposer.dispose(libraryEditor);
|
||||
}
|
||||
|
||||
myLibraryToEditorMap.clear();
|
||||
public LibraryEditor getLibraryEditor() {
|
||||
return myLibraryEditor;
|
||||
}
|
||||
|
||||
public boolean hasChanges() {
|
||||
if (myTableModifiableModel.isChanged()) {
|
||||
return true;
|
||||
}
|
||||
for (final Library library : myLibraryToEditorMap.keySet()) {
|
||||
final LibraryEditor libraryEditor = myLibraryToEditorMap.get(library);
|
||||
if (libraryEditor.hasChanges()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addLibraryEditorListener(@NotNull LibraryEditorListener listener) {
|
||||
myLibraryEditorListeners.add(listener);
|
||||
}
|
||||
|
||||
public void libraryRenamed(@NotNull Library library, String oldName, String newName) {
|
||||
for (LibraryEditorListener listener : myLibraryEditorListeners) {
|
||||
listener.libraryRenamed(library, oldName, newName);
|
||||
}
|
||||
}
|
||||
|
||||
public Library[] getLibraries() {
|
||||
return myTableModifiableModel.getLibraries();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Object getSelectedElement() {
|
||||
final TreePath selectionPath = myTreeBuilder.getTree().getSelectionPath();
|
||||
return getPathElement(selectionPath);
|
||||
return getLibraryEditor().hasChanges();
|
||||
}
|
||||
|
||||
private Object[] getSelectedElements() {
|
||||
@@ -334,157 +236,16 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Library getSelectedLibrary() {
|
||||
if (myTreeBuilder != null && myTreeBuilder.getTreeStructure() instanceof LibraryTreeStructure) {
|
||||
return ((LibraryTreeStructure)myTreeBuilder.getTreeStructure()).getLibrary();
|
||||
} else {
|
||||
return convertElementToLibrary(getSelectedElement());
|
||||
}
|
||||
}
|
||||
|
||||
private Library[] getSelectedLibraries() {
|
||||
final List<Library> libs = new ArrayList<Library>();
|
||||
final Object[] selectedElements = getSelectedElements();
|
||||
for (Object selectedElement : selectedElements) {
|
||||
final Library library = convertElementToLibrary(selectedElement);
|
||||
if (library != null) {
|
||||
libs.add(library);
|
||||
}
|
||||
}
|
||||
return libs.toArray(new Library[libs.size()]);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Library convertElementToLibrary(Object selectedElement) {
|
||||
LibraryElement libraryElement = null;
|
||||
if (selectedElement instanceof LibraryElement) {
|
||||
libraryElement = (LibraryElement)selectedElement;
|
||||
}
|
||||
else if (selectedElement instanceof ItemElement) {
|
||||
selectedElement = ((ItemElement)selectedElement).getParent();
|
||||
}
|
||||
if (selectedElement instanceof ClassesElement) {
|
||||
libraryElement = ((ClassesElement)selectedElement).getParent();
|
||||
}
|
||||
else if (selectedElement instanceof SourcesElement) {
|
||||
libraryElement = ((SourcesElement)selectedElement).getParent();
|
||||
}
|
||||
else if (selectedElement instanceof JavadocElement) {
|
||||
libraryElement = ((JavadocElement)selectedElement).getParent();
|
||||
}
|
||||
return libraryElement != null? libraryElement.getLibrary() : null;
|
||||
}
|
||||
|
||||
public void renameLibrary(Library library, String newName) {
|
||||
if (library == null) {
|
||||
return;
|
||||
}
|
||||
final LibraryEditor libraryEditor = getLibraryEditor(library);
|
||||
public void renameLibrary(String newName) {
|
||||
final LibraryEditor libraryEditor = getLibraryEditor();
|
||||
libraryEditor.setName(newName);
|
||||
librariesChanged(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if Ok button was pressed on dialog close, false otherwise
|
||||
*/
|
||||
@Nullable
|
||||
public Library[] openDialog(final Component parent, final Collection<Library> selection, final boolean expandSelectedItems) {
|
||||
final MyDialogWrapper dialogWrapper = new MyDialogWrapper(parent);
|
||||
if (selection != null) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
for (final Library library : selection) {
|
||||
selectLibrary(library, expandSelectedItems);
|
||||
}
|
||||
}
|
||||
}, ModalityState.stateForComponent(dialogWrapper.getContentPane()));
|
||||
}
|
||||
dialogWrapper.show();
|
||||
return dialogWrapper.isOK() ? dialogWrapper.getSelectedLibraries() : null;
|
||||
}
|
||||
|
||||
public ActionListener createAddLibraryAction(boolean select){
|
||||
return new AddLibraryAction(select);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
myTreeBuilder = null;
|
||||
}
|
||||
|
||||
private class AddLibraryAction implements ActionListener {
|
||||
private boolean myNeedSelection;
|
||||
|
||||
public AddLibraryAction() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public AddLibraryAction(boolean select) {
|
||||
myNeedSelection = select;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final String initial = suggestNewLibraryName(myTableModifiableModel);
|
||||
final String prompt = ProjectBundle.message("library.name.prompt");
|
||||
final String title = myAddLibraryButton.getText().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 (libraryAlreadyExists(myTableModifiableModel, 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 = myTableModifiableModel.createLibrary(libraryName);
|
||||
selectLibrary(library, true);
|
||||
if (myProject != null){
|
||||
final BaseLibrariesConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library);
|
||||
final LibraryEditor libraryEditor = getLibraryEditor(library);
|
||||
if (libraryEditor.hasChanges()) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable(){
|
||||
public void run() {
|
||||
libraryEditor.commit(); //update lib node
|
||||
}
|
||||
});
|
||||
}
|
||||
final DefaultMutableTreeNode libraryNode = MasterDetailsComponent.findNodeByObject((TreeNode)rootConfigurable.getTree().getModel().getRoot(), library);
|
||||
if (myNeedSelection){
|
||||
rootConfigurable.selectNodeInTree(libraryNode);
|
||||
if (!myEditingModuleLibraries) {
|
||||
appendLibraryToModules(ModuleStructureConfigurable.getInstance(myProject), library);
|
||||
}
|
||||
}
|
||||
}
|
||||
librariesChanged(true);
|
||||
}
|
||||
|
||||
private void appendLibraryToModules(final ModuleStructureConfigurable rootConfigurable, final Library libraryToSelect) {
|
||||
final List<Module> modules = new ArrayList<Module>();
|
||||
ContainerUtil.addAll(modules, rootConfigurable.getModules());
|
||||
final ChooseModulesDialog dlg = new ChooseModulesDialog(myProject,
|
||||
modules, ProjectBundle.message("choose.modules.dialog.title"),
|
||||
ProjectBundle
|
||||
.message("choose.modules.dialog.description", libraryToSelect.getName()));
|
||||
dlg.show();
|
||||
if (dlg.isOK()) {
|
||||
final List<Module> choosenModules = dlg.getChosenElements();
|
||||
for (Module module : choosenModules) {
|
||||
rootConfigurable.addLibraryOrderEntry(module, libraryToSelect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private abstract class AttachItemAction implements ActionListener {
|
||||
private final FileChooserDescriptor myDescriptor;
|
||||
private VirtualFile myLastChosen = null;
|
||||
@@ -510,31 +271,28 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
}
|
||||
|
||||
public final void actionPerformed(ActionEvent e) {
|
||||
final Library library = getSelectedLibrary();
|
||||
if (library != null) {
|
||||
myDescriptor.setTitle(getTitle());
|
||||
myDescriptor.setDescription(getDescription());
|
||||
for (Map.Entry<DataKey, Object> entry : myFileChooserUserData.entrySet()) {
|
||||
myDescriptor.putUserData(entry.getKey(), entry.getValue());
|
||||
}
|
||||
VirtualFile toSelect = getFileToSelect(library);
|
||||
final VirtualFile[] attachedFiles =
|
||||
attachFiles(library, scanForActualRoots(FileChooser.chooseFiles(myPanel, myDescriptor, toSelect)), getRootType(),
|
||||
addAsJarDirectories());
|
||||
if (attachedFiles.length > 0) {
|
||||
myLastChosen = attachedFiles[0];
|
||||
}
|
||||
myDescriptor.setTitle(getTitle());
|
||||
myDescriptor.setDescription(getDescription());
|
||||
for (Map.Entry<DataKey, Object> entry : myFileChooserUserData.entrySet()) {
|
||||
myDescriptor.putUserData(entry.getKey(), entry.getValue());
|
||||
}
|
||||
VirtualFile toSelect = getFileToSelect();
|
||||
final VirtualFile[] attachedFiles =
|
||||
attachFiles(scanForActualRoots(FileChooser.chooseFiles(myPanel, myDescriptor, toSelect)), getRootType(),
|
||||
addAsJarDirectories());
|
||||
if (attachedFiles.length > 0) {
|
||||
myLastChosen = attachedFiles[0];
|
||||
}
|
||||
fireLibrariesChanged();
|
||||
myTree.requestFocus();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private VirtualFile getFileToSelect(Library library) {
|
||||
private VirtualFile getFileToSelect() {
|
||||
VirtualFile toSelect = myLastChosen;
|
||||
if (toSelect == null) {
|
||||
for (OrderRootType orderRootType : OrderRootType.getAllPersistentTypes()) {
|
||||
final VirtualFile[] existingRoots = library.getFiles(orderRootType);
|
||||
final VirtualFile[] existingRoots = getLibraryEditor().getFiles(orderRootType);
|
||||
if (existingRoots.length > 0) {
|
||||
VirtualFile existingRoot = existingRoots [0];
|
||||
if (existingRoot.getFileSystem() instanceof JarFileSystem) {
|
||||
@@ -552,9 +310,10 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toSelect == null && Comparing.strEqual(myLibraryTableProvider.getTableLevel(), LibraryTablesRegistrar.PROJECT_LEVEL)) {
|
||||
if (toSelect == null) {
|
||||
final Project project = myProject;
|
||||
if (project != null) {
|
||||
//todo[nik] perhaps we shouldn't select project base dir if global library is edited
|
||||
toSelect = project.getBaseDir();
|
||||
}
|
||||
}
|
||||
@@ -562,12 +321,12 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
}
|
||||
}
|
||||
|
||||
private VirtualFile[] attachFiles(final Library library, final VirtualFile[] files, final OrderRootType rootType, final boolean isJarDirectories) {
|
||||
final VirtualFile[] filesToAttach = filterAlreadyAdded(library, files, rootType);
|
||||
private VirtualFile[] attachFiles(final VirtualFile[] files, final OrderRootType rootType, final boolean isJarDirectories) {
|
||||
final VirtualFile[] filesToAttach = filterAlreadyAdded(files, rootType);
|
||||
if (filesToAttach.length > 0) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final LibraryEditor libraryEditor = getLibraryEditor(library);
|
||||
final LibraryEditor libraryEditor = getLibraryEditor();
|
||||
for (VirtualFile file : filesToAttach) {
|
||||
if (isJarDirectories) {
|
||||
libraryEditor.addJarDirectory(file, false);
|
||||
@@ -576,9 +335,6 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
libraryEditor.addRoot(file, rootType);
|
||||
}
|
||||
}
|
||||
if (myEditingModuleLibraries) {
|
||||
commitChanges();
|
||||
}
|
||||
}
|
||||
});
|
||||
myTreeBuilder.updateFromRoot();
|
||||
@@ -586,23 +342,14 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
return filesToAttach;
|
||||
}
|
||||
|
||||
private VirtualFile[] filterAlreadyAdded(Library lib, VirtualFile[] files, final OrderRootType rootType) {
|
||||
private VirtualFile[] filterAlreadyAdded(VirtualFile[] files, final OrderRootType rootType) {
|
||||
if (files == null || files.length == 0) {
|
||||
return VirtualFile.EMPTY_ARRAY;
|
||||
}
|
||||
final Set<VirtualFile> chosenFilesSet = new HashSet<VirtualFile>(Arrays.asList(files));
|
||||
final Set<VirtualFile> alreadyAdded = new HashSet<VirtualFile>();
|
||||
if (lib == null) {
|
||||
final Library[] libraries = myTableModifiableModel.getLibraries();
|
||||
for (Library library : libraries) {
|
||||
final VirtualFile[] libraryFiles = getLibraryEditor(library).getFiles(rootType);
|
||||
ContainerUtil.addAll(alreadyAdded, libraryFiles);
|
||||
}
|
||||
}
|
||||
else {
|
||||
final VirtualFile[] libraryFiles = getLibraryEditor(lib).getFiles(rootType);
|
||||
ContainerUtil.addAll(alreadyAdded, libraryFiles);
|
||||
}
|
||||
final VirtualFile[] libraryFiles = getLibraryEditor().getFiles(rootType);
|
||||
ContainerUtil.addAll(alreadyAdded, libraryFiles);
|
||||
chosenFilesSet.removeAll(alreadyAdded);
|
||||
return VfsUtil.toVirtualFileArray(chosenFilesSet);
|
||||
}
|
||||
@@ -614,12 +361,12 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
}
|
||||
|
||||
protected String getTitle() {
|
||||
final Library selectedLibrary = getSelectedLibrary();
|
||||
if (selectedLibrary != null) {
|
||||
return ProjectBundle.message("library.attach.classes.to.library.action", getLibraryEditor(selectedLibrary).getName());
|
||||
final String name = getLibraryEditor().getName();
|
||||
if (StringUtil.isEmpty(name)) {
|
||||
return ProjectBundle.message("library.attach.classes.action");
|
||||
}
|
||||
else {
|
||||
return ProjectBundle.message("library.attach.classes.action");
|
||||
return ProjectBundle.message("library.attach.classes.to.library.action", name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -643,12 +390,12 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
}
|
||||
|
||||
protected String getTitle() {
|
||||
final Library selectedLibrary = getSelectedLibrary();
|
||||
if (selectedLibrary != null) {
|
||||
return ProjectBundle.message("library.attach.jar.directory.to.library.action", getLibraryEditor(selectedLibrary).getName());
|
||||
final String name = getLibraryEditor().getName();
|
||||
if (StringUtil.isEmpty(name)) {
|
||||
return ProjectBundle.message("library.attach.jar.directory.action");
|
||||
}
|
||||
else {
|
||||
return ProjectBundle.message("library.attach.jar.directory.action");
|
||||
return ProjectBundle.message("library.attach.jar.directory.to.library.action", name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -714,12 +461,9 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
|
||||
private class AttachUrlJavadocAction implements ActionListener {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final Library library = getSelectedLibrary();
|
||||
if (library != null) {
|
||||
final VirtualFile vFile = Util.showSpecifyJavadocUrlDialog(myPanel);
|
||||
if (vFile != null) {
|
||||
attachFiles(library, new VirtualFile[] {vFile}, JavadocOrderRootType.getInstance(), false);
|
||||
}
|
||||
final VirtualFile vFile = Util.showSpecifyJavadocUrlDialog(myPanel);
|
||||
if (vFile != null) {
|
||||
attachFiles(new VirtualFile[] {vFile}, JavadocOrderRootType.getInstance(), false);
|
||||
}
|
||||
myTree.requestFocus();
|
||||
}
|
||||
@@ -734,18 +478,11 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
for (Object selectedElement : selectedElements) {
|
||||
if (selectedElement instanceof LibraryElement) {
|
||||
removeLibrary(((LibraryElement)selectedElement).getLibrary());
|
||||
}
|
||||
else if (selectedElement instanceof ItemElement) {
|
||||
if (selectedElement instanceof ItemElement) {
|
||||
final ItemElement itemElement = (ItemElement)selectedElement;
|
||||
final Library library = itemElement.getLibrary();
|
||||
getLibraryEditor(library).removeRoot(itemElement.getUrl(), itemElement.getRootType());
|
||||
getLibraryEditor().removeRoot(itemElement.getUrl(), itemElement.getRootType());
|
||||
}
|
||||
}
|
||||
if (myEditingModuleLibraries) {
|
||||
commitChanges();
|
||||
}
|
||||
}
|
||||
});
|
||||
librariesChanged(true);
|
||||
@@ -776,136 +513,6 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
myListeners.remove(listener);
|
||||
}
|
||||
|
||||
private class RenameLibraryAction implements ActionListener {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final Library selectedLibrary = getSelectedLibrary();
|
||||
if (selectedLibrary == null) {
|
||||
return;
|
||||
}
|
||||
final String currentName = selectedLibrary.getName();
|
||||
final String newName = Messages.showInputDialog(myTree, ProjectBundle.message("library.rename.prompt"),
|
||||
ProjectBundle.message("library.rename.title", getLibraryEditor(selectedLibrary).getName()), Messages.getQuestionIcon(), getLibraryEditor(selectedLibrary).getName(), new InputValidator() {
|
||||
public boolean checkInput(String inputString) {
|
||||
return true;
|
||||
}
|
||||
public boolean canClose(String libraryName) {
|
||||
if (!currentName.equals(libraryName)) {
|
||||
if (libraryAlreadyExists(libraryName)) {
|
||||
Messages.showErrorDialog(ProjectBundle.message("library.name.already.exists.error", libraryName),
|
||||
ProjectBundle.message("library.name.already.exists.title"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
renameLibrary(selectedLibrary, newName);
|
||||
}
|
||||
}
|
||||
|
||||
boolean libraryAlreadyExists(String libraryName) {
|
||||
for (Iterator it = myTableModifiableModel.getLibraryIterator(); it.hasNext(); ) {
|
||||
final Library lib = (Library)it.next();
|
||||
final LibraryEditor editor = getLibraryEditor(lib);
|
||||
final String libName = editor != null ? editor.getName() : lib.getName();
|
||||
if (libraryName.equals(libName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private class MyDialogWrapper extends DialogWrapper {
|
||||
private JTextField myNameField;
|
||||
private Library[] mySelectedLibraries;
|
||||
|
||||
public MyDialogWrapper(final Component parent) {
|
||||
super(parent, true);
|
||||
setTitle(myLibraryTableProvider.getLibraryTablePresentation().getLibraryTableEditorTitle());
|
||||
init();
|
||||
|
||||
Disposer.register(getDisposable(), LibraryTableEditor.this);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"RefusedBequest"})
|
||||
protected String getDimensionServiceKey() {
|
||||
return "#com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor.MyDialogWrapper";
|
||||
}
|
||||
|
||||
@SuppressWarnings({"RefusedBequest"})
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
if (myNameField != null) {
|
||||
return myNameField;
|
||||
}
|
||||
return myTree;
|
||||
}
|
||||
|
||||
protected void doOKAction() {
|
||||
mySelectedLibraries = LibraryTableEditor.this.getSelectedLibraries();
|
||||
|
||||
if (myNameField != null) {
|
||||
final Library library = getSelectedLibrary();
|
||||
final String currentName = getLibraryEditor(library).getName();
|
||||
String newName = myNameField.getText().trim();
|
||||
if (newName.length() == 0) {
|
||||
newName = null;
|
||||
}
|
||||
if (!Comparing.equal(newName, currentName)) {
|
||||
if (!myEditingModuleLibraries) {
|
||||
if (newName == null) {
|
||||
Messages.showErrorDialog(ProjectBundle.message("library.name.not.specified.error", newName), ProjectBundle.message("library.name.not.specified.title"));
|
||||
return;
|
||||
}
|
||||
if (libraryAlreadyExists(newName)) {
|
||||
Messages.showErrorDialog(ProjectBundle.message("library.name.already.exists.error", newName), ProjectBundle.message("library.name.already.exists.title"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
renameLibrary(library, newName);
|
||||
}
|
||||
}
|
||||
commitChanges();
|
||||
super.doOKAction();
|
||||
}
|
||||
|
||||
protected JComponent createNorthPanel() {
|
||||
if (myTreeBuilder.getTreeStructure() instanceof LibraryTreeStructure) {
|
||||
final Library library = getSelectedLibrary();
|
||||
final JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
|
||||
final LibraryEditor libraryEditor = getLibraryEditor(library);
|
||||
String currentName = libraryEditor.getName();
|
||||
/*
|
||||
if (currentName == null || currentName.length() == 0) {
|
||||
final String[] urls = libraryEditor.getUrls(OrderRootType.CLASSES);
|
||||
if (urls.length > 0) {
|
||||
String url = urls[0];
|
||||
final int idx = url.lastIndexOf('/');
|
||||
if (idx)
|
||||
}
|
||||
}
|
||||
*/
|
||||
myNameField = new JTextField(currentName);
|
||||
panel.add(myNameField, BorderLayout.CENTER);
|
||||
final JLabel label = new JLabel("Name: ");
|
||||
panel.add(label, BorderLayout.WEST);
|
||||
label.setLabelFor(myNameField);
|
||||
label.setDisplayedMnemonic('N');
|
||||
myNameField.selectAll();
|
||||
return panel;
|
||||
}
|
||||
return super.createNorthPanel();
|
||||
}
|
||||
|
||||
protected JComponent createCenterPanel() {
|
||||
return LibraryTableEditor.this.getComponent();
|
||||
}
|
||||
|
||||
public Library[] getSelectedLibraries() {
|
||||
return mySelectedLibraries;
|
||||
}
|
||||
}
|
||||
|
||||
private class MyTreeSelectionListener implements TreeSelectionListener {
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
updateButtons();
|
||||
@@ -913,35 +520,18 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
|
||||
public void updateButtons() {
|
||||
final Object[] selectedElements = getSelectedElements();
|
||||
final Class<? extends Object> elementsClass = getElementsClass(selectedElements);
|
||||
myRemoveButton.setEnabled(
|
||||
elementsClass != null &&
|
||||
!(elementsClass.isAssignableFrom(ClassesElement.class) || elementsClass.equals(SourcesElement.class) || elementsClass.isAssignableFrom(JavadocElement.class) || elementsClass.isAssignableFrom(AnnotationElement.class))
|
||||
&& (myLibraryTableProvider.isLibraryTableEditable() || !elementsClass.isAssignableFrom(LibraryElement.class))
|
||||
final Class<?> elementsClass = getElementsClass(selectedElements);
|
||||
myRemoveButton.setEnabled(elementsClass != null &&
|
||||
!(elementsClass.isAssignableFrom(ClassesElement.class) || elementsClass.equals(SourcesElement.class) || elementsClass.isAssignableFrom(JavadocElement.class) || elementsClass.isAssignableFrom(AnnotationElement.class))
|
||||
);
|
||||
myRenameLibraryButton.setEnabled(selectedElements.length == 1 && elementsClass != null && elementsClass.equals(LibraryElement.class));
|
||||
if (elementsClass != null && elementsClass.isAssignableFrom(ItemElement.class)) {
|
||||
myRemoveButton.setText(ProjectBundle.message("library.detach.action"));
|
||||
}
|
||||
else {
|
||||
myRemoveButton.setText(ProjectBundle.message("library.detach.action"));
|
||||
}
|
||||
boolean attachActionsEnabled = selectedElements.length == 1 || getSelectedLibrary() != null;
|
||||
myAttachClassesButton.setEnabled(attachActionsEnabled);
|
||||
myAttachJavadocsButton.setEnabled(attachActionsEnabled);
|
||||
myAttachUrlJavadocsButton.setEnabled(attachActionsEnabled);
|
||||
myAttachSourcesButton.setEnabled(attachActionsEnabled);
|
||||
myAttachAnnotationsButton.setEnabled(attachActionsEnabled);
|
||||
myAttachJarDirectoriesButton.setEnabled(attachActionsEnabled);
|
||||
myAttachMoreButton.setEnabled(attachActionsEnabled);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Class<? extends Object> getElementsClass(Object[] elements) {
|
||||
private Class<?> getElementsClass(Object[] elements) {
|
||||
if (elements.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Class<? extends Object> cls = null;
|
||||
Class<?> cls = null;
|
||||
for (Object element : elements) {
|
||||
if (cls == null) {
|
||||
cls = element.getClass();
|
||||
@@ -1052,19 +642,20 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
|
||||
private class AttachMoreAction implements ActionListener {
|
||||
private final LibraryTableAttachHandler[] myHandlers;
|
||||
private final ExistingLibraryEditor myLibraryEditor;
|
||||
|
||||
public AttachMoreAction(LibraryTableAttachHandler[] handlers) {
|
||||
public AttachMoreAction(LibraryTableAttachHandler[] handlers, final ExistingLibraryEditor libraryEditor) {
|
||||
myHandlers = handlers;
|
||||
myLibraryEditor = libraryEditor;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final Library library = getSelectedLibrary();
|
||||
assert library != null;
|
||||
final Ref<Library.ModifiableModel> modelRef = Ref.create(null);
|
||||
final NullableComputable<Library.ModifiableModel> computable = new NullableComputable<Library.ModifiableModel>() {
|
||||
public Library.ModifiableModel compute() {
|
||||
if (myTreeBuilder == null) {
|
||||
// The following lines were born in severe pain & suffering, please respect
|
||||
final Library library = myLibraryEditor.getLibrary();
|
||||
final InvocationHandler invocationHandler = Proxy.isProxyClass(library.getClass())? Proxy.getInvocationHandler(library) : null;
|
||||
final Library realLibrary = invocationHandler instanceof ModuleEditor.ProxyDelegateAccessor? (Library)((ModuleEditor.ProxyDelegateAccessor)invocationHandler)
|
||||
.getDelegate() : library;
|
||||
@@ -1076,7 +667,7 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
return model;
|
||||
}
|
||||
else {
|
||||
return getLibraryEditor(library).getModel();
|
||||
return myLibraryEditor.getModel();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1089,7 +680,7 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
public void run() {
|
||||
if (myTreeBuilder != null) myTreeBuilder.queueUpdate();
|
||||
if (myProject != null) {
|
||||
ModuleStructureConfigurable.getInstance(myProject).fireItemsChangeListener(library);
|
||||
ModuleStructureConfigurable.getInstance(myProject).fireItemsChangeListener(myLibraryEditor.getLibrary());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1119,7 +710,6 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
|
||||
public PopupStep onChosen(final LibraryTableAttachHandler handler, final boolean finalChoice) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
getSelectedLibrary();
|
||||
handler.performAttach(myProject, computable).doWhenProcessed(successRunnable).doWhenRejected(rejectRunnable);
|
||||
}
|
||||
});
|
||||
|
||||
-1
@@ -20,7 +20,6 @@ import com.intellij.openapi.roots.OrderRootType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class LibraryTableTreeContentElement {
|
||||
// empty, just to serve as a base for all tree structure elements
|
||||
|
||||
public abstract LibraryTableTreeContentElement getParent();
|
||||
|
||||
|
||||
-94
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibrariesAlphaComparator;
|
||||
import com.intellij.openapi.roots.ui.configuration.OrderRootTypeUIFactory;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
class LibraryTableTreeStructure extends AbstractLibraryTreeStructure {
|
||||
private final Object myRootElement = new Object();
|
||||
|
||||
public LibraryTableTreeStructure(LibraryTableEditor parentEditor) {
|
||||
super(parentEditor);
|
||||
myRootElementDescriptor = new NodeDescriptor(null, null) {
|
||||
public boolean update() {
|
||||
myName = ProjectBundle.message("library.root.node");
|
||||
return false;
|
||||
}
|
||||
public Object getElement() {
|
||||
return myRootElement;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Object getRootElement() {
|
||||
return myRootElement;
|
||||
}
|
||||
|
||||
public Object[] getChildElements(Object element) {
|
||||
if (element == myRootElement) {
|
||||
final Library[] libraries = myParentEditor.getLibraries();
|
||||
Arrays.sort(libraries, LibrariesAlphaComparator.INSTANCE);
|
||||
LibraryElement[] elements = new LibraryElement[libraries.length];
|
||||
for (int idx = 0; idx < libraries.length; idx++) {
|
||||
final Library library = libraries[idx];
|
||||
boolean allPathsValid = true;
|
||||
for (OrderRootType type : OrderRootType.getAllTypes()) {
|
||||
allPathsValid &= allPathsValid(library, type);
|
||||
}
|
||||
elements[idx] = new LibraryElement(library, myParentEditor, !allPathsValid);
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
if (element instanceof LibraryElement) {
|
||||
final LibraryElement libraryItemElement = (LibraryElement)element;
|
||||
ArrayList<LibraryTableTreeContentElement> elements = new ArrayList<LibraryTableTreeContentElement>(3);
|
||||
final Library library = libraryItemElement.getLibrary();
|
||||
|
||||
final LibraryEditor parentEditor = myParentEditor.getLibraryEditor(library);
|
||||
for (OrderRootType type : OrderRootType.getAllTypes()) {
|
||||
final String[] urls = parentEditor.getUrls(type);
|
||||
if (urls.length > 0) {
|
||||
elements.add(OrderRootTypeUIFactory.FACTORY.getByKey(type).createElement(libraryItemElement));
|
||||
}
|
||||
}
|
||||
return elements.toArray();
|
||||
}
|
||||
|
||||
if (element instanceof LibraryTableTreeContentElement) {
|
||||
final LibraryTableTreeContentElement contentElement = (LibraryTableTreeContentElement)element;
|
||||
final LibraryTableTreeContentElement parentElement = contentElement.getParent();
|
||||
if (parentElement instanceof LibraryElement) {
|
||||
return buildItems(contentElement, ((LibraryElement)parentElement).getLibrary(), contentElement.getOrderRootType());
|
||||
}
|
||||
}
|
||||
return ArrayUtil.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
|
||||
private boolean allPathsValid(Library library, OrderRootType orderRootType) {
|
||||
return myParentEditor.getLibraryEditor(library).allPathsValid(orderRootType);
|
||||
}
|
||||
|
||||
}
|
||||
+49
-10
@@ -15,21 +15,25 @@
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.ide.util.treeView.AbstractTreeStructure;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.OrderRootTypeUIFactory;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LibraryTreeStructure extends AbstractLibraryTreeStructure {
|
||||
public class LibraryTreeStructure extends AbstractTreeStructure {
|
||||
private final LibraryElement myRootElement;
|
||||
protected NodeDescriptor myRootElementDescriptor;
|
||||
protected final LibraryTableEditor myParentEditor;
|
||||
|
||||
public LibraryTreeStructure(LibraryTableEditor parentElement, Library library) {
|
||||
super(parentElement);
|
||||
myRootElement = new LibraryElement(library, myParentEditor, false);
|
||||
public LibraryTreeStructure(LibraryTableEditor parentElement) {
|
||||
myParentEditor = parentElement;
|
||||
myRootElement = new LibraryElement(myParentEditor, false);
|
||||
myRootElementDescriptor = new NodeDescriptor(null, null) {
|
||||
public boolean update() {
|
||||
myName = ProjectBundle.message("library.root.node");
|
||||
@@ -48,8 +52,7 @@ public class LibraryTreeStructure extends AbstractLibraryTreeStructure {
|
||||
public Object[] getChildElements(Object element) {
|
||||
if (element == myRootElement) {
|
||||
ArrayList<LibraryTableTreeContentElement> elements = new ArrayList<LibraryTableTreeContentElement>(3);
|
||||
final Library library = myRootElement.getLibrary();
|
||||
final LibraryEditor parentEditor = myParentEditor.getLibraryEditor(library);
|
||||
final LibraryEditor parentEditor = myParentEditor.getLibraryEditor();
|
||||
for (OrderRootType type : OrderRootType.getAllTypes()) {
|
||||
final String[] urls = parentEditor.getUrls(type);
|
||||
if (urls.length > 0) {
|
||||
@@ -63,13 +66,49 @@ public class LibraryTreeStructure extends AbstractLibraryTreeStructure {
|
||||
final LibraryTableTreeContentElement contentElement = (LibraryTableTreeContentElement)element;
|
||||
final LibraryTableTreeContentElement parentElement = contentElement.getParent();
|
||||
if (parentElement instanceof LibraryElement) {
|
||||
return buildItems(contentElement, ((LibraryElement)parentElement).getLibrary(), contentElement.getOrderRootType());
|
||||
return buildItems(contentElement, contentElement.getOrderRootType());
|
||||
}
|
||||
}
|
||||
return ArrayUtil.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
|
||||
public Library getLibrary() {
|
||||
return myRootElement.getLibrary();
|
||||
public void commit() {
|
||||
}
|
||||
|
||||
public boolean hasSomethingToCommit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Object[] buildItems(LibraryTableTreeContentElement parent, OrderRootType orderRootType) {
|
||||
ArrayList<ItemElement> items = new ArrayList<ItemElement>();
|
||||
final LibraryEditor libraryEditor = myParentEditor.getLibraryEditor();
|
||||
final String[] urls = libraryEditor.getUrls(orderRootType).clone();
|
||||
Arrays.sort(urls, LibraryTableEditor.ourUrlComparator);
|
||||
for (String url : urls) {
|
||||
items.add(new ItemElement(parent, url, orderRootType, libraryEditor.isJarDirectory(url), libraryEditor.isValid(url, orderRootType)));
|
||||
}
|
||||
return items.toArray();
|
||||
}
|
||||
|
||||
public Object getParentElement(Object element) {
|
||||
Object rootElement = getRootElement();
|
||||
if (element == rootElement) {
|
||||
return null;
|
||||
}
|
||||
if (element instanceof LibraryTableTreeContentElement) {
|
||||
return ((LibraryTableTreeContentElement)element).getParent();
|
||||
}
|
||||
return rootElement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NodeDescriptor createDescriptor(Object element, NodeDescriptor parentDescriptor) {
|
||||
if (element == getRootElement()) {
|
||||
return myRootElementDescriptor;
|
||||
}
|
||||
if (element instanceof LibraryTableTreeContentElement) {
|
||||
return ((LibraryTableTreeContentElement)element).createDescriptor(parentDescriptor, myParentEditor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.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.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class NewLibraryEditor implements LibraryEditor {
|
||||
private String myLibraryName;
|
||||
private final Map<OrderRootType, VirtualFilePointerContainer> myRoots;
|
||||
private final Map<String, Boolean> myJarDirectories = new HashMap<String, Boolean>();
|
||||
|
||||
public NewLibraryEditor() {
|
||||
myRoots = new HashMap<OrderRootType, VirtualFilePointerContainer>();
|
||||
for (OrderRootType rootType : OrderRootType.getAllTypes()) {
|
||||
myRoots.put(rootType, VirtualFilePointerManager.getInstance().createContainer(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return myLibraryName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUrls(OrderRootType rootType) {
|
||||
return myRoots.get(rootType).getUrls();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFile[] getFiles(OrderRootType rootType) {
|
||||
return LibraryImpl.getRootFiles(myRoots.get(rootType), myJarDirectories);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
myLibraryName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRoot(VirtualFile file, OrderRootType rootType) {
|
||||
myRoots.get(rootType).add(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addJarDirectory(VirtualFile file, boolean recursive) {
|
||||
myRoots.get(OrderRootType.CLASSES).add(file);
|
||||
myJarDirectories.put(file.getUrl(), recursive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoot(String url, OrderRootType rootType) {
|
||||
final VirtualFilePointerContainer container = myRoots.get(rootType);
|
||||
final VirtualFilePointer pointer = container.findByUrl(url);
|
||||
if (pointer != null) {
|
||||
myJarDirectories.remove(pointer.getUrl());
|
||||
container.remove(pointer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChanges() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJarDirectory(String url) {
|
||||
return myJarDirectories.containsKey(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(String url, OrderRootType orderRootType) {
|
||||
final VirtualFilePointer pointer = myRoots.get(orderRootType).findByUrl(url);
|
||||
return pointer != null && pointer.isValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
public void apply(@NotNull Library.ModifiableModel model) {
|
||||
model.setName(myLibraryName);
|
||||
for (Map.Entry<OrderRootType, VirtualFilePointerContainer> entry : myRoots.entrySet()) {
|
||||
for (String url : entry.getValue().getUrls()) {
|
||||
model.addRoot(url, entry.getKey());
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Boolean> entry : myJarDirectories.entrySet()) {
|
||||
model.addJarDirectory(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-17
@@ -27,15 +27,13 @@ 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.LibraryTable;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.CreateNewLibraryAction;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
|
||||
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.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
@@ -98,7 +96,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
|
||||
}
|
||||
|
||||
protected void loadTree() {
|
||||
createLibrariesNode(myContext.createModifiableModelProvider(myLevel, false));
|
||||
createLibrariesNode(myContext.createModifiableModelProvider(myLevel));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -118,7 +116,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
|
||||
return result;
|
||||
}
|
||||
|
||||
private void createLibrariesNode(final LibraryTableModifiableModelProvider modelProvider) {
|
||||
private void createLibrariesNode(final StructureLibraryTableModifiableModelProvider modelProvider) {
|
||||
final Library[] libraries = modelProvider.getModifiableModel().getLibraries();
|
||||
for (Library library : libraries) {
|
||||
myRoot.add(new MyNode(new LibraryConfigurable(modelProvider, library, myProject, TREE_UPDATER)));
|
||||
@@ -149,7 +147,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
|
||||
if (table != null) {
|
||||
final String level = table.getTableLevel();
|
||||
final LibraryConfigurable configurable =
|
||||
new LibraryConfigurable(myContext.createModifiableModelProvider(level, false), library, myProject, TREE_UPDATER);
|
||||
new LibraryConfigurable(myContext.createModifiableModelProvider(level), library, myProject, TREE_UPDATER);
|
||||
final MyNode node = new MyNode(configurable);
|
||||
addNode(node, myRoot);
|
||||
myContext.getDaemonAnalyzer().queueUpdate(new LibraryProjectStructureElement(myContext, library));
|
||||
@@ -175,29 +173,23 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
|
||||
setPopup(false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AnAction[] getChildren(@Nullable final AnActionEvent e) {
|
||||
return new AnAction[]{new AnAction(getAddText()) {
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final LibraryTableEditor editor = LibraryTableEditor.editLibraryTable(getModelProvider(false), myProject);
|
||||
editor.addLibraryEditorListener(myContext);
|
||||
editor.createAddLibraryAction(true).actionPerformed(null);
|
||||
Disposer.dispose(editor);
|
||||
}
|
||||
}};
|
||||
return new AnAction[]{new CreateNewLibraryAction(getAddText(), getModelProvider(), myProject)};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract String getAddText();
|
||||
|
||||
public abstract LibraryTableModifiableModelProvider getModelProvider(final boolean editable);
|
||||
public abstract StructureLibraryTableModifiableModelProvider getModelProvider();
|
||||
|
||||
public abstract BaseLibrariesConfigurable getOppositeGroup();
|
||||
|
||||
protected void removeLibrary(final Library library) {
|
||||
final LibraryTable table = library.getTable();
|
||||
if (table != null) {
|
||||
getModelProvider(true).getModifiableModel().removeLibrary(library);
|
||||
getModelProvider().getModifiableModel().removeLibrary(library);
|
||||
myContext.getDaemonAnalyzer().removeElement(new LibraryProjectStructureElement(myContext, library));
|
||||
// TODO: myContext.invalidateModules(myContext.myLibraryDependencyCache.get(library.getName()));
|
||||
}
|
||||
@@ -266,7 +258,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
|
||||
|
||||
LOG.assertTrue(library != null);
|
||||
|
||||
final LibraryTable.ModifiableModel libsModel = configurable.getModelProvider(true).getModifiableModel();
|
||||
final LibraryTable.ModifiableModel libsModel = configurable.getModelProvider().getModifiableModel();
|
||||
final Library lib = libsModel.createLibrary(myNameTf.getText());
|
||||
final Library.ModifiableModel model = ((LibrariesModifiableModel)libsModel).getLibraryEditor(lib).getModel();
|
||||
for (OrderRootType type : OrderRootType.getAllTypes()) {
|
||||
|
||||
+2
-3
@@ -21,7 +21,6 @@ import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -63,8 +62,8 @@ public class GlobalLibrariesConfigurable extends BaseLibrariesConfigurable {
|
||||
return ServiceManager.getService(project, GlobalLibrariesConfigurable.class);
|
||||
}
|
||||
|
||||
public LibraryTableModifiableModelProvider getModelProvider(final boolean editable) {
|
||||
return myContext.getGlobalLibrariesProvider(editable);
|
||||
public StructureLibraryTableModifiableModelProvider getModelProvider() {
|
||||
return myContext.getGlobalLibrariesProvider();
|
||||
}
|
||||
|
||||
public BaseLibrariesConfigurable getOppositeGroup() {
|
||||
|
||||
+4
-4
@@ -248,10 +248,10 @@ public class LibrariesContainerFactory {
|
||||
@Nullable
|
||||
private LibraryTableModifiableModelProvider getProvider(LibraryLevel libraryLevel) {
|
||||
if (libraryLevel == LibraryLevel.PROJECT) {
|
||||
return myContext.getProjectLibrariesProvider(false);
|
||||
return myContext.getProjectLibrariesProvider();
|
||||
}
|
||||
else if (libraryLevel == LibraryLevel.GLOBAL) {
|
||||
return myContext.getGlobalLibrariesProvider(false);
|
||||
return myContext.getGlobalLibrariesProvider();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@@ -264,12 +264,12 @@ public class LibrariesContainerFactory {
|
||||
|
||||
@NotNull
|
||||
public VirtualFile[] getLibraryFiles(@NotNull final Library library, @NotNull final OrderRootType rootType) {
|
||||
LibrariesModifiableModel projectLibrariesModel = (LibrariesModifiableModel)myContext.getProjectLibrariesProvider(false).getModifiableModel();
|
||||
LibrariesModifiableModel projectLibrariesModel = myContext.getProjectLibrariesProvider().getModifiableModel();
|
||||
if (projectLibrariesModel.hasLibraryEditor(library)) {
|
||||
LibraryEditor libraryEditor = projectLibrariesModel.getLibraryEditor(library);
|
||||
return libraryEditor.getFiles(rootType);
|
||||
}
|
||||
LibrariesModifiableModel globalLibraries = (LibrariesModifiableModel)myContext.getGlobalLibrariesProvider(false).getModifiableModel();
|
||||
LibrariesModifiableModel globalLibraries = myContext.getGlobalLibrariesProvider().getModifiableModel();
|
||||
if (globalLibraries.hasLibraryEditor(library)) {
|
||||
LibraryEditor libraryEditor = globalLibraries.getLibraryEditor(library);
|
||||
return libraryEditor.getFiles(rootType);
|
||||
|
||||
+10
-8
@@ -21,6 +21,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
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;
|
||||
@@ -34,7 +35,7 @@ import java.util.*;
|
||||
*/
|
||||
|
||||
public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
|
||||
private final Map<Library, LibraryEditor> myLibrary2EditorMap = new HashMap<Library, LibraryEditor>();
|
||||
private final Map<Library, ExistingLibraryEditor> myLibrary2EditorMap = new HashMap<Library, ExistingLibraryEditor>();
|
||||
private final Set<Library> myRemovedLibraries = new HashSet<Library>();
|
||||
|
||||
private LibraryTable.ModifiableModel myLibrariesModifiableModel;
|
||||
@@ -96,15 +97,16 @@ public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
|
||||
}
|
||||
|
||||
public void deferredCommit(){
|
||||
for (LibraryEditor libraryEditor : new ArrayList<LibraryEditor>(myLibrary2EditorMap.values())) {
|
||||
final List<ExistingLibraryEditor> libraryEditors = new ArrayList<ExistingLibraryEditor>(myLibrary2EditorMap.values());
|
||||
myLibrary2EditorMap.clear();
|
||||
for (ExistingLibraryEditor libraryEditor : libraryEditors) {
|
||||
libraryEditor.commit(); // TODO: is seems like commit will recreate the editor, but it should not
|
||||
Disposer.dispose(libraryEditor);
|
||||
}
|
||||
if (!(myLibrary2EditorMap.isEmpty() && myRemovedLibraries.isEmpty())) {
|
||||
if (!libraryEditors.isEmpty() || !myRemovedLibraries.isEmpty()) {
|
||||
getLibrariesModifiableModel().commit();
|
||||
myLibrariesModifiableModel = null;
|
||||
}
|
||||
myLibrary2EditorMap.clear();
|
||||
myRemovedLibraries.clear();
|
||||
}
|
||||
|
||||
@@ -116,20 +118,20 @@ public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
|
||||
return myLibrary2EditorMap.containsKey(library);
|
||||
}
|
||||
|
||||
public LibraryEditor getLibraryEditor(Library library){
|
||||
public ExistingLibraryEditor getLibraryEditor(Library library){
|
||||
final Library source = ((LibraryImpl)library).getSource();
|
||||
if (source != null) {
|
||||
return getLibraryEditor(source);
|
||||
}
|
||||
LibraryEditor libraryEditor = myLibrary2EditorMap.get(library);
|
||||
ExistingLibraryEditor libraryEditor = myLibrary2EditorMap.get(library);
|
||||
if (libraryEditor == null){
|
||||
libraryEditor = createLibraryEditor(library);
|
||||
}
|
||||
return libraryEditor;
|
||||
}
|
||||
|
||||
private LibraryEditor createLibraryEditor(final Library library) {
|
||||
final LibraryEditor libraryEditor = new LibraryEditor(library, myLibraryEditorListener);
|
||||
private ExistingLibraryEditor createLibraryEditor(final Library library) {
|
||||
final ExistingLibraryEditor libraryEditor = new ExistingLibraryEditor(library, myLibraryEditorListener);
|
||||
myLibrary2EditorMap.put(library, libraryEditor);
|
||||
return libraryEditor;
|
||||
}
|
||||
|
||||
+5
-12
@@ -21,12 +21,10 @@ 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.LibraryTable;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -42,17 +40,17 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
|
||||
|
||||
private LibraryTableEditor myLibraryEditor;
|
||||
private final Library myLibrary;
|
||||
private final LibraryTableModifiableModelProvider myModel;
|
||||
private final StructureLibraryTableModifiableModelProvider myModel;
|
||||
private final Project myProject;
|
||||
private final LibraryProjectStructureElement myProjectStructureElement;
|
||||
private boolean myUpdatingName;
|
||||
|
||||
protected LibraryConfigurable(final LibraryTableModifiableModelProvider libraryTable,
|
||||
protected LibraryConfigurable(final StructureLibraryTableModifiableModelProvider modelProvider,
|
||||
final Library library,
|
||||
final Project project,
|
||||
final Runnable updateTree) {
|
||||
super(true, updateTree);
|
||||
myModel = libraryTable;
|
||||
myModel = modelProvider;
|
||||
myProject = project;
|
||||
myLibrary = library;
|
||||
final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myProject).getContext();
|
||||
@@ -60,9 +58,8 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
|
||||
}
|
||||
|
||||
public JComponent createOptionsPanel() {
|
||||
myLibraryEditor = LibraryTableEditor.editLibrary(myModel, myLibrary, myProject);
|
||||
myLibraryEditor = LibraryTableEditor.editLibrary(myProject, myModel.getModifiableModel().getLibraryEditor(myLibrary));
|
||||
final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myProject).getContext();
|
||||
myLibraryEditor.addLibraryEditorListener(context);
|
||||
myLibraryEditor.addListener(new Runnable() {
|
||||
public void run() {
|
||||
context.getDaemonAnalyzer().queueUpdate(myProjectStructureElement);
|
||||
@@ -89,11 +86,7 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
|
||||
}
|
||||
|
||||
public void disposeUIResources() {
|
||||
if (myLibraryEditor != null) {
|
||||
myLibraryEditor.cancelChanges();
|
||||
Disposer.dispose(myLibraryEditor);
|
||||
myLibraryEditor = null;
|
||||
}
|
||||
myLibraryEditor = null;
|
||||
}
|
||||
|
||||
public void setDisplayName(final String name) {
|
||||
|
||||
+2
-2
@@ -59,8 +59,8 @@ public class ProjectLibrariesConfigurable extends BaseLibrariesConfigurable {
|
||||
}
|
||||
|
||||
|
||||
public LibraryTableModifiableModelProvider getModelProvider(final boolean editable) {
|
||||
return myContext.getProjectLibrariesProvider(editable);
|
||||
public StructureLibraryTableModifiableModelProvider getModelProvider() {
|
||||
return myContext.getProjectLibrariesProvider();
|
||||
}
|
||||
|
||||
public BaseLibrariesConfigurable getOppositeGroup() {
|
||||
|
||||
+17
-26
@@ -19,9 +19,9 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.module.ModifiableModuleModel;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
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.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator;
|
||||
@@ -103,45 +103,35 @@ public class StructureConfigurableContext implements Disposable, LibraryEditorLi
|
||||
}
|
||||
}
|
||||
|
||||
public LibraryTableModifiableModelProvider getGlobalLibrariesProvider(final boolean tableEditable) {
|
||||
return createModifiableModelProvider(LibraryTablesRegistrar.APPLICATION_LEVEL, tableEditable);
|
||||
public StructureLibraryTableModifiableModelProvider getGlobalLibrariesProvider() {
|
||||
return createModifiableModelProvider(LibraryTablesRegistrar.APPLICATION_LEVEL);
|
||||
}
|
||||
|
||||
public LibraryTableModifiableModelProvider createModifiableModelProvider(final String level, final boolean isTableEditable) {
|
||||
final LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(level, myProject);
|
||||
return new LibraryTableModifiableModelProvider() {
|
||||
public LibraryTable.ModifiableModel getModifiableModel() {
|
||||
return myLevel2Providers.get(level);
|
||||
}
|
||||
|
||||
public String getTableLevel() {
|
||||
return table.getTableLevel();
|
||||
}
|
||||
|
||||
public LibraryTablePresentation getLibraryTablePresentation() {
|
||||
return table.getPresentation();
|
||||
}
|
||||
|
||||
public boolean isLibraryTableEditable() {
|
||||
return isTableEditable && table.isEditable();
|
||||
}
|
||||
};
|
||||
public StructureLibraryTableModifiableModelProvider createModifiableModelProvider(final String level) {
|
||||
return new StructureLibraryTableModifiableModelProvider(level, this);
|
||||
}
|
||||
|
||||
public LibraryTableModifiableModelProvider getProjectLibrariesProvider(final boolean tableEditable) {
|
||||
return createModifiableModelProvider(LibraryTablesRegistrar.PROJECT_LEVEL, tableEditable);
|
||||
public StructureLibraryTableModifiableModelProvider getProjectLibrariesProvider() {
|
||||
return createModifiableModelProvider(LibraryTablesRegistrar.PROJECT_LEVEL);
|
||||
}
|
||||
|
||||
|
||||
public List<LibraryTableModifiableModelProvider> getCustomLibrariesProviders(final boolean tableEditable) {
|
||||
public List<LibraryTableModifiableModelProvider> getCustomLibrariesProviders() {
|
||||
return ContainerUtil.map2List(LibraryTablesRegistrar.getInstance().getCustomLibraryTables(), new NotNullFunction<LibraryTable, LibraryTableModifiableModelProvider>() {
|
||||
@NotNull
|
||||
public LibraryTableModifiableModelProvider fun(final LibraryTable libraryTable) {
|
||||
return createModifiableModelProvider(libraryTable.getTableLevel(), tableEditable);
|
||||
return createModifiableModelProvider(libraryTable.getTableLevel());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public LibraryTable.ModifiableModel getModifiableLibraryTable(@NotNull LibraryTable table) {
|
||||
final String tableLevel = table.getTableLevel();
|
||||
if (tableLevel.equals(LibraryTableImplUtil.MODULE_LEVEL)) {
|
||||
return table.getModifiableModel();
|
||||
}
|
||||
return myLevel2Providers.get(tableLevel);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Library getLibrary(final String libraryName, final String libraryLevel) {
|
||||
@@ -187,4 +177,5 @@ public class StructureConfigurableContext implements Disposable, LibraryEditorLi
|
||||
public void clear() {
|
||||
myLevel2Providers.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+37
@@ -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.ui.configuration.projectRoot;
|
||||
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class StructureLibraryTableModifiableModelProvider implements LibraryTableModifiableModelProvider {
|
||||
private final String myLevel;
|
||||
private final StructureConfigurableContext myContext;
|
||||
|
||||
public StructureLibraryTableModifiableModelProvider(String level,
|
||||
final StructureConfigurableContext context) {
|
||||
myLevel = level;
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
public LibrariesModifiableModel getModifiableModel() {
|
||||
return myContext.myLevel2Providers.get(myLevel);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user