command line shortener: process Default JRE correctly

+ update on module change
This commit is contained in:
Anna.Kozlova
2017-10-09 16:07:26 +02:00
parent 0c33e3fe95
commit 0cd0153a3c
5 changed files with 28 additions and 17 deletions
@@ -67,7 +67,7 @@ public class ApplicationConfigurable extends SettingsEditor<ApplicationConfigura
ClassBrowser.createApplicationClassBrowser(project, myModuleSelector).setField(getMainClassField());
myVersionDetector = new JreVersionDetector();
myShortenClasspathModeCombo.setComponent(new ShortenCommandLineModeCombo(myProject, myJrePathEditor));
myShortenClasspathModeCombo.setComponent(new ShortenCommandLineModeCombo(myProject, myJrePathEditor, myModule.getComponent()));
myAnchor = UIUtil.mergeComponentsWithAnchor(myMainClass, myCommonProgramParameters, myJrePathEditor, myModule,
myShortenClasspathModeCombo);
}
@@ -1,10 +1,13 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.ui;
import com.intellij.application.options.ModuleDescriptionsComboBox;
import com.intellij.execution.ShortenCommandLine;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.ui.ColoredListCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
@@ -12,13 +15,16 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.event.ActionListener;
public class ShortenCommandLineModeCombo extends ComboBox<ShortenCommandLine> {
private final Project myProject;
public ShortenCommandLineModeCombo(Project project, JrePathEditor pathEditor) {
public ShortenCommandLineModeCombo(Project project,
JrePathEditor pathEditor,
ModuleDescriptionsComboBox component) {
myProject = project;
initModel(null, pathEditor);
initModel(null, pathEditor, component.getSelectedModule());
setRenderer(new ColoredListCellRenderer<ShortenCommandLine>() {
@Override
protected void customizeCellRenderer(@NotNull JList<? extends ShortenCommandLine> list,
@@ -27,7 +33,7 @@ public class ShortenCommandLineModeCombo extends ComboBox<ShortenCommandLine> {
boolean selected,
boolean hasFocus) {
if (value == null) {
ShortenCommandLine defaultMode = ShortenCommandLine.getDefaultMethod(myProject, getJdkRoot(pathEditor));
ShortenCommandLine defaultMode = ShortenCommandLine.getDefaultMethod(myProject, getJdkRoot(pathEditor, component.getSelectedModule()));
append("user-local default: " + defaultMode.getPresentableName()).append(" - " + defaultMode.getDescription(), SimpleTextAttributes.GRAYED_ATTRIBUTES);
}
else {
@@ -35,16 +41,18 @@ public class ShortenCommandLineModeCombo extends ComboBox<ShortenCommandLine> {
}
}
});
pathEditor.addActionListener(e -> {
ActionListener updateModelListener = e -> {
Object item = getSelectedItem();
initModel((ShortenCommandLine)item, pathEditor);
});
initModel((ShortenCommandLine)item, pathEditor, component.getSelectedModule());
};
pathEditor.addActionListener(updateModelListener);
component.addActionListener(updateModelListener);
}
private void initModel(ShortenCommandLine preselection, JrePathEditor pathEditor) {
private void initModel(ShortenCommandLine preselection, JrePathEditor pathEditor, Module module) {
removeAllItems();
String jdkRoot = getJdkRoot(pathEditor);
String jdkRoot = getJdkRoot(pathEditor, module);
addItem(null);
for (ShortenCommandLine mode : ShortenCommandLine.values()) {
if (mode.isApplicable(jdkRoot)) {
@@ -56,7 +64,11 @@ public class ShortenCommandLineModeCombo extends ComboBox<ShortenCommandLine> {
}
@Nullable
private static String getJdkRoot(JrePathEditor pathEditor) {
private static String getJdkRoot(JrePathEditor pathEditor, Module module) {
if (!pathEditor.isAlternativeJreSelected() && module != null) {
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
return sdk != null ? sdk.getHomePath() : null;
}
String jrePathOrName = pathEditor.getJrePathOrName();
if (jrePathOrName != null) {
Sdk configuredJdk = ProjectJdkTable.getInstance().findJdk(jrePathOrName);
@@ -279,7 +279,7 @@ public class JUnitConfigurable<T extends JUnitConfiguration> extends SettingsEdi
model.addElement(changeList.getName());
}
myShortenClasspathModeCombo.setComponent(new ShortenCommandLineModeCombo(myProject, myJrePathEditor));
myShortenClasspathModeCombo.setComponent(new ShortenCommandLineModeCombo(myProject, myJrePathEditor, myModule.getComponent()));
}
private static void addRadioButtonsListeners(final JRadioButton[] radioButtons, ChangeListener listener) {
@@ -153,7 +153,7 @@
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.application.options.ModulesComboBox"/>
<componentClass value="com.intellij.application.options.ModuleDescriptionsComboBox"/>
<labelLocation value="West"/>
<text resource-bundle="messages/ExecutionBundle" key="application.configuration.use.classpath.and.jdk.of.module.label"/>
</properties>
@@ -16,7 +16,7 @@
package com.theoryinpractice.testng.configuration;
import com.intellij.application.options.ModulesComboBox;
import com.intellij.application.options.ModuleDescriptionsComboBox;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.JavaExecutionUtil;
import com.intellij.execution.MethodBrowser;
@@ -76,7 +76,7 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
private JPanel panel;
private LabeledComponent<EditorTextFieldWithBrowseButton> classField;
private LabeledComponent<ModulesComboBox> moduleClasspath;
private LabeledComponent<ModuleDescriptionsComboBox> moduleClasspath;
private JrePathEditor alternateJDK;
private final ConfigurationModuleSelector moduleSelector;
private JComboBox<TestType> myTestKind;
@@ -203,7 +203,7 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
commonJavaParameters.setProgramParametersLabel(ExecutionBundle.message("junit.configuration.test.runner.parameters.label"));
myShortenCommandLineCombo.setComponent(new ShortenCommandLineModeCombo(project, alternateJDK));
myShortenCommandLineCombo.setComponent(new ShortenCommandLineModeCombo(project, alternateJDK, getModulesComponent()));
setAnchor(outputDirectory.getLabel());
alternateJDK.setAnchor(moduleClasspath.getLabel());
commonJavaParameters.setAnchor(moduleClasspath.getLabel());
@@ -275,7 +275,7 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
return classField.getComponent().getText();
}
public ModulesComboBox getModulesComponent() {
public ModuleDescriptionsComboBox getModulesComponent() {
return moduleClasspath.getComponent();
}
@@ -421,7 +421,6 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
outputDirectoryButton.addBrowseFolderListener("TestNG", "Select test output directory", project,
FileChooserDescriptorFactory.createSingleFolderDescriptor());
moduleClasspath.setEnabled(true);
moduleClasspath.setComponent(new ModulesComboBox());
propertiesTableModel = new TestNGParametersTableModel();
listenerModel = new TestNGListenersTableModel();