Search in sources :

Example 61 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorAgentImpl method doOpen.

private void doOpen(final VirtualFile file, final OpenEditorCallback callback, final Constraints constraints) {
    EditorPartStack activePartStack = editorMultiPartStack.getActivePartStack();
    if (constraints == null && activePartStack != null) {
        PartPresenter partPresenter = activePartStack.getPartByPath(file.getLocation());
        if (partPresenter != null) {
            workspaceAgent.setActivePart(partPresenter, EDITING);
            callback.onEditorActivated((EditorPartPresenter) partPresenter);
            return;
        }
    }
    final FileType fileType = fileTypeRegistry.getFileTypeByFile(file);
    final EditorProvider editorProvider = editorRegistry.getEditor(fileType);
    if (editorProvider instanceof AsyncEditorProvider) {
        AsyncEditorProvider provider = (AsyncEditorProvider) editorProvider;
        Promise<EditorPartPresenter> promise = provider.createEditor(file);
        if (promise != null) {
            promise.then(new Operation<EditorPartPresenter>() {

                @Override
                public void apply(EditorPartPresenter arg) throws OperationException {
                    initEditor(file, callback, fileType, arg, constraints, editorProvider);
                }
            });
            return;
        }
    }
    final EditorPartPresenter editor = editorProvider.getEditor();
    initEditor(file, callback, fileType, editor, constraints, editorProvider);
}
Also used : FileType(org.eclipse.che.ide.api.filetypes.FileType) AsyncEditorProvider(org.eclipse.che.ide.api.editor.AsyncEditorProvider) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) EditorPartStack(org.eclipse.che.ide.api.parts.EditorPartStack) EditorProvider(org.eclipse.che.ide.api.editor.EditorProvider) AsyncEditorProvider(org.eclipse.che.ide.api.editor.AsyncEditorProvider) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 62 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorAgentImpl method loadState.

@Override
@SuppressWarnings("unchecked")
public void loadState(@NotNull final JsonObject state) {
    if (state.hasKey("FILES")) {
        JsonObject files = state.getObject("FILES");
        EditorPartStack partStack = editorMultiPartStack.createRootPartStack();
        final Map<EditorPartPresenter, EditorPartStack> activeEditors = new HashMap<>();
        List<Promise<Void>> restore = restore(files, partStack, activeEditors);
        Promise<ArrayOf<?>> promise = promiseProvider.all2(restore.toArray(new Promise[restore.size()]));
        promise.then(new Operation() {

            @Override
            public void apply(Object arg) throws OperationException {
                String activeFile = "";
                if (state.hasKey("ACTIVE_EDITOR")) {
                    activeFile = state.getString("ACTIVE_EDITOR");
                }
                EditorPartPresenter activeEditorPart = null;
                for (Map.Entry<EditorPartPresenter, EditorPartStack> entry : activeEditors.entrySet()) {
                    entry.getValue().setActivePart(entry.getKey());
                    if (activeFile.equals(entry.getKey().getEditorInput().getFile().getLocation().toString())) {
                        activeEditorPart = entry.getKey();
                    }
                }
                workspaceAgent.setActivePart(activeEditorPart);
            }
        });
    }
}
Also used : ArrayOf(elemental.util.ArrayOf) HashMap(java.util.HashMap) JsonObject(elemental.json.JsonObject) Operation(org.eclipse.che.api.promises.client.Operation) Promise(org.eclipse.che.api.promises.client.Promise) HasDataObject(org.eclipse.che.ide.api.data.HasDataObject) JsonObject(elemental.json.JsonObject) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) EditorPartStack(org.eclipse.che.ide.api.parts.EditorPartStack) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 63 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorAgentImpl method finalizeInit.

private void finalizeInit(final VirtualFile file, final OpenEditorCallback callback, final EditorPartPresenter editor, EditorProvider editorProvider) {
    openedEditors.add(editor);
    openedEditorsToProviders.put(editor, editorProvider.getId());
    workspaceAgent.setActivePart(editor);
    editor.addPropertyListener(new PropertyListener() {

        @Override
        public void propertyChanged(PartPresenter source, int propId) {
            if (propId == EditorPartPresenter.PROP_INPUT) {
                if (editor instanceof HasReadOnlyProperty) {
                    ((HasReadOnlyProperty) editor).setReadOnly(file.isReadOnly());
                }
                if (editor instanceof TextEditor) {
                    editorContentSynchronizerProvider.get().trackEditor(editor);
                }
                callback.onEditorOpened(editor);
                eventBus.fireEvent(new EditorOpenedEvent(file, editor));
            }
        }
    });
}
Also used : TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorOpenedEvent(org.eclipse.che.ide.api.editor.EditorOpenedEvent) PropertyListener(org.eclipse.che.ide.api.parts.PropertyListener) HasReadOnlyProperty(org.eclipse.che.ide.api.editor.texteditor.HasReadOnlyProperty) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 64 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter 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 65 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorAgentImpl method restoreCreateEditor.

private void restoreCreateEditor(final File resourceFile, JsonObject file, final EditorPartStack editorPartStack, final AsyncCallback<Void> openCallback, final Map<EditorPartPresenter, EditorPartStack> activeEditors) {
    String providerId = file.getString("EDITOR_PROVIDER");
    final OpenEditorCallback callback;
    if (file.hasKey("CURSOR_OFFSET") && file.hasKey("TOP_VISIBLE_LINE")) {
        final int cursorOffset = (int) file.getNumber("CURSOR_OFFSET");
        final int topLine = (int) file.getNumber("TOP_VISIBLE_LINE");
        callback = new RestoreStateEditorCallBack(cursorOffset, topLine);
    } else {
        callback = new OpenEditorCallbackImpl();
    }
    final boolean active = file.hasKey("ACTIVE") && file.getBoolean("ACTIVE");
    final EditorProvider provider = editorRegistry.findEditorProviderById(providerId);
    if (provider instanceof AsyncEditorProvider) {
        ((AsyncEditorProvider) provider).createEditor(resourceFile).then(new Operation<EditorPartPresenter>() {

            @Override
            public void apply(EditorPartPresenter arg) throws OperationException {
                restoreInitEditor(resourceFile, callback, fileTypeRegistry.getFileTypeByFile(resourceFile), arg, provider, editorPartStack);
                if (active) {
                    activeEditors.put(arg, editorPartStack);
                }
            }
        });
    } else {
        EditorPartPresenter editor = provider.getEditor();
        restoreInitEditor(resourceFile, callback, fileTypeRegistry.getFileTypeByFile(resourceFile), editor, provider, editorPartStack);
        if (active) {
            activeEditors.put(editor, editorPartStack);
        }
    }
    openCallback.onSuccess(null);
}
Also used : OpenEditorCallbackImpl(org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl) AsyncEditorProvider(org.eclipse.che.ide.api.editor.AsyncEditorProvider) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) EditorProvider(org.eclipse.che.ide.api.editor.EditorProvider) AsyncEditorProvider(org.eclipse.che.ide.api.editor.AsyncEditorProvider) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)79 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)21 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)19 OperationException (org.eclipse.che.api.promises.client.OperationException)13 Project (org.eclipse.che.ide.api.resources.Project)13 Resource (org.eclipse.che.ide.api.resources.Resource)11 Test (org.junit.Test)10 Operation (org.eclipse.che.api.promises.client.Operation)9 Path (org.eclipse.che.ide.resource.Path)8 File (org.eclipse.che.ide.api.resources.File)7 Scheduler (com.google.gwt.core.client.Scheduler)6 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)6 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)6 Optional (com.google.common.base.Optional)5 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)5 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)5 HandlesTextOperations (org.eclipse.che.ide.api.editor.texteditor.HandlesTextOperations)4 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 JsonObject (elemental.json.JsonObject)3