use of org.eclipse.che.ide.api.resources.Project 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.Project 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.Project 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.resources.Project 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.Project in project che by eclipse.
the class MovePresenter method createMoveDto.
private CreateMoveRefactoring createMoveDto() {
List<ElementToMove> elements = new ArrayList<>();
Project project = null;
for (Resource resource : refactorInfo.getResources()) {
ElementToMove element = dtoFactory.createDto(ElementToMove.class);
if (resource instanceof Container) {
element.setPath(resource.getLocation().toString());
element.setPack(true);
} else {
element.setPath(JavaUtil.resolveFQN(resource));
element.setPack(false);
}
elements.add(element);
if (project == null) {
project = resource.getRelatedProject().get();
}
}
CreateMoveRefactoring moveRefactoring = dtoFactory.createDto(CreateMoveRefactoring.class);
moveRefactoring.setElements(elements);
if (project != null) {
moveRefactoring.setProjectPath(project.getLocation().toString());
}
return moveRefactoring;
}
Aggregations