Search in sources :

Example 6 with OpenEditorCallbackImpl

use of org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl 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)6 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)6 OperationException (org.eclipse.che.api.promises.client.OperationException)5 Optional (com.google.common.base.Optional)4 Scheduler (com.google.gwt.core.client.Scheduler)4 Operation (org.eclipse.che.api.promises.client.Operation)4 File (org.eclipse.che.ide.api.resources.File)4 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 Project (org.eclipse.che.ide.api.resources.Project)3 Resource (org.eclipse.che.ide.api.resources.Resource)3 SyntheticFile (org.eclipse.che.ide.api.resources.SyntheticFile)3 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)3 AsyncEditorProvider (org.eclipse.che.ide.api.editor.AsyncEditorProvider)1 EditorProvider (org.eclipse.che.ide.api.editor.EditorProvider)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1 FileType (org.eclipse.che.ide.api.filetypes.FileType)1 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)1 PropertyListener (org.eclipse.che.ide.api.parts.PropertyListener)1 ClassFile (org.eclipse.che.ide.ext.java.shared.dto.model.ClassFile)1