use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class ParametersHintsPresenter method show.
/**
* The method gets method parameters via {@link JavaNavigationService} and then call special method on view to display them.
*
* @param activeEditor
* active editor which contains method or constructor for which parameters will be displayed
*/
public void show(final TextEditor activeEditor) {
final int offset = activeEditor.getCursorOffset();
if (!isCursorInRightPlace(activeEditor, offset)) {
return;
}
VirtualFile file = activeEditor.getEditorInput().getFile();
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
final int lineStartOffset = getLineStartOffset(activeEditor, offset);
navigationService.getMethodParametersHints(project.get().getLocation(), JavaUtil.resolveFQN(file), offset, lineStartOffset).then(new Operation<List<MethodParameters>>() {
@Override
public void apply(List<MethodParameters> parameters) throws OperationException {
if (parameters.isEmpty()) {
return;
}
PositionConverter.PixelCoordinates coordinates = activeEditor.getPositionConverter().offsetToPixel(offset);
view.show(parameters, coordinates.getX(), coordinates.getY());
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
Log.error(getClass(), error.getMessage());
}
});
}
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class OpenImplementationPresenter method actionPerformed.
public void actionPerformed(final Member member) {
if (member.isBinary()) {
final Resource resource = context.getResource();
if (resource == null) {
return;
}
final Optional<Project> project = resource.getRelatedProject();
service.getEntry(project.get().getLocation(), member.getLibId(), member.getRootPath()).then(new Operation<JarEntry>() {
@Override
public void apply(final JarEntry entry) throws OperationException {
service.getContent(project.get().getLocation(), member.getLibId(), Path.valueOf(entry.getPath())).then(new Operation<ClassContent>() {
@Override
public void apply(ClassContent content) throws OperationException {
final String clazz = entry.getName().substring(0, entry.getName().indexOf('.'));
final VirtualFile file = new SyntheticFile(entry.getName(), clazz, content.getContent());
editorAgent.openEditor(file, new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursor(member.getFileRegion());
}
});
}
});
}
});
} else {
context.getWorkspaceRoot().getFile(member.getRootPath()).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
editorAgent.openEditor(file.get(), new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursor(member.getFileRegion());
}
});
}
}
});
}
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
activeEditor.setFocus();
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class MavenMessagesHandler method handleOperations.
private void handleOperations(final DtoFactory factory, final WsAgentStateController wsAgentStateController) {
eventBus.addHandler(WsAgentStateEvent.TYPE, new WsAgentStateHandler() {
@Override
public void onWsAgentStarted(WsAgentStateEvent event) {
wsAgentStateController.getMessageBus().then(new Operation<MessageBus>() {
@Override
public void apply(MessageBus messageBus) throws OperationException {
try {
handleMavenServerEvents(messageBus);
handleMavenArchetype(messageBus);
} catch (WebSocketException e) {
dependencyResolver.hide();
Log.error(getClass(), e);
}
}
});
}
@Override
public void onWsAgentStopped(WsAgentStateEvent event) {
dependencyResolver.hide();
}
});
eventBus.addHandler(WorkspaceStoppedEvent.TYPE, new WorkspaceStoppedEvent.Handler() {
@Override
public void onWorkspaceStopped(WorkspaceStoppedEvent event) {
dependencyResolver.hide();
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class ProcessesPanelPresenterTest method setUp.
@Before
public void setUp() {
DevMachine devMachine = mock(DevMachine.class);
when(devMachine.getId()).thenReturn(WORKSPACE_ID);
when(appContext.getDevMachine()).thenReturn(devMachine);
when(appContext.getWorkspace()).thenReturn(workspace);
when(workspace.getRuntime()).thenReturn(workspaceRuntime);
when(processesPromise.then(Matchers.<Operation<List<MachineProcessDto>>>anyObject())).thenReturn(processesPromise);
when(commandConsoleFactory.create(anyString())).thenReturn(mock(OutputConsole.class));
when(appContext.getWorkspaceId()).thenReturn(WORKSPACE_ID);
when(workspaceAgent.getPartStack(eq(PartStackType.INFORMATION))).thenReturn(partStack);
when(execAgentCommandManager.getProcesses(anyString(), anyBoolean())).thenReturn(promise);
when(promise.then(any(Operation.class))).thenReturn(promise);
presenter = new ProcessesPanelPresenter(view, localizationConstant, resources, eventBus, workspaceAgent, appContext, notificationManager, entityFactory, terminalFactory, commandConsoleFactory, dialogFactory, consoleTreeContextMenuFactory, commandTypeRegistry, sshService, execAgentCommandManager, macroProcessor, dtoFactory);
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class AbstractDebugger method deleteBreakpoint.
@Override
public void deleteBreakpoint(final VirtualFile file, final int lineNumber) {
if (!isConnected()) {
return;
}
LocationDto locationDto = dtoFactory.createDto(LocationDto.class);
locationDto.setLineNumber(lineNumber + 1);
String fqn = pathToFqn(file);
if (fqn == null) {
return;
}
locationDto.setTarget(fqn);
Promise<Void> promise = service.deleteBreakpoint(debugSessionDto.getId(), locationDto);
promise.then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
for (DebuggerObserver observer : observers) {
Breakpoint breakpoint = new Breakpoint(Breakpoint.Type.BREAKPOINT, lineNumber, file.getLocation().toString(), file, false);
observer.onBreakpointDeleted(breakpoint);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Log.error(AbstractDebugger.class, arg.getMessage());
}
});
}
Aggregations