Search in sources :

Example 26 with Resource

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

the class ResourceManager method createProject.

Promise<Project> createProject(final Project.ProjectRequest createRequest) {
    checkArgument(checkProjectName(createRequest.getBody().getName()), "Invalid project name");
    checkArgument(typeRegistry.getProjectType(createRequest.getBody().getType()) != null, "Invalid project type");
    final Path path = Path.valueOf(createRequest.getBody().getPath());
    return findResource(path, true).thenPromise(new Function<Optional<Resource>, Promise<Project>>() {

        @Override
        public Promise<Project> apply(Optional<Resource> resource) throws FunctionException {
            if (resource.isPresent()) {
                if (resource.get().isProject()) {
                    throw new IllegalStateException("Project already exists");
                } else if (resource.get().isFile()) {
                    throw new IllegalStateException("File can not be converted to project");
                }
                return update(path, createRequest);
            }
            final MutableProjectConfig projectConfig = (MutableProjectConfig) createRequest.getBody();
            final List<NewProjectConfig> projectConfigList = projectConfig.getProjects();
            projectConfigList.add(asDto(projectConfig));
            final List<NewProjectConfigDto> configDtoList = asDto(projectConfigList);
            return ps.createBatchProjects(configDtoList).thenPromise(new Function<List<ProjectConfigDto>, Promise<Project>>() {

                @Override
                public Promise<Project> apply(final List<ProjectConfigDto> configList) throws FunctionException {
                    return ps.getProjects().then(new Function<List<ProjectConfigDto>, Project>() {

                        @Override
                        public Project apply(List<ProjectConfigDto> updatedConfiguration) throws FunctionException {
                            //cache new configs
                            cachedConfigs = updatedConfiguration.toArray(new ProjectConfigDto[updatedConfiguration.size()]);
                            for (ProjectConfigDto projectConfigDto : configList) {
                                if (projectConfigDto.getPath().equals(path.toString())) {
                                    final Project newResource = resourceFactory.newProjectImpl(projectConfigDto, ResourceManager.this);
                                    store.register(newResource);
                                    eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(newResource, ADDED | DERIVED)));
                                    return newResource;
                                }
                            }
                            throw new IllegalStateException("Created project is not found");
                        }
                    });
                }
            });
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) Optional(com.google.common.base.Optional) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Promise(org.eclipse.che.api.promises.client.Promise) Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) List(java.util.List) ArrayList(java.util.ArrayList) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 27 with Resource

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

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

the class ResourceManager method onExternalDeltaMoved.

private Promise<Void> onExternalDeltaMoved(final ResourceDelta delta) {
    //search resource to remove at first
    return findResource(delta.getFromPath(), true).thenPromise(new Function<Optional<Resource>, Promise<Void>>() {

        @Override
        public Promise<Void> apply(final Optional<Resource> toRemove) throws FunctionException {
            if (!toRemove.isPresent()) {
                return promises.resolve(null);
            }
            store.dispose(delta.getFromPath(), true);
            return findResource(delta.getToPath(), true).then(new Function<Optional<Resource>, Void>() {

                @Override
                public Void apply(final Optional<Resource> resource) throws FunctionException {
                    if (resource.isPresent() && toRemove.isPresent()) {
                        Resource intercepted = resource.get();
                        if (!store.getResource(intercepted.getLocation()).isPresent()) {
                            store.register(intercepted);
                        }
                        eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(intercepted, toRemove.get(), ADDED | MOVED_FROM | MOVED_TO | DERIVED)));
                    }
                    return null;
                }
            });
        }
    });
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) Function(org.eclipse.che.api.promises.client.Function) Optional(com.google.common.base.Optional) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 29 with Resource

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

the class RevealResourceAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
    final Resource[] resources = appContext.getResources();
    checkState(resources != null && resources.length == 1);
    eventBus.fireEvent(new RevealResourceEvent(resources[0]));
}
Also used : Resource(org.eclipse.che.ide.api.resources.Resource) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent)

Example 30 with Resource

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

the class CopyPasteManager method moveResource.

private Promise<Void> moveResource(final Resource resource, final Path destination) {
    //simple move without overwriting
    return resource.move(destination).thenPromise(new Function<Resource, Promise<Void>>() {

        @Override
        public Promise<Void> apply(Resource resource) throws FunctionException {
            eventBus.fireEvent(new RevealResourceEvent(resource));
            return promises.resolve(null);
        }
    }).catchErrorPromise(new Function<PromiseError, Promise<Void>>() {

        @Override
        public Promise<Void> apply(final PromiseError error) throws FunctionException {
            //resource may already exists
            if (error.getMessage().contains("exists")) {
                //create dialog with overwriting option
                return createFromAsyncRequest(new RequestCall<Void>() {

                    @Override
                    public void makeCall(final AsyncCallback<Void> callback) {
                        //handle overwrite operation
                        final ConfirmCallback overwrite = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                //copy with overwriting
                                resource.move(destination, true).then(new Operation<Resource>() {

                                    @Override
                                    public void apply(Resource ignored) throws OperationException {
                                        callback.onSuccess(null);
                                    }
                                }).catchError(new Operation<PromiseError>() {

                                    @Override
                                    public void apply(PromiseError error) throws OperationException {
                                        callback.onFailure(error.getCause());
                                    }
                                });
                            }
                        };
                        //skip this resource
                        final ConfirmCallback skip = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                callback.onSuccess(null);
                            }
                        };
                        //change destination name
                        final ConfirmCallback rename = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                dialogFactory.createInputDialog("Enter new name", "Enter new name", new InputCallback() {

                                    @Override
                                    public void accepted(String value) {
                                        final Path newPath = destination.parent().append(value);
                                        moveResource(resource, newPath).then(new Operation<Void>() {

                                            @Override
                                            public void apply(Void result) throws OperationException {
                                                callback.onSuccess(result);
                                            }
                                        }).catchError(new Operation<PromiseError>() {

                                            @Override
                                            public void apply(PromiseError error) throws OperationException {
                                                callback.onFailure(error.getCause());
                                            }
                                        });
                                    }
                                }, new CancelCallback() {

                                    @Override
                                    public void cancelled() {
                                    }
                                }).show();
                            }
                        };
                        dialogFactory.createChoiceDialog("Error", error.getMessage(), "Overwrite", "Skip", "Change Name", overwrite, skip, rename).show();
                    }
                });
            } else {
                //notify user about failed copying
                notificationManager.notify("Error moving resource", error.getMessage(), FAIL, FLOAT_MODE);
                return promises.resolve(null);
            }
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) RequestCall(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.RequestCall) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Operation(org.eclipse.che.api.promises.client.Operation) Function(org.eclipse.che.api.promises.client.Function) Promise(org.eclipse.che.api.promises.client.Promise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CancelCallback(org.eclipse.che.ide.api.dialogs.CancelCallback) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) OperationException(org.eclipse.che.api.promises.client.OperationException)

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