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.
17 package com
.intellij
.execution
.impl
;
19 import com
.intellij
.execution
.ExecutionBundle
;
20 import com
.intellij
.execution
.Executor
;
21 import com
.intellij
.execution
.configurations
.RunConfiguration
;
22 import com
.intellij
.openapi
.help
.HelpManager
;
23 import com
.intellij
.openapi
.options
.ConfigurationException
;
24 import com
.intellij
.openapi
.options
.ex
.SingleConfigurableEditor
;
25 import com
.intellij
.openapi
.project
.Project
;
26 import com
.intellij
.openapi
.ui
.DialogWrapper
;
27 import com
.intellij
.openapi
.ui
.Messages
;
28 import com
.intellij
.openapi
.wm
.ex
.IdeFocusTraversalPolicy
;
29 import org
.jetbrains
.annotations
.NonNls
;
32 import java
.awt
.event
.ActionEvent
;
34 public class RunDialog
extends DialogWrapper
{
35 private final Project myProject
;
36 private final RunConfigurable myConfigurable
;
37 private JComponent myCenterPanel
;
38 @NonNls public static String HELP_ID
= "reference.dialogs.rundebug";
39 private final Executor myExecutor
;
41 public RunDialog(final Project project
, final Executor executor
) {
44 myExecutor
= executor
;
46 final String title
= executor
.getId();
49 setOKButtonText(executor
.getStartActionText());
50 setOKButtonIcon(executor
.getIcon());
52 myConfigurable
= new RunConfigurable(project
, this);
54 myConfigurable
.reset();
57 protected Action
[] createActions(){
58 return new Action
[]{getOKAction(),getCancelAction(),new ApplyAction(),getHelpAction()};
61 protected void doHelpAction() {
62 HelpManager
.getInstance().invokeHelp(HELP_ID
);
65 protected String
getDimensionServiceKey(){
66 return "#com.intellij.execution.impl.RunDialog";
69 public JComponent
getPreferredFocusedComponent() {
70 return IdeFocusTraversalPolicy
.getPreferredFocusedComponent(myCenterPanel
);
73 protected void doOKAction(){
75 myConfigurable
.apply();
77 catch(ConfigurationException e
){
78 Messages
.showMessageDialog(myProject
, e
.getMessage(), ExecutionBundle
.message("invalid.data.dialog.title"), Messages
.getErrorIcon());
84 protected JComponent
createCenterPanel() {
85 myCenterPanel
= myConfigurable
.createComponent();
89 public void setOKActionEnabled(final boolean isEnabled
){
90 super.setOKActionEnabled(isEnabled
);
93 protected void dispose() {
94 myConfigurable
.disposeUIResources();
98 public static boolean editConfiguration(final Project project
, final RunnerAndConfigurationSettingsImpl configuration
, final String title
) {
99 return editConfiguration(project
, configuration
, title
, null, null);
102 public static boolean editConfiguration(final Project project
, final RunnerAndConfigurationSettingsImpl configuration
, final String title
, final String okText
, final Icon okIcon
) {
103 final SingleConfigurationConfigurable
<RunConfiguration
> configurable
= SingleConfigurationConfigurable
.editSettings(configuration
);
104 final SingleConfigurableEditor dialog
= new SingleConfigurableEditor(project
, configurable
) {
106 if (okIcon
!= null) setOKButtonIcon(okIcon
);
107 if (okText
!= null) setOKButtonText(okText
);
111 dialog
.setTitle(title
);
113 return dialog
.isOK();
116 private class ApplyAction
extends AbstractAction
{
117 public ApplyAction() {
118 super(ExecutionBundle
.message("apply.action.name"));
121 public void actionPerformed(final ActionEvent event
) {
123 myConfigurable
.apply();
125 catch(ConfigurationException e
){
126 Messages
.showMessageDialog(myProject
, e
.getMessage(), ExecutionBundle
.message("invalid.data.dialog.title"), Messages
.getErrorIcon());
131 public Executor
getExecutor() {