Search in sources :

Example 21 with VirtualFile

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);
                    }
                });
            }
        }
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) AnchorElement(elemental.html.AnchorElement) Text(elemental.dom.Text) HasNotificationPanel(org.eclipse.che.ide.api.editor.texteditor.HasNotificationPanel) JarFileNode(org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode) TextEditorPartView(org.eclipse.che.ide.api.editor.texteditor.TextEditorPartView) DivElement(elemental.html.DivElement) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorOpenedEvent(org.eclipse.che.ide.api.editor.EditorOpenedEvent) Event(elemental.events.Event) FileContentUpdateEvent(org.eclipse.che.ide.api.event.FileContentUpdateEvent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) EventListener(elemental.events.EventListener)

Example 22 with VirtualFile

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));
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Test(org.junit.Test)

Example 23 with VirtualFile

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());
        }
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 24 with VirtualFile

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);
        }
    });
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) Resource(org.eclipse.che.ide.api.resources.Resource) LinkedRenameRefactoringApply(org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 25 with VirtualFile

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;
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource) CreateRenameRefactoring(org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring)

Aggregations

VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)48 Project (org.eclipse.che.ide.api.resources.Project)21 Resource (org.eclipse.che.ide.api.resources.Resource)19 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)18 OperationException (org.eclipse.che.api.promises.client.OperationException)15 Operation (org.eclipse.che.api.promises.client.Operation)14 PromiseError (org.eclipse.che.api.promises.client.PromiseError)9 File (org.eclipse.che.ide.api.resources.File)8 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)6 Test (org.junit.Test)6 Optional (com.google.common.base.Optional)5 Scheduler (com.google.gwt.core.client.Scheduler)4 HashMap (java.util.HashMap)4 EditorInput (org.eclipse.che.ide.api.editor.EditorInput)4 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)4 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 Path (org.eclipse.che.ide.resource.Path)4 Breakpoint (org.eclipse.che.ide.api.debug.Breakpoint)3 JarFileNode (org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode)3