use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class EditorCurrentProjectTypeMacro method expand.
/** {@inheritDoc} */
@Override
public Promise<String> expand() {
final EditorPartPresenter editor = getActiveEditor();
if (editor == null) {
return promises.resolve("");
}
final VirtualFile file = editor.getEditorInput().getFile();
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
if (!project.isPresent()) {
return promises.resolve("");
}
return promises.resolve(project.get().getType());
}
return promises.resolve("");
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class AppContextImpl method getRootProject.
@Override
public Project getRootProject() {
if (projects == null) {
return null;
}
if (currentResource == null || currentResources == null) {
EditorAgent editorAgent = editorAgentProvider.get();
if (editorAgent == null) {
return null;
}
final EditorPartPresenter editor = editorAgent.getActiveEditor();
if (editor == null) {
return null;
}
final VirtualFile file = editor.getEditorInput().getFile();
if (file instanceof SyntheticNode) {
final Path projectPath = ((SyntheticNode) file).getProject();
for (Project project : projects) {
if (project.getLocation().equals(projectPath)) {
return project;
}
}
}
}
if (currentResource == null) {
return null;
}
Project root = null;
for (Project project : projects) {
if (project.getLocation().isPrefixOf(currentResource.getLocation())) {
root = project;
}
}
if (root == null) {
return null;
}
for (int i = 1; i < currentResources.length; i++) {
if (!root.getLocation().isPrefixOf(currentResources[i].getLocation())) {
return null;
}
}
return root;
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class BreakpointManagerImpl method addBreakpoint.
/**
* Adds breakpoint to the list and JVM.
*/
private void addBreakpoint(final Breakpoint breakpoint) {
List<Breakpoint> pathBreakpoints = breakpoints.get(breakpoint.getPath());
if (pathBreakpoints == null) {
pathBreakpoints = new ArrayList<>();
breakpoints.put(breakpoint.getPath(), pathBreakpoints);
}
if (!pathBreakpoints.contains(breakpoint)) {
pathBreakpoints.add(breakpoint);
}
preserveBreakpoints();
final BreakpointRenderer breakpointRenderer = getBreakpointRendererForFile(breakpoint.getPath());
if (breakpointRenderer != null) {
breakpointRenderer.addBreakpointMark(breakpoint.getLineNumber(), new LineChangeAction() {
@Override
public void onLineChange(VirtualFile file, int firstLine, int linesAdded, int linesRemoved) {
BreakpointManagerImpl.this.onLineChange(file, firstLine, linesAdded, linesRemoved);
}
});
breakpointRenderer.setBreakpointActive(breakpoint.getLineNumber(), breakpoint.isActive());
}
for (BreakpointManagerObserver observer : observers) {
observer.onBreakpointAdded(breakpoint);
}
Debugger debugger = debuggerManager.getActiveDebugger();
if (debugger != null) {
debugger.addBreakpoint(breakpoint.getFile(), breakpoint.getLineNumber());
}
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class EditorTabWidget method onResourceChanged.
@Override
public void onResourceChanged(ResourceChangedEvent event) {
final ResourceDelta delta = event.getDelta();
if (delta.getKind() == ADDED) {
if (!delta.getResource().isFile() || (delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) {
return;
}
final Resource resource = delta.getResource();
final Path movedFrom = delta.getFromPath();
if (file.getLocation().equals(movedFrom)) {
file = (VirtualFile) resource;
title.setText(file.getDisplayName());
}
} else if (delta.getKind() == UPDATED) {
if (!delta.getResource().isFile()) {
return;
}
final Resource resource = delta.getResource();
if (file.getLocation().equals(resource.getLocation())) {
file = (VirtualFile) resource;
title.setText(file.getDisplayName());
}
}
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class JavaRefactoringRename method performRename.
private void performRename(RenameRefactoringSession session) {
final LinkedRenameRefactoringApply dto = createLinkedRenameRefactoringApplyDto(newName, session.getSessionId());
Promise<RefactoringResult> applyModelPromise = refactoringServiceClient.applyLinkedModeRename(dto);
applyModelPromise.then(new Operation<RefactoringResult>() {
@Override
public void apply(RefactoringResult result) throws OperationException {
switch(result.getSeverity()) {
case OK:
case INFO:
final VirtualFile file = textEditor.getDocument().getFile();
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
refactoringServiceClient.reindexProject(project.get().getLocation().toString());
}
refactoringUpdater.updateAfterRefactoring(result.getChanges());
break;
case WARNING:
case ERROR:
enableAutoSave();
undoChanges();
showWarningDialog();
break;
case FATAL:
undoChanges();
notificationManager.notify(locale.failedToRename(), result.getEntries().get(0).getMessage(), FAIL, FLOAT_MODE);
break;
default:
break;
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
enableAutoSave();
undoChanges();
notificationManager.notify(locale.failedToRename(), arg.getMessage(), FAIL, FLOAT_MODE);
}
});
}
Aggregations