private ValueParser<?> getValueParser(PropertyTypeId typeId) { ValueParser<?> parser = typeId.getValueParser(); if (typeId.isPropertyMultivalue()) { char delimiter = typeId.isPropertyNumeric() ? DEFAULT_NUMERIC_DELIMITER : DEFAULT_DELIMITER; parser = ValueParserConstants.multi(parser, delimiter); } return parser; }
@Override protected String convertToString(Object value) { return ((PropertyTypeId) value).getStringId(); }
@Override protected Object convertToType(Class aClass, Object o) { return PropertyTypeId.lookupMnemonic(o.toString()); }
/** * Gets the string representation of this type, as it should be given * when defining a descriptor in the xml. * * @param valueType The type to look for * @param multiValue Whether the descriptor is multivalued or not * * @return The string id * * @deprecated The signature will probably be altered in 7.0.0 but a similar functionality will be available */ @Deprecated public static String typeIdFor(Class<?> valueType, boolean multiValue) { for (Map.Entry<String, PropertyTypeId> entry : CONSTANTS_BY_MNEMONIC.entrySet()) { if (entry.getValue().propertyValueType() == valueType && entry.getValue().isPropertyMultivalue() == multiValue) { return entry.getKey(); } } return null; } }
private Element createPropertyDefinitionElementBR(PropertyDescriptor<?> propertyDescriptor) { final Element propertyElement = createPropertyValueElement(propertyDescriptor, propertyDescriptor.defaultValue()); propertyElement.setAttribute(PropertyDescriptorField.TYPE.attributeName(), PropertyTypeId.typeIdFor(propertyDescriptor.type(), propertyDescriptor.isMultiValue())); Map<PropertyDescriptorField, String> propertyValuesById = propertyDescriptor.attributeValuesById(); for (Map.Entry<PropertyDescriptorField, String> entry : propertyValuesById.entrySet()) { propertyElement.setAttribute(entry.getKey().attributeName(), entry.getValue()); } return propertyElement; }
@Override public void initialize(URL location, ResourceBundle resources) { commitButton.setOnAction(e -> { commitHandler.ifPresent(Runnable::run); getStage().close(); this.free(); }); commitButton.disableProperty().bind(validationSupport.invalidProperty()); Platform.runLater(() -> { typeId.bind(typeChoiceBox.getSelectionModel().selectedItemProperty()); typeChoiceBox.setConverter(DesignerUtil.stringConverter(PropertyTypeId::getStringId, PropertyTypeId::lookupMnemonic)); typeChoiceBox.getItems().addAll(PropertyTypeId.typeIdsToConstants().values()); FXCollections.sort(typeChoiceBox.getItems()); }); Platform.runLater(this::registerBasicValidators); typeIdProperty().values() .filter(Objects::nonNull) .subscribe(this::registerTypeDependentValidators); }
String typeId = propertyElement.getAttribute(PropertyDescriptorField.TYPE.attributeName()); PropertyDescriptorExternalBuilder<?> pdFactory = PropertyTypeId.factoryFor(typeId); if (pdFactory == null) { throw new IllegalArgumentException("No property descriptor factory for type: " + typeId);
/** * Builds the descriptor. May throw IllegalArgumentException. * * @return the descriptor if it can be built */ public PropertyDescriptor<?> build() { PropertyDescriptorExternalBuilder<?> externalBuilder = getTypeId().getFactory(); Map<PropertyDescriptorField, String> values = new HashMap<>(); values.put(PropertyDescriptorField.NAME, getName()); values.put(PropertyDescriptorField.DEFAULT_VALUE, getValue()); values.put(PropertyDescriptorField.DESCRIPTION, getDescription()); values.put(PropertyDescriptorField.MIN, "-2000000"); values.put(PropertyDescriptorField.MAX, "+2000000"); return externalBuilder.build(values); }
/** * Gets the string representation of this type, as it should be given * when defining a descriptor in the xml. * * @param valueType The type to look for * @param multiValue Whether the descriptor is multivalued or not * * @return The string id * * @deprecated The signature will probably be altered in 7.0.0 but a similar functionality will be available */ @Deprecated public static String typeIdFor(Class<?> valueType, boolean multiValue) { for (Map.Entry<String, PropertyTypeId> entry : CONSTANTS_BY_MNEMONIC.entrySet()) { if (entry.getValue().propertyValueType() == valueType && entry.getValue().isPropertyMultivalue() == multiValue) { return entry.getKey(); } } return null; } }
private Element createPropertyDefinitionElementBR(PropertyDescriptor<?> propertyDescriptor) { final Element propertyElement = createPropertyValueElement(propertyDescriptor, propertyDescriptor.defaultValue()); propertyElement.setAttribute(PropertyDescriptorField.TYPE.attributeName(), PropertyTypeId.typeIdFor(propertyDescriptor.type(), propertyDescriptor.isMultiValue())); Map<PropertyDescriptorField, String> propertyValuesById = propertyDescriptor.attributeValuesById(); for (Map.Entry<PropertyDescriptorField, String> entry : propertyValuesById.entrySet()) { propertyElement.setAttribute(entry.getKey().attributeName(), entry.getValue()); } return propertyElement; }
this.setTableMenuButtonVisible(true); ObservableList<PropertyTypeId> availableBuilders = FXCollections.observableArrayList(PropertyTypeId.typeIdsToConstants().values()); Collections.sort(availableBuilders); StringConverter<PropertyTypeId> converter = DesignerUtil.stringConverter(PropertyTypeId::getStringId, PropertyTypeId::lookupMnemonic);
String typeId = propertyElement.getAttribute(PropertyDescriptorField.TYPE.attributeName()); PropertyDescriptorExternalBuilder<?> pdFactory = PropertyTypeId.factoryFor(typeId); if (pdFactory == null) { throw new IllegalArgumentException("No property descriptor factory for type: " + typeId);
/** * Returns an xml string of this property definition. * * @return An xml string */ public String toXml() { return String.format("<property name=\"%s\" type=\"%s\" value=\"%s\" />", getName(), getTypeId().getStringId(), getValue()); }