Search in sources :

Example 16 with Container

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

the class MoveAction method updateInPerspective.

/** {@inheritDoc} */
@Override
public void updateInPerspective(ActionEvent event) {
    event.getPresentation().setVisible(true);
    final Resource[] resources = appContext.getResources();
    if (resources == null || resources.length != 1) {
        event.getPresentation().setEnabled(false);
        return;
    }
    final Resource resource = resources[0];
    final Optional<Project> project = resource.getRelatedProject();
    if (!project.isPresent()) {
        event.getPresentation().setEnabled(false);
        return;
    }
    final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
    if (resource.getResourceType() == FILE) {
        event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent() && isJavaFile((File) resource));
    } else if (resource instanceof Container) {
        event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent());
    }
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 17 with Container

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

the class MoveAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent actionEvent) {
    final Resource[] resources = appContext.getResources();
    if (resources == null || resources.length > 1) {
        return;
    }
    final Resource resource = resources[0];
    final Optional<Project> project = resource.getRelatedProject();
    if (!JavaUtil.isJavaProject(project.get())) {
        return;
    }
    final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
    if (!srcFolder.isPresent() || resource.getLocation().equals(srcFolder.get().getLocation())) {
        return;
    }
    RefactoredItemType renamedItemType = null;
    if (resource.getResourceType() == FILE && isJavaFile((File) resource)) {
        renamedItemType = COMPILATION_UNIT;
    } else if (resource instanceof Container) {
        renamedItemType = PACKAGE;
    }
    if (renamedItemType == null) {
        return;
    }
    movePresenter.show(RefactorInfo.of(REFACTOR_MENU, renamedItemType, resources));
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 18 with Container

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

the class RenameRefactoringAction method updateInPerspective.

@Override
public void updateInPerspective(ActionEvent event) {
    event.getPresentation().setVisible(true);
    if (editorInFocus) {
        final EditorPartPresenter editorPart = editorAgent.getActiveEditor();
        if (editorPart == null || !(editorPart instanceof TextEditor)) {
            event.getPresentation().setEnabled(false);
            return;
        }
        final VirtualFile file = editorPart.getEditorInput().getFile();
        if (file instanceof File) {
            final Optional<Project> project = ((File) file).getRelatedProject();
            if (!project.isPresent()) {
                event.getPresentation().setEnabled(false);
                return;
            }
            event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && isJavaFile(file));
        } else {
            event.getPresentation().setEnabled(isJavaFile(file));
        }
    } else {
        final Resource[] resources = appContext.getResources();
        if (resources == null || resources.length > 1) {
            event.getPresentation().setEnabled(false);
            return;
        }
        final Resource resource = resources[0];
        final Optional<Project> project = resource.getRelatedProject();
        if (!project.isPresent()) {
            event.getPresentation().setEnabled(false);
            return;
        }
        final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
        if (resource.getResourceType() == FILE) {
            event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent() && isJavaFile((File) resource));
        } else if (resource instanceof Container) {
            event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent());
        }
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container) 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) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 19 with Container

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

the class RenameRefactoringAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    if (editorInFocus) {
        final EditorPartPresenter editorPart = editorAgent.getActiveEditor();
        if (editorPart == null || !(editorPart instanceof TextEditor)) {
            return;
        }
        javaRefactoringRename.refactor((TextEditor) editorPart);
    } else {
        final Resource[] resources = appContext.getResources();
        if (resources == null || resources.length > 1) {
            return;
        }
        final Resource resource = resources[0];
        final Optional<Project> project = resource.getRelatedProject();
        if (!JavaUtil.isJavaProject(project.get())) {
            return;
        }
        final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
        if (!srcFolder.isPresent() || resource.getLocation().equals(srcFolder.get().getLocation())) {
            return;
        }
        RefactoredItemType renamedItemType = null;
        if (resource.getResourceType() == FILE && isJavaFile((File) resource)) {
            renamedItemType = COMPILATION_UNIT;
        } else if (resource instanceof Container) {
            renamedItemType = PACKAGE;
        }
        if (renamedItemType == null) {
            return;
        }
        renamePresenter.show(RefactorInfo.of(renamedItemType, resources));
    }
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container) 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) RefactoredItemType(org.eclipse.che.ide.ext.java.client.refactoring.move.RefactoredItemType) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 20 with Container

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

the class ResourceManager method findResource.

private Promise<Optional<Resource>> findResource(final Path absolutePath, boolean quiet) {
    //search resource in local cache
    final Optional<Resource> optionalCachedResource = store.getResource(absolutePath);
    if (optionalCachedResource.isPresent()) {
        return promises.resolve(optionalCachedResource);
    }
    //request from server
    final Path projectPath = Path.valueOf(absolutePath.segment(0)).makeAbsolute();
    final Optional<Resource> optProject = store.getResource(projectPath);
    final boolean isPresent = optProject.isPresent();
    checkState(isPresent || quiet, "Resource with path '" + projectPath + "' doesn't exists");
    if (!isPresent) {
        return promises.resolve(Optional.<Resource>absent());
    }
    final Resource project = optProject.get();
    checkState(project.getResourceType() == PROJECT, "Resource with path '" + projectPath + "' isn't a project");
    final int seekDepth = absolutePath.segmentCount() - 1;
    return getRemoteResources((Container) project, seekDepth, true).then(new Function<Resource[], Optional<Resource>>() {

        @Override
        public Optional<Resource> apply(Resource[] resources) throws FunctionException {
            for (Resource resource : resources) {
                if (absolutePath.equals(resource.getLocation())) {
                    return of(resource);
                }
            }
            return absent();
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Container(org.eclipse.che.ide.api.resources.Container) Optional(com.google.common.base.Optional) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException)

Aggregations

Container (org.eclipse.che.ide.api.resources.Container)38 Resource (org.eclipse.che.ide.api.resources.Resource)32 Project (org.eclipse.che.ide.api.resources.Project)13 Operation (org.eclipse.che.api.promises.client.Operation)7 OperationException (org.eclipse.che.api.promises.client.OperationException)7 Optional (com.google.common.base.Optional)5 PromiseError (org.eclipse.che.api.promises.client.PromiseError)5 File (org.eclipse.che.ide.api.resources.File)5 Path (org.eclipse.che.ide.resource.Path)5 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)4 SVGResource (org.vectomatic.dom.svg.ui.SVGResource)4 List (java.util.List)3 FunctionException (org.eclipse.che.api.promises.client.FunctionException)3 Folder (org.eclipse.che.ide.api.resources.Folder)3 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)3 RevealResourceEvent (org.eclipse.che.ide.resources.reveal.RevealResourceEvent)3 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2 Promise (org.eclipse.che.api.promises.client.Promise)2 Node (org.eclipse.che.ide.api.data.tree.Node)2