Search in sources :

Example 1 with JsonArray

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

the class ProjectExplorerStateComponent method loadState.

@Override
public void loadState(@NotNull JsonObject state) {
    if (state.hasKey(SHOW_HIDDEN_FILES)) {
        projectExplorer.showHiddenFiles(state.getBoolean(SHOW_HIDDEN_FILES));
    }
    JsonArray paths = state.hasKey(PATH_PARAM_ID) ? state.getArray(PATH_PARAM_ID) : Json.createArray();
    if (paths.length() == 0) {
        return;
    }
    Promise<Node> revealPromise = null;
    final MessageLoader loader = loaderFactory.newLoader("Restoring project structure...");
    loader.show();
    for (int i = 0; i < paths.length(); i++) {
        final String path = paths.getString(i);
        if (revealPromise == null) {
            revealPromise = revealer.reveal(Path.valueOf(path), false).thenPromise(new Function<Node, Promise<Node>>() {

                @Override
                public Promise<Node> apply(Node node) throws FunctionException {
                    if (node != null) {
                        projectExplorer.getTree().setExpanded(node, true, false);
                    }
                    return revealer.reveal(Path.valueOf(path), false);
                }
            });
            continue;
        }
        revealPromise.thenPromise(new Function<Node, Promise<Node>>() {

            @Override
            public Promise<Node> apply(Node node) throws FunctionException {
                if (node != null) {
                    projectExplorer.getTree().setExpanded(node, true, false);
                }
                return revealer.reveal(Path.valueOf(path), false);
            }
        }).catchError(new Function<PromiseError, Node>() {

            @Override
            public Node apply(PromiseError error) throws FunctionException {
                Log.info(getClass(), error.getMessage());
                return null;
            }
        });
    }
    if (revealPromise != null) {
        revealPromise.then(new Operation<Node>() {

            @Override
            public void apply(Node node) throws OperationException {
                loader.hide();
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                loader.hide();
            }
        });
    }
}
Also used : Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) JsonArray(elemental.json.JsonArray) MessageLoader(org.eclipse.che.ide.ui.loaders.request.MessageLoader)

Example 2 with JsonArray

use of elemental.json.JsonArray 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 3 with JsonArray

use of elemental.json.JsonArray 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 4 with JsonArray

use of elemental.json.JsonArray 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 5 with JsonArray

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

the class JsonRpcListTest method shouldToJsonArrayCreatedDoubleArray.

@Test
public void shouldToJsonArrayCreatedDoubleArray() throws Exception {
    JsonArray expected = jsonFactory.createArray();
    expected.set(0, 0D);
    JsonRpcList jsonRpcList = new JsonRpcList(singletonList(0D), jsonFactory, dtoFactory);
    JsonArray actual = jsonRpcList.toJsonArray();
    assertTrue(expected.jsEquals(actual));
}
Also used : JsonArray(elemental.json.JsonArray) Test(org.junit.Test)

Aggregations

JsonArray (elemental.json.JsonArray)69 Test (org.junit.Test)62 JsonValue (elemental.json.JsonValue)23 JsonString (elemental.json.JsonString)19 JsonObject (elemental.json.JsonObject)14 Matchers.anyString (org.mockito.Matchers.anyString)10 JsonNumber (elemental.json.JsonNumber)5 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Node (org.eclipse.che.ide.api.data.tree.Node)2 ResourceNode (org.eclipse.che.ide.resources.tree.ResourceNode)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Promise (org.eclipse.che.api.promises.client.Promise)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1 Path (org.eclipse.che.ide.resource.Path)1 MessageLoader (org.eclipse.che.ide.ui.loaders.request.MessageLoader)1 Ignore (org.junit.Ignore)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1