use of org.eclipse.che.ide.resource.Path 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.resource.Path 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.resource.Path in project che by eclipse.
the class ProjectImporter method importProject.
public void importProject(final CompleteCallback callback, MutableProjectConfig projectConfig) {
final Path path = !isNullOrEmpty(projectConfig.getPath()) ? Path.valueOf(projectConfig.getPath()) : !isNullOrEmpty(projectConfig.getName()) ? Path.valueOf(projectConfig.getName()).makeAbsolute() : null;
checkState(path != null, "Import path is undefined");
startImport(path, projectConfig.getSource()).then(new Operation<Project>() {
@Override
public void apply(Project arg) throws OperationException {
if (callback != null) {
callback.onCompleted();
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (callback != null) {
callback.onFailure(arg.getCause());
}
}
});
}
use of org.eclipse.che.ide.resource.Path 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.resource.Path 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);
}
}
});
}
Aggregations