use of org.eclipse.che.api.promises.client.FunctionException in project che by eclipse.
the class ProjectResolver method resolve.
public Promise<Project> resolve(final Project project) {
return project.resolve().thenPromise(new Function<List<SourceEstimation>, Promise<Project>>() {
@Override
public Promise<Project> apply(List<SourceEstimation> estimations) throws FunctionException {
if (estimations == null || estimations.isEmpty()) {
return promiseProvider.resolve(project);
}
final List<String> primeTypes = newArrayList();
for (SourceEstimation estimation : estimations) {
if (projectTypeRegistry.getProjectType(estimation.getType()).isPrimaryable()) {
primeTypes.add(estimation.getType());
}
}
final MutableProjectConfig config = new MutableProjectConfig(project);
final SourceStorage source = project.getSource();
if (source != null && source.getParameters() != null && source.getParameters().containsKey("keepDir")) {
config.setType(Constants.BLANK_ID);
} else if (primeTypes.isEmpty()) {
return promiseProvider.resolve(project);
} else if (primeTypes.size() == 1) {
config.setType(primeTypes.get(0));
} else {
config.setType(Constants.BLANK_ID);
projectWizard.show(config);
return promiseProvider.resolve(project);
}
return project.update().withBody(config).send();
}
}).catchErrorPromise(new Function<PromiseError, Promise<Project>>() {
@Override
public Promise<Project> apply(PromiseError error) throws FunctionException {
Log.warn(ProjectResolver.class, error.getMessage());
return promiseProvider.resolve(project);
}
});
}
use of org.eclipse.che.api.promises.client.FunctionException 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.api.promises.client.FunctionException 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.api.promises.client.FunctionException in project che by eclipse.
the class LanguageServerSignatureHelp method signatureHelp.
@Override
public Promise<Optional<SignatureHelp>> signatureHelp(Document document, int offset) {
TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, offset);
Promise<SignatureHelpDTO> promise = client.signatureHelp(paramsDTO);
return promise.then(new Function<SignatureHelpDTO, Optional<SignatureHelp>>() {
@Override
public Optional<SignatureHelp> apply(SignatureHelpDTO arg) throws FunctionException {
if (arg == null) {
return Optional.absent();
}
return Optional.<SignatureHelp>of(new SignatureHelpImpl(arg));
}
}).catchError(new Function<PromiseError, Optional<SignatureHelp>>() {
@Override
public Optional<SignatureHelp> apply(PromiseError arg) throws FunctionException {
notificationManager.notify(arg.getMessage(), StatusNotification.Status.FAIL, StatusNotification.DisplayMode.EMERGE_MODE);
return Optional.absent();
}
});
}
use of org.eclipse.che.api.promises.client.FunctionException in project che by eclipse.
the class OccurrencesProvider method computeOccurrences.
@Override
public JsPromise<OrionOccurrenceOverlay[]> computeOccurrences(OrionOccurrenceContextOverlay context) {
final EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
if (activeEditor == null || !(activeEditor instanceof TextEditor)) {
return null;
}
final TextEditor editor = ((TextEditor) activeEditor);
if (!(editor.getConfiguration() instanceof LanguageServerEditorConfiguration)) {
return null;
}
final LanguageServerEditorConfiguration configuration = (LanguageServerEditorConfiguration) editor.getConfiguration();
if (configuration.getServerCapabilities().isDocumentHighlightProvider() == null || !configuration.getServerCapabilities().isDocumentHighlightProvider()) {
return null;
}
final Document document = editor.getDocument();
final TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, context.getStart());
// FIXME: the result should be a Promise<List<DocumentHighlightDTO>> but the typefox API returns a single DocumentHighlightDTO
Promise<DocumentHighlightDTO> promise = client.documentHighlight(paramsDTO);
Promise<OrionOccurrenceOverlay[]> then = promise.then(new Function<DocumentHighlightDTO, OrionOccurrenceOverlay[]>() {
@Override
public OrionOccurrenceOverlay[] apply(DocumentHighlightDTO highlight) throws FunctionException {
if (highlight == null) {
return new OrionOccurrenceOverlay[0];
}
final OrionOccurrenceOverlay[] occurrences = new OrionOccurrenceOverlay[1];
final OrionOccurrenceOverlay occurrence = OrionOccurrenceOverlay.create();
// FIXME: this assumes that the language server will
// compute a range based on 'line 1', ie, the whole
// file content is on line 1 and the location to
// highlight is given by the 'character' position
// only.
occurrence.setStart(highlight.getRange().getStart().getCharacter());
occurrence.setEnd(highlight.getRange().getEnd().getCharacter() + 1);
occurrences[0] = occurrence;
return occurrences;
}
});
return (JsPromise<OrionOccurrenceOverlay[]>) then;
}
Aggregations