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