mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
"Add Framework Support" UI
This commit is contained in:
@@ -56,8 +56,8 @@ public class ChooseLibrariesDialog extends DialogWrapper {
|
||||
return myChooser.getMarkedElements();
|
||||
}
|
||||
|
||||
private static class LibraryElementChooser extends ElementsChooser<Library> {
|
||||
private LibraryElementChooser(final List<Library> elements) {
|
||||
static class LibraryElementChooser extends ElementsChooser<Library> {
|
||||
LibraryElementChooser(final List<Library> elements) {
|
||||
super(elements, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="5" 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="584" height="146"/>
|
||||
<xy x="20" y="20" width="584" height="261"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="37d09" class="javax.swing.JLabel" binding="myMessage">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
<text value="<html>{} jars will be downloaded into <b>lib</b> directory<br> Project level library <b>spring</b> will be created</html>"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a5b73" class="javax.swing.JRadioButton" binding="myDownloadFromMavenButton">
|
||||
<component id="a5b73" class="javax.swing.JRadioButton">
|
||||
<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">
|
||||
<preferred-size width="207" height="22"/>
|
||||
@@ -30,37 +21,17 @@
|
||||
<text value="Download from &Maven repository"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="3e4b8">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="207" height="14"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="f63e3" class="javax.swing.JRadioButton" binding="myDoNotCreateButton">
|
||||
<component id="f63e3" class="javax.swing.JRadioButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="207" height="22"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Do &not create library"/>
|
||||
<text value="Do &not create new library"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6cdd8" class="javax.swing.JButton" binding="myConfigureButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Configure..."/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="2f96b">
|
||||
<constraints>
|
||||
<grid row="0" column="1" 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="46359" class="javax.swing.JRadioButton" binding="myLocateOnDiskButton">
|
||||
<component id="46359" class="javax.swing.JRadioButton">
|
||||
<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>
|
||||
@@ -68,14 +39,71 @@
|
||||
<text value="Pick up files from &disk"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="4f3d8" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="4" 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="37d09" class="javax.swing.JLabel" binding="myMessage">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
<text value="<html>{} jars will be downloaded into <b>lib</b> directory<br> Project level library <b>spring</b> will be created</html>"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="2f96b">
|
||||
<constraints>
|
||||
<grid row="0" column="1" 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="6cdd8" class="javax.swing.JButton" binding="myConfigureButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Configure..."/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="20f07" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="5" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="6efe3" class="javax.swing.JLabel" binding="myExistingLibrariesLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" 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="Use suitable e&xisting libraries:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="d793e" binding="myExistingLibrariesPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<buttonGroups>
|
||||
<group name="buttonGroup">
|
||||
<group name="myButtonGroup" bound="true">
|
||||
<member id="a5b73"/>
|
||||
<member id="947c3"/>
|
||||
<member id="f63e3"/>
|
||||
<member id="46359"/>
|
||||
<member id="f63e3"/>
|
||||
</group>
|
||||
</buttonGroups>
|
||||
</form>
|
||||
|
||||
@@ -15,15 +15,19 @@
|
||||
*/
|
||||
package com.intellij.facet.impl.ui.libraries;
|
||||
|
||||
import com.intellij.facet.ui.libraries.LibraryInfo;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.util.ElementsChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
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.Computable;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ui.RadioButtonEnumModel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -31,6 +35,8 @@ import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
@@ -39,42 +45,67 @@ public class LibraryOptionsPanel {
|
||||
|
||||
private JLabel myMessage;
|
||||
private JPanel myPanel;
|
||||
private JRadioButton myDownloadFromMavenButton;
|
||||
private JRadioButton myDoNotCreateButton;
|
||||
private JButton myConfigureButton;
|
||||
private JRadioButton myLocateOnDiskButton;
|
||||
private JPanel myExistingLibrariesPanel;
|
||||
private JLabel myExistingLibrariesLabel;
|
||||
private ButtonGroup myButtonGroup;
|
||||
private ElementsChooser<Library> myLibrariesChooser;
|
||||
|
||||
private LibraryCompositionSettings myLibraryCompositionSettings;
|
||||
private LibrariesContainer myLibrariesContainer;
|
||||
|
||||
|
||||
private enum Choice {
|
||||
DOWNLOAD,
|
||||
PICK_FILES,
|
||||
DO_NOT_CREATE
|
||||
}
|
||||
|
||||
private RadioButtonEnumModel<Choice> myButtonEnumModel;
|
||||
|
||||
public LibraryOptionsPanel(LibraryCompositionSettings libraryCompositionSettings, LibrariesContainer librariesContainer) {
|
||||
|
||||
public LibraryOptionsPanel(LibraryCompositionSettings libraryCompositionSettings) {
|
||||
myLibraryCompositionSettings = libraryCompositionSettings;
|
||||
myLibrariesContainer = librariesContainer;
|
||||
|
||||
List<Library> suitableLibraries = calculateSuitableLibraries();
|
||||
if (!suitableLibraries.isEmpty()) {
|
||||
myLibraryCompositionSettings.setUsedLibraries(suitableLibraries);
|
||||
}
|
||||
|
||||
myLibrariesChooser = new ChooseLibrariesDialog.LibraryElementChooser(suitableLibraries);
|
||||
myLibrariesChooser.getComponents()[0].setPreferredSize(new Dimension(10, 10)); // this makes scrollbars to work
|
||||
myExistingLibrariesPanel.add(myLibrariesChooser);
|
||||
myExistingLibrariesLabel.setLabelFor(myLibrariesChooser.getComponent());
|
||||
|
||||
myButtonEnumModel = RadioButtonEnumModel.bindEnum(Choice.class, myButtonGroup);
|
||||
ActionListener listener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
updateState();
|
||||
}
|
||||
};
|
||||
myDownloadFromMavenButton.addActionListener(listener);
|
||||
myLocateOnDiskButton.addActionListener(listener);
|
||||
myDoNotCreateButton.addActionListener(listener);
|
||||
myButtonEnumModel.addActionListener(listener);
|
||||
|
||||
myConfigureButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
if (myLocateOnDiskButton.isSelected()) {
|
||||
EditLibraryDialog dialog = new EditLibraryDialog(myConfigureButton, myLibraryCompositionSettings);
|
||||
if (myLibraryCompositionSettings.getAddedJars().isEmpty()) {
|
||||
VirtualFile[] files = showFileChooser();
|
||||
Library.ModifiableModel modifiableModel = dialog.getLibrary().getModifiableModel();
|
||||
for (VirtualFile file : files) {
|
||||
modifiableModel.addRoot(file, OrderRootType.CLASSES);
|
||||
switch (myButtonEnumModel.getSelected()) {
|
||||
case DOWNLOAD:
|
||||
showDialog(new DownloadingOptionsDialog(myConfigureButton, myLibraryCompositionSettings));
|
||||
break;
|
||||
case PICK_FILES:
|
||||
EditLibraryDialog dialog = new EditLibraryDialog(myConfigureButton, myLibraryCompositionSettings);
|
||||
if (myLibraryCompositionSettings.getAddedJars().isEmpty()) {
|
||||
VirtualFile[] files = showFileChooser();
|
||||
Library.ModifiableModel modifiableModel = dialog.getLibrary().getModifiableModel();
|
||||
for (VirtualFile file : files) {
|
||||
modifiableModel.addRoot(file, OrderRootType.CLASSES);
|
||||
}
|
||||
}
|
||||
modifiableModel.commit();
|
||||
}
|
||||
showDialog(dialog);
|
||||
}
|
||||
else {
|
||||
DownloadingOptionsDialog dialog = new DownloadingOptionsDialog(myConfigureButton, myLibraryCompositionSettings);
|
||||
showDialog(dialog);
|
||||
showDialog(dialog);
|
||||
break;
|
||||
case DO_NOT_CREATE:
|
||||
break;
|
||||
}
|
||||
updateState();
|
||||
}
|
||||
@@ -88,13 +119,28 @@ public class LibraryOptionsPanel {
|
||||
@Override
|
||||
public Point compute() {
|
||||
Point point = myConfigureButton.getLocationOnScreen();
|
||||
point.translate(- 50, - dialog.getSize().height);
|
||||
point.translate(- 50, - dialog.getSize().height - 20);
|
||||
return point;
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private List<Library> calculateSuitableLibraries() {
|
||||
LibraryInfo[] libraryInfos = myLibraryCompositionSettings.getLibraryInfos();
|
||||
RequiredLibrariesInfo requiredLibraries = new RequiredLibrariesInfo(libraryInfos);
|
||||
List<Library> suitableLibraries = new ArrayList<Library>();
|
||||
Library[] libraries = myLibrariesContainer.getAllLibraries();
|
||||
for (Library library : libraries) {
|
||||
RequiredLibrariesInfo.RequiredClassesNotFoundInfo info =
|
||||
requiredLibraries.checkLibraries(myLibrariesContainer.getLibraryFiles(library, OrderRootType.CLASSES), false);
|
||||
if (info == null || info.getLibraryInfos().length < libraryInfos.length) {
|
||||
suitableLibraries.add(library);
|
||||
}
|
||||
}
|
||||
return suitableLibraries;
|
||||
}
|
||||
|
||||
private VirtualFile[] showFileChooser() {
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, false, true, false, false, true);
|
||||
descriptor.setTitle(IdeBundle.message("file.chooser.select.paths.title"));
|
||||
@@ -112,41 +158,46 @@ public class LibraryOptionsPanel {
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
private void updateState() {
|
||||
if (myMessage.isEnabled()) {
|
||||
myMessage.setForeground(Color.black);
|
||||
}
|
||||
myConfigureButton.setEnabled(true);
|
||||
if (myDownloadFromMavenButton.isSelected()) {
|
||||
String path = myLibraryCompositionSettings.getDirectoryForDownloadedLibrariesPath().substring(myLibraryCompositionSettings.getBaseDirectoryForDownloadedFiles().length());
|
||||
String message = MessageFormat.format("<html>{0} jar(s) will be downloaded into <b>{1}</b> directory<br> " +
|
||||
"{2} library <b>{3}</b> will be created</html>",
|
||||
myLibraryCompositionSettings.getLibraryInfos().length,
|
||||
path,
|
||||
myLibraryCompositionSettings.getLibraryLevel(),
|
||||
myLibraryCompositionSettings.getLibraryName());
|
||||
myMessage.setText(message);
|
||||
}
|
||||
else if (myLocateOnDiskButton.isSelected()) {
|
||||
if (myLibraryCompositionSettings.getAddedJars().isEmpty()) {
|
||||
myMessage.setForeground(Color.red);
|
||||
myMessage.setText("Press Configure button to add classes to the library");
|
||||
}
|
||||
else {
|
||||
String message = MessageFormat.format("<html>{0} level library <b>{1}</b><br>" +
|
||||
"with {2} file(s) will be created</html>",
|
||||
myLibraryCompositionSettings.getLibraryLevel(),
|
||||
myLibraryCompositionSettings.getLibraryName(),
|
||||
myLibraryCompositionSettings.getAddedJars().size());
|
||||
myMessage.setText(message);
|
||||
}
|
||||
}
|
||||
else {
|
||||
myMessage.setText("<html>No library will be created<br>" +
|
||||
"You can add it later manually</html>");
|
||||
myConfigureButton.setEnabled(false);
|
||||
|
||||
String message = "";
|
||||
|
||||
switch (myButtonEnumModel.getSelected()) {
|
||||
case DOWNLOAD:
|
||||
String path = myLibraryCompositionSettings.getDirectoryForDownloadedLibrariesPath()
|
||||
.substring(myLibraryCompositionSettings.getBaseDirectoryForDownloadedFiles().length());
|
||||
message = MessageFormat.format("{0} jar(s) will be downloaded into <b>{1}</b> directory <br>" +
|
||||
"{2} library <b>{3}</b> will be created",
|
||||
myLibraryCompositionSettings.getLibraryInfos().length,
|
||||
path,
|
||||
myLibraryCompositionSettings.getLibraryLevel(),
|
||||
myLibraryCompositionSettings.getLibraryName());
|
||||
break;
|
||||
case PICK_FILES:
|
||||
if (myLibraryCompositionSettings.getAddedJars().isEmpty()) {
|
||||
myMessage.setForeground(Color.red);
|
||||
message = "Press Configure button to add classes to the library";
|
||||
}
|
||||
else {
|
||||
message = MessageFormat.format("{0} level library <b>{1}</b>" +
|
||||
"with {2} file(s) will be created",
|
||||
myLibraryCompositionSettings.getLibraryLevel(),
|
||||
myLibraryCompositionSettings.getLibraryName(),
|
||||
myLibraryCompositionSettings.getAddedJars().size());
|
||||
}
|
||||
break;
|
||||
case DO_NOT_CREATE:
|
||||
message = "No new library will be created";
|
||||
myConfigureButton.setEnabled(false);
|
||||
break;
|
||||
}
|
||||
|
||||
myMessage.setText("<html>" + message + "</html>");
|
||||
}
|
||||
|
||||
public LibraryCompositionSettings getLibraryCompositionSettings() {
|
||||
@@ -155,7 +206,7 @@ public class LibraryOptionsPanel {
|
||||
|
||||
|
||||
public void apply() {
|
||||
|
||||
myLibraryCompositionSettings.setUsedLibraries(myLibrariesChooser.getMarkedElements());
|
||||
}
|
||||
|
||||
public JComponent getMainPanel() {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class FrameworkSupportNode extends CheckedTreeNode {
|
||||
final LibraryCompositionSettings libraryCompositionSettings = getLibraryCompositionSettings();
|
||||
if (myLibraryCompositionOptionsPanel == null || !myLibraryCompositionOptionsPanel.getLibraryCompositionSettings().equals(libraryCompositionSettings)) {
|
||||
if (libraryCompositionSettings != null) {
|
||||
myLibraryCompositionOptionsPanel = new LibraryOptionsPanel(libraryCompositionSettings);
|
||||
myLibraryCompositionOptionsPanel = new LibraryOptionsPanel(libraryCompositionSettings, librariesContainer);
|
||||
}
|
||||
else {
|
||||
myLibraryCompositionOptionsPanel = null;
|
||||
|
||||
Reference in New Issue
Block a user