Search in sources :

Example 66 with JsonArray

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

the class EditorAgentImpl method storeEditors.

private JsonArray storeEditors(EditorPartStack partStack) {
    JsonArray result = Json.createArray();
    int i = 0;
    List<EditorPartPresenter> parts = partStack.getParts();
    for (EditorPartPresenter part : parts) {
        JsonObject file = Json.createObject();
        file.put("PATH", part.getEditorInput().getFile().getLocation().toString());
        file.put("EDITOR_PROVIDER", openedEditorsToProviders.get(part));
        if (part instanceof TextEditor) {
            file.put("CURSOR_OFFSET", ((TextEditor) part).getCursorOffset());
            file.put("TOP_VISIBLE_LINE", ((TextEditor) part).getTopVisibleLine());
        }
        if (partStack.getActivePart().equals(part)) {
            file.put("ACTIVE", true);
        }
        result.set(i++, file);
    }
    return result;
}
Also used : JsonArray(elemental.json.JsonArray) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) JsonObject(elemental.json.JsonObject) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 67 with JsonArray

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

the class EditorAgentImpl method restore.

private List<Promise<Void>> restore(JsonObject files, EditorPartStack editorPartStack, Map<EditorPartPresenter, EditorPartStack> activeEditors) {
    if (files.hasKey("FILES")) {
        //plain
        JsonArray filesArray = files.getArray("FILES");
        List<Promise<Void>> promises = new ArrayList<>();
        for (int i = 0; i < filesArray.length(); i++) {
            JsonObject file = filesArray.getObject(i);
            Promise<Void> openFile = openFile(file, editorPartStack, activeEditors);
            promises.add(openFile);
        }
        return promises;
    } else {
        //split
        return restoreSplit(files, editorPartStack, activeEditors);
    }
}
Also used : JsonArray(elemental.json.JsonArray) Promise(org.eclipse.che.api.promises.client.Promise) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) JsonObject(elemental.json.JsonObject)

Example 68 with JsonArray

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

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

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