Search in sources :

Example 11 with PartPresenter

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

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

the class FileWatcher method editorOpened.

public void editorOpened(final EditorPartPresenter editor) {
    final PropertyListener propertyListener = new PropertyListener() {

        @Override
        public void propertyChanged(PartPresenter source, int propId) {
            if (propId == EditorPartPresenter.PROP_DIRTY) {
                if (!editor.isDirty()) {
                    reparseAllOpenedFiles();
                    //remove just saved editor
                    editor2reconcile.remove(editor);
                }
            }
        }
    };
    editor.addPropertyListener(propertyListener);
}
Also used : PropertyListener(org.eclipse.che.ide.api.parts.PropertyListener) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 13 with PartPresenter

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

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

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

PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)16 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)9 JsonObject (elemental.json.JsonObject)6 JsonArray (elemental.json.JsonArray)4 PropertyListener (org.eclipse.che.ide.api.parts.PropertyListener)4 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)3 FileType (org.eclipse.che.ide.api.filetypes.FileType)2 EditorTab (org.eclipse.che.ide.api.parts.EditorTab)2 Path (org.eclipse.che.ide.resource.Path)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 HasDataObject (org.eclipse.che.ide.api.data.HasDataObject)1 AbstractEditorPresenter (org.eclipse.che.ide.api.editor.AbstractEditorPresenter)1 AsyncEditorProvider (org.eclipse.che.ide.api.editor.AsyncEditorProvider)1 EditorOpenedEvent (org.eclipse.che.ide.api.editor.EditorOpenedEvent)1 EditorProvider (org.eclipse.che.ide.api.editor.EditorProvider)1 EditorWithErrors (org.eclipse.che.ide.api.editor.EditorWithErrors)1 EditorState (org.eclipse.che.ide.api.editor.EditorWithErrors.EditorState)1