mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
specific library types can change presentation/behaviour of attach root buttons
This commit is contained in:
+12
-52
@@ -8,7 +8,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="1f4da" layout-manager="GridLayoutManager" row-count="9" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="0" vgap="6">
|
||||
<grid id="1f4da" layout-manager="GridLayoutManager" row-count="4" 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="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@@ -16,75 +16,35 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="f673d" class="javax.swing.JButton" binding="myAttachClassesButton">
|
||||
<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.attach.classes.button"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="3da7">
|
||||
<constraints>
|
||||
<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"/>
|
||||
<grid row="3" 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="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"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="733a5" class="javax.swing.JButton" binding="myAttachJavadocsButton">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="module.libraries.javadoc.attach.button"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="56f78" class="javax.swing.JButton" binding="myRemoveButton">
|
||||
<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="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="library.detach.action"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="47ce1" class="javax.swing.JButton" binding="myAttachUrlJavadocsButton">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="module.libraries.javadoc.url.button"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3a1fb" class="javax.swing.JButton" binding="myAttachJarDirectoriesButton">
|
||||
<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.attach.jar.directories.button"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="79b4b" class="javax.swing.JButton" binding="myAttachAnnotationsButton" 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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/ProjectBundle" key="attach.annotations.button"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1134d" class="javax.swing.JButton" binding="myAttachMoreButton" default-binding="true">
|
||||
<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="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.more.button"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="2f9aa" binding="myAttachButtonsPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<xy id="bc98" binding="myTreePanel" layout-manager="XYLayout" hgap="-1" vgap="-1">
|
||||
|
||||
+1
-1
@@ -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();
|
||||
|
||||
+1
-2
@@ -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<Library> {
|
||||
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) {
|
||||
|
||||
+165
@@ -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<? extends AttachRootButtonDescriptor> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -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 <T> void addFileChooserContext(DataKey<T> key, T value) {
|
||||
myLibraryRootsComponent.addFileChooserContext(key, value);
|
||||
public void setContextModule(Module module) {
|
||||
myLibraryRootsComponent.setContextModule(module);
|
||||
}
|
||||
|
||||
protected String getDimensionServiceKey() {
|
||||
|
||||
+44
-183
@@ -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<Runnable> myListeners = new ArrayList<Runnable>();
|
||||
@Nullable private final Project myProject;
|
||||
|
||||
private final Map<DataKey, Object> myFileChooserUserData = new HashMap<DataKey, Object>();
|
||||
private final Computable<LibraryEditor> myLibraryEditorComputable;
|
||||
private LibraryRootsComponentDescriptor myDescriptor;
|
||||
private Module myContextModule;
|
||||
|
||||
public LibraryRootsComponent(@Nullable Project project, @NotNull LibraryEditor libraryEditor) {
|
||||
this(project, new Computable.PredefinedValueComputable<LibraryEditor>(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 <T> void addFileChooserContext(DataKey<T> 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<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());
|
||||
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<Library.ModifiableModel> modelRef = Ref.create(null);
|
||||
final NullableComputable<Library.ModifiableModel> 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<Library.ModifiableModel>() {
|
||||
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<LibraryTableAttachHandler>(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;
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
@@ -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<P extends LibraryProperties> extends LibraryPr
|
||||
@NotNull
|
||||
public abstract P createDefaultProperties();
|
||||
|
||||
@Nullable
|
||||
public LibraryRootsComponentDescriptor createLibraryRootsComponentDescriptor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract LibraryPropertiesEditor createPropertiesEditor(@NotNull LibraryEditorComponent<P> properties);
|
||||
}
|
||||
|
||||
+54
@@ -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;
|
||||
}
|
||||
}
|
||||
+52
@@ -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);
|
||||
}
|
||||
}
|
||||
+25
@@ -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<? extends AttachRootButtonDescriptor> createAttachButtons();
|
||||
}
|
||||
Reference in New Issue
Block a user