100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Added buttons for command/scene execution in manager UI
Christian Bauer0b7c6f1b2881
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.javaindex d6f6482d5..da51132b1 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java@@ -24,8 +24,10 @@ import com.google.gwt.user.client.ui.Widget;import elemental.client.Browser;import org.openremote.manager.client.Environment;import org.openremote.manager.client.datapoint.DatapointBrowser;+import org.openremote.manager.client.util.CollectionsUtil;import org.openremote.manager.client.widget.*;import org.openremote.model.AttributeEvent;+import org.openremote.model.AttributeExecuteStatus;import org.openremote.model.AttributeType;import org.openremote.model.ReadAttributesEvent;import org.openremote.model.asset.Asset;@@ -35,6 +37,7 @@ import org.openremote.model.datapoint.NumberDatapoint;import org.openremote.model.event.bus.EventRegistration;import java.util.ArrayList;+import java.util.LinkedHashMap;import java.util.List;import java.util.function.Consumer;@@ -82,6 +85,26 @@ public abstract class AttributesBrowsersuper.createAttributeGroups();}+ @Override+ protected void sortAttributes(LinkedHashMap<AssetAttribute, FormGroup> attributeGroups) {+ // Executable commands first, then sort form groups by label text ascending+ CollectionsUtil.sortMap(attributeGroups, (o1, o2) -> {+ if (o1.getKey().isExecutable() && !o2.getKey().isExecutable()) {+ return -1;+ } else if (!o1.getKey().isExecutable() && o2.getKey().isExecutable()) {+ return 1;+ } else {+ return o1.getValue().getFormLabel().getText().compareTo(o2.getValue().getFormLabel().getText());+ }+ }+ );+ }++ @Override+ protected boolean isEditorReadOnly(AssetAttribute attribute) {+ return attribute.isExecutable() || super.isEditorReadOnly(attribute);+ }+@Overridepublic void setOpaque(boolean opaque) {super.setOpaque(opaque);@@ -107,22 +130,68 @@ public abstract class AttributesBrowserFormGroupActions formGroupActions,IsWidget editor) {- // Allow direct read/write of attribute if we understand attribute type (have an editor)+ // Allow read/write of attribute if we understand attribute type (have an editor)if (editor != null) {- FormButton writeValueButton = new FormButton();- writeValueButton.setEnabled(!attribute.isReadOnly());- writeValueButton.setText(container.getMessages().write());- writeValueButton.setPrimary(true);- writeValueButton.setIcon("cloud-upload");- writeValueButton.addClickHandler(clickEvent -> writeAttributeValue(attribute));- formGroupActions.add(writeValueButton);-- FormButton readValueButton = new FormButton();- readValueButton.setText(container.getMessages().read());- readValueButton.setIcon("cloud-download");- readValueButton.addClickHandler(clickEvent -> readAttributeValue(attribute));- readButtons.add(readValueButton);- formGroupActions.add(readValueButton);++ if (attribute.isExecutable()) {+ // A command is executed by writing a special value+ FormButton startButton = new FormButton();+ startButton.setEnabled(!attribute.isReadOnly());+ startButton.setText(container.getMessages().start());+ startButton.setPrimary(true);+ startButton.setIcon("play-circle");+ startButton.addClickHandler(clickEvent -> {+ attribute.setValue(AttributeExecuteStatus.REQUEST_START.asJsonValue());+ writeAttributeValue(attribute);+ });+ formGroupActions.add(startButton);++ FormButton repeatButton = new FormButton();+ repeatButton.setEnabled(!attribute.isReadOnly());+ repeatButton.setText(container.getMessages().repeat());+ repeatButton.setPrimary(true);+ repeatButton.setIcon("repeat");+ repeatButton.addClickHandler(clickEvent -> {+ attribute.setValue(AttributeExecuteStatus.REQUEST_REPEATING.asJsonValue());+ writeAttributeValue(attribute);+ });+ formGroupActions.add(repeatButton);++ FormButton cancelButton = new FormButton();+ cancelButton.setEnabled(!attribute.isReadOnly());+ cancelButton.setText(container.getMessages().cancel());+ cancelButton.setPrimary(true);+ cancelButton.setIcon("stop-circle");+ cancelButton.addClickHandler(clickEvent -> {+ attribute.setValue(AttributeExecuteStatus.REQUEST_CANCEL.asJsonValue());+ writeAttributeValue(attribute);+ });+ formGroupActions.add(cancelButton);++ FormButton readStatusButton = new FormButton();+ readStatusButton.setText(container.getMessages().getStatus());+ readStatusButton.setIcon("cloud-download");+ readStatusButton.addClickHandler(clickEvent -> readAttributeValue(attribute));+ readButtons.add(readStatusButton);+ formGroupActions.add(readStatusButton);++ } else {+ // Default read/write actions+ FormButton writeValueButton = new FormButton();+ writeValueButton.setEnabled(!attribute.isReadOnly());+ writeValueButton.setText(container.getMessages().write());+ writeValueButton.setPrimary(true);+ writeValueButton.setIcon("cloud-upload");+ writeValueButton.addClickHandler(clickEvent -> writeAttributeValue(attribute));+ formGroupActions.add(writeValueButton);++ FormButton readValueButton = new FormButton();+ readValueButton.setText(container.getMessages().read());+ readValueButton.setIcon("cloud-download");+ readValueButton.addClickHandler(clickEvent -> readAttributeValue(attribute));+ readButtons.add(readValueButton);+ formGroupActions.add(readValueButton);+ }}}@@ -209,7 +278,11 @@ public abstract class AttributesBrowserenvironment.getEventService().dispatch(new AttributeEvent(attribute.getState()));- showSuccess(container.getMessages().attributeWriteSent(attribute.getName()));+ if (attribute.isExecutable()) {+ showSuccess(container.getMessages().commandRequestSent(attribute.getName()));+ } else {+ showSuccess(container.getMessages().attributeWriteSent(attribute.getName()));+ }}protected void refreshAttribute(AssetAttribute attribute) {diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.javaindex bba210303..d5d485889 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java@@ -112,7 +112,7 @@ public class AttributesEditor}@Override- protected boolean isReadOnly(AssetAttribute attribute) {+ protected boolean isEditorReadOnly(AssetAttribute attribute) {return false; // Always allow editing of attribute value}diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.javaindex 22b7f872e..3887dc288 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java@@ -147,8 +147,8 @@ public abstract class AttributesView<attributeGroups.put(attribute, formGroup);}}- // Sort form groups by label text ascending- CollectionsUtil.sortMap(attributeGroups, Comparator.comparing(a -> a.getFormLabel().getText()));++ sortAttributes(attributeGroups);for (FormGroup attributeGroup : attributeGroups.values()) {container.getPanel().add(attributeGroup);@@ -207,11 +207,11 @@ public abstract class AttributesView<AttributeType attributeType = attribute.getType().orElse(AttributeType.STRING);if (attributeType == AttributeType.STRING) {attributeEditor = createStringEditor(attribute, defaultValueItem, style, formGroup);- } else if (attributeType == AttributeType.INTEGER) {+ } else if (attributeType == AttributeType.INTEGER) {attributeEditor = createIntegerEditor(attribute, defaultValueItem, style, formGroup);} else if (attributeType == AttributeType.DECIMAL) {attributeEditor = createDecimalEditor(attribute, defaultValueItem, style, formGroup);- } else if (attributeType == AttributeType.BOOLEAN) {+ } else if (attributeType == AttributeType.BOOLEAN) {attributeEditor = createBooleanEditor(attribute, defaultValueItem, style, formGroup);} else {return null;@@ -233,7 +233,7 @@ public abstract class AttributesView<String currentValue = attribute.getValueAsString();Optional<String> defaultValue = defaultValueItem.map(AbstractValueHolder::getValueAsString);- Consumer<String> updateConsumer = isReadOnly(attribute) ? null : value -> {+ Consumer<String> updateConsumer = isEditorReadOnly(attribute) ? null : value -> {formGroup.setError(false);attribute.setValueUnchecked(Json.create(value));};@@ -277,7 +277,7 @@ public abstract class AttributesView<protected AttributeEditor createIntegerEditor(AssetAttribute attribute, Optional<MetaItem> defaultValueItem, S style, FormGroup formGroup) {String currentValue = attribute.getValueAsString();Optional<String> defaultValue = defaultValueItem.map(AbstractValueHolder::getValueAsString);- Consumer<String> updateConsumer = isReadOnly(attribute) ? null : value -> {+ Consumer<String> updateConsumer = isEditorReadOnly(attribute) ? null : value -> {Integer intValue = Integer.valueOf(value);formGroup.setError(false);attribute.setValueUnchecked(Json.create(intValue));@@ -332,7 +332,7 @@ public abstract class AttributesView<protected AttributeEditor createDecimalEditor(AssetAttribute attribute, Optional<MetaItem> defaultValueItem, S style, FormGroup formGroup) {String currentValue = attribute.getValueAsString();Optional<String> defaultValue = defaultValueItem.map(AbstractValueHolder::getValueAsString);- Consumer<String> updateConsumer = isReadOnly(attribute) ? null : value -> {+ Consumer<String> updateConsumer = isEditorReadOnly(attribute) ? null : value -> {Double decimalValue = Double.valueOf(value);formGroup.setError(false);attribute.setValueUnchecked(Json.create(decimalValue));@@ -387,7 +387,7 @@ public abstract class AttributesView<protected AttributeEditor createBooleanEditor(AssetAttribute attribute, Optional<MetaItem> defaultValueItem, S style, FormGroup formGroup) {Boolean currentValue = attribute.getValueAsBoolean();Optional<Boolean> defaultValue = defaultValueItem.map(AbstractValueHolder::getValueAsBoolean);- Consumer<Boolean> updateConsumer = isReadOnly(attribute) ? null : value -> {+ Consumer<Boolean> updateConsumer = isEditorReadOnly(attribute) ? null : value -> {formGroup.setError(false);attribute.setValueUnchecked(Json.create(value));};@@ -445,7 +445,7 @@ public abstract class AttributesView<return input;}- protected boolean isReadOnly(AssetAttribute attribute) {+ protected boolean isEditorReadOnly(AssetAttribute attribute) {return attribute.isReadOnly();}@@ -453,6 +453,13 @@ public abstract class AttributesView<return true;}+ protected void sortAttributes(LinkedHashMap<AssetAttribute, FormGroup> attributeGroups) {+ // Sort form groups by label text ascending+ CollectionsUtil.sortMap(attributeGroups, Comparator.comparing(+ entry -> entry.getValue().getFormLabel().getText())+ );+ }+protected void removeAttribute(AssetAttribute attribute) {Attribute.Functions.removeAttribute(attributes, attribute.getName());editors.remove(attribute.getName());diff --git a/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java b/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.javaindex 77566ff9c..2bf7e0591 100644--- a/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java+++ b/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java@@ -328,4 +328,12 @@ public interface ManagerMessages extends Messages {String showLiveUpdates();String refreshAllAttributes();++ String start();++ String repeat();++ String getStatus();++ String commandRequestSent(String name);}diff --git a/manager/client/src/main/java/org/openremote/manager/client/util/CollectionsUtil.java b/manager/client/src/main/java/org/openremote/manager/client/util/CollectionsUtil.javaindex 4b96deffa..6ffe25ec1 100644--- a/manager/client/src/main/java/org/openremote/manager/client/util/CollectionsUtil.java+++ b/manager/client/src/main/java/org/openremote/manager/client/util/CollectionsUtil.java@@ -23,9 +23,9 @@ import java.util.*;public class CollectionsUtil {- public static <K, V> void sortMap(LinkedHashMap<K, V> map, Comparator<? super V> c) {+ public static <K, V> void sortMap(LinkedHashMap<K, V> map, Comparator<Map.Entry<K, V>> c) {List<Map.Entry<K, V>> entries = new ArrayList<>(map.entrySet());- Collections.sort(entries, (lhs, rhs) -> c.compare(lhs.getValue(), rhs.getValue()));+ entries.sort(c);map.clear();for(Map.Entry<K, V> e : entries) {map.put(e.getKey(), e.getValue());diff --git a/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties b/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.propertiesindex 5d848ef66..1b63f1c41 100644--- a/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties+++ b/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties@@ -174,3 +174,7 @@ noTenantsFound=No tenants found, please create a tenant.noUserFound=No users found, please create a user.showLiveUpdates=Show live updatesrefreshAllAttributes=Read and refresh all attributes+start=Start+repeat=Repeat+getStatus=Get Status+commandRequestSent=Sent command request: {0}