2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.execution
.junit2
.configuration
;
18 import com
.intellij
.execution
.ExecutionBundle
;
19 import com
.intellij
.execution
.RunJavaConfiguration
;
20 import com
.intellij
.openapi
.actionSystem
.LangDataKeys
;
21 import com
.intellij
.openapi
.diagnostic
.Logger
;
22 import com
.intellij
.openapi
.fileChooser
.FileChooser
;
23 import com
.intellij
.openapi
.fileChooser
.FileChooserDescriptor
;
24 import com
.intellij
.openapi
.fileChooser
.FileChooserDescriptorFactory
;
25 import com
.intellij
.openapi
.module
.Module
;
26 import com
.intellij
.openapi
.ui
.LabeledComponent
;
27 import com
.intellij
.openapi
.ui
.TextFieldWithBrowseButton
;
28 import com
.intellij
.openapi
.vfs
.VirtualFile
;
29 import com
.intellij
.ui
.RawCommandLineEditor
;
33 import java
.awt
.event
.ActionEvent
;
34 import java
.awt
.event
.ActionListener
;
36 public class CommonJavaParameters
extends JPanel
{
37 private static final Logger LOG
= Logger
.getInstance("#com.intellij.execution.junit2.configuration.CommonJavaParameters");
38 private static final int[] ourProperties
= new int[]{
39 RunJavaConfiguration
.PROGRAM_PARAMETERS_PROPERTY
,
40 RunJavaConfiguration
.VM_PARAMETERS_PROPERTY
,
41 RunJavaConfiguration
.WORKING_DIRECTORY_PROPERTY
44 private JPanel myWholePanel
;
45 private LabeledComponent
<TextFieldWithBrowseButton
> myWorkingDirectory
;
46 private LabeledComponent
<RawCommandLineEditor
> myProgramParameters
;
47 private LabeledComponent
<RawCommandLineEditor
> myVMParameters
;
49 private final LabeledComponent
[] myFields
= new LabeledComponent
[3];
50 private Module myModule
= null;
52 public CommonJavaParameters() {
53 super(new BorderLayout());
54 add(myWholePanel
, BorderLayout
.CENTER
);
55 copyDialogCaption(myProgramParameters
);
56 copyDialogCaption(myVMParameters
);
57 myWorkingDirectory
.getComponent()
58 .addActionListener(new ActionListener() {
59 public void actionPerformed(ActionEvent e
) {
60 FileChooserDescriptor fileChooserDescriptor
= FileChooserDescriptorFactory
.createSingleFolderDescriptor();
61 fileChooserDescriptor
.setTitle(ExecutionBundle
.message("select.working.directory.message"));
62 fileChooserDescriptor
.putUserData(LangDataKeys
.MODULE_CONTEXT
, myModule
);
63 VirtualFile
[] files
= FileChooser
.chooseFiles(myWorkingDirectory
, fileChooserDescriptor
);
64 if (files
.length
!= 0) {
65 setText(RunJavaConfiguration
.WORKING_DIRECTORY_PROPERTY
, files
[0].getPresentableUrl());
69 myFields
[RunJavaConfiguration
.PROGRAM_PARAMETERS_PROPERTY
] = myProgramParameters
;
70 myFields
[RunJavaConfiguration
.VM_PARAMETERS_PROPERTY
] = myVMParameters
;
71 myFields
[RunJavaConfiguration
.WORKING_DIRECTORY_PROPERTY
] = myWorkingDirectory
;
74 private static void copyDialogCaption(final LabeledComponent
<RawCommandLineEditor
> component
) {
75 final RawCommandLineEditor rawCommandLineEditor
= component
.getComponent();
76 rawCommandLineEditor
.setDialogCaption(component
.getRawText());
77 component
.getLabel().setLabelFor(rawCommandLineEditor
.getTextField());
80 public String
getProgramParametersText() {
81 return getLabeledComponent(RunJavaConfiguration
.PROGRAM_PARAMETERS_PROPERTY
).getText();
84 public void setProgramParametersText(String textWithMnemonic
) {
85 getLabeledComponent(RunJavaConfiguration
.PROGRAM_PARAMETERS_PROPERTY
).setText(textWithMnemonic
);
86 copyDialogCaption(myProgramParameters
);
89 public void applyTo(final RunJavaConfiguration configuration
) {
90 for (final int property
: ourProperties
) {
91 configuration
.setProperty(property
, getText(property
));
95 public void reset(final RunJavaConfiguration configuration
) {
96 for (final int property
: ourProperties
) {
97 setText(property
, configuration
.getProperty(property
));
101 public void setText(final int property
, final String value
) {
102 final JComponent component
= getLabeledComponent(property
).getComponent();
103 if (component
instanceof TextFieldWithBrowseButton
)
104 ((TextFieldWithBrowseButton
)component
).setText(value
);
105 else if (component
instanceof RawCommandLineEditor
)
106 ((RawCommandLineEditor
)component
).setText(value
);
107 else LOG
.error(component
.getClass().getName());
110 public String
getText(final int property
) {
111 final JComponent component
= getLabeledComponent(property
).getComponent();
112 if (component
instanceof TextFieldWithBrowseButton
)
113 return ((TextFieldWithBrowseButton
)component
).getText();
114 else if (component
instanceof RawCommandLineEditor
)
115 return ((RawCommandLineEditor
)component
).getText();
116 else LOG
.error(component
.getClass().getName());
120 private LabeledComponent
getLabeledComponent(final int index
) {
121 return myFields
[index
];
124 public void setModuleContext(final Module module
) {