From 30e298cd775232d0438802cd44ab47dafc9e7bf0 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Wed, 14 Mar 2012 12:57:18 +0400 Subject: [PATCH] IDEA-76142: Gradle support - cannot update IDEA projects once one of build.gradle files changes 'Expand' project change tree nodes state is preserved during the single IDE launch session even if they are not persistent --- .../plugins/gradle/config/GradleSettings.java | 29 ++++++++++++++++--- .../GradleProjectStructureChangesPanel.java | 6 ++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleSettings.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleSettings.java index a970e5f1112d..2efdb62e35b8 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleSettings.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleSettings.java @@ -45,6 +45,9 @@ public class GradleSettings implements PersistentStateComponent, /** Holds changes confirmed by the end-user. */ private final AtomicReference> myExpandStates = new AtomicReference>(new HashMap()); + /** @see #getWorkingExpandStates() */ + private final AtomicReference> myWorkingExpandStates + = new AtomicReference>(new HashMap()); /** Holds information about 'expand/collapse' status of the 'sync project structure tree' nodes. */ //private final AtomicReference> myAcceptedChanges // = new AtomicReference>(); @@ -54,8 +57,9 @@ public class GradleSettings implements PersistentStateComponent, @Override public GradleSettings getState() { - if (!PRESERVE_EXPAND_STATE) { - myExpandStates.get().clear(); + myExpandStates.get().clear(); + if (PRESERVE_EXPAND_STATE) { + myExpandStates.get().putAll(myWorkingExpandStates.get()); } return this; } @@ -104,15 +108,32 @@ public class GradleSettings implements PersistentStateComponent, project.getMessageBus().syncPublisher(GradleConfigNotifier.TOPIC).onLinkedProjectPathChange(oldPath, path); } + @SuppressWarnings("UnusedDeclaration") @NotNull - public Map getExpandStates() { + public Map getExpandStates() { // Necessary for the serialization. return myExpandStates.get(); } + + /** + * It's possible to configure the gradle integration to not persist 'expand states' (see {@link #PRESERVE_EXPAND_STATE}). + *

+ * However, we want the state to be saved during the single IDE session even if we don't want to persist it between the + * different sessions. + *

+ * This method allows to retrieve that 'non-persistent state'. + * + * @return project structure changes tree nodes 'expand state' to use + */ + @NotNull + public Map getWorkingExpandStates() { + return myWorkingExpandStates.get(); + } @SuppressWarnings("UnusedDeclaration") public void setExpandStates(@Nullable Map state) { // Necessary for the serialization. if (state != null) { - myExpandStates.set(state); + myExpandStates.get().putAll(state); + myWorkingExpandStates.get().putAll(state); } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureChangesPanel.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureChangesPanel.java index 100f32edf451..239e313cefd5 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureChangesPanel.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureChangesPanel.java @@ -99,14 +99,14 @@ public class GradleProjectStructureChangesPanel extends GradleToolWindowPanel { @Override public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { if (!mySuppressCollapseTracking) { - mySettings.getExpandStates().put(getPath(event.getPath()), true); + mySettings.getWorkingExpandStates().put(getPath(event.getPath()), true); } } @Override public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { if (!mySuppressCollapseTracking) { - mySettings.getExpandStates().put(getPath(event.getPath()), false); + mySettings.getWorkingExpandStates().put(getPath(event.getPath()), false); } } }); @@ -361,7 +361,7 @@ public class GradleProjectStructureChangesPanel extends GradleToolWindowPanel { */ private void applyCollapseState(@NotNull TreePath path) { final String key = getPath(path); - final Boolean expanded = mySettings.getExpandStates().get(key); + final Boolean expanded = mySettings.getWorkingExpandStates().get(key); if (expanded == null) { return; }