List of usage examples for java.beans PropertyDescriptor isPreferred
public boolean isPreferred()
From source file:net.sf.taverna.t2.workbench.ui.servicepanel.actions.AddServiceProviderAction.java
protected JPanel buildEditor(Configuration configuration) { List<String> uiBuilderConfig = new ArrayList<>(); int lastPreferred = 0; for (PropertyDescriptor property : getProperties(configuration)) { if (property.isHidden() || property.isExpert()) // TODO: Add support for expert properties continue; String propertySpec = property.getName() + ":name=" + property.getDisplayName(); if (property.isPreferred()) // Add it to the front uiBuilderConfig.add(lastPreferred++, propertySpec); else//from w w w . j av a 2 s.c o m uiBuilderConfig.add(propertySpec); } return UIBuilder.buildEditor(configuration, uiBuilderConfig.toArray(new String[0])); }
From source file:com.twinsoft.convertigo.beans.core.MySimpleBeanInfo.java
protected PropertyDescriptor getPropertyDescriptor(String name) throws IntrospectionException { checkAdditionalProperties();//w ww . j ava 2 s . com for (int i = 0; i < properties.length; i++) { PropertyDescriptor property = properties[i]; if (name.equals(property.getName())) { PropertyDescriptor clone = new PropertyDescriptor(name, property.getReadMethod(), property.getWriteMethod()); clone.setDisplayName(property.getDisplayName()); clone.setShortDescription(property.getShortDescription()); clone.setPropertyEditorClass(property.getPropertyEditorClass()); clone.setBound(property.isBound()); clone.setConstrained(property.isConstrained()); clone.setExpert(property.isExpert()); clone.setHidden(property.isHidden()); clone.setPreferred(property.isPreferred()); for (String attributeName : Collections.list(property.attributeNames())) { clone.setValue(attributeName, property.getValue(attributeName)); } return properties[i] = clone; } } return null; }
From source file:com.ocs.dynamo.domain.model.impl.EntityModelFactoryImpl.java
/** * Constructs an attribute model for a property * /* www . ja va2 s.c o m*/ * @param descriptor * the property descriptor * @param entityModel * the entity model * @param parentClass * the type of the direct parent of the attribute (relevant in case of embedded * attributes) * @param nested * whether this is a nested attribute * @param prefix * the prefix to apply to the attribute name * @return */ private <T> List<AttributeModel> constructAttributeModel(PropertyDescriptor descriptor, EntityModelImpl<T> entityModel, Class<?> parentClass, boolean nested, String prefix) { List<AttributeModel> result = new ArrayList<AttributeModel>(); // validation methods annotated with @AssertTrue or @AssertFalse have to // be ignored String fieldName = descriptor.getName(); AssertTrue assertTrue = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, AssertTrue.class); AssertFalse assertFalse = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, AssertFalse.class); if (assertTrue == null && assertFalse == null) { AttributeModelImpl model = new AttributeModelImpl(); model.setEntityModel(entityModel); String displayName = DefaultFieldFactory.createCaptionByPropertyId(fieldName); // first, set the defaults model.setDisplayName(displayName); model.setDescription(displayName); model.setPrompt(displayName); model.setMainAttribute(descriptor.isPreferred()); model.setSearchable(descriptor.isPreferred()); model.setName((prefix == null ? "" : (prefix + ".")) + fieldName); model.setImage(false); model.setReadOnly(descriptor.isHidden()); model.setSortable(true); model.setComplexEditable(false); model.setPrecision(SystemPropertyUtils.getDefaultDecimalPrecision()); model.setSearchCaseSensitive(false); model.setSearchPrefixOnly(false); model.setUrl(false); model.setUseThousandsGrouping(true); Id idAttr = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, Id.class); if (idAttr != null) { entityModel.setIdAttributeModel(model); // the ID column is hidden. details collections are also hidden // by default model.setVisible(false); } else { model.setVisible(true); } model.setType(descriptor.getPropertyType()); // determine the possible date type model.setDateType(determineDateType(model.getType(), entityModel.getEntityClass(), fieldName)); // determine default display format model.setDisplayFormat(determineDefaultDisplayFormat(model.getType(), entityModel.getEntityClass(), fieldName, model.getDateType())); // determine if the attribute is required based on the @NotNull // annotation NotNull notNull = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, NotNull.class); model.setRequired(notNull != null); model.setAttributeType(determineAttributeType(parentClass, model)); // minimum and maximum length based on the @Size annotation Size size = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, Size.class); if (AttributeType.BASIC.equals(model.getAttributeType()) && size != null) { model.setMaxLength(size.max()); model.setMinLength(size.min()); } setNestedEntityModel(model); // only basic attributes are shown in the table by default model.setVisibleInTable( !nested && model.isVisible() && (AttributeType.BASIC.equals(model.getAttributeType()))); if (getMessageService() != null) { model.setTrueRepresentation(getMessageService().getMessage("ocs.true")); model.setFalseRepresentation(getMessageService().getMessage("ocs.false")); } // by default, use a combo box to look up model.setSelectMode(AttributeSelectMode.COMBO); model.setTextFieldMode(AttributeTextFieldMode.TEXTFIELD); model.setSearchSelectMode(AttributeSelectMode.COMBO); // is the field an email field? Email email = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, Email.class); model.setEmail(email != null); // override the defaults with annotation values setAnnotationOverrides(parentClass, model, descriptor, nested); // override any earlier version with message bundle contents setMessageBundleOverrides(entityModel, model); if (!model.isEmbedded()) { result.add(model); } else { // an embedded object is not directly added. Instead, its child // properties are added as attributes if (model.getType().equals(entityModel.getEntityClass())) { throw new IllegalStateException("Embedding a class in itself is not allowed"); } PropertyDescriptor[] embeddedDescriptors = BeanUtils.getPropertyDescriptors(model.getType()); for (PropertyDescriptor embeddedDescriptor : embeddedDescriptors) { String name = embeddedDescriptor.getName(); if (!skipAttribute(name)) { List<AttributeModel> embeddedModels = constructAttributeModel(embeddedDescriptor, entityModel, model.getType(), nested, model.getName()); result.addAll(embeddedModels); } } } } return result; }
From source file:org.eclipse.wb.internal.core.model.description.rules.StandardBeanPropertiesRule.java
@Override public void begin(String namespace, String name, Attributes attributes) throws Exception { ComponentDescription componentDescription = (ComponentDescription) digester.peek(); List<PropertyDescriptor> descriptors = ReflectionUtils.getPropertyDescriptors( componentDescription.getBeanInfo(), componentDescription.getComponentClass()); componentDescription.setPropertyDescriptors(descriptors); for (PropertyDescriptor propertyDescriptor : descriptors) { // prepare property parts String propertyName = propertyDescriptor.getName(); Method setMethod = ReflectionUtils.getWriteMethod(propertyDescriptor); Method getMethod = ReflectionUtils.getReadMethod(propertyDescriptor); // add property if (setMethod != null) { GenericPropertyDescription propertyDescription = addSingleProperty(componentDescription, propertyName, setMethod, getMethod); tryToSetPropertyEditorAWT(propertyDescriptor, propertyDescription); if (propertyDescriptor.isPreferred()) { propertyDescription.setCategory(PropertyCategory.PREFERRED); }/*from www . j ava 2 s. c om*/ } } }