use of org.eclipse.che.ide.api.resources.Resource 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);
}
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");
}
});
}
});
}
});
}
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);
}
}
}
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;
}
});
}
});
}
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]));
}
Aggregations