Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-4379 Cannot reduce process panel size #4829

Merged
merged 9 commits into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public interface StateComponent {
*
* @param state the component state object
*/
void loadState(@NotNull JsonObject state);
void setState(@NotNull JsonObject state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What reason for this renaming?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make names more clear for developer.
The StateComponent interface has
JsonObject getState() method and now it has setState instead of loadState

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to JavaDoc Called when component should restore his state. loadSatte more reasonable for me.
@evidolob your opinion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @vparfonov, in common case set prefix used for setters, mutator method for object but that method doesn't has side effects. In this case we have huge side effects, so set prefix is confusing, load is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it changes the state, it sets a new state.
But it's not a problem to me to revert the method name.


}
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ private JsonArray storeEditors(EditorPartStack partStack) {

@Override
@SuppressWarnings("unchecked")
public void loadState(@NotNull final JsonObject state) {
public void setState(@NotNull final JsonObject state) {
if (state.hasKey("FILES")) {
JsonObject files = state.getObject("FILES");
EditorPartStack partStack = editorMultiPartStack.createRootPartStack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ public JsonObject getState() {
}

@Override
public void loadState(@NotNull JsonObject state) {

public void setState(@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 @@ -85,7 +85,7 @@ private void restoreState(JsonObject settings) {
for (String key : workspace.keys()) {
if (persistenceComponents.containsKey(key)) {
StateComponent component = persistenceComponents.get(key);
component.loadState(workspace.getObject(key));
component.setState(workspace.getObject(key));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,16 @@ public JsonObject getState() {
}

@Override
public void loadState(JsonObject state) {
public void setState(JsonObject state) {
if (state.hasKey("perspectives")) {
JsonObject perspectives = state.getObject("perspectives");
Map<String, Perspective> perspectiveMap = perspectiveManagerProvider.get().getPerspectives();
for (String key : perspectives.keys()) {
if (perspectiveMap.containsKey(key)) {
perspectiveMap.get(key).loadState(perspectives.getObject(key));
perspectiveMap.get(key).setState(perspectives.getObject(key));
}
}
}
}

}
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 @@ -341,20 +345,24 @@ private JsonObject getPartStackState(PartStack partStack, WorkBenchPartControlle
}

@Override
public void loadState(@NotNull JsonObject state) {
public void setState(@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);
setPartStackState(partStacks.get(INFORMATION), belowPartController, partStackState, perspectiveMaximized);
break;
case NAVIGATION:
restorePartController(partStacks.get(NAVIGATION), leftPartController, partStack);
setPartStackState(partStacks.get(NAVIGATION), leftPartController, partStackState, perspectiveMaximized);
break;
case TOOLING:
restorePartController(partStacks.get(TOOLING), rightPartController, partStack);
setPartStackState(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 setPartStackState(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 @@ -147,10 +147,11 @@ public void restoreShouldCallLoadState() throws Exception {
appStateManager.restoreWorkspaceState(WS_ID);

ArgumentCaptor<JsonObject> stateCaptor = ArgumentCaptor.forClass(JsonObject.class);
verify(component1).loadState(stateCaptor.capture());
verify(component1).setState(stateCaptor.capture());

JsonObject jsonObject = stateCaptor.getValue();
assertThat(jsonObject.hasKey("key1")).isTrue();
assertThat(jsonObject.getString("key1")).isEqualTo("value1");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public List<? extends PartPresenter> answer(InvocationOnMock invocationOnMock) t
}
});

perspective.loadState(state);
perspective.setState(state);

verify(workBenchController).setSize(142d);
}
Expand All @@ -194,7 +194,7 @@ public void shouldRestoreHiddenPartStackState() throws Exception {

partStack.put("HIDDEN", true);

perspective.loadState(state);
perspective.setState(state);

verify(workBenchController).setHidden(true);
}
Expand All @@ -216,7 +216,7 @@ public void shouldRestoreOpenedParts() throws Exception {
when(dynaProvider.<PartPresenter>getProvider(anyString())).thenReturn(partProvider);
when(partProvider.get()).thenReturn(partPresenter);

perspective.loadState(state);
perspective.setState(state);

verify(dynaProvider).getProvider("foo.Bar");
verify(partProvider).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ public void shouldRestoreStorePerspectives() throws Exception {
JsonObject perspective1State = Json.createObject();
perspectives.put("perspective1", perspective1State);

presenter.loadState(state);
presenter.setState(state);

verify(perspective1).loadState(perspective1State);
verify(perspective1).setState(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