Search in sources :

Example 96 with Resource

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

the class FileStructurePresenter method show.

/**
     * Shows the structure of the opened class.
     *
     * @param editorPartPresenter
     *         the active editor
     */
public void show(EditorPartPresenter editorPartPresenter) {
    loader.show();
    view.setTitle(editorPartPresenter.getEditorInput().getFile().getName());
    if (!(editorPartPresenter instanceof TextEditor)) {
        Log.error(getClass(), "Open Declaration support only TextEditor as editor");
        return;
    }
    activeEditor = ((TextEditor) editorPartPresenter);
    cursorOffset = activeEditor.getCursorOffset();
    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);
        javaNavigationService.getCompilationUnit(project.get().getLocation(), fqn, showInheritedMembers).then(new Operation<CompilationUnit>() {

            @Override
            public void apply(CompilationUnit unit) throws OperationException {
                view.setStructure(unit, showInheritedMembers);
                showInheritedMembers = !showInheritedMembers;
                loader.hide();
                view.show();
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError arg) throws OperationException {
                Log.error(FileStructurePresenter.class, arg.getMessage());
                loader.hide();
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 97 with Resource

use of org.eclipse.che.ide.api.resources.Resource 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 98 with Resource

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

the class ClasspathMacro method expand.

@Override
public Promise<String> expand() {
    final Resource[] resources = appContext.getResources();
    if (resources == null || resources.length != 1) {
        return promises.resolve("");
    }
    final Resource resource = resources[0];
    final Optional<Project> project = resource.getRelatedProject();
    if (!JavaUtil.isJavaProject(project.get())) {
        return promises.resolve("");
    }
    final String projectPath = project.get().getLocation().toString();
    return classpathContainer.getClasspathEntries(projectPath).then(new Function<List<ClasspathEntryDto>, String>() {

        @Override
        public String apply(List<ClasspathEntryDto> arg) throws FunctionException {
            classpathResolver.resolveClasspathEntries(arg);
            Set<String> libs = classpathResolver.getLibs();
            StringBuilder classpath = new StringBuilder();
            for (String lib : libs) {
                classpath.append(lib).append(':');
            }
            for (ClasspathEntryDto container : classpathResolver.getContainers()) {
                if (!JRE_CONTAINER.equals(container.getPath())) {
                    addLibsFromContainer(container, classpath);
                }
            }
            if (classpath.toString().isEmpty()) {
                classpath.append(appContext.getProjectsRoot().toString()).append(projectPath).append(':');
            }
            return classpath.toString();
        }
    });
}
Also used : Set(java.util.Set) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) Project(org.eclipse.che.ide.api.resources.Project) List(java.util.List)

Example 99 with Resource

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

the class SourcepathMacro method expand.

@Override
public Promise<String> expand() {
    final Resource[] resources = appContext.getResources();
    if (resources == null || resources.length != 1) {
        return promises.resolve("");
    }
    final Resource resource = resources[0];
    final Optional<Project> project = resource.getRelatedProject();
    if (!JavaUtil.isJavaProject(project.get())) {
        return promises.resolve("");
    }
    final String projectPath = project.get().getLocation().toString();
    return classpathContainer.getClasspathEntries(projectPath).then(new Function<List<ClasspathEntryDto>, String>() {

        @Override
        public String apply(List<ClasspathEntryDto> arg) throws FunctionException {
            classpathResolver.resolveClasspathEntries(arg);
            Set<String> sources = classpathResolver.getSources();
            StringBuilder classpath = new StringBuilder();
            for (String source : sources) {
                classpath.append(source.substring(projectPath.length() + 1)).append(':');
            }
            if (classpath.toString().isEmpty()) {
                classpath.append(appContext.getProjectsRoot().toString()).append(projectPath);
            }
            return classpath.toString();
        }
    });
}
Also used : Set(java.util.Set) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) Project(org.eclipse.che.ide.api.resources.Project) List(java.util.List)

Example 100 with Resource

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

the class QuickDocPresenter method showDocumentation.

@Override
public void showDocumentation() {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    if (!(activeEditor instanceof TextEditor)) {
        Log.error(getClass(), "Quick Document support only TextEditor as editor");
        return;
    }
    TextEditor editor = ((TextEditor) activeEditor);
    int offset = editor.getCursorOffset();
    final PositionConverter.PixelCoordinates coordinates = editor.getPositionConverter().offsetToPixel(offset);
    final Resource resource = appContext.getResource();
    if (resource != null) {
        final Optional<Project> project = resource.getRelatedProject();
        final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
        if (!srcFolder.isPresent()) {
            return;
        }
        final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), resource);
        final String docUrl = appContext.getDevMachine().getWsAgentBaseUrl() + "/java/javadoc/find?fqn=" + fqn + "&projectpath=" + project.get().getLocation() + "&offset=" + offset;
        view.show(agentURLDecorator.modify(docUrl), coordinates.getX(), coordinates.getY());
    }
}
Also used : 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) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) PositionConverter(org.eclipse.che.ide.api.editor.position.PositionConverter)

Aggregations

Resource (org.eclipse.che.ide.api.resources.Resource)146 Project (org.eclipse.che.ide.api.resources.Project)73 OperationException (org.eclipse.che.api.promises.client.OperationException)48 Operation (org.eclipse.che.api.promises.client.Operation)46 PromiseError (org.eclipse.che.api.promises.client.PromiseError)40 Container (org.eclipse.che.ide.api.resources.Container)32 Path (org.eclipse.che.ide.resource.Path)30 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)22 Optional (com.google.common.base.Optional)15 File (org.eclipse.che.ide.api.resources.File)14 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)14 List (java.util.List)13 Promise (org.eclipse.che.api.promises.client.Promise)13 FunctionException (org.eclipse.che.api.promises.client.FunctionException)12 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)12 ArrayList (java.util.ArrayList)11 Function (org.eclipse.che.api.promises.client.Function)9 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)9 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)9 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)8