1 package com
.intellij
.execution
.impl
;
3 import com
.intellij
.execution
.BeforeRunTask
;
4 import com
.intellij
.execution
.BeforeRunTaskProvider
;
5 import com
.intellij
.execution
.configurations
.RunConfiguration
;
6 import com
.intellij
.execution
.configurations
.UnknownRunConfiguration
;
7 import com
.intellij
.openapi
.extensions
.Extensions
;
8 import com
.intellij
.openapi
.options
.ConfigurationException
;
9 import com
.intellij
.openapi
.options
.SettingsEditor
;
10 import com
.intellij
.openapi
.ui
.FixedSizeButton
;
11 import com
.intellij
.openapi
.util
.Disposer
;
12 import com
.intellij
.openapi
.util
.Key
;
13 import org
.jetbrains
.annotations
.NotNull
;
17 import java
.awt
.event
.ActionEvent
;
18 import java
.awt
.event
.ActionListener
;
19 import java
.util
.Collections
;
26 public class ConfigurationSettingsEditorWrapper
extends SettingsEditor
<RunnerAndConfigurationSettingsImpl
> {
28 private JPanel myComponentPlace
;
29 private JCheckBox myCbStoreProjectConfiguration
;
30 private JPanel myWholePanel
;
32 private JPanel myStepsPanel
;
33 private Map
<Key
<?
extends BeforeRunTask
>, BeforeRunTask
> myStepsBeforeLaunch
;
35 private boolean myStoreProjectConfiguration
;
37 private final ConfigurationSettingsEditor myEditor
;
39 public ConfigurationSettingsEditorWrapper(final RunnerAndConfigurationSettingsImpl settings
) {
40 myEditor
= new ConfigurationSettingsEditor(settings
);
41 Disposer
.register(this, myEditor
);
45 private void doReset(RunnerAndConfigurationSettingsImpl settings
) {
46 final RunConfiguration runConfiguration
= settings
.getConfiguration();
47 final RunManagerImpl runManager
= RunManagerImpl
.getInstanceImpl(runConfiguration
.getProject());
49 myStepsBeforeLaunch
= runManager
.getBeforeRunTasks(runConfiguration
);
51 final BeforeRunTaskProvider
[] providers
= Extensions
.getExtensions(BeforeRunTaskProvider
.EXTENSION_POINT_NAME
,
52 runConfiguration
.getProject());
53 myStepsPanel
.removeAll();
54 if (providers
.length
== 0 || runConfiguration
instanceof UnknownRunConfiguration
) {
55 myStepsPanel
.setVisible(false);
58 myStepsPanel
.setLayout(new GridLayout(providers
.length
, 1));
59 for (BeforeRunTaskProvider provider
: providers
) {
60 final StepBeforeLaunchRow stepRow
= new StepBeforeLaunchRow(runConfiguration
, myStepsBeforeLaunch
, provider
);
61 myStepsPanel
.add(stepRow
);
65 myStoreProjectConfiguration
= runManager
.isConfigurationShared(settings
);
66 myCbStoreProjectConfiguration
.setEnabled(!(runConfiguration
instanceof UnknownRunConfiguration
));
67 myCbStoreProjectConfiguration
.setSelected(myStoreProjectConfiguration
);
68 myCbStoreProjectConfiguration
.addActionListener(new ActionListener() {
69 public void actionPerformed(ActionEvent e
) {
70 myStoreProjectConfiguration
= myCbStoreProjectConfiguration
.isSelected();
76 protected JComponent
createEditor() {
77 myComponentPlace
.setLayout(new GridBagLayout());
78 myComponentPlace
.add(myEditor
.getComponent(), new GridBagConstraints(0,0,1,1,1.0,1.0, GridBagConstraints
.NORTHWEST
, GridBagConstraints
.BOTH
, new Insets(0,0,0,0), 0,0));
79 myComponentPlace
.doLayout();
83 protected void disposeEditor() {
86 public void resetEditorFrom(final RunnerAndConfigurationSettingsImpl settings
) {
87 myEditor
.resetEditorFrom(settings
);
91 public void applyEditorTo(final RunnerAndConfigurationSettingsImpl settings
) throws ConfigurationException
{
92 myEditor
.applyEditorTo(settings
);
96 public RunnerAndConfigurationSettingsImpl
getSnapshot() throws ConfigurationException
{
97 RunnerAndConfigurationSettingsImpl result
= myEditor
.getSnapshot();
102 private void doApply(final RunnerAndConfigurationSettingsImpl settings
) {
103 final RunConfiguration runConfiguration
= settings
.getConfiguration();
104 final RunManagerImpl runManager
= RunManagerImpl
.getInstanceImpl(runConfiguration
.getProject());
105 runManager
.setBeforeRunTasks(runConfiguration
, myStepsBeforeLaunch
);
106 runManager
.shareConfiguration(runConfiguration
, myStoreProjectConfiguration
);
109 public Map
<Key
<?
extends BeforeRunTask
>, BeforeRunTask
> getStepsBeforeLaunch() {
110 return Collections
.unmodifiableMap(myStepsBeforeLaunch
);
113 public boolean isStoreProjectConfiguration() {
114 return myStoreProjectConfiguration
;
117 private class StepBeforeLaunchRow
extends JPanel
{
118 private final JCheckBox myCheckBox
;
119 private FixedSizeButton myButton
;
121 public StepBeforeLaunchRow(final RunConfiguration runConfiguration
, final Map
<Key
<?
extends BeforeRunTask
>, BeforeRunTask
> tasks
, final BeforeRunTaskProvider
<BeforeRunTask
> provider
) {
122 super(new GridBagLayout());
123 final BeforeRunTask beforeRunTask
= tasks
.get(provider
.getId());
124 final boolean isChecked
= beforeRunTask
.isEnabled();
125 myCheckBox
= new JCheckBox(provider
.getDescription(runConfiguration
, beforeRunTask
), isChecked
);
126 GridBagConstraints gc
= new GridBagConstraints(GridBagConstraints
.RELATIVE
, 0 , 1, 1, 0, 1, GridBagConstraints
.WEST
, GridBagConstraints
.NONE
, new Insets(0,0,0,0), 0, 0);
129 if (provider
.hasConfigurationButton()) {
130 myButton
= new FixedSizeButton(20);
133 myButton
.addActionListener(new ActionListener() {
134 public void actionPerformed(ActionEvent e
) {
135 provider
.configureTask(runConfiguration
, beforeRunTask
);
136 myCheckBox
.setText(provider
.getDescription(runConfiguration
, beforeRunTask
));
141 add(Box
.createHorizontalBox(), gc
);
143 enableSettings(provider
, runConfiguration
, beforeRunTask
);
144 myCheckBox
.addActionListener(new ActionListener() {
145 public void actionPerformed(ActionEvent e
) {
146 beforeRunTask
.setEnabled(myCheckBox
.isSelected());
147 enableSettings(provider
, runConfiguration
, beforeRunTask
);
152 private void enableSettings(BeforeRunTaskProvider
<BeforeRunTask
> provider
, final RunConfiguration runConfiguration
, final BeforeRunTask task
) {
153 if (myButton
!= null) {
154 myButton
.setEnabled(myCheckBox
.isSelected());
156 myCheckBox
.setText(provider
.getDescription(runConfiguration
, task
));