mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce XCollection annotation, get rid of custom getState for AppletConfiguration
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package com.intellij.execution.applet;
|
||||
|
||||
import com.intellij.application.options.ModulesComboBox;
|
||||
@@ -17,6 +19,8 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.table.TableView;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.ListTableModel;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -29,7 +33,6 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class AppletConfigurable extends SettingsEditor<AppletConfiguration> implements CheckableRunConfigurationEditor<AppletConfiguration>,
|
||||
@@ -60,25 +63,25 @@ public class AppletConfigurable extends SettingsEditor<AppletConfiguration> impl
|
||||
|
||||
private static final ColumnInfo[] PARAMETER_COLUMNS = new ColumnInfo[]{
|
||||
new MyColumnInfo(ExecutionBundle.message("applet.configuration.parameter.name.column")) {
|
||||
public String valueOf(final AppletConfiguration.AppletParameter appletParameter) {
|
||||
public String valueOf(final AppletParameter appletParameter) {
|
||||
return appletParameter.getName();
|
||||
}
|
||||
|
||||
public void setValue(final AppletConfiguration.AppletParameter appletParameter, final String name) {
|
||||
public void setValue(final AppletParameter appletParameter, final String name) {
|
||||
appletParameter.setName(name);
|
||||
}
|
||||
},
|
||||
new MyColumnInfo(ExecutionBundle.message("applet.configuration.parameter.value.column")) {
|
||||
public String valueOf(final AppletConfiguration.AppletParameter appletParameter) {
|
||||
public String valueOf(final AppletParameter appletParameter) {
|
||||
return appletParameter.getValue();
|
||||
}
|
||||
|
||||
public void setValue(final AppletConfiguration.AppletParameter appletParameter, final String value) {
|
||||
public void setValue(final AppletParameter appletParameter, final String value) {
|
||||
appletParameter.setValue(value);
|
||||
}
|
||||
}
|
||||
};
|
||||
private final ListTableModel<AppletConfiguration.AppletParameter> myParameters;
|
||||
private final ListTableModel<AppletParameter> myParameters;
|
||||
private final TableView myTable;
|
||||
@NonNls
|
||||
protected static final String HTTP_PREFIX = "http:/";
|
||||
@@ -153,9 +156,9 @@ public class AppletConfigurable extends SettingsEditor<AppletConfiguration> impl
|
||||
}
|
||||
|
||||
private void addParameter() {
|
||||
final ArrayList<AppletConfiguration.AppletParameter> newItems =
|
||||
final ArrayList<AppletParameter> newItems =
|
||||
new ArrayList<>(myParameters.getItems());
|
||||
final AppletConfiguration.AppletParameter parameter = new AppletConfiguration.AppletParameter("newParameter", "");
|
||||
final AppletParameter parameter = new AppletParameter("newParameter", "");
|
||||
newItems.add(parameter);
|
||||
myParameters.setItems(newItems);
|
||||
|
||||
@@ -172,10 +175,10 @@ public class AppletConfigurable extends SettingsEditor<AppletConfiguration> impl
|
||||
return myPolicyFile.getComponent();
|
||||
}
|
||||
|
||||
private static List<AppletConfiguration.AppletParameter> cloneParameters(final List<AppletConfiguration.AppletParameter> items) {
|
||||
final List<AppletConfiguration.AppletParameter> params = new ArrayList<>();
|
||||
for (AppletConfiguration.AppletParameter appletParameter : items) {
|
||||
params.add(new AppletConfiguration.AppletParameter(appletParameter.getName(), appletParameter.getValue()));
|
||||
private static List<AppletParameter> cloneParameters(@NotNull List<AppletParameter> items) {
|
||||
List<AppletParameter> params = new SmartList<>();
|
||||
for (AppletParameter appletParameter : items) {
|
||||
params.add(new AppletParameter(appletParameter.getName(), appletParameter.getValue()));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
@@ -192,11 +195,6 @@ public class AppletConfigurable extends SettingsEditor<AppletConfiguration> impl
|
||||
return myHtmlFile;
|
||||
}
|
||||
|
||||
private static String toNull(String s) {
|
||||
s = s.trim();
|
||||
return s.length() == 0 ? null : s;
|
||||
}
|
||||
|
||||
private static String toSystemFormat(String s) {
|
||||
s = s.trim();
|
||||
return s.length() == 0 ? null : s.replace(File.separatorChar, '/');
|
||||
@@ -205,8 +203,7 @@ public class AppletConfigurable extends SettingsEditor<AppletConfiguration> impl
|
||||
public void applyEditorTo(@NotNull final AppletConfiguration configuration) {
|
||||
checkEditorData(configuration);
|
||||
myTable.stopEditing();
|
||||
final List<AppletConfiguration.AppletParameter> params = cloneParameters(myParameters.getItems());
|
||||
configuration.setAppletParameters(params);
|
||||
configuration.getOptions().setAppletParameters(ContainerUtil.nullize(cloneParameters(myParameters.getItems())));
|
||||
}
|
||||
|
||||
public void resetEditorFrom(@NotNull AppletConfiguration runConfiguration) {
|
||||
@@ -225,13 +222,9 @@ public class AppletConfigurable extends SettingsEditor<AppletConfiguration> impl
|
||||
(configuration.getHtmlUsed() ? myURL : myMainClass).setSelected(true);
|
||||
changePanel();
|
||||
|
||||
final AppletConfiguration.AppletParameter[] appletParameters = runConfiguration.getAppletParameters();
|
||||
if (appletParameters != null) {
|
||||
myParameters.setItems(cloneParameters(Arrays.asList(appletParameters)));
|
||||
}
|
||||
myParameters.setItems(cloneParameters(ContainerUtil.notNullize(configuration.getAppletParameters())));
|
||||
myModuleSelector.reset(runConfiguration);
|
||||
myJrePathEditor
|
||||
.setPathOrName(configuration.getAlternativeJrePath(), configuration.getAlternativeJrePathEnabled());
|
||||
myJrePathEditor.setPathOrName(configuration.getAlternativeJrePath(), configuration.getAlternativeJrePathEnabled());
|
||||
}
|
||||
|
||||
private RawCommandLineEditor getVMParametersComponent() {
|
||||
@@ -289,18 +282,18 @@ public class AppletConfigurable extends SettingsEditor<AppletConfiguration> impl
|
||||
myHtmlFileLabel.setAnchor(anchor);
|
||||
}
|
||||
|
||||
private static abstract class MyColumnInfo extends ColumnInfo<AppletConfiguration.AppletParameter, String> {
|
||||
private static abstract class MyColumnInfo extends ColumnInfo<AppletParameter, String> {
|
||||
public MyColumnInfo(final String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public TableCellEditor getEditor(final AppletConfiguration.AppletParameter item) {
|
||||
public TableCellEditor getEditor(final AppletParameter item) {
|
||||
final JTextField textField = new JTextField();
|
||||
textField.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
return new DefaultCellEditor(textField);
|
||||
}
|
||||
|
||||
public boolean isCellEditable(final AppletConfiguration.AppletParameter appletParameter) {
|
||||
public boolean isCellEditable(final AppletParameter appletParameter) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,12 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JdkUtil;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -34,22 +33,15 @@ import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigurationModule> implements SingleClassConfiguration, RefactoringListenerProvider,
|
||||
PersistentStateComponent<Element> {
|
||||
private static final String NAME_ATTR = "name";
|
||||
private static final String VALUE_ATTR = "value";
|
||||
private static final String PARAMETER_ELEMENT_NAME = "parameter";
|
||||
|
||||
private AppletParameter[] myAppletParameters;
|
||||
|
||||
public AppletConfiguration(@NotNull Project project, @NotNull ConfigurationFactory factory) {
|
||||
super(new JavaRunConfigurationModule(project, false), factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AppletConfigurationOptions getOptions() {
|
||||
public AppletConfigurationOptions getOptions() {
|
||||
return (AppletConfigurationOptions)super.getOptions();
|
||||
}
|
||||
|
||||
@@ -129,42 +121,6 @@ public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
|
||||
getOptions().setPolicyFile(ExternalizablePath.urlValue(localPath));
|
||||
}
|
||||
|
||||
public static class AppletParameter {
|
||||
public String myName;
|
||||
public String myValue;
|
||||
|
||||
public AppletParameter(@NonNls final String name, final String value) {
|
||||
myName = name;
|
||||
myValue = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
myName = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
public void setValue(final String value) {
|
||||
myValue = value;
|
||||
}
|
||||
|
||||
public boolean equals(final Object obj) {
|
||||
if (!(obj instanceof AppletParameter)) return false;
|
||||
final AppletParameter second = (AppletParameter)obj;
|
||||
return Comparing.equal(myName, second.myName) && Comparing.equal(myValue, second.myValue);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Comparing.hashcode(myName, myValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Module> getValidModules() {
|
||||
return JavaRunConfigurationModule.getModulesForClass(getProject(), getOptions().getMainClassName());
|
||||
@@ -174,35 +130,9 @@ public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
|
||||
public Element getState() {
|
||||
Element element = new Element("state");
|
||||
super.writeExternal(element);
|
||||
|
||||
if (myAppletParameters != null) {
|
||||
for (AppletParameter myAppletParameter : myAppletParameters) {
|
||||
Element parameterElement = new Element(PARAMETER_ELEMENT_NAME);
|
||||
element.addContent(parameterElement);
|
||||
parameterElement.setAttribute(NAME_ATTR, myAppletParameter.getName());
|
||||
parameterElement.setAttribute(VALUE_ATTR, myAppletParameter.getValue());
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element element) {
|
||||
super.readExternal(element);
|
||||
|
||||
List<Element> paramList = element.getChildren(PARAMETER_ELEMENT_NAME);
|
||||
if (paramList.isEmpty()) {
|
||||
myAppletParameters = null;
|
||||
}
|
||||
else {
|
||||
List<AppletParameter> parameters = new SmartList<>();
|
||||
for (Element child : paramList) {
|
||||
parameters.add(new AppletParameter(child.getAttributeValue(NAME_ATTR), child.getAttributeValue(VALUE_ATTR)));
|
||||
}
|
||||
myAppletParameters = parameters.toArray(new AppletParameter[parameters.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringElementListener getRefactoringElementListener(final PsiElement element) {
|
||||
if (getOptions().getHtmlUsed()) {
|
||||
@@ -256,19 +186,6 @@ public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
|
||||
throw new RuntimeConfigurationWarning("URL " + getOptions().getHtmlFileName() + " is not valid: " + ex.getLocalizedMessage());
|
||||
}
|
||||
|
||||
@Transient
|
||||
public AppletParameter[] getAppletParameters() {
|
||||
return myAppletParameters;
|
||||
}
|
||||
|
||||
public void setAppletParameters(AppletParameter[] appletParameters) {
|
||||
myAppletParameters = appletParameters;
|
||||
}
|
||||
|
||||
public void setAppletParameters(final List<AppletParameter> parameters) {
|
||||
setAppletParameters(parameters.toArray(new AppletParameter[parameters.size()]));
|
||||
}
|
||||
|
||||
private AppletHtmlFile getHtmlURL() throws CantRunException {
|
||||
if (getOptions().getHtmlUsed()) {
|
||||
if (getOptions().getHtmlFileName() == null) {
|
||||
@@ -306,11 +223,8 @@ public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
|
||||
"width=" + getOptions().getWidth() + "\n" +
|
||||
"height=" + getOptions().getHeight() + "\n" +
|
||||
"align=top>\n");
|
||||
final AppletParameter[] appletParameters = getAppletParameters();
|
||||
if (appletParameters != null) {
|
||||
for (final AppletParameter parameter : appletParameters) {
|
||||
writer.write("<param name=\"" + parameter.getName() + "\" value=\"" + parameter.getValue() + "\">\n");
|
||||
}
|
||||
for (AppletParameter parameter : ContainerUtil.notNullize(getOptions().getAppletParameters())) {
|
||||
writer.write("<param name=\"" + parameter.getName() + "\" value=\"" + parameter.getValue() + "\">\n");
|
||||
}
|
||||
writer.write("</applet>\n</body>\n</html>\n");
|
||||
}
|
||||
|
||||
+34
-11
@@ -3,20 +3,43 @@
|
||||
*/
|
||||
package com.intellij.execution.applet
|
||||
|
||||
import com.intellij.execution.ExternalizablePath
|
||||
import com.intellij.execution.configurations.ModuleBasedConfigurationOptions
|
||||
import com.intellij.util.xmlb.annotations.OptionTag
|
||||
import com.intellij.openapi.application.PathManager
|
||||
import com.intellij.util.xmlb.annotations.*
|
||||
|
||||
class AppletConfigurationOptions : ModuleBasedConfigurationOptions() {
|
||||
@get:OptionTag("MAIN_CLASS_NAME") var mainClassName by string()
|
||||
@get:OptionTag("HTML_FILE_NAME") var htmlFileName by string()
|
||||
@get:OptionTag("HTML_USED") var htmlUsed by storedProperty(false)
|
||||
@get:OptionTag("MAIN_CLASS_NAME")
|
||||
var mainClassName by string()
|
||||
|
||||
@get:OptionTag("WIDTH") var width by storedProperty(400)
|
||||
@get:OptionTag("HEIGHT") var height by storedProperty(300)
|
||||
@get:OptionTag("HTML_FILE_NAME")
|
||||
var htmlFileName by string()
|
||||
|
||||
@get:OptionTag("POLICY_FILE") var policyFile by string()
|
||||
@get:OptionTag("VM_PARAMETERS") var vmParameters by string()
|
||||
@get:OptionTag("HTML_USED")
|
||||
var htmlUsed by storedProperty(false)
|
||||
|
||||
@get:OptionTag("ALTERNATIVE_JRE_PATH_ENABLED") var alternativeJrePathEnabled by storedProperty(false)
|
||||
@get:OptionTag("ALTERNATIVE_JRE_PATH") var alternativeJrePath by string()
|
||||
}
|
||||
@get:OptionTag("WIDTH")
|
||||
var width by storedProperty(400)
|
||||
|
||||
@get:OptionTag("HEIGHT")
|
||||
var height by storedProperty(300)
|
||||
|
||||
@get:OptionTag("POLICY_FILE")
|
||||
var policyFile by string(ExternalizablePath.urlValue("${PathManager.getHomePath()}/bin/appletviewer.policy"))
|
||||
|
||||
@get:OptionTag("VM_PARAMETERS")
|
||||
var vmParameters by string()
|
||||
|
||||
@get:OptionTag("ALTERNATIVE_JRE_PATH_ENABLED")
|
||||
var alternativeJrePathEnabled by storedProperty(false)
|
||||
|
||||
@get:OptionTag("ALTERNATIVE_JRE_PATH")
|
||||
var alternativeJrePath by string()
|
||||
|
||||
@get:Property(surroundWithTag = false)
|
||||
@get:XCollection()
|
||||
var appletParameters by storedProperty<List<AppletParameter>?>()
|
||||
}
|
||||
|
||||
@Tag("parameter")
|
||||
data class AppletParameter(@get:Attribute("name") var name: String? = null, @get:Attribute("value") var value: String? = null)
|
||||
Reference in New Issue
Block a user