use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class FullTextSearchPresenter method search.
@Override
public void search(final String text) {
final Path startPoint = isNullOrEmpty(view.getPathToSearch()) ? defaultStartPoint : Path.valueOf(view.getPathToSearch());
appContext.getWorkspaceRoot().getContainer(startPoint).then(new Operation<Optional<Container>>() {
@Override
public void apply(Optional<Container> optionalContainer) throws OperationException {
if (!optionalContainer.isPresent()) {
view.showErrorMessage("Path '" + startPoint + "' doesn't exists");
return;
}
final Container container = optionalContainer.get();
container.search(view.getFileMask(), prepareQuery(text)).then(new Operation<Resource[]>() {
@Override
public void apply(Resource[] result) throws OperationException {
view.close();
findResultPresenter.handleResponse(result, text);
}
});
}
});
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class ProjectWizard method complete.
/** {@inheritDoc} */
@Override
public void complete(@NotNull final CompleteCallback callback) {
if (mode == CREATE) {
appContext.getWorkspaceRoot().newProject().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
} else if (mode == UPDATE) {
appContext.getWorkspaceRoot().getContainer(Path.valueOf(dataObject.getPath())).then(new Operation<Optional<Container>>() {
@Override
public void apply(Optional<Container> optContainer) throws OperationException {
checkState(optContainer.isPresent(), "Failed to update non existed path");
final Container container = optContainer.get();
if (container.getResourceType() == PROJECT) {
((Project) container).update().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
} else if (container.getResourceType() == FOLDER) {
((Folder) container).toProject().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
}
}
});
} else if (mode == IMPORT) {
appContext.getWorkspaceRoot().newProject().withBody(dataObject).send().thenPromise(new Function<Project, Promise<Project>>() {
@Override
public Promise<Project> apply(Project project) throws FunctionException {
return project.update().withBody(dataObject).send();
}
}).then(addCommands(callback)).catchError(onFailure(callback));
}
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class InMemoryResourceStore method dispose.
/** {@inheritDoc} */
@Override
public void dispose(Path path, boolean withChildren) {
checkArgument(path != null, "Null path occurred");
final Path parent = path.segmentCount() == 1 ? Path.ROOT : path.parent();
Resource[] container = memoryCache.get(parent);
if (container != null) {
int index = -1;
for (int i = 0; i < container.length; i++) {
if (container[i].getName().equals(path.lastSegment())) {
index = i;
break;
}
}
if (index != -1) {
int size = container.length;
int numMoved = container.length - index - 1;
if (numMoved > 0) {
System.arraycopy(container, index + 1, container, index, numMoved);
}
container = copyOf(container, --size);
memoryCache.put(parent, container);
}
}
if (memoryCache.containsKey(path)) {
container = memoryCache.remove(path);
if (container != null && withChildren) {
for (Resource resource : container) {
if (resource instanceof Container) {
dispose(resource.getLocation(), true);
}
}
}
}
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class ResourceImpl method getParentWithMarker.
/** {@inheritDoc} */
@Override
public Optional<Resource> getParentWithMarker(String type) {
checkArgument(!isNullOrEmpty(type), "Invalid marker type occurred");
if (getMarker(type).isPresent()) {
return Optional.<Resource>of(this);
}
Container optParent = getParent();
while (optParent != null) {
Container parent = optParent;
final Optional<Marker> marker = parent.getMarker(type);
if (marker.isPresent()) {
return Optional.<Resource>of(parent);
}
optParent = parent.getParent();
}
return absent();
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class ResourceImpl method getRelatedProject.
/** {@inheritDoc} */
@Override
public Optional<Project> getRelatedProject() {
if (this instanceof Project) {
return of((Project) this);
}
Container optionalParent = getParent();
if (optionalParent == null) {
return absent();
}
Container parent = optionalParent;
while (!(parent instanceof Project)) {
optionalParent = parent.getParent();
if (optionalParent == null) {
return absent();
}
parent = optionalParent;
}
return of((Project) parent);
}
Aggregations