use of org.eclipse.che.ide.api.resources.VirtualFile 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.resources.VirtualFile in project che by eclipse.
the class OpenImplementationPresenter method show.
/**
* Shows the implementations of the selected element.
*
* @param editorPartPresenter
* the active editor
*/
public void show(final EditorPartPresenter editorPartPresenter) {
if (!(editorPartPresenter instanceof TextEditor)) {
Log.error(getClass(), "Open Declaration support only TextEditor as editor");
return;
}
activeEditor = ((TextEditor) editorPartPresenter);
final VirtualFile file = activeEditor.getEditorInput().getFile();
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
final Optional<Resource> srcFolder = ((Resource) file).getParentWithMarker(SourceFolderMarker.ID);
if (!srcFolder.isPresent()) {
return;
}
final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);
service.getImplementations(project.get().getLocation(), fqn, activeEditor.getCursorOffset()).then(new Operation<ImplementationsDescriptorDTO>() {
@Override
public void apply(ImplementationsDescriptorDTO impls) throws OperationException {
int overridingSize = impls.getImplementations().size();
String title = locale.openImplementationWindowTitle(impls.getMemberName(), overridingSize);
NoImplementationWidget noImplementationWidget = new NoImplementationWidget(popupResources, javaResources, locale, OpenImplementationPresenter.this, title);
if (overridingSize == 1) {
actionPerformed(impls.getImplementations().get(0));
} else if (overridingSize > 1) {
openOneImplementation(impls, noImplementationWidget, (TextEditor) editorPartPresenter);
} else if (!isNullOrEmpty(impls.getMemberName()) && overridingSize == 0) {
showNoImplementations(noImplementationWidget, (TextEditor) editorPartPresenter);
}
}
});
}
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class JavaEditorAction method updateProjectAction.
@Override
protected void updateProjectAction(ActionEvent e) {
if (editorAgent.getActiveEditor() != null) {
EditorInput input = editorAgent.getActiveEditor().getEditorInput();
VirtualFile file = input.getFile();
final String fileExtension = fileTypeRegistry.getFileTypeByFile(file).getExtension();
if ("java".equals(fileExtension) || "class".equals(fileExtension)) {
e.getPresentation().setEnabledAndVisible(true);
return;
}
}
e.getPresentation().setEnabledAndVisible(false);
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class JavaCodeAssistProcessor method computeCompletionProposals.
@Override
public void computeCompletionProposals(final TextEditor textEditor, final int offset, final boolean triggered, final CodeAssistCallback callback) {
if (errorMessage != null) {
return;
}
final VirtualFile file = editor.getEditorInput().getFile();
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
Unmarshallable<Proposals> unmarshaller = unmarshallerFactory.newUnmarshaller(Proposals.class);
client.computeProposals(project.get().getLocation().toString(), resolveFQN(file), offset, textEditor.getDocument().getContents(), new AsyncRequestCallback<Proposals>(unmarshaller) {
@Override
protected void onSuccess(Proposals proposals) {
showProposals(callback, proposals);
}
@Override
protected void onFailure(Throwable throwable) {
Log.error(JavaCodeAssistProcessor.class, throwable);
}
});
}
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class JavaQuickAssistProcessor method setupProposals.
private void setupProposals(final CodeAssistCallback callback, final TextEditor textEditor, final int offset, final List<Problem> annotations) {
final VirtualFile file = textEditor.getEditorInput().getFile();
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
Unmarshallable<Proposals> unmarshaller = unmarshallerFactory.newUnmarshaller(Proposals.class);
client.computeAssistProposals(project.get().getLocation().toString(), resolveFQN(file), offset, annotations, new AsyncRequestCallback<Proposals>(unmarshaller) {
@Override
protected void onSuccess(Proposals proposals) {
showProposals(callback, proposals, textEditor);
}
@Override
protected void onFailure(Throwable throwable) {
Log.error(JavaCodeAssistProcessor.class, throwable);
}
});
}
}
Aggregations