From c49f929592344c71b534a1603d3ac1fc9b761a84 Mon Sep 17 00:00:00 2001 From: Evgeny Zakrevsky Date: Fri, 9 Sep 2011 19:48:25 +0400 Subject: [PATCH] run configurations layout --- .../execution/remote/RemoteConfigurable.form | 129 +-- .../FrameworkSupportOptionsComponent.java | 4 +- .../ConfigurationSettingsEditorWrapper.java | 3 +- .../intellij/openapi/ui/LabeledComponent.java | 4 +- .../intellij/ui/components/JBRadioButton.java | 62 + .../com/intellij/ui/ComponentWithAnchor.java | 0 .../util/src/com/intellij/util/ui/UIUtil.java | 15 + .../run/AndroidRunConfigurationEditor.form | 15 +- .../run/testing/TestRunParameters.form | 4 +- plugins/devkit/src/DevKitBundle.properties | 2 +- .../src/run/PluginRunConfigurationEditor.java | 34 +- .../configuration/JUnitConfigurable.form | 268 +++-- .../configuration/JUnitConfigurable.java | 1 + .../TestNGConfigurationEditor.java | 1 + .../xpath/xslt/run/RunSettingsEditor.form | 85 +- .../xpath/xslt/run/XsltRunSettingsEditor.java | 1004 +++++++++-------- 16 files changed, 876 insertions(+), 755 deletions(-) create mode 100644 platform/platform-api/src/com/intellij/ui/components/JBRadioButton.java rename platform/{platform-api => util}/src/com/intellij/ui/ComponentWithAnchor.java (100%) diff --git a/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.form b/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.form index b1d77a657b30..8cb3d3239b3e 100644 --- a/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.form +++ b/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.form @@ -3,7 +3,7 @@ - + @@ -16,13 +16,10 @@ - - + + - - - - + @@ -30,17 +27,17 @@ - + - + - + @@ -48,7 +45,7 @@ - + @@ -75,7 +72,7 @@ - + @@ -100,77 +97,65 @@ - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - + diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java index b32593454936..0dc096001ae0 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java @@ -52,9 +52,7 @@ public class FrameworkSupportOptionsComponent { layout.setVerticalFill(true); myMainPanel = new JPanel(layout); - JComponent separator = SeparatorFactory.createSeparator(node.getTitle() + " Settings", null); - separator.setBorder(IdeBorderFactory.createEmptyBorder(0, 0, 5, 5)); - myMainPanel.add(separator); + myMainPanel.setBorder(IdeBorderFactory.createTitledBorder(node.getTitle() + " Settings", false, true, true)); final JComponent component = myConfigurable.getComponent(); if (component != null) { diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java b/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java index 6a24fe39bd40..1aaa63854dbe 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java @@ -34,6 +34,7 @@ import com.intellij.openapi.ui.FixedSizeButton; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; import com.intellij.ui.components.JBScrollPane; +import com.intellij.util.ui.UIUtil; import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; @@ -96,7 +97,7 @@ public class ConfigurationSettingsEditorWrapper extends SettingsEditor extends JPanel implements private String myLabelConstraints = BorderLayout.NORTH; public LabeledComponent() { - super(new BorderLayout(AbstractLayout.DEFAULT_HGAP, AbstractLayout.DEFAULT_VGAP)); + super(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP)); insertLabel(); } diff --git a/platform/platform-api/src/com/intellij/ui/components/JBRadioButton.java b/platform/platform-api/src/com/intellij/ui/components/JBRadioButton.java new file mode 100644 index 000000000000..dcd67ec8e161 --- /dev/null +++ b/platform/platform-api/src/com/intellij/ui/components/JBRadioButton.java @@ -0,0 +1,62 @@ +package com.intellij.ui.components; + +import com.intellij.ui.ComponentWithAnchor; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; + +/** + * @author evgeny.zakrevsky + */ +public class JBRadioButton extends JRadioButton implements ComponentWithAnchor { + private JComponent anchor; + + public JBRadioButton() { + } + + public JBRadioButton(Icon icon) { + super(icon); + } + + public JBRadioButton(Action a) { + super(a); + } + + public JBRadioButton(Icon icon, boolean selected) { + super(icon, selected); + } + + public JBRadioButton(String text) { + super(text); + } + + public JBRadioButton(String text, boolean selected) { + super(text, selected); + } + + public JBRadioButton(String text, Icon icon) { + super(text, icon); + } + + public JBRadioButton(String text, Icon icon, boolean selected) { + super(text, icon, selected); + } + + @Override + public JComponent getAnchor() { + return anchor; + } + + @Override + public void setAnchor(@Nullable JComponent anchor) { + if (anchor != this) { + this.anchor = anchor; + } + } + + @Override + public Dimension getPreferredSize() { + return anchor == null ? super.getPreferredSize() : anchor.getPreferredSize(); + } +} diff --git a/platform/platform-api/src/com/intellij/ui/ComponentWithAnchor.java b/platform/util/src/com/intellij/ui/ComponentWithAnchor.java similarity index 100% rename from platform/platform-api/src/com/intellij/ui/ComponentWithAnchor.java rename to platform/util/src/com/intellij/ui/ComponentWithAnchor.java diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index b61772892000..c0d8b126250e 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.ColorUtil; +import com.intellij.ui.ComponentWithAnchor; import com.intellij.ui.SideBorder; import com.intellij.util.ArrayUtil; import com.intellij.util.PairFunction; @@ -2430,5 +2431,19 @@ public class UIUtil { return false; } + public static void mergeComponentsWithAnchor(ComponentWithAnchor c1,ComponentWithAnchor c2) { + if (c1.getAnchor() == null) { + c1.setAnchor(c2.getAnchor()); + } else { + if (c2.getAnchor() == null) { + c2.setAnchor(c1.getAnchor()); + } else { + JComponent anchor = c1.getAnchor().getPreferredSize().getWidth() > c2.getAnchor().getPreferredSize().getWidth() ? + c1.getAnchor() : c2.getAnchor(); + c2.setAnchor(anchor); + c1.setAnchor(anchor); + } + } + } } diff --git a/plugins/android/src/org/jetbrains/android/run/AndroidRunConfigurationEditor.form b/plugins/android/src/org/jetbrains/android/run/AndroidRunConfigurationEditor.form index 12a9b35429a1..42ac4eb8a56a 100644 --- a/plugins/android/src/org/jetbrains/android/run/AndroidRunConfigurationEditor.form +++ b/plugins/android/src/org/jetbrains/android/run/AndroidRunConfigurationEditor.form @@ -24,7 +24,7 @@ - + @@ -54,7 +54,7 @@ - + @@ -62,7 +62,7 @@ - + @@ -72,12 +72,17 @@ - + + + + + + @@ -102,7 +107,7 @@ - + diff --git a/plugins/android/src/org/jetbrains/android/run/testing/TestRunParameters.form b/plugins/android/src/org/jetbrains/android/run/testing/TestRunParameters.form index e7cd04d90a5c..9b414bb56def 100644 --- a/plugins/android/src/org/jetbrains/android/run/testing/TestRunParameters.form +++ b/plugins/android/src/org/jetbrains/android/run/testing/TestRunParameters.form @@ -3,7 +3,7 @@ - + @@ -99,7 +99,7 @@ - + diff --git a/plugins/devkit/src/DevKitBundle.properties b/plugins/devkit/src/DevKitBundle.properties index 9080c75d785f..80baf0e9371a 100644 --- a/plugins/devkit/src/DevKitBundle.properties +++ b/plugins/devkit/src/DevKitBundle.properties @@ -50,7 +50,7 @@ error.no.plugin.xml=No plugin.xml file found error.plugin.xml.readonly=The plugin.xml file is read-only #run configurations -run.configuration.classpath.from.module.choose=Choose classpath and jdk from module: +run.configuration.classpath.from.module.choose=Use Classpath and JDK from Module: run.configuration.no.module.specified=No plugin module specified for configuration run.configuration.title=Plugin run.configuration.type.description=Plugin Sandbox Environment diff --git a/plugins/devkit/src/run/PluginRunConfigurationEditor.java b/plugins/devkit/src/run/PluginRunConfigurationEditor.java index fb0792009526..7de998588075 100644 --- a/plugins/devkit/src/run/PluginRunConfigurationEditor.java +++ b/plugins/devkit/src/run/PluginRunConfigurationEditor.java @@ -25,9 +25,13 @@ import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.ui.LabeledComponent; +import com.intellij.ui.ComponentWithAnchor; import com.intellij.ui.RawCommandLineEditor; +import com.intellij.ui.components.JBLabel; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.devkit.DevKitBundle; import org.jetbrains.idea.devkit.projectRoots.IdeaJdk; import org.jetbrains.idea.devkit.projectRoots.Sandbox; @@ -42,13 +46,14 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; -public class PluginRunConfigurationEditor extends SettingsEditor { +public class PluginRunConfigurationEditor extends SettingsEditor implements ComponentWithAnchor { private DefaultComboBoxModel myModulesModel = new DefaultComboBoxModel(); private final JComboBox myModules = new JComboBox(myModulesModel); - private final JLabel myModuleLabel = new JLabel(DevKitBundle.message("run.configuration.classpath.from.module.choose")); + private final JBLabel myModuleLabel = new JBLabel(DevKitBundle.message("run.configuration.classpath.from.module.choose")); private final LabeledComponent myVMParameters = new LabeledComponent(); private final LabeledComponent myProgramParameters = new LabeledComponent(); + private JComponent anchor; @NonNls private final JCheckBox myShowLogs = new JCheckBox(DevKitBundle.message("show.smth", "idea.log")); @@ -88,6 +93,21 @@ public class PluginRunConfigurationEditor extends SettingsEditor - + @@ -74,144 +74,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -287,6 +149,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurable.java b/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurable.java index 45ece6d2fd27..ee841d336e1d 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurable.java +++ b/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurable.java @@ -204,6 +204,7 @@ public class JUnitConfigurable extends SettingsEditor implem setAnchor(myDir.getLabel()); myAlternativeJREPanel.setAnchor(myModule.getLabel()); + myCommonJavaParameters.setAnchor(myModule.getLabel()); } public void applyEditorTo(final JUnitConfiguration configuration) { diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationEditor.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationEditor.java index 7da1bd322d57..6cefd651b4b0 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationEditor.java +++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationEditor.java @@ -184,6 +184,7 @@ public class TestNGConfigurationEditor extends SettingsEditor - + @@ -15,7 +15,7 @@ - + @@ -28,7 +28,7 @@ - + @@ -37,30 +37,21 @@ - + - - - - - - - - - - + - + - + @@ -69,7 +60,7 @@ - + @@ -79,7 +70,7 @@ - + @@ -94,9 +85,7 @@ - - - + @@ -106,7 +95,7 @@ - + @@ -134,7 +123,7 @@ - + @@ -197,8 +186,8 @@ - - + + @@ -227,56 +216,55 @@ - + - + - + - + + + + + + + - + - + - + - + - + - + + + - - - - - - - - - @@ -289,6 +277,15 @@ + + + + + + + + + diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunSettingsEditor.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunSettingsEditor.java index 7cf3a0e245bf..8610b5fc4f7d 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunSettingsEditor.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunSettingsEditor.java @@ -44,10 +44,14 @@ import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.ui.ComboboxWithBrowseButton; +import com.intellij.ui.ComponentWithAnchor; import com.intellij.ui.DocumentAdapter; import com.intellij.ui.RawCommandLineEditor; +import com.intellij.ui.components.JBLabel; +import com.intellij.ui.components.JBRadioButton; import com.intellij.ui.table.JBTable; import com.intellij.util.ArrayUtil; +import com.intellij.util.ui.UIUtil; import org.intellij.lang.xpath.xslt.XsltSupport; import org.intellij.lang.xpath.xslt.associations.FileAssociationsManager; import org.intellij.lang.xpath.xslt.associations.impl.AnyXMLDescriptor; @@ -55,6 +59,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.border.EmptyBorder; import javax.swing.event.DocumentEvent; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableCellRenderer; @@ -66,532 +71,571 @@ import java.util.*; import java.util.List; class XsltRunSettingsEditor extends SettingsEditor { - static final boolean ALLOW_CHOOSING_SDK = !(StdFileTypes.JAVA instanceof PlainTextFileType); - private final Project myProject; + static final boolean ALLOW_CHOOSING_SDK = !(StdFileTypes.JAVA instanceof PlainTextFileType); + private final Project myProject; - private Editor myEditor; + private Editor myEditor; - static class AddParameterAction extends AnAction { - private final JTable myParams; + static class AddParameterAction extends AnAction { + private final JTable myParams; - public AddParameterAction(JTable params) { - super("Add", "Add Parameter", IconLoader.getIcon("/general/add.png")); - myParams = params; - } - - public void actionPerformed(AnActionEvent e) { - ((Editor.ParamTableModel)myParams.getModel()).addParam(); - } + public AddParameterAction(JTable params) { + super("Add", "Add Parameter", IconLoader.getIcon("/general/add.png")); + myParams = params; } - static class RemoveParameterAction extends AnAction { - private final JTable myParams; + public void actionPerformed(AnActionEvent e) { + ((Editor.ParamTableModel)myParams.getModel()).addParam(); + } + } - public RemoveParameterAction(JBTable paramModel) { - super("Remove", "Remove Parameter", IconLoader.getIcon("/general/remove.png")); - myParams = paramModel; - } + static class RemoveParameterAction extends AnAction { + private final JTable myParams; - public void update(AnActionEvent e) { - e.getPresentation().setEnabled(myParams.getRowCount() > 0 && myParams.getSelectedRow() != -1); - } - - public void actionPerformed(AnActionEvent e) { - ((Editor.ParamTableModel)myParams.getModel()).removeParam(myParams.getSelectedRow()); - } + public RemoveParameterAction(JBTable paramModel) { + super("Remove", "Remove Parameter", IconLoader.getIcon("/general/remove.png")); + myParams = paramModel; } - static class Editor { - private JTabbedPane myComponent; + public void update(AnActionEvent e) { + e.getPresentation().setEnabled(myParams.getRowCount() > 0 && myParams.getSelectedRow() != -1); + } - private TextFieldWithBrowseButton myXsltFile; - private ComboboxWithBrowseButton myXmlInputFile; - private TextFieldWithBrowseButton myOutputFile; - private JCheckBox myOpenOutputFile; - private JCheckBox myOpenInBrowser; - private JPanel myParamsToolbar; - private JBTable myParameters; + public void actionPerformed(AnActionEvent e) { + ((Editor.ParamTableModel)myParams.getModel()).removeParam(myParams.getSelectedRow()); + } + } - private ButtonGroup myOutputOptions; - private JRadioButton myShowInConsole; - private JCheckBox mySaveToFile; - private JRadioButton myShowInStdout; + static class Editor implements ComponentWithAnchor { + private JTabbedPane myComponent; - private RawCommandLineEditor myVmArguments; - private JCheckBox mySmartErrorHandling; - private TextFieldWithBrowseButton myWorkingDirectory; + private TextFieldWithBrowseButton myXsltFile; + private ComboboxWithBrowseButton myXmlInputFile; + private TextFieldWithBrowseButton myOutputFile; + private JCheckBox myOpenOutputFile; + private JCheckBox myOpenInBrowser; + private JPanel myParamsToolbar; + private JBTable myParameters; - private ButtonGroup myJdkOptions; - private JRadioButton myJdkChoice; - private JRadioButton myModuleChoice; - private ComboBox myModule; - private ComboBox myJDK; - private ComboBox myFileType; - private JPanel myClasspathAndJDKPanel; + private ButtonGroup myOutputOptions; + private JBRadioButton myShowInConsole; + private JCheckBox mySaveToFile; + private JRadioButton myShowInStdout; - private final AnyXMLDescriptor myXmlDescriptor; - private final FileChooserDescriptor myXsltDescriptor; + private RawCommandLineEditor myVmArguments; + private JCheckBox mySmartErrorHandling; + private TextFieldWithBrowseButton myWorkingDirectory; - public Editor(final Project project) { - final PsiManager psiManager = PsiManager.getInstance(project); + private ButtonGroup myJdkOptions; + private JRadioButton myJdkChoice; + private JRadioButton myModuleChoice; + private ComboBox myModule; + private ComboBox myJDK; + private ComboBox myFileType; + private JPanel myClasspathAndJDKPanel; + private JPanel myPanelSettings; + private JPanel myPanelAdvanced; + private JBLabel myXSLTScriptFileLabel; + private JComponent anchor; - myXsltDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) { - public boolean isFileVisible(final VirtualFile file, boolean showHiddenFiles) { - if (file.isDirectory()) return true; - if (!super.isFileVisible(file, showHiddenFiles)) return false; + private final AnyXMLDescriptor myXmlDescriptor; + private final FileChooserDescriptor myXsltDescriptor; - return ApplicationManager.getApplication().runReadAction(new Computable() { - public Boolean compute() { - final PsiFile psiFile = psiManager.findFile(file); - return psiFile != null && XsltSupport.isXsltFile(psiFile); - } - }); - } - }; - final TextComponentAccessor projectDefaultAccessor = new TextComponentAccessor() { - public String getText(JTextField component) { - final String text = component.getText(); - final VirtualFile baseDir = project.getBaseDir(); - return text.length() > 0 ? text : (baseDir != null ? baseDir.getPresentableUrl() : ""); - } + public Editor(final Project project) { + final PsiManager psiManager = PsiManager.getInstance(project); - public void setText(JTextField component, String text) { - component.setText(text); - } - }; - myXsltFile.addBrowseFolderListener("Choose XSLT File", null, project, myXsltDescriptor, projectDefaultAccessor); - myXsltFile.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { - final VirtualFileManager fileMgr = VirtualFileManager.getInstance(); - final FileAssociationsManager associationsManager = FileAssociationsManager.getInstance(project); - protected void textChanged(DocumentEvent e) { - final String text = myXsltFile.getText(); - final JComboBox comboBox = myXmlInputFile.getComboBox(); - final Object oldXml = getXmlInputFile(); - if (text.length() != 0) { - final ComboBoxModel model = comboBox.getModel(); + myXsltDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) { + public boolean isFileVisible(final VirtualFile file, boolean showHiddenFiles) { + if (file.isDirectory()) return true; + if (!super.isFileVisible(file, showHiddenFiles)) return false; - boolean found = false; - for (int i=0; i() { + public Boolean compute() { + final PsiFile psiFile = psiManager.findFile(file); + return psiFile != null && XsltSupport.isXsltFile(psiFile); + } + }); + } + }; + final TextComponentAccessor projectDefaultAccessor = new TextComponentAccessor() { + public String getText(JTextField component) { + final String text = component.getText(); + final VirtualFile baseDir = project.getBaseDir(); + return text.length() > 0 ? text : (baseDir != null ? baseDir.getPresentableUrl() : ""); + } - final Object[] associations = new String[files.length]; - for (int i = 0; i < files.length; i++) { - final VirtualFile f = files[i].getVirtualFile(); - assert f != null; - associations[i] = f.getPath().replace('/', File.separatorChar); - } - comboBox.setModel(new DefaultComboBoxModel(associations)); - } - if (!found) { - comboBox.getEditor().setItem(oldXml); - } - comboBox.setSelectedItem(oldXml); - } else { - comboBox.setModel(new DefaultComboBoxModel(ArrayUtil.EMPTY_OBJECT_ARRAY)); - comboBox.getEditor().setItem(oldXml); - } - } - }); + public void setText(JTextField component, String text) { + component.setText(text); + } + }; + myXsltFile.addBrowseFolderListener("Choose XSLT File", null, project, myXsltDescriptor, projectDefaultAccessor); + myXsltFile.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { + final VirtualFileManager fileMgr = VirtualFileManager.getInstance(); + final FileAssociationsManager associationsManager = FileAssociationsManager.getInstance(project); - myXmlInputFile.getComboBox().setEditable(true); + protected void textChanged(DocumentEvent e) { + final String text = myXsltFile.getText(); + final JComboBox comboBox = myXmlInputFile.getComboBox(); + final Object oldXml = getXmlInputFile(); + if (text.length() != 0) { + final ComboBoxModel model = comboBox.getModel(); - myXmlDescriptor = new AnyXMLDescriptor(); - myXmlInputFile.addBrowseFolderListener("Choose XML File", null, project, myXmlDescriptor, new TextComponentAccessor() { - public String getText(JComboBox comboBox) { - Object item = comboBox.getEditor().getItem(); - if (item.toString().length() == 0) { - final String text = projectDefaultAccessor.getText(myXsltFile.getChildComponent()); - final VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(text.replace(File.separatorChar, '/'))); - if (file != null && !file.isDirectory()) { - final VirtualFile parent = file.getParent(); - assert parent != null; - return parent.getPresentableUrl(); - } - } - return item.toString(); - } + boolean found = false; + for (int i = 0; i < model.getSize(); i++) { + if (oldXml.equals(model.getElementAt(i))) found = true; + } + final VirtualFile virtualFile = fileMgr.findFileByUrl(VfsUtil.pathToUrl(text.replace(File.separatorChar, '/'))); + final PsiFile psiFile; + if (virtualFile != null && (psiFile = psiManager.findFile(virtualFile)) != null) { + final PsiFile[] files = associationsManager.getAssociationsFor(psiFile); - public void setText(JComboBox comboBox, String text) { - comboBox.getEditor().setItem(text); - } - }); - - myOutputFile.addBrowseFolderListener("Choose Output File", "The selected file will be overwritten during execution.", - project, FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor()); - - final ItemListener outputStateListener = new ItemListener() { - public void itemStateChanged(ItemEvent e) { - updateOutputState(); - } - }; - myShowInConsole.addItemListener(outputStateListener); - myShowInStdout.addItemListener(outputStateListener); - mySaveToFile.addItemListener(outputStateListener); - myClasspathAndJDKPanel.setVisible(ALLOW_CHOOSING_SDK); - updateOutputState(); - - myFileType.setRenderer(new FileTypeRenderer(myFileType.getRenderer()) { - @Override - public void customize(JList list, FileType type, int index, boolean selected, boolean hasFocus) { - if (type == null) { - setIcon(IconLoader.getIcon("/actions/cancel.png")); - setText("Disabled"); - } - else { - super.customize(list, type, index, selected, hasFocus); - } + final Object[] associations = new String[files.length]; + for (int i = 0; i < files.length; i++) { + final VirtualFile f = files[i].getVirtualFile(); + assert f != null; + associations[i] = f.getPath().replace('/', File.separatorChar); } - }); - myFileType.setModel(new DefaultComboBoxModel(getFileTypes(project))); + comboBox.setModel(new DefaultComboBoxModel(associations)); + } + if (!found) { + comboBox.getEditor().setItem(oldXml); + } + comboBox.setSelectedItem(oldXml); + } + else { + comboBox.setModel(new DefaultComboBoxModel(ArrayUtil.EMPTY_OBJECT_ARRAY)); + comboBox.getEditor().setItem(oldXml); + } + } + }); - myParameters.setModel(new ParamTableModel()); - myParameters.setDefaultRenderer(String.class, new DefaultTableCellRenderer() { - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - setForeground(null); - setToolTipText(null); - if (column == 0) { - if (table.getModel().getValueAt(row, 1) == null) { - setForeground(Color.BLUE); - setToolTipText("No value set for parameter '" + value + "'"); - } - } else if (value == null) { - value = ""; - } - return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - } - }); + myXmlInputFile.getComboBox().setEditable(true); - final Module[] modules = ModuleManager.getInstance(project).getModules(); - myModule.setModel(new DefaultComboBoxModel(ArrayUtil.mergeArrays(new Object[]{ "" }, modules, Object.class))); - myModule.setRenderer(new ListCellRendererWrapper(myModule) { - @Override - public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) { - if (value instanceof Module) { - final Module module = (Module)value; - setText(ApplicationManager.getApplication().runReadAction(new Computable() { - public String compute() { - return module.getName(); - } - })); - setIcon(ModuleType.get(module).getNodeIcon(true)); - } else if (value instanceof String) { - setText((String)value); - } + myXmlDescriptor = new AnyXMLDescriptor(); + myXmlInputFile.addBrowseFolderListener("Choose XML File", null, project, myXmlDescriptor, new TextComponentAccessor() { + public String getText(JComboBox comboBox) { + Object item = comboBox.getEditor().getItem(); + if (item.toString().length() == 0) { + final String text = projectDefaultAccessor.getText(myXsltFile.getChildComponent()); + final VirtualFile file = + VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(text.replace(File.separatorChar, '/'))); + if (file != null && !file.isDirectory()) { + final VirtualFile parent = file.getParent(); + assert parent != null; + return parent.getPresentableUrl(); + } + } + return item.toString(); + } + + public void setText(JComboBox comboBox, String text) { + comboBox.getEditor().setItem(text); + } + }); + + myOutputFile.addBrowseFolderListener("Choose Output File", "The selected file will be overwritten during execution.", + project, FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor()); + + final ItemListener outputStateListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + updateOutputState(); + } + }; + myShowInConsole.addItemListener(outputStateListener); + myShowInStdout.addItemListener(outputStateListener); + mySaveToFile.addItemListener(outputStateListener); + myClasspathAndJDKPanel.setVisible(ALLOW_CHOOSING_SDK); + updateOutputState(); + + myFileType.setRenderer(new FileTypeRenderer(myFileType.getRenderer()) { + @Override + public void customize(JList list, FileType type, int index, boolean selected, boolean hasFocus) { + if (type == null) { + setIcon(IconLoader.getIcon("/actions/cancel.png")); + setText("Disabled"); + } + else { + super.customize(list, type, index, selected, hasFocus); + } + } + }); + myFileType.setModel(new DefaultComboBoxModel(getFileTypes(project))); + + myParameters.setModel(new ParamTableModel()); + myParameters.setDefaultRenderer(String.class, new DefaultTableCellRenderer() { + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + setForeground(null); + setToolTipText(null); + if (column == 0) { + if (table.getModel().getValueAt(row, 1) == null) { + setForeground(Color.BLUE); + setToolTipText("No value set for parameter '" + value + "'"); + } + } + else if (value == null) { + value = ""; + } + return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + } + }); + + final Module[] modules = ModuleManager.getInstance(project).getModules(); + myModule.setModel(new DefaultComboBoxModel(ArrayUtil.mergeArrays(new Object[]{""}, modules, Object.class))); + myModule.setRenderer(new ListCellRendererWrapper(myModule) { + @Override + public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) { + if (value instanceof Module) { + final Module module = (Module)value; + setText(ApplicationManager.getApplication().runReadAction(new Computable() { + public String compute() { + return module.getName(); } - }); + })); + setIcon(ModuleType.get(module).getNodeIcon(true)); + } + else if (value instanceof String) { + setText((String)value); + } + } + }); - final Sdk[] allJdks = ProjectJdkTable.getInstance().getAllJdks(); - myJDK.setModel(new DefaultComboBoxModel(allJdks)); - if (allJdks.length > 0) { - myJDK.setSelectedIndex(0); - } else { - myJdkChoice.setEnabled(false); - myJDK.setEnabled(false); - } - myJDK.setRenderer(new ListCellRendererWrapper(myJDK) { - @Override - public void customize(JList list, final Sdk jdk, int index, boolean isSelected, boolean cellHasFocus) { - if (jdk != null) { - setText(ApplicationManager.getApplication().runReadAction(new Computable() { - public String compute() { - return jdk.getName(); - } - })); - setIcon(jdk.getSdkType().getIcon()); - } + final Sdk[] allJdks = ProjectJdkTable.getInstance().getAllJdks(); + myJDK.setModel(new DefaultComboBoxModel(allJdks)); + if (allJdks.length > 0) { + myJDK.setSelectedIndex(0); + } + else { + myJdkChoice.setEnabled(false); + myJDK.setEnabled(false); + } + myJDK.setRenderer(new ListCellRendererWrapper(myJDK) { + @Override + public void customize(JList list, final Sdk jdk, int index, boolean isSelected, boolean cellHasFocus) { + if (jdk != null) { + setText(ApplicationManager.getApplication().runReadAction(new Computable() { + public String compute() { + return jdk.getName(); } - }); - - final ItemListener updateListener = new ItemListener() { - public void itemStateChanged(ItemEvent e) { - updateJdkState(); - } - }; - myModuleChoice.addItemListener(updateListener); - myJdkChoice.addItemListener(updateListener); - updateJdkState(); - - myWorkingDirectory.addBrowseFolderListener("Working Directory", null, project, FileChooserDescriptorFactory.createSingleFolderDescriptor()); - - final DefaultActionGroup group = new DefaultActionGroup(); - group.add(new AddParameterAction(myParameters)); - group.add(new RemoveParameterAction(myParameters)); - final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar("XsltRunSettingsEditor", group, true); - myParamsToolbar.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); - myParamsToolbar.add(actionToolbar.getComponent()); - - myVmArguments.setDialogCaption("VM Arguments"); + })); + setIcon(jdk.getSdkType().getIcon()); + } } + }); - @SuppressWarnings({"UseOfObsoleteCollectionType"}) - private static Vector getFileTypes(Project project) { - final Vector v = new Vector(); - - final FileType[] fileTypes = FileTypeManager.getInstance().getRegisteredFileTypes(); - for (FileType fileType : fileTypes) { - // get rid of file types useless for highlighting - if (fileType == StdFileTypes.CLASS || - fileType == StdFileTypes.IDEA_PROJECT || - fileType == StdFileTypes.IDEA_WORKSPACE || - fileType == StdFileTypes.IDEA_MODULE || - fileType == StdFileTypes.GUI_DESIGNER_FORM) - { - continue; - } - - try { - if (fileType instanceof LanguageFileType) { - final SyntaxHighlighter sh = SyntaxHighlighterFactory.getSyntaxHighlighter(((LanguageFileType)fileType).getLanguage(), project, null); - if (sh != null) { - v.add(fileType); - } - } - } catch (Throwable e) { - Logger.getInstance(XsltRunSettingsEditor.class.getName()).info("Encountered incompatible FileType: " + fileType.getName(), e); - } - } - Collections.sort(v, new Comparator() { - public int compare(FileType o1, FileType o2) { - return o1.getDescription().compareTo(o2.getDescription()); - } - }); - - // off - v.insertElementAt(null, 0); - return v; + final ItemListener updateListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + updateJdkState(); } + }; + myModuleChoice.addItemListener(updateListener); + myJdkChoice.addItemListener(updateListener); + updateJdkState(); - public void resetFrom(XsltRunConfiguration s) { - myXsltFile.setText(s.getXsltFile()); - myXmlInputFile.getComboBox().setSelectedItem(s.getXmlInputFile()); + myWorkingDirectory + .addBrowseFolderListener("Working Directory", null, project, FileChooserDescriptorFactory.createSingleFolderDescriptor()); - final VirtualFile xmlInputFile = s.findXmlInputFile(); - if (xmlInputFile != null) { - final Module contextModule = ProjectRootManager.getInstance(s.getProject()).getFileIndex().getModuleForFile(xmlInputFile); - if (contextModule != null) { - myXmlDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, contextModule); - } else { - myXmlDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, s.getModule()); - } - } else { - myXmlDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, s.getModule()); - } + final DefaultActionGroup group = new DefaultActionGroup(); + group.add(new AddParameterAction(myParameters)); + group.add(new RemoveParameterAction(myParameters)); + final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar("XsltRunSettingsEditor", group, true); + myParamsToolbar.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); + myParamsToolbar.add(actionToolbar.getComponent()); - myFileType.setSelectedItem(s.getFileType()); - myOutputFile.setText(s.myOutputFile); - myOpenOutputFile.setSelected(s.myOpenOutputFile); - myOpenInBrowser.setSelected(s.myOpenInBrowser); - myParameters.setModel(new ParamTableModel(s.getParameters())); - myVmArguments.setText(s.getVmArguments()); - myWorkingDirectory.setText(s.myWorkingDirectory); - final Module module = s.getModule(); - if (module != null) { - myModule.setSelectedItem(module); - myXsltDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, module); - } else { - final VirtualFile xsltFile = s.findXsltFile(); - if (xsltFile != null) { - myXsltDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, ProjectRootManager.getInstance(s.getProject()).getFileIndex().getModuleForFile(xsltFile)); - } - myModule.setSelectedIndex(0); - } - myJDK.setSelectedItem(s.getJdk()); - mySmartErrorHandling.setSelected(s.mySmartErrorHandling); - setSelectedIndex(myOutputOptions, s.getOutputType().ordinal()); - setSelectedIndex(myJdkOptions, s.getJdkChoice().ordinal()); - mySaveToFile.setSelected(s.isSaveToFile()); - } + myVmArguments.setDialogCaption("VM Arguments"); - public void applyTo(XsltRunConfiguration s) { - s.setXsltFile(myXsltFile.getText()); - s.setXmlInputFile(getXmlInputFile()); - s.setFileType((FileType)myFileType.getSelectedItem()); - s.myOutputFile = myOutputFile.getText(); - s.myOpenOutputFile = myOpenOutputFile.isSelected(); - s.myOpenInBrowser = myOpenInBrowser.isSelected(); - s.setParameters(((ParamTableModel)myParameters.getModel()).getParams()); - s.setVmArguments(myVmArguments.getText()); - s.myWorkingDirectory = myWorkingDirectory.getText(); - s.setModule(getModule()); - s.setJDK((Sdk)myJDK.getSelectedItem()); - s.setJdkChoice(XsltRunConfiguration.JdkChoice.values()[getSelectedIndex(myJdkOptions)]); - s.mySmartErrorHandling = mySmartErrorHandling.isSelected(); - s.setOutputType(XsltRunConfiguration.OutputType.values()[getSelectedIndex(myOutputOptions)]); - s.setSaveToFile(mySaveToFile.isSelected()); - } + myPanelSettings.setBorder(new EmptyBorder(UIUtil.PANEL_SMALL_INSETS)); + myPanelAdvanced.setBorder(new EmptyBorder(UIUtil.PANEL_SMALL_INSETS)); - private void updateOutputState() { - myOutputFile.setEnabled(mySaveToFile.isSelected()); - myOpenOutputFile.setEnabled(mySaveToFile.isEnabled() && mySaveToFile.isSelected()); - myOpenInBrowser.setEnabled(mySaveToFile.isEnabled() && mySaveToFile.isSelected()); - - final int selectedIndex = getSelectedIndex(myOutputOptions); - final boolean b = selectedIndex == XsltRunConfiguration.OutputType.CONSOLE.ordinal(); - myFileType.setEnabled(b); - } - - private void updateJdkState() { - myModule.setEnabled(getSelectedIndex(myJdkOptions) == XsltRunConfiguration.JdkChoice.FROM_MODULE.ordinal()); - myJDK.setEnabled(getSelectedIndex(myJdkOptions) == XsltRunConfiguration.JdkChoice.JDK.ordinal()); - } - - @Nullable - private Module getModule() { - final Object selectedItem = myModule.getSelectedItem(); - return selectedItem instanceof Module ? (Module)selectedItem : null; - } - - private String getXmlInputFile() { - final JComboBox comboBox = myXmlInputFile.getComboBox(); - final Object currentItem = comboBox.getEditor().getItem(); - String s = (String)(currentItem != null ? currentItem : comboBox.getSelectedItem()); - return s != null ? s : ""; - } - - private static void setSelectedIndex(ButtonGroup group, int i) { - final Enumeration buttons = group.getElements(); - //noinspection ForLoopThatDoesntUseLoopVariable - for (int j = 0; buttons.hasMoreElements(); j++) { - group.setSelected(buttons.nextElement().getModel(), i == j); - } - } - - private static int getSelectedIndex(ButtonGroup group) { - final ButtonModel selection = group.getSelection(); - if (selection == null) return -1; - final Enumeration buttons = group.getElements(); - //noinspection ForLoopThatDoesntUseLoopVariable - for (int i = 0; buttons.hasMoreElements(); i++) { - final AbstractButton button = buttons.nextElement(); - if (group.isSelected(button.getModel())) return i; - } - return -1; - } - - private static class ParamTableModel extends AbstractTableModel { - static class Param { - public String name; - public String value; - - public Param(String name, String value) { - this.name = name; - this.value = value; - } - - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final Param param = (Param)o; - - return name.equals(param.name) && value.equals(param.value); - } - - public int hashCode() { - int result = name.hashCode(); - result = 29 * result + value.hashCode(); - return result; - } - } - - private final List myParams = new ArrayList(); - - public ParamTableModel() { - } - - public ParamTableModel(List> params) { - for (Pair pair : params) { - myParams.add(new Param(pair.getFirst(), pair.getSecond())); - } - } - - public Class getColumnClass(int columnIndex) { - return String.class; - } - - public int getRowCount() { - return myParams.size(); - } - - public int getColumnCount() { - return 2; - } - - public String getColumnName(int column) { - return column == 0 ? "Name" : "Value"; - } - - public boolean isCellEditable(int rowIndex, int columnIndex) { - return true; - } - - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - // can happen if param is deleted while editing it - if (rowIndex >= myParams.size()) return; - - final Param param = myParams.get(rowIndex); - final String value = (String)aValue; - if (columnIndex == 0) { - param.name = value; - } else { - param.value = value; - } - fireTableCellUpdated(rowIndex, columnIndex); - } - - public Object getValueAt(int rowIndex, int columnIndex) { - final Param param = myParams.get(rowIndex); - return columnIndex == 0 ? param.name : param.value; - } - - public void addParam() { - myParams.add(new Param("Param" + (myParams.size() + 1), null)); - fireTableRowsInserted(myParams.size() - 1, myParams.size() - 1); - } - - public void removeParam(int selectedRow) { - myParams.remove(selectedRow); - fireTableRowsDeleted(selectedRow, selectedRow); - } - - public List> getParams() { - final ArrayList> pairs = new ArrayList>(myParams.size()); - for (Param param : myParams) { - pairs.add(Pair.create(param.name, param.value)); - } - return pairs; - } - } - - public JComponent getComponent() { - return myComponent; - } + setAnchor(myShowInConsole); } - public XsltRunSettingsEditor(Project project) { - myProject = project; + @Override + public JComponent getAnchor() { + return anchor; } - protected void resetEditorFrom(XsltRunConfiguration s) { - myEditor.resetFrom(s); + @Override + public void setAnchor(@Nullable JComponent anchor) { + this.anchor = anchor; + myXSLTScriptFileLabel.setAnchor(anchor); + myShowInConsole.setAnchor(anchor); } - protected void applyEditorTo(XsltRunConfiguration s) throws ConfigurationException { - myEditor.applyTo(s); + @SuppressWarnings({"UseOfObsoleteCollectionType"}) + private static Vector getFileTypes(Project project) { + final Vector v = new Vector(); + + final FileType[] fileTypes = FileTypeManager.getInstance().getRegisteredFileTypes(); + for (FileType fileType : fileTypes) { + // get rid of file types useless for highlighting + if (fileType == StdFileTypes.CLASS || + fileType == StdFileTypes.IDEA_PROJECT || + fileType == StdFileTypes.IDEA_WORKSPACE || + fileType == StdFileTypes.IDEA_MODULE || + fileType == StdFileTypes.GUI_DESIGNER_FORM) { + continue; + } + + try { + if (fileType instanceof LanguageFileType) { + final SyntaxHighlighter sh = + SyntaxHighlighterFactory.getSyntaxHighlighter(((LanguageFileType)fileType).getLanguage(), project, null); + if (sh != null) { + v.add(fileType); + } + } + } + catch (Throwable e) { + Logger.getInstance(XsltRunSettingsEditor.class.getName()).info("Encountered incompatible FileType: " + fileType.getName(), e); + } + } + Collections.sort(v, new Comparator() { + public int compare(FileType o1, FileType o2) { + return o1.getDescription().compareTo(o2.getDescription()); + } + }); + + // off + v.insertElementAt(null, 0); + return v; } - @NotNull - protected JComponent createEditor() { - myEditor = new Editor(myProject); - return myEditor.getComponent(); + public void resetFrom(XsltRunConfiguration s) { + myXsltFile.setText(s.getXsltFile()); + myXmlInputFile.getComboBox().setSelectedItem(s.getXmlInputFile()); + + final VirtualFile xmlInputFile = s.findXmlInputFile(); + if (xmlInputFile != null) { + final Module contextModule = ProjectRootManager.getInstance(s.getProject()).getFileIndex().getModuleForFile(xmlInputFile); + if (contextModule != null) { + myXmlDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, contextModule); + } + else { + myXmlDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, s.getModule()); + } + } + else { + myXmlDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, s.getModule()); + } + + myFileType.setSelectedItem(s.getFileType()); + myOutputFile.setText(s.myOutputFile); + myOpenOutputFile.setSelected(s.myOpenOutputFile); + myOpenInBrowser.setSelected(s.myOpenInBrowser); + myParameters.setModel(new ParamTableModel(s.getParameters())); + myVmArguments.setText(s.getVmArguments()); + myWorkingDirectory.setText(s.myWorkingDirectory); + final Module module = s.getModule(); + if (module != null) { + myModule.setSelectedItem(module); + myXsltDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, module); + } + else { + final VirtualFile xsltFile = s.findXsltFile(); + if (xsltFile != null) { + myXsltDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, + ProjectRootManager.getInstance(s.getProject()).getFileIndex().getModuleForFile(xsltFile)); + } + myModule.setSelectedIndex(0); + } + myJDK.setSelectedItem(s.getJdk()); + mySmartErrorHandling.setSelected(s.mySmartErrorHandling); + setSelectedIndex(myOutputOptions, s.getOutputType().ordinal()); + setSelectedIndex(myJdkOptions, s.getJdkChoice().ordinal()); + mySaveToFile.setSelected(s.isSaveToFile()); } - protected void disposeEditor() { - myEditor = null; + public void applyTo(XsltRunConfiguration s) { + s.setXsltFile(myXsltFile.getText()); + s.setXmlInputFile(getXmlInputFile()); + s.setFileType((FileType)myFileType.getSelectedItem()); + s.myOutputFile = myOutputFile.getText(); + s.myOpenOutputFile = myOpenOutputFile.isSelected(); + s.myOpenInBrowser = myOpenInBrowser.isSelected(); + s.setParameters(((ParamTableModel)myParameters.getModel()).getParams()); + s.setVmArguments(myVmArguments.getText()); + s.myWorkingDirectory = myWorkingDirectory.getText(); + s.setModule(getModule()); + s.setJDK((Sdk)myJDK.getSelectedItem()); + s.setJdkChoice(XsltRunConfiguration.JdkChoice.values()[getSelectedIndex(myJdkOptions)]); + s.mySmartErrorHandling = mySmartErrorHandling.isSelected(); + s.setOutputType(XsltRunConfiguration.OutputType.values()[getSelectedIndex(myOutputOptions)]); + s.setSaveToFile(mySaveToFile.isSelected()); } + + private void updateOutputState() { + myOutputFile.setEnabled(mySaveToFile.isSelected()); + myOpenOutputFile.setEnabled(mySaveToFile.isEnabled() && mySaveToFile.isSelected()); + myOpenInBrowser.setEnabled(mySaveToFile.isEnabled() && mySaveToFile.isSelected()); + + final int selectedIndex = getSelectedIndex(myOutputOptions); + final boolean b = selectedIndex == XsltRunConfiguration.OutputType.CONSOLE.ordinal(); + myFileType.setEnabled(b); + } + + private void updateJdkState() { + myModule.setEnabled(getSelectedIndex(myJdkOptions) == XsltRunConfiguration.JdkChoice.FROM_MODULE.ordinal()); + myJDK.setEnabled(getSelectedIndex(myJdkOptions) == XsltRunConfiguration.JdkChoice.JDK.ordinal()); + } + + @Nullable + private Module getModule() { + final Object selectedItem = myModule.getSelectedItem(); + return selectedItem instanceof Module ? (Module)selectedItem : null; + } + + private String getXmlInputFile() { + final JComboBox comboBox = myXmlInputFile.getComboBox(); + final Object currentItem = comboBox.getEditor().getItem(); + String s = (String)(currentItem != null ? currentItem : comboBox.getSelectedItem()); + return s != null ? s : ""; + } + + private static void setSelectedIndex(ButtonGroup group, int i) { + final Enumeration buttons = group.getElements(); + //noinspection ForLoopThatDoesntUseLoopVariable + for (int j = 0; buttons.hasMoreElements(); j++) { + group.setSelected(buttons.nextElement().getModel(), i == j); + } + } + + private static int getSelectedIndex(ButtonGroup group) { + final ButtonModel selection = group.getSelection(); + if (selection == null) return -1; + final Enumeration buttons = group.getElements(); + //noinspection ForLoopThatDoesntUseLoopVariable + for (int i = 0; buttons.hasMoreElements(); i++) { + final AbstractButton button = buttons.nextElement(); + if (group.isSelected(button.getModel())) return i; + } + return -1; + } + + private static class ParamTableModel extends AbstractTableModel { + static class Param { + public String name; + public String value; + + public Param(String name, String value) { + this.name = name; + this.value = value; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + final Param param = (Param)o; + + return name.equals(param.name) && value.equals(param.value); + } + + public int hashCode() { + int result = name.hashCode(); + result = 29 * result + value.hashCode(); + return result; + } + } + + private final List myParams = new ArrayList(); + + public ParamTableModel() { + } + + public ParamTableModel(List> params) { + for (Pair pair : params) { + myParams.add(new Param(pair.getFirst(), pair.getSecond())); + } + } + + public Class getColumnClass(int columnIndex) { + return String.class; + } + + public int getRowCount() { + return myParams.size(); + } + + public int getColumnCount() { + return 2; + } + + public String getColumnName(int column) { + return column == 0 ? "Name" : "Value"; + } + + public boolean isCellEditable(int rowIndex, int columnIndex) { + return true; + } + + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + // can happen if param is deleted while editing it + if (rowIndex >= myParams.size()) return; + + final Param param = myParams.get(rowIndex); + final String value = (String)aValue; + if (columnIndex == 0) { + param.name = value; + } + else { + param.value = value; + } + fireTableCellUpdated(rowIndex, columnIndex); + } + + public Object getValueAt(int rowIndex, int columnIndex) { + final Param param = myParams.get(rowIndex); + return columnIndex == 0 ? param.name : param.value; + } + + public void addParam() { + myParams.add(new Param("Param" + (myParams.size() + 1), null)); + fireTableRowsInserted(myParams.size() - 1, myParams.size() - 1); + } + + public void removeParam(int selectedRow) { + myParams.remove(selectedRow); + fireTableRowsDeleted(selectedRow, selectedRow); + } + + public List> getParams() { + final ArrayList> pairs = new ArrayList>(myParams.size()); + for (Param param : myParams) { + pairs.add(Pair.create(param.name, param.value)); + } + return pairs; + } + } + + public JComponent getComponent() { + return myComponent; + } + } + + public XsltRunSettingsEditor(Project project) { + myProject = project; + } + + protected void resetEditorFrom(XsltRunConfiguration s) { + myEditor.resetFrom(s); + } + + protected void applyEditorTo(XsltRunConfiguration s) throws ConfigurationException { + myEditor.applyTo(s); + } + + @NotNull + protected JComponent createEditor() { + myEditor = new Editor(myProject); + return myEditor.getComponent(); + } + + protected void disposeEditor() { + myEditor = null; + } }