Search in sources :

Example 6 with Container

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

the class NewJavaSourceFileAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final Resource[] resources = appContext.getResources();
    final boolean inJavaProject = resources != null && resources.length == 1 && isJavaProject(resources[0].getRelatedProject().get());
    checkState(inJavaProject && resources[0].getParentWithMarker(ID).isPresent());
    final Resource resource = resources[0];
    if (resource instanceof Container) {
        newJavaSourceFilePresenter.showDialog((Container) resource);
    } else {
        final Container parent = resource.getParent();
        if (parent != null) {
            newJavaSourceFilePresenter.showDialog(parent);
        } else {
            throw new IllegalStateException("Failed to get parent container");
        }
    }
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 7 with Container

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

the class ResourceManager method update.

/**
     * Update state of specific properties in project and save this state on the server.
     * As the result method should return the {@link Promise} with new {@link Project} object.
     * <p/>
     * During the update method have to iterate on children of updated resource and if any of
     * them has changed own type, e.g. folder -> project, project -> folder, specific event
     * has to be fired.
     * <p/>
     * Method is not intended to be called in third party components. It is the service method
     * for {@link Project}.
     *
     * @param path
     *         the path to project which should be updated
     * @param request
     *         the update request
     * @return the {@link Promise} with new {@link Project} object.
     * @see ResourceChangedEvent
     * @see ProjectRequest
     * @see Project#update()
     * @since 4.4.0
     */
protected Promise<Project> update(final Path path, final ProjectRequest request) {
    final ProjectConfig projectConfig = request.getBody();
    final SourceStorage source = projectConfig.getSource();
    final SourceStorageDto sourceDto = dtoFactory.createDto(SourceStorageDto.class);
    if (source != null) {
        sourceDto.setLocation(source.getLocation());
        sourceDto.setType(source.getType());
        sourceDto.setParameters(source.getParameters());
    }
    final ProjectConfigDto dto = dtoFactory.createDto(ProjectConfigDto.class).withName(projectConfig.getName()).withPath(path.toString()).withDescription(projectConfig.getDescription()).withType(projectConfig.getType()).withMixins(projectConfig.getMixins()).withAttributes(projectConfig.getAttributes()).withSource(sourceDto);
    return ps.updateProject(dto).thenPromise(new Function<ProjectConfigDto, Promise<Project>>() {

        @Override
        public Promise<Project> apply(ProjectConfigDto reference) throws FunctionException {
            /* Note: After update, project may become to be other type,
                   e.g. blank -> java or maven, or ant, or etc. And this may
                   cause sub-project creations. Simultaneously on the client
                   side there is outdated information about sub-projects, so
                   we need to get updated project list. */
            //dispose outdated resource
            final Optional<Resource> outdatedResource = store.getResource(path);
            checkState(outdatedResource.isPresent(), "Outdated resource wasn't found");
            final Resource resource = outdatedResource.get();
            checkState(resource instanceof Container, "Outdated resource is not a container");
            Container container = (Container) resource;
            if (resource instanceof Folder) {
                Container parent = resource.getParent();
                checkState(parent != null, "Parent of the resource wasn't found");
                container = parent;
            }
            return synchronize(container).then(new Function<Resource[], Project>() {

                @Override
                public Project apply(Resource[] synced) throws FunctionException {
                    final Optional<Resource> updatedProject = store.getResource(path);
                    checkState(updatedProject.isPresent(), "Updated resource is not present");
                    checkState(updatedProject.get().isProject(), "Updated resource is not a project");
                    eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(updatedProject.get(), UPDATED)));
                    return (Project) updatedProject.get();
                }
            });
        }
    });
}
Also used : Optional(com.google.common.base.Optional) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Resource(org.eclipse.che.ide.api.resources.Resource) Folder(org.eclipse.che.ide.api.resources.Folder) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Promise(org.eclipse.che.api.promises.client.Promise) Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) Container(org.eclipse.che.ide.api.resources.Container) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 8 with Container

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

the class ResourceManager method parentOf.

Optional<Container> parentOf(Resource resource) {
    final Path parentLocation = resource.getLocation().segmentCount() == 1 ? Path.ROOT : resource.getLocation().parent();
    final Optional<Resource> optionalParent = store.getResource(parentLocation);
    if (!optionalParent.isPresent()) {
        return absent();
    }
    final Resource parentResource = optionalParent.get();
    checkState(parentResource instanceof Container, "Parent resource is not a container");
    return of((Container) parentResource);
}
Also used : Path(org.eclipse.che.ide.resource.Path) Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 9 with Container

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

the class ResourceManager method traverse.

private void traverse(TreeElement tree, ResourceVisitor visitor) {
    for (final TreeElement element : tree.getChildren()) {
        final Resource resource = newResourceFrom(element.getNode());
        visitor.visit(resource);
        if (resource instanceof Container) {
            traverse(element, visitor);
        }
    }
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource) TreeElement(org.eclipse.che.api.project.shared.dto.TreeElement)

Example 10 with Container

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

the class AbstractNewResourceAction method updateInPerspective.

@Override
public void updateInPerspective(@NotNull ActionEvent e) {
    e.getPresentation().setVisible(true);
    final Resource[] resources = appContext.getResources();
    if (resources != null && resources.length == 1) {
        final Resource resource = resources[0];
        if (resource instanceof Container) {
            e.getPresentation().setEnabled(true);
        } else {
            e.getPresentation().setEnabled(resource.getParent() != null);
        }
    } else {
        e.getPresentation().setEnabled(false);
    }
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource)

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