Search in sources :

Example 31 with VirtualFile

use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.

the class FileStructurePresenter method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(final Member member) {
    if (member.isBinary()) {
        final Resource resource = context.getResource();
        if (resource == null) {
            return;
        }
        final Optional<Project> project = resource.getRelatedProject();
        javaNavigationService.getEntry(project.get().getLocation(), member.getLibId(), member.getRootPath()).then(new Operation<JarEntry>() {

            @Override
            public void apply(final JarEntry entry) throws OperationException {
                javaNavigationService.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(editor, member.getFileRegion().getOffset());
                            }
                        });
                    }
                });
            }
        });
    } 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(editor, member.getFileRegion().getOffset());
                        }
                    });
                }
            }
        });
    }
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

        @Override
        public void execute() {
            setCursorPosition(member.getFileRegion());
        }
    });
    showInheritedMembers = false;
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ClassContent(org.eclipse.che.ide.ext.java.shared.dto.ClassContent) Optional(com.google.common.base.Optional) Scheduler(com.google.gwt.core.client.Scheduler) Resource(org.eclipse.che.ide.api.resources.Resource) OpenEditorCallbackImpl(org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl) Operation(org.eclipse.che.api.promises.client.Operation) JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) Project(org.eclipse.che.ide.api.resources.Project) SyntheticFile(org.eclipse.che.ide.api.resources.SyntheticFile) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) SyntheticFile(org.eclipse.che.ide.api.resources.SyntheticFile) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 32 with VirtualFile

use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.

the class OpenImplementationPresenter method show.

/**
     * Shows the implementations of the selected element.
     *
     * @param editorPartPresenter
     *         the active editor
     */
public void show(final EditorPartPresenter editorPartPresenter) {
    if (!(editorPartPresenter instanceof TextEditor)) {
        Log.error(getClass(), "Open Declaration support only TextEditor as editor");
        return;
    }
    activeEditor = ((TextEditor) editorPartPresenter);
    final VirtualFile file = activeEditor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        final Optional<Resource> srcFolder = ((Resource) file).getParentWithMarker(SourceFolderMarker.ID);
        if (!srcFolder.isPresent()) {
            return;
        }
        final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);
        service.getImplementations(project.get().getLocation(), fqn, activeEditor.getCursorOffset()).then(new Operation<ImplementationsDescriptorDTO>() {

            @Override
            public void apply(ImplementationsDescriptorDTO impls) throws OperationException {
                int overridingSize = impls.getImplementations().size();
                String title = locale.openImplementationWindowTitle(impls.getMemberName(), overridingSize);
                NoImplementationWidget noImplementationWidget = new NoImplementationWidget(popupResources, javaResources, locale, OpenImplementationPresenter.this, title);
                if (overridingSize == 1) {
                    actionPerformed(impls.getImplementations().get(0));
                } else if (overridingSize > 1) {
                    openOneImplementation(impls, noImplementationWidget, (TextEditor) editorPartPresenter);
                } else if (!isNullOrEmpty(impls.getMemberName()) && overridingSize == 0) {
                    showNoImplementations(noImplementationWidget, (TextEditor) editorPartPresenter);
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Resource(org.eclipse.che.ide.api.resources.Resource) ImplementationsDescriptorDTO(org.eclipse.che.ide.ext.java.shared.dto.ImplementationsDescriptorDTO) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 33 with VirtualFile

use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.

the class JavaEditorAction method updateProjectAction.

@Override
protected void updateProjectAction(ActionEvent e) {
    if (editorAgent.getActiveEditor() != null) {
        EditorInput input = editorAgent.getActiveEditor().getEditorInput();
        VirtualFile file = input.getFile();
        final String fileExtension = fileTypeRegistry.getFileTypeByFile(file).getExtension();
        if ("java".equals(fileExtension) || "class".equals(fileExtension)) {
            e.getPresentation().setEnabledAndVisible(true);
            return;
        }
    }
    e.getPresentation().setEnabledAndVisible(false);
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) EditorInput(org.eclipse.che.ide.api.editor.EditorInput)

Example 34 with VirtualFile

use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.

the class JavaCodeAssistProcessor method computeCompletionProposals.

@Override
public void computeCompletionProposals(final TextEditor textEditor, final int offset, final boolean triggered, final CodeAssistCallback callback) {
    if (errorMessage != null) {
        return;
    }
    final VirtualFile file = editor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        Unmarshallable<Proposals> unmarshaller = unmarshallerFactory.newUnmarshaller(Proposals.class);
        client.computeProposals(project.get().getLocation().toString(), resolveFQN(file), offset, textEditor.getDocument().getContents(), new AsyncRequestCallback<Proposals>(unmarshaller) {

            @Override
            protected void onSuccess(Proposals proposals) {
                showProposals(callback, proposals);
            }

            @Override
            protected void onFailure(Throwable throwable) {
                Log.error(JavaCodeAssistProcessor.class, throwable);
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) ImageResource(com.google.gwt.resources.client.ImageResource) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource) Proposals(org.eclipse.che.ide.ext.java.shared.dto.Proposals)

Example 35 with VirtualFile

use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.

the class JavaQuickAssistProcessor method setupProposals.

private void setupProposals(final CodeAssistCallback callback, final TextEditor textEditor, final int offset, final List<Problem> annotations) {
    final VirtualFile file = textEditor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        Unmarshallable<Proposals> unmarshaller = unmarshallerFactory.newUnmarshaller(Proposals.class);
        client.computeAssistProposals(project.get().getLocation().toString(), resolveFQN(file), offset, annotations, new AsyncRequestCallback<Proposals>(unmarshaller) {

            @Override
            protected void onSuccess(Proposals proposals) {
                showProposals(callback, proposals, textEditor);
            }

            @Override
            protected void onFailure(Throwable throwable) {
                Log.error(JavaCodeAssistProcessor.class, throwable);
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource) Proposals(org.eclipse.che.ide.ext.java.shared.dto.Proposals)

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