Skip to content

Commit

Permalink
CHE-4379 Cannot reduce process panel size (#4829)
Browse files Browse the repository at this point in the history
* CHE-4379 Cannot reduce process panel size

* CHE-4379 Cannot reduce process panel size

* CHE-4379 Cannot reduce process panel size
  • Loading branch information
Vitaliy Guliy authored Apr 24, 2017
1 parent b42ccbf commit 261cb40
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,5 @@ public void loadState(JsonObject state) {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -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 <b>true</b> 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")) {
Expand All @@ -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<PartPresenter> provider = dynaProvider.getProvider(activePart);
if (provider != null) {
partStack.setActivePart(provider.get());
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,5 @@ public void restoreShouldCallLoadState() throws Exception {
assertThat(jsonObject.hasKey("key1")).isTrue();
assertThat(jsonObject.getString("key1")).isEqualTo("value1");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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.<SplitLayoutPanel>anyObject(),
Matchers.<SimplePanel>anyObject())).thenReturn(workBenchController);

Expand Down Expand Up @@ -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<PartPresenter> partPresenters = new ArrayList<>();
partPresenters.add(partPresenter);
when(partStackPresenter.getParts()).thenAnswer(new Answer<List<? extends PartPresenter>>() {
@Override
public List<? extends PartPresenter> answer(InvocationOnMock invocationOnMock) throws Throwable {
return partPresenters;
}
});

perspective.loadState(state);

verify(workBenchController, never()).setSize(142d);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ public void shouldRestoreStorePerspectives() throws Exception {

verify(perspective1).loadState(perspective1State);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -124,7 +124,6 @@ void processCurrentProject() {
final PartStack toolingPartStack = workspaceAgent.getPartStack(TOOLING);

if (rootProject == null) {

if (toolingPartStack.containsPart(contributePart)) {
invalidateContext(lastSelected);
hidePart();
Expand Down

0 comments on commit 261cb40

Please sign in to comment.