From d503c0a01b1ffa9e549efc113f3c0abcef3bbd56 Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 1 Nov 2010 13:10:27 +0300 Subject: [PATCH] specific library types can change presentation/behaviour of attach root buttons --- .../LibraryRootsComponentForm.form | 64 +---- .../classpath/ClasspathPanelImpl.java | 2 +- .../classpath/NewLibraryChooser.java | 3 +- ...efaultLibraryRootsComponentDescriptor.java | 165 +++++++++++++ .../LibraryEditorDialogBase.java | 6 +- .../libraryEditor/LibraryRootsComponent.java | 227 ++++-------------- .../libraryEditor/LibraryTreeStructure.java | 4 +- .../openapi/roots/libraries/LibraryType.java | 6 + .../ui/AttachRootButtonDescriptor.java | 54 +++++ .../ui/AttachRootButtonDescriptorBase.java | 52 ++++ .../ui/LibraryRootsComponentDescriptor.java | 25 ++ 11 files changed, 365 insertions(+), 243 deletions(-) create mode 100644 java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/DefaultLibraryRootsComponentDescriptor.java create mode 100644 platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/AttachRootButtonDescriptor.java create mode 100644 platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/AttachRootButtonDescriptorBase.java create mode 100644 platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/LibraryRootsComponentDescriptor.java diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form index e394db950bef..0be7e0298846 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form @@ -8,7 +8,7 @@ - + @@ -16,75 +16,35 @@ - - - - - - - - - + - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java index 293cde8ab466..623523a41471 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java @@ -381,7 +381,7 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { provider = getStructureConfigurableContext().createModifiableModelProvider(table.getTableLevel()); } EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(ClasspathPanelImpl.this, provider, library, myState.getProject()); - dialog.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, getRootModel().getModule()); + dialog.setContextModule(getRootModel().getModule()); dialog.show(); myEntryTable.repaint(); ModuleStructureConfigurable.getInstance(myState.getProject()).getTree().repaint(); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/NewLibraryChooser.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/NewLibraryChooser.java index 47dbf09ba63c..b892182b9bd9 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/NewLibraryChooser.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/NewLibraryChooser.java @@ -17,7 +17,6 @@ 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; @@ -64,7 +63,7 @@ class NewLibraryChooser implements ClasspathElementChooser { registrar.getLibraryTable()); CreateNewLibraryDialog dialog = new CreateNewLibraryDialog(myParentComponent, myContext, new NewLibraryEditor(), tables, 1); final Module contextModule = DataKeys.MODULE_CONTEXT.getData(DataManager.getInstance().getDataContext(myParentComponent)); - dialog.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, contextModule); + dialog.setContextModule(contextModule); dialog.show(); myIsOk = dialog.isOK(); if (myIsOk) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/DefaultLibraryRootsComponentDescriptor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/DefaultLibraryRootsComponentDescriptor.java new file mode 100644 index 000000000000..adec368db738 --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/DefaultLibraryRootsComponentDescriptor.java @@ -0,0 +1,165 @@ +/* + * 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.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.ProjectBundle; +import com.intellij.openapi.projectRoots.ui.Util; +import com.intellij.openapi.roots.AnnotationOrderRootType; +import com.intellij.openapi.roots.JavadocOrderRootType; +import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.libraries.ui.AttachRootButtonDescriptor; +import com.intellij.openapi.roots.libraries.ui.AttachRootButtonDescriptorBase; +import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor; +import com.intellij.openapi.roots.ui.configuration.PathUIUtils; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.Arrays; +import java.util.List; + +/** + * @author nik + */ +public class DefaultLibraryRootsComponentDescriptor extends LibraryRootsComponentDescriptor { + @NotNull + @Override + public List createAttachButtons() { + return Arrays.asList(new AttachClassesAction(), new AttachJarDirectoriesAction(), new AttachSourcesAction(), + new AttachAnnotationsAction(), new AttachJavadocAction(), new AttachUrlJavadocAction()); + } + + private static class AttachClassesAction extends AttachRootButtonDescriptorBase { + private AttachClassesAction() { + super(OrderRootType.CLASSES, ProjectBundle.message("module.libraries.attach.classes.button")); + } + + public FileChooserDescriptor createChooserDescriptor() { + return new FileChooserDescriptor(false, true, true, false, false, true); + } + + public String getChooserTitle(final String libraryName) { + if (StringUtil.isEmpty(libraryName)) { + return ProjectBundle.message("library.attach.classes.action"); + } + else { + return ProjectBundle.message("library.attach.classes.to.library.action", libraryName); + } + } + + public String getChooserDescription() { + return ProjectBundle.message("library.attach.classes.description"); + } + } + + private static class AttachJarDirectoriesAction extends AttachRootButtonDescriptorBase { + private AttachJarDirectoriesAction() { + super(OrderRootType.CLASSES, ProjectBundle.message("module.libraries.attach.jar.directories.button")); + } + + public FileChooserDescriptor createChooserDescriptor() { + return new FileChooserDescriptor(false, true, false, false, false, true); + } + + public boolean addAsJarDirectories() { + return true; + } + + public String getChooserTitle(final String libraryName) { + if (StringUtil.isEmpty(libraryName)) { + return ProjectBundle.message("library.attach.jar.directory.action"); + } + else { + return ProjectBundle.message("library.attach.jar.directory.to.library.action", libraryName); + } + } + + public String getChooserDescription() { + return ProjectBundle.message("library.attach.jar.directory.description"); + } + } + + private class AttachSourcesAction extends AttachRootButtonDescriptorBase { + private AttachSourcesAction() { + super(OrderRootType.SOURCES, ProjectBundle.message("module.libraries.attach.sources.button")); + } + + public String getChooserTitle(final String libraryName) { + return ProjectBundle.message("library.attach.sources.action"); + } + + public String getChooserDescription() { + return ProjectBundle.message("library.attach.sources.description"); + } + + @NotNull + public VirtualFile[] scanForActualRoots(@NotNull final VirtualFile[] rootCandidates, JComponent parent) { + return PathUIUtils.scanAndSelectDetectedJavaSourceRoots(parent, rootCandidates); + } + } + + private static class AttachAnnotationsAction extends AttachRootButtonDescriptorBase { + private AttachAnnotationsAction() { + super(AnnotationOrderRootType.getInstance(), ProjectBundle.message("attach.annotations.button")); + } + + public String getChooserTitle(final String libraryName) { + return ProjectBundle.message("library.attach.external.annotations.action"); + } + + public String getChooserDescription() { + return ProjectBundle.message("library.attach.external.annotations.description"); + } + + @Override + public FileChooserDescriptor createChooserDescriptor() { + return new FileChooserDescriptor(false, true, false, false, false, false); + } + } + + private static class AttachJavadocAction extends AttachRootButtonDescriptorBase { + private AttachJavadocAction() { + super(JavadocOrderRootType.getInstance(), ProjectBundle.message("module.libraries.javadoc.attach.button")); + } + + public String getChooserTitle(final String libraryName) { + return ProjectBundle.message("library.attach.javadoc.action"); + } + + public String getChooserDescription() { + return ProjectBundle.message("library.attach.javadoc.description"); + } + } + + private static class AttachUrlJavadocAction extends AttachRootButtonDescriptor { + private AttachUrlJavadocAction() { + super(JavadocOrderRootType.getInstance(), ProjectBundle.message("module.libraries.javadoc.url.button")); + } + + @Override + public VirtualFile[] selectFiles(@NotNull JComponent parent, + @Nullable VirtualFile initialSelection, + @Nullable Module contextModule, + @Nullable String libraryName) { + final VirtualFile vFile = Util.showSpecifyJavadocUrlDialog(parent); + if (vFile != null) { + return new VirtualFile[]{vFile}; + } + return VirtualFile.EMPTY_ARRAY; + } + } +} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorDialogBase.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorDialogBase.java index fa0e0dcb770d..4272ace878e7 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorDialogBase.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorDialogBase.java @@ -15,7 +15,7 @@ */ package com.intellij.openapi.roots.ui.configuration.libraryEditor; -import com.intellij.openapi.actionSystem.DataKey; +import com.intellij.openapi.module.Module; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.impl.ModuleLibraryTable; import com.intellij.openapi.roots.libraries.LibraryTable; @@ -44,8 +44,8 @@ public abstract class LibraryEditorDialogBase extends DialogWrapper { Disposer.register(getDisposable(), myLibraryRootsComponent); } - public void addFileChooserContext(DataKey key, T value) { - myLibraryRootsComponent.addFileChooserContext(key, value); + public void setContextModule(Module module) { + myLibraryRootsComponent.setContextModule(module); } protected String getDimensionServiceKey() { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java index 5c3b8a121f23..a32fa074a2de 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java @@ -19,32 +19,29 @@ import com.intellij.ide.IconUtilEx; import com.intellij.ide.util.treeView.AbstractTreeStructure; 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.fileChooser.FileChooser; -import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectBundle; -import com.intellij.openapi.projectRoots.ui.Util; -import com.intellij.openapi.roots.AnnotationOrderRootType; -import com.intellij.openapi.roots.JavadocOrderRootType; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.impl.libraries.LibraryImpl; -import com.intellij.openapi.roots.libraries.*; +import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.libraries.LibraryProperties; +import com.intellij.openapi.roots.libraries.LibraryType; +import com.intellij.openapi.roots.libraries.LibraryUtil; +import com.intellij.openapi.roots.libraries.ui.AttachRootButtonDescriptor; import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent; import com.intellij.openapi.roots.libraries.ui.LibraryPropertiesEditor; +import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor; import com.intellij.openapi.roots.ui.configuration.ModuleEditor; -import com.intellij.openapi.roots.ui.configuration.PathUIUtils; import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager; import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable; +import com.intellij.openapi.ui.VerticalFlowLayout; import com.intellij.openapi.ui.ex.MultiLineLabel; 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.text.StringUtil; import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.ex.http.HttpFileSystem; import com.intellij.ui.ScrollPaneFactory; @@ -80,16 +77,11 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent private JPanel myPanel; private JButton myRemoveButton; - private JButton myAttachClassesButton; - private JButton myAttachJarDirectoriesButton; - private JButton myAttachSourcesButton; - private JButton myAttachJavadocsButton; - private JButton myAttachUrlJavadocsButton; private JPanel myTreePanel; - private JButton myAttachAnnotationsButton; private JButton myAttachMoreButton; private MultiLineLabel myPropertiesLabel; private JPanel myPropertiesPanel; + private JPanel myAttachButtonsPanel; private LibraryPropertiesEditor myPropertiesEditor; private Tree myTree; private LibraryTableTreeBuilder myTreeBuilder; @@ -99,8 +91,9 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent private final Collection myListeners = new ArrayList(); @Nullable private final Project myProject; - private final Map myFileChooserUserData = new HashMap(); private final Computable myLibraryEditorComputable; + private LibraryRootsComponentDescriptor myDescriptor; + private Module myContextModule; public LibraryRootsComponent(@Nullable Project project, @NotNull LibraryEditor libraryEditor) { this(project, new Computable.PredefinedValueComputable(libraryEditor)); @@ -112,12 +105,16 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent final LibraryEditor editor = getLibraryEditor(); final LibraryType type = editor.getType(); if (type != null) { + myDescriptor = type.createLibraryRootsComponentDescriptor(); //noinspection unchecked myPropertiesEditor = type.createPropertiesEditor(this); if (myPropertiesEditor != null) { myPropertiesPanel.add(myPropertiesEditor.createComponent(), BorderLayout.CENTER); } } + if (myDescriptor == null) { + myDescriptor = new DefaultLibraryRootsComponentDescriptor(); + } init(new LibraryTreeStructure(this)); updateProperties(); } @@ -151,21 +148,21 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent myTreePanel.setLayout(new BorderLayout()); myTreePanel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER); - myRemoveButton.addActionListener(new RemoveAction()); - myAttachClassesButton.addActionListener(new AttachClassesAction()); - myAttachJarDirectoriesButton.addActionListener(new AttachJarDirectoriesAction()); - myAttachSourcesButton.addActionListener(new AttachSourcesAction()); - myAttachJavadocsButton.addActionListener(new AttachJavadocAction()); - myAttachUrlJavadocsButton.addActionListener(new AttachUrlJavadocAction()); - myAttachAnnotationsButton.addActionListener(new AttachAnnotationsAction()); + final JPanel buttonsPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 5, true, false)); + for (AttachRootButtonDescriptor descriptor : myDescriptor.createAttachButtons()) { + JButton button = new JButton(descriptor.getButtonText()); + button.addActionListener(new AttachItemAction(descriptor)); + buttonsPanel.add(button); + } + myAttachButtonsPanel.add(buttonsPanel, BorderLayout.CENTER); + myRemoveButton.addActionListener(new RemoveAction()); final LibraryTableAttachHandler[] handlers = LibraryTableAttachHandler.EP_NAME.getExtensions(); - final LibraryEditor libraryEditor = getLibraryEditor(); - if (handlers.length == 0 || myProject == null) { + if (handlers.length == 0 || myProject == null || myDescriptor != null) { myAttachMoreButton.setVisible(false); } else { - myAttachMoreButton.addActionListener(new AttachMoreAction(handlers, libraryEditor)); + myAttachMoreButton.addActionListener(new AttachMoreAction(handlers)); if (handlers.length == 1) { myAttachMoreButton.setText(handlers[0].getLongName()); } @@ -183,8 +180,8 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent return myPanel; } - public void addFileChooserContext(DataKey key, T value) { - myFileChooserUserData.put(key, value); + public void setContextModule(Module module) { + myContextModule = module; } public LibraryEditor getLibraryEditor() { @@ -259,40 +256,20 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent } } - private abstract class AttachItemAction implements ActionListener { - private final FileChooserDescriptor myDescriptor; + private class AttachItemAction implements ActionListener { private VirtualFile myLastChosen = null; + private final AttachRootButtonDescriptor myDescriptor; - protected abstract String getTitle(); - protected abstract String getDescription(); - protected abstract OrderRootType getRootType(); - - protected AttachItemAction() { - myDescriptor = createDescriptor(); + protected AttachItemAction(AttachRootButtonDescriptor descriptor) { + myDescriptor = descriptor; } - protected FileChooserDescriptor createDescriptor() { - return new FileChooserDescriptor(false, true, true, false, true, true); - } - - protected VirtualFile[] scanForActualRoots(VirtualFile[] rootCandidates) { - return rootCandidates; - } - - protected boolean addAsJarDirectories() { - return false; - } - public final void actionPerformed(ActionEvent e) { - myDescriptor.setTitle(getTitle()); - myDescriptor.setDescription(getDescription()); - for (Map.Entry entry : myFileChooserUserData.entrySet()) { - myDescriptor.putUserData(entry.getKey(), entry.getValue()); - } VirtualFile toSelect = getFileToSelect(); - final VirtualFile[] attachedFiles = - attachFiles(scanForActualRoots(FileChooser.chooseFiles(myPanel, myDescriptor, toSelect)), getRootType(), - addAsJarDirectories()); + final VirtualFile[] files = myDescriptor.selectFiles(myPanel, toSelect, myContextModule, getLibraryEditor().getName()); + if (files.length == 0) return; + + final VirtualFile[] attachedFiles = attachFiles(myDescriptor.scanForActualRoots(files, myPanel), myDescriptor.getRootType(), myDescriptor.addAsJarDirectories()); if (attachedFiles.length > 0) { myLastChosen = attachedFiles[0]; } @@ -368,121 +345,6 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent return VfsUtil.toVirtualFileArray(chosenFilesSet); } - private class AttachClassesAction extends AttachItemAction { - @SuppressWarnings({"RefusedBequest"}) - protected FileChooserDescriptor createDescriptor() { - return new FileChooserDescriptor(false, true, true, false, false, true); - } - - protected String getTitle() { - final String name = getLibraryEditor().getName(); - if (StringUtil.isEmpty(name)) { - return ProjectBundle.message("library.attach.classes.action"); - } - else { - return ProjectBundle.message("library.attach.classes.to.library.action", name); - } - } - - protected String getDescription() { - return ProjectBundle.message("library.attach.classes.description"); - } - - protected OrderRootType getRootType() { - return OrderRootType.CLASSES; - } - } - - private class AttachJarDirectoriesAction extends AttachItemAction { - @SuppressWarnings({"RefusedBequest"}) - protected FileChooserDescriptor createDescriptor() { - return new FileChooserDescriptor(false, true, false, false, false, true); - } - - protected boolean addAsJarDirectories() { - return true; - } - - protected String getTitle() { - 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.to.library.action", name); - } - } - - protected String getDescription() { - return ProjectBundle.message("library.attach.jar.directory.description"); - } - - protected OrderRootType getRootType() { - return OrderRootType.CLASSES; - } - } - - private class AttachSourcesAction extends AttachItemAction { - protected String getTitle() { - return ProjectBundle.message("library.attach.sources.action"); - } - - protected String getDescription() { - return ProjectBundle.message("library.attach.sources.description"); - } - - protected OrderRootType getRootType() { - return OrderRootType.SOURCES; - } - - protected VirtualFile[] scanForActualRoots(final VirtualFile[] rootCandidates) { - return PathUIUtils.scanAndSelectDetectedJavaSourceRoots(myPanel, rootCandidates); - } - } - - private class AttachAnnotationsAction extends AttachItemAction { - protected String getTitle() { - return ProjectBundle.message("library.attach.external.annotations.action"); - } - - protected String getDescription() { - return ProjectBundle.message("library.attach.external.annotations.description"); - } - - protected OrderRootType getRootType() { - return AnnotationOrderRootType.getInstance(); - } - - @Override - protected FileChooserDescriptor createDescriptor() { - return new FileChooserDescriptor(false, true, false, false, false, false); - } - } - - private class AttachJavadocAction extends AttachItemAction { - protected String getTitle() { - return ProjectBundle.message("library.attach.javadoc.action"); - } - - protected String getDescription() { - return ProjectBundle.message("library.attach.javadoc.description"); - } - - protected OrderRootType getRootType() { - return JavadocOrderRootType.getInstance(); - } - } - - private class AttachUrlJavadocAction implements ActionListener { - public void actionPerformed(ActionEvent e) { - final VirtualFile vFile = Util.showSpecifyJavadocUrlDialog(myPanel); - if (vFile != null) { - attachFiles(new VirtualFile[] {vFile}, JavadocOrderRootType.getInstance(), false); - } - myTree.requestFocus(); - } - } - private class RemoveAction implements ActionListener { public void actionPerformed(ActionEvent e) { final Object[] selectedElements = getSelectedElements(); @@ -657,24 +519,23 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent private class AttachMoreAction implements ActionListener { private final LibraryTableAttachHandler[] myHandlers; - private final LibraryEditor myLibraryEditor; - public AttachMoreAction(LibraryTableAttachHandler[] handlers, final LibraryEditor libraryEditor) { + public AttachMoreAction(LibraryTableAttachHandler[] handlers) { myHandlers = handlers; - myLibraryEditor = libraryEditor; } public void actionPerformed(ActionEvent e) { + final LibraryEditor libraryEditor = getLibraryEditor(); final Ref modelRef = Ref.create(null); final NullableComputable computable; - if (myLibraryEditor instanceof ExistingLibraryEditor) { - final ExistingLibraryEditor libraryEditor = (ExistingLibraryEditor)myLibraryEditor; + if (libraryEditor instanceof ExistingLibraryEditor) { + final ExistingLibraryEditor existingLibraryEditor = (ExistingLibraryEditor)libraryEditor; //todo[nik, greg] actually we cannot reliable find target library if the editor is closed so jars are downloaded under the modal progress dialog now computable = new NullableComputable() { public Library.ModifiableModel compute() { if (myTreeBuilder == null) { // The following lines were born in severe pain & suffering, please respect - final Library library = libraryEditor.getLibrary(); + final Library library = existingLibraryEditor.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; @@ -686,7 +547,7 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent return model; } else { - return libraryEditor.getModel(); + return existingLibraryEditor.getModel(); } } }; @@ -703,8 +564,8 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { if (myTreeBuilder != null) myTreeBuilder.queueUpdate(); - if (myProject != null && myLibraryEditor instanceof ExistingLibraryEditor) { - ModuleStructureConfigurable.getInstance(myProject).fireItemsChangeListener(((ExistingLibraryEditor)myLibraryEditor).getLibrary()); + if (myProject != null && libraryEditor instanceof ExistingLibraryEditor) { + ModuleStructureConfigurable.getInstance(myProject).fireItemsChangeListener(((ExistingLibraryEditor)libraryEditor).getLibrary()); } } }); @@ -718,7 +579,7 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent } }; if (myHandlers.length == 1) { - myHandlers[0].performAttach(myProject, myLibraryEditor, computable).doWhenDone(successRunnable).doWhenRejected(rejectRunnable); + myHandlers[0].performAttach(myProject, libraryEditor, computable).doWhenDone(successRunnable).doWhenRejected(rejectRunnable); } else { final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep(null, myHandlers) { @@ -734,7 +595,7 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent public PopupStep onChosen(final LibraryTableAttachHandler handler, final boolean finalChoice) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { - handler.performAttach(myProject, myLibraryEditor, computable).doWhenProcessed(successRunnable).doWhenRejected(rejectRunnable); + handler.performAttach(myProject, libraryEditor, computable).doWhenProcessed(successRunnable).doWhenRejected(rejectRunnable); } }); return PopupStep.FINAL_CHOICE; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTreeStructure.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTreeStructure.java index 9df0b60662a4..0f81d98cae64 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTreeStructure.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTreeStructure.java @@ -28,8 +28,8 @@ import java.util.Arrays; public class LibraryTreeStructure extends AbstractTreeStructure { private final Object myRootElement; - protected NodeDescriptor myRootElementDescriptor; - protected final LibraryRootsComponent myParentEditor; + private final NodeDescriptor myRootElementDescriptor; + private final LibraryRootsComponent myParentEditor; public LibraryTreeStructure(LibraryRootsComponent parentElement) { myParentEditor = parentElement; diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryType.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryType.java index e25b81fa6bea..fc1f2c0a4f07 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryType.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryType.java @@ -18,6 +18,7 @@ package com.intellij.openapi.roots.libraries; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent; import com.intellij.openapi.roots.libraries.ui.LibraryPropertiesEditor; +import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,6 +38,11 @@ public abstract class LibraryType

extends LibraryPr @NotNull public abstract P createDefaultProperties(); + @Nullable + public LibraryRootsComponentDescriptor createLibraryRootsComponentDescriptor() { + return null; + } + @Nullable public abstract LibraryPropertiesEditor createPropertiesEditor(@NotNull LibraryEditorComponent

properties); } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/AttachRootButtonDescriptor.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/AttachRootButtonDescriptor.java new file mode 100644 index 000000000000..29cadc4f31da --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/AttachRootButtonDescriptor.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.libraries.ui; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +/** + * @author nik + */ +public abstract class AttachRootButtonDescriptor { + private final OrderRootType myOrderRootType; + protected final String myButtonText; + + protected AttachRootButtonDescriptor(@NotNull OrderRootType orderRootType, @NotNull String buttonText) { + myOrderRootType = orderRootType; + myButtonText = buttonText; + } + + public abstract VirtualFile[] selectFiles(@NotNull JComponent parent, @Nullable VirtualFile initialSelection, + @Nullable Module contextModule, @Nullable String libraryName); + + public String getButtonText() { + return myButtonText; + } + + public OrderRootType getRootType() { + return myOrderRootType; + } + + public boolean addAsJarDirectories() { + return false; + } + + @NotNull + public VirtualFile[] scanForActualRoots(@NotNull VirtualFile[] rootCandidates, JComponent parent) { + return rootCandidates; + } +} diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/AttachRootButtonDescriptorBase.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/AttachRootButtonDescriptorBase.java new file mode 100644 index 000000000000..c08e182cdb4d --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/AttachRootButtonDescriptorBase.java @@ -0,0 +1,52 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.libraries.ui; + +import com.intellij.openapi.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.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +/** +* @author nik +*/ +public abstract class AttachRootButtonDescriptorBase extends AttachRootButtonDescriptor { + public AttachRootButtonDescriptorBase(@NotNull OrderRootType rootType, @NotNull String buttonText) { + super(rootType, buttonText); + } + + public FileChooserDescriptor createChooserDescriptor() { + return new FileChooserDescriptor(false, true, true, false, true, true); + } + + public abstract String getChooserTitle(final @Nullable String libraryName); + public abstract String getChooserDescription(); + + @Override + public VirtualFile[] selectFiles(final @NotNull JComponent parent, @Nullable VirtualFile initialSelection, + final @Nullable Module contextModule, @Nullable String libraryName) { + final FileChooserDescriptor chooserDescriptor = createChooserDescriptor(); + chooserDescriptor.setTitle(getChooserTitle(libraryName)); + chooserDescriptor.setDescription(getChooserDescription()); + if (contextModule != null) { + chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, contextModule); + } + return FileChooser.chooseFiles(parent, chooserDescriptor, initialSelection); + } +} diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/LibraryRootsComponentDescriptor.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/LibraryRootsComponentDescriptor.java new file mode 100644 index 000000000000..73e9bba008c2 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/LibraryRootsComponentDescriptor.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.libraries.ui; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author nik + */ +public abstract class LibraryRootsComponentDescriptor { + @NotNull + public abstract List createAttachButtons(); +}