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);
@@ -37,8 +37,8 @@ public abstract class FrameworkSupportConfigurable implements Disposable {
public abstract void addSupport(@NotNull Module module, @NotNull ModifiableRootModel model, final @Nullable Library library);
@SuppressWarnings({"ConstantConditions"})
public FrameworkVersion getSelectedVersion() {
//noinspection ConstantConditions
return null;
}
@@ -977,7 +977,7 @@ error.library.download.failed=Library downloading failed: {0}
label.missed.libraries.prefix=The following libraries are missing:
label.missed.libraries.text={0}.<br>Class ''{1}'' not found
missing.libraries.fix.button=Fix...
specify.libraries.dialog.title=Specify Libraries
setup.library.dialog.title=Setup Library
new.library.file.chooser.title=New Library Files
new.library.file.chooser.description=Select jar files in which library classes are located
file.chooser.show.path=Show path
@@ -0,0 +1,23 @@
/*
* 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.util;
/**
* @author nik
*/
public interface ParametrizedRunnable<T> {
void run(T t);
}
+3
View File
@@ -108,6 +108,9 @@
<library.creator implementation="org.jetbrains.plugins.groovy.config.GroovyLibraryCreator"/>
<library.presentationProvider implementation="org.jetbrains.plugins.groovy.config.GroovyLibraryPresentationProvider"/>
<library.presentationProvider implementation="org.jetbrains.plugins.groovy.gpp.GppLibraryPresentationProvider"/>
<library.presentationProvider implementation="org.jetbrains.plugins.groovy.gant.GantLibraryPresentationProvider"/>
<library.presentationProvider implementation="org.jetbrains.plugins.groovy.gradle.GradleLibraryPresentationProvider"/>
<projectService serviceInterface="org.jetbrains.plugins.groovy.gant.GantSettings" serviceImplementation="org.jetbrains.plugins.groovy.gant.GantSettings"/>
<projectService serviceInterface="org.jetbrains.plugins.groovy.gradle.GradleSettings" serviceImplementation="org.jetbrains.plugins.groovy.gradle.GradleSettings"/>
@@ -309,20 +309,8 @@ continue.outside.loop=The continue statement is only allowed inside loops
break.outside.loop.or.switch=The break statement is only allowed inside loops or switches
label.already.used=Label ''{0}'' is already in use
break.outside.loop=The break statement with named labels is only allowed inside loops
########################################################################################################################
# Facet configuration
########################################################################################################################
new.button.label=New
groovy.sdk.configuration.label=<html><b>Groovy SDK:</b><br>Choose Groovy SDK specific for this module</html>
add.new.groovy.lib=New SDK
invalid.groovy.sdk.path.message=Invalid path to Groovy SDK
invalid.groovy.sdk.path.text=Wrong path specified
duplicate.groovy.lib.version=Duplicate Groovy SDK version
duplicate.groovy.lib.version.add=Add one more Groovy SDK of version {0}?
groovy.sdk.combo.box.project.item=<No Groovy SDK>
Constructor=Constructor
facet.create.project.lib=Create &Project Groovy library ''{0}''
facet.create.application.lib=Create Glob&al Groovy library ''{0}''
groovy.like.library.found=Groovy library found
groovy.like.library.found.text=Do you want to set up Groovy for module ''{0}'' \n\
with found library ''{1}'' (Groovy version {2})?
@@ -15,34 +15,8 @@
*/
package org.jetbrains.plugins.groovy.config;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.roots.libraries.LibraryUtil;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
import com.intellij.openapi.roots.ui.configuration.projectRoot.GlobalLibrariesConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectLibrariesConfigurable;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.CollectionFactory;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.config.ui.CreateLibraryDialog;
import javax.swing.*;
import java.util.List;
import java.util.Set;
/**
* @author peter
@@ -50,104 +24,5 @@ import java.util.Set;
public abstract class AbstractGroovyLibraryManager extends LibraryManager {
public static final ExtensionPointName<AbstractGroovyLibraryManager> EP_NAME = ExtensionPointName.create("org.intellij.groovy.libraryManager");
@NotNull
private static String generatePointerName(final String defaultName, final Set<String> usedLibraryNames) {
String newName = defaultName;
int index = 1;
while (usedLibraryNames.contains(newName)) {
newName = defaultName + " (" + index + ")";
index++;
}
return newName;
}
public Icon getDialogIcon() {
return getIcon();
}
private void fillLibrary(String path, Library.ModifiableModel model) {
NewLibraryEditor editor = new NewLibraryEditor();
editor.setName(model.getName());
fillLibrary(path, editor);
editor.apply(model);
}
protected abstract void fillLibrary(String path, LibraryEditor libraryEditor);
@Nullable
private Library createSDKLibrary(final String path,
final String name,
final Project project,
final boolean inModuleSettings,
final boolean inProject) {
Library library;
final Library.ModifiableModel model;
LibraryTable.ModifiableModel globalModel = null;
if (inModuleSettings) {
globalModel = project != null && inProject ?
ProjectLibrariesConfigurable.getInstance(project).getModelProvider().getModifiableModel() :
GlobalLibrariesConfigurable.getInstance(project).getModelProvider().getModifiableModel();
assert globalModel != null;
library = globalModel.createLibrary(name);
model = ((LibrariesModifiableModel)globalModel).getLibraryEditor(library).getModel();
} else {
LibraryTable table =
project != null && inProject ? ProjectLibraryTable.getInstance(project) : LibraryTablesRegistrar.getInstance().getLibraryTable();
library = LibraryUtil.createLibrary(table, name);
model = library.getModifiableModel();
}
assert library != null;
fillLibrary(path, model);
if (!inModuleSettings) {
model.commit();
}
else {
globalModel.commit();
}
return library;
}
@Nullable
public Library createLibrary(@NotNull final String path, final LibrariesContainer container, final boolean inModuleSettings) {
final List<String> versions = CollectionFactory.arrayList();
final Set<String> usedLibraryNames = CollectionFactory.newTroveSet();
for (Library library : container.getAllLibraries()) {
usedLibraryNames.add(library.getName());
final VirtualFile[] libraryFiles = container.getLibraryFiles(library, OrderRootType.CLASSES);
if (managesLibrary(libraryFiles)) {
ContainerUtil.addIfNotNull(getLibraryVersion(libraryFiles), versions);
}
}
final String newVersion = getSDKVersion(path);
final String libraryKind = getLibraryCategoryName();
boolean addVersion = !versions.contains(newVersion) ||
Messages.showOkCancelDialog("Add one more " + libraryKind + " library of version " + newVersion + "?",
"Duplicate library version", getDialogIcon()) == 0;
if (addVersion && !AbstractConfigUtils.UNDEFINED_VERSION.equals(newVersion)) {
final Project project = container.getProject();
final String name = generatePointerName(getLibraryPrefix() + "-" + newVersion, usedLibraryNames);
final CreateLibraryDialog dialog = new CreateLibraryDialog(project, "Create " + libraryKind + " library",
"Create Project " + libraryKind + " library '" + name + "'",
"Create Global " + libraryKind + " library '" + name + "'");
dialog.show();
if (dialog.isOK()) {
return ApplicationManager.getApplication().runWriteAction(new Computable<Library>() {
@Nullable
public Library compute() {
return createSDKLibrary(path, name, project, inModuleSettings, dialog.isInProject());
}
});
}
}
return null;
}
}
@@ -22,7 +22,6 @@ import com.intellij.ide.util.projectWizard.ModuleBuilder;
import com.intellij.openapi.module.ModuleType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.GroovyIcons;
import org.jetbrains.plugins.groovy.config.ui.GroovyFacetEditor;
import org.jetbrains.plugins.groovy.util.GroovyUtils;
import javax.swing.*;
@@ -47,7 +46,7 @@ public class GroovyFacetSupportProvider extends FrameworkSupportProvider {
@NotNull
public FrameworkSupportConfigurable createConfigurable(final @NotNull FrameworkSupportModel model) {
return new GroovySupportConfigurable(new GroovyFacetEditor(model.getProject()));
return new GroovySupportConfigurable();
}
public boolean isEnabledForModuleType(@NotNull ModuleType moduleType) {
@@ -15,21 +15,12 @@
*/
package org.jetbrains.plugins.groovy.config;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryCreator;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager;
import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.GroovyIcons;
import org.jetbrains.plugins.groovy.config.ui.GroovyFacetEditor;
import javax.swing.*;
import java.util.List;
/**
* @author nik
@@ -56,52 +47,4 @@ public class GroovyLibraryCreator extends CustomLibraryCreator {
public CustomLibraryDescription getDescription() {
return myDescription;
}
private static class GroovyLibraryDescription extends CustomLibraryDescription {
private final Condition<List<VirtualFile>> myCondition;
public GroovyLibraryDescription() {
myCondition = new Condition<List<VirtualFile>>() {
@Override
public boolean value(List<VirtualFile> virtualFiles) {
return LibraryPresentationManager.getInstance().isLibraryOfKind(virtualFiles, GroovyLibraryPresentationProvider.GROOVY_KIND);
}
};
}
@NotNull
@Override
public String getDefaultLibraryName() {
return "xxx";
}
@NotNull
@Override
public Condition<List<VirtualFile>> getSuitableLibraryCondition() {
return myCondition;
}
@Override
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, VirtualFile contextDirectory) {
final VirtualFile[] files = FileChooser.chooseFiles(parentComponent, FileChooserDescriptorFactory.createSingleFolderDescriptor());
if (files.length != 1) return null;
final VirtualFile dir = files[0];
final AbstractGroovyLibraryManager manager = GroovyFacetEditor.findManager(dir);
if (manager == null) return null;
final String path = dir.getPath();
final String sdkVersion = manager.getSDKVersion(path);
if (AbstractConfigUtils.UNDEFINED_VERSION.equals(sdkVersion)) {
return null;
}
return new NewLibraryConfiguration(manager.getLibraryPrefix() + "-" + sdkVersion) {
@Override
public void addRoots(@NotNull LibraryEditor editor) {
manager.fillLibrary(path, editor);
}
};
}
}
}
@@ -0,0 +1,135 @@
/*
* 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 org.jetbrains.plugins.groovy.config;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.roots.libraries.LibraryKind;
import com.intellij.openapi.roots.libraries.LibraryPresentationProvider;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager;
import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.util.GroovyUtils;
import javax.swing.*;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author nik
*/
public class GroovyLibraryDescription extends CustomLibraryDescription {
private final Condition<List<VirtualFile>> myCondition;
private String myEnvVariable;
public GroovyLibraryDescription() {
this("GROOVY_HOME", getAllGroovyKinds());
}
private static Set<? extends LibraryKind<?>> getAllGroovyKinds() {
final HashSet<LibraryKind<?>> kinds = new HashSet<LibraryKind<?>>();
for (LibraryPresentationProvider provider : LibraryPresentationProvider.EP_NAME.getExtensions()) {
if (provider instanceof GroovyLibraryPresentationProviderBase) {
kinds.add(provider.getKind());
}
}
return kinds;
}
public GroovyLibraryDescription(@NotNull String envVariable, @NotNull LibraryKind<?> libraryKind) {
this(envVariable, Collections.singleton(libraryKind));
}
public GroovyLibraryDescription(@NotNull String envVariable, @NotNull final Set<? extends LibraryKind<?>> libraryKinds) {
myEnvVariable = envVariable;
myCondition = new Condition<List<VirtualFile>>() {
@Override
public boolean value(List<VirtualFile> virtualFiles) {
return LibraryPresentationManager.getInstance().isLibraryOfKind(virtualFiles, libraryKinds);
}
};
}
@Nullable
public static AbstractGroovyLibraryManager findManager(VirtualFile dir) {
if (GroovyUtils.getFilesInDirectoryByPattern(dir.getPath() + "/lib", "groovy.*\\.jar").length == 0) {
return null;
}
final String name = dir.getName();
final AbstractGroovyLibraryManager[] managers = AbstractGroovyLibraryManager.EP_NAME.getExtensions();
for (final AbstractGroovyLibraryManager manager : managers) {
if (manager.managesName(name) && manager.isSDKHome(dir)) {
return manager;
}
}
for (final AbstractGroovyLibraryManager manager : managers) {
if (manager.isSDKHome(dir)) {
return manager;
}
}
return null;
}
@NotNull
@Override
public Condition<List<VirtualFile>> getSuitableLibraryCondition() {
return myCondition;
}
@Override
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, VirtualFile contextDirectory) {
final String envHome = System.getenv(myEnvVariable);
VirtualFile initial = null;
if (envHome != null && envHome.length() > 0) {
initial = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(envHome));
}
final VirtualFile[] files = FileChooser.chooseFiles(parentComponent, FileChooserDescriptorFactory.createSingleFolderDescriptor(), initial);
if (files.length != 1) return null;
final VirtualFile dir = files[0];
final AbstractGroovyLibraryManager manager = findManager(dir);
if (manager == null) {
//todo[nik,peter] show error message in file chooser
return null;
}
final String path = dir.getPath();
final String sdkVersion = manager.getSDKVersion(path);
if (AbstractConfigUtils.UNDEFINED_VERSION.equals(sdkVersion)) {
return null;
}
return new NewLibraryConfiguration(manager.getLibraryPrefix() + "-" + sdkVersion) {
@Override
public void addRoots(@NotNull LibraryEditor editor) {
manager.fillLibrary(path, editor);
}
};
}
}
@@ -82,11 +82,6 @@ public class GroovyLibraryManager extends AbstractGroovyLibraryManager {
return GroovyConfigUtils.getInstance().getSDKVersion(path);
}
@Override
public Icon getDialogIcon() {
return GroovyIcons.GROOVY_ICON_32x32;
}
@Nls
@NotNull
@Override
@@ -16,42 +16,25 @@
package org.jetbrains.plugins.groovy.config;
import com.intellij.openapi.roots.libraries.LibraryKind;
import com.intellij.openapi.roots.libraries.LibraryPresentationProvider;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.List;
/**
* @author nik
*/
public class GroovyLibraryPresentationProvider extends LibraryPresentationProvider<GroovyLibraryProperties> {
public class GroovyLibraryPresentationProvider extends GroovyLibraryPresentationProviderBase {
public static final LibraryKind<GroovyLibraryProperties> GROOVY_KIND = LibraryKind.create("groovy");
private GroovyLibraryManager myManager = new GroovyLibraryManager();
public GroovyLibraryPresentationProvider() {
super(GROOVY_KIND);
}
@Override
public Icon getIcon(GroovyLibraryProperties properties) {
return properties.getManager().getIcon();
public LibraryManager getLibraryManager() {
return myManager;
}
@Override
public String getDescription(@NotNull GroovyLibraryProperties properties) {
final String version = properties.getVersion();
return properties.getManager().getLibraryCategoryName() + " library" + (version != null ? " of version " + version : ":");
}
@Override
public GroovyLibraryProperties detect(@NotNull List<VirtualFile> classesRoots) {
final VirtualFile[] libraryFiles = classesRoots.toArray(new VirtualFile[classesRoots.size()]);
final LibraryManager manager = LibraryManager.findManagerFor(AbstractGroovyLibraryManager.EP_NAME.getExtensions(), libraryFiles);
if (manager != null) {
final String version = manager.getLibraryVersion(libraryFiles);
return new GroovyLibraryProperties(manager, version);
}
return null;
protected boolean acceptManager(LibraryManager manager) {
return manager instanceof GroovyLibraryManager;
}
}
@@ -0,0 +1,59 @@
/*
* 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 org.jetbrains.plugins.groovy.config;
import com.intellij.openapi.roots.libraries.LibraryKind;
import com.intellij.openapi.roots.libraries.LibraryPresentationProvider;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.List;
/**
* @author nik
*/
public abstract class GroovyLibraryPresentationProviderBase extends LibraryPresentationProvider<GroovyLibraryProperties> {
public GroovyLibraryPresentationProviderBase(LibraryKind<GroovyLibraryProperties> kind) {
super(kind);
}
public abstract LibraryManager getLibraryManager();
@Override
public Icon getIcon(GroovyLibraryProperties properties) {
return getLibraryManager().getIcon();
}
@Override
public String getDescription(@NotNull GroovyLibraryProperties properties) {
final String version = properties.getVersion();
return getLibraryManager().getLibraryCategoryName() + " library" + (version != null ? " of version " + version : ":");
}
@Override
public GroovyLibraryProperties detect(@NotNull List<VirtualFile> classesRoots) {
final VirtualFile[] libraryFiles = classesRoots.toArray(new VirtualFile[classesRoots.size()]);
final LibraryManager manager = LibraryManager.findManagerFor(AbstractGroovyLibraryManager.EP_NAME.getExtensions(), libraryFiles);
if (manager != null && acceptManager(manager)) {
final String version = manager.getLibraryVersion(libraryFiles);
return new GroovyLibraryProperties(version);
}
return null;
}
protected abstract boolean acceptManager(LibraryManager manager);
}
@@ -22,18 +22,12 @@ import org.jetbrains.annotations.Nullable;
* @author nik
*/
public class GroovyLibraryProperties extends LibraryProperties<GroovyLibraryProperties> {
private LibraryManager myManager;
private String myVersion;
public GroovyLibraryProperties(LibraryManager manager, String version) {
myManager = manager;
public GroovyLibraryProperties(String version) {
myVersion = version;
}
public LibraryManager getManager() {
return myManager;
}
@Nullable
public String getVersion() {
return myVersion;
@@ -16,147 +16,37 @@
package org.jetbrains.plugins.groovy.config;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.ide.util.frameworkSupport.FrameworkVersion;
import com.intellij.ide.util.frameworkSupport.FrameworkVersionWithLibrary;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.ModifiableRootModel;
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.Messages;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.CollectionFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.config.ui.GroovyFacetEditor;
import org.jetbrains.plugins.groovy.util.LibrariesUtil;
import javax.swing.*;
import java.util.List;
/**
* @author peter
*/
public class GroovySupportConfigurable extends FrameworkSupportConfigurable {
private final GroovyFacetEditor facetEditor;
private FrameworkVersionWithLibrary myVersion;
public GroovySupportConfigurable(final GroovyFacetEditor facetEditor) {
this.facetEditor = facetEditor;
public GroovySupportConfigurable() {
}
@Override
public FrameworkVersion getSelectedVersion() {
if (myVersion == null) {
myVersion = new FrameworkVersionWithLibrary("", true, new GroovyLibraryDescription());
}
return myVersion;
}
@NotNull
public JComponent getComponent() {
return facetEditor.getComponent();
return null;
}
public void addSupport(@NotNull final Module module, @NotNull final ModifiableRootModel rootModel, @Nullable Library library) {
addGroovySupport(module, rootModel);
}
private boolean cleanDuplicates(List<LibraryManager> managers, ModifiableRootModel rootModel, final LibrariesContainer container) {
if (managers.isEmpty()) return true;
for (OrderEntry entry : rootModel.getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
final Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library == null) {
cleanUndefinedGroovyLibrary(rootModel, (LibraryOrderEntry)entry);
} else {
final LibraryManager manager = LibraryManager.findManagerFor(library, managers.toArray(new LibraryManager[managers.size()]), container);
if (manager != null) {
@SuppressWarnings({"NonConstantStringShouldBeStringBuffer"})
String message = "There is already a " + manager.getLibraryCategoryName() + " library";
final String version = manager.getLibraryVersion(container.getLibraryFiles(library, OrderRootType.CLASSES));
if (StringUtil.isNotEmpty(version)) {
message += " of version " + version;
}
message += ".\n Do you want to replace the existing one?";
final String replace = "&Replace";
final int result =
Messages
.showDialog(rootModel.getProject(), message, "Library already exists", new String[]{replace, "&Add", "&Cancel"}, 0, null);
if (result == 2 || result < 0) {
return false; //cancel or escape
}
if (result == 0) {
rootModel.removeOrderEntry(entry);
}
}
}
}
}
return true;
}
private static void cleanUndefinedGroovyLibrary(ModifiableRootModel rootModel, LibraryOrderEntry entry) {
final String libraryName = entry.getLibraryName();
if (libraryName == null) {
return;
}
for (AbstractGroovyLibraryManager each : AbstractGroovyLibraryManager.EP_NAME.getExtensions()) {
if (each.managesName(libraryName)) {
rootModel.removeOrderEntry(entry);
return;
}
}
}
public void addGroovySupport(final Module module, ModifiableRootModel rootModel) {
final LibrariesContainer container = LibrariesContainerFactory.createContainer(rootModel);
if (!facetEditor.addNewSdk()) {
final Library selectedLibrary = facetEditor.getSelectedLibrary();
if (selectedLibrary != null) {
List<LibraryManager> suitable = CollectionFactory.arrayList();
for (final LibraryManager manager : AbstractGroovyLibraryManager.EP_NAME.getExtensions()) {
if (manager.managesLibrary(container.getLibraryFiles(selectedLibrary, OrderRootType.CLASSES))) {
suitable.add(manager);
}
}
if (cleanDuplicates(suitable, rootModel, container)) {
LibrariesUtil.placeEntryToCorrectPlace(rootModel, rootModel.addLibraryEntry(selectedLibrary));
}
}
return;
}
final String path = facetEditor.getNewSdkPath();
final AbstractGroovyLibraryManager libraryManager = facetEditor.getChosenManager();
if (path != null && libraryManager != null) {
List<LibraryManager> suitable = CollectionFactory.arrayList();
suitable.add(libraryManager);
final VirtualFile vfile = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(path));
if (vfile != null) {
for (final LibraryManager manager : AbstractGroovyLibraryManager.EP_NAME.getExtensions()) {
if (manager != libraryManager && manager.isSDKHome(vfile)) {
suitable.add(manager);
}
}
}
if (!cleanDuplicates(suitable, rootModel, container)) return;
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
if (module.isDisposed()) {
return;
}
final Library lib = libraryManager.createLibrary(path, LibrariesContainerFactory.createContainer(module), false);
if (lib != null) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
LibrariesUtil.placeEntryToCorrectPlace(rootModel, rootModel.addLibraryEntry(lib));
rootModel.commit();
}
});
}
}
});
}
}
}
@@ -15,9 +15,6 @@
*/
package org.jetbrains.plugins.groovy.config;
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.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.Nls;
@@ -31,18 +28,6 @@ import javax.swing.*;
*/
public abstract class LibraryManager {
@Nullable
public static LibraryManager findManagerFor(@NotNull Library library, final LibraryManager[] managers, final LibrariesContainer container) {
for (final LibraryManager manager : managers) {
final String name = library.getName();
if (name != null && manager.managesName(name) && manager.managesLibrary(container.getLibraryFiles(library, OrderRootType.CLASSES))) {
return manager;
}
}
return findManagerFor(managers, container.getLibraryFiles(library, OrderRootType.CLASSES));
}
@Nullable
public static LibraryManager findManagerFor(LibraryManager[] managers, final VirtualFile[] libraryFiles) {
for (final LibraryManager manager : managers) {
@@ -1,46 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.groovy.config.ui.CreateLibraryDialog">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="436" height="297"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="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>
<component id="1f646" class="javax.swing.JRadioButton" binding="myGlobal" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="org/jetbrains/plugins/groovy/GroovyBundle" key="facet.create.application.lib"/>
</properties>
</component>
<component id="6bfe3" class="javax.swing.JRadioButton" binding="myInProject">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="org/jetbrains/plugins/groovy/GroovyBundle" key="facet.create.project.lib"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<buttonGroups>
<group name="myButtonGroup">
<member id="680e8"/>
<member id="1f646"/>
<member id="6bfe3"/>
</group>
</buttonGroups>
</form>
@@ -1,50 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.config.ui;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import javax.swing.*;
import java.awt.event.KeyEvent;
public class CreateLibraryDialog extends DialogWrapper {
private JPanel contentPane;
private JRadioButton myInProject;
private JRadioButton myGlobal;
public CreateLibraryDialog(Project project, final String title, final String inProjectText, final String isGlobalText) {
super(project, true);
setModal(true);
setTitle(title);
myInProject.setSelected(true);
myInProject.setMnemonic(KeyEvent.VK_P);
myGlobal.setMnemonic(KeyEvent.VK_G);
myInProject.setText(inProjectText);
myGlobal.setText(isGlobalText);
init();
}
protected JComponent createCenterPanel() {
return contentPane;
}
public boolean isInProject() {
return myInProject.isSelected();
}
}
@@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.groovy.config.ui.GroovyFacetEditor">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="371" height="97"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="5ee1f" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="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>
<component id="4579" class="javax.swing.JComboBox" binding="myComboBox" custom-create="true">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="8bf97" class="javax.swing.JRadioButton" binding="myExistingSdk">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text value="Existing SDK:"/>
</properties>
</component>
<component id="964e1" class="javax.swing.JRadioButton" binding="myNewSdk">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="New SDK"/>
</properties>
</component>
<hspacer id="66fd5">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="ff66a" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="mySdkPath" custom-create="true">
<constraints>
<grid row="1" column="2" row-span="1" col-span="2" vsize-policy="0" hsize-policy="7" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="200" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="475b9" class="javax.swing.JLabel" binding="myNewSdkLabel">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Installation path:"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<buttonGroups>
<group name="buttonGroup1">
<member id="8bf97"/>
<member id="964e1"/>
</group>
</buttonGroups>
</form>
@@ -1,254 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.config.ui;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDialog;
import com.intellij.openapi.fileChooser.FileChooserFactory;
import com.intellij.openapi.project.Project;
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.TextFieldWithBrowseButton;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.config.AbstractGroovyLibraryManager;
import org.jetbrains.plugins.groovy.config.LibraryManager;
import org.jetbrains.plugins.groovy.util.GroovyUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
/**
* @author ilyas
*/
public class GroovyFacetEditor {
@NonNls private static final String GROOVY_HOME = "GROOVY_HOME";
private static final Comparator<Pair<Library, LibraryManager>> LIBRARY_COMPARATOR = new Comparator<Pair<Library, LibraryManager>>() {
public int compare(Pair<Library, LibraryManager> o1, Pair<Library, LibraryManager> o2) {
final String name1 = o1.first.getName();
final String name2 = o2.first.getName();
if (name1 == null || name2 == null) return 1;
return -name1.compareToIgnoreCase(name2);
}
};
private TextFieldWithBrowseButton mySdkPath;
private JPanel myPanel;
private JComboBox myComboBox;
private JRadioButton myExistingSdk;
private JRadioButton myNewSdk;
private JLabel myNewSdkLabel;
private final Class<? extends LibraryManager> myAcceptableManager;
public GroovyFacetEditor(@Nullable Project project) {
this(project, LibraryManager.class, GROOVY_HOME);
}
public GroovyFacetEditor(@Nullable Project project, @NotNull Class<? extends LibraryManager> acceptableManager, final String envHome) {
myAcceptableManager = acceptableManager;
Set<Pair<Library, LibraryManager>> libs = configureComboBox(project);
configureSdkPathField(project);
boolean hasVersions = !libs.isEmpty();
myNewSdk.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
boolean status = myNewSdk.isSelected();
mySdkPath.setEnabled(status);
myComboBox.setEnabled(!status);
}
});
if (hasVersions) {
myExistingSdk.setSelected(true);
mySdkPath.setEnabled(false);
myNewSdkLabel.setVisible(false);
} else {
myExistingSdk.setVisible(false);
myNewSdk.setVisible(false);
myNewSdk.setSelected(true);
myNewSdkLabel.setVisible(true);
mySdkPath.setEnabled(true);
myComboBox.setEnabled(false);
myComboBox.setVisible(false);
}
final String s = System.getenv(envHome);
if (s != null && s.length() > 0) {
mySdkPath.setText(s);
}
}
private Set<Pair<Library, LibraryManager>> configureComboBox(Project project) {
final LibrariesContainer container = LibrariesContainerFactory.createContainer(project);
final AbstractGroovyLibraryManager[] managers = AbstractGroovyLibraryManager.EP_NAME.getExtensions();
Set<Pair<Library, LibraryManager>> libs = new TreeSet<Pair<Library, LibraryManager>>(LIBRARY_COMPARATOR);
for (Library library : container.getAllLibraries()) {
final LibraryManager manager = LibraryManager.findManagerFor(library, managers, container);
if (myAcceptableManager.isInstance(manager)) {
libs.add(Pair.create(library, manager));
}
}
if (!libs.isEmpty()) {
myComboBox.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof Pair) {
final Pair<Library, LibraryManager> pair = (Pair<Library, LibraryManager>) value;
setIcon(pair.second.getIcon());
setText(pair.first.getName());
}
return this;
}
});
Pair<Library, LibraryManager> maxValue = libs.iterator().next();
for (final Pair<Library, LibraryManager> lib : libs) {
myComboBox.addItem(lib);
final String version = lib.first.getName();
FontMetrics fontMetrics = myComboBox.getFontMetrics(myComboBox.getFont());
if (fontMetrics.stringWidth(version) > fontMetrics.stringWidth(maxValue.getFirst().getName())) {
maxValue = lib;
}
}
myComboBox.setPrototypeDisplayValue(maxValue);
}
else {
myComboBox.setEnabled(false);
myComboBox.setVisible(false);
}
return libs;
}
@Nullable
public Library getSelectedLibrary() {
final Object selectedItem = myComboBox.getSelectedItem();
if (selectedItem != null && selectedItem instanceof Pair) {
return ((Pair<Library,LibraryManager>)selectedItem).first;
}
return null;
}
@Nullable
public String getNewSdkPath() {
return mySdkPath.getText();
}
@Nullable
public AbstractGroovyLibraryManager getChosenManager() {
if (addNewSdk()) {
final String path = getNewSdkPath();
if (path != null) {
final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(path));
if (file != null && file.isDirectory()) {
return findManager(file);
}
}
return null;
}
final Object selectedItem = myComboBox.getSelectedItem();
if (selectedItem != null && selectedItem instanceof Pair) {
return (AbstractGroovyLibraryManager)((Pair)selectedItem).second;
}
return null;
}
public boolean addNewSdk() {
return !myNewSdk.isVisible() || myNewSdk.isSelected();
}
private void configureSdkPathField(@Nullable final Project project) {
mySdkPath.getButton().addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {
public boolean isFileSelectable(VirtualFile file) {
if (!super.isFileSelectable(file)) {
return false;
}
return findManager(file) != null;
}
};
final FileChooserDialog dialog = FileChooserFactory.getInstance().createFileChooser(descriptor, project);
final VirtualFile[] files = dialog.choose(null, project);
if (files.length > 0) {
final VirtualFile dir = files[0];
mySdkPath.setText(FileUtil.toSystemDependentName(dir.getPath()));
}
}
});
}
@Nullable
public static AbstractGroovyLibraryManager findManager(VirtualFile dir) {
if (GroovyUtils.getFilesInDirectoryByPattern(dir.getPath() + "/lib", "groovy.*\\.jar").length == 0) {
return null;
}
final String name = dir.getName();
final AbstractGroovyLibraryManager[] managers = AbstractGroovyLibraryManager.EP_NAME.getExtensions();
for (final AbstractGroovyLibraryManager manager : managers) {
if (manager.managesName(name) && manager.isSDKHome(dir)) {
return manager;
}
}
for (final AbstractGroovyLibraryManager manager : managers) {
if (manager.isSDKHome(dir)) {
return manager;
}
}
return null;
}
public JComponent getComponent() {
return myPanel;
}
private void createUIComponents() {
myComboBox = new JComboBox() {
public void setEnabled(boolean enabled) {
super.setEnabled(!myNewSdk.isSelected() && enabled);
}
};
mySdkPath = new TextFieldWithBrowseButton() {
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(addNewSdk() && enabled);
}
};
}
}
@@ -56,11 +56,6 @@ public class GantLibraryManager extends AbstractGroovyLibraryManager {
return GantUtils.getGantVersion(path);
}
@Override
public Icon getDialogIcon() {
return GantIcons.GANT_ICON_16x16;
}
@Nls
@NotNull
@Override
@@ -0,0 +1,43 @@
/*
* 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 org.jetbrains.plugins.groovy.gant;
import com.intellij.openapi.roots.libraries.LibraryKind;
import org.jetbrains.plugins.groovy.config.GroovyLibraryPresentationProviderBase;
import org.jetbrains.plugins.groovy.config.GroovyLibraryProperties;
import org.jetbrains.plugins.groovy.config.LibraryManager;
/**
* @author nik
*/
public class GantLibraryPresentationProvider extends GroovyLibraryPresentationProviderBase {
private static final LibraryKind<GroovyLibraryProperties> GANT_KIND = LibraryKind.create("gant");
private GantLibraryManager myLibraryManager = new GantLibraryManager();
public GantLibraryPresentationProvider() {
super(GANT_KIND);
}
@Override
public LibraryManager getLibraryManager() {
return myLibraryManager;
}
@Override
protected boolean acceptManager(LibraryManager manager) {
return manager instanceof GantLibraryManager;
}
}
@@ -0,0 +1,43 @@
/*
* 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 org.jetbrains.plugins.groovy.gpp;
import com.intellij.openapi.roots.libraries.LibraryKind;
import org.jetbrains.plugins.groovy.config.GroovyLibraryPresentationProviderBase;
import org.jetbrains.plugins.groovy.config.GroovyLibraryProperties;
import org.jetbrains.plugins.groovy.config.LibraryManager;
/**
* @author nik
*/
public class GppLibraryPresentationProvider extends GroovyLibraryPresentationProviderBase {
private static final LibraryKind<GroovyLibraryProperties> GPP_KIND = LibraryKind.create("gpp");
private GppLibraryManager myLibraryManager = new GppLibraryManager();
public GppLibraryPresentationProvider() {
super(GPP_KIND);
}
@Override
public LibraryManager getLibraryManager() {
return myLibraryManager;
}
@Override
protected boolean acceptManager(LibraryManager manager) {
return manager instanceof GppLibraryManager;
}
}
@@ -0,0 +1,43 @@
/*
* 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 org.jetbrains.plugins.groovy.gradle;
import com.intellij.openapi.roots.libraries.LibraryKind;
import org.jetbrains.plugins.groovy.config.GroovyLibraryPresentationProviderBase;
import org.jetbrains.plugins.groovy.config.GroovyLibraryProperties;
import org.jetbrains.plugins.groovy.config.LibraryManager;
/**
* @author nik
*/
public class GradleLibraryPresentationProvider extends GroovyLibraryPresentationProviderBase {
private static final LibraryKind<GroovyLibraryProperties> GRADLE_KIND = LibraryKind.create("gradle");
private GradleLibraryManager myLibraryManager = new GradleLibraryManager();
public GradleLibraryPresentationProvider() {
super(GRADLE_KIND);
}
@Override
public LibraryManager getLibraryManager() {
return myLibraryManager;
}
@Override
protected boolean acceptManager(LibraryManager manager) {
return manager instanceof GradleLibraryManager;
}
}