org.zkoss.zk.ui.Desktop.getAttribute()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(249)

本文整理了Java中org.zkoss.zk.ui.Desktop.getAttribute()方法的一些代码示例,展示了Desktop.getAttribute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Desktop.getAttribute()方法的具体详情如下:
包路径:org.zkoss.zk.ui.Desktop
类名称:Desktop
方法名:getAttribute

Desktop.getAttribute介绍

[英]Returns the value of the specified custom attribute associated with the desktop.
[中]返回与桌面关联的指定自定义属性的值。

代码示例

代码示例来源:origin: org.zkoss.zats/zats-mimic

public Object getAttribute(String name) {
  return desktop.getAttribute(name);
}

代码示例来源:origin: org.zkoss.zk/zk

@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));
}

代码示例来源:origin: org.zkoss.zk/zk

@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();
      }
    }
  }
}

代码示例来源:origin: org.zkoss.zk/zk

@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();
      }
    }
  }
}

代码示例来源:origin: org.zkoss.zk/zk

@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));
}

代码示例来源:origin: org.zkoss.zk/zk

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);
}

代码示例来源:origin: org.zkoss.zk/zk

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);
}

代码示例来源:origin: org.zkoss.zk/zk

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;
}

代码示例来源:origin: org.zkoss.zk/zk

/** 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")));
    }
  }
}

代码示例来源:origin: org.zkoss.zk/zk

/**
 * 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);
  }
}

代码示例来源:origin: org.zkoss.zk/zk

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);
}

代码示例来源:origin: org.zkoss.zk/zk

/**
 * 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);
  }
}

代码示例来源:origin: org.zkoss.zk/zk

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;
}

代码示例来源:origin: org.zkoss.zk/zk

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;
}

代码示例来源:origin: org.zkoss.zk/zk

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);
}

代码示例来源:origin: org.carewebframework/org.carewebframework.ext.performance

/**
 * 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);
}

代码示例来源:origin: org.carewebframework/org.carewebframework.ext.performance

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;
  }
}

代码示例来源:origin: org.zkoss.zk/zkex

/**
 * 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();
      }
      
    }
  }
}

代码示例来源:origin: org.zkoss.zk/zk

/**
   * 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));
  }
}

代码示例来源:origin: org.zkoss.zk/zul

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();
}

相关文章