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);
}
}
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()]);
}
Aggregations