From 261cb400dcc43272e27eecdba223b9fb4a46aae4 Mon Sep 17 00:00:00 2001 From: Vitaliy Guliy Date: Mon, 24 Apr 2017 17:57:59 +0300 Subject: [PATCH] CHE-4379 Cannot reduce process panel size (#4829) * CHE-4379 Cannot reduce process panel size * CHE-4379 Cannot reduce process panel size * CHE-4379 Cannot reduce process panel size --- .../ProjectExplorerStateComponent.java | 1 - .../che/ide/workspace/WorkspacePresenter.java | 1 + .../general/AbstractPerspective.java | 69 +++++++++++++++---- .../statepersistance/AppStateManagerTest.java | 1 + .../AbstractPerspectivePersistenceTest.java | 40 +++++++++++ .../WorkspacePresenterPersistenceTest.java | 1 + .../client/ContributionMixinProvider.java | 3 +- 7 files changed, 99 insertions(+), 17 deletions(-) diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerStateComponent.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerStateComponent.java index 5bd5c1e1ad1..cd5f82503d7 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerStateComponent.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerStateComponent.java @@ -86,7 +86,6 @@ public JsonObject getState() { @Override public void loadState(@NotNull JsonObject state) { - if (state.hasKey(SHOW_HIDDEN_FILES)) { projectExplorer.showHiddenFiles(state.getBoolean(SHOW_HIDDEN_FILES)); } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspacePresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspacePresenter.java index 9067d24c2da..b3f61c67b6c 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspacePresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspacePresenter.java @@ -174,4 +174,5 @@ public void loadState(JsonObject state) { } } } + } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/perspectives/general/AbstractPerspective.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/perspectives/general/AbstractPerspective.java index f78a7d4fa40..34a5ff28a16 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/perspectives/general/AbstractPerspective.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/perspectives/general/AbstractPerspective.java @@ -321,13 +321,17 @@ public JsonObject getState() { private JsonObject getPartStackState(PartStack partStack, WorkBenchPartController partController) { JsonObject state = Json.createObject(); state.put("SIZE", partController.getSize()); + state.put("STATE", partStack.getPartStackState().name()); + if (partStack.getParts().isEmpty()) { state.put("HIDDEN", true); } else { if (partStack.getActivePart() != null) { state.put("ACTIVE_PART", partStack.getActivePart().getClass().getName()); } + state.put("HIDDEN", partController.isHidden()); + JsonArray parts = Json.createArray(); state.put("PARTS", parts); int i = 0; @@ -343,18 +347,22 @@ private JsonObject getPartStackState(PartStack partStack, WorkBenchPartControlle @Override public void loadState(@NotNull JsonObject state) { if (state.hasKey("PART_STACKS")) { - JsonObject part_stacks = state.getObject("PART_STACKS"); - for (String partStackType : part_stacks.keys()) { - JsonObject partStack = part_stacks.getObject(partStackType); + JsonObject partStacksState = state.getObject("PART_STACKS"); + + // Don't restore part dimensions if perspective is maximized. + boolean perspectiveMaximized = isPerspectiveMaximized(partStacksState); + + for (String partStackType : partStacksState.keys()) { + JsonObject partStackState = partStacksState.getObject(partStackType); switch (PartStackType.valueOf(partStackType)) { case INFORMATION: - restorePartController(partStacks.get(INFORMATION), belowPartController, partStack); + loadPartStackState(partStacks.get(INFORMATION), belowPartController, partStackState, perspectiveMaximized); break; case NAVIGATION: - restorePartController(partStacks.get(NAVIGATION), leftPartController, partStack); + loadPartStackState(partStacks.get(NAVIGATION), leftPartController, partStackState, perspectiveMaximized); break; case TOOLING: - restorePartController(partStacks.get(TOOLING), rightPartController, partStack); + loadPartStackState(partStacks.get(TOOLING), rightPartController, partStackState, perspectiveMaximized); break; } } @@ -370,9 +378,38 @@ public void loadState(@NotNull JsonObject state) { } } - private void restorePartController(PartStack partStack, WorkBenchPartController controller, JsonObject partStackJSON) { - if (partStackJSON.hasKey("PARTS")) { - JsonArray parts = partStackJSON.get("PARTS"); + /** + * Determines whether perspective is maximized. + * + * @param partStacksState part stack state + * @return true is perspective has maximized part stack + */ + private boolean isPerspectiveMaximized(JsonObject partStacksState) { + for (String partStackType : partStacksState.keys()) { + JsonObject partStackState = partStacksState.getObject(partStackType); + if (partStackState.hasKey("STATE") && PartStack.State.MAXIMIZED.name().equals(partStackState.getString("STATE"))) { + return true; + } + } + + return false; + } + + /** + * Set part stack state. + * + * @param partStack + * @param controller + * @param partStackState + * @param skipRestoreDimensions + */ + private void loadPartStackState(PartStack partStack, + WorkBenchPartController controller, + JsonObject partStackState, + boolean skipRestoreDimensions) { + if (partStackState.hasKey("PARTS")) { + JsonArray parts = partStackState.get("PARTS"); + for (int i = 0; i < parts.length(); i++) { JsonObject value = parts.get(i); if (value.hasKey("CLASS")) { @@ -389,8 +426,8 @@ private void restorePartController(PartStack partStack, WorkBenchPartController } // restore part stack's active part - if (partStackJSON.hasKey("ACTIVE_PART")) { - String activePart = partStackJSON.getString("ACTIVE_PART"); + if (partStackState.hasKey("ACTIVE_PART")) { + String activePart = partStackState.getString("ACTIVE_PART"); Provider provider = dynaProvider.getProvider(activePart); if (provider != null) { partStack.setActivePart(provider.get()); @@ -403,13 +440,17 @@ private void restorePartController(PartStack partStack, WorkBenchPartController return; } - if (partStackJSON.hasKey("HIDDEN") && partStackJSON.getBoolean("HIDDEN")) { + if (skipRestoreDimensions) { + return; + } + + if (partStackState.hasKey("HIDDEN") && partStackState.getBoolean("HIDDEN")) { partStack.minimize(); return; } - if (partStackJSON.hasKey("SIZE")) { - double size = partStackJSON.getNumber("SIZE"); + if (partStackState.hasKey("SIZE")) { + double size = partStackState.getNumber("SIZE"); // Size of the part must not be less 100 pixels. if (size <= MIN_PART_SIZE) { diff --git a/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/statepersistance/AppStateManagerTest.java b/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/statepersistance/AppStateManagerTest.java index 1dab42e94c9..8bf57f7cc22 100644 --- a/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/statepersistance/AppStateManagerTest.java +++ b/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/statepersistance/AppStateManagerTest.java @@ -153,4 +153,5 @@ public void restoreShouldCallLoadState() throws Exception { assertThat(jsonObject.hasKey("key1")).isTrue(); assertThat(jsonObject.getString("key1")).isEqualTo("value1"); } + } diff --git a/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/perspectives/general/AbstractPerspectivePersistenceTest.java b/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/perspectives/general/AbstractPerspectivePersistenceTest.java index fee9661adad..50fe00fc89c 100644 --- a/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/perspectives/general/AbstractPerspectivePersistenceTest.java +++ b/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/perspectives/general/AbstractPerspectivePersistenceTest.java @@ -26,6 +26,7 @@ import org.eclipse.che.ide.api.editor.AbstractEditorPresenter; import org.eclipse.che.ide.api.event.ActivePartChangedEvent; import org.eclipse.che.ide.api.parts.PartPresenter; +import org.eclipse.che.ide.api.parts.PartStack; import org.eclipse.che.ide.api.parts.PartStackView; import org.eclipse.che.ide.part.PartStackPresenter; import org.eclipse.che.ide.workspace.PartStackPresenterFactory; @@ -39,6 +40,7 @@ import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mock; +import static org.mockito.Mockito.never; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -110,6 +112,8 @@ public void setUp() throws Exception { when(view.getInformationPanel()).thenReturn(simpleLayoutPanel); when(view.getToolPanel()).thenReturn(simplePanel); + when(partStackPresenter.getPartStackState()).thenReturn(PartStack.State.NORMAL); + when(controllerFactory.createController(Matchers.anyObject(), Matchers.anyObject())).thenReturn(workBenchController); @@ -224,4 +228,40 @@ public void shouldRestoreOpenedParts() throws Exception { verify(partStackPresenter).addPart(partPresenter); } + @Test + public void shouldRestoreMaximizedPartStack() throws Exception { + JsonObject state = Json.createObject(); + + JsonObject parts = Json.createObject(); + state.put("PART_STACKS", parts); + + JsonObject partStack = Json.createObject(); + parts.put("INFORMATION", partStack); + + partStack.put("STATE", PartStack.State.MAXIMIZED.name()); + + JsonArray partsArray = Json.createArray(); + partStack.put("PARTS", partsArray); + + JsonObject part = Json.createObject(); + partsArray.set(0, part); + part.put("CLASS", "foo.Bar"); + + partStack.put("SIZE", 142); + + // partStackPresenter.getParts() must return non empty list + final List partPresenters = new ArrayList<>(); + partPresenters.add(partPresenter); + when(partStackPresenter.getParts()).thenAnswer(new Answer>() { + @Override + public List answer(InvocationOnMock invocationOnMock) throws Throwable { + return partPresenters; + } + }); + + perspective.loadState(state); + + verify(workBenchController, never()).setSize(142d); + } + } diff --git a/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/state/WorkspacePresenterPersistenceTest.java b/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/state/WorkspacePresenterPersistenceTest.java index d4c1e05bb61..5aad8e0332e 100644 --- a/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/state/WorkspacePresenterPersistenceTest.java +++ b/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/state/WorkspacePresenterPersistenceTest.java @@ -106,4 +106,5 @@ public void shouldRestoreStorePerspectives() throws Exception { verify(perspective1).loadState(perspective1State); } + } diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributionMixinProvider.java b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributionMixinProvider.java index 6215315ca5c..c3341c9d01b 100644 --- a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributionMixinProvider.java +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributionMixinProvider.java @@ -114,7 +114,7 @@ public void onSelectionChanged(SelectionChangedEvent event) { }); } - void processCurrentProject() { + private void processCurrentProject() { final Project rootProject = appContext.getRootProject(); if (lastSelected != null && lastSelected.equals(rootProject)) { @@ -124,7 +124,6 @@ void processCurrentProject() { final PartStack toolingPartStack = workspaceAgent.getPartStack(TOOLING); if (rootProject == null) { - if (toolingPartStack.containsPart(contributePart)) { invalidateContext(lastSelected); hidePart();