Search in sources :

Example 1 with HasDataObject

use of org.eclipse.che.ide.api.data.HasDataObject 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)

Example 2 with HasDataObject

use of org.eclipse.che.ide.api.data.HasDataObject in project che by eclipse.

the class AppContextImpl method onSelectionChanged.

@Override
public void onSelectionChanged(SelectionChangedEvent event) {
    final Selection<?> selection = event.getSelection();
    if (selection instanceof Selection.NoSelectionProvided) {
        return;
    }
    currentResource = null;
    currentResources = null;
    if (selection == null || selection.getHeadElement() == null) {
        return;
    }
    final Object headObject = selection.getHeadElement();
    final List<?> allObjects = selection.getAllElements();
    if (headObject instanceof HasDataObject) {
        Object data = ((HasDataObject) headObject).getData();
        if (data instanceof Resource) {
            currentResource = (Resource) data;
        }
    } else if (headObject instanceof Resource) {
        currentResource = (Resource) headObject;
    }
    Set<Resource> resources = Sets.newHashSet();
    for (Object object : allObjects) {
        if (object instanceof HasDataObject) {
            Object data = ((HasDataObject) object).getData();
            if (data instanceof Resource) {
                resources.add((Resource) data);
            }
        } else if (object instanceof Resource) {
            resources.add((Resource) object);
        }
    }
    currentResources = resources.toArray(new Resource[resources.size()]);
}
Also used : HasDataObject(org.eclipse.che.ide.api.data.HasDataObject) Resource(org.eclipse.che.ide.api.resources.Resource) HasDataObject(org.eclipse.che.ide.api.data.HasDataObject)

Aggregations

HasDataObject (org.eclipse.che.ide.api.data.HasDataObject)2 Resource (org.eclipse.che.ide.api.resources.Resource)2 JsonObject (elemental.json.JsonObject)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 ProjectExplorerPresenter (org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter)1 Path (org.eclipse.che.ide.resource.Path)1