use of org.eclipse.che.ide.api.resources.VirtualFile 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.VirtualFile 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.VirtualFile 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.VirtualFile 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());
}
});
}
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class OpenImplementationPresenter method actionPerformed.
public void actionPerformed(final Member member) {
if (member.isBinary()) {
final Resource resource = context.getResource();
if (resource == null) {
return;
}
final Optional<Project> project = resource.getRelatedProject();
service.getEntry(project.get().getLocation(), member.getLibId(), member.getRootPath()).then(new Operation<JarEntry>() {
@Override
public void apply(final JarEntry entry) throws OperationException {
service.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(member.getFileRegion());
}
});
}
});
}
});
} 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(member.getFileRegion());
}
});
}
}
});
}
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
activeEditor.setFocus();
}
});
}
Aggregations