use of org.eclipse.che.ide.api.resources.Folder 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();
}
});
}
});
}
use of org.eclipse.che.ide.api.resources.Folder in project che by eclipse.
the class NewPackageAction method onAccepted.
private void onAccepted(String value) {
final Resource resource = appContext.getResource();
checkState(resource instanceof Container, "Parent should be a container");
((Container) resource).newFolder(value.replace('.', '/')).then(new Operation<Folder>() {
@Override
public void apply(Folder pkg) throws OperationException {
eventBus.fireEvent(new RevealResourceEvent(pkg));
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
dialogFactory.createMessageDialog(coreLocalizationConstant.invalidName(), error.getMessage(), null).show();
}
});
}
use of org.eclipse.che.ide.api.resources.Folder in project che by eclipse.
the class NewFolderAction method createFolder.
final void createFolder(String name) {
Resource resource = appContext.getResource();
if (!(resource instanceof Container)) {
final Container parent = resource.getParent();
checkState(parent != null, "Parent should be a container");
resource = parent;
}
((Container) resource).newFolder(name).then(new Operation<Folder>() {
@Override
public void apply(Folder folder) throws OperationException {
eventBus.fireEvent(new RevealResourceEvent(folder));
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
dialogFactory.createMessageDialog("Error", error.getMessage(), null).show();
}
});
}
Aggregations