Search in sources :

Example 1 with ProjectExplorerPresenter

use of org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter 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

JsonObject (elemental.json.JsonObject)1 HasDataObject (org.eclipse.che.ide.api.data.HasDataObject)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)1 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 ProjectExplorerPresenter (org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter)1 Path (org.eclipse.che.ide.resource.Path)1