groovy support configuration panels replaced by new editor

This commit is contained in:
nik
2010-10-01 17:10:38 +04:00
parent 7f4ada79e7
commit fff4e60d2c
39 changed files with 746 additions and 929 deletions
@@ -18,6 +18,7 @@ package com.intellij.facet.impl.ui.libraries;
import com.intellij.facet.ui.libraries.LibraryDownloadInfo;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryDownloadDescription;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.ui.CheckBoxList;
@@ -45,13 +46,15 @@ public class DownloadingOptionsDialog extends DialogWrapper {
private JPanel myNameWrappingPanel;
private final LibraryCompositionSettings mySettings;
private final LibraryNameAndLevelPanel myNameAndLevelPanel;
private LibraryDownloadDescription myDownloadDescription;
protected DownloadingOptionsDialog(Component parent, LibraryCompositionSettings settings) {
super(parent, true);
setTitle("Downloading Options");
mySettings = settings;
final List<LibraryDownloadInfo> downloads = settings.getLibraryDescription().getDownloads();
myDownloadDescription = settings.getLibraryDescription().getDownloadDescription();
final List<LibraryDownloadInfo> downloads = myDownloadDescription.getDownloads();
myFilesList.setModel(new CollectionListModel(ContainerUtil.map2Array(downloads, JCheckBox.class, new Function<LibraryDownloadInfo, JCheckBox>() {
@Override
public JCheckBox fun(LibraryDownloadInfo libraryInfo) {
@@ -92,7 +95,7 @@ public class DownloadingOptionsDialog extends DialogWrapper {
mySettings.setDirectoryForDownloadedLibrariesPath(myDirectoryField.getText());
List<LibraryDownloadInfo> selected = new ArrayList<LibraryDownloadInfo>();
List<LibraryDownloadInfo> downloads = mySettings.getLibraryDescription().getDownloads();
List<LibraryDownloadInfo> downloads = myDownloadDescription.getDownloads();
for (int i = 0; i < downloads.size(); i++) {
if (myFilesList.isItemSelected(i)) {
selected.add(downloads.get(i));
@@ -24,18 +24,12 @@ import com.intellij.facet.ui.libraries.FacetLibrariesValidator;
import com.intellij.facet.ui.libraries.FacetLibrariesValidatorDescription;
import com.intellij.facet.ui.libraries.LibraryInfo;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.roots.ui.configuration.libraries.AddCustomLibraryDialog;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import com.intellij.ide.util.frameworkSupport.CustomLibraryDescriptionImpl;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ModuleRootModel;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Processor;
@@ -93,10 +87,8 @@ public class FacetLibrariesValidatorImpl extends FacetLibrariesValidator {
String missingJars = IdeBundle.message("label.missed.libraries.prefix") + " " + info.getMissingJarsText();
LibraryInfo[] missingLibraries = info.getLibraryInfos();
VirtualFile baseDir = myContext.getModule().getProject().getBaseDir();
final String baseDirPath = baseDir != null ? baseDir.getPath() : "";
CustomLibraryDescription description = new CustomLibraryDescriptionImpl(missingLibraries, myDescription.getDefaultLibraryName());
return new ValidationResult(missingJars, new LibrariesQuickFix(description, baseDirPath));
return new ValidationResult(missingJars, new LibrariesQuickFix(description));
}
private void onChange() {
@@ -126,59 +118,19 @@ public class FacetLibrariesValidatorImpl extends FacetLibrariesValidator {
}
private class LibrariesQuickFix extends FacetConfigurationQuickFix {
private String myBaseDirPath;
private CustomLibraryDescription myDescription;
public LibrariesQuickFix(CustomLibraryDescription description, String baseDirPath) {
public LibrariesQuickFix(CustomLibraryDescription description) {
super(IdeBundle.message("missing.libraries.fix.button"));
myDescription = description;
myBaseDirPath = baseDirPath;
}
public void run(final JComponent place) {
final LibraryCompositionSettings settings = new LibraryCompositionSettings(myDescription, myBaseDirPath);
LibraryOptionsPanel panel = new LibraryOptionsPanel(settings, myContext.getLibrariesContainer(), false);
LibraryCompositionDialog dialog = new LibraryCompositionDialog(place, panel);
AddCustomLibraryDialog dialog = AddCustomLibraryDialog.createDialog(myDescription, myContext.getLibrariesContainer(),
myContext.getModule(), myContext.getModifiableRootModel(), null);
dialog.show();
Disposer.dispose(settings);
myAddedLibraries.addAll(dialog.getAddedLibraries());
onChange();
}
}
private class LibraryCompositionDialog extends DialogWrapper {
private final LibraryOptionsPanel myPanel;
private LibraryCompositionDialog(final JComponent parent, final LibraryOptionsPanel panel) {
super(parent, true);
setTitle(IdeBundle.message("specify.libraries.dialog.title"));
myPanel = panel;
init();
}
protected JComponent createCenterPanel() {
return myPanel.getMainPanel();
}
protected void doOKAction() {
myPanel.apply();
final LibraryCompositionSettings settings = myPanel.getSettings();
final LibrariesContainer librariesContainer = myContext.getLibrariesContainer();
if (settings.downloadFiles(myPanel.getMainPanel())) {
ModifiableRootModel rootModel = myContext.getModifiableRootModel();
if (rootModel == null) {
final ModifiableRootModel model = ModuleRootManager.getInstance(myContext.getModule()).getModifiableModel();
new WriteAction() {
protected void run(final Result result) {
settings.addLibraries(model, myAddedLibraries, librariesContainer);
model.commit();
}
}.execute();
}
else {
settings.addLibraries(rootModel, myAddedLibraries, librariesContainer);
}
super.doOKAction();
}
}
}
}
@@ -16,11 +16,12 @@
package com.intellij.facet.impl.ui.libraries;
import com.intellij.facet.ui.libraries.LibraryDownloadInfo;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryDownloadDescription;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
@@ -58,8 +59,11 @@ public class LibraryCompositionSettings implements Disposable {
final @NotNull String baseDirectoryForDownloadedFiles) {
myLibraryDescription = libraryDescription;
myBaseDirectoryForDownloadedFiles = baseDirectoryForDownloadedFiles;
myDownloadedLibraryName = libraryDescription.getDefaultLibraryName();
mySelectedDownloads = myLibraryDescription.getDownloads();
final LibraryDownloadDescription downloadDescription = myLibraryDescription.getDownloadDescription();
if (downloadDescription != null) {
myDownloadedLibraryName = downloadDescription.getDefaultLibraryName();
mySelectedDownloads = downloadDescription.getDownloads();
}
}
public ExistingLibraryEditor getOrCreateEditor(@NotNull Library library) {
@@ -118,20 +122,19 @@ public class LibraryCompositionSettings implements Disposable {
}
public boolean downloadFiles(final @NotNull JComponent parent) {
if (myDownloadLibraries) {
if (!myLibraryDescription.getDownloads().isEmpty()) {
LibraryDownloadInfo[] toDownload = mySelectedDownloads.toArray(new LibraryDownloadInfo[mySelectedDownloads.size()]);
LibraryDownloader downloader = new LibraryDownloader(toDownload, null, parent,
getDirectoryForDownloadedLibrariesPath(), myDownloadedLibraryName);
VirtualFile[] files = downloader.download();
if (files.length != toDownload.length) {
return false;
}
myNewLibraryEditor = new NewLibraryEditor();
myNewLibraryEditor.setName(myDownloadedLibraryName);
for (VirtualFile file : files) {
myNewLibraryEditor.addRoot(file, OrderRootType.CLASSES);
}
final LibraryDownloadDescription downloadDescription = myLibraryDescription.getDownloadDescription();
if (myDownloadLibraries && downloadDescription != null) {
LibraryDownloadInfo[] toDownload = mySelectedDownloads.toArray(new LibraryDownloadInfo[mySelectedDownloads.size()]);
LibraryDownloader downloader = new LibraryDownloader(toDownload, null, parent,
getDirectoryForDownloadedLibrariesPath(), myDownloadedLibraryName);
VirtualFile[] files = downloader.download();
if (files.length != toDownload.length) {
return false;
}
myNewLibraryEditor = new NewLibraryEditor();
myNewLibraryEditor.setName(myDownloadedLibraryName);
for (VirtualFile file : files) {
myNewLibraryEditor.addRoot(file, OrderRootType.CLASSES);
}
}
return true;
@@ -20,6 +20,7 @@ import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.ProjectStructureDialogCellAppearanceUtils;
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryDownloadDescription;
import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
@@ -126,7 +127,7 @@ public class LibraryOptionsPanel {
});
myExistingLibraryComboBox.setRenderer(new LibraryListCellRenderer());
boolean canDownload = !mySettings.getLibraryDescription().getDownloads().isEmpty();
boolean canDownload = mySettings.getLibraryDescription().getDownloadDescription() != null;
myDownloadRadioButton.setVisible(canDownload);
myButtonEnumModel.setSelected(libraries.isEmpty() && canDownload ? Choice.DOWNLOAD : Choice.USE_LIBRARY);
@@ -241,7 +242,7 @@ public class LibraryOptionsPanel {
showConfigurePanel = false;
}
if (!showConfigurePanel) {
if (!showConfigurePanel && mySettings.getLibraryDescription().getDownloadDescription() != null) {
//show the longest message on the hidden card to ensure that dialog won't jump if user selects another option
message = getDownloadFilesMessage();
}
@@ -259,9 +260,10 @@ public class LibraryOptionsPanel {
else {
path = PathUtil.getFileName(downloadPath);
}
final LibraryDownloadDescription downloadDescription = mySettings.getLibraryDescription().getDownloadDescription();
return MessageFormat.format("{0} jar(s) will be downloaded into <b>{1}</b> directory <br>" +
"{2} library <b>{3}</b> will be created",
mySettings.getLibraryDescription().getDownloads().size(),
downloadDescription.getDownloads().size(),
path,
mySettings.getLibraryLevel(),
mySettings.getDownloadedLibraryName());
@@ -23,6 +23,7 @@ import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryDownloadDescription;
import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
import com.intellij.openapi.util.Condition;
@@ -40,16 +41,17 @@ import java.util.List;
public class CustomLibraryDescriptionImpl extends CustomLibraryDescription {
private final LibraryInfo[] myLibraryInfos;
private String myDefaultLibraryName;
private final List<LibraryDownloadInfo> myDownloads;
private final LibraryDownloadDescription myDownloadDescription;
private final Condition<List<VirtualFile>> mySuitableLibraryCondition;
public CustomLibraryDescriptionImpl(@NotNull LibraryInfo[] libraryInfos, @NotNull String defaultLibraryName) {
myLibraryInfos = libraryInfos;
myDefaultLibraryName = defaultLibraryName;
myDownloads = new ArrayList<LibraryDownloadInfo>();
List<LibraryDownloadInfo> downloads = new ArrayList<LibraryDownloadInfo>();
for (LibraryInfo info : libraryInfos) {
ContainerUtil.addIfNotNull(myDownloads, info.getDownloadingInfo());
ContainerUtil.addIfNotNull(downloads, info.getDownloadingInfo());
}
myDownloadDescription = !downloads.isEmpty() ? new LibraryDownloadDescription(defaultLibraryName, downloads) : null;
mySuitableLibraryCondition = new Condition<List<VirtualFile>>() {
@Override
public boolean value(List<VirtualFile> virtualFiles) {
@@ -59,16 +61,9 @@ public class CustomLibraryDescriptionImpl extends CustomLibraryDescription {
};
}
@NotNull
@Override
public String getDefaultLibraryName() {
return myDefaultLibraryName;
}
@NotNull
@Override
public List<LibraryDownloadInfo> getDownloads() {
return myDownloads;
public LibraryDownloadDescription getDownloadDescription() {
return myDownloadDescription;
}
@NotNull
@@ -0,0 +1,35 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.util.frameworkSupport;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public class FrameworkVersionWithLibrary extends FrameworkVersion {
private CustomLibraryDescription myLibraryDescription;
public FrameworkVersionWithLibrary(@NotNull String versionName, boolean isDefault, CustomLibraryDescription libraryDescription) {
super(versionName, isDefault);
myLibraryDescription = libraryDescription;
}
public CustomLibraryDescription getLibraryDescription() {
return myLibraryDescription;
}
}
@@ -173,29 +173,35 @@ public class AddSupportForFrameworksPanel implements Disposable {
optionsPanel.add(separator);
final FrameworkSupportConfigurable configurable = node.getConfigurable();
optionsPanel.add(configurable.getComponent());
final JComponent component = configurable.getComponent();
if (component != null) {
optionsPanel.add(component);
}
final boolean addSeparator = component != null;
final JPanel librariesOptionsPanelWrapper = new JPanel(new BorderLayout());
optionsPanel.add(librariesOptionsPanelWrapper);
configurable.addListener(new FrameworkSupportConfigurableListener() {
public void frameworkVersionChanged() {
librariesOptionsPanelWrapper.removeAll();
addLibrariesOptionsPanel(node, librariesOptionsPanelWrapper);
addLibrariesOptionsPanel(node, librariesOptionsPanelWrapper, addSeparator);
librariesOptionsPanelWrapper.revalidate();
}
});
addLibrariesOptionsPanel(node, librariesOptionsPanelWrapper);
addLibrariesOptionsPanel(node, librariesOptionsPanelWrapper, addSeparator);
myOptionsPanel.add(id, optionsPanel);
myInitializedOptionsPanelIds.add(id);
}
}
private void addLibrariesOptionsPanel(FrameworkSupportNode node, JPanel librariesOptionsPanelWrapper) {
private void addLibrariesOptionsPanel(FrameworkSupportNode node, JPanel librariesOptionsPanelWrapper, boolean addSeparator) {
final LibraryOptionsPanel libraryOptionsPanel = node.getLibraryCompositionOptionsPanel(myLibrariesContainer);
if (libraryOptionsPanel != null) {
JComponent separator = SeparatorFactory.createSeparator("Libraries", null);
separator.setBorder(IdeBorderFactory.createEmptyBorder(5, 0, 5, 5));
librariesOptionsPanelWrapper.add(BorderLayout.NORTH, separator);
if (addSeparator) {
JComponent separator = SeparatorFactory.createSeparator("Libraries", null);
separator.setBorder(IdeBorderFactory.createEmptyBorder(5, 0, 5, 5));
librariesOptionsPanelWrapper.add(BorderLayout.NORTH, separator);
}
librariesOptionsPanelWrapper.add(BorderLayout.CENTER, libraryOptionsPanel.getMainPanel());
}
}
@@ -76,6 +76,10 @@ public class FrameworkSupportNode extends CheckedTreeNode {
FrameworkVersion version = myConfigurable.getSelectedVersion();
if (version == null) return null;
if (version instanceof FrameworkVersionWithLibrary) {
return ((FrameworkVersionWithLibrary)version).getLibraryDescription();
}
CustomLibraryDescription description = myLibraryDescriptions.get(version);
if (description == null) {
description = new CustomLibraryDescriptionImpl(version.getLibraries(), StringUtil.notNullize(version.getLibraryName()));
@@ -89,7 +93,7 @@ public class FrameworkSupportNode extends CheckedTreeNode {
final LibraryCompositionSettings libraryCompositionSettings = getLibraryCompositionSettings();
if (myLibraryCompositionOptionsPanel == null || !myLibraryCompositionOptionsPanel.getSettings().equals(libraryCompositionSettings)) {
if (libraryCompositionSettings != null) {
myLibraryCompositionOptionsPanel = new LibraryOptionsPanel(libraryCompositionSettings, librariesContainer, true);
myLibraryCompositionOptionsPanel = new LibraryOptionsPanel(libraryCompositionSettings, librariesContainer, myConfigurable.getComponent() != null);
}
else {
myLibraryCompositionOptionsPanel = null;
@@ -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.libraries;
import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings;
import com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ParametrizedRunnable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author nik
*/
public class AddCustomLibraryDialog extends DialogWrapper {
private final LibraryOptionsPanel myPanel;
private final LibrariesContainer myLibrariesContainer;
private final Module myModule;
private final ModifiableRootModel myModifiableRootModel;
private final @Nullable ParametrizedRunnable<ModifiableRootModel> myBeforeLibraryAdded;
private final List<Library> myAddedLibraries = new ArrayList<Library>();
private AddCustomLibraryDialog(CustomLibraryDescription description, LibrariesContainer librariesContainer,
Module module,
ModifiableRootModel modifiableRootModel,
@Nullable ParametrizedRunnable<ModifiableRootModel> beforeLibraryAdded) {
super(module.getProject(), true);
myLibrariesContainer = librariesContainer;
myModule = module;
myModifiableRootModel = modifiableRootModel;
myBeforeLibraryAdded = beforeLibraryAdded;
setTitle(IdeBundle.message("setup.library.dialog.title"));
VirtualFile baseDir = myModule.getProject().getBaseDir();
final String baseDirPath = baseDir != null ? baseDir.getPath() : "";
myPanel = new LibraryOptionsPanel(new LibraryCompositionSettings(description, baseDirPath), myLibrariesContainer, false);
init();
}
public static AddCustomLibraryDialog createDialog(@NotNull CustomLibraryDescription description,
final @NotNull Module module,
final ParametrizedRunnable<ModifiableRootModel> beforeLibraryAdded) {
return createDialog(description, LibrariesContainerFactory.createContainer(module), module, null, beforeLibraryAdded);
}
public static AddCustomLibraryDialog createDialog(CustomLibraryDescription description,
final @NotNull LibrariesContainer librariesContainer, final @NotNull Module module,
final @Nullable ModifiableRootModel modifiableRootModel,
@Nullable ParametrizedRunnable<ModifiableRootModel> beforeLibraryAdded) {
return new AddCustomLibraryDialog(description, librariesContainer, module, modifiableRootModel, beforeLibraryAdded);
}
protected JComponent createCenterPanel() {
return myPanel.getMainPanel();
}
protected void doOKAction() {
myPanel.apply();
if (myPanel.getSettings().downloadFiles(myPanel.getMainPanel())) {
if (myModifiableRootModel == null) {
final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
new WriteAction() {
protected void run(final Result result) {
addLibraries(model);
model.commit();
}
}.execute();
}
else {
addLibraries(myModifiableRootModel);
}
super.doOKAction();
}
}
private void addLibraries(ModifiableRootModel model) {
if (myBeforeLibraryAdded != null) {
myBeforeLibraryAdded.run(model);
}
myPanel.getSettings().addLibraries(model, myAddedLibraries, myLibrariesContainer);
}
public List<Library> getAddedLibraries() {
return myAddedLibraries;
}
}
@@ -17,7 +17,6 @@ package com.intellij.openapi.roots.ui.configuration.libraries;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.libraries.Library;
@@ -29,24 +28,25 @@ import javax.swing.*;
/**
* @author nik
*/
public class AddExistingCustomLibraryAction extends DumbAwareAction {
public class AddExistingCustomLibraryAction extends CustomLibraryActionBase {
private Library myLibrary;
private StructureConfigurableContext myContext;
private ModuleStructureConfigurable myModuleStructureConfigurable;
private Module myModule;
public AddExistingCustomLibraryAction(Library library, Icon icon, StructureConfigurableContext context,
ModuleStructureConfigurable moduleStructureConfigurable, Module module) {
super(library.getName(), null, icon);
public AddExistingCustomLibraryAction(Library library,
Icon icon,
CustomLibraryCreator creator,
StructureConfigurableContext context,
ModuleStructureConfigurable moduleStructureConfigurable,
Module module) {
super(library.getName(), null, icon, context, moduleStructureConfigurable, creator, module);
myLibrary = library;
myContext = context;
myModuleStructureConfigurable = moduleStructureConfigurable;
myModule = module;
}
@Override
public void actionPerformed(AnActionEvent e) {
final ModifiableRootModel rootModel = myContext.getModulesConfigurator().getOrCreateModuleEditor(myModule).getModifiableRootModelProxy();
if (!askAndRemoveDuplicatedLibraryEntry(myCreator.getDescription(), rootModel)) {
return;
}
final LibraryOrderEntry orderEntry = rootModel.addLibraryEntry(myLibrary);
myModuleStructureConfigurable.selectOrderEntry(myModule, orderEntry);
}
@@ -22,7 +22,6 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
@@ -44,20 +43,11 @@ import java.util.*;
/**
* @author nik
*/
public class CreateCustomLibraryAction extends DumbAwareAction {
private final CustomLibraryCreator myCreator;
private StructureConfigurableContext myContext;
private ModuleStructureConfigurable myModuleStructureConfigurable;
private Module myModule;
public class CreateCustomLibraryAction extends CustomLibraryActionBase {
public CreateCustomLibraryAction(final String name, CustomLibraryCreator creator,
StructureConfigurableContext context,
ModuleStructureConfigurable moduleStructureConfigurable, Module module) {
super(name, null, creator.getIcon());
myCreator = creator;
myContext = context;
myModuleStructureConfigurable = moduleStructureConfigurable;
myModule = module;
super(name, null, creator.getIcon(), context, moduleStructureConfigurable, creator, module);
}
@Override
@@ -79,6 +69,9 @@ public class CreateCustomLibraryAction extends DumbAwareAction {
if (dialog.isOK()) {
final Library library = dialog.createLibrary(myContext.getModifiableLibraryTable(dialog.getSelectedTable()));
final ModifiableRootModel rootModel = myContext.getModulesConfigurator().getOrCreateModuleEditor(myModule).getModifiableRootModelProxy();
if (!askAndRemoveDuplicatedLibraryEntry(myCreator.getDescription(), rootModel)) {
return;
}
final LibraryOrderEntry orderEntry = rootModel.addLibraryEntry(library);
myModuleStructureConfigurable.selectOrderEntry(myModule, orderEntry);
}
@@ -112,7 +105,7 @@ public class CreateCustomLibraryAction extends DumbAwareAction {
group.add(new CreateCustomLibraryAction("New...", creator, context, moduleStructureConfigurable, module));
for (Library library : librariesToAdd) {
Icon icon = LibraryPresentationManager.getInstance().getNamedLibraryIcon(library, context);
group.add(new AddExistingCustomLibraryAction(library, icon, context, moduleStructureConfigurable, module));
group.add(new AddExistingCustomLibraryAction(library, icon, creator, context, moduleStructureConfigurable, module));
}
actions.add(group);
}
@@ -0,0 +1,88 @@
/*
* 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.libraries;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author nik
*/
public abstract class CustomLibraryActionBase extends DumbAwareAction {
protected final CustomLibraryCreator myCreator;
protected final StructureConfigurableContext myContext;
protected final ModuleStructureConfigurable myModuleStructureConfigurable;
protected Module myModule;
protected CustomLibraryActionBase(String text, String description, Icon icon, StructureConfigurableContext context,
ModuleStructureConfigurable moduleStructureConfigurable, CustomLibraryCreator creator, Module module) {
super(text, description, icon);
myContext = context;
myModuleStructureConfigurable = moduleStructureConfigurable;
myCreator = creator;
myModule = module;
}
protected boolean askAndRemoveDuplicatedLibraryEntry(@NotNull CustomLibraryDescription description, @NotNull ModifiableRootModel rootModel) {
List<OrderEntry> existingEntries = new ArrayList<OrderEntry>();
for (OrderEntry entry : rootModel.getOrderEntries()) {
if (!(entry instanceof LibraryOrderEntry)) continue;
final Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library == null) continue;
final VirtualFile[] files = myContext.getLibraryFiles(library, OrderRootType.CLASSES);
if (description.getSuitableLibraryCondition().value(Arrays.asList(files))) {
existingEntries.add(entry);
}
}
if (!existingEntries.isEmpty()) {
String message;
if (existingEntries.size() > 1) {
message = "There are already " + existingEntries.size() + " " + myCreator.getDisplayName() + " libraries.\n Do you want to replace they?";
}
else {
final String name = existingEntries.get(0).getPresentableName();
message = "There is already a " + myCreator.getDisplayName() + " library '" + name + "'.\n Do you want to replace it?";
}
final int result = Messages.showDialog(rootModel.getProject(), message, "Library Already Exists", new String[]{"&Replace", "&Add", "&Cancel"}, 0, null);
if (result == 0) {
for (OrderEntry entry : existingEntries) {
rootModel.removeOrderEntry(entry);
}
}
else if (result != 1) {
return false;
}
}
return true;
}
}
@@ -15,26 +15,21 @@
*/
package com.intellij.openapi.roots.ui.configuration.libraries;
import com.intellij.facet.ui.libraries.LibraryDownloadInfo;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Collections;
import java.util.List;
/**
* @author nik
*/
public abstract class CustomLibraryDescription {
@NotNull
public abstract String getDefaultLibraryName();
@NotNull
public List<LibraryDownloadInfo> getDownloads() {
return Collections.emptyList();
@Nullable
public LibraryDownloadDescription getDownloadDescription() {
return null;
}
@NotNull
@@ -0,0 +1,44 @@
/*
* 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.libraries;
import com.intellij.facet.ui.libraries.LibraryDownloadInfo;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author nik
*/
public class LibraryDownloadDescription {
private final String myDefaultLibraryName;
private final List<LibraryDownloadInfo> myDownloads;
public LibraryDownloadDescription(@NotNull String defaultLibraryName, @NotNull List<LibraryDownloadInfo> downloads) {
myDefaultLibraryName = defaultLibraryName;
myDownloads = downloads;
}
@NotNull
public String getDefaultLibraryName() {
return myDefaultLibraryName;
}
@NotNull
public List<LibraryDownloadInfo> getDownloads() {
return myDownloads;
}
}
@@ -54,4 +54,6 @@ public abstract class LibraryPresentationManager {
public abstract List<Library> getLibraries(@NotNull Set<LibraryKind<?>> kinds, @NotNull Project project, @Nullable StructureConfigurableContext context);
public abstract boolean isLibraryOfKind(@NotNull List<VirtualFile> files, @NotNull LibraryKind<?> kind);
public abstract boolean isLibraryOfKind(@NotNull List<VirtualFile> files, @NotNull Set<? extends LibraryKind<?>> acceptedKinds);
}
@@ -92,6 +92,16 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
});
}
@Override
public boolean isLibraryOfKind(@NotNull List<VirtualFile> files, @NotNull final Set<? extends LibraryKind<?>> acceptedKinds) {
return !LibraryDetectionManager.getInstance().processProperties(files, new LibraryDetectionManager.LibraryPropertiesProcessor() {
@Override
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind<P> processedKind, @NotNull P properties) {
return !acceptedKinds.contains(processedKind);
}
});
}
public static List<LibraryKind<?>> getLibraryKinds(@NotNull Library library, StructureConfigurableContext context) {
final List<LibraryKind<?>> result = new SmartList<LibraryKind<?>>();
final VirtualFile[] files = getLibraryFiles(library, context);