use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class BreakpointManagerImpl method restoreBreakpoints.
private void restoreBreakpoints() {
Storage localStorage = Storage.getLocalStorageIfSupported();
if (localStorage == null) {
return;
}
String data = localStorage.getItem(LOCAL_STORAGE_BREAKPOINTS_KEY);
if (data == null || data.isEmpty()) {
return;
}
List<StorableBreakpointDto> allDtoBreakpoints = dtoFactory.createListDtoFromJson(data, StorableBreakpointDto.class);
Promise<Void> bpPromise = promises.resolve(null);
for (final StorableBreakpointDto dto : allDtoBreakpoints) {
bpPromise.thenPromise(new Function<Void, Promise<Void>>() {
@Override
public Promise<Void> apply(Void ignored) throws FunctionException {
return appContext.getWorkspaceRoot().getFile(dto.getPath()).then(new Function<Optional<File>, Void>() {
@Override
public Void apply(Optional<File> file) throws FunctionException {
if (!file.isPresent()) {
return null;
}
if (dto.getType() == Type.CURRENT) {
doSetCurrentBreakpoint(file.get(), dto.getLineNumber());
} else {
addBreakpoint(new Breakpoint(dto.getType(), dto.getLineNumber(), dto.getPath(), file.get(), dto.isActive()));
}
return null;
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Log.error(getClass(), "Failed to restore breakpoint. ", arg.getCause());
}
});
}
});
}
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class WorkspaceEventsHandler method onWorkspaceStarting.
private void onWorkspaceStarting(final String workspaceId) {
// TODO timer is a workaround. Is needed because for some reason after receiving of event workspace starting
// get workspace event should contain runtime but it doesn't
new Timer() {
@Override
public void run() {
workspaceServiceClient.getWorkspace(workspaceId).then(new Operation<WorkspaceDto>() {
@Override
public void apply(WorkspaceDto workspace) throws OperationException {
String devMachineName = getDevMachineName(workspace);
if (devMachineName != null) {
subscribeOnWsAgentOutputChannel(workspace, devMachineName);
}
workspaceComponent.setCurrentWorkspace(workspace);
loader.show(LoaderPresenter.Phase.STARTING_WORKSPACE_RUNTIME);
eventBus.fireEvent(new WorkspaceStartingEvent(workspace));
}
});
}
}.schedule(1000);
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class CreateWorkspacePresenter method createWorkspace.
private void createWorkspace() {
WorkspaceConfigDto workspaceConfig = getWorkspaceConfig();
workspaceClient.create(workspaceConfig, null).then(new Operation<WorkspaceDto>() {
@Override
public void apply(WorkspaceDto workspace) throws OperationException {
DefaultWorkspaceComponent component = wsComponentProvider.get();
component.startWorkspace(workspace, callback);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
callback.onFailure(new Exception(arg.getCause()));
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class LanguageServerFileTypeRegister method start.
@Override
public void start(final Callback<WsAgentComponent, Exception> callback) {
Promise<List<LanguageDescriptionDTO>> registeredLanguages = serverLanguageRegistry.getSupportedLanguages();
registeredLanguages.then(new Operation<List<LanguageDescriptionDTO>>() {
@Override
public void apply(List<LanguageDescriptionDTO> langs) throws OperationException {
if (!langs.isEmpty()) {
JsArrayString contentTypes = JsArrayString.createArray().cast();
for (LanguageDescriptionDTO lang : langs) {
String primaryExtension = lang.getFileExtensions().get(0);
for (String ext : lang.getFileExtensions()) {
final FileType fileType = new FileType(resources.file(), ext);
fileTypeRegistry.registerFileType(fileType);
editorRegistry.registerDefaultEditor(fileType, editorProvider);
ext2langId.put(ext, lang.getLanguageId());
}
List<String> mimeTypes = lang.getMimeTypes();
if (mimeTypes.isEmpty()) {
mimeTypes = newArrayList("text/x-" + lang.getLanguageId());
}
for (String contentTypeId : mimeTypes) {
contentTypes.push(contentTypeId);
OrionContentTypeOverlay contentType = OrionContentTypeOverlay.create();
contentType.setId(contentTypeId);
contentType.setName(lang.getLanguageId());
contentType.setExtension(primaryExtension);
contentType.setExtends("text/plain");
// highlighting
OrionHighlightingConfigurationOverlay config = OrionHighlightingConfigurationOverlay.create();
config.setId(lang.getLanguageId() + ".highlighting");
config.setContentTypes(contentTypeId);
config.setPatterns(lang.getHighlightingConfiguration());
Logger logger = Logger.getLogger(LanguageServerFileTypeRegister.class.getName());
contentTypeRegistrant.registerFileType(contentType, config);
}
}
orionHoverRegistrant.registerHover(contentTypes, hoverProvider);
orionOccurrencesRegistrant.registerOccurrencesHandler(contentTypes, occurrencesProvider);
}
callback.onSuccess(LanguageServerFileTypeRegister.this);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
callback.onFailure(new Exception(arg.getMessage(), arg.getCause()));
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class GoToSymbolAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
DocumentSymbolParamsDTO paramsDTO = dtoFactory.createDto(DocumentSymbolParamsDTO.class);
TextDocumentIdentifierDTO identifierDTO = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
identifierDTO.setUri(editorAgent.getActiveEditor().getEditorInput().getFile().getLocation().toString());
paramsDTO.setTextDocument(identifierDTO);
activeEditor = (TextEditor) editorAgent.getActiveEditor();
cursorPosition = activeEditor.getDocument().getCursorPosition();
client.documentSymbol(paramsDTO).then(new Operation<List<SymbolInformationDTO>>() {
@Override
public void apply(List<SymbolInformationDTO> arg) throws OperationException {
cachedItems = arg;
presenter.run(GoToSymbolAction.this);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify("Can't fetch document symbols.", arg.getMessage(), StatusNotification.Status.FAIL, StatusNotification.DisplayMode.FLOAT_MODE);
}
});
}
Aggregations