本文整理了Java中com.vaadin.v7.data.Property.getType()
方法的一些代码示例,展示了Property.getType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Property.getType()
方法的具体详情如下:
包路径:com.vaadin.v7.data.Property
类名称:Property
方法名:getType
[英]Returns the type of the Property. The methods getValue
and setValue
must be compatible with this type: one must be able to safely cast the value returned from getValue
to the given type and pass any variable assignable to this type as an argument to setValue
.
[中]返回属性的类型。方法getValue
和setValue
必须与此类型兼容:必须能够安全地将从getValue
返回的值强制转换为给定类型,并将可分配给此类型的任何变量作为参数传递给setValue
。
代码示例来源:origin: com.vaadin/vaadin-compatibility-server
@Override
public Class getType() {
return wrappedProperty.getType();
}
代码示例来源:origin: com.haulmont.cuba/cuba-web
@Override
public Class getType() {
return itemProperty.getType();
}
代码示例来源:origin: com.vaadin/vaadin-compatibility-server
/**
* Constructs a new <code>DateField</code> that's bound to the specified
* <code>Property</code> and has no caption.
*
* @param dataSource
* the Property to be edited with this editor.
*/
public DateField(Property dataSource) throws IllegalArgumentException {
if (!Date.class.isAssignableFrom(dataSource.getType())) {
throw new IllegalArgumentException(
"Can't use " + dataSource.getType().getName()
+ " typed property as datasource");
}
setPropertyDataSource(dataSource);
}
代码示例来源:origin: viritin/viritin
@Override
public void setPropertyDataSource(Property newDataSource) {
if (newDataSource != null) {
type = newDataSource.getType();
}
super.setPropertyDataSource(newDataSource);
}
代码示例来源:origin: viritin/viritin
@SuppressWarnings("unchecked")
@Override
public Class<? extends Collection<T>> getType() {
try {
return getPropertyDataSource().getType();
} catch (Exception e) {
return null;
}
}
代码示例来源:origin: viritin/viritin
@Override
public void setPropertyDataSource(Property newDataSource) {
if (newDataSource != null) {
Class<T> type = newDataSource.getType();
setOptions(type.getEnumConstants());
}
super.setPropertyDataSource(newDataSource);
}
代码示例来源:origin: com.vaadin/vaadin-compatibility-server
/**
* Gets the field type.
*
* @see AbstractField#getType()
*/
@Override
public Class<?> getType() {
if (getPropertyDataSource() != null) {
return getPropertyDataSource().getType();
}
return Object.class;
}
代码示例来源:origin: OpenNMS/opennms
private synchronized void loadPropertiesIfNull() {
if (m_properties == null) {
m_properties = new TreeMap<Object,Class<?>>();
BeanItem<T> item = null;
try {
item = new BeanItem<T>(m_datasource.createInstance(m_itemClass));
} catch (InstantiationException e) {
LoggerFactory.getLogger(getClass()).error("Class {} does not have a default constructor. Cannot create an instance.", getItemClass());
} catch (IllegalAccessException e) {
LoggerFactory.getLogger(getClass()).error("Class {} does not have a public default constructor. Cannot create an instance.", getItemClass());
}
for (Object key : item.getItemPropertyIds()) {
m_properties.put(key, item.getItemProperty(key).getType());
}
}
}
}
代码示例来源:origin: OpenNMS/opennms
@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
final ZoneId userTimeZoneId = UserTimeZoneExtractor.extractUserTimeZoneIdOrNull(source.getUI());
final Property property = source.getContainerProperty(itemId, columnId);
if (property == null || property.getValue() == null) {
return null;
}
String formattedValue;
if(property.getType().equals(Instant.class)){
formattedValue = timeformatService.format((Instant) property.getValue(), userTimeZoneId);
} else if(property.getType().equals(Date.class)){
formattedValue = timeformatService.format((Date) property.getValue(), userTimeZoneId);
} else {
formattedValue = property.toString();
}
return formattedValue;
}
}
代码示例来源:origin: com.vaadin/vaadin-compatibility-server
@Override
public Field<?> createField(Item item, Object propertyId,
Component uiContext) {
Class<?> type = item.getItemProperty(propertyId).getType();
Field<?> field = createFieldByPropertyType(type);
field.setCaption(createCaptionByPropertyId(propertyId));
return field;
}
代码示例来源:origin: com.vaadin/vaadin-compatibility-server
@Override
public Field createField(Container container, Object itemId,
Object propertyId, Component uiContext) {
Property containerProperty = container.getContainerProperty(itemId,
propertyId);
Class<?> type = containerProperty.getType();
Field<?> field = createFieldByPropertyType(type);
field.setCaption(createCaptionByPropertyId(propertyId));
return field;
}
代码示例来源:origin: com.vaadin/vaadin-compatibility-server
/**
* Retrieves the type of the currently used data model. If the field has no
* data source then the model type of the converter is used.
*
* @since 7.1
* @return The type of the currently used data model or null if no data
* source or converter is set.
*/
protected Class<?> getModelType() {
Property<?> pd = getPropertyDataSource();
if (pd != null) {
return pd.getType();
} else if (getConverter() != null) {
return getConverter().getModelType();
}
return null;
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void testReadFromDataSourceItemString() throws RepositoryException {
// GIVEN
definition.setType("String");
rootNode.setProperty(propertyName, "stringValue");
JcrNodeAdapter rootItem = new JcrNodeAdapter(rootNode);
BasicTransformer<String> handler = new BasicTransformer<>(rootItem, definition, String.class, mock(I18NAuthoringSupport.class));
// WHEN
String value = handler.readFromItem();
// THEN
assertNotNull(value);
assertEquals(rootNode.getProperty(propertyName).getString(), value);
assertNotNull(rootItem.getItemProperty(propertyName));
assertEquals(String.class, rootItem.getItemProperty(propertyName).getType());
assertEquals(rootNode.getProperty(propertyName).getString(), rootItem.getItemProperty(propertyName).getValue());
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void createDefaultPropertyByPropertyTypeWithNullValue() {
//WHEN
Property property = DefaultPropertyUtil.newProperty(null, Long.class);
//THEN
assertEquals(null, property.getValue());
assertEquals(Long.class, property.getType());
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void testGetItemPropertyWithStringProperty() throws Exception {
// GIVEN
// Create a NewNodeAdapter
String nodeName = "rootNode";
String id = "propertyID";
String value = "test";
Node parentNode = session.getRootNode().addNode(nodeName);
JcrNodeAdapter adapter = new JcrNodeAdapter(parentNode);
// Create the property
Property propertyInitial = DefaultPropertyUtil.newDefaultProperty("String", value);
adapter.addItemProperty(id, propertyInitial);
// WHEN
Property property = adapter.getItemProperty(id);
// THEN
assertSame(property, propertyInitial);
assertEquals(PropertyType.nameFromValue(PropertyType.STRING), property.getType().getSimpleName());
assertEquals(value, property.getValue().toString());
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void testReadFromDataSourceWrongTypeIncompatibleValue() throws RepositoryException {
// GIVEN
definition.setType("Long");
rootNode.setProperty(propertyName, "titi");
JcrNodeAdapter rootItem = new JcrNodeAdapter(rootNode);
BasicTransformer<Long> handler = new BasicTransformer<>(rootItem, definition, Long.class, mock(I18NAuthoringSupport.class));
// WHEN
Object value = handler.readFromItem();
// THEN
assertNull(value);
assertEquals(Long.class, rootItem.getItemProperty(propertyName).getType());
assertEquals(null, rootItem.getItemProperty(propertyName).getValue());
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void testReadFromDataSourceWrongTypeEmptyValue() throws RepositoryException {
// GIVEN
definition.setType("Boolean");
rootNode.setProperty(propertyName, "");
JcrNodeAdapter rootItem = new JcrNodeAdapter(rootNode);
BasicTransformer<Boolean> handler = new BasicTransformer<>(rootItem, definition, Boolean.class, mock(I18NAuthoringSupport.class));
// WHEN
Object value = handler.readFromItem();
// THEN
assertNull(value);
assertEquals(Boolean.class, rootItem.getItemProperty(propertyName).getType());
assertEquals(null, rootItem.getItemProperty(propertyName).getValue());
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void testReadFromDataSourceItemLong() throws RepositoryException {
// GIVEN
definition.setType("Long");
rootNode.setProperty(propertyName, 200L);
JcrNodeAdapter rootItem = new JcrNodeAdapter(rootNode);
BasicTransformer<Long> handler = new BasicTransformer<>(rootItem, definition, Long.class, mock(I18NAuthoringSupport.class));
// WHEN
Long value = handler.readFromItem();
// THEN
assertNotNull(value);
assertEquals(rootNode.getProperty(propertyName).getLong(), (long) value); // once we know it's not null, go for primitive check
assertNotNull(rootItem.getItemProperty(propertyName));
assertEquals(Long.class, rootItem.getItemProperty(propertyName).getType());
assertEquals(rootNode.getProperty(propertyName).getLong(), rootItem.getItemProperty(propertyName).getValue());
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void testReadFromDataSourceWrongType() throws RepositoryException {
// GIVEN
definition.setType("Boolean");
rootNode.setProperty(propertyName, "false");
JcrNodeAdapter rootItem = new JcrNodeAdapter(rootNode);
BasicTransformer<Boolean> handler = new BasicTransformer<>(rootItem, definition, Boolean.class, mock(I18NAuthoringSupport.class));
// WHEN
Boolean value = handler.readFromItem();
// THEN
assertNotNull(value);
assertEquals("Keep the original JCR value", Boolean.FALSE, value);
assertEquals(Boolean.class, rootItem.getItemProperty(propertyName).getType());
assertEquals(Boolean.FALSE, rootItem.getItemProperty(propertyName).getValue());
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void testReadFromDataSourceItemReadOnly() throws RepositoryException {
// GIVEN
definition.setType("String");
Item rootItem = new PropertysetItem();
// underlying property is read-only
rootItem.addItemProperty(propertyName, new ObjectProperty<>("foo", String.class, true));
BasicTransformer<String> transformer = new BasicTransformer<>(rootItem, definition, String.class, mock(I18NAuthoringSupport.class));
// WHEN
String value = transformer.readFromItem();
// THEN
assertNotNull(value);
assertEquals(String.class, rootItem.getItemProperty(propertyName).getType());
assertEquals("foo", rootItem.getItemProperty(propertyName).getValue());
assertTrue(new TransformedProperty<>(transformer).isReadOnly());
}
内容来源于网络,如有侵权,请联系作者删除!