use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class SelectPathPresenter method show.
public void show(Resource[] resources, boolean showFiles, SelectionPathHandler handler) {
checkArgument(resources != null, "Null resources occurred");
if (resources.length == 0) {
view.setStructure(Collections.<Node>emptyList(), showFiles);
return;
}
final List<Node> nodes = new ArrayList<>();
final NodeSettings settings = settingsProvider.getSettings();
for (Resource resource : resources) {
if (resource.getResourceType() == Resource.FILE && !showFiles) {
continue;
}
final Node node;
if (resource.getResourceType() == Resource.FILE) {
node = nodeFactory.newFileNode((File) resource, settings);
} else {
node = nodeFactory.newContainerNode((Container) resource, settings);
}
nodes.add(node);
}
view.setStructure(nodes, showFiles);
this.handler = handler;
view.show();
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class ResourceNode method updatePresentation.
@Override
public void updatePresentation(@NotNull NodePresentation presentation) {
final StringBuilder cssBuilder = new StringBuilder();
final Optional<Marker> presentableTextMarker = getData().getMarker(PresentableTextMarker.ID);
if (presentableTextMarker.isPresent() && getData() instanceof Container) {
presentation.setPresentableText(((PresentableTextMarker) presentableTextMarker.get()).getPresentableText());
} else {
presentation.setPresentableText(getData().getName());
}
if (resourceIsCut) {
cssBuilder.append("opacity:0.5;");
} else {
cssBuilder.append("opacity:1;");
}
SVGResource icon = null;
for (NodeIconProvider iconProvider : nodeIconProviders) {
icon = iconProvider.getIcon(getData());
if (icon != null) {
break;
}
}
if (icon != null) {
presentation.setPresentableIcon(icon);
} else {
if (getData().getResourceType() == FOLDER) {
presentation.setPresentableIcon(getData().getName().startsWith(".") ? nodesResources.hiddenSimpleFolder() : nodesResources.simpleFolder());
} else if (getData().getResourceType() == PROJECT) {
presentation.setPresentableIcon(((Project) getData()).isProblem() ? nodesResources.notValidProjectFolder() : nodesResources.projectFolder());
cssBuilder.append("font-weight:bold;");
} else if (getData().getResourceType() == FILE) {
presentation.setPresentableIcon(nodesResources.file());
}
}
presentation.setPresentableTextCss(cssBuilder.toString());
}
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);
}
}
}
}
}
Aggregations