Search in sources :

Example 1 with JarEntry

use of org.eclipse.che.ide.ext.java.shared.JarEntry in project che by eclipse.

the class OpenImplementationPresenter method actionPerformed.

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

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

        @Override
        public void execute() {
            activeEditor.setFocus();
        }
    });
}
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 2 with JarEntry

use of org.eclipse.che.ide.ext.java.shared.JarEntry in project che by eclipse.

the class JavaNavigation method getJarEntryResource.

private JarEntry getJarEntryResource(JarEntryResource resource) {
    JarEntry entry = DtoFactory.getInstance().createDto(JarEntry.class);
    if (resource instanceof JarEntryDirectory) {
        entry.setType(JarEntryType.FOLDER);
    }
    if (resource instanceof JarEntryFile) {
        entry.setType(JarEntryType.FILE);
    }
    entry.setName(resource.getName());
    entry.setPath(resource.getFullPath().toOSString());
    return entry;
}
Also used : JarEntryDirectory(org.eclipse.jdt.internal.core.JarEntryDirectory) JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile)

Example 3 with JarEntry

use of org.eclipse.che.ide.ext.java.shared.JarEntry 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 4 with JarEntry

use of org.eclipse.che.ide.ext.java.shared.JarEntry in project che by eclipse.

the class JarNavigationTest method testNonJavaFile.

@Test
public void testNonJavaFile() throws Exception {
    String javaHome = System.getProperty("java.home") + "/lib/ext/zipfs.jar";
    IPackageFragmentRoot root = project.getPackageFragmentRoot(new File(javaHome).getPath());
    List<JarEntry> rootContent = navigation.getChildren(project, root.hashCode(), "/META-INF/services");
    assertThat(rootContent).isNotNull().isNotEmpty().onProperty("name").containsExactly("java.nio.file.spi.FileSystemProvider");
}
Also used : JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) File(java.io.File) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 5 with JarEntry

use of org.eclipse.che.ide.ext.java.shared.JarEntry in project che by eclipse.

the class JarNavigationTest method testExternalJar.

@Test
public void testExternalJar() throws Exception {
    String javaHome = getClass().getResource("/temp").getPath() + "/ws/test/gwt-user.jar";
    IPackageFragmentRoot root = project.getPackageFragmentRoot(new File(javaHome).getPath());
    List<JarEntry> content = navigation.getPackageFragmentRootContent(project, root.hashCode());
    assertThat(content).isNotNull().isNotEmpty().onProperty("name").contains("com.google", "javax", "org", "META-INF", "about.html");
}
Also used : JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) File(java.io.File) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Aggregations

JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)23 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)16 File (java.io.File)15 Test (org.junit.Test)15 Operation (org.eclipse.che.api.promises.client.Operation)4 OperationException (org.eclipse.che.api.promises.client.OperationException)4 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)4 Optional (com.google.common.base.Optional)3 Scheduler (com.google.gwt.core.client.Scheduler)3 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)3 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)3 File (org.eclipse.che.ide.api.resources.File)3 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)3 Project (org.eclipse.che.ide.api.resources.Project)2 Resource (org.eclipse.che.ide.api.resources.Resource)2 SyntheticFile (org.eclipse.che.ide.api.resources.SyntheticFile)2 IClassFile (org.eclipse.jdt.core.IClassFile)2 JarEntryDirectory (org.eclipse.jdt.internal.core.JarEntryDirectory)2 JarEntryFile (org.eclipse.jdt.internal.core.JarEntryFile)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1