NotNull, dispose
[fedora-idea.git] / platform / lang-impl / src / com / intellij / execution / impl / RunDialog.java
blobe9be41398d987b0d21c5b56cfa7a8da6211e044c
1 /*
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;
31 import javax.swing.*;
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) {
42 super(project, true);
43 myProject = project;
44 myExecutor = executor;
46 final String title = executor.getId();
47 setTitle(title);
49 setOKButtonText(executor.getStartActionText());
50 setOKButtonIcon(executor.getIcon());
52 myConfigurable = new RunConfigurable(project, this);
53 init();
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(){
74 try{
75 myConfigurable.apply();
77 catch(ConfigurationException e){
78 Messages.showMessageDialog(myProject, e.getMessage(), ExecutionBundle.message("invalid.data.dialog.title"), Messages.getErrorIcon());
79 return;
81 super.doOKAction();
84 protected JComponent createCenterPanel() {
85 myCenterPanel = myConfigurable.createComponent();
86 return myCenterPanel;
89 public void setOKActionEnabled(final boolean isEnabled){
90 super.setOKActionEnabled(isEnabled);
93 protected void dispose() {
94 myConfigurable.disposeUIResources();
95 super.dispose();
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);
112 dialog.show();
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) {
122 try{
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() {
132 return myExecutor;