fixed duplicated entries for project structure dialog in workspace.xml

This commit is contained in:
nik
2010-09-24 14:52:30 +04:00
parent 3103e6633d
commit 8cc0438d30
14 changed files with 211 additions and 180 deletions
@@ -78,6 +78,7 @@ public class ArtifactEditorSettings implements PersistentStateComponent<Artifact
myTypesToShowContent.addAll(typesToShowContent);
}
@Tag("artifact-editor")
public static class ArtifactEditorSettingsState {
@Tag("show-sorted")
public boolean mySortElements = true;
@@ -0,0 +1,35 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.roots.ui.configuration.artifacts;
import com.intellij.openapi.ui.MasterDetailsState;
import com.intellij.util.xmlb.annotations.Property;
/**
* @author nik
*/
public class ArtifactStructureConfigurableState extends MasterDetailsState {
private ArtifactEditorSettings.ArtifactEditorSettingsState myDefaultArtifactSettings = new ArtifactEditorSettings.ArtifactEditorSettingsState();
@Property(surroundWithTag = false)
public ArtifactEditorSettings.ArtifactEditorSettingsState getDefaultArtifactSettings() {
return myDefaultArtifactSettings;
}
public void setDefaultArtifactSettings(ArtifactEditorSettings.ArtifactEditorSettingsState defaultArtifactSettings) {
myDefaultArtifactSettings = defaultArtifactSettings;
}
}
@@ -20,9 +20,6 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.DumbAwareAction;
@@ -36,6 +33,7 @@ import com.intellij.openapi.roots.ui.configuration.ModuleEditor;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorListener;
import com.intellij.openapi.roots.ui.configuration.projectRoot.*;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
import com.intellij.openapi.ui.MasterDetailsState;
import com.intellij.openapi.ui.MasterDetailsStateService;
import com.intellij.packaging.artifacts.*;
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
@@ -55,16 +53,12 @@ import java.util.List;
/**
* @author nik
*/
@State(
name = "ArtifactsStructureConfigurable.UI",
storages = {@Storage(id = "other", file = "$WORKSPACE_FILE$")}
)
public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
private ArtifactsStructureConfigurableContextImpl myPackagingEditorContext;
private final ArtifactEditorSettings myDefaultSettings = new ArtifactEditorSettings();
public ArtifactsStructureConfigurable(@NotNull Project project) {
super(project);
super(project, new ArtifactStructureConfigurableState());
MasterDetailsStateService.getInstance(project).register("ArtifactsStructureConfigurable.UI", this);
}
@@ -163,6 +157,18 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
}
}
@Override
public MasterDetailsState getState() {
((ArtifactStructureConfigurableState)myState).setDefaultArtifactSettings(myDefaultSettings.getState());
return super.getState();
}
@Override
public void loadState(MasterDetailsState object) {
super.loadState(object);
myDefaultSettings.loadState(((ArtifactStructureConfigurableState)myState).getDefaultArtifactSettings());
}
@Nls
public String getDisplayName() {
return ProjectBundle.message("display.name.artifacts");
@@ -192,11 +198,6 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
return node;
}
@Override
protected PersistentStateComponent<?> getAdditionalSettings() {
return myDefaultSettings;
}
@Override
public void reset() {
myPackagingEditorContext.resetModifiableModel();
@@ -31,6 +31,7 @@ import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.*;
import com.intellij.openapi.ui.MasterDetailsComponent;
import com.intellij.openapi.ui.MasterDetailsState;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.Condition;
@@ -66,6 +67,11 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i
protected boolean myAutoScrollEnabled = true;
protected BaseStructureConfigurable(Project project, MasterDetailsState state) {
super(state);
myProject = project;
}
protected BaseStructureConfigurable(final Project project) {
myProject = project;
}
@@ -27,8 +27,6 @@ import com.intellij.facet.ui.MultipleFacetSettingsEditor;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.options.ConfigurationException;
@@ -37,6 +35,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
import com.intellij.openapi.ui.DetailsComponent;
import com.intellij.openapi.ui.MasterDetailsStateService;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.openapi.util.IconLoader;
import org.jetbrains.annotations.NotNull;
@@ -50,15 +49,6 @@ import java.util.List;
/**
* @author nik
*/
@State(
name = "FacetStructureConfigurable.UI",
storages = {
@Storage(
id = "other",
file = "$WORKSPACE_FILE$"
)
}
)
public class FacetStructureConfigurable extends BaseStructureConfigurable {
private static final Icon ICON = IconLoader.getIcon("/modules/modules.png");//todo[nik] use facets icon
private final ModuleManager myModuleManager;
@@ -67,6 +57,7 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable {
public FacetStructureConfigurable(final Project project, ModuleManager moduleManager) {
super(project);
MasterDetailsStateService.getInstance(project).register("FacetStructureConfigurable.UI", this);
myModuleManager = moduleManager;
}
@@ -16,29 +16,21 @@
package com.intellij.openapi.roots.ui.configuration.projectRoot;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.ui.MasterDetailsStateService;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@State(
name = "GlobalLibrariesConfigurable.UI",
storages = {
@Storage(
id ="other",
file = "$WORKSPACE_FILE$"
)}
)
public class GlobalLibrariesConfigurable extends BaseLibrariesConfigurable {
public GlobalLibrariesConfigurable(final Project project) {
super(project);
MasterDetailsStateService.getInstance(project).register("GlobalLibrariesConfigurable.UI", this);
myLevel = LibraryTablesRegistrar.APPLICATION_LEVEL;
}
@@ -19,8 +19,6 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
@@ -32,6 +30,7 @@ import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.SdkProjectStructureElement;
import com.intellij.openapi.ui.MasterDetailsComponent;
import com.intellij.openapi.ui.MasterDetailsStateService;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.util.Consumer;
import org.jetbrains.annotations.Nls;
@@ -46,20 +45,9 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@State(
name = "JdkListConfigurable.UI",
storages = {
@Storage(
id ="other",
file = "$WORKSPACE_FILE$"
)}
)
public class JdkListConfigurable extends BaseStructureConfigurable {
private final ProjectSdksModel myJdksTreeModel;
SdkModel.Listener myListener = new SdkModel.Listener() {
private final SdkModel.Listener myListener = new SdkModel.Listener() {
public void sdkAdded(Sdk sdk) {
}
@@ -87,6 +75,7 @@ public class JdkListConfigurable extends BaseStructureConfigurable {
public JdkListConfigurable(final Project project, ProjectStructureConfigurable root) {
super(project);
MasterDetailsStateService.getInstance(project).register("JdkListConfigurable.UI", this);
myJdksTreeModel = root.getProjectJdksModel();
myJdksTreeModel.addListener(myListener);
}
@@ -30,8 +30,6 @@ import com.intellij.ide.util.projectWizard.ProjectWizardUtil;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.module.*;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.DumbAware;
@@ -52,6 +50,7 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProj
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureDaemonAnalyzer;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.MasterDetailsStateService;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.openapi.util.Comparing;
@@ -83,14 +82,6 @@ import java.util.List;
* User: anna
* Date: 02-Jun-2006
*/
@State(
name = "ModuleStructureConfigurable.UI",
storages = {
@Storage(
id ="other",
file = "$WORKSPACE_FILE$"
)}
)
public class ModuleStructureConfigurable extends BaseStructureConfigurable implements Place.Navigator {
private static final Icon COMPACT_EMPTY_MIDDLE_PACKAGES_ICON = IconLoader.getIcon("/objectBrowser/compactEmptyPackages.png");
@@ -105,6 +96,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
public ModuleStructureConfigurable(Project project, ModuleManager manager) {
super(project);
MasterDetailsStateService.getInstance(project).register("ModuleStructureConfigurable.UI", this);
myModuleManager = manager;
}
@@ -16,30 +16,20 @@
package com.intellij.openapi.roots.ui.configuration.projectRoot;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
import com.intellij.openapi.ui.MasterDetailsStateService;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@State(
name = "ProjectLibrariesConfigurable.UI",
storages = {
@Storage(
id ="other",
file = "$WORKSPACE_FILE$"
)}
)
public class ProjectLibrariesConfigurable extends BaseLibrariesConfigurable {
public ProjectLibrariesConfigurable(final Project project) {
super(project);
MasterDetailsStateService.getInstance(project).register("ProjectLibrariesConfigurable.UI", this);
myLevel = LibraryTablesRegistrar.PROJECT_LEVEL;
}
@@ -20,7 +20,6 @@ import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.execution.ExecutionBundle;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.NonDefaultProjectConfigurable;
@@ -39,13 +38,11 @@ import com.intellij.util.Icons;
import com.intellij.util.containers.Convertor;
import com.intellij.util.containers.HashSet;
import com.intellij.util.ui.tree.TreeUtil;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Tag;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
@@ -64,7 +61,6 @@ import java.util.*;
public class ScopeChooserConfigurable extends MasterDetailsComponent implements NonDefaultProjectConfigurable, SearchableConfigurable {
private static final Icon SCOPES = IconLoader.getIcon("/ide/scopeConfigurable.png");
private static final Icon SAVE_ICON = IconLoader.getIcon("/runConfigurations/saveTempConfig.png");
private ScopeChooserConfigurableState myScopesState = new ScopeChooserConfigurableState();
private final NamedScopesHolder myLocalScopesManager;
private final NamedScopesHolder mySharedScopesManager;
@@ -80,6 +76,7 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements
}
public ScopeChooserConfigurable(final Project project) {
super(new ScopeChooserConfigurableState());
myLocalScopesManager = NamedScopeManager.getInstance(project);
mySharedScopesManager = DependencyValidationManager.getInstance(project);
myProject = project;
@@ -145,24 +142,19 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements
}
}
@Override
protected PersistentStateComponent<?> getAdditionalSettings() {
return myScopesState;
}
@TestOnly
public void loadScopesState(ScopeChooserConfigurableState scopesState) {
myScopesState = scopesState;
public ScopeChooserConfigurableState getScopesState() {
return (ScopeChooserConfigurableState)myState;
}
public boolean isModified() {
if (myRoot.getChildCount() != myScopesState.myOrder.size()) return true;
final List<String> order = getScopesState().myOrder;
if (myRoot.getChildCount() != order.size()) return true;
for (int i = 0; i < myRoot.getChildCount(); i++) {
final MyNode node = (MyNode)myRoot.getChildAt(i);
final ScopeConfigurable scopeConfigurable = (ScopeConfigurable)node.getConfigurable();
final NamedScope namedScope = scopeConfigurable.getEditableObject();
if (myScopesState.myOrder.size() <= i) return true;
final String name = myScopesState.myOrder.get(i);
if (order.size() <= i) return true;
final String name = order.get(i);
if (!Comparing.strEqual(name, namedScope.getName())) return true;
if (isInitialized(scopeConfigurable)) {
final NamedScopesHolder holder = scopeConfigurable.getHolder();
@@ -202,19 +194,21 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements
}
final List<String> order = getScopesState().myOrder;
TreeUtil.sort(myRoot, new Comparator<DefaultMutableTreeNode>() {
public int compare(final DefaultMutableTreeNode o1, final DefaultMutableTreeNode o2) {
final int idx1 = myScopesState.myOrder.indexOf(((MyNode)o1).getDisplayName());
final int idx2 = myScopesState.myOrder.indexOf(((MyNode)o2).getDisplayName());
final int idx1 = order.indexOf(((MyNode)o1).getDisplayName());
final int idx2 = order.indexOf(((MyNode)o2).getDisplayName());
return idx1 - idx2;
}
});
}
private void loadStateOrder() {
myScopesState.myOrder.clear();
final List<String> order = getScopesState().myOrder;
order.clear();
for (int i = 0; i < myRoot.getChildCount(); i++) {
myScopesState.myOrder.add(((MyNode)myRoot.getChildAt(i)).getDisplayName());
order.add(((MyNode)myRoot.getChildAt(i)).getDisplayName());
}
}
@@ -527,17 +521,9 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements
}
}
public static class ScopeChooserConfigurableState implements PersistentStateComponent<ScopeChooserConfigurableState> {
public static class ScopeChooserConfigurableState extends MasterDetailsState {
@Tag("order")
@AbstractCollection(surroundWithTag = false, elementTag = "scope", elementValueAttribute = "name")
public List<String> myOrder = new ArrayList<String>();
public ScopeChooserConfigurableState getState() {
return this;
}
public void loadState(ScopeChooserConfigurableState state) {
XmlSerializerUtil.copyBean(state, this);
}
}
}
@@ -26,6 +26,7 @@ import com.intellij.openapi.util.DimensionService;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.util.text.StringTokenizer;
import com.intellij.util.xmlb.annotations.Tag;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
@@ -33,6 +34,7 @@ import java.awt.*;
import java.util.ArrayList;
import java.util.List;
@Tag("splitter-proportions")
public class SplitterProportionsDataImpl implements SplitterProportionsData {
private List<Float> proportions = new ArrayList<Float>();
private static final String DATA_VERSION = "1";
@@ -17,9 +17,7 @@
package com.intellij.openapi.ui;
import com.intellij.CommonBundle;
import com.intellij.ide.ui.SplitterProportionsDataImpl;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
@@ -38,14 +36,10 @@ import com.intellij.ui.navigation.History;
import com.intellij.ui.navigation.Place;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.Icons;
import com.intellij.util.ReflectionUtil;
import com.intellij.util.containers.HashSet;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.tree.TreeUtil;
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
import com.intellij.util.xmlb.XmlSerializer;
import com.intellij.util.xmlb.annotations.Tag;
import org.jdom.Element;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -64,8 +58,7 @@ import java.util.List;
* User: anna
* Date: 29-May-2006
*/
public abstract class MasterDetailsComponent implements Configurable, PersistentStateComponent<MasterDetailsComponent.UIState>, DetailsComponent.Facade,
MasterDetails {
public abstract class MasterDetailsComponent implements Configurable, DetailsComponent.Facade, MasterDetails {
protected static final Logger LOG = Logger.getInstance("#com.intellij.openapi.ui.MasterDetailsComponent");
protected static final Icon COPY_ICON = IconLoader.getIcon("/actions/copy.png");
protected NamedConfigurable myCurrentConfigurable;
@@ -93,16 +86,7 @@ public abstract class MasterDetailsComponent implements Configurable, Persistent
myHistory = history;
}
public static class UIState {
@Tag("splitter-proportions")
public SplitterProportionsDataImpl proportions = new SplitterProportionsDataImpl();
@Tag("last-edited")
public String lastEditedConfigurable;
@Tag("settings")
public Element mySettingsElement;
}
protected UIState myState = new UIState();
protected final MasterDetailsState myState;
protected Runnable TREE_UPDATER;
@@ -111,7 +95,7 @@ public abstract class MasterDetailsComponent implements Configurable, Persistent
public void run() {
MyNode node = (MyNode)myTree.getSelectionPath().getLastPathComponent();
if (node != null) {
myState.lastEditedConfigurable = getNodePathString(node); //survive after rename;
myState.setLastEditedConfigurable(getNodePathString(node)); //survive after rename;
myDetails.setText(node.getConfigurable().getBannerSlogan());
((DefaultTreeModel)myTree.getModel()).reload(node);
fireItemsChangedExternally();
@@ -137,8 +121,12 @@ public abstract class MasterDetailsComponent implements Configurable, Persistent
private boolean myToReinitWholePanel = true;
protected MasterDetailsComponent() {
installAutoScroll();
this(new MasterDetailsState());
}
protected MasterDetailsComponent(MasterDetailsState state) {
myState = state;
installAutoScroll();
reinintWholePanelIfNeeded();
}
@@ -338,7 +326,7 @@ public abstract class MasterDetailsComponent implements Configurable, Persistent
myHasDeletedItems = false;
((DefaultTreeModel)myTree.getModel()).reload();
//myTree.requestFocus();
myState.proportions.restoreSplitterProportions(myWholePanel);
myState.getProportions().restoreSplitterProportions(myWholePanel);
final Enumeration enumeration = myRoot.breadthFirstEnumeration();
boolean selected = false;
@@ -346,7 +334,7 @@ public abstract class MasterDetailsComponent implements Configurable, Persistent
final MyNode node = (MyNode)enumeration.nextElement();
if (node instanceof MyRootNode) continue;
final String path = getNodePathString(node);
if (!selected && Comparing.strEqual(path, myState.lastEditedConfigurable)) {
if (!selected && Comparing.strEqual(path, myState.getLastEditedConfigurable())) {
TreeUtil.selectInTree(node, false, myTree);
selected = true;
}
@@ -377,39 +365,16 @@ public abstract class MasterDetailsComponent implements Configurable, Persistent
return path.toString();
}
@Nullable
protected PersistentStateComponent<?> getAdditionalSettings() {
return null;
}
public UIState getState() {
myState.mySettingsElement = null;
PersistentStateComponent<?> additionalSettings = getAdditionalSettings();
if (additionalSettings != null) {
final Object state = additionalSettings.getState();
if (state != null) {
myState.mySettingsElement = XmlSerializer.serialize(state, new SkipDefaultValuesSerializationFilters());
}
}
public MasterDetailsState getState() {
return myState;
}
public void loadState(final UIState object) {
myState.lastEditedConfigurable = object.lastEditedConfigurable;
myState.proportions = object.proportions;
final PersistentStateComponent<?> additionalSettings = getAdditionalSettings();
if (additionalSettings != null) {
final Element settingsElement = object.mySettingsElement;
if (settingsElement != null) {
final Class<?> stateType = ReflectionUtil.getRawType(ReflectionUtil.resolveVariableInHierarchy(PersistentStateComponent.class.getTypeParameters()[0], additionalSettings.getClass()));
//noinspection unchecked
((PersistentStateComponent)additionalSettings).loadState(XmlSerializer.deserialize(settingsElement, stateType));
}
}
public void loadState(final MasterDetailsState object) {
XmlSerializerUtil.copyBean(object, myState);
}
public void disposeUIResources() {
myState.proportions.saveSplitterProportions(myWholePanel);
myState.getProportions().saveSplitterProportions(myWholePanel);
myAutoScrollHandler.cancelAllRequests();
myDetails.disposeUIResources();
myInitializedConfigurables.clear();
@@ -622,7 +587,7 @@ public abstract class MasterDetailsComponent implements Configurable, Persistent
protected void setSelectedNode(@Nullable MyNode node) {
if (node != null) {
myState.lastEditedConfigurable = getNodePathString(node);
myState.setLastEditedConfigurable(getNodePathString(node));
}
updateSelection(node != null ? node.getConfigurable() : null);
}
@@ -839,7 +804,7 @@ public abstract class MasterDetailsComponent implements Configurable, Persistent
void itemsExternallyChanged();
}
public static interface ActionGroupWithPreselection {
public interface ActionGroupWithPreselection {
ActionGroup getActionGroup();
int getDefaultIndex();
@@ -0,0 +1,46 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.ui;
import com.intellij.ide.ui.SplitterProportionsDataImpl;
import com.intellij.util.xmlb.annotations.Property;
import com.intellij.util.xmlb.annotations.Tag;
/**
* @author nik
*/
public class MasterDetailsState {
private SplitterProportionsDataImpl proportions = new SplitterProportionsDataImpl();
private String lastEditedConfigurable;
@Property(surroundWithTag = false)
public SplitterProportionsDataImpl getProportions() {
return proportions;
}
public void setProportions(SplitterProportionsDataImpl proportions) {
this.proportions = proportions;
}
@Tag("last-edited")
public String getLastEditedConfigurable() {
return lastEditedConfigurable;
}
public void setLastEditedConfigurable(String lastEditedConfigurable) {
this.lastEditedConfigurable = lastEditedConfigurable;
}
}
@@ -25,13 +25,16 @@ import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.util.xmlb.annotations.MapAnnotation;
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
import com.intellij.util.xmlb.XmlSerializer;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Tag;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
@State(
name="masterDetails",
@@ -41,49 +44,81 @@ import java.util.Map;
file = "$WORKSPACE_FILE$"
)}
)
public class MasterDetailsStateService implements PersistentStateComponent<MasterDetailsStateService.State>{
public class MasterDetailsStateService implements PersistentStateComponent<MasterDetailsStateService.States>{
private final SkipDefaultValuesSerializationFilters mySerializationFilter = new SkipDefaultValuesSerializationFilters();
private final Map<String, MasterDetailsComponent> myComponents = new HashMap<String, MasterDetailsComponent>();
private final State myStates = new State();
private final States myStates = new States();
public static MasterDetailsStateService getInstance(@NotNull Project project) {
return ServiceManager.getService(project, MasterDetailsStateService.class);
}
public void register(@NonNls String key, MasterDetailsComponent masterDetailsComponent) {
public void register(@NotNull @NonNls String key, MasterDetailsComponent masterDetailsComponent) {
myComponents.put(key, masterDetailsComponent);
final MasterDetailsComponent.UIState loadedState = myStates.getStates().get(key);
if (loadedState != null) {
masterDetailsComponent.loadState(loadedState);
}
}
public State getState() {
for (Map.Entry<String, MasterDetailsComponent> entry : myComponents.entrySet()) {
myStates.getStates().put(entry.getKey(), entry.getValue().getState());
}
return myStates;
}
public void loadState(State state) {
myStates.setStates(state.getStates());
for (Map.Entry<String, MasterDetailsComponent.UIState> entry : myStates.getStates().entrySet()) {
final MasterDetailsComponent component = myComponents.get(entry.getKey());
if (component != null) {
component.loadState(entry.getValue());
for (ComponentState state : myStates.getStates()) {
if (key.equals(state.myKey)) {
final Element element = state.mySettings;
if (element != null) {
loadComponentState(masterDetailsComponent, element);
}
}
}
}
public static class State {
private Map<String, MasterDetailsComponent.UIState> myStates = new HashMap<String, MasterDetailsComponent.UIState>();
private static void loadComponentState(MasterDetailsComponent masterDetailsComponent, Element element) {
final MasterDetailsState loadedState = XmlSerializer.deserialize(element, masterDetailsComponent.getState().getClass());
masterDetailsComponent.loadState(loadedState);
}
public States getState() {
myStates.getStates().clear();
for (Map.Entry<String, MasterDetailsComponent> entry : myComponents.entrySet()) {
final Element element = XmlSerializer.serialize(entry.getValue().getState(), mySerializationFilter);
if (element != null) {
final ComponentState state = new ComponentState();
state.myKey = entry.getKey();
state.mySettings = element;
myStates.getStates().add(state);
}
}
Collections.sort(myStates.getStates(), new Comparator<ComponentState>() {
@Override
public int compare(ComponentState o1, ComponentState o2) {
return o1.myKey.compareTo(o2.myKey);
}
});
return myStates;
}
public void loadState(States states) {
myStates.setStates(states.getStates());
for (ComponentState state : myStates.getStates()) {
final MasterDetailsComponent component = myComponents.get(state.myKey);
if (component != null) {
loadComponentState(component, state.mySettings);
}
}
}
@Tag("state")
public static class ComponentState {
@Attribute("key")
public String myKey;
@Tag("settings")
public Element mySettings;
}
public static class States {
private List<ComponentState> myStates = new ArrayList<ComponentState>();
@Tag("states")
@MapAnnotation(surroundWithTag = false, entryTagName = "state", surroundKeyWithTag = false, surroundValueWithTag = false)
public Map<String, MasterDetailsComponent.UIState> getStates() {
@AbstractCollection(surroundWithTag = false)
public List<ComponentState> getStates() {
return myStates;
}
public void setStates(final Map<String, MasterDetailsComponent.UIState> states) {
public void setStates(List<ComponentState> states) {
myStates = states;
}
}