private static TypeID getComponentTypeID(DesignComponent component, String propertyName) { return component.getComponentDescriptor().getPropertyDescriptor(propertyName).getType(); }
private DesignComponent goThroughChildren(DesignComponent currentComponent, DesignComponent child, DescriptorRegistry registry) { Collection<PropertyDescriptor> descriptorsList = child.getComponentDescriptor().getPropertyDescriptors(); if (descriptorsList != null) { for (PropertyDescriptor descriptor : descriptorsList) { if (registry.isInHierarchy(PointCD.TYPEID, descriptor.getType())) { if (child.readProperty(descriptor.getName()).getComponent() == currentComponent) { return currentComponent; } } } } return null; }
/** * Returns whether the property value is compatible with a specified property descriptor. * @param propertyDescriptor the property descriptor * @return true, if the property value is allowed for the property descriptor */ public boolean isCompatible(PropertyDescriptor propertyDescriptor) { if (propertyDescriptor == null) { return false; } if (kind == Kind.NULL) { if (!propertyDescriptor.isAllowNull()) { PropertyValue defaultValue = propertyDescriptor.getDefaultValue(); if (defaultValue == null || defaultValue.getKind() != PropertyValue.Kind.NULL) { // HACK for PropertyDescriptor for disallowing to use null values return false; } } } else if (kind == Kind.USERCODE) { if (!propertyDescriptor.isAllowUserCode()) { return false; } } return isCompatible(propertyDescriptor.getType()); }
String propertyName = propertyDescriptor.getName(); PropertyValue propertyValue = properties.get(propertyName); if (propertyValue == null || ! propertyValue.isCompatible(propertyDescriptor.getType())) { propertyValue = propertyDescriptor.createDefaultValue(this, propertyName); if (! propertyValue.isCompatible(propertyDescriptor))
private static void saveComponent (Document xml, Node parentNode, DesignComponent component) { ComponentDescriptor descriptor = component.getComponentDescriptor (); Node node = xml.createElement (COMPONENT_NODE); parentNode.appendChild (node); setAttribute (xml, node, COMPONENTID_ATTR, Long.toString (component.getComponentID ())); setAttribute (xml, node, TYPEID_ATTR, component.getType ().getEncoded ()); Collection<PropertyDescriptor> propertyDescriptors = descriptor.getPropertyDescriptors (); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { if (! propertyDescriptor.isUseForSerialization ()) continue; String propertyName = propertyDescriptor.getName (); if (component.isDefaultValue (propertyName)) continue; PropertyValue propertyValue = component.readProperty (propertyName); String serialized = propertyValue.serialize (); Node propertyNode = xml.createElement (PROPERTY_NODE); node.appendChild (propertyNode); setAttribute (xml, propertyNode, NAME_ATTR, propertyDescriptor.getName ()); setAttribute (xml, propertyNode, TYPEID_ATTR, propertyDescriptor.getType ().getEncoded ()); setAttribute (xml, propertyNode, VALUE_ATTR, serialized); } for (DesignComponent child : component.getComponents ()) saveComponent (xml, node, child); }
private static String createEditorIDForPropertyDescriptor (PropertyDescriptor property) { TypeID type = property.getType (); if (MidpTypes.TYPEID_BOOLEAN.equals (type)) return MidpPropertyPresenterDeserializer.EDITOR_BOOLEAN; if (MidpTypes.TYPEID_CHAR.equals (type)) return MidpPropertyPresenterDeserializer.EDITOR_CHAR; if (MidpTypes.TYPEID_BYTE.equals (type)) return MidpPropertyPresenterDeserializer.EDITOR_BYTE; if (MidpTypes.TYPEID_SHORT.equals (type)) return MidpPropertyPresenterDeserializer.EDITOR_SHORT; if (MidpTypes.TYPEID_INT.equals (type)) return MidpPropertyPresenterDeserializer.EDITOR_INT; if (MidpTypes.TYPEID_LONG.equals (type)) return MidpPropertyPresenterDeserializer.EDITOR_LONG; if (MidpTypes.TYPEID_FLOAT.equals (type)) return MidpPropertyPresenterDeserializer.EDITOR_FLOAT; if (MidpTypes.TYPEID_DOUBLE.equals (type)) return MidpPropertyPresenterDeserializer.EDITOR_DOUBLE; // TODO if (MidpTypes.TYPEID_JAVA_LANG_STRING.equals (type)) return MidpPropertyPresenterDeserializer.EDITOR_STRING; return MidpPropertyPresenterDeserializer.EDITOR_JAVA_CODE; }
Element propertyNode = document.createElement (XMLComponentDescriptor.PROPERTY_DESCRIPTOR_NODE); setAttribute (document, propertyNode, XMLComponentDescriptor.NAME_ATTR, propertyDescriptor.getName ()); setAttribute (document, propertyNode, XMLComponentDescriptor.TYPEID_ATTR, propertyDescriptor.getType ().toString ()); String userCode = propertyDescriptor.getDefaultValue ().getUserCode (); if (userCode != null)