use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.
the class EditorContentSynchronizerImplTest method shouldUpdatePathForGroupWhenFileLocationIsChanged.
@Test
public void shouldUpdatePathForGroupWhenFileLocationIsChanged() {
Resource resource = mock(Resource.class);
ResourceDelta delta = mock(ResourceDelta.class);
ResourceChangedEvent resourceChangedEvent = new ResourceChangedEvent(delta);
Path fromPath = new Path(FILE_PATH);
Path toPath = new Path("testProject/src/main/java/org/eclipse/che/examples/changedFile");
EditorPartPresenter openedEditor1 = mock(EditorPartPresenter.class);
when(openedEditor1.getEditorInput()).thenReturn(editorInput);
when(delta.getKind()).thenReturn(ResourceDelta.ADDED);
when(delta.getFlags()).thenReturn(5632);
when(delta.getFromPath()).thenReturn(fromPath);
when(delta.getToPath()).thenReturn(toPath);
when(delta.getResource()).thenReturn(resource);
when(resource.isFile()).thenReturn(true);
editorContentSynchronizer.trackEditor(openedEditor1);
editorContentSynchronizer.onResourceChanged(resourceChangedEvent);
final EditorGroupSynchronization oldGroup = editorContentSynchronizer.editorGroups.get(fromPath);
final EditorGroupSynchronization newGroup = editorContentSynchronizer.editorGroups.get(toPath);
assertNull(oldGroup);
assertNotNull(newGroup);
}
use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.
the class JavaDebuggerFileHandler method openFile.
@Override
public void openFile(Location location, AsyncCallback<VirtualFile> callback) {
VirtualFile activeFile = null;
String activePath = null;
final EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
if (activeEditor != null) {
activeFile = editorAgent.getActiveEditor().getEditorInput().getFile();
activePath = activeFile.getLocation().toString();
}
if (activePath != null && !activePath.equals(location.getTarget()) && !activePath.equals(location.getResourcePath())) {
if (location.isExternalResource()) {
openExternalResource(location, callback);
} else {
doOpenFile(location, callback);
}
} else {
scrollEditorToExecutionPoint((TextEditor) activeEditor, location.getLineNumber());
callback.onSuccess(activeFile);
}
}
use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.
the class FileStructurePresenter method actionPerformed.
/** {@inheritDoc} */
@Override
public void actionPerformed(final Member member) {
if (member.isBinary()) {
final Resource resource = context.getResource();
if (resource == null) {
return;
}
final Optional<Project> project = resource.getRelatedProject();
javaNavigationService.getEntry(project.get().getLocation(), member.getLibId(), member.getRootPath()).then(new Operation<JarEntry>() {
@Override
public void apply(final JarEntry entry) throws OperationException {
javaNavigationService.getContent(project.get().getLocation(), member.getLibId(), Path.valueOf(entry.getPath())).then(new Operation<ClassContent>() {
@Override
public void apply(ClassContent content) throws OperationException {
final String clazz = entry.getName().substring(0, entry.getName().indexOf('.'));
final VirtualFile file = new SyntheticFile(entry.getName(), clazz, content.getContent());
editorAgent.openEditor(file, new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursor(editor, member.getFileRegion().getOffset());
}
});
}
});
}
});
} else {
context.getWorkspaceRoot().getFile(member.getRootPath()).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
editorAgent.openEditor(file.get(), new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursor(editor, member.getFileRegion().getOffset());
}
});
}
}
});
}
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
setCursorPosition(member.getFileRegion());
}
});
showInheritedMembers = false;
}
use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.
the class QuickDocPresenter method showDocumentation.
@Override
public void showDocumentation() {
EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
if (activeEditor == null) {
return;
}
if (!(activeEditor instanceof TextEditor)) {
Log.error(getClass(), "Quick Document support only TextEditor as editor");
return;
}
TextEditor editor = ((TextEditor) activeEditor);
int offset = editor.getCursorOffset();
final PositionConverter.PixelCoordinates coordinates = editor.getPositionConverter().offsetToPixel(offset);
final Resource resource = appContext.getResource();
if (resource != null) {
final Optional<Project> project = resource.getRelatedProject();
final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
if (!srcFolder.isPresent()) {
return;
}
final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), resource);
final String docUrl = appContext.getDevMachine().getWsAgentBaseUrl() + "/java/javadoc/find?fqn=" + fqn + "&projectpath=" + project.get().getLocation() + "&offset=" + offset;
view.show(agentURLDecorator.modify(docUrl), coordinates.getX(), coordinates.getY());
}
}
use of org.eclipse.che.ide.api.editor.EditorPartPresenter 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);
}
Aggregations