update copyright
[fedora-idea.git] / plugins / devkit / src / run / PluginRunConfigurationEditor.java
blob0473e7edb4dd6c1c26f367e3c586bfa0f450ee17
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.
16 package org.jetbrains.idea.devkit.run;
18 import com.intellij.execution.configurations.LogFileOptions;
19 import com.intellij.openapi.application.ApplicationManager;
20 import com.intellij.openapi.diagnostic.Logger;
21 import com.intellij.openapi.module.Module;
22 import com.intellij.openapi.options.ConfigurationException;
23 import com.intellij.openapi.options.SettingsEditor;
24 import com.intellij.openapi.projectRoots.Sdk;
25 import com.intellij.openapi.roots.ModuleRootManager;
26 import com.intellij.openapi.ui.LabeledComponent;
27 import com.intellij.openapi.util.Computable;
28 import com.intellij.ui.RawCommandLineEditor;
29 import org.jetbrains.annotations.NonNls;
30 import org.jetbrains.annotations.NotNull;
31 import org.jetbrains.idea.devkit.DevKitBundle;
32 import org.jetbrains.idea.devkit.projectRoots.IdeaJdk;
33 import org.jetbrains.idea.devkit.projectRoots.Sandbox;
35 import javax.swing.*;
36 import javax.swing.event.ChangeEvent;
37 import javax.swing.event.ChangeListener;
38 import java.awt.*;
39 import java.awt.event.ActionEvent;
40 import java.awt.event.ActionListener;
41 import java.io.File;
42 import java.io.IOException;
43 import java.util.ArrayList;
45 public class PluginRunConfigurationEditor extends SettingsEditor<PluginRunConfiguration> {
47 private DefaultComboBoxModel myModulesModel = new DefaultComboBoxModel();
48 private final JComboBox myModules = new JComboBox(myModulesModel);
49 private final JLabel myModuleLabel = new JLabel(DevKitBundle.message("run.configuration.classpath.from.module.choose"));
50 private final LabeledComponent<RawCommandLineEditor> myVMParameters = new LabeledComponent<RawCommandLineEditor>();
51 private final LabeledComponent<RawCommandLineEditor> myProgramParameters = new LabeledComponent<RawCommandLineEditor>();
53 @NonNls private final JCheckBox myShowLogs = new JCheckBox(DevKitBundle.message("show.smth", "idea.log"));
55 private final PluginRunConfiguration myPRC;
56 private static final Logger LOG = Logger.getInstance("#org.jetbrains.idea.devkit.run.PluginRunConfigurationEditor");
58 public PluginRunConfigurationEditor(final PluginRunConfiguration prc) {
59 myPRC = prc;
60 myShowLogs.setSelected(isShow(prc));
61 myShowLogs.addChangeListener(new ChangeListener() {
62 public void stateChanged(ChangeEvent e) {
63 setShow(prc, myShowLogs.isSelected());
65 });
66 myModules.addActionListener(new ActionListener() {
67 public void actionPerformed(ActionEvent e) {
68 if (myModules.getSelectedItem() != null){
69 prc.removeAllLogFiles();
70 Sdk jdk = ModuleRootManager.getInstance((Module)myModules.getSelectedItem()).getSdk();
71 jdk = IdeaJdk.findIdeaJdk(jdk);
72 if (jdk != null) {
73 final String sandboxHome = ((Sandbox)jdk.getSdkAdditionalData()).getSandboxHome();
74 if (sandboxHome == null){
75 return;
77 try {
78 @NonNls final String file = new File(sandboxHome).getCanonicalPath() + File.separator + "system" + File.separator + "log" + File.separator +
79 "idea.log";
80 if (new File(file).exists()){
81 prc.addLogFile(file, DevKitBundle.message("idea.log.tab.title"), myShowLogs.isSelected());
84 catch (IOException e1) {
85 LOG.error(e1);
90 });
93 private static void setShow(PluginRunConfiguration prc, boolean show){
94 final ArrayList<LogFileOptions> logFiles = prc.getLogFiles();
95 for (LogFileOptions logFile: logFiles) {
96 logFile.setEnable(show);
100 private static boolean isShow(PluginRunConfiguration prc){
101 final ArrayList<LogFileOptions> logFiles = prc.getLogFiles();
102 for (LogFileOptions logFile : logFiles) {
103 if (logFile.isEnabled()) return true;
105 return false;
108 public void resetEditorFrom(PluginRunConfiguration prc) {
109 myModules.setSelectedItem(prc.getModule());
110 getVMParameters().setText(prc.VM_PARAMETERS);
111 getProgramParameters().setText(prc.PROGRAM_PARAMETERS);
115 public void applyEditorTo(PluginRunConfiguration prc) throws ConfigurationException {
116 prc.setModule(((Module)myModules.getSelectedItem()));
117 prc.VM_PARAMETERS = getVMParameters().getText();
118 prc.PROGRAM_PARAMETERS = getProgramParameters().getText();
121 @NotNull
122 public JComponent createEditor() {
123 myModulesModel = new DefaultComboBoxModel(myPRC.getModules());
124 myModules.setModel(myModulesModel);
125 myModules.setRenderer(new DefaultListCellRenderer() {
126 public Component getListCellRendererComponent(JList list, final Object value, int index, boolean isSelected, boolean cellHasFocus) {
127 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
128 if (value != null) {
129 setText(ApplicationManager.getApplication().runReadAction(new Computable<String >() {
130 public String compute() {
131 return ((Module)value).getName();
133 }));
134 setIcon(((Module)value).getModuleType().getNodeIcon(true));
136 return this;
139 JPanel wholePanel = new JPanel(new GridBagLayout());
140 myVMParameters.setText(DevKitBundle.message("vm.parameters"));
141 myVMParameters.setComponent(new RawCommandLineEditor());
142 myVMParameters.getComponent().setDialogCaption(myVMParameters.getRawText());
144 myProgramParameters.setText(DevKitBundle.message("program.parameters"));
145 myProgramParameters.setComponent(new RawCommandLineEditor());
146 myProgramParameters.getComponent().setDialogCaption(myProgramParameters.getRawText());
148 GridBagConstraints gc = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 0, 0);
149 wholePanel.add(myVMParameters, gc);
150 wholePanel.add(myProgramParameters, gc);
151 wholePanel.add(myShowLogs, gc);
152 wholePanel.add(myModuleLabel, gc);
153 gc.weighty = 1;
154 wholePanel.add(myModules, gc);
155 return wholePanel;
158 public RawCommandLineEditor getVMParameters() {
159 return myVMParameters.getComponent();
162 public RawCommandLineEditor getProgramParameters() {
163 return myProgramParameters.getComponent();
166 public void disposeEditor() {