* ID of the Property to retrieve
* @return Property with the given ID or <code>null</code>
*/
- public Property<?> getContainerProperty(Object itemId, Object propertyId);
+ public Property getContainerProperty(Object itemId, Object propertyId);
/**
* Gets the data type of all Properties identified by the given Property ID.
* identifier of the Property to get
* @return the Property with the given ID or <code>null</code>
*/
- public Property<?> getItemProperty(Object id);
+ public Property getItemProperty(Object id);
/**
* Gets the collection of IDs of all Properties stored in the Item.
* @throws Property.ReadOnlyException
* if the object is in read-only mode
*/
- public void setValue(Object newValue) throws Property.ReadOnlyException;
+ public void setValue(T newValue) throws Property.ReadOnlyException;
/**
* Returns the type of the Property. The methods <code>getValue</code> and
* If the property was not found in the item or no item has been
* set
*/
- protected Property<?> getItemProperty(Object propertyId)
- throws BindException {
+ protected Property getItemProperty(Object propertyId) throws BindException {
Item item = getItemDataSource();
if (item == null) {
throw new BindException("Could not lookup property with id "
* java.lang.Object)
*/
@Override
- public Property<?> getContainerProperty(Object itemId, Object propertyId) {
+ public Property getContainerProperty(Object itemId, Object propertyId) {
Item item = getItem(itemId);
if (item == null) {
return null;
* documentation from implemented interface.
*/
@Override
- public Property<?> getContainerProperty(Object itemId, Object propertyId) {
+ public Property getContainerProperty(Object itemId, Object propertyId) {
return container.getContainerProperty(itemId, propertyId);
}
* documentation from implemented interface.
*/
@Override
- public Property<?> getContainerProperty(Object itemId, Object propertyId) {
+ public Property getContainerProperty(Object itemId, Object propertyId) {
return container.getContainerProperty(itemId, propertyId);
}
* @return the requested property's value, or <code>null</code>
*/
@Override
- public Property<?> getContainerProperty(Object itemId, Object propertyId) {
+ public Property getContainerProperty(Object itemId, Object propertyId) {
if (!(itemId instanceof File)) {
return null;
* here, we use the default documentation from implemented interface.
*/
@Override
- public Property<?> getItemProperty(Object id) {
+ public Property getItemProperty(Object id) {
return getContainerProperty(file, id);
}
* java.lang.Object)
*/
@Override
- public Property<?> getContainerProperty(Object itemId, Object propertyId) {
+ public Property getContainerProperty(Object itemId, Object propertyId) {
if (!containsId(itemId)) {
return null;
}
* @see com.vaadin.data.Item#getItemProperty(java.lang.Object)
*/
@Override
- public Property<?> getItemProperty(Object id) {
+ public Property getItemProperty(Object id) {
return new IndexedContainerProperty(itemId, id);
}
*
* @since 3.0
*/
- private class IndexedContainerProperty implements Property<Object>,
+ private class IndexedContainerProperty<T> implements Property<T>,
Property.ValueChangeNotifier {
/**
* @see com.vaadin.data.Property#getType()
*/
@Override
- public Class<?> getType() {
- return types.get(propertyId);
+ public Class<T> getType() {
+ return (Class<T>) types.get(propertyId);
}
/*
* @see com.vaadin.data.Property#getValue()
*/
@Override
- public Object getValue() {
- return items.get(itemId).get(propertyId);
+ public T getValue() {
+ return (T) items.get(itemId).get(propertyId);
}
/*
* @see #invokeSetMethod(Object)
*/
@Override
- @SuppressWarnings("unchecked")
- public void setValue(Object newValue) throws Property.ReadOnlyException {
+ public void setValue(T newValue) throws Property.ReadOnlyException {
// Checks the mode
if (isReadOnly()) {
throw new Property.ReadOnlyException();
}
- // Checks the type of the value
- if (newValue != null && !type.isAssignableFrom(newValue.getClass())) {
- throw new IllegalArgumentException(
- "Invalid value type for ObjectProperty.");
- }
-
- invokeSetMethod((T) newValue);
+ invokeSetMethod(newValue);
fireValueChange();
}
* @see #invokeSetMethod(Object)
*/
@Override
- public void setValue(Object newValue) throws ReadOnlyException {
+ public void setValue(T newValue) throws ReadOnlyException {
// Checks the mode
if (isReadOnly()) {
throw new Property.ReadOnlyException();
}
- // Checks the type of the value
- if (newValue != null && !type.isAssignableFrom(newValue.getClass())) {
- throw new IllegalArgumentException(
- "Invalid value type for NestedMethodProperty.");
- }
-
- invokeSetMethod((T) newValue);
+ invokeSetMethod(newValue);
fireValueChange();
}
* read-only mode
*/
@Override
- @SuppressWarnings("unchecked")
- public void setValue(Object newValue) throws Property.ReadOnlyException {
+ public void setValue(T newValue) throws Property.ReadOnlyException {
// Checks the mode
if (isReadOnly()) {
throw new Property.ReadOnlyException();
}
- // Checks the type of the value
- if (newValue != null && !type.isAssignableFrom(newValue.getClass())) {
- throw new IllegalArgumentException("Invalid value type "
- + newValue.getClass().getName()
- + " for ObjectProperty of type " + type.getName() + ".");
- }
-
- // the cast is safe after an isAssignableFrom check
- this.value = (T) newValue;
+ this.value = newValue;
fireValueChange();
}
}
@Override
- public void setValue(Object newValue) throws ReadOnlyException {
+ public void setValue(String newValue) throws ReadOnlyException {
if (dataSource == null) {
return;
}
* @return the Property with the given ID or <code>null</code>
*/
@Override
- public Property<?> getItemProperty(Object id) {
+ public Property getItemProperty(Object id) {
return map.get(id);
}
* @see com.vaadin.data.Property#setValue(java.lang.Object)
*/
@Override
- public void setValue(Object newValue) throws ReadOnlyException {
+ public void setValue(String newValue) throws ReadOnlyException {
if (isReadOnly()) {
throw new ReadOnlyException();
}
}
@Override
- public void setValue(Object newValue) throws ReadOnlyException {
+ public void setValue(T newValue) throws ReadOnlyException {
// Causes a value change to be sent to this listener which in turn fires
// a new value change event for this property
wrappedProperty.setValue(newValue);
}
@Override
- public Property<?> getItemProperty(Object id) {
+ public Property getItemProperty(Object id) {
if (id instanceof String && id != null) {
for (ColumnProperty cp : properties) {
if (id.equals(cp.getPropertyId())) {
*/
@Override
- public Property<?> getContainerProperty(Object itemId, Object propertyId) {
+ public Property getContainerProperty(Object itemId, Object propertyId) {
Item item = getItem(itemId);
if (item == null) {
return null;
* @throws Property.ReadOnlyException
*/
@Override
- public void setValue(Object newFieldValue)
- throws Property.ReadOnlyException, Converter.ConversionException {
- // This check is needed as long as setValue accepts Object instead of T
- if (newFieldValue != null) {
- if (!getType().isAssignableFrom(newFieldValue.getClass())) {
- throw new Converter.ConversionException("Value of type "
- + newFieldValue.getClass() + " cannot be assigned to "
- + getType().getName());
- }
- }
- setValue((T) newFieldValue, false);
+ public void setValue(T newFieldValue) throws Property.ReadOnlyException,
+ Converter.ConversionException {
+ setValue(newFieldValue, false);
}
/**
* @see com.vaadin.data.Container#getContainerProperty(Object, Object)
*/
@Override
- public Property<?> getContainerProperty(Object itemId, Object propertyId) {
+ public Property getContainerProperty(Object itemId, Object propertyId) {
return items.getContainerProperty(itemId, propertyId);
}
}
@Override
- public void setValue(Object newValue) throws ReadOnlyException {
+ public void setValue(String newValue) throws ReadOnlyException {
super.setValue(newValue);
/*
* Make sure w reset lastKnownTextContent field on value change. The
}
@Override
- public Field<?> createField(Container container, Object itemId,
+ public Field createField(Container container, Object itemId,
Object propertyId, Component uiContext) {
- Property<?> containerProperty = container.getContainerProperty(itemId,
+ Property containerProperty = container.getContainerProperty(itemId,
propertyId);
Class<?> type = containerProperty.getType();
Field<?> field = createFieldByPropertyType(type);
* @see com.vaadin.data.Item#getItemProperty(Object)
*/
@Override
- public Property<?> getItemProperty(Object id) {
+ public Property getItemProperty(Object id) {
final Field<?> field = fields.get(id);
if (field == null) {
// field does not exist or it is not (yet) created for this property
* @param propertyId
* the id of the property.
*/
- public Field<?> getField(Object propertyId) {
+ public Field getField(Object propertyId) {
return fields.get(propertyId);
}
* the New value of the label.
*/
@Override
- public void setValue(Object newStringValue) {
- if (newStringValue != null && newStringValue.getClass() != String.class) {
- throw new Converter.ConversionException("Value of type "
- + newStringValue.getClass() + " cannot be assigned to "
- + String.class.getName());
- }
+ public void setValue(String newStringValue) {
if (getPropertyDataSource() == null) {
- getState().text = (String) newStringValue;
+ getState().text = newStringValue;
} else {
throw new IllegalStateException(
"Label is only a Property.Viewer and cannot update its data source");
* @see com.vaadin.ui.AbstractField#setValue()
*/
@Override
- public void setValue(Object newValue) {
+ public void setValue(Number newValue) {
if (dataSource == null) {
throw new IllegalStateException("Datasource must be set");
}
}
@Override
- public void setValue(Object newFieldValue) {
- if (newFieldValue instanceof Number) {
- // Support setting all types of Numbers
- newFieldValue = ((Number) newFieldValue).doubleValue();
- }
+ public void setValue(Double newFieldValue) {
super.setValue(newFieldValue);
- // The cast is safe if the above call returned without throwing
- getState().value = (Double) newFieldValue;
+ getState().value = newFieldValue;
}
/**
}
@Override
- public void setValue(Object newValue) throws ReadOnlyException {
+ public void setValue(String newValue) throws ReadOnlyException {
throw new ReadOnlyException();
}
assertEquals("abc", paulaBean.getFirstName());
}
- public void testFailingConversion() {
- TextField tf = new TextField();
- tf.setConverter(new Converter<String, Integer>() {
-
- @Override
- public Integer convertToModel(String value, Locale locale) {
- throw new ConversionException("Failed");
- }
-
- @Override
- public String convertToPresentation(Integer value, Locale locale) {
- throw new ConversionException("Failed");
- }
-
- @Override
- public Class<Integer> getModelType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Class<String> getPresentationType() {
- // TODO Auto-generated method stub
- return null;
- }
- });
- try {
- tf.setValue(1);
- fail("setValue(Integer) should throw an exception");
- } catch (Converter.ConversionException e) {
- // OK, expected
- }
- }
-
public void testIntegerStringConversion() {
TextField tf = new TextField();
};
};
- Property property = new AbstractProperty() {
+ Property<String> property = new AbstractProperty<String>() {
@Override
- public Object getValue() {
+ public String getValue() {
return null;
}
@Override
- public void setValue(Object newValue) throws ReadOnlyException,
+ public void setValue(String newValue) throws ReadOnlyException,
ConversionException {
fireValueChange();
}
@Override
- public Class<?> getType() {
+ public Class<String> getType() {
return String.class;
}
};
public void testOutOfBounds() {
Slider s = new Slider(0, 10);
- s.setValue(0);
+ s.setValue(0.0);
Assert.assertEquals(0.0, s.getValue());
- s.setValue(10);
+ s.setValue(10.0);
Assert.assertEquals(10.0, s.getValue());
try {
- s.setValue(20);
+ s.setValue(20.0);
fail("Should throw out of bounds exception");
} catch (ValueOutOfBoundsException e) {
// TODO: handle exception
* Override in subclasses to set value with changeVariables().
*/
protected void setValue(AbstractField<T> field) {
- field.setValue("newValue");
+ field.setValue((T) "newValue");
}
}
Integer.TYPE, myTest, "getInt", "setInt", new Object[0],
new Object[] { null }, 0);
- methodProperty2.setValue("3");
+ methodProperty2.setValue(3);
System.out.println("Succeeded");
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.MenuItem;
-public abstract class AbstractFieldTest<T extends AbstractField<?>> extends
+public abstract class AbstractFieldTest<T extends AbstractField> extends
AbstractComponentTest<T> implements ValueChangeListener,
ReadOnlyStatusChangeListener {
for (int row = 0; row < ROWS; row++) {
Item i = t.addItem(String.valueOf(row));
for (int col = 0; col < COLS; col++) {
- Property<?> p = i.getItemProperty("COLUMN_" + col);
+ Property<String> p = i.getItemProperty("COLUMN_" + col);
p.setValue("item " + row + "/" + col);
}
}
}
@Override
- public void setValue(Object newValue) throws ReadOnlyException {
- if (newValue == null) {
- value = null;
- } else if (newValue instanceof BigDecimal) {
- value = (BigDecimal) newValue;
- } else {
- throw new IllegalArgumentException(
- "Value must be of type BigDecimal");
- }
+ public void setValue(BigDecimal newValue) throws ReadOnlyException {
+ value = newValue;
}
@Override
// Get first item
Object itemId = indexedContainer.getIdByIndex(0);
Item item = indexedContainer.getItem(itemId);
- Property<String> property = (Property<String>) item
+ Property<String> property = item
.getItemProperty("name");
// Prepend with Z so item should get sorted later
property.setValue("Z " + property.getValue());
Slider s = new Slider();
s.setWidth("200px");
try {
- s.setValue(50);
+ s.setValue(50.0);
} catch (ValueOutOfBoundsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
s.setOrientation(SliderOrientation.VERTICAL);
s.setHeight("200px");
try {
- s.setValue(50);
+ s.setValue(50.0);
} catch (ValueOutOfBoundsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fields[0].setRequiredError("required error");
fields[1] = new TextField();
- fields[1].setValue("TEXTFIELD2");
+ ((TextField) fields[1]).setValue("TEXTFIELD2");
fields[1]
.setComponentError(new UserError("component error, user error"));
fields[0].setRequiredError("required error");
fields[1] = new TextField();
- fields[1].setValue("TEXTFIELD2");
+ ((TextField) fields[1]).setValue("TEXTFIELD2");
fields[1]
.setComponentError(new UserError("component error, user error"));
// get the created item
final Item item = tree.getItem(id);
// set our "caption" property
- @SuppressWarnings("unchecked")
- final Property<String> p = (Property<String>) item
- .getItemProperty(CAPTION_PROPERTY);
+ final Property<String> p = item.getItemProperty(CAPTION_PROPERTY);
p.setValue(caption);
if (parent != null) {
tree.setChildrenAllowed(parent, true);
return getSecondaryTypesList(itemId);
}
- final Field<?> f = super.createField(container, itemId, propertyId,
+ final Field f = super.createField(container, itemId, propertyId,
uiContext);
if (f != null) {
if (f instanceof TextField) {
table.addContainerProperty("Text", String.class, null);
for (int i = 0; i < 150; i++) {
Item item = table.addItem("Item" + i);
- Property<?> p = item.getItemProperty("Text");
+ Property<String> p = item.getItemProperty("Text");
p.setValue(i % 5 == 0 ? "enabled" : "disabled");
}