From 7aab04231ecd335f56c3d091cbfb25ebc041d548 Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 21 Oct 2009 15:49:28 +0400 Subject: [PATCH] IDEADEV-40699: Artifacts dialog: "Show content of elements" options could be remembered --- .../ProjectJdksConfigurable.java | 3 +- .../artifacts/ArtifactEditorImpl.java | 6 +++ .../artifacts/ArtifactEditorSettings.java | 3 +- .../ArtifactsStructureConfigurable.java | 11 +++- ...factsStructureConfigurableContextImpl.java | 10 +++- .../artifacts/LayoutTreeComponent.java | 1 + .../ScopeChooserConfigurable.java | 52 ++++++++++++++----- .../openapi/ui/MasterDetailsComponent.java | 33 +++++++++++- .../openapi/ui/MasterDetailsStateService.java | 34 +++++++++--- .../copyright/ui/CopyrightProfilesPanel.java | 3 +- 10 files changed, 127 insertions(+), 29 deletions(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectJdksConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectJdksConfigurable.java index f9c1c0c88f69..284853e27b6b 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectJdksConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectJdksConfigurable.java @@ -25,7 +25,6 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.Project; @@ -66,7 +65,7 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent implements C super(); myProject = project; myProjectJdksModel = ProjectJdksModel.getInstance(project); - ServiceManager.getService(project, MasterDetailsStateService.class).register("ProjectJDKs.UI", this); + MasterDetailsStateService.getInstance(project).register("ProjectJDKs.UI", this); initTree(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java index f1734380c162..782a77cf7e91 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java @@ -212,6 +212,7 @@ public class ArtifactEditorImpl implements ArtifactEditorEx { } myShowContentCheckBox.setThirdStateEnabled(false); myLayoutTreeComponent.rebuildTree(); + onShowContentSettingsChanged(); } }); @@ -233,6 +234,10 @@ public class ArtifactEditorImpl implements ArtifactEditorEx { return getMainComponent(); } + private void onShowContentSettingsChanged() { + ((ArtifactsStructureConfigurableContextImpl)myContext.getParent()).getDefaultSettings().setTypesToShowContent(mySubstitutionParameters.getTypesToSubstitute()); + } + public void updateShowContentCheckbox() { final ThreeStateCheckBox.State state; if (mySubstitutionParameters.isAllSubstituted()) { @@ -246,6 +251,7 @@ public class ArtifactEditorImpl implements ArtifactEditorEx { } myShowContentCheckBox.setThirdStateEnabled(state == ThreeStateCheckBox.State.DONT_CARE); myShowContentCheckBox.setState(state); + onShowContentSettingsChanged(); } public ArtifactEditorSettings createSettings() { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorSettings.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorSettings.java index e24ee4acf2bb..e83f002bf09d 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorSettings.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorSettings.java @@ -81,7 +81,8 @@ public class ArtifactEditorSettings implements PersistentStateComponent myTypesToShowContentIds = new ArrayList(); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java index a45c9559fbf1..62bf9dbc498d 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java @@ -20,6 +20,7 @@ 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.options.ConfigurationException; @@ -29,6 +30,7 @@ import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.ui.configuration.projectRoot.BaseStructureConfigurable; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement; +import com.intellij.openapi.ui.MasterDetailsStateService; import com.intellij.packaging.artifacts.*; import com.intellij.packaging.elements.CompositePackagingElement; import org.jetbrains.annotations.Nls; @@ -49,15 +51,17 @@ import java.util.*; public class ArtifactsStructureConfigurable extends BaseStructureConfigurable { @NonNls private static final String DEFAULT_ARTIFACT_NAME = "unnamed"; private ArtifactsStructureConfigurableContextImpl myPackagingEditorContext; + private ArtifactEditorSettings myDefaultSettings = new ArtifactEditorSettings(); public ArtifactsStructureConfigurable(@NotNull Project project) { super(project); + MasterDetailsStateService.getInstance(project).register("ArtifactsStructureConfigurable.UI", this); } @Override public void init(StructureConfigurableContext context) { super.init(context); - myPackagingEditorContext = new ArtifactsStructureConfigurableContextImpl(myContext, myProject, new ArtifactAdapter() { + myPackagingEditorContext = new ArtifactsStructureConfigurableContextImpl(myContext, myProject, myDefaultSettings, new ArtifactAdapter() { @Override public void artifactAdded(@NotNull Artifact artifact) { final MyNode node = addArtifactNode(artifact); @@ -96,6 +100,11 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable { return node; } + @Override + protected PersistentStateComponent getAdditionalSettings() { + return myDefaultSettings; + } + @Override public void reset() { myPackagingEditorContext.resetModifiableModel(); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java index 42a168bb6e97..8f6dc39bdff6 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java @@ -43,9 +43,11 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon private Map> myModifiableRoots = new HashMap>(); private Map myArtifactEditors = new HashMap(); private Map myEditorSettings = new HashMap(); - private ArtifactEditorSettings myDefaultSettings = new ArtifactEditorSettings(); + private final ArtifactEditorSettings myDefaultSettings; - public ArtifactsStructureConfigurableContextImpl(StructureConfigurableContext context, Project project, final ArtifactAdapter modifiableModelListener) { + public ArtifactsStructureConfigurableContextImpl(StructureConfigurableContext context, Project project, + ArtifactEditorSettings defaultSettings, final ArtifactAdapter modifiableModelListener) { + myDefaultSettings = defaultSettings; myModifiableModelListener = modifiableModelListener; myContext = context; myProject = project; @@ -123,6 +125,10 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon return myModifiableModel; } + public ArtifactEditorSettings getDefaultSettings() { + return myDefaultSettings; + } + @NotNull public ModulesProvider getModulesProvider() { return myContext.getModulesConfigurator(); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTreeComponent.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTreeComponent.java index 6c626f2e4841..c1810e4e7571 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTreeComponent.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTreeComponent.java @@ -101,6 +101,7 @@ public class LayoutTreeComponent implements DnDTarget, Disposable { public void setSortElements(boolean sortElements) { mySortElements = sortElements; myBuilder.setNodeDescriptorComparator(getComparator()); + ((ArtifactsStructureConfigurableContextImpl)myArtifactsEditor.getContext().getParent()).getDefaultSettings().setSortElements(sortElements); } @Nullable diff --git a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserConfigurable.java b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserConfigurable.java index cf699492c514..5b703b80f650 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserConfigurable.java +++ b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserConfigurable.java @@ -20,6 +20,7 @@ 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; @@ -41,9 +42,13 @@ 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; @@ -53,10 +58,7 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.Set; +import java.util.*; /** * User: anna @@ -65,7 +67,7 @@ import java.util.Set; 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; @@ -85,7 +87,7 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements mySharedScopesManager = DependencyValidationManager.getInstance(project); myProject = project; - ServiceManager.getService(project, MasterDetailsStateService.class).register("ScopeChooserConfigurable.UI", this); + MasterDetailsStateService.getInstance(project).register("ScopeChooserConfigurable.UI", this); initTree(); } @@ -124,14 +126,24 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements loadStateOrder(); } + @Override + protected PersistentStateComponent getAdditionalSettings() { + return myScopesState; + } + + @TestOnly + public void loadScopesState(ScopeChooserConfigurableState scopesState) { + myScopesState = scopesState; + } + public boolean isModified() { - if (myRoot.getChildCount() != myState.order.size()) return true; + if (myRoot.getChildCount() != myScopesState.myOrder.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 (myState.order.size() <= i) return true; - final String name = myState.order.get(i); + if (myScopesState.myOrder.size() <= i) return true; + final String name = myScopesState.myOrder.get(i); if (!Comparing.strEqual(name, namedScope.getName())) return true; if (isInitialized(scopeConfigurable)) { final NamedScopesHolder holder = scopeConfigurable.getHolder(); @@ -171,17 +183,17 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements TreeUtil.sort(myRoot, new Comparator() { public int compare(final DefaultMutableTreeNode o1, final DefaultMutableTreeNode o2) { - final int idx1 = myState.order.indexOf(((MyNode)o1).getDisplayName()); - final int idx2 = myState.order.indexOf(((MyNode)o2).getDisplayName()); + final int idx1 = myScopesState.myOrder.indexOf(((MyNode)o1).getDisplayName()); + final int idx2 = myScopesState.myOrder.indexOf(((MyNode)o2).getDisplayName()); return idx1 - idx2; } }); } private void loadStateOrder() { - myState.order.clear(); + myScopesState.myOrder.clear(); for (int i = 0; i < myRoot.getChildCount(); i++) { - myState.order.add(((MyNode)myRoot.getChildAt(i)).getDisplayName()); + myScopesState.myOrder.add(((MyNode)myRoot.getChildAt(i)).getDisplayName()); } } @@ -493,4 +505,18 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements return myConfigurable; } } + + public static class ScopeChooserConfigurableState implements PersistentStateComponent { + @Tag("order") + @AbstractCollection(surroundWithTag = false, elementTag = "scope", elementValueAttribute = "name") + public List myOrder = new ArrayList(); + + public ScopeChooserConfigurableState getState() { + return this; + } + + public void loadState(ScopeChooserConfigurableState state) { + XmlSerializerUtil.copyBean(state, this); + } + } } diff --git a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java index 9c5d72b5cdb6..502eb7ed069d 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java @@ -38,9 +38,14 @@ 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 org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -89,9 +94,12 @@ public abstract class MasterDetailsComponent implements Configurable, Persistent } public static class UIState { + @Tag("splitter-proportions") public SplitterProportionsDataImpl proportions = new SplitterProportionsDataImpl(); + @Tag("last-edited") public String lastEditedConfigurable; - public List order = new ArrayList(); + @Tag("settings") + public Element mySettingsElement; } protected UIState myState = new UIState(); @@ -370,14 +378,35 @@ 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()); + } + } return myState; } public void loadState(final UIState object) { myState.lastEditedConfigurable = object.lastEditedConfigurable; myState.proportions = object.proportions; - myState.order = object.order; + 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 disposeUIResources() { diff --git a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsStateService.java b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsStateService.java index 4d98d62a7b93..0c80779dd42c 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsStateService.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsStateService.java @@ -21,14 +21,18 @@ package com.intellij.openapi.ui; import com.intellij.openapi.components.PersistentStateComponent; +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.annotations.Tag; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; -import org.jetbrains.annotations.NonNls; - @State( name="masterDetails", storages= { @@ -38,25 +42,43 @@ import org.jetbrains.annotations.NonNls; )} ) public class MasterDetailsStateService implements PersistentStateComponent{ - public State myStates = new State(); + private Map myComponents = new HashMap(); + private State myStates = new State(); + + public static MasterDetailsStateService getInstance(@NotNull Project project) { + return ServiceManager.getService(project, MasterDetailsStateService.class); + } public void register(@NonNls String key, MasterDetailsComponent masterDetailsComponent) { + myComponents.put(key, masterDetailsComponent); final MasterDetailsComponent.UIState loadedState = myStates.getStates().get(key); - if (loadedState != null) masterDetailsComponent.loadState(loadedState); - myStates.getStates().put(key, masterDetailsComponent.getState()); + if (loadedState != null) { + masterDetailsComponent.loadState(loadedState); + } } public State getState() { + for (Map.Entry 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 entry : myStates.getStates().entrySet()) { + final MasterDetailsComponent component = myComponents.get(entry.getKey()); + if (component != null) { + component.loadState(entry.getValue()); + } + } } public static class State { - public Map myStates = new HashMap(); + private Map myStates = new HashMap(); + @Tag("states") + @MapAnnotation(surroundWithTag = false, entryTagName = "state", surroundKeyWithTag = false, surroundValueWithTag = false) public Map getStates() { return myStates; } diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java index 0d60a036666b..28a3bb56a604 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java @@ -21,7 +21,6 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonShortcuts; import com.intellij.openapi.actionSystem.CustomShortcutSet; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.options.ConfigurationException; @@ -60,7 +59,7 @@ public class CopyrightProfilesPanel extends MasterDetailsComponent { private final AtomicBoolean myInitialized = new AtomicBoolean(false); public CopyrightProfilesPanel(Project project) { - ServiceManager.getService(project, MasterDetailsStateService.class).register("Copyright.UI", this); + MasterDetailsStateService.getInstance(project).register("Copyright.UI", this); myProject = project; myManager = CopyrightManager.getInstance(project); initTree();