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);
}
}
});
}
use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class CopyPasteManager method copyResource.
private Promise<Void> copyResource(final Resource resource, final Path destination) {
//simple copy without overwriting
return resource.copy(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.copy(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);
copyResource(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 copying resource", error.getMessage(), FAIL, FLOAT_MODE);
return promises.resolve(null);
}
}
});
}
use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class InMemoryResourceStore method register.
/** {@inheritDoc} */
@Override
public boolean register(Resource resource) {
checkArgument(resource != null, "Null resource occurred");
final Path parent = resource.getLocation().segmentCount() == 1 ? Path.ROOT : resource.getLocation().parent();
if (!memoryCache.containsKey(parent)) {
memoryCache.put(parent, new Resource[] { resource });
intercept(resource);
return true;
} else {
Resource[] container = memoryCache.get(parent);
final int index = binarySearch(container, resource, NAME_COMPARATOR);
if (index >= 0) {
//update existing resource with new one
container[index] = resource;
intercept(resource);
return false;
} else {
//such resource doesn't exists, then simply add it
//negate inverted index into positive one
final int posIndex = -index - 1;
final int size = container.length;
final Resource[] tmpContainer = copyOf(container, size + 1);
//prepare cell to insert
arraycopy(tmpContainer, posIndex, tmpContainer, posIndex + 1, size - posIndex);
tmpContainer[posIndex] = resource;
container = tmpContainer;
memoryCache.put(parent, container);
intercept(resource);
return true;
}
}
}
use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class InMemoryResourceStore method getAll.
/** {@inheritDoc} */
@Override
public Optional<Resource[]> getAll(Path parent) {
checkArgument(parent != null, "Null path occurred");
if (!memoryCache.containsKey(parent)) {
return absent();
}
Resource[] all = new Resource[0];
for (Map.Entry<Path, Resource[]> setEntry : memoryCache.entrySet()) {
/* There is no need to check compared path if its segment count is less then given one. */
final Path comparedPath = setEntry.getKey();
if (!parent.isPrefixOf(comparedPath)) {
continue;
}
final Resource[] resources = setEntry.getValue();
if (resources == null || resources.length == 0) {
continue;
}
final Resource[] tmpResourcesArr = copyOf(all, all.length + resources.length);
arraycopy(resources, 0, tmpResourcesArr, all.length, resources.length);
all = tmpResourcesArr;
}
if (all.length == 0) {
return of(EMPTY_RESOURCES);
}
return of(all);
}
use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class FindResultGroupNode method getChildrenImpl.
/** {@inheritDoc} */
@Override
protected Promise<List<Node>> getChildrenImpl() {
List<Node> fileNodes = new ArrayList<>();
for (Resource resource : findResults) {
if (resource.getResourceType() != FILE) {
continue;
}
FileNode node = nodeFactory.newFileNode((File) resource, null);
NodePresentation presentation = node.getPresentation(true);
presentation.setInfoText(resource.getLocation().toString());
presentation.setInfoTextWrapper(Pair.of("(", ")"));
presentation.setInfoTextCss("color:" + getEditorInfoTextColor() + ";font-size: 11px");
fileNodes.add(node);
}
//sort nodes by file name
Collections.sort(fileNodes, new NameComparator());
return Promises.resolve(fileNodes);
}
Aggregations