public EProcess() { prc.getEventController().addListener(this, Object.class); }
/** * a new listener will be created to set the new value of this bean to the given beanvalue. * * @param anotherValue beanvalue to bind */ public void bind(final BeanValue<T> anotherValue) { // if (!getType().equals(anotherValue.getType())) // ManagedException.implementationError("binding beanvalues must have the same type", anotherValue.getType()); changeHandler().addListener(new IListener<ChangeEvent>() { @Override public void handleEvent(ChangeEvent changeEvent) { if (changeEvent.hasChanged) { anotherValue.setValue((T) changeEvent.newValue); } } }); }
/** * constructor * @param path for nodes to be notified * @param notification the notification content * @param response any node response * @param responseListener listeners to node responses */ public Notification(String path, Object notification, Map<String, Object> response, IListener<Notification> responseListener) { super(); this.notification = notification; this.path = path; this.response = response; if (responseListener != null) { getResponseController().addListener(responseListener); } }
private void createBinding() { firstValue.changeHandler().addListener(new IListener<ChangeEvent>() { @Override public void handleEvent(ChangeEvent changeEvent) { if (!updating && changeEvent.hasChanged) { try { updating = true; secondValue.setValue(converter.to((FIRST) changeEvent.newValue)); } finally { updating = false; } } } }); secondValue.changeHandler().addListener(new IListener<ChangeEvent>() { @Override public void handleEvent(ChangeEvent changeEvent) { if (!updating && changeEvent.hasChanged) { try { updating = true; firstValue.setValue(converter.from((SECOND) changeEvent.newValue)); } finally { updating = false; } } } }); }
/** * constructor * * @param ovalue orginal value to be bound to this wrapper instance. the value is holding an enum * @param enumValues enumeration values */ public OptionsWrapper(IValueAccess<E> ovalue, E[] enumValues) { super(); assert enumValues.length <= ATTR_NAMES.length : "maximum count of "+ ATTR_NAMES.length + " enumeration values exceeded"; this.enumerations = enumValues; this.ovalue = ovalue; /* * if the value was set from outside, we listen to it to refresh our wrapper and * perhaps other data-bound values */ ovalue.changeHandler().addListener(new IListener<ChangeEvent>() { @SuppressWarnings("unchecked") @Override public void handleEvent(ChangeEvent event) { if (!changingValue) { Object value = event.getSource(); BeanValue.getBeanValue(OptionsWrapper.this, ATTR_NAMES[indexOf((E) value)]).setValue(true); } } }); }
/** * convenience to observe an attribute * * @param name attribute name * @param listener observer */ public void observe(String name, IListener listener) { getAttribute(name).changeHandler().addListener(listener); }
/** * convenience method add a listener to all enumvalues. * * @param wrapper wrapper instance to have an instance using booleans for each enum type that was selected. * @param listener user defined listener to act on selection changes. * @param enumConstants enum constants */ protected void setEnumBooleanListener(OptionsWrapper<?> wrapper, IListener<ChangeEvent> listener, Enum[] enumConstants) { for (int i = 0; i < enumConstants.length; i++) { LOG.debug("adding valuechange-listener for attribute: " + OptionsWrapper.ATTR_NAMES[i]); BeanValue.getBeanValue(wrapper, OptionsWrapper.ATTR_NAMES[i]).changeHandler().addListener(listener); //TODO: listener bei dispose evtl. wieder abbauen! } }
/** * constructor * * @param core {@link #core} * @param connections {@link #connections} */ @SuppressWarnings("rawtypes") public Node(T core, List<IConnection<T, D>> connections) { super(); controller = Net.createEventController(); statistics = new NodeStatistics(); this.core = core; if (connections != null) { this.connections = connections; for (IConnection<T, D> connection : connections) { controller.addListener((IListener) connection); } } else { this.connections = new LinkedList<IConnection<T, D>>(); } }
/** * connect the attribute by the given attribute-name to another attribute through listening to value changes. if the * other attribute is changing, the own attribute will fire a value change, too (without changing the value!) to * inform other listeners, that a dependent attribute was changed. maybe useful for refreshings. the connect 'other' * attribute is accessible though {@link #getConnection(String)}. * * @param attrName the beans attribute name to be connected. the attribute has to be at least of type * {@link IValueAccess}! check it through {@link #getAttribute(String)}. * @param valueToConnect foreign attribute to listen for changes. * @param callback method to be called, if foreign attribute changes. */ public void connect(final String attrName, IValueAccess<?> valueToConnect, final IAction<?> callback, boolean afterChanging) { valueToConnect.changeHandler().addListener( new ValueConnection(this, attrName, valueToConnect, callback, afterChanging), ChangeEvent.class); isconnected = true; }
/** * uses the information of {@link #attributeID} to inject the real {@link AttributeDefinition} into registered * change listeners * * @throws CloneNotSupportedException */ void injectAttributeOnChangeListeners(BeanDefinition beandef) { //provide dependency listeners their attribute-definition if (hasListeners()) { Collection<IListener> listener = changeHandler().getListeners(null); boolean isBean = beandef instanceof Bean; for (IListener l : listener) { if (l instanceof AbstractDependencyListener) { AbstractDependencyListener<?, ?> dl = (AbstractDependencyListener<?, ?>) l; if (isBean) {//create a specific listener instance for the given bean! LOG.debug(beandef.getId() + ": re-assigning dependency-listener-clone " + dl); dl = (AbstractDependencyListener<?, ?>) dl.clone(); Class eventType = changeHandler().getEventType(l); changeHandler().removeListener(l); changeHandler().addListener(dl, eventType); } if (dl.attributeID != null) { String name = StringUtil.substring(dl.attributeID, ".", null); LOG.debug(beandef.getId() + ": resetting value of attribute " + name); dl.setAttribute((AttributeDefinition) beandef.getAttribute(name)); } } } } }