IDEADEV-38479 Show run configuration's icon in "Run"-window
[fedora-idea.git] / platform / lang-api / src / com / intellij / execution / configurations / UnknownRunConfiguration.java
blob47d3c250c28eb8cdeb8509b00a89138065b872b2
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.configurations;
19 import com.intellij.execution.ExecutionException;
20 import com.intellij.execution.Executor;
21 import com.intellij.execution.runners.ExecutionEnvironment;
22 import com.intellij.execution.runners.ProgramRunner;
23 import com.intellij.openapi.options.SettingsEditor;
24 import com.intellij.openapi.options.ConfigurationException;
25 import com.intellij.openapi.project.Project;
26 import com.intellij.openapi.util.InvalidDataException;
27 import com.intellij.openapi.util.JDOMExternalizable;
28 import com.intellij.openapi.util.WriteExternalException;
29 import org.jdom.Attribute;
30 import org.jdom.Element;
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.annotations.Nullable;
34 import javax.swing.*;
35 import java.util.List;
36 import java.util.concurrent.atomic.AtomicInteger;
38 /**
39 * @author spleaner
41 public class UnknownRunConfiguration implements RunConfiguration {
42 private ConfigurationFactory myFactory;
43 private Element myStoredElement;
44 private String myName;
45 private Project myProject;
47 private static final AtomicInteger myUniqueName = new AtomicInteger(1);
48 private boolean myDoNotStore;
50 public UnknownRunConfiguration(@NotNull final ConfigurationFactory factory, @NotNull final Project project) {
51 myFactory = factory;
52 myProject = project;
55 public void setDoNotStore(boolean b) {
56 myDoNotStore = b;
59 @Nullable
60 public Icon getIcon() {
61 return null;
64 public boolean isDoNotStore() {
65 return myDoNotStore;
68 public ConfigurationFactory getFactory() {
69 return myFactory;
72 public void setName(final String name) {
73 myName = name;
76 public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
77 return new UnknownSettingsEditor();
80 public Project getProject() {
81 return myProject;
84 @NotNull
85 public ConfigurationType getType() {
86 return UnknownConfigurationType.INSTANCE;
89 public JDOMExternalizable createRunnerSettings(final ConfigurationInfoProvider provider) {
90 return null;
93 public SettingsEditor<JDOMExternalizable> getRunnerSettingsEditor(final ProgramRunner runner) {
94 return null;
97 public RunConfiguration clone() {
98 try {
99 final UnknownRunConfiguration cloned = (UnknownRunConfiguration) super.clone();
100 return cloned;
101 } catch (CloneNotSupportedException e) {
102 return null;
107 public int getUniqueID() {
108 return System.identityHashCode(this);
111 public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
112 return null;
115 public String getName() {
116 if (myName == null) {
117 myName = String.format("Unknown%s", myUniqueName.getAndAdd(1));
120 return myName;
123 public void checkConfiguration() throws RuntimeConfigurationException {
124 throw new RuntimeConfigurationException("Broken configuration due to unavailable plugin or invalid configuration data.");
127 public void readExternal(final Element element) throws InvalidDataException {
128 myStoredElement = (Element) element.clone();
131 public void writeExternal(final Element element) throws WriteExternalException {
132 if (myStoredElement != null) {
133 final List attributeList = myStoredElement.getAttributes();
134 for (Object anAttributeList : attributeList) {
135 final Attribute a = (Attribute) anAttributeList;
136 element.setAttribute(a.getName(), a.getValue());
139 final List list = myStoredElement.getChildren();
140 for (Object child : list) {
141 final Element c = (Element) child;
142 element.addContent((Element) c.clone());
147 private static class UnknownSettingsEditor extends SettingsEditor<UnknownRunConfiguration> {
148 private JPanel myPanel;
150 private UnknownSettingsEditor() {
151 myPanel = new JPanel();
152 myPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 50, 0));
154 myPanel.add(new JLabel("This configuration can not be edited", JLabel.CENTER));
157 protected void resetEditorFrom(final UnknownRunConfiguration s) {
160 protected void applyEditorTo(final UnknownRunConfiguration s) throws ConfigurationException {
163 @NotNull
164 protected JComponent createEditor() {
165 return myPanel;
168 protected void disposeEditor() {