/** * @param comp the component. Its desktop must be either null * or the same as desktop. */ public EventProcessor(Desktop desktop, Component comp, Event event) { if (desktop == null || comp == null || event == null) throw new IllegalArgumentException("null"); final Desktop dt = comp.getDesktop(); if (dt != null && desktop != dt) throw new IllegalStateException("Process events for another desktop? " + comp); _desktop = desktop; _comp = comp; _event = event; }
/** Ensure the use of component is correct. */ private void checkDesktop(Component comp) { final Desktop dt = comp.getDesktop(); if (dt != null && dt != _exec.getDesktop()) throw new IllegalStateException( "Access denied: component, " + comp + ", belongs to another desktop: " + dt); }
private static boolean isObsolete(AuRequest request) { final Component comp = request.getComponent(); if (comp != null) { final Desktop dt = comp.getDesktop(); return dt != null && dt != request.getDesktop(); //Since 3.5.0, we allow a component to process events even //if it is detached (due to implementation of EventQueue) } return false; }
private static Desktop getDesktop(Component comp) { final Desktop dt = comp.getDesktop(); if (dt != null) return dt; final Execution exec = Executions.getCurrent(); return exec != null ? exec.getDesktop() : null; }
public void didActivate(Component comp) { if (_rootComp.equals(comp)) { //zk 1442, don't do multiple subscribed if didActivate is called every request (e.x. jboss5) initQueue(); if (_deferredActivator == null) { //defer activation to execution only for the first didActivate when failover comp.getDesktop().addListener(_deferredActivator = new DeferredActivator()); } } }
/** 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); }
public int sendCommand(String command, Map<String, Object> args) { checkInit(); final Set<Property> notifys = new HashSet<Property>(); Event evt = null; //ZK-3133 if (args != null && args.containsKey(BinderCtrl.CLIENT_INFO)) { Map<String, Object> inf = new HashMap<String, Object>(); inf.put("", args.get(BinderCtrl.CLIENT_INFO)); evt = ClientInfoEvent.getClientInfoEvent(new AuRequest(_rootComp.getDesktop(), command, inf)); } //args come from user, we don't eval it. int result = doCommand(_rootComp, null, command, evt, args, notifys); if (result == COMMAND_FAIL_VALIDATE && _validationMessages != null) { notifys.add(new PropertyImpl(_validationMessages, ".", null)); } fireNotifyChanges(notifys); return result; }
public void call(Component host) { host.getDesktop().getWebApp().getConfiguration().afterShadowDetached(se, host); } });
public void call(Component host) { host.getDesktop().getWebApp().getConfiguration().afterShadowAttached(se, host); } });
public void onEvent(Event event) throws Exception { Component target = event.getTarget(); if (target instanceof ComponentCtrl && target.getDesktop() != null) { for (ShadowElement se : new ArrayList<ShadowElement>( ((ComponentCtrl) target).getShadowRoots())) { if (se instanceof HtmlShadowElement) { ((HtmlShadowElement) se).rebuildShadowTree(); } } } else { // cleanup Iterable<EventListener<? extends Event>> eventListeners = target .getEventListeners(ON_REBUILD_SHADOW_TREE_LATER); for (EventListener<? extends Event> listener : eventListeners) { target.removeEventListener(ON_REBUILD_SHADOW_TREE_LATER, listener); } } }
/** * Registers an event sent to the specified target for monitoring. * * @param target The component that will be the target of the event. * @param eventName The name of the event to be monitored. * @param tag The tag to be included in the log entry. * @param displayElapsed If true, the performance information will be sent to the display. */ public static void monitorEvent(Component target, String eventName, String tag, boolean displayElapsed) { Desktop dt = target.getDesktop(); PerformanceData pd = (PerformanceData) dt.getAttribute(PerformanceData.ATTR_PERF_DATA); if (pd == null) { pd = new PerformanceData(dt); dt.setAttribute(PerformanceData.ATTR_PERF_DATA, pd); } pd.monitorEvent(target, eventName, tag, displayElapsed); }
public void setParent(Component parent) { Component host = getShadowHostIfAny(); setParent0(parent); if (host == null) host = getShadowHostIfAny(); if (host != null) { if (parent != null) { host.getDesktop().getWebApp().getConfiguration().afterShadowAttached(this, host); } else { host.getDesktop().getWebApp().getConfiguration().afterShadowDetached(this, host); } } }
/** * Removes the relation points between shadow host and this shadow element. */ public void detach() { Component prevhost = getShadowHostIfAny(); if (_host != null) { ComponentCtrl host = (ComponentCtrl) _host; _host = null; // clear first to avoid endloop ((ComponentCtrl) host).removeShadowRoot(this); onHostDetached((Component) host); } setParent0(null); if (prevhost != null) { if (prevhost.getDesktop() != null) prevhost.getDesktop().getWebApp().getConfiguration().afterShadowDetached(this, prevhost); else { final ShadowElement se = this; ((ComponentCtrl) prevhost).addCallback(AFTER_PAGE_DETACHED, new Callback<Component>() { public void call(Component host) { host.getDesktop().getWebApp().getConfiguration().afterShadowDetached(se, host); } }); } } }
protected void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url) throws IOException { if (url == null) { return; //skip } final Event evt = (Event) (request).getSession().getAttribute(ZkEventExceptionFilter.EVENT); final Component comp = evt.getTarget(); final String updateURI = comp.getDesktop().getUpdateURI(null); if (url.indexOf(updateURI) >= 0) { //saved request Events.postEvent(new Event(ON_LOGIN_OK, comp, null)); //post onLoginOK event if (_resendZkEvent) { (request).getSession().removeAttribute(ZkEventExceptionFilter.EVENT); Events.postEvent(evt); } return; } //must redirect if (url.startsWith("http://") || url.startsWith("https://")) { Executions.getCurrent().sendRedirect(url); return; } //other url, assume login fail if (!comp.isListenerAvailable(ZkAuthenticationEntryPoint.ON_ACEGILOGIN, true)) { final EventListener<Event> listener = new ShowWindowEventListener<Event>(); comp.setAttribute(ZkAuthenticationEntryPoint.ON_ACEGILOGIN, listener); comp.addEventListener(ZkAuthenticationEntryPoint.ON_ACEGILOGIN, listener); } Events.postEvent(new Event(ZkAuthenticationEntryPoint.ON_ACEGILOGIN, comp, url)); }
private EventLog getEventLog(Event event) { Component target = event.getTarget(); if (target != null) { Desktop desktop = target.getDesktop(); if (desktop == null) { desktop = Executions.getCurrent().getDesktop(); } if (desktop != null) { PerformanceData pd = (PerformanceData) desktop.getAttribute(PerformanceData.ATTR_PERF_DATA); if (pd != null) { return pd.getEventLog(event); } } } return null; } }
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; }
/** * Creates an instance of {@link UploadEvent} based on the event name and component, * the {@link UploadEvent} contains the latest upload media from user. * Internal Use Only. * * @param name event name * @param component component that triggers the upload event * @return upload event * @since 8.6.0 */ public static UploadEvent getLatestUploadEvent(String name, Component component) { Desktop desktop = component.getDesktop(); String uuid = component.getUuid(); final List<Media> result = cast((List) desktop.getAttribute(uuid)); desktop.removeAttribute(uuid); return new UploadEvent(name, desktop.getComponentByUuid(uuid), UploadUtils.parseResult(result)); } }
/** Evaluates the value to an Object. * Note: it does NOT call {@link #isEffective} and it doesn't coerce * the result (i.e., Object.class is assumed). */ public Object getValue(Component comp) { if (_value != null) return _value.getValue(_evalr, comp); Desktop desktop = comp.getDesktop(); Page page; if (desktop == null) { Execution exec = Executions.getCurrent(); if (exec == null) throw new IllegalStateException("Not attached, nor execution"); desktop = exec.getDesktop(); page = ((ExecutionCtrl) exec).getCurrentPage(); } else { page = comp.getPage(); } return ((WebAppCtrl) desktop.getWebApp()).getUiEngine().getNativeContent(comp, _navval.getChildren(), ((Native) _navval.newInstance(page, comp)).getHelper()); }
return _component == null ? null : _component.getPage(); case DESKTOP: return _component == null ? null : _component.getDesktop(); case SESSION: return _component == null ? null : Components.getImplicit(_component, "session");