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 01c93a435756..fa50511d5993 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 @@ -64,10 +64,19 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent { super(); myProject = project; myProjectJdksModel = ProjectStructureConfigurable.getInstance(project).getProjectJdksModel(); - MasterDetailsStateService.getInstance(project).register("ProjectJDKs.UI", this); initTree(); } + @Override + protected String getComponentStateKey() { + return "ProjectJDKs.UI"; + } + + @Override + protected MasterDetailsStateService getStateService() { + return MasterDetailsStateService.getInstance(myProject); + } + protected void initTree() { super.initTree(); new TreeSpeedSearch(myTree, new Convertor() { 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 d82671ef4b17..5e1087318155 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 @@ -34,7 +34,6 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorLi 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.openapi.ui.NamedConfigurable; import com.intellij.packaging.artifacts.*; import com.intellij.packaging.impl.artifacts.ArtifactUtil; @@ -61,7 +60,11 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable { public ArtifactsStructureConfigurable(@NotNull Project project) { super(project, new ArtifactStructureConfigurableState()); - MasterDetailsStateService.getInstance(project).register("ArtifactsStructureConfigurable.UI", this); + } + + @Override + protected String getComponentStateKey() { + return "ArtifactsStructureConfigurable.UI"; } public void init(StructureConfigurableContext context, ModuleStructureConfigurable moduleStructureConfigurable, @@ -160,7 +163,7 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable { } @Override - public MasterDetailsState getState() { + protected MasterDetailsState getState() { ((ArtifactStructureConfigurableState)myState).setDefaultArtifactSettings(myDefaultSettings.getState()); return super.getState(); } @@ -209,6 +212,7 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable { @Override public void reset() { + loadComponentState(); myPackagingEditorContext.resetModifiableModel(); super.reset(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java index eb3973368615..fb5f2b2aca83 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java @@ -32,6 +32,7 @@ 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.MasterDetailsStateService; import com.intellij.openapi.ui.NamedConfigurable; import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.Condition; @@ -100,6 +101,10 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i }); } + @Override + protected MasterDetailsStateService getStateService() { + return MasterDetailsStateService.getInstance(myProject); + } public ActionCallback navigateTo(@Nullable final Place place, final boolean requestFocus) { if (place == null) return new ActionCallback.Done(); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java index e5eb0f045588..b94f19f0b99d 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java @@ -37,7 +37,6 @@ 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; @@ -59,10 +58,14 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable { public FacetStructureConfigurable(final Project project, ModuleManager moduleManager) { super(project); - MasterDetailsStateService.getInstance(project).register("FacetStructureConfigurable.UI", this); myModuleManager = moduleManager; } + @Override + protected String getComponentStateKey() { + return "FacetStructureConfigurable.UI"; + } + public static FacetStructureConfigurable getInstance(final @NotNull Project project) { return ServiceManager.getService(project, FacetStructureConfigurable.class); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/GlobalLibrariesConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/GlobalLibrariesConfigurable.java index 8ac240060a2a..988bcccf763c 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/GlobalLibrariesConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/GlobalLibrariesConfigurable.java @@ -19,7 +19,6 @@ import com.intellij.openapi.components.ServiceManager; 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.NotNull; @@ -31,10 +30,14 @@ public class GlobalLibrariesConfigurable extends BaseLibrariesConfigurable { public GlobalLibrariesConfigurable(final Project project) { super(project); - MasterDetailsStateService.getInstance(project).register("GlobalLibrariesConfigurable.UI", this); myLevel = LibraryTablesRegistrar.APPLICATION_LEVEL; } + @Override + protected String getComponentStateKey() { + return "GlobalLibrariesConfigurable.UI"; + } + @Nls public String getDisplayName() { return "Global Libraries"; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/JdkListConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/JdkListConfigurable.java index 613d0ab370f9..8e8faae3231c 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/JdkListConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/JdkListConfigurable.java @@ -30,7 +30,6 @@ 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; @@ -75,10 +74,15 @@ 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); } + + @Override + protected String getComponentStateKey() { + return "JdkListConfigurable.UI"; + } + protected void processRemovedItems() { } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java index 07c7d6a59d2e..efbd4009a52c 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java @@ -50,7 +50,6 @@ 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; @@ -96,10 +95,13 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple public ModuleStructureConfigurable(Project project, ModuleManager manager) { super(project); - MasterDetailsStateService.getInstance(project).register("ModuleStructureConfigurable.UI", this); myModuleManager = manager; } + @Override + protected String getComponentStateKey() { + return "ModuleStructureConfigurable.UI"; + } protected void initTree() { super.initTree(); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ProjectLibrariesConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ProjectLibrariesConfigurable.java index d2cb1f580067..1a9845c9df4f 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ProjectLibrariesConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ProjectLibrariesConfigurable.java @@ -19,7 +19,6 @@ import com.intellij.openapi.components.ServiceManager; 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.NotNull; @@ -30,10 +29,14 @@ import javax.swing.*; public class ProjectLibrariesConfigurable extends BaseLibrariesConfigurable { public ProjectLibrariesConfigurable(final Project project) { super(project); - MasterDetailsStateService.getInstance(project).register("ProjectLibrariesConfigurable.UI", this); myLevel = LibraryTablesRegistrar.PROJECT_LEVEL; } + @Override + protected String getComponentStateKey() { + return "ProjectLibrariesConfigurable.UI"; + } + @Nls public String getDisplayName() { return "Libraries"; 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 5c1ea5606de7..1171bdda8b8c 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 @@ -61,6 +61,7 @@ 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"); + @NonNls public static final String SCOPE_CHOOSER_CONFIGURABLE_UI_KEY = "ScopeChooserConfigurable.UI"; private final NamedScopesHolder myLocalScopesManager; private final NamedScopesHolder mySharedScopesManager; @@ -81,10 +82,19 @@ public class ScopeChooserConfigurable extends MasterDetailsComponent implements mySharedScopesManager = DependencyValidationManager.getInstance(project); myProject = project; - MasterDetailsStateService.getInstance(project).register("ScopeChooserConfigurable.UI", this); initTree(); } + @Override + protected String getComponentStateKey() { + return SCOPE_CHOOSER_CONFIGURABLE_UI_KEY; + } + + @Override + protected MasterDetailsStateService getStateService() { + return MasterDetailsStateService.getInstance(myProject); + } + protected ArrayList createActions(final boolean fromPopup) { final ArrayList result = new ArrayList(); result.add(new MyAddAction(fromPopup)); 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 f7fea3927e78..c8baff067dbe 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java @@ -323,6 +323,7 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom protected abstract boolean wasObjectStored(Object editableObject); public void reset() { + loadComponentState(); myHasDeletedItems = false; ((DefaultTreeModel)myTree.getModel()).reload(); //myTree.requestFocus(); @@ -345,6 +346,17 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom updateSelectionFromTree(); } + protected void loadComponentState() { + final String key = getComponentStateKey(); + final MasterDetailsStateService stateService = getStateService(); + if (key != null && stateService != null) { + final MasterDetailsState state = stateService.getComponentState(key, myState.getClass()); + if (state != null) { + loadState(state); + } + } + } + private static String getNodePathString(final MyNode node) { StringBuilder path = new StringBuilder(); MyNode current = node; @@ -365,11 +377,22 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom return path.toString(); } - public MasterDetailsState getState() { + @Nullable + @NonNls + protected String getComponentStateKey() { + return null; + } + + @Nullable + protected MasterDetailsStateService getStateService() { + return null; + } + + protected MasterDetailsState getState() { return myState; } - public void loadState(final MasterDetailsState object) { + protected void loadState(final MasterDetailsState object) { XmlSerializerUtil.copyBean(object, myState); } @@ -391,6 +414,11 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom } }); myRoot.removeAllChildren(); + final String key = getComponentStateKey(); + final MasterDetailsStateService stateService = getStateService(); + if (key != null && stateService != null) { + stateService.setComponentState(key, getState()); + } myCurrentConfigurable = null; } 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 5b786f55372b..6bd41e819a80 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsStateService.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsStateService.java @@ -33,6 +33,7 @@ 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; import java.util.*; @@ -46,57 +47,53 @@ import java.util.*; ) public class MasterDetailsStateService implements PersistentStateComponent{ private final SkipDefaultValuesSerializationFilters mySerializationFilter = new SkipDefaultValuesSerializationFilters(); - private final Map myComponents = new HashMap(); - private final States myStates = new States(); + private final Map myStates = new HashMap(); public static MasterDetailsStateService getInstance(@NotNull Project project) { return ServiceManager.getService(project, MasterDetailsStateService.class); } - public void register(@NotNull @NonNls String key, MasterDetailsComponent masterDetailsComponent) { - myComponents.put(key, masterDetailsComponent); - for (ComponentState state : myStates.getStates()) { - if (key.equals(state.myKey)) { - final Element element = state.mySettings; - if (element != null) { - loadComponentState(masterDetailsComponent, element); - } - } - } + /** + * @deprecated override {@link MasterDetailsComponent#getComponentStateKey()} and {@link MasterDetailsComponent#getStateService()} instead + */ + public void register(String key, MasterDetailsComponent component) { } - private static void loadComponentState(MasterDetailsComponent masterDetailsComponent, Element element) { - final MasterDetailsState loadedState = XmlSerializer.deserialize(element, masterDetailsComponent.getState().getClass()); - masterDetailsComponent.loadState(loadedState); + @Nullable + public MasterDetailsState getComponentState(@NotNull @NonNls String key, Class stateClass) { + ComponentState state = myStates.get(key); + return state != null ? XmlSerializer.deserialize(state.mySettings, stateClass) : null; + } + + public void setComponentState(@NotNull @NonNls String key, @NotNull MasterDetailsState state) { + final Element element = XmlSerializer.serialize(state, mySerializationFilter); + if (element == null) { + myStates.remove(key); + } + else { + final ComponentState componentState = new ComponentState(); + componentState.myKey = key; + componentState.mySettings = element; + myStates.put(key, componentState); + } } public States getState() { - myStates.getStates().clear(); - for (Map.Entry 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() { + States states = new States(); + states.myStates.addAll(myStates.values()); + Collections.sort(states.getStates(), new Comparator() { @Override public int compare(ComponentState o1, ComponentState o2) { return o1.myKey.compareTo(o2.myKey); } }); - return myStates; + return states; } 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); - } + myStates.clear(); + for (ComponentState state : states.getStates()) { + myStates.put(state.myKey, state); } } 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 79c6ea143e93..1eebcd37f55a 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java @@ -60,13 +60,22 @@ public class CopyrightProfilesPanel extends MasterDetailsComponent implements Se private final AtomicBoolean myInitialized = new AtomicBoolean(false); public CopyrightProfilesPanel(Project project) { - MasterDetailsStateService.getInstance(project).register("Copyright.UI", this); - myProject = project; - myManager = CopyrightManager.getInstance(project); - initTree(); - } + myProject = project; + myManager = CopyrightManager.getInstance(project); + initTree(); + } - protected void processRemovedItems() { + @Override + protected MasterDetailsStateService getStateService() { + return MasterDetailsStateService.getInstance(myProject); + } + + @Override + protected String getComponentStateKey() { + return "Copyright.UI"; + } + + protected void processRemovedItems() { Map profiles = getAllProfiles(); final List deleted = new ArrayList(); for (CopyrightProfile profile : myManager.getCopyrights()) {