Search in sources :

Example 11 with EditorPartStack

use of org.eclipse.che.ide.api.parts.EditorPartStack in project che by eclipse.

the class OrionEditorPresenter method updateTabReference.

private void updateTabReference(File file, Path oldPath) {
    final PartPresenter activePart = editorMultiPartStackPresenter.getActivePart();
    final EditorPartStack activePartStack = editorMultiPartStackPresenter.getPartStackByPart(activePart);
    if (activePartStack == null) {
        return;
    }
    final EditorTab editorTab = activePartStack.getTabByPath(oldPath);
    if (editorTab != null) {
        editorTab.setFile(file);
    }
}
Also used : EditorTab(org.eclipse.che.ide.api.parts.EditorTab) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) EditorPartStack(org.eclipse.che.ide.api.parts.EditorPartStack)

Example 12 with EditorPartStack

use of org.eclipse.che.ide.api.parts.EditorPartStack in project che by eclipse.

the class EditorMultiPartStackPresenter method addEditorPartStack.

private EditorPartStack addEditorPartStack(final PartPresenter part, final EditorPartStack relativePartStack, final Constraints constraints, double size) {
    final EditorPartStack editorPartStack = editorPartStackFactory.get();
    partStackPresenters.add(editorPartStack);
    view.addPartStack(editorPartStack, relativePartStack, constraints, size);
    if (part != null) {
        editorPartStack.addPart(part);
    }
    return editorPartStack;
}
Also used : EditorPartStack(org.eclipse.che.ide.api.parts.EditorPartStack)

Example 13 with EditorPartStack

use of org.eclipse.che.ide.api.parts.EditorPartStack 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 14 with EditorPartStack

use of org.eclipse.che.ide.api.parts.EditorPartStack 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 15 with EditorPartStack

use of org.eclipse.che.ide.api.parts.EditorPartStack in project che by eclipse.

the class EditorAgentImpl method onSelectionChanged.

@Override
public void onSelectionChanged(SelectionChangedEvent event) {
    final String isLinkedWithEditor = preferencesManager.getValue(LinkWithEditorAction.LINK_WITH_EDITOR);
    if (!parseBoolean(isLinkedWithEditor)) {
        return;
    }
    final Selection<?> selection = event.getSelection();
    if (selection instanceof Selection.NoSelectionProvided) {
        return;
    }
    Resource currentResource = null;
    if (selection == null || selection.getHeadElement() == null || selection.getAllElements().size() > 1) {
        return;
    }
    final Object headObject = selection.getHeadElement();
    if (headObject instanceof HasDataObject) {
        Object data = ((HasDataObject) headObject).getData();
        if (data instanceof Resource) {
            currentResource = (Resource) data;
        }
    } else if (headObject instanceof Resource) {
        currentResource = (Resource) headObject;
    }
    EditorPartStack activePartStack = editorMultiPartStack.getActivePartStack();
    if (currentResource == null || activePartStack == null || activeEditor == null) {
        return;
    }
    final Path locationOfActiveOpenedFile = activeEditor.getEditorInput().getFile().getLocation();
    final Path selectedResourceLocation = currentResource.getLocation();
    if (!(activePart instanceof ProjectExplorerPresenter) && selectedResourceLocation.equals(locationOfActiveOpenedFile)) {
        return;
    }
    PartPresenter partPresenter = activePartStack.getPartByPath(selectedResourceLocation);
    if (partPresenter != null) {
        workspaceAgent.setActivePart(partPresenter, EDITING);
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) HasDataObject(org.eclipse.che.ide.api.data.HasDataObject) Resource(org.eclipse.che.ide.api.resources.Resource) HasDataObject(org.eclipse.che.ide.api.data.HasDataObject) JsonObject(elemental.json.JsonObject) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) EditorPartStack(org.eclipse.che.ide.api.parts.EditorPartStack) ProjectExplorerPresenter(org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter)

Aggregations

EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)16 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)7 JsonObject (elemental.json.JsonObject)3 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)3 OperationException (org.eclipse.che.api.promises.client.OperationException)2 Promise (org.eclipse.che.api.promises.client.Promise)2 HasDataObject (org.eclipse.che.ide.api.data.HasDataObject)2 EditorTab (org.eclipse.che.ide.api.parts.EditorTab)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayOf (elemental.util.ArrayOf)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Operation (org.eclipse.che.api.promises.client.Operation)1 Constraints (org.eclipse.che.ide.api.constraints.Constraints)1 AsyncEditorProvider (org.eclipse.che.ide.api.editor.AsyncEditorProvider)1 EditorProvider (org.eclipse.che.ide.api.editor.EditorProvider)1 FileType (org.eclipse.che.ide.api.filetypes.FileType)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 ProjectExplorerPresenter (org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter)1