/** * 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()); }
public List<PropertyDescriptor> getDeclaredPropertyDescriptors() { return Arrays.asList( new PropertyDescriptor(PROP_DATE, MidpTypes.TYPEID_LONG, PropertyValue.createNull (), true, true, MidpVersionable.MIDP), new PropertyDescriptor(PROP_TIME_ZONE, MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue.createNull(), true, true, MidpVersionable.MIDP), new PropertyDescriptor(PROP_INPUT_MODE, MidpTypes.TYPEID_INT, PropertyValue.createNull (), false, true, MidpVersionable.MIDP) ); }
public MidpPropertyPresenterSerializer (String displayName, PropertyDescriptor property) { this.displayName = displayName; this.editorID = createEditorIDForPropertyDescriptor (property); this.propertyName = property.getName (); }
public void run() { for (String propertyName : propertyNames) { PropertyDescriptor propertyDescriptor = component.get().getComponentDescriptor().getPropertyDescriptor(propertyName); if (!(propertyDescriptor.getDefaultValue().getKind() != PropertyValue.Kind.NULL || propertyDescriptor.isAllowNull())) { supportsDefaultValue[0] = false; break; } } } });
assert propertyDescriptor != null; 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) setAttribute (document, propertyNode, XMLComponentDescriptor.DEFAULT_VALUE_ATTR, userCode); setAttribute (document, propertyNode, XMLComponentDescriptor.ALLOW_NULL, Boolean.toString (propertyDescriptor.isAllowNull ())); setAttribute (document, propertyNode, XMLComponentDescriptor.ALLOW_USER_CODE, Boolean.toString (propertyDescriptor.isAllowUserCode ())); setAttribute (document, propertyNode, XMLComponentDescriptor.USE_FOR_SERIALIZATION_ATTR, Boolean.toString (propertyDescriptor.isUseForSerialization ())); setAttribute (document, propertyNode, XMLComponentDescriptor.READ_ONLY_ATTR, Boolean.toString (propertyDescriptor.isReadOnly ())); rootNode.appendChild (propertyNode);
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); }
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)) Debug.warning("Default property value is not compatible", componentID, propertyName, propertyValue); // NOI18N
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; }
private static void collectUsedReferences (HashSet<DesignComponent> referencedComponents, DesignComponent component) { ComponentDescriptor descriptor = component.getComponentDescriptor (); Collection<PropertyDescriptor> propertyDescriptors = descriptor.getPropertyDescriptors (); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { if (! propertyDescriptor.isUseForSerialization ()) continue; PropertyValue propertyValue = component.readProperty (propertyDescriptor.getName ()); Debug.collectAllComponentReferences (propertyValue, referencedComponents); } }
private static TypeID getComponentTypeID(DesignComponent component, String propertyName) { return component.getComponentDescriptor().getPropertyDescriptor(propertyName).getType(); }
private void analyze (DefaultListModel list, DesignComponent component) { ComponentDescriptor descriptor = component.getComponentDescriptor (); if (descriptor == null) return; VersionDescriptor version = descriptor.getVersionDescriptor (); if (! version.isCompatibleWith (MidpVersionDescriptor.MIDP_1)) { reportComponent (list, component); return; } for (PropertyDescriptor property : descriptor.getPropertyDescriptors ()) { if (! property.getVersionable ().isCompatibleWith (MidpVersionable.MIDP_1)) if (! component.isDefaultValue (property.getName ())) reportComponentProperty (list, component, property.getName ()); processComponentProperty (list, component, property); } for (DesignComponent child : component.getComponents ()) analyze (list, child); }
public void run() { propertyValue = component.get().getComponentDescriptor().getPropertyDescriptor(propertyName).getDefaultValue(); } });
/** * Writes a property value. * @param propertyName the property name * @param propertyValue the property value */ public void writeProperty(String propertyName, PropertyValue propertyValue) { assert document.getTransactionManager().isWriteAccess(); assert propertyValue != null : "Null property value"; // NOI18N assert componentDescriptor != null; PropertyValue oldValue = properties.get(propertyName); assert oldValue != null : "Missing old value in " + this + "." + propertyName; // NOI18N if (oldValue == propertyValue) return; PropertyDescriptor propertyDescriptor = componentDescriptor.getPropertyDescriptor(propertyName); assert propertyDescriptor != null : "Missing property descriptor in " + this + "." + propertyName; // NOI18N assert ! propertyDescriptor.isReadOnly() : "Cannot write read-only property " + this + "." + propertyName; // NOI18N // TODO - allow writing during deserialization assert propertyValue.isCompatible(propertyDescriptor); properties.put(propertyName, propertyValue); document.getTransactionManager().writePropertyHappened(this, propertyName, oldValue, propertyValue); }
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; }
public void run() { List<String> propertyNames = element.getPropertyValueNames(); for (String propertyName : propertyNames) { PropertyValue pv = component.readProperty(propertyName); if (PropertyValue.Kind.USERCODE.equals(pv.getKind())) { component.writeProperty(propertyName, component.getComponentDescriptor().getPropertyDescriptor(propertyName).getDefaultValue()); } } } });
@Override public boolean isAcceptable (ComponentProducer producer, AcceptSuggestion suggestion) { if (getComponent().getComponentDescriptor().getPropertyDescriptor(DisplayableCD.PROP_COMMANDS).isReadOnly()) return false; DescriptorRegistry registry = getComponent().getDocument().getDescriptorRegistry(); return registry.isInHierarchy(CommandCD.TYPEID, producer.getMainComponentTypeID ()); }
public List<PropertyDescriptor> getDeclaredPropertyDescriptors() { return Arrays.asList ( new PropertyDescriptor(PROP_RESOURCE_PATH, MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue.createNull(), false, true, MidpVersionable.MIDP) ); }
/** * Returns a property descriptor for a property. * @param propertyName the property name * @return the property descriptor */ public final PropertyDescriptor getPropertyDescriptor (String propertyName) { // HINT - optimize to HashMap for (PropertyDescriptor propertyDescriptor : getPropertyDescriptors ()) { if (propertyName.equals (propertyDescriptor.getName ())) return propertyDescriptor; } return null; }
public List<PropertyDescriptor> getDeclaredPropertyDescriptors () { return Arrays.asList ( new PropertyDescriptor (PROP_ACCESS_CODE, MidpTypes.TYPEID_JAVA_CODE, PropertyValue.createNull (), false, false, Versionable.FOREVER) ); }
void dumpComponent(String indent) { assert document.getTransactionManager().isAccess(); System.out.println(indent + componentID + " : " + componentDescriptor); // NOI18N indent += " "; // NOI18N HashSet<String> undefinedProperties = new HashSet<String> (properties.keySet()); Collection<PropertyDescriptor> propertyDescriptors = componentDescriptor.getPropertyDescriptors(); for (PropertyDescriptor property : propertyDescriptors) { String name = property.getName(); System.out.println(indent + (properties.get(name) == defaultProperties.get(name) ? "## " : ":: ") + name + " = " + properties.get(name)); // NOI18N undefinedProperties.remove(name); } for (String name : undefinedProperties) System.out.println(indent + "?? " + name + " = " + properties.get(name)); // NOI18N for (Object presenter : presenters.lookupAll(Object.class)) System.out.println(indent + ">>" + presenter); // NOI18N for (DesignComponent child : children) child.dumpComponent(indent); }