public Object getAttribute(String name) { return desktop.getAttribute(name); }
@SuppressWarnings("unchecked") /*package*/ void onProgress(long cbRead) { int percent = 0; if (_cbtotal > 0) { _cbrcv = cbRead; percent = (int) (_cbrcv * 100 / _cbtotal); } ((Map) _desktop.getAttribute(Attributes.UPLOAD_PERCENT)).put(_key, new Integer(percent)); }
@SuppressWarnings("unchecked") public void onActivate() { if (_desktop != null) { List<Callback> callbacks = (List<Callback>) _desktop.getAttribute(Add_ON_ACTIVATE); if (callbacks != null) { for (Iterator<Callback> it = callbacks.iterator(); it.hasNext();) { Callback callback = it.next(); callback.call(null); it.remove(); } } } }
@SuppressWarnings("unchecked") public void onBeforeDeactivate() { if (_desktop != null) { List<Callback> callbacks = (List<Callback>) _desktop.getAttribute(Add_ON_DEACTIVATE); if (callbacks != null) { for (Iterator<Callback> it = callbacks.iterator(); it.hasNext();) { Callback callback = it.next(); callback.call(null); it.remove(); } } } }
@SuppressWarnings("unchecked") /*package*/ ItemFactory(Desktop desktop, HttpServletRequest request, String key, int sizeThreshold, File repository, org.zkoss.zk.ui.sys.DiskFileItemFactory factory) { super(sizeThreshold, repository); _factory = factory; _desktop = desktop; _key = key; long cbtotal = 0; String ctlen = request.getHeader("content-length"); if (ctlen != null) try { cbtotal = Long.parseLong(ctlen.trim()); //if (log.isDebugEnabled()) log.debug("content-length="+cbtotal); } catch (Throwable ex) { log.warn("", ex); } _cbtotal = cbtotal; if (_desktop.getAttribute(Attributes.UPLOAD_PERCENT) == null) { _desktop.setAttribute(Attributes.UPLOAD_PERCENT, new HashMap()); _desktop.setAttribute(Attributes.UPLOAD_SIZE, new HashMap()); } ((Map) _desktop.getAttribute(Attributes.UPLOAD_PERCENT)).put(key, new Integer(0)); ((Map) _desktop.getAttribute(Attributes.UPLOAD_SIZE)).put(key, new Long(_cbtotal)); }
public String nextComponentUuid(Desktop desktop, Component comp, ComponentInfo compInfo) { String number; if ((number = (String) desktop.getAttribute(ID_NUM)) == null) { number = "0"; desktop.setAttribute(ID_NUM, number); } int i = Integer.parseInt(number); i++; desktop.setAttribute(ID_NUM, String.valueOf(i)); return ComponentsCtrl.toAutoId(ID_PREFIX, i); }
public Object getAttribute(String name, boolean recurse) { Object val = getAttribute(name); Desktop desktop; return val != null || !recurse || (desktop = getDesktop()) == null ? val : desktop.getAttribute(name, true); }
public Object getAttribute(String name, boolean recurse) { Object val = getAttribute(name); return val != null || !recurse || hasAttribute(name) ? val : _desktop != null ? _desktop.getAttribute(name, true) : null; }
/** Process fileitems named file0, file1 and so on. */ @SuppressWarnings("unchecked") private static final void processItems(Desktop desktop, Map<String, Object> params, Map<String, String> attrs) throws IOException { String uuid = attrs.get("uuid"); List<Media> meds = (List<Media>) desktop.getAttribute(uuid); if (meds == null) { meds = new LinkedList<Media>(); desktop.setAttribute(uuid, meds); } final boolean alwaysNative = "true".equals(params.get("native")); final Object fis = params.get("file"); if (fis instanceof FileItem) { meds.add(processItem(desktop, (FileItem) fis, alwaysNative, (org.zkoss.zk.ui.sys.DiskFileItemFactory) params.get("diskFileItemFactory"))); } else if (fis != null) { for (Iterator it = ((List) fis).iterator(); it.hasNext();) { meds.add(processItem(desktop, (FileItem) it.next(), alwaysNative, (org.zkoss.zk.ui.sys.DiskFileItemFactory) params.get("diskFileItemFactory"))); } } }
/** * Adds a callback method to be executed only once after the execution * deactivated. * @param callback * @since 7.0.5 */ public void addOnDeactivate(Callback callback) { Execution exec = Executions.getCurrent(); if (exec == null) throw new IllegalStateException("Execution cannot be null!"); Desktop desktop = exec.getDesktop(); if (desktop != null) { List<Callback> callbacks = (List<Callback>) desktop.getAttribute(Add_ON_DEACTIVATE); if (callbacks == null) { callbacks = new LinkedList<Callback>(); desktop.setAttribute(Add_ON_DEACTIVATE, callbacks); } callbacks.add(callback); } }
public String nextPageUuid(Page page) { final Desktop desktop = page.getDesktop(); String number; if ((number = (String) desktop.getAttribute(ID_NUM)) == null) { number = "0"; desktop.setAttribute(ID_NUM, number); } int i = Integer.parseInt(number); i++; desktop.setAttribute(ID_NUM, String.valueOf(i)); return ComponentsCtrl.toAutoId(ID_PREFIX, i); }
/** * Adds a callback method to be executed only once after the execution * activated. * @param callback * @since 7.0.5 */ public void addOnActivate(Callback callback) { Execution exec = Executions.getCurrent(); if (exec == null) throw new IllegalStateException("Execution cannot be null!"); Desktop desktop = exec.getDesktop(); if (desktop != null) { List<Callback> callbacks = (List<Callback>) desktop.getAttribute(Add_ON_ACTIVATE); if (callbacks == null) { callbacks = new LinkedList<Callback>(); desktop.setAttribute(Add_ON_ACTIVATE, callbacks); } callbacks.add(callback); } }
public Object getAttributeOrFellow(String name, boolean recurse) { Object val = getAttribute(name); if (val != null || hasAttribute(name)) return val; val = getFellowIfAny(name); if (val != null) return val; return recurse && _desktop != null ? _desktop.getAttribute(name, true) : null; }
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; }
public <T extends Event> EventQueue<T> lookup(String name, String scope, boolean autoCreate) { final boolean bAppScope = EventQueues.APPLICATION.equals(scope); final boolean bSessionScope = EventQueues.SESSION.equals(scope); // if the scope is in session or application, it won't need an Execution // to work with this event queue for publishing if (bSessionScope && Sessions.getCurrent() == null) { throw new IllegalStateException("Current session is not available"); } else if (bAppScope || bSessionScope) { return lookup0(name, bAppScope ? (Scope) WebApps.getCurrent() : Sessions.getCurrent(), autoCreate); } else if (EventQueues.DESKTOP.equals(scope)) { final Execution exec = Executions.getCurrent(); if (exec == null) throw new IllegalStateException("Not in an execution"); final Desktop desktop = exec.getDesktop(); Map<String, EventQueue<T>> eqs = cast((Map) desktop.getAttribute(ATTR_EVENT_QUEUES)); if (eqs == null) desktop.setAttribute(ATTR_EVENT_QUEUES, eqs = new HashMap<String, EventQueue<T>>(4)); EventQueue<T> eq = eqs.get(name); if (autoCreate && eq == null) eqs.put(name, eq = new DesktopEventQueue<T>()); if (log.isDebugEnabled()) { log.debug("Lookup event queue: name [{}], scope [{}], autoCreate [{}]", name, scope, autoCreate); } return eq; } else throw new UnsupportedOperationException("Unknown scope: " + scope); }
/** * 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); }
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; } }
/** * Terminate a {@linkplain OperationThread} which is stored in desktop and clear it. * * @param desktop the associated desktop */ public static void destroyWith(Desktop desktop) { if (desktop == null){ throw new NullPointerException("desktop is null"); } if(D.ON && log.debugable()){ log.debug("destory a Operation Thread for desktop:"+desktop); } synchronized(desktop) { if (desktop.isAlive()) {// destroy desktop if it still alive. OperationThread t = (OperationThread) desktop .getAttribute(DESKTOP_KEY); desktop.removeAttribute(DESKTOP_KEY); if (t != null && t.isRunning()) { t.terminate(); } } } }
/** * 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)); } }
public void onClose(Event evt) { if (evt.getData() == null) _result.clear(); else { final Desktop desktop = Executions.getCurrent().getDesktop(); final Configuration config = desktop.getWebApp().getConfiguration(); if (!config.isEventThreadEnabled()) { if (_listener != null) try { _listener.onEvent(new UploadEvent(Events.ON_UPLOAD, null, getResult())); } catch (Exception e) { throw new UiException(e); } else Events.postEvent(new UploadEvent(Events.ON_UPLOAD, (Component) desktop.getAttribute(ATTR_FILEUPLOAD_TARGET), getResult())); } } detach(); }