&& Property.ValueChangeNotifier.class .isAssignableFrom(dataSource.getClass())) { ((Property.ValueChangeNotifier) dataSource).removeListener(this); ((Property.ValueChangeNotifier) dataSource).addListener(this);
if (property instanceof ValueChangeNotifier) { final ValueChangeNotifier notifier = (ValueChangeNotifier) property; notifier.addValueChangeListener(this); propertyItemMapCache.put(property, item); if (property instanceof ValueChangeNotifier) { final ValueChangeNotifier notifier = (ValueChangeNotifier) property; notifier.removeValueChangeListener(this); propertyItemMapCache.remove(property);
if (dataSource instanceof Property.ValueChangeNotifier) { ((Property.ValueChangeNotifier) dataSource) .removeListener(this); ((Property.ValueChangeNotifier) dataSource).addListener(this);
Property prop = this.innerItem.getItemProperty(propId); if(prop instanceof Property.ValueChangeNotifier) { ((Property.ValueChangeNotifier)prop).removeListener(changeHandler); Property prop = this.innerItem.getItemProperty(propId); if(prop instanceof Property.ValueChangeNotifier) { ((Property.ValueChangeNotifier)prop).addListener(changeHandler);
/** * Constructor * @param item Item * @param itemStore Item store */ public ItemPropertyValueChangeListener(Item item, ItemStore<Item> itemStore) { super(); this.item = new WeakReference<>(item); this.itemStore = itemStore; if (item != null) { // add value change listener to track property modifications Collection<?> itemPropertyIds = item.getItemPropertyIds(); if (itemPropertyIds != null) { trackedItemProperties = new HashSet<>(itemPropertyIds.size()); for (Object itemPropertyId : itemPropertyIds) { Property<?> itemProperty = item.getItemProperty(itemPropertyId); if (itemProperty instanceof ValueChangeNotifier) { ((ValueChangeNotifier) itemProperty).addValueChangeListener(this); trackedItemProperties.add(new WeakReference<>(itemProperty)); } } } } }
@SuppressWarnings("unchecked") @Override public void setPropertyDataSource(@SuppressWarnings("rawtypes") Property newDataSource) { // Stops listening the old data source changes if (dataSource != null && Property.ValueChangeNotifier.class.isAssignableFrom(dataSource.getClass())) { ((Property.ValueChangeNotifier) dataSource).removeValueChangeListener(this); } // Check if the current converter is compatible. if (newDataSource != null && !ConverterUtil.canConverterPossiblyHandle(getConverter(), getType(), newDataSource.getType())) { // There is no converter set or there is no way the current converter can be compatible Converter<T, Object> c = ConverterUtil.getConverter(getType(), newDataSource.getType(), getSession()); setConverter(c); } dataSource = newDataSource; if (dataSource != null) { // Update value from the data source updateValueFromDataSource(); } // Listens the new data source if (dataSource != null && Property.ValueChangeNotifier.class.isAssignableFrom(dataSource.getClass())) { ((Property.ValueChangeNotifier) dataSource).addValueChangeListener(this); } markAsDirty(); }
/** * Generates cell component. * * @param source The table this cell is generated for. * @param itemId ID of the item this cell is presenting property of. * @param columnId ID of the column this cell is located at. * @return Component used to render this cell. */ public Component generateCell(final Table source, final Object itemId, final Object columnId) { Property statusProperty = source.getItem(itemId).getItemProperty(columnId); noneIconResource = new ClassResource(QueryItemStatusColumnGenerator.class, "images/textfield.png"); addedIconResource = new ClassResource(QueryItemStatusColumnGenerator.class, "images/textfield_add.png"); modifiedIconResource = new ClassResource(QueryItemStatusColumnGenerator.class, "images/textfield_rename.png"); removedIconResource = new ClassResource(QueryItemStatusColumnGenerator.class, "images/textfield_delete.png"); statusIcon = new Image(null, noneIconResource); statusIcon.setHeight("16px"); if (statusProperty instanceof ValueChangeNotifier) { ValueChangeNotifier notifier = (ValueChangeNotifier) statusProperty; notifier.addValueChangeListener(this); } refreshImage(statusProperty); return statusIcon; }
/** * Refreshes the view by clearing cache, discarding buffered changes and * current query instance. New query is created on demand. */ @Override public void refresh() { for (final Property property : propertyItemMapCache.keySet()) { if (property instanceof ValueChangeNotifier) { final ValueChangeNotifier notifier = (ValueChangeNotifier) property; notifier.removeValueChangeListener(this); } } query = null; batchCount = 0; itemIdList = null; itemCache.clear(); itemCacheAccessLog.clear(); propertyItemMapCache.clear(); discard(); }
/** * Adapt a {@link ValueHolder} {@link com.holonplatform.vaadin7.components.ValueHolder.ValueChangeListener} and * register it in given notifier. * @param <V> Value type * @param source Source {@link ValueHolder} * @param notifier Actual {@link ValueChangeNotifier} * @param listener Listener to adapt * @return Listener registration */ public static <V> Registration adapt(ValueHolder<V> source, ValueChangeNotifier notifier, com.holonplatform.vaadin7.components.ValueHolder.ValueChangeListener<V> listener) { ObjectUtils.argumentNotNull(notifier, "ValueChangeNotifier must be not null"); ObjectUtils.argumentNotNull(listener, "ValueChangeListener must be not null"); final com.vaadin.data.Property.ValueChangeListener vcl = new ValueChangeListenerAdapter<>(source, listener); notifier.addValueChangeListener(vcl); return new ValueChangeNotifierRegistration(notifier, vcl); }
@Override public void remove() { notifier.removeValueChangeListener(listener); }
/** * Detach this listener from item properties */ public void detach() { if (trackedItemProperties != null) { for (WeakReference<Property<?>> itemProperty : trackedItemProperties) { Property<?> property = itemProperty.get(); if (property != null) { ((ValueChangeNotifier) property).removeValueChangeListener(this); } } } }
public void addListener(ValueChangeListener listener) { // if possible, listener for the original datasource values, not the // wrapped field converted values if (converter != null && converter.getPropertyDataSource() instanceof Property.ValueChangeNotifier) { ((Property.ValueChangeNotifier) converter.getPropertyDataSource()) .addListener(listener); } else if (property instanceof Property.ValueChangeNotifier) { ((Property.ValueChangeNotifier) property).addListener(listener); } else { wrappedField.addListener(listener); } }
private void setScaleDataSource(Property<Double> scale) { // Listens the new data source if possible if (scale != null && Property.ValueChangeNotifier.class .isAssignableFrom(scale.getClass())) { ((Property.ValueChangeNotifier) scale).addValueChangeListener(this); } }
public void addListener(ValueChangeListener listener) { /* * This operation affects ALL properties, so we have to iterate over the * list of ids instead of the map. */ for (String propertyId : getItemPropertyIds()) { ((Property.ValueChangeNotifier) getItemProperty(propertyId)) .addListener(listener); } }
public void removeListener(ValueChangeListener listener) { /* * This operation affects ALL properties, so we have to iterate over the * list of ids instead of the map. */ for (String propertyId : getItemPropertyIds()) { ((Property.ValueChangeNotifier) getItemProperty(propertyId)) .removeListener(listener); } } }
public void removeListener(ValueChangeListener listener) { // see addListener() if (converter != null && converter.getPropertyDataSource() instanceof Property.ValueChangeNotifier) { ((Property.ValueChangeNotifier) converter.getPropertyDataSource()) .removeListener(listener); } else if (property instanceof Property.ValueChangeNotifier) { ((Property.ValueChangeNotifier) property).removeListener(listener); } else { wrappedField.removeListener(listener); } }