use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class FileStructurePresenter method show.
/**
* Shows the structure of the opened class.
*
* @param editorPartPresenter
* the active editor
*/
public void show(EditorPartPresenter editorPartPresenter) {
loader.show();
view.setTitle(editorPartPresenter.getEditorInput().getFile().getName());
if (!(editorPartPresenter instanceof TextEditor)) {
Log.error(getClass(), "Open Declaration support only TextEditor as editor");
return;
}
activeEditor = ((TextEditor) editorPartPresenter);
cursorOffset = activeEditor.getCursorOffset();
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);
javaNavigationService.getCompilationUnit(project.get().getLocation(), fqn, showInheritedMembers).then(new Operation<CompilationUnit>() {
@Override
public void apply(CompilationUnit unit) throws OperationException {
view.setStructure(unit, showInheritedMembers);
showInheritedMembers = !showInheritedMembers;
loader.hide();
view.show();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Log.error(FileStructurePresenter.class, arg.getMessage());
loader.hide();
}
});
}
}
use of org.eclipse.che.ide.api.resources.Resource 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.Resource in project che by eclipse.
the class ClasspathMacro method expand.
@Override
public Promise<String> expand() {
final Resource[] resources = appContext.getResources();
if (resources == null || resources.length != 1) {
return promises.resolve("");
}
final Resource resource = resources[0];
final Optional<Project> project = resource.getRelatedProject();
if (!JavaUtil.isJavaProject(project.get())) {
return promises.resolve("");
}
final String projectPath = project.get().getLocation().toString();
return classpathContainer.getClasspathEntries(projectPath).then(new Function<List<ClasspathEntryDto>, String>() {
@Override
public String apply(List<ClasspathEntryDto> arg) throws FunctionException {
classpathResolver.resolveClasspathEntries(arg);
Set<String> libs = classpathResolver.getLibs();
StringBuilder classpath = new StringBuilder();
for (String lib : libs) {
classpath.append(lib).append(':');
}
for (ClasspathEntryDto container : classpathResolver.getContainers()) {
if (!JRE_CONTAINER.equals(container.getPath())) {
addLibsFromContainer(container, classpath);
}
}
if (classpath.toString().isEmpty()) {
classpath.append(appContext.getProjectsRoot().toString()).append(projectPath).append(':');
}
return classpath.toString();
}
});
}
use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class SourcepathMacro method expand.
@Override
public Promise<String> expand() {
final Resource[] resources = appContext.getResources();
if (resources == null || resources.length != 1) {
return promises.resolve("");
}
final Resource resource = resources[0];
final Optional<Project> project = resource.getRelatedProject();
if (!JavaUtil.isJavaProject(project.get())) {
return promises.resolve("");
}
final String projectPath = project.get().getLocation().toString();
return classpathContainer.getClasspathEntries(projectPath).then(new Function<List<ClasspathEntryDto>, String>() {
@Override
public String apply(List<ClasspathEntryDto> arg) throws FunctionException {
classpathResolver.resolveClasspathEntries(arg);
Set<String> sources = classpathResolver.getSources();
StringBuilder classpath = new StringBuilder();
for (String source : sources) {
classpath.append(source.substring(projectPath.length() + 1)).append(':');
}
if (classpath.toString().isEmpty()) {
classpath.append(appContext.getProjectsRoot().toString()).append(projectPath);
}
return classpath.toString();
}
});
}
use of org.eclipse.che.ide.api.resources.Resource 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());
}
}
Aggregations