use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class ClassFileSourcesDownloader method onEditorOpened.
@Override
public void onEditorOpened(EditorOpenedEvent event) {
EditorPartPresenter editor = event.getEditor();
VirtualFile file = editor.getEditorInput().getFile();
if (file instanceof JarFileNode) {
final JarFileNode jarFileNode = (JarFileNode) file;
if (jarFileNode.isContentGenerated()) {
if (editor instanceof TextEditor) {
final TextEditor presenter = (TextEditor) editor;
TextEditorPartView view = presenter.getView();
final DivElement divElement = Elements.createDivElement();
divElement.setClassName(resources.css().editorInfoPanel());
Text textNode = Elements.createTextNode(constant.mavenClassDecompiled());
DivElement decompiledElement = Elements.createDivElement();
decompiledElement.appendChild(textNode);
decompiledElement.setClassName(resources.css().editorMessage());
divElement.appendChild(decompiledElement);
AnchorElement anchorElement = Elements.createAnchorElement();
anchorElement.appendChild(Elements.createTextNode(constant.mavenDownloadSources()));
anchorElement.setHref("#");
anchorElement.setClassName(resources.css().downloadLink());
divElement.appendChild(anchorElement);
final HasNotificationPanel.NotificationRemover remover = view.addNotification((Element) divElement);
anchorElement.setOnclick(new EventListener() {
@Override
public void handleEvent(Event evt) {
downloadSources(jarFileNode, remover);
}
});
}
}
}
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class RecipeFileFactoryTest method dockerFileShouldBeCreated.
@Test
public void dockerFileShouldBeCreated() throws Exception {
VirtualFile fileNode = factory.newInstance(SOME_TEXT);
assertThat(fileNode, notNullValue());
assertThat(fileNode, instanceOf(VirtualFile.class));
}
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);
}
});
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class RenamePresenter method createRenameRefactoringDto.
private CreateRenameRefactoring createRenameRefactoringDto(RefactorInfo refactorInfo) {
CreateRenameRefactoring dto = dtoFactory.createDto(CreateRenameRefactoring.class);
dto.setRefactorLightweight(false);
if (refactorInfo == null) {
final VirtualFile file = editorAgent.getActiveEditor().getEditorInput().getFile();
dto.setType(JAVA_ELEMENT);
dto.setPath(JavaUtil.resolveFQN(file));
dto.setOffset(((TextEditor) editorAgent.getActiveEditor()).getCursorOffset());
if (file instanceof Resource) {
final Project project = ((Resource) file).getRelatedProject().get();
dto.setProjectPath(project.getLocation().toString());
}
} else {
final Resource[] resources = refactorInfo.getResources();
checkState(resources != null && resources.length == 1);
final Resource resource = resources[0];
if (resource.getResourceType() == FILE) {
dto.setPath(JavaUtil.resolveFQN(resource));
dto.setType(COMPILATION_UNIT);
} else if (resource instanceof Container) {
dto.setPath(resource.getLocation().toString());
dto.setType(PACKAGE);
}
final Project project = resource.getRelatedProject().get();
dto.setProjectPath(project.getLocation().toString());
}
return dto;
}
Aggregations