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); } }
/** * 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)); } } } } }
if (property instanceof ValueChangeNotifier) { final ValueChangeNotifier notifier = (ValueChangeNotifier) property; notifier.addValueChangeListener(this); propertyItemMapCache.put(property, item);
@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; }
/** * 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); }