mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-20864 Maven: run configuration improvements
This commit is contained in:
+17
-10
@@ -8,16 +8,6 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="4eaf6" class="com.intellij.openapi.ui.LabeledComponent" binding="workingDirComponent">
|
||||
<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>
|
||||
<componentClass value="com.intellij.openapi.ui.TextFieldWithBrowseButton"/>
|
||||
<labelLocation value="West"/>
|
||||
<text value="Working &directory"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="3a9c4">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
@@ -78,6 +68,23 @@
|
||||
<text value="Resolve &Workspace artifacts"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="41a03" binding="myWorkingDirectoryPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="4eaf6" class="com.intellij.openapi.ui.LabeledComponent" binding="workingDirComponent">
|
||||
<constraints border-constraint="Center"/>
|
||||
<properties>
|
||||
<componentClass value="com.intellij.openapi.ui.TextFieldWithBrowseButton"/>
|
||||
<labelLocation value="West"/>
|
||||
<text value="Working &directory"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
+112
-3
@@ -18,29 +18,42 @@ package org.jetbrains.idea.maven.execution;
|
||||
import com.intellij.codeInsight.completion.CompletionResultSet;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.execution.configurations.ParametersList;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.util.treeView.NodeRenderer;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.FixedSizeButton;
|
||||
import com.intellij.openapi.ui.LabeledComponent;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.ui.popup.PopupChooserBuilder;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.EditorTextField;
|
||||
import com.intellij.ui.PanelWithAnchor;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.treeStructure.Tree;
|
||||
import com.intellij.util.TextFieldCompletionProvider;
|
||||
import com.intellij.util.execution.ParametersListUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.model.MavenConstants;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager;
|
||||
import org.jetbrains.idea.maven.utils.MavenProjectNamer;
|
||||
import org.jetbrains.idea.maven.utils.Strings;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Kaznacheev
|
||||
@@ -52,6 +65,7 @@ public abstract class MavenRunnerParametersConfigurable implements Configurable,
|
||||
private LabeledComponent<EditorTextField> profilesComponent;
|
||||
private JBLabel myFakeLabel;
|
||||
private JCheckBox myResolveToWorkspaceCheckBox;
|
||||
private JPanel myWorkingDirectoryPanel;
|
||||
private JComponent anchor;
|
||||
|
||||
public MavenRunnerParametersConfigurable(@NotNull final Project project) {
|
||||
@@ -91,9 +105,104 @@ public abstract class MavenRunnerParametersConfigurable implements Configurable,
|
||||
goalsComponent.setComponent(new MavenArgumentsCompletionProvider(project).createEditor(project));
|
||||
}
|
||||
|
||||
createShowProjectTreeButton(project);
|
||||
|
||||
setAnchor(profilesComponent.getLabel());
|
||||
}
|
||||
|
||||
private void createShowProjectTreeButton(final Project project) {
|
||||
final FixedSizeButton showProjectTreeButton = new FixedSizeButton();
|
||||
showProjectTreeButton.setIcon(AllIcons.Actions.Module);
|
||||
|
||||
showProjectTreeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
|
||||
|
||||
List<MavenProject> projectList = projectsManager.getProjects();
|
||||
if (projectList.isEmpty()) return;
|
||||
|
||||
MavenProject[] projects = projectList.toArray(new MavenProject[projectList.size()]);
|
||||
Arrays.sort(projects, new MavenProjectNamer.MavenProjectComparator());
|
||||
|
||||
Map<MavenProject, DefaultMutableTreeNode> projectsToNode = new HashMap<MavenProject, DefaultMutableTreeNode>();
|
||||
for (MavenProject mavenProject : projects) {
|
||||
projectsToNode.put(mavenProject, new DefaultMutableTreeNode(mavenProject));
|
||||
}
|
||||
|
||||
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
||||
|
||||
for (MavenProject mavenProject : projects) {
|
||||
DefaultMutableTreeNode parent;
|
||||
|
||||
MavenProject aggregator = projectsManager.findAggregator(mavenProject);
|
||||
if (aggregator != null) {
|
||||
parent = projectsToNode.get(aggregator);
|
||||
}
|
||||
else {
|
||||
parent = root;
|
||||
}
|
||||
|
||||
parent.add(projectsToNode.get(mavenProject));
|
||||
}
|
||||
|
||||
final Map<MavenProject, String> projectsNameMap = MavenProjectNamer.generateNameMap(projectList);
|
||||
|
||||
final JTree projectTree = new Tree(root);
|
||||
projectTree.setRootVisible(false);
|
||||
projectTree.setCellRenderer(new NodeRenderer() {
|
||||
@Override
|
||||
public void customizeCellRenderer(JTree tree,
|
||||
Object value,
|
||||
boolean selected,
|
||||
boolean expanded,
|
||||
boolean leaf,
|
||||
int row,
|
||||
boolean hasFocus) {
|
||||
if (value instanceof DefaultMutableTreeNode) {
|
||||
MavenProject mavenProject = (MavenProject)((DefaultMutableTreeNode)value).getUserObject();
|
||||
value = projectsNameMap.get(mavenProject);
|
||||
}
|
||||
|
||||
super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
|
||||
}
|
||||
});
|
||||
|
||||
final Ref<JBPopup> popupRef = new Ref<JBPopup>();
|
||||
|
||||
Runnable clickCallBack = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TreePath path = projectTree.getSelectionPath();
|
||||
if (path == null) return;
|
||||
|
||||
Object lastPathComponent = path.getLastPathComponent();
|
||||
if (!(lastPathComponent instanceof DefaultMutableTreeNode)) return;
|
||||
|
||||
Object object = ((DefaultMutableTreeNode)lastPathComponent).getUserObject();
|
||||
if (object == null) return; // may be it's the root
|
||||
|
||||
workingDirComponent.getComponent().setText(((MavenProject)object).getDirectory());
|
||||
|
||||
popupRef.get().closeOk(null);
|
||||
}
|
||||
};
|
||||
|
||||
JBPopup popup = new PopupChooserBuilder(projectTree)
|
||||
.setTitle("Select maven project")
|
||||
.setItemChoosenCallback(clickCallBack).setAutoselectOnMouseMove(true)
|
||||
.setCloseOnEnter(false)
|
||||
.createPopup();
|
||||
|
||||
popupRef.set(popup);
|
||||
|
||||
popup.showUnderneathOf(showProjectTreeButton);
|
||||
}
|
||||
});
|
||||
|
||||
myWorkingDirectoryPanel.add(showProjectTreeButton, BorderLayout.EAST);
|
||||
}
|
||||
|
||||
public JComponent createComponent() {
|
||||
return panel;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.idea.maven.utils;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import gnu.trove.THashMap;
|
||||
@@ -86,22 +85,7 @@ public class MavenProjectNamer {
|
||||
|
||||
private static void doBuildProjectTree(MavenProjectsManager manager, Map<MavenProject, Integer> res, List<MavenProject> rootProjects, int deep) {
|
||||
MavenProject[] rootProjectArray = rootProjects.toArray(new MavenProject[rootProjects.size()]);
|
||||
Arrays.sort(rootProjectArray, new Comparator<MavenProject>() {
|
||||
@Override
|
||||
public int compare(MavenProject o1, MavenProject o2) {
|
||||
MavenId id1 = o1.getMavenId();
|
||||
MavenId id2 = o2.getMavenId();
|
||||
|
||||
int res = Comparing.compare(id1.getGroupId(), id2.getGroupId());
|
||||
if (res != 0) return res;
|
||||
|
||||
res = Comparing.compare(id1.getArtifactId(), id2.getArtifactId());
|
||||
if (res != 0) return res;
|
||||
|
||||
res = Comparing.compare(id1.getVersion(), id2.getVersion());
|
||||
return res;
|
||||
}
|
||||
});
|
||||
Arrays.sort(rootProjectArray, new MavenProjectComparator());
|
||||
|
||||
for (MavenProject project : rootProjectArray) {
|
||||
if (!res.containsKey(project)) {
|
||||
@@ -120,4 +104,20 @@ public class MavenProjectNamer {
|
||||
return res;
|
||||
}
|
||||
|
||||
public static class MavenProjectComparator implements Comparator<MavenProject> {
|
||||
@Override
|
||||
public int compare(MavenProject o1, MavenProject o2) {
|
||||
MavenId id1 = o1.getMavenId();
|
||||
MavenId id2 = o2.getMavenId();
|
||||
|
||||
int res = Comparing.compare(id1.getGroupId(), id2.getGroupId());
|
||||
if (res != 0) return res;
|
||||
|
||||
res = Comparing.compare(id1.getArtifactId(), id2.getArtifactId());
|
||||
if (res != 0) return res;
|
||||
|
||||
res = Comparing.compare(id1.getVersion(), id2.getVersion());
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user