Search in sources :

Example 21 with JarEntry

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

the class JarNavigationTest method testJavaPackage.

@Test
public void testJavaPackage() throws Exception {
    String javaHome = System.getProperty("java.home") + "/lib/rt.jar";
    IPackageFragmentRoot root = project.getPackageFragmentRoot(new File(javaHome).getPath());
    List<JarEntry> rootContent = navigation.getChildren(project, root.hashCode(), "java");
    assertThat(rootContent).isNotNull().isNotEmpty().onProperty("name").contains("lang", "io", "util", "net", "nio");
}
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 22 with JarEntry

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

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

the class JavaNavigation method convertToJarEntry.

private List<JarEntry> convertToJarEntry(Object[] rootContent, IPackageFragmentRoot root) throws JavaModelException {
    List<JarEntry> result = new ArrayList<>();
    for (Object o : rootContent) {
        if (o instanceof IPackageFragment) {
            JarEntry entry = DtoFactory.getInstance().createDto(JarEntry.class);
            IPackageFragment packageFragment = (IPackageFragment) o;
            entry.setName(getSpecificText((IJavaElement) o));
            entry.setPath(packageFragment.getElementName());
            entry.setType(JarEntryType.PACKAGE);
            result.add(entry);
        }
        if (o instanceof IClassFile) {
            JarEntry entry = getJarClass((IClassFile) o);
            result.add(entry);
        }
        if (o instanceof JarEntryResource) {
            result.add(getJarEntryResource((JarEntryResource) o));
        }
    }
    Collections.sort(result, comparator);
    return result;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IClassFile(org.eclipse.jdt.core.IClassFile) ArrayList(java.util.ArrayList) JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) JarEntryResource(org.eclipse.jdt.internal.core.JarEntryResource) IJarEntryResource(org.eclipse.jdt.core.IJarEntryResource)

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