use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class FindUsagesPresenter method findUsages.
public void findUsages(TextEditor activeEditor) {
final VirtualFile virtualFile = activeEditor.getEditorInput().getFile();
if (virtualFile instanceof Resource) {
final Project project = ((Resource) virtualFile).getRelatedProject().get();
if (project == null) {
return;
}
final Optional<Resource> srcFolder = ((Resource) virtualFile).getParentWithMarker(SourceFolderMarker.ID);
if (!srcFolder.isPresent()) {
return;
}
final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) virtualFile);
String projectPath = project.getLocation().toString();
FindUsagesRequest request = dtoFactory.createDto(FindUsagesRequest.class);
request.setFQN(fqn);
request.setProjectPath(projectPath);
request.setOffset(activeEditor.getCursorOffset());
Promise<FindUsagesResponse> promise = searchService.findUsages(request);
promise.then(new Operation<FindUsagesResponse>() {
@Override
public void apply(FindUsagesResponse arg) throws OperationException {
handleResponse(arg);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Throwable cause = arg.getCause();
if (cause instanceof ServerException) {
handleError(((ServerException) cause).getHTTPStatus(), cause.getMessage());
return;
}
//in case websocket request
if (cause instanceof org.eclipse.che.ide.websocket.rest.exceptions.ServerException) {
handleError(((org.eclipse.che.ide.websocket.rest.exceptions.ServerException) cause).getHTTPStatus(), cause.getMessage());
return;
}
Log.error(getClass(), arg);
manager.notify(localizationConstant.failedToProcessFindUsage(), arg.getMessage(), FAIL, FLOAT_MODE);
}
});
}
}
use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class JavaRefactoringRename method createRenameRefactoringDto.
@NotNull
private CreateRenameRefactoring createRenameRefactoringDto(TextEditor editor, boolean isActiveLinkedMode) {
CreateRenameRefactoring dto = dtoFactory.createDto(CreateRenameRefactoring.class);
dto.setOffset(editor.getCursorOffset());
dto.setRefactorLightweight(isActiveLinkedMode);
final VirtualFile file = editor.getEditorInput().getFile();
dto.setPath(JavaUtil.resolveFQN(file));
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
dto.setProjectPath(project.get().getLocation().toString());
}
dto.setType(JAVA_ELEMENT);
return dto;
}
use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class RenameRefactoringAction method updateInPerspective.
@Override
public void updateInPerspective(ActionEvent event) {
event.getPresentation().setVisible(true);
if (editorInFocus) {
final EditorPartPresenter editorPart = editorAgent.getActiveEditor();
if (editorPart == null || !(editorPart instanceof TextEditor)) {
event.getPresentation().setEnabled(false);
return;
}
final VirtualFile file = editorPart.getEditorInput().getFile();
if (file instanceof File) {
final Optional<Project> project = ((File) file).getRelatedProject();
if (!project.isPresent()) {
event.getPresentation().setEnabled(false);
return;
}
event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && isJavaFile(file));
} else {
event.getPresentation().setEnabled(isJavaFile(file));
}
} else {
final Resource[] resources = appContext.getResources();
if (resources == null || resources.length > 1) {
event.getPresentation().setEnabled(false);
return;
}
final Resource resource = resources[0];
final Optional<Project> project = resource.getRelatedProject();
if (!project.isPresent()) {
event.getPresentation().setEnabled(false);
return;
}
final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
if (resource.getResourceType() == FILE) {
event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent() && isJavaFile((File) resource));
} else if (resource instanceof Container) {
event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent());
}
}
}
use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class RenameRefactoringAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent event) {
if (editorInFocus) {
final EditorPartPresenter editorPart = editorAgent.getActiveEditor();
if (editorPart == null || !(editorPart instanceof TextEditor)) {
return;
}
javaRefactoringRename.refactor((TextEditor) editorPart);
} else {
final Resource[] resources = appContext.getResources();
if (resources == null || resources.length > 1) {
return;
}
final Resource resource = resources[0];
final Optional<Project> project = resource.getRelatedProject();
if (!JavaUtil.isJavaProject(project.get())) {
return;
}
final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
if (!srcFolder.isPresent() || resource.getLocation().equals(srcFolder.get().getLocation())) {
return;
}
RefactoredItemType renamedItemType = null;
if (resource.getResourceType() == FILE && isJavaFile((File) resource)) {
renamedItemType = COMPILATION_UNIT;
} else if (resource instanceof Container) {
renamedItemType = PACKAGE;
}
if (renamedItemType == null) {
return;
}
renamePresenter.show(RefactorInfo.of(renamedItemType, resources));
}
}
use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class ParametersHintsPresenter method show.
/**
* The method gets method parameters via {@link JavaNavigationService} and then call special method on view to display them.
*
* @param activeEditor
* active editor which contains method or constructor for which parameters will be displayed
*/
public void show(final TextEditor activeEditor) {
final int offset = activeEditor.getCursorOffset();
if (!isCursorInRightPlace(activeEditor, offset)) {
return;
}
VirtualFile file = activeEditor.getEditorInput().getFile();
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
final int lineStartOffset = getLineStartOffset(activeEditor, offset);
navigationService.getMethodParametersHints(project.get().getLocation(), JavaUtil.resolveFQN(file), offset, lineStartOffset).then(new Operation<List<MethodParameters>>() {
@Override
public void apply(List<MethodParameters> parameters) throws OperationException {
if (parameters.isEmpty()) {
return;
}
PositionConverter.PixelCoordinates coordinates = activeEditor.getPositionConverter().offsetToPixel(offset);
view.show(parameters, coordinates.getX(), coordinates.getY());
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
Log.error(getClass(), error.getMessage());
}
});
}
}
Aggregations