/** Adds the event handler for the specified event name. * <p>Note: the new handler won't overwrite the previous one, * unless {@link EventHandler#getCondition} is the same. * Rather, the new handler is appended to the list. You can retreive * list by invoking {@link #getAll}. * * @see #getAll * @since 3.0.0 */ public void add(String evtnm, EventHandler evthd) { if (evtnm == null || evthd == null) throw new IllegalArgumentException("null"); if (_evthds == null) _evthds = new HashMap<String, List<EventHandler>>(4); List<EventHandler> ehl = _evthds.get(evtnm); if (ehl == null) { _evthds.put(evtnm, ehl = new LinkedList<EventHandler>()); } else { for (Iterator<EventHandler> it = ehl.iterator(); it.hasNext();) { final EventHandler eh = it.next(); if (Objects.equals(eh.getCondition(), evthd.getCondition())) it.remove(); //replicate } } ehl.add(evthd); }
public ZScript getEventHandler(String evtnm) { final EventHandler evthd = _auxinf != null && _auxinf.evthds != null ? _auxinf.evthds.get(this, evtnm) : null; return evthd != null ? evthd.getZScript() : null; }
/** Returns the first effective event handler of the specified event name, * or null if not available. * * <p>It checks whether an event handler is effective by calling * {@link EventHandler#isEffective(Component)}. * * @param comp the component used to evaluate whether an event handler * is effective. * @see EventHandler#isEffective(Component) * @since 3.0.0 */ public EventHandler get(Component comp, String evtnm) { if (_evthds != null) { final List<EventHandler> ehl = _evthds.get(evtnm); if (ehl != null) for (EventHandler eh : ehl) if (eh.isEffective(comp)) return eh; } return null; }
/** Adds an event handler. * * @param name the event name. * @param zscript the script. */ public void addEventHandler(String name, ZScript zscript, ConditionImpl cond) { if (name == null || zscript == null) throw new IllegalArgumentException("name and zscript cannot be null"); //if (!Events.isValid(name)) // throw new IllegalArgumentException("Invalid event name: "+name); //AbstractParser has checked it, so no need to check again final EventHandler evthd = new EventHandler(_evalr, zscript, cond); if (_evthds == null) _evthds = new EventHandlerMap(); _evthds.add(name, evthd); }
final ZScript zscript = ZScript.parseContent((String)entry.getValue()); ((ComponentCtrl)_comp).addEventHandler( (String)entry.getKey(), new EventHandler(zscript,null));
final ZScript zscript = evthd != null ? evthd.getZScript() : null; if (zscript != null) { execinf.update(null, null, zscript);