project startup tasks, ability to share startup tasks list

This commit is contained in:
irengrig
2015-08-20 16:45:01 +02:00
parent 12311d85f2
commit da468b1f4e
6 changed files with 89 additions and 6 deletions
@@ -37,6 +37,7 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.ui.*;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBList;
import com.intellij.ui.popup.PopupFactoryImpl;
import com.intellij.ui.treeStructure.Tree;
@@ -63,6 +64,7 @@ public class ProjectStartupConfigurable implements SearchableConfigurable, Confi
private Tree myTree;
private ProjectStartupConfiguration myConfiguration;
private ToolbarDecorator myDecorator;
private JBCheckBox mySharedCheckBox;
public ProjectStartupConfigurable(Project project) {
myProject = project;
@@ -152,8 +154,13 @@ public class ProjectStartupConfigurable implements SearchableConfigurable, Confi
});
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
final JPanel tasksPanel = myDecorator.createPanel();
mySharedCheckBox = new JBCheckBox("Share");
mySharedCheckBox.setMnemonic('s');
final JPanel panel = new JPanel(new BorderLayout());
panel.add(mySharedCheckBox, BorderLayout.EAST);
return FormBuilder.createFormBuilder() // todo bundle
.addLabeledComponentFillVertically("Tasks to be executed right after opening the project.", tasksPanel)
.addLabeledComponent(new JLabel("Tasks to be executed right after opening the project."), panel)
.addComponentFillVertically(tasksPanel, 2)
.getPanel();
}
@@ -285,6 +292,7 @@ public class ProjectStartupConfigurable implements SearchableConfigurable, Confi
@Override
public boolean isModified() {
if (mySharedCheckBox.isSelected() != myConfiguration.isShared()) return true;
final List<RunnerAndConfigurationSettings> recorded = myConfiguration.getStartupConfigurations();
final List<RunnerAndConfigurationSettings> current = ((ProjectStartupTasksTreeModel)myTree.getModel()).getConfigurations();
return ! Comparing.equal(recorded, current);
@@ -292,13 +300,17 @@ public class ProjectStartupConfigurable implements SearchableConfigurable, Confi
@Override
public void apply() throws ConfigurationException {
myConfiguration.setStartupConfigurations(((ProjectStartupTasksTreeModel)myTree.getModel()).getConfigurations(), false);
myConfiguration.setStartupConfigurations(((ProjectStartupTasksTreeModel)myTree.getModel()).getConfigurations(), mySharedCheckBox.isSelected());
}
@Override
public void reset() {
final ProjectStartupTasksTreeModel model = new ProjectStartupTasksTreeModel(myConfiguration.getStartupConfigurations());
setModel(model);
mySharedCheckBox.setSelected(myConfiguration.isShared());
mySharedCheckBox.setEnabled(myConfiguration.isShared() || myConfiguration.canBeShared());
canBeSharedCheck(model);
selectPathOrFirst(null);
}
@@ -306,6 +318,24 @@ public class ProjectStartupConfigurable implements SearchableConfigurable, Confi
myTree.setModel(model);
myTree.setShowsRootHandles(false);
myTree.setRootVisible(false);
canBeSharedCheck(model);
}
private void canBeSharedCheck(ProjectStartupTasksTreeModel model) {
boolean canBeShared = true;
final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(myProject);
final List<RunnerAndConfigurationSettings> configurations = model.getConfigurations();
for (RunnerAndConfigurationSettings configuration : configurations) {
if (! runManager.isConfigurationShared(configuration)) {
canBeShared = false;
break;
}
}
mySharedCheckBox.setEnabled(canBeShared);
if (! canBeShared) {
mySharedCheckBox.setSelected(false);
}
}
@Override
@@ -131,10 +131,12 @@ public class ProjectStartupConfiguration {
});
if (shared) {
myLocal.clear();
myLocal.shared();
myShared.setList(names);
} else {
myShared.clear();
myLocal.setList(names);
myLocal.local();
}
}
@@ -153,10 +155,17 @@ public class ProjectStartupConfiguration {
}
public boolean isShared() {
return ! myShared.isEmpty();
return ! myShared.isEmpty() || myLocal.isShared();
}
public boolean isEmpty() {
return myShared.isEmpty() && myLocal.isEmpty();
}
public void checkOnChange(RunnerAndConfigurationSettings settings) {
if (! isShared()) return;
if (! myRunManager.isConfigurationShared(settings)) {
myLocal.local();
}
}
}
@@ -28,7 +28,7 @@ import java.util.List;
* @author Irina.Chernushina on 8/19/2015.
*/
public class ProjectStartupConfigurationBase implements PersistentStateComponent<Element> {
private final static String TOP_ELEMENT = "startup-tasks";
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";
@@ -18,6 +18,8 @@ package com.intellij.execution.startup;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.components.StoragePathMacros;
import org.jdom.Element;
import org.jetbrains.annotations.Nullable;
/**
* @author Irina.Chernushina on 8/19/2015.
@@ -29,4 +31,38 @@ import com.intellij.openapi.components.StoragePathMacros;
}
)
public class ProjectStartupLocalConfiguration extends ProjectStartupConfigurationBase {
private final static String SHARED = "shared";
private boolean myIsShared;
@Nullable
@Override
public Element getState() {
Element state = super.getState();
if (state == null) {
if (! myIsShared) return null;
state = new Element(TOP_ELEMENT);
}
state.setAttribute(SHARED, String.valueOf(myIsShared));
return state;
}
@Override
public void loadState(Element state) {
super.loadState(state);
if (state != null) {
myIsShared = "true".equals(state.getAttributeValue(SHARED));
}
}
public void local() {
myIsShared = false;
}
public void shared() {
myIsShared = true;
}
public boolean isShared() {
return myIsShared;
}
}
@@ -51,7 +51,15 @@ public class ProjectStartupRunner implements StartupActivity {
@Override
public void runConfigurationChanged(@NotNull RunnerAndConfigurationSettings settings, String existingId) {
projectStartupConfiguration.rename(existingId, settings);
if (existingId != null) {
projectStartupConfiguration.rename(existingId, settings);
}
projectStartupConfiguration.checkOnChange(settings);
}
@Override
public void runConfigurationAdded(@NotNull RunnerAndConfigurationSettings settings) {
projectStartupConfiguration.checkOnChange(settings);
}
});
final Alarm alarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, project);
@@ -27,7 +27,7 @@ import com.intellij.openapi.components.StorageScheme;
name = "ProjectStartupSharedConfiguration",
storages = {
@Storage(file = StoragePathMacros.PROJECT_FILE),
@Storage(file = StoragePathMacros.PROJECT_CONFIG_DIR + "/startup.xml", scheme = StorageScheme.DEFAULT)
@Storage(file = StoragePathMacros.PROJECT_CONFIG_DIR + "/startup.xml", scheme = StorageScheme.DIRECTORY_BASED)
}
)
public class ProjectStartupSharedConfiguration extends ProjectStartupConfigurationBase {