Search in sources :

Example 11 with JsonObject

use of elemental.json.JsonObject in project che by eclipse.

the class AbstractPerspective method getPartStackState.

private JsonObject getPartStackState(PartStack partStack, WorkBenchPartController partController) {
    JsonObject state = Json.createObject();
    state.put("SIZE", partController.getSize());
    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;
        for (PartPresenter entry : partStack.getParts()) {
            JsonObject presenterState = Json.createObject();
            presenterState.put("CLASS", entry.getClass().getName());
            parts.set(i++, presenterState);
        }
    }
    return state;
}
Also used : JsonArray(elemental.json.JsonArray) JsonObject(elemental.json.JsonObject) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter)

Example 12 with JsonObject

use of elemental.json.JsonObject in project che by eclipse.

the class AbstractPerspective method restorePartController.

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 (!partStack.containsPart(partPresenter)) {
                        partStack.addPart(partPresenter);
                    }
                }
            }
        }
    }
    //hide part stack if it has no parts
    if (partStack.getParts().isEmpty()) {
        controller.setHidden(true);
        return;
    }
    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 < MIN_PART_SIZE) {
            size = DEFAULT_PART_SIZE;
        }
        controller.setSize(size);
    }
}
Also used : JsonArray(elemental.json.JsonArray) JsonObject(elemental.json.JsonObject) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter)

Example 13 with JsonObject

use of elemental.json.JsonObject in project che by eclipse.

the class AbstractPerspectivePersistenceTest method shouldRestoreHiddenPartStackState.

@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);
    perspective.loadState(state);
    verify(workBenchController).setHidden(true);
}
Also used : JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 14 with JsonObject

use of elemental.json.JsonObject in project che by eclipse.

the class AbstractPerspectivePersistenceTest method shouldRestorePartStackSize.

@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);
    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).setSize(142d);
}
Also used : JsonArray(elemental.json.JsonArray) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) JsonObject(elemental.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) Test(org.junit.Test)

Example 15 with JsonObject

use of elemental.json.JsonObject in project che by eclipse.

the class AbstractPerspectivePersistenceTest method shouldStoreActivePart.

@Test
public void shouldStoreActivePart() throws Exception {
    JsonObject state = perspective.getState();
    assertThat(state).isNotNull();
    String activePart = state.getString("ACTIVE_PART");
    assertThat(activePart).isNotNull().isNotEmpty();
}
Also used : JsonObject(elemental.json.JsonObject) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

JsonObject (elemental.json.JsonObject)70 Test (org.junit.Test)49 JsonValue (elemental.json.JsonValue)19 JsonArray (elemental.json.JsonArray)14 JsonString (elemental.json.JsonString)5 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)5 ArrayList (java.util.ArrayList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Promise (org.eclipse.che.api.promises.client.Promise)3 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 JsonException (elemental.json.JsonException)2 List (java.util.List)2 Map (java.util.Map)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 StateComponent (org.eclipse.che.ide.api.component.StateComponent)2 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)2 Perspective (org.eclipse.che.ide.api.parts.Perspective)2 Before (org.junit.Before)2 ArrayOf (elemental.util.ArrayOf)1