Пример #1
0
  /*package*/ void registerLoadEvents(Component comp) {
    if (isLoadable()) { // bug 1804356
      if (_loadWhenEvents != null) {
        for (String expr : _loadWhenEvents) {
          final Object[] objs = ComponentsCtrl.parseEventExpression(comp, expr, comp, false);
          // objs[0] component, objs[1] event name
          final Component target = (Component) objs[0];
          final String evtname = (String) objs[1];
          if (target == null) {
            throw new NullPointerException("component not found , expr is " + expr);
          }
          LoadEventListener listener =
              (LoadEventListener) target.getAttribute("zk.LoadEventListener." + evtname);
          if (listener == null) {
            listener = new LoadEventListener();
            target.setAttribute("zk.LoadEventListener." + evtname, listener);
            target.addEventListener(1000, evtname, listener);
          }
          listener.addDataTarget(this, comp);
        }
      }
      if (_loadAfterEvents != null) {
        for (String expr : _loadAfterEvents) {
          final Object[] objs = ComponentsCtrl.parseEventExpression(comp, expr, comp, false);
          // objs[0] component, objs[1] event name
          final Component target = (Component) objs[0];
          final String evtname = (String) objs[1];

          LoadAfterEventListener listener =
              (LoadAfterEventListener) target.getAttribute("zk.LoadAfterEventListener." + evtname);
          if (listener == null) {
            listener = new LoadAfterEventListener();
            target.setAttribute("zk.LoadAfterEventListener." + evtname, listener);
            target.addEventListener(evtname, listener);
            target.addEventListener(evtname + "LoadAfter", listener);
          }
          listener.addDataTarget(this, comp);
        }
      }
    }
  }
Пример #2
0
  /*package*/ void registerSaveEvents(Component comp) {
    if (isSavable()) { // bug 1804356
      if (_saveWhenEvents != null) {
        for (String expr : _saveWhenEvents) {
          final Object[] objs = ComponentsCtrl.parseEventExpression(comp, expr, comp, false);
          // objs[0] component, objs[1] event name
          final Component target = (Component) objs[0];
          final String evtname = (String) objs[1];

          SaveEventListener listener =
              (SaveEventListener) target.getAttribute("zk.SaveEventListener." + evtname);
          if (listener == null) {
            listener = new SaveEventListener();
            target.setAttribute("zk.SaveEventListener." + evtname, listener);
            target.addEventListener(1000, evtname, listener);
          }
          listener.addDataTarget(this, comp);
        }
      }
      if (_saveAfterEvents != null) {
        for (final Iterator it = _saveAfterEvents.iterator(); it.hasNext(); ) {
          final String expr = (String) it.next();
          final Object[] objs = ComponentsCtrl.parseEventExpression(comp, expr, comp, false);
          // objs[0] component, objs[1] event name
          final Component target = (Component) objs[0];
          final String evtname = (String) objs[1];

          SaveAfterEventListener listener =
              (SaveAfterEventListener) target.getAttribute("zk.SaveAfterEventListener." + evtname);
          if (listener == null) {
            listener = new SaveAfterEventListener();
            target.setAttribute("zk.SaveAfterEventListener." + evtname, listener);
            target.addEventListener(evtname, listener);
            target.addEventListener(evtname + "SaveAfter", listener);
          }
          listener.addDataTarget(this, comp);
        }
      }
    }
  }