Search in sources :

Example 1 with ValueType

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();
}
Also used : IntStream(java.util.stream.IntStream) Supplier(org.openremote.model.interop.Supplier) java.util(java.util) ValueType(org.openremote.model.value.ValueType) Environment(org.openremote.app.client.Environment) MetaItemDescriptor(org.openremote.model.attribute.MetaItemDescriptor) Pair(org.openremote.model.util.Pair) EnumUtil(org.openremote.model.util.EnumUtil) ValidationFailure(org.openremote.model.ValidationFailure) org.openremote.app.client.widget(org.openremote.app.client.widget) Collectors(java.util.stream.Collectors) AssetMeta(org.openremote.model.asset.AssetMeta) AttributeValidationResult(org.openremote.model.attribute.AttributeValidationResult) MetaItem(org.openremote.model.attribute.MetaItem) AgentLink(org.openremote.model.asset.agent.AgentLink) Value(org.openremote.model.value.Value) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) ProtocolDescriptor(org.openremote.model.asset.agent.ProtocolDescriptor) IsWidget(com.google.gwt.user.client.ui.IsWidget) Values(org.openremote.model.value.Values) TextUtil.isNullOrEmpty(org.openremote.model.util.TextUtil.isNullOrEmpty) AssetAttribute(org.openremote.model.asset.AssetAttribute) ValueType(org.openremote.model.value.ValueType) Value(org.openremote.model.value.Value) MetaItemDescriptor(org.openremote.model.attribute.MetaItemDescriptor)

Example 2 with ValueType

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);
}
Also used : Browser(elemental.client.Browser) EventRegistration(org.openremote.model.event.bus.EventRegistration) Consumer(org.openremote.model.interop.Consumer) SimulatorState(org.openremote.model.simulator.SimulatorState) java.util(java.util) ValueType(org.openremote.model.value.ValueType) Environment(org.openremote.app.client.Environment) AttributeRef(org.openremote.model.attribute.AttributeRef) ValidationFailure(org.openremote.model.ValidationFailure) org.openremote.app.client.widget(org.openremote.app.client.widget) AttributeViewImpl(org.openremote.app.client.assets.attributes.AttributeViewImpl) RequestSimulatorState(org.openremote.model.simulator.RequestSimulatorState) ShowSuccessEvent(org.openremote.app.client.event.ShowSuccessEvent) AttributeValidationResult(org.openremote.model.attribute.AttributeValidationResult) Value(org.openremote.model.value.Value) SimulatorElement(org.openremote.model.simulator.SimulatorElement) AbstractAttributeViewExtension(org.openremote.app.client.assets.attributes.AbstractAttributeViewExtension) IsWidget(com.google.gwt.user.client.ui.IsWidget) AssetAttribute(org.openremote.model.asset.AssetAttribute) AttributeView(org.openremote.app.client.assets.attributes.AttributeView) IsWidget(com.google.gwt.user.client.ui.IsWidget) ValueType(org.openremote.model.value.ValueType) SimulatorElement(org.openremote.model.simulator.SimulatorElement) ShowSuccessEvent(org.openremote.app.client.event.ShowSuccessEvent) Value(org.openremote.model.value.Value)

Example 3 with ValueType

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);
}
Also used : java.util(java.util) CodecUtil(org.openremote.container.util.CodecUtil) ConnectionStatus(org.openremote.model.asset.agent.ConnectionStatus) VelbusConfiguration(org.openremote.agent.protocol.velbus.VelbusConfiguration) org.openremote.agent.protocol(org.openremote.agent.protocol) FeatureProcessor(org.openremote.agent.protocol.velbus.device.FeatureProcessor) VelbusDeviceType(org.openremote.agent.protocol.velbus.device.VelbusDeviceType) Level(java.util.logging.Level) AgentLink(org.openremote.model.asset.agent.AgentLink) Document(org.w3c.dom.Document) PROTOCOL_NAMESPACE(org.openremote.model.Constants.PROTOCOL_NAMESPACE) REGEXP_PATTERN_INTEGER_POSITIVE_NON_ZERO(org.openremote.model.util.TextUtil.REGEXP_PATTERN_INTEGER_POSITIVE_NON_ZERO) InputSource(org.xml.sax.InputSource) NodeList(org.w3c.dom.NodeList) ValueType(org.openremote.model.value.ValueType) Asset(org.openremote.model.asset.Asset) AssetType(org.openremote.model.asset.AssetType) Pair(org.openremote.model.util.Pair) FileInfo(org.openremote.model.file.FileInfo) EnumUtil(org.openremote.model.util.EnumUtil) Logger(java.util.logging.Logger) AssetMeta(org.openremote.model.asset.AssetMeta) Consumer(java.util.function.Consumer) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) org.openremote.model.attribute(org.openremote.model.attribute) Values(org.openremote.model.value.Values) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TextUtil.isNullOrEmpty(org.openremote.model.util.TextUtil.isNullOrEmpty) AssetAttribute(org.openremote.model.asset.AssetAttribute) DevicePropertyValue(org.openremote.agent.protocol.velbus.device.DevicePropertyValue) Consumer(java.util.function.Consumer) ValueType(org.openremote.model.value.ValueType) DevicePropertyValue(org.openremote.agent.protocol.velbus.device.DevicePropertyValue)

Aggregations

java.util (java.util)3 AssetAttribute (org.openremote.model.asset.AssetAttribute)3 ValueType (org.openremote.model.value.ValueType)3 IsWidget (com.google.gwt.user.client.ui.IsWidget)2 Environment (org.openremote.app.client.Environment)2 org.openremote.app.client.widget (org.openremote.app.client.widget)2 ValidationFailure (org.openremote.model.ValidationFailure)2 AssetMeta (org.openremote.model.asset.AssetMeta)2 AgentLink (org.openremote.model.asset.agent.AgentLink)2 AttributeValidationResult (org.openremote.model.attribute.AttributeValidationResult)2 EnumUtil (org.openremote.model.util.EnumUtil)2 Pair (org.openremote.model.util.Pair)2 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 Browser (elemental.client.Browser)1 StringReader (java.io.StringReader)1 Consumer (java.util.function.Consumer)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1