mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
project startup tasks, better serialization
This commit is contained in:
+10
-1
@@ -97,7 +97,7 @@ public class ProjectStartupConfigurable implements SearchableConfigurable, Confi
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
myProjectStartupTaskManager = ProjectStartupTaskManager.getInstance(myProject);
|
||||
initManager();
|
||||
|
||||
myModel = new ProjectStartupTasksTableModel(RunManagerEx.getInstanceEx(myProject));
|
||||
myTable = new JBTable(myModel);
|
||||
@@ -166,6 +166,12 @@ public class ProjectStartupConfigurable implements SearchableConfigurable, Confi
|
||||
.getPanel();
|
||||
}
|
||||
|
||||
private void initManager() {
|
||||
if (myProjectStartupTaskManager == null) {
|
||||
myProjectStartupTaskManager = ProjectStartupTaskManager.getInstance(myProject);
|
||||
}
|
||||
}
|
||||
|
||||
private void selectPathOrFirst(RunnerAndConfigurationSettings settings) {
|
||||
if (myTable.isEmpty()) return;
|
||||
|
||||
@@ -276,6 +282,7 @@ public class ProjectStartupConfigurable implements SearchableConfigurable, Confi
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
initManager();
|
||||
final Set<RunnerAndConfigurationSettings> shared = new HashSet<RunnerAndConfigurationSettings>(myProjectStartupTaskManager.getSharedConfigurations());
|
||||
final List<RunnerAndConfigurationSettings> list = new ArrayList<RunnerAndConfigurationSettings>(shared);
|
||||
list.addAll(myProjectStartupTaskManager.getLocalConfigurations());
|
||||
@@ -288,6 +295,7 @@ public class ProjectStartupConfigurable implements SearchableConfigurable, Confi
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
initManager();
|
||||
final List<RunnerAndConfigurationSettings> shared = new ArrayList<RunnerAndConfigurationSettings>();
|
||||
final List<RunnerAndConfigurationSettings> local = new ArrayList<RunnerAndConfigurationSettings>();
|
||||
|
||||
@@ -306,6 +314,7 @@ public class ProjectStartupConfigurable implements SearchableConfigurable, Confi
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
initManager();
|
||||
myModel.setData(myProjectStartupTaskManager.getSharedConfigurations(), myProjectStartupTaskManager.getLocalConfigurations());
|
||||
selectPathOrFirst(null);
|
||||
}
|
||||
|
||||
+28
-35
@@ -17,10 +17,13 @@ package com.intellij.execution.startup;
|
||||
|
||||
import com.intellij.execution.RunnerAndConfigurationSettings;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jdom.Element;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import com.intellij.util.xmlb.annotations.AbstractCollection;
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -29,12 +32,8 @@ import java.util.*;
|
||||
/**
|
||||
* @author Irina.Chernushina on 8/19/2015.
|
||||
*/
|
||||
public class ProjectStartupConfigurationBase implements PersistentStateComponent<Element> {
|
||||
protected final static String TOP_ELEMENT = "startup-tasks";
|
||||
private final static String TASK = "task";
|
||||
private final static String NAME = "name";
|
||||
private final static String ID = "id";
|
||||
|
||||
public class ProjectStartupConfigurationBase implements PersistentStateComponent<ProjectStartupConfigurationBase> {
|
||||
@Tag("configurations") @AbstractCollection(surroundWithTag = false)
|
||||
private final List<ConfigurationDescriptor> myList;
|
||||
|
||||
protected ProjectStartupConfigurationBase() {
|
||||
@@ -43,38 +42,20 @@ public class ProjectStartupConfigurationBase implements PersistentStateComponent
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Element getState() {
|
||||
if (myList.isEmpty()) return null;
|
||||
final Element element = new Element(TOP_ELEMENT);
|
||||
for (ConfigurationDescriptor descriptor : myList) {
|
||||
final Element child = new Element(TASK);
|
||||
child.setAttribute(NAME, descriptor.getName());
|
||||
child.setAttribute(ID, descriptor.getId());
|
||||
|
||||
element.addContent(child);
|
||||
}
|
||||
return element;
|
||||
public ProjectStartupConfigurationBase getState() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
myList.clear();
|
||||
final List<Element> children = state.getChildren();
|
||||
for (Element child : children) {
|
||||
if (TASK.equals(child.getName())) {
|
||||
final String name = child.getAttributeValue(NAME);
|
||||
final String id = child.getAttributeValue(ID);
|
||||
if (! StringUtil.isEmptyOrSpaces(name) && ! StringUtil.isEmptyOrSpaces(id)) {
|
||||
myList.add(new ConfigurationDescriptor(id, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
public void loadState(ProjectStartupConfigurationBase state) {
|
||||
XmlSerializerUtil.copyBean(state, this);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
myList.clear();
|
||||
}
|
||||
|
||||
@Transient
|
||||
public List<ConfigurationDescriptor> getList() {
|
||||
return myList;
|
||||
}
|
||||
@@ -128,25 +109,37 @@ public class ProjectStartupConfigurationBase implements PersistentStateComponent
|
||||
return false;
|
||||
}
|
||||
|
||||
@Tag("configuration")
|
||||
public static class ConfigurationDescriptor {
|
||||
private final @NotNull String myId;
|
||||
private final @NotNull String myName;
|
||||
private String myId;
|
||||
private String myName;
|
||||
|
||||
public ConfigurationDescriptor() {
|
||||
}
|
||||
|
||||
public ConfigurationDescriptor(@NotNull String id, @NotNull String name) {
|
||||
myId = id;
|
||||
myName = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Attribute("id")
|
||||
public String getId() {
|
||||
return myId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Attribute("name")
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
myId = id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
myName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
Reference in New Issue
Block a user