Search in sources :

Example 1 with JarFileNode

use of org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode in project che by eclipse.

the class JavaDebuggerFileHandler method openExternalResource.

private void openExternalResource(final Location location, final AsyncCallback<VirtualFile> callback) {
    final String className = extractOuterClassFqn(location.getTarget());
    final int libId = location.getExternalResourceId();
    final Path projectPath = new Path(location.getResourceProjectPath());
    service.getEntry(projectPath, libId, className).then(new Operation<JarEntry>() {

        @Override
        public void apply(final JarEntry jarEntry) throws OperationException {
            final JarFileNode file = nodeFactory.newJarFileNode(jarEntry, libId, projectPath, null);
            AsyncCallback<VirtualFile> downloadSourceCallback = new AsyncCallback<VirtualFile>() {

                @Override
                public void onSuccess(final VirtualFile result) {
                    if (file.isContentGenerated()) {
                        handleContentGeneratedResource(file, location, callback);
                    } else {
                        handleActivatedFile(file, callback, location.getLineNumber());
                    }
                }

                @Override
                public void onFailure(Throwable caught) {
                    callback.onFailure(caught);
                }
            };
            handleActivatedFile(file, downloadSourceCallback, location.getLineNumber());
            eventBus.fireEvent(FileEvent.createOpenFileEvent(file));
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            callback.onFailure(arg.getCause());
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Operation(org.eclipse.che.api.promises.client.Operation) JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) JarFileNode(org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 2 with JarFileNode

use of org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode in project che by eclipse.

the class OpenDeclarationFinder method openDeclaration.

public void openDeclaration() {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    if (!(activeEditor instanceof TextEditor)) {
        Log.error(getClass(), "Open Declaration support only TextEditor as editor");
        return;
    }
    TextEditor editor = ((TextEditor) activeEditor);
    int offset = editor.getCursorOffset();
    final VirtualFile file = editor.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);
        navigationService.findDeclaration(project.get().getLocation(), fqn, offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(project.get().getLocation(), result);
                }
            }
        });
    } else if (file instanceof JarFileNode) {
        navigationService.findDeclaration(((JarFileNode) file).getProjectLocation(), file.getLocation().toString().replace('/', '.'), offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(((JarFileNode) file).getProject(), result);
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) OpenDeclarationDescriptor(org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) JarFileNode(org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 3 with JarFileNode

use of org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode 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)

Aggregations

VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)3 JarFileNode (org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode)3 Operation (org.eclipse.che.api.promises.client.Operation)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)2 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Text (elemental.dom.Text)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 AnchorElement (elemental.html.AnchorElement)1 DivElement (elemental.html.DivElement)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 EditorOpenedEvent (org.eclipse.che.ide.api.editor.EditorOpenedEvent)1 HasNotificationPanel (org.eclipse.che.ide.api.editor.texteditor.HasNotificationPanel)1 TextEditorPartView (org.eclipse.che.ide.api.editor.texteditor.TextEditorPartView)1 FileContentUpdateEvent (org.eclipse.che.ide.api.event.FileContentUpdateEvent)1 Project (org.eclipse.che.ide.api.resources.Project)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)1