/** Converts the data of the specified request to a set of Component. * The data is assumed to contain a list of item ID in the * comman-separated format * * @return a set of components. */ @SuppressWarnings("unchecked") public static <T extends Component> Set<T> convertToItems(Desktop desktop, List<String> uuids) { final Set<T> items = new LinkedHashSet<T>(); if (uuids != null) for (String uuid : uuids) { final Component item = desktop.getComponentByUuidIfAny(uuid.trim()); if (item != null) items.add((T) item); //notice that it might be null (since the items might be //removed by the last request) } return items; }
private String nextUuid(Desktop desktop) { for (int count = 0;;) { String uuid = ((DesktopCtrl) desktop).getNextUuid(this); if (desktop.getComponentByUuidIfAny(uuid) == null) return uuid; if (++count > 10000) throw new UiException( "It took too much time to look for unique UUID. Please check the implementation of IdGenerator."); } }
/** Returns the component of the specified ID or UUID. * ID could be the component's ID or UUID. * To specify an UUID, it must be the format: <code>uuid(comp_uuid)</code>. * @return the component, or null if not found * @since 5.0.4 */ public static Component getComponentById(Component comp, String id) { final int len = id.length(); if (id.startsWith("uuid(") && id.charAt(len - 1) == ')') { Desktop dt = comp.getDesktop(); if (dt == null) { final Execution exec = Executions.getCurrent(); if (exec == null) return null; dt = exec.getDesktop(); } return dt != null ? dt.getComponentByUuidIfAny(id.substring(5, len - 1)) : null; } return comp.getFellowIfAny(id); }
/** Converts an AU request to an open event. * @since 5.0.0 */ public static final OpenEvent getOpenEvent(AuRequest request) { final Map<String, Object> data = request.getData(); return new OpenEvent(request.getCommand(), request.getComponent(), AuRequests.getBoolean(data, "open"), request.getDesktop().getComponentByUuidIfAny((String) data.get("reference")), data.get("value")); }
/** * Extracts a select event from the au request. * * @param request The AU request. * @return The select event. */ public static final WonderbarSelectEvent getSelectEvent(AuRequest request) { Map<String, Object> data = request.getData(); Desktop desktop = request.getDesktop(); return new WonderbarSelectEvent(request.getComponent(), (WonderbarItem) desktop.getComponentByUuidIfAny((String) data.get("reference")), null, AuRequests.parseKeys(data)); }
/** Activates this request. * <p>Used internally to identify the component and page after * an execution is activated. Applications rarely need to access this * method. * @since 3.0.5 */ public void activate() throws ComponentNotFoundException { if (_uuid != null) { _comp = _desktop.getComponentByUuidIfAny(_uuid); if (_comp != null) { _page = _comp.getPage(); } else { _page = _desktop.getPageIfAny(_uuid); //it could be page UUID if (_page == null) throw new ComponentNotFoundException("Component not found: " + _uuid); } } }
download = true; //yes, it is for download } else { final Component comp = desktop.getComponentByUuidIfAny(uuid); if (comp == null) { // B65-ZK-1599 response.sendError(HttpServletResponse.SC_GONE,
public boolean service(AuRequest request, boolean everError) { if ("updateResult".equals(request.getCommand())) { final Map<String, Object> data = request.getData(); Desktop desktop = request.getDesktop(); final String uuid = (String) request.getData().get("wid"); final Component comp = desktop.getComponentByUuidIfAny(uuid); final String sid = (String) request.getData().get("sid"); if (comp == null) { Map<String, Integer> percent = cast((Map) desktop.getAttribute(Attributes.UPLOAD_PERCENT)); Map<String, Object> size = cast((Map) desktop.getAttribute(Attributes.UPLOAD_SIZE)); String key = uuid + '_' + sid; if (percent != null) { percent.remove(key); size.put(key, "Upload Aborted"); } return false; } final List<Media> result = cast((List) AuRequests.getUpdateResult(request)); Events.postEvent(new UploadEvent(Events.ON_UPLOAD, comp, UploadUtils.parseResult(result))); Map percent = (Map) desktop.getAttribute(Attributes.UPLOAD_PERCENT); Map size = (Map) desktop.getAttribute(Attributes.UPLOAD_SIZE); final String key = uuid + '_' + sid; percent.remove(key); size.remove(key); return true; } return false; }
final Set<Comboitem> prevSelectedItems = new LinkedHashSet<Comboitem>(); Comboitem prevSeld = (Comboitem) request.getDesktop() .getComponentByUuidIfAny((String) request.getData().get("prevSeld"));
/** Converts an AU request to a key event. * @since 5.0.0 */ public static final KeyEvent getKeyEvent(AuRequest request) { final Map<String, Object> data = request.getData(); return new KeyEvent(request.getCommand(), request.getComponent(), AuRequests.getInt(data, "keyCode", 0), AuRequests.getBoolean(data, "ctrlKey"), AuRequests.getBoolean(data, "shiftKey"), AuRequests.getBoolean(data, "altKey"), AuRequests.getBoolean(data, "metaKey"), request.getDesktop().getComponentByUuidIfAny((String) data.get("reference"))); }
public Object resolveParameter(Annotation anno, Class<?> returnType) { Object val = bindingArgs.get(((BindingParam) anno).value()); if (val != null && returnType.isAssignableFrom(val.getClass())) { //escape return val; } else if (Component.class.isAssignableFrom(returnType) && val instanceof String) { return _root.getDesktop().getComponentByUuidIfAny((String) val); } else if (val instanceof JSONAware) { BindContext bindContext = getBindContext(); Binder binder = getBinder(); @SuppressWarnings("rawtypes") Converter converter = binder.getConverter("jsonBindingParam"); if (converter != null) { try { bindContext.setAttribute(BINDING_PARAM_CALL_TYPE, returnType); @SuppressWarnings("unchecked") Object result = converter.coerceToBean(val, binder.getView(), bindContext); return result; } catch (Exception ex) { return Classes.coerce(returnType, val); } finally { bindContext.setAttribute(BINDING_PARAM_CALL_TYPE, null); } } else return Classes.coerce(returnType, val); } else { return val == null ? null : Classes.coerce(returnType, val); } } });
/** Returns the component representing the area that the click occurs, * or null if not associated with any component. * <p>This method assumes {@link #getArea} is either a component's ID * or a component's UUID. It is true when {@link org.zkoss.zul.Area} is used * to partition a component, such as {@link org.zkoss.zul.Imagemap} and {@link org.zkoss.zul.Chart}. * @since 5.0.4 */ public Component getAreaComponent() { if (_areacomp == null && _area != null) { final Component target = getTarget(); Desktop desktop = null; if (target != null) { _areacomp = target.getFellowIfAny(_area); if (_areacomp != null) return _areacomp; desktop = target.getDesktop(); } if (desktop == null) { final Execution exec = Executions.getCurrent(); if (exec != null) desktop = exec.getDesktop(); } if (desktop != null) return _areacomp = desktop.getComponentByUuidIfAny(_area); } return _areacomp; }
/** Converts an AU request to a select event. * @since 6.0.0 */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static final <T extends Component, E> SelectEvent<T, E> getSelectEvent(AuRequest request, SelectedObjectHandler<T> handler) { final Map<String, Object> data = request.getData(); final Desktop desktop = request.getDesktop(); final List<String> sitems = cast((List) data.get("items")); final Set<T> items = AuRequests.convertToItems(desktop, sitems); final Set<T> prevSelectedItems = (Set<T>) (handler == null ? null : handler.getPreviousSelectedItems()); final Set<T> unselectedItems = (Set<T>) (handler == null ? null : handler.getUnselectedItems()); final Set<E> prevSelectedObjects = (Set<E>) (handler == null ? null : handler.getPreviousSelectedObjects()); final Set<E> unselectedObjects = (Set<E>) (handler == null ? null : handler.getUnselectedObjects()); final Set<E> objs = (Set<E>) (handler == null ? null : handler.getObjects(items)); return new SelectEvent<T, E>(request.getCommand(), request.getComponent(), items, prevSelectedItems, unselectedItems, objs, prevSelectedObjects, unselectedObjects, (T) desktop.getComponentByUuidIfAny((String) data.get("reference")), null, AuRequests.parseKeys(data)); }
final Component c = _page.getDesktop().getComponentByUuidIfAny(newUuid); if (c != null && c != this) throw new UiException("Replicated UUID is not allowed for " + getClass() + ": " + newUuid);
final Desktop desktop = _page.getDesktop(); if (oldpage == null) { if (_uuid == null || _uuid.startsWith(ANONYMOUS_ID) || desktop.getComponentByUuidIfAny(_uuid) != null) _uuid = nextUuid(desktop);
SelectEvent evt = new SelectEvent(Events.ON_SELECT, this, curSeldItems, prevSeldItems, unselectedItems, selectedObjects, prevSeldObjects, unselectedObjects, desktop.getComponentByUuidIfAny((String) data.get("reference")), null, AuRequests.parseKeys(data)); Events.postEvent(evt); } else if (cmd.equals("onInnerWidth")) {
SelectEvent evt = new SelectEvent(Events.ON_SELECT, this, curSeldItems, prevSeldItems, unselectedItems, selectedObjects, prevSeldObjects, unselectedObjects, desktop.getComponentByUuidIfAny((String) data.get("reference")), null, AuRequests.parseKeys(data)); Events.postEvent(evt); } else if (inPagingMold() && cmd.equals(ZulEvents.ON_PAGE_SIZE)) { //since 5.0.2