/** * Pops up a command type chooser dialog at the position relative to the browser's client area. * * @param left the left position, in pixels * @param top the top position, in pixels * @return promise that will be resolved with a chosen {@link CommandType} or rejected in case * command type selection has been cancelled */ public Promise<CommandType> show(int left, int top) { final List<CommandType> commandTypes = new ArrayList<>(commandTypeRegistry.getCommandTypes()); if (commandTypes.size() == 1) { return promiseProvider.resolve(commandTypes.get(0)); } commandTypes.sort(comparing(CommandType::getDisplayName)); view.setCommandTypes(commandTypes); view.show(left, top); return promiseProvider.create( Executor.create( (ExecutorBody<CommandType>) (resolve, reject) -> { resolveFunction = resolve; rejectFunction = reject; })); }
@Override protected Promise<List<Node>> getChildrenImpl() { if (!element.getMatches().isEmpty()) { return presenter .computeMatches(this) .then( (List<MatchNode> matches) -> { List<Node> result = new ArrayList<>(matches); result.addAll(computeChildren()); return result; }); } else { return promiseProvider.create( Executor.create( (resolve, reject) -> { resolve.apply(computeChildren()); })); } }
/** * Pops up a dialog for choosing a machine. * * <p><b>Note:</b> if there is only one machine running in the workspace then returned promise * will be resolved with that machine without asking user. * * @return promise that will be resolved with a chosen {@link MachineImpl} or rejected in case * machine selection has been cancelled. */ public Promise<MachineImpl> show() { final WorkspaceImpl workspace = appContext.getWorkspace(); final RuntimeImpl runtime = workspace.getRuntime(); if (runtime != null) { final List<? extends MachineImpl> machines = new ArrayList<>(runtime.getMachines().values()); if (machines.size() == 1) { return promiseProvider.resolve(machines.get(0)); } view.setMachines(machines); } view.show(); return promiseProvider.create( Executor.create( (ExecutorBody<MachineImpl>) (resolve, reject) -> { resolveFunction = resolve; rejectFunction = reject; })); }
@Override protected Promise<List<Node>> getChildrenImpl() { return promiseProvider.create( Executor.create( (resolve, reject) -> { try { resolve.apply(computeChildren()); } catch (Exception e) { reject.apply(JsPromiseError.create(e)); } })); }