Skip to content

Commit

Permalink
CHE-3369 Git history panel is not opened (eclipse-che#3414)
Browse files Browse the repository at this point in the history
* CHE-3369 Git history panel is not opened

* CHE-3369 Git history panel is not opened

* CHE-3369 Git history panel is not opened
  • Loading branch information
Vitaliy Guliy authored Dec 19, 2016
1 parent 34967da commit 7692648
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,8 @@ public void addPart(@NotNull PartPresenter part) {
@Override
public void addPart(@NotNull PartPresenter part, @Nullable Constraints constraint) {
if (containsPart(part)) {
workBenchPartController.setHidden(true);

TabItem selectedItem = getTabByPart(part);

if (selectedItem != null) {
selectedItem.unSelect();
}

TabItem tab = getTabByPart(part);
onTabClicked(tab);
return;
}

Expand Down Expand Up @@ -203,13 +197,33 @@ public PartPresenter getActivePart() {
@Override
public void setActivePart(@NotNull PartPresenter part) {
TabItem tab = getTabByPart(part);

if (tab == null) {
return;
}

activePart = part;
activeTab = tab;

if (state == State.MINIMIZED) {
state = State.NORMAL;
workBenchPartController.setSize(currentSize);
workBenchPartController.setHidden(false);

// Notify the part stack state has been changed.
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
eventBus.fireEvent(new PartStackStateChangedEvent(PartStackPresenter.this));
}
});
} else if (state == State.COLLAPSED) {
// Collapsed state means the other part stack is maximized.
// Ask the delegate to restore part stacks.
if (delegate != null) {
delegate.onRestore(this);
}
}

selectActiveTab(tab);
}

Expand Down Expand Up @@ -241,7 +255,6 @@ public void openPreviousActivePart() {
}

TabItem selectedTab = getTabByPart(activePart);

if (selectedTab != null) {
selectActiveTab(selectedTab);
}
Expand Down Expand Up @@ -321,6 +334,7 @@ public void collapse() {
// Collapse and update the state.
currentSize = workBenchPartController.getSize();
workBenchPartController.setSize(0);
workBenchPartController.setHidden(true);
state = State.COLLAPSED;

// Deselect the active tab.
Expand Down Expand Up @@ -358,6 +372,7 @@ public void minimize() {
if (state == State.NORMAL) {
currentSize = workBenchPartController.getSize();
workBenchPartController.setSize(0);
workBenchPartController.setHidden(true);
state = State.MINIMIZED;
}

Expand Down Expand Up @@ -389,6 +404,7 @@ public void restore() {
State prevState = state;
state = State.NORMAL;
workBenchPartController.setSize(currentSize);
workBenchPartController.setHidden(false);

// Ask the delegate to restore part stacks if this part stack was maximized.
if (prevState == State.MAXIMIZED) {
Expand Down Expand Up @@ -458,7 +474,6 @@ private void selectActiveTab(@NotNull TabItem selectedTab) {
workBenchPartController.setHidden(false);

PartPresenter selectedPart = parts.get(selectedTab);

view.selectTab(selectedPart);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,10 @@ public void addPart(@NotNull PartPresenter part, @NotNull PartStackType type, @N
PartStack destPartStack = partStacks.get(type);

List<String> rules = part.getRules();

if (rules.isEmpty() && !destPartStack.containsPart(part)) {
if (rules.isEmpty() || rules.contains(perspectiveId)) {
destPartStack.addPart(part, constraint);
return;
}

if (rules.contains(perspectiveId)) {
destPartStack.addPart(part, constraint);
}
}

@Override
Expand Down Expand Up @@ -344,24 +339,20 @@ private JsonObject getPartStackState(PartStack partStack, WorkBenchPartControlle
public void loadState(@NotNull JsonObject state) {
if (state.hasKey("PART_STACKS")) {
JsonObject part_stacks = state.getObject("PART_STACKS");
List<PartPresenter> activeParts = new ArrayList<>();
for (String partStackType : part_stacks.keys()) {
JsonObject partStack = part_stacks.getObject(partStackType);
switch (PartStackType.valueOf(partStackType)) {
case INFORMATION:
restorePartController(partStacks.get(INFORMATION), belowPartController, partStack, activeParts);
restorePartController(partStacks.get(INFORMATION), belowPartController, partStack);
break;
case NAVIGATION:
restorePartController(partStacks.get(NAVIGATION), leftPartController, partStack, activeParts);
restorePartController(partStacks.get(NAVIGATION), leftPartController, partStack);
break;
case TOOLING:
restorePartController(partStacks.get(TOOLING), rightPartController, partStack, activeParts);
restorePartController(partStacks.get(TOOLING), rightPartController, partStack);
break;
}
}
for (PartPresenter part : activeParts) {
setActivePart(part);
}
}

if (state.hasKey("ACTIVE_PART")) {
Expand All @@ -373,46 +364,44 @@ public void loadState(@NotNull JsonObject state) {
}
}

private void restorePartController(PartStack stack, WorkBenchPartController controller, JsonObject partStack,
List<PartPresenter> activeParts) {
double size = 0;
if (partStack.hasKey("SIZE")) {
size = partStack.getNumber("SIZE");
controller.setSize(size);
}

if (partStack.hasKey("HIDDEN")) {
controller.setHidden(partStack.getBoolean("HIDDEN"));
}

if (partStack.hasKey("PARTS")) {
JsonArray parts = partStack.get("PARTS");
private void restorePartController(PartStack partStack, WorkBenchPartController controller, JsonObject partStackJSON) {
if (partStackJSON.hasKey("PARTS")) {
JsonArray parts = partStackJSON.get("PARTS");
for (int i = 0; i < parts.length(); i++) {
JsonObject value = parts.get(i);
if (value.hasKey("CLASS")) {
String className = value.getString("CLASS");
Provider<PartPresenter> provider = dynaProvider.getProvider(className);
if (provider != null) {
PartPresenter partPresenter = provider.get();
if (!stack.containsPart(partPresenter)) {
stack.addPart(partPresenter);
if (!partStack.containsPart(partPresenter)) {
partStack.addPart(partPresenter);
}
}
}
}
}

//hide part stack if we cannot restore opened parts
if (stack.getParts().isEmpty()) {
//hide part stack if it has no parts
if (partStack.getParts().isEmpty()) {
controller.setHidden(true);
return;
}

if (partStack.hasKey("ACTIVE_PART")) {
String className = partStack.getString("ACTIVE_PART");
Provider<PartPresenter> provider = dynaProvider.getProvider(className);
if (provider != null) {
activeParts.add(provider.get());
if (partStackJSON.hasKey("HIDDEN") && partStackJSON.getBoolean("HIDDEN")) {
partStack.minimize();
return;
}

if (partStackJSON.hasKey("SIZE")) {
double size = partStackJSON.getNumber("SIZE");

// Size of the part must not be less 100 pixels.
if (size < 100) {
size = 100;
}

controller.setSize(size);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.mockito.Captor;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.vectomatic.dom.svg.ui.SVGResource;

import java.util.List;
Expand All @@ -41,8 +40,6 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -157,17 +154,13 @@ public void partShouldBeAddedWithoutConstraints() {
}

@Test
public void partShouldNotBeAddedWhenItAlreadyExist() {
public void partShouldBeSelectedIfItIsAddedTwice() {
presenter.addPart(partPresenter);
reset(view);

presenter.addPart(partPresenter);

verify(workBenchPartController).setHidden(true);

verify(partButton).unSelect();

verify(view, never()).addTab(partButton, partPresenter);
verify(view).selectTab(partPresenter);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -56,6 +55,7 @@
*/
@RunWith(GwtMockitoTestRunner.class)
public class AbstractPerspectivePersistenceTest {

//constructor mocks
@Mock
private PerspectiveViewImpl view;
Expand Down Expand Up @@ -96,7 +96,6 @@ public class AbstractPerspectivePersistenceTest {
@Mock
private Provider<PartPresenter> partProvider;


private AbstractPerspective perspective;

@Before
Expand Down Expand Up @@ -152,38 +151,51 @@ public void shouldNotStoreEditorPartStack() throws Exception {
@Test
public void shouldRestorePartStackSize() 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("SIZE", 42);

JsonObject parts = Json.createObject();
state.put("PART_STACKS", parts);

JsonObject partStack = Json.createObject();
parts.put("INFORMATION", partStack);

JsonArray partsArray = Json.createArray();
partStack.put("PARTS", partsArray);

JsonObject part = Json.createObject();
partsArray.set(0, part);
part.put("CLASS", "foo.Bar");

partStack.put("SIZE", 42);

// 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).setSize(42d);

}

@Test
public void shouldRestoreHiddenPartStackState() 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("HIDDEN", true);

//PartStackPresenter should not be empty otherwise setHidden() will call twice
final List<PartPresenter> partPresenters = new ArrayList<>();
partPresenters.add(mock(PartPresenter.class));
when(partStackPresenter.getParts()).thenAnswer(new Answer<List<? extends PartPresenter>>() {
public List<? extends PartPresenter> answer(InvocationOnMock invocation) throws Throwable {
return partPresenters;
}
JsonObject parts = Json.createObject();
state.put("PART_STACKS", parts);

});
JsonObject partStack = Json.createObject();
parts.put("INFORMATION", partStack);

partStack.put("HIDDEN", true);

perspective.loadState(state);

verify(workBenchController).setHidden(true);
}

Expand All @@ -210,6 +222,6 @@ public void shouldRestoreOpenedParts() throws Exception {
verify(partProvider).get();

verify(partStackPresenter).addPart(partPresenter);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ public void showDialog(Project project) {
if (isViewClosed) {
workspaceAgent.openPart(this, PartStackType.TOOLING);
isViewClosed = false;
}

PartPresenter activePart = partStack.getActivePart();
if (activePart == null || !activePart.equals(this)) {
} else {
partStack.setActivePart(this);
}
}
Expand Down

0 comments on commit 7692648

Please sign in to comment.