Search in sources :

Example 36 with JsonObject

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

the class ProjectExplorerStateComponent method getState.

@Override
public JsonObject getState() {
    final List<Path> paths = new ArrayList<>();
    outer: for (Node node : projectExplorer.getTree().getNodeStorage().getAll()) {
        if (projectExplorer.getTree().isExpanded(node) && node instanceof ResourceNode) {
            final List<Node> childrenToStore = projectExplorer.getTree().getNodeStorage().getChildren(node);
            for (Node children : childrenToStore) {
                if (children instanceof ResourceNode) {
                    paths.add(((ResourceNode) children).getData().getLocation());
                    continue outer;
                }
            }
        }
    }
    JsonObject state = Json.createObject();
    JsonArray array = Json.createArray();
    state.put(PATH_PARAM_ID, array);
    int i = 0;
    for (Path path : paths) {
        array.set(i++, path.toString());
    }
    state.put(SHOW_HIDDEN_FILES, projectExplorer.isShowHiddenFiles());
    return state;
}
Also used : Path(org.eclipse.che.ide.resource.Path) JsonArray(elemental.json.JsonArray) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) ArrayList(java.util.ArrayList) JsonObject(elemental.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Example 37 with JsonObject

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

the class AbstractPerspectivePersistenceTest method shouldStoreParts.

@Test
public void shouldStoreParts() throws Exception {
    JsonObject state = perspective.getState();
    JsonObject partStacks = state.getObject("PART_STACKS");
    assertThat(partStacks).isNotNull();
}
Also used : JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 38 with JsonObject

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

the class AbstractPerspectivePersistenceTest method shouldRestoreOpenedParts.

@Test
//TODO
@Ignore
public void shouldRestoreOpenedParts() 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");
    when(dynaProvider.<PartPresenter>getProvider(anyString())).thenReturn(partProvider);
    when(partProvider.get()).thenReturn(partPresenter);
    perspective.loadState(state);
    verify(dynaProvider).getProvider("foo.Bar");
    verify(partProvider).get();
    verify(partStackPresenter).addPart(partPresenter);
}
Also used : JsonArray(elemental.json.JsonArray) JsonObject(elemental.json.JsonObject) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 39 with JsonObject

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

the class JsonRpcEntityQualifier method qualify.

public JsonRpcEntityType qualify(String message) {
    checkNotNull(message, "Message must not be null");
    checkArgument(!message.isEmpty(), "Message must not be empty");
    Log.debug(getClass(), "Qualifying message: " + message);
    JsonObject jsonObject = jsonFactory.parse(message);
    List<String> keys = asList(jsonObject.keys());
    Log.debug(getClass(), "Json keys: " + keys);
    if (keys.contains("method")) {
        Log.debug(getClass(), "Qualified to request");
        return JsonRpcEntityType.REQUEST;
    } else if (keys.contains("error") != keys.contains("result")) {
        Log.debug(getClass(), "Qualified to response");
        return JsonRpcEntityType.RESPONSE;
    } else {
        Log.debug(getClass(), "Qualified to undefined");
        return JsonRpcEntityType.UNDEFINED;
    }
}
Also used : JsonObject(elemental.json.JsonObject)

Example 40 with JsonObject

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

the class JsonRpcError method toJsonObject.

public JsonObject toJsonObject() {
    JsonObject error = jsonFactory.createObject();
    error.put("code", code);
    error.put("message", message);
    return error;
}
Also used : JsonObject(elemental.json.JsonObject)

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