use of org.openremote.model.value.ValueType in project openremote by openremote.
the class MetaEditor method onMetaItemTypeChanged.
protected void onMetaItemTypeChanged(MetaItemEditor itemEditor, boolean updateItem) {
if (updateItem) {
itemEditor.item.clearValue();
// TODO Should use meta item descriptors from server
Value initialValue = Arrays.stream(AssetMeta.values()).filter(assetMeta -> assetMeta.getUrn().equals(itemEditor.nameList.getSelectedValue())).map(MetaItemDescriptor::getInitialValue).findFirst().orElse(null);
ValueType valueType = EnumUtil.enumFromString(ValueType.class, itemEditor.typeList.getSelectedValue()).orElse(null);
if (valueType == ValueType.BOOLEAN && initialValue == null) {
initialValue = Values.create(false);
}
itemEditor.onModified(initialValue);
}
itemEditor.updateValueEditor();
}
use of org.openremote.model.value.ValueType in project openremote by openremote.
the class Simulator method writeView.
protected void writeView() {
clear();
addLabel(environment.getMessages().simulator());
formGroups.clear();
List<SimulatorElement> sortedElements = Arrays.asList(simulatorState.getElements());
sortedElements.sort(Comparator.comparing(o -> simulatorState.getElementName(o)));
for (SimulatorElement element : sortedElements) {
FormGroup formGroup = new FormGroup();
String elementName = simulatorState.getElementName(element);
FormLabel formLabel = new FormLabel(elementName);
formLabel.addStyleName("largest");
formGroup.setFormLabel(formLabel);
FormField formField = new FormField();
formGroup.setFormField(formField);
// Don't push simulator value validation up to the presenter as it is a special case that should
// just be evaluated in-situ and shouldn't invalidate the parent attribute
Consumer<Value> onModified = value -> {
element.setValue(value);
List<ValidationFailure> failures = element.getValidationFailures();
formGroup.setError(failures != null && !failures.isEmpty());
};
ValueType valueType = element.getExpectedType().getValueType();
IsWidget editor = valueEditorSupplier.createValueEditor(element, valueType, style, parentView, onModified);
formField.add(editor);
formGroups.put(element.getAttributeRef(), formGroup);
add(formGroup);
}
if (sortedElements.size() > 0) {
FormGroup submitGroup = new FormGroup();
submitGroup.getElement().getStyle().setWidth(80, com.google.gwt.dom.client.Style.Unit.PCT);
FormField submitField = new FormField();
submitGroup.setFormField(submitField);
FormButton writeButton = new FormButton(environment.getMessages().writeSimulatorState());
writeButton.setPrimary(true);
writeButton.addClickHandler(event -> {
if (isValid()) {
environment.getEventService().dispatch(simulatorState);
environment.getEventBus().dispatch(new ShowSuccessEvent(environment.getMessages().simulatorStateSubmitted()));
}
});
submitField.add(writeButton);
add(submitGroup);
} else {
add(new FormInlineLabel(environment.getMessages().noAttributesLinkedToSimulator()));
}
// "Blink" the editor so users know there might be a new value
for (FormGroup formGroup : formGroups.values()) {
formGroup.addStyleName(environment.getWidgetStyle().HighlightBackground());
}
Browser.getWindow().setTimeout(() -> {
for (FormGroup formGroup : formGroups.values()) formGroup.removeStyleName(environment.getWidgetStyle().HighlightBackground());
}, 250);
}
use of org.openremote.model.value.ValueType in project openremote by openremote.
the class AbstractVelbusProtocol method doLinkAttribute.
@Override
protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {
Pair<VelbusNetwork, Consumer<ConnectionStatus>> velbusNetworkConsumerPair = networkConfigurationMap.get(protocolConfiguration.getReferenceOrThrow());
if (velbusNetworkConsumerPair == null) {
LOG.info("Protocol Configuration doesn't have a valid VelbusNetwork so cannot link");
return;
}
VelbusNetwork velbusNetwork = velbusNetworkConsumerPair.key;
// Get the device that this attribute is linked to
int deviceAddress = getVelbusDeviceAddress(attribute);
// Get the property that this attribute is linked to
String property = getVelbusDevicePropertyLink(attribute);
AttributeRef attributeRef = attribute.getReferenceOrThrow();
ValueType valueType = attribute.getType().orElse(AttributeType.STRING).getValueType();
LOG.fine("Linking attribute to device '" + deviceAddress + "' and property '" + property + "': " + attributeRef);
Consumer<DevicePropertyValue> propertyValueConsumer = propertyValue -> updateLinkedAttribute(new AttributeState(attributeRef, propertyValue != null ? propertyValue.toValue(valueType) : null));
attributePropertyValueConsumers.put(attributeRef, propertyValueConsumer);
velbusNetwork.addPropertyValueConsumer(deviceAddress, property, propertyValueConsumer);
}
Aggregations