📄 abstractcomponent.java
字号:
onListenerChanged(desktop, false); if (asap && !isAsapRequired(evtnm)) smartUpdate(getAttrOfEvent(evtnm), null); } return true; } } } } return false; } public boolean addForward( String orgEvent, Component target, String targetEvent) { return addForward0(orgEvent, target, targetEvent); } public boolean addForward( String orgEvent, String targetPath, String targetEvent) { return addForward0(orgEvent, targetPath, targetEvent); } /** * @param target the target. It is either a component, or a string, * which is used internal for implementing {@link #writeObject} */ private boolean addForward0( String orgEvent, Object target, String targetEvent) { if (orgEvent == null) orgEvent = "onClick"; else if (!Events.isValid(orgEvent)) throw new IllegalArgumentException("Illegal event name: "+orgEvent); if (targetEvent == null) targetEvent = orgEvent; else if (!Events.isValid(targetEvent)) throw new IllegalArgumentException("Illegal event name: "+targetEvent); if (_forwards == null) _forwards = new HashMap(4); Object[] info = (Object[])_forwards.get(orgEvent); final List fwds; if (info != null) { fwds = (List)info[1]; for (Iterator it = fwds.iterator(); it.hasNext();) { final Object[] fwd = (Object[])it.next(); if (Objects.equals(fwd[0], target) && Objects.equals(fwd[1], targetEvent)) //found return false; } } else { final ForwardListener listener = new ForwardListener(orgEvent); addEventListener(orgEvent, listener); info = new Object[] {listener, fwds = new LinkedList()}; _forwards.put(orgEvent, info); } fwds.add(new Object[] {target, targetEvent}); return true; } public boolean removeForward( String orgEvent, Component target, String targetEvent) { return removeForward0(orgEvent, target, targetEvent); } public boolean removeForward( String orgEvent, String targetPath, String targetEvent) { return removeForward0(orgEvent, targetPath, targetEvent); } private boolean removeForward0( String orgEvent, Object target, String targetEvent) { if (_forwards != null) { final Object[] info = (Object[])_forwards.get(orgEvent); if (info != null) { final List fwds = (List)info[1]; for (Iterator it = fwds.iterator(); it.hasNext();) { final Object[] fwd = (Object[])it.next(); if (Objects.equals(fwd[0], target) && Objects.equals(fwd[1], targetEvent)) { //found it.remove(); //remove it if (fwds.isEmpty()) { //no more event _forwards.remove(orgEvent); removeEventListener( orgEvent, (EventListener)info[0]); } return true; } } } } return false; } public Namespace getNamespace() { if (this instanceof IdSpace) return _spaceInfo.ns; final IdSpace idspace = getSpaceOwner(); return idspace instanceof Page ? ((Page)idspace).getNamespace(): idspace == null ? null: ((Component)idspace).getNamespace(); } public boolean isListenerAvailable(String evtnm, boolean asap) { if (_listeners != null) { final List l = (List)_listeners.get(evtnm); if (l != null) { if (!asap) return !l.isEmpty(); for (Iterator it = l.iterator(); it.hasNext();) { final EventListener li = (EventListener)it.next(); if (!(li instanceof Deferrable) || !(((Deferrable)li).isDeferrable())) return true; } } } return false; } public Iterator getListenerIterator(String evtnm) { if (_listeners != null) { final List l = (List)_listeners.get(evtnm); if (l != null) return new ListenerIterator(l); } return CollectionsX.EMPTY_ITERATOR; } public void applyProperties() { _def.applyProperties(this); } public ComponentDefinition getDefinition() { return _def; } //-- ComponentCtrl --// public void setComponentDefinition(ComponentDefinition compdef) { if (compdef == null) throw new IllegalArgumentException("null"); if (!compdef.isInstance(this)) throw new IllegalArgumentException("Incompatible "+compdef+" for "+this); _def = compdef; } public ZScript getEventHandler(String evtnm) { final EventHandler evthd = _evthds != null ? _evthds.get(this, evtnm): null; return evthd != null ? evthd.getZScript(): null; } public void addSharedEventHandlerMap(EventHandlerMap evthds) { if (evthds != null && !evthds.isEmpty()) { unshareEventHandlerMap(false); if (_evthds == null) { _evthds = evthds; _evthdsShared = true; } else { _evthds.addAll(evthds); } final Desktop desktop = getDesktop(); if (desktop != null) onListenerChanged(desktop, true); } } private void onListenerChanged(Desktop desktop, boolean listen) { if (listen) { if (Events.isListened(this, Events.ON_CLIENT_INFO, false)) //asap+deferrable response("clientInfo", new AuClientInfo(desktop)); //We always fire event not a root, since we don't like to //check when setParent or setPage is called if (Events.isListened(this, Events.ON_PIGGYBACK, false)) ((DesktopCtrl)desktop).onPiggybackListened(this, true); } else { if (!Events.isListened(this, Events.ON_PIGGYBACK, false)) ((DesktopCtrl)desktop).onPiggybackListened(this, false); } } public void addEventHandler(String name, EventHandler evthd) { if (name == null || evthd == null) throw new IllegalArgumentException("name and evthd required"); unshareEventHandlerMap(true); _evthds.add(name, evthd); } /** Clones the shared event handlers, if shared. * @param autocreate whether to create an event handler map if not available. */ private void unshareEventHandlerMap(boolean autocreate) { if (_evthdsShared) { _evthds = (EventHandlerMap)_evthds.clone(); _evthdsShared = false; } else if (autocreate && _evthds == null) { _evthds = new EventHandlerMap(); } } public Annotation getAnnotation(String annotName) { return _annots != null ? _annots.getAnnotation(annotName): null; } public Annotation getAnnotation(String propName, String annotName) { return _annots != null ? _annots.getAnnotation(propName, annotName): null; } public Collection getAnnotations() { return _annots != null ? _annots.getAnnotations(): Collections.EMPTY_LIST; } public Collection getAnnotations(String propName) { return _annots != null ? _annots.getAnnotations(propName): Collections.EMPTY_LIST; } public List getAnnotatedPropertiesBy(String annotName) { return _annots != null ? _annots.getAnnotatedPropertiesBy(annotName): Collections.EMPTY_LIST; } public List getAnnotatedProperties() { return _annots != null ? _annots.getAnnotatedProperties(): Collections.EMPTY_LIST; } public void addSharedAnnotationMap(AnnotationMap annots) { if (annots != null && !annots.isEmpty()) { unshareAnnotationMap(false); if (_annots == null) { _annots = annots; _annotsShared = true; } else { _annots.addAll(annots); } } } public void addAnnotation(String annotName, Map annotAttrs) { unshareAnnotationMap(true); _annots.addAnnotation(annotName, annotAttrs); } public void addAnnotation(String propName, String annotName, Map annotAttrs) { unshareAnnotationMap(true); _annots.addAnnotation(propName, annotName, annotAttrs); } /** Clones the shared annotations, if shared. * @param autocreate whether to create an annotation map if not available. */ private void unshareAnnotationMap(boolean autocreate) { if (_annotsShared) { _annots = (AnnotationMap)_annots.clone(); _annotsShared = false; } else if (autocreate && _annots == null) { _annots = new AnnotationMap(); } } public void sessionWillPassivate(Page page) { //nothing to do } public void sessionDidActivate(Page page) { sessionDidActivate0(page, this, true); } /** * @param pageLevelIdSpace whether this component's ID space is * at the page level. */ private static void sessionDidActivate0(Page page, AbstractComponent comp, boolean pageLevelIdSpace) { comp._page = page; //Note: we need only to fix the first-level spaceInfo. //Others are handled by readObject if (pageLevelIdSpace && comp._spaceInfo != null) { pageLevelIdSpace = false; comp._spaceInfo.ns.setParent(page.getNamespace()); } for (AbstractComponent p = comp._first; p != null; p = p._next) { sessionDidActivate0(page, p, pageLevelIdSpace); //recursive } } /** Returns the extra controls that tell ZK how to handle this component * specially. * It is used only by component developers. * * <p>It is simpler to override {@link #newExtraCtrl} instead of this. * By use of {@link #newExtraCtrl}, you don't need to care of * cloning and serialization. * * <p>Default: return the object being created by {@link #newExtraCtrl}, * if any. * * @see ComponentCtrl#getExtraCtrl */ public Object getExtraCtrl() { return _xtrl; } /** Used by {@link #getExtraCtrl} to create a client control. * It is used only by component developers. * * <p>Default: return null. * * <p>To provide extra controls, it is simpler to override this method * instead of {@link #getExtraCtrl}. * By use of {@link #newExtraCtrl}, you don't need to care of * cloning and serialization. */ protected Object newExtraCtrl() { return null; } /** Notifies that an {@link WrongValueException} instance is thrown, * and {@link WrongValueException#getComponent} is this component. * It is a callback and the component can store the error message, * show up the custom information, or even 'eat' the exception. * * <p>Default: does nothing but returns ex. * * @param ex the exception being thrown (never null) * @return the exception to throw, or null to ignore the exception * In most cases, just return ex * @since 2.4.0 */ public WrongValueException onWrongValue(WrongValueException ex) { return ex; } //-- Object --// public String toString() { final String clsnm = getClass().getName(); final int j = clsnm.lastIndexOf('.'); return "<"+clsnm.substring(j+1)+' ' +(_id == null || ComponentsCtrl.isAutoId(_id) ? _uuid: _id)+'>'; } public final boolean equals(Object o) { //no more override return this == o; } /** Holds info shared of the same ID space. */ private static class SpaceInfo { private Map attrs = new HashMap(8); //don't create it dynamically because _ip bind it at constructor private SimpleNamespace ns; /** A map of ((String id, Component fellow). */ private Map fellows = new HashMap(32); private SpaceInfo(Component owner) { ns = new SimpleNamespace(owner); init(owner); } private SpaceInfo(Component owner, SimpleNamespace from) { ns = new SimpleNamespace(owner); ns.copy(from); init(owner); } private void init(Component owner) { ns.setVariable("spaceScope", attrs, true); ns.setVariable("spaceOwner", owner, true); } } private class ChildIter implements ListIterator { private AbstractComponent _p, _lastRet; private int _j; private int _modCntSnap; private ChildIter(int index) { if (index < 0 || index > _nChild) throw new IndexOutOfBoundsException("Index: "+index+", Size: "+_nChild); if (index < (_nChild >> 1)) { _p = _first; for (_j = 0; _j < index; _j++) _p = _p._next; } else { _p = null; //means the end of the list for (_j = _nChild; _j > index; _j--) _p = _p != null ? _p._prev: _last; } _modCntSnap = _modCntChd; } public boolean hasNext() { checkComodification(); return _j < _nChild; } public Object next() { if (_j >= _nChild) throw new java.util.NoSuchElementException(); checkComodification(); _lastRet = _p; _p = _p._next; _j++; return _lastRet; } public boolean hasPrevious() { checkComodification(); return _j > 0; } public Object previous() { if (_j <= 0) throw new java.util.NoSuchElementException(); checkComodification(); _lastRet = _p = _p != null ? _p._prev: _last; _j--; return _lastRet; } private void checkComodification() { if (_modCntChd != _modCntSnap) throw new java.util.ConcurrentModificationException(); } public int nextIndex() { return _j; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -