Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Asset viewing and editing are now two different activities in manager UI

Christian Bauer3e4391983bab
diff --git a/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java b/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java
index 790821cdd..3b8f8c343 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java
@@ -36,8 +36,10 @@ import org.openremote.manager.client.apps.AppsActivity;
import org.openremote.manager.client.apps.AppsPlace;
import org.openremote.manager.client.assets.AssetsDashboardActivity;
import org.openremote.manager.client.assets.AssetsDashboardPlace;
-import org.openremote.manager.client.assets.asset.AssetActivity;
-import org.openremote.manager.client.assets.asset.AssetPlace;
+import org.openremote.manager.client.assets.asset.AssetEditActivity;
+import org.openremote.manager.client.assets.asset.AssetEditPlace;
+import org.openremote.manager.client.assets.asset.AssetViewActivity;
+import org.openremote.manager.client.assets.asset.AssetViewPlace;
import org.openremote.manager.client.assets.tenant.AssetsTenantActivity;
import org.openremote.manager.client.assets.tenant.AssetsTenantPlace;
import org.openremote.manager.client.event.ShowFailureEvent;
@@ -75,7 +77,8 @@ public class ManagerActivityMapper implements AppActivityMapper {
protected final ManagerMessages managerMessages;
protected final Provider<AssetsDashboardActivity> assetsDashboardActivityProvider;
protected final Provider<AssetsTenantActivity> assetsTenantActivityProvider;
- protected final Provider<AssetActivity> assetActivityProvider;
+ protected final Provider<AssetViewActivity> assetViewActivityProvider;
+ protected final Provider<AssetEditActivity> assetEditActivityProvider;
protected final Provider<MapActivity> mapActivityProvider;
protected final Provider<GlobalRulesListActivity> globalRulesActivityProvider;
protected final Provider<GlobalRulesEditorActivity> globalRulesEditorActivityProvider;
@@ -97,7 +100,8 @@ public class ManagerActivityMapper implements AppActivityMapper {
ManagerMessages managerMessages,
Provider<AssetsDashboardActivity> assetsDashboardActivityProvider,
Provider<AssetsTenantActivity> assetsTenantActivityProvider,
- Provider<AssetActivity> assetActivityProvider,
+ Provider<AssetViewActivity> assetViewActivityProvider,
+ Provider<AssetEditActivity> assetEditActivityProvider,
Provider<MapActivity> mapActivityProvider,
Provider<GlobalRulesListActivity> globalRulesActivityProvider,
Provider<GlobalRulesEditorActivity> globalRulesEditorActivityProvider,
@@ -117,7 +121,8 @@ public class ManagerActivityMapper implements AppActivityMapper {
this.managerMessages = managerMessages;
this.assetsDashboardActivityProvider = assetsDashboardActivityProvider;
this.assetsTenantActivityProvider = assetsTenantActivityProvider;
- this.assetActivityProvider = assetActivityProvider;
+ this.assetViewActivityProvider = assetViewActivityProvider;
+ this.assetEditActivityProvider = assetEditActivityProvider;
this.mapActivityProvider = mapActivityProvider;
this.globalRulesActivityProvider = globalRulesActivityProvider;
this.globalRulesEditorActivityProvider = globalRulesEditorActivityProvider;
@@ -142,8 +147,11 @@ public class ManagerActivityMapper implements AppActivityMapper {
if (place instanceof AssetsTenantPlace) {
return assetsTenantActivityProvider.get().init(securityService, (AssetsTenantPlace) place);
}
- if (place instanceof AssetPlace) {
- return assetActivityProvider.get().init(securityService, (AssetPlace) place);
+ if (place instanceof AssetViewPlace) {
+ return assetViewActivityProvider.get().init(securityService, (AssetViewPlace) place);
+ }
+ if (place instanceof AssetEditPlace) {
+ return assetEditActivityProvider.get().init(securityService, (AssetEditPlace) place);
}
if (place instanceof MapPlace) {
return mapActivityProvider.get().init(securityService, (MapPlace) place);
diff --git a/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java b/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java
index c2dfc42a1..ab52b445b 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java
@@ -28,7 +28,8 @@ import org.openremote.manager.client.admin.users.AdminUserPlace;
import org.openremote.manager.client.admin.users.AdminUsersPlace;
import org.openremote.manager.client.apps.AppsPlace;
import org.openremote.manager.client.assets.AssetsDashboardPlace;
-import org.openremote.manager.client.assets.asset.AssetPlace;
+import org.openremote.manager.client.assets.asset.AssetEditPlace;
+import org.openremote.manager.client.assets.asset.AssetViewPlace;
import org.openremote.manager.client.assets.tenant.AssetsTenantPlace;
import org.openremote.manager.client.map.MapAssetPlace;
import org.openremote.manager.client.map.MapTenantPlace;
@@ -46,7 +47,8 @@ import org.openremote.manager.client.user.UserAccountPlace;
MapTenantPlace.Tokenizer.class,
AssetsDashboardPlace.Tokenizer.class,
AssetsTenantPlace.Tokenizer.class,
- AssetPlace.Tokenizer.class,
+ AssetViewPlace.Tokenizer.class,
+ AssetEditPlace.Tokenizer.class,
GlobalRulesListPlace.Tokenizer.class,
GlobalRulesEditorPlace.Tokenizer.class,
TenantRulesListPlace.Tokenizer.class,
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderPresenter.java b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderPresenter.java
index b7a3a384e..a196b15a6 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderPresenter.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderPresenter.java
@@ -24,7 +24,7 @@ import com.google.inject.Inject;
import org.openremote.manager.client.admin.overview.AdminOverviewPlace;
import org.openremote.manager.client.apps.AppsPlace;
import org.openremote.manager.client.assets.AssetsDashboardPlace;
-import org.openremote.manager.client.assets.asset.AssetPlace;
+import org.openremote.manager.client.assets.asset.AssetViewPlace;
import org.openremote.manager.client.assets.browser.AssetBrowserSelection;
import org.openremote.manager.client.assets.browser.AssetTreeNode;
import org.openremote.manager.client.assets.browser.TenantTreeNode;
@@ -112,7 +112,7 @@ public class HeaderPresenter implements HeaderView.Presenter {
if (assetBrowserSelection.getSelectedNode() instanceof TenantTreeNode) {
placeController.goTo(new AssetsTenantPlace(assetBrowserSelection.getSelectedNode().getId()));
} else if (assetBrowserSelection.getSelectedNode() instanceof AssetTreeNode) {
- placeController.goTo(new AssetPlace(assetBrowserSelection.getSelectedNode().getId()));
+ placeController.goTo(new AssetViewPlace(assetBrowserSelection.getSelectedNode().getId()));
} else {
placeController.goTo(new AssetsDashboardPlace());
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.ui.xml
index 3e0aabf01..2e2441723 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.ui.xml
@@ -4,7 +4,7 @@
<ui:style>
.logoButton {
- height: 36px;
+ height: 32px;
}
.navItemFirst {
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardActivity.java
index 5bff65533..5ce961f4f 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardActivity.java
@@ -21,7 +21,7 @@ package org.openremote.manager.client.assets;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import org.openremote.manager.client.Environment;
-import org.openremote.manager.client.assets.asset.AssetPlace;
+import org.openremote.manager.client.assets.asset.AssetViewPlace;
import org.openremote.manager.client.assets.browser.AssetBrowser;
import org.openremote.manager.client.assets.browser.AssetBrowserSelection;
import org.openremote.manager.client.assets.browser.AssetTreeNode;
@@ -65,7 +65,7 @@ public class AssetsDashboardActivity
);
} else if (event.getSelectedNode() instanceof AssetTreeNode) {
environment.getPlaceController().goTo(
- new AssetPlace(event.getSelectedNode().getId())
+ new AssetViewPlace(event.getSelectedNode().getId())
);
}
}));
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardImpl.ui.xml
index 1d9c19465..a1029ba9e 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardImpl.ui.xml
@@ -32,7 +32,7 @@
<w:Hyperlink
addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
icon="plus-square"
- targetHistoryToken="asset:"
+ targetHistoryToken="assetEdit:"
text="{managerMessages.createAsset}"/>
</g:HTMLPanel>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardPlace.java b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardPlace.java
index cfcced09e..56e286153 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardPlace.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsDashboardPlace.java
@@ -19,11 +19,10 @@
*/
package org.openremote.manager.client.assets;
-import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
-public class AssetsDashboardPlace extends Place implements AssetsPlace {
+public class AssetsDashboardPlace extends AssetsPlace {
public AssetsDashboardPlace() {
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsModule.java b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsModule.java
index 25e4a204f..cc90942d7 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsModule.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsModule.java
@@ -22,9 +22,7 @@ package org.openremote.manager.client.assets;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
-import org.openremote.manager.client.assets.asset.AssetActivity;
-import org.openremote.manager.client.assets.asset.AssetView;
-import org.openremote.manager.client.assets.asset.AssetViewImpl;
+import org.openremote.manager.client.assets.asset.*;
import org.openremote.manager.client.assets.browser.AssetBrowser;
import org.openremote.manager.client.assets.browser.AssetBrowserImpl;
import org.openremote.manager.client.assets.browser.AssetBrowserPresenter;
@@ -47,7 +45,10 @@ public class AssetsModule extends AbstractGinModule {
bind(AssetsTenantActivity.class);
bind(AssetView.class).to(AssetViewImpl.class).in(Singleton.class);
- bind(AssetActivity.class);
+ bind(AssetViewActivity.class);
+
+ bind(AssetEdit.class).to(AssetEditImpl.class).in(Singleton.class);
+ bind(AssetEditActivity.class);
}
@Provides
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsPlace.java b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsPlace.java
index bca704b51..1843615e6 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsPlace.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/AssetsPlace.java
@@ -19,6 +19,8 @@
*/
package org.openremote.manager.client.assets;
-public interface AssetsPlace {
+import com.google.gwt.place.shared.Place;
+
+public class AssetsPlace extends Place {
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AbstractAssetActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AbstractAssetActivity.java
new file mode 100644
index 000000000..38a1a1593
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AbstractAssetActivity.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.client.assets.asset;
+
+import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.assets.AssetBrowsingActivity;
+import org.openremote.manager.client.assets.browser.AssetBrowser;
+import org.openremote.manager.client.mvp.AppActivity;
+import org.openremote.model.asset.Asset;
+
+public abstract class AbstractAssetActivity<PLACE extends AssetPlace> extends AssetBrowsingActivity<PLACE> {
+
+ protected String assetId;
+ protected Asset asset;
+ protected Asset parentAsset;
+
+ public AbstractAssetActivity(Environment environment, AssetBrowser.Presenter assetBrowserPresenter) {
+ super(environment, assetBrowserPresenter);
+ }
+
+ @Override
+ protected AppActivity<PLACE> init(PLACE place) {
+ this.assetId = place.getAssetId();
+ return this;
+ }
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEdit.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEdit.java
new file mode 100644
index 000000000..cc68ff521
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEdit.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.client.assets.asset;
+
+import com.google.gwt.user.client.ui.IsWidget;
+import elemental.json.JsonObject;
+import org.openremote.manager.client.assets.attributes.AttributesEditor;
+import org.openremote.manager.client.assets.browser.BrowserTreeNode;
+import org.openremote.manager.client.widget.FormView;
+import org.openremote.manager.shared.map.GeoJSON;
+import org.openremote.model.asset.AssetType;
+
+import java.util.Date;
+
+public interface AssetEdit extends FormView, IsWidget {
+
+ interface Presenter {
+
+ void view();
+
+ void onParentSelection(BrowserTreeNode treeNode);
+
+ void centerMap();
+
+ void onMapClicked(double lng, double lat);
+
+ void onAssetTypeSelected(AssetType value);
+
+ void update();
+
+ void create();
+
+ void delete();
+ }
+
+ void setPresenter(Presenter presenter);
+
+ void setName(String name);
+
+ String getName();
+
+ void setNameError(boolean error);
+
+ void setCreatedOn(Date createdOn);
+
+ void setParentNode(BrowserTreeNode treeNode);
+
+ void initialiseMap(JsonObject mapOptions);
+
+ boolean isMapInitialised();
+
+ void setLocation(double[] coordinates);
+
+ void showMapPopup(double lng, double lat, String text);
+
+ void hideMapPopup();
+
+ void showFeaturesSelection(GeoJSON mapFeatures);
+
+ void flyTo(double[] coordinates);
+
+ void setTypeSelectionEnabled(boolean enabled);
+
+ void setAvailableTypes(AssetType[] assetTypes);
+
+ void selectType(AssetType assetType);
+
+ void setTypeInputVisible(boolean visible);
+
+ void setType(String type);
+
+ String getType();
+
+ void setTypeError(boolean error);
+
+ AttributesEditor.Container getAttributesEditorContainer();
+
+ void setAttributesEditor(AttributesEditor attributesEditor);
+
+ void enableCreate(boolean enable);
+
+ void enableUpdate(boolean enable);
+
+ void enableDelete(boolean enable);
+
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.java
similarity index 72%
rename from manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetActivity.java
rename to manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.java
index 718403655..356c52fc5 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.java
@@ -20,15 +20,12 @@
package org.openremote.manager.client.assets.asset;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
-import elemental.json.Json;
-import elemental.json.JsonValue;
import org.openremote.manager.client.Environment;
import org.openremote.manager.client.admin.TenantMapper;
-import org.openremote.manager.client.assets.AssetBrowsingActivity;
import org.openremote.manager.client.assets.AssetMapper;
import org.openremote.manager.client.assets.AssetsDashboardPlace;
+import org.openremote.manager.client.assets.attributes.AttributesEditor;
import org.openremote.manager.client.assets.browser.*;
-import org.openremote.manager.client.assets.editor.AttributesEditor;
import org.openremote.manager.client.assets.tenant.AssetsTenantPlace;
import org.openremote.manager.client.event.ShowFailureEvent;
import org.openremote.manager.client.event.ShowSuccessEvent;
@@ -36,17 +33,13 @@ import org.openremote.manager.client.event.bus.EventBus;
import org.openremote.manager.client.event.bus.EventRegistration;
import org.openremote.manager.client.interop.elemental.JsonObjectMapper;
import org.openremote.manager.client.map.MapView;
-import org.openremote.manager.client.mvp.AppActivity;
import org.openremote.manager.shared.asset.AssetResource;
-import org.openremote.manager.shared.http.EntityWriter;
import org.openremote.manager.shared.map.MapResource;
import org.openremote.manager.shared.security.Tenant;
import org.openremote.manager.shared.security.TenantResource;
import org.openremote.manager.shared.validation.ConstraintViolation;
-import org.openremote.model.Attribute;
import org.openremote.model.Attributes;
import org.openremote.model.Consumer;
-import org.openremote.model.Runnable;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetType;
@@ -56,11 +49,11 @@ import java.util.Collection;
import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;
-public class AssetActivity
- extends AssetBrowsingActivity<AssetPlace>
- implements AssetView.Presenter {
+public class AssetEditActivity
+ extends AbstractAssetActivity<AssetEditPlace>
+ implements AssetEdit.Presenter {
- final AssetView view;
+ final AssetEdit view;
final AssetResource assetResource;
final AssetMapper assetMapper;
final MapResource mapResource;
@@ -69,22 +62,19 @@ public class AssetActivity
final TenantMapper tenantMapper;
final protected Consumer<ConstraintViolation[]> validationErrorHandler;
- String assetId;
- Asset asset;
double[] selectedCoordinates;
- Asset parentAsset;
AttributesEditor attributesEditor;
@Inject
- public AssetActivity(Environment environment,
- AssetBrowser.Presenter assetBrowserPresenter,
- AssetView view,
- AssetResource assetResource,
- AssetMapper assetMapper,
- MapResource mapResource,
- JsonObjectMapper jsonObjectMapper,
- TenantResource tenantResource,
- TenantMapper tenantMapper) {
+ public AssetEditActivity(Environment environment,
+ AssetBrowser.Presenter assetBrowserPresenter,
+ AssetEdit view,
+ AssetResource assetResource,
+ AssetMapper assetMapper,
+ MapResource mapResource,
+ JsonObjectMapper jsonObjectMapper,
+ TenantResource tenantResource,
+ TenantMapper tenantMapper) {
super(environment, assetBrowserPresenter);
this.view = view;
this.assetResource = assetResource;
@@ -110,30 +100,26 @@ public class AssetActivity
}
- @Override
- protected AppActivity<AssetPlace> init(AssetPlace place) {
- this.assetId = place.getAssetId();
- return this;
- }
-
@Override
public void start(AcceptsOneWidget container, EventBus eventBus, Collection<EventRegistration> registrations) {
view.setPresenter(this);
container.setWidget(view.asWidget());
- registrations.add(eventBus.register(AssetBrowserSelection.class, event -> {
- if (event.getSelectedNode() instanceof TenantTreeNode) {
- environment.getPlaceController().goTo(
- new AssetsTenantPlace(event.getSelectedNode().getId())
- );
- } else if (event.getSelectedNode() instanceof AssetTreeNode) {
- if (this.assetId == null || !this.assetId.equals(event.getSelectedNode().getId())) {
+ registrations.add(eventBus.register(
+ AssetBrowserSelection.class, event -> {
+ if (event.getSelectedNode() instanceof TenantTreeNode) {
environment.getPlaceController().goTo(
- new AssetPlace(event.getSelectedNode().getId())
+ new AssetsTenantPlace(event.getSelectedNode().getId())
);
+ } else if (event.getSelectedNode() instanceof AssetTreeNode) {
+ if (this.assetId == null || !this.assetId.equals(event.getSelectedNode().getId())) {
+ environment.getPlaceController().goTo(
+ new AssetEditPlace(event.getSelectedNode().getId())
+ );
+ }
}
}
- }));
+ ));
if (!view.isMapInitialised()) {
environment.getRequestService().execute(
@@ -143,13 +129,10 @@ public class AssetActivity
view::initialiseMap,
ex -> handleRequestException(ex, environment)
);
- } else {
- view.refreshMap();
}
asset = null;
if (assetId != null) {
- view.setFormBusy(true);
assetBrowserPresenter.loadAsset(assetId, loadedAsset -> {
this.asset = loadedAsset;
assetBrowserPresenter.selectAsset(asset);
@@ -177,6 +160,13 @@ public class AssetActivity
view.setPresenter(null);
}
+ @Override
+ public void view() {
+ if (assetId != null) {
+ environment.getPlaceController().goTo(new AssetViewPlace(assetId));
+ }
+ }
+
@Override
public void onParentSelection(BrowserTreeNode treeNode) {
if (treeNode instanceof TenantTreeNode) {
@@ -229,7 +219,7 @@ public class AssetActivity
environment.getMessages().assetUpdated(asset.getName())
));
assetBrowserPresenter.refresh(asset.getParentId() == null);
- environment.getPlaceController().goTo(new AssetPlace(assetId));
+ environment.getPlaceController().goTo(new AssetViewPlace(assetId));
},
ex -> handleRequestException(ex, environment.getEventBus(), environment.getMessages(), validationErrorHandler)
);
@@ -292,7 +282,6 @@ public class AssetActivity
protected void startCreateAsset(Tenant authenticatedTenant) {
assetBrowserPresenter.clearSelection();
- view.setFormBusy(true);
asset = new Asset();
asset.setName("My New Asset");
asset.setRealmId(authenticatedTenant.getId());
@@ -310,7 +299,6 @@ public class AssetActivity
protected void startEditAsset() {
clearViewMessages();
view.setTypeSelectionEnabled(false);
- view.setEditable(asset.getWellKnownType().isEditable());
writeAssetToView();
writeTypeToView();
writeAttributesEditorToView();
@@ -330,12 +318,8 @@ public class AssetActivity
view.setName(asset.getName());
view.setCreatedOn(asset.getCreatedOn());
view.setLocation(asset.getCoordinates());
- if (asset != null && asset.getId() != null) {
- view.showFeaturesSelection(MapView.getFeature(asset));
- view.flyTo(asset.getCoordinates());
- } else {
- view.hideFeaturesSelection();
- }
+ view.showFeaturesSelection(MapView.getFeature(asset));
+ view.flyTo(asset.getCoordinates());
view.enableCreate(assetId == null);
view.enableUpdate(assetId != null);
view.enableDelete(assetId != null);
@@ -358,68 +342,22 @@ public class AssetActivity
protected void writeTypeToView() {
AssetType assetType = asset.getWellKnownType();
view.selectType(assetType);
- view.setAvailableTypes(AssetType.editable());
+ view.setAvailableTypes(AssetType.valuesSorted());
view.setTypeInputVisible(AssetType.CUSTOM.equals(assetType));
view.setType(asset.getType());
}
protected void writeAttributesEditorToView() {
- switch (asset.getWellKnownType()) {
- /* TODO Implement asset type-specific editors
- case AGENT:
- attributesEditor = new AgentAttributesEditor(
- environment,
- view.getAttributesEditorContainer(),
- new Attributes(asset.getAttributes()),
- isCreateAsset,
- asset,
- connectorResource,
- connectorArrayMapper
- );
- break;
- */
- default:
- attributesEditor = new AttributesEditor<AttributesEditor.Style>(
- environment,
- view.getAttributesEditorContainer(),
- new Attributes(
- assetId == null
- ? asset.getWellKnownType().getDefaultAttributes()
- : asset.getAttributes()
- ),
- assetId == null
- ) {
- @Override
- protected void readAttributeValue(Attribute attribute, Runnable onSuccess) {
- environment.getRequestService().execute(
- value -> value,
- requestParams -> assetResource.readAttributeValue(requestParams, assetId, attribute.getName()),
- 200,
- result -> {
- JsonValue value = Json.instance().parse(result);
- // TODO Bug in Elemental, can't check this value for null etc.
- attribute.setValueUnchecked(value);
- showInfo(container.getMessages().attributeValueRefreshed(attribute.getName()));
- onSuccess.run();
- },
- ex -> handleRequestException(ex, environment)
- );
- }
-
- @Override
- protected void writeAttributeValue(Attribute attribute) {
- environment.getRequestService().execute(
- (EntityWriter<String>) value -> value,
- requestParams -> assetResource.writeAttributeValue(
- requestParams, assetId, attribute.getName(), attribute.getValue().toJson()
- ),
- 204,
- () -> showSuccess(container.getMessages().attributeValueStored(attribute.getName())),
- ex -> handleRequestException(ex, environment)
- );
- }
- };
- }
+ attributesEditor = new AttributesEditor(
+ environment,
+ view.getAttributesEditorContainer(),
+ new Attributes(
+ assetId == null
+ ? asset.getWellKnownType().getDefaultAttributes()
+ : asset.getAttributes()
+ ),
+ assetId == null
+ );
view.setAttributesEditor(attributesEditor);
attributesEditor.build();
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.java
new file mode 100644
index 000000000..ca637c5fe
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.java
@@ -0,0 +1,444 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.client.assets.asset;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.resources.client.CssResource;
+import com.google.gwt.text.shared.AbstractRenderer;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiHandler;
+import com.google.gwt.user.client.ui.*;
+import com.google.inject.Provider;
+import elemental.json.JsonObject;
+import org.openremote.manager.client.app.dialog.ConfirmationDialog;
+import org.openremote.manager.client.assets.attributes.AttributesEditor;
+import org.openremote.manager.client.assets.browser.AssetBrowser;
+import org.openremote.manager.client.assets.browser.AssetSelector;
+import org.openremote.manager.client.assets.browser.BrowserTreeNode;
+import org.openremote.manager.client.i18n.ManagerMessages;
+import org.openremote.manager.client.widget.*;
+import org.openremote.manager.client.widget.PushButton;
+import org.openremote.manager.shared.map.GeoJSON;
+import org.openremote.model.Constants;
+import org.openremote.model.asset.AssetType;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+
+public class AssetEditImpl extends FormViewImpl implements AssetEdit {
+
+ interface UI extends UiBinder<FlexSplitPanel, AssetEditImpl> {
+ }
+
+ interface Style extends CssResource {
+
+ String navItem();
+
+ String formMessages();
+
+ String mapWidget();
+ }
+
+ interface AttributesEditorStyle extends CssResource, AttributesEditor.Style {
+
+ String integerEditor();
+
+ String decimalEditor();
+
+ String stringEditor();
+
+ String booleanEditor();
+ }
+
+ @UiField
+ Style style;
+
+ @UiField
+ AttributesEditorStyle attributesEditorStyle;
+
+ @UiField
+ FlexSplitPanel splitPanel;
+
+ @UiField
+ HTMLPanel sidebarContainer;
+
+ @UiField
+ InlineLabel headlineLabel;
+
+ @UiField
+ FormButton viewButton;
+
+ /* ############################################################################ */
+
+ @UiField
+ FormGroup nameGroup;
+ @UiField
+ TextBox nameInput;
+
+ @UiField
+ FormGroup createdOnGroup;
+ @UiField
+ FormOutputText createdOnOutput;
+ @UiField
+ FormButton showHistoryButton;
+
+ @UiField(provided = true)
+ AssetSelector parentAssetSelector;
+
+ @UiField
+ FormGroup locationGroup;
+ @UiField
+ FormOutputLocation locationOutput;
+ @UiField
+ FormButton centerMapButton;
+ @UiField
+ MapWidget mapWidget;
+
+ /* ############################################################################ */
+
+ @UiField
+ Form attributesForm;
+ @UiField
+ FormGroup typeGroup;
+ @UiField(provided = true)
+ FormValueListBox<AssetType> typeListBox;
+ @UiField
+ FormInputText typeInput;
+ @UiField
+ Label customTypeInfoLabel;
+ @UiField
+ FlowPanel attributesEditorContainer;
+
+ /* ############################################################################ */
+
+ @UiField
+ Form submitForm;
+ @UiField
+ FormGroup submitButtonGroup;
+ @UiField
+ PushButton createButton;
+ @UiField
+ PushButton updateButton;
+ @UiField
+ PushButton deleteButton;
+
+ final AssetBrowser assetBrowser;
+ Presenter presenter;
+ AttributesEditor attributesEditor;
+
+ @Inject
+ public AssetEditImpl(AssetBrowser assetBrowser,
+ Provider<ConfirmationDialog> confirmationDialogProvider,
+ ManagerMessages managerMessages) {
+ super(confirmationDialogProvider);
+ this.assetBrowser = assetBrowser;
+
+ parentAssetSelector = new AssetSelector(
+ assetBrowser.getPresenter(),
+ managerMessages,
+ managerMessages.parentAsset(),
+ managerMessages.selectAssetDescription(),
+ treeNode -> {
+ if (presenter != null) {
+ presenter.onParentSelection(treeNode);
+ }
+ }
+ ) {
+ @Override
+ public void beginSelection() {
+ AssetEditImpl.this.setOpaque(true);
+ super.beginSelection();
+ }
+
+ @Override
+ public void endSelection() {
+ super.endSelection();
+ AssetEditImpl.this.setOpaque(false);
+ }
+ };
+
+ typeListBox = new FormValueListBox<>(
+ new AbstractRenderer<AssetType>() {
+ @Override
+ public String render(AssetType assetType) {
+ if (assetType == null)
+ assetType = AssetType.CUSTOM;
+ return managerMessages.assetTypeLabel(assetType.name());
+ }
+ }
+ );
+
+ typeListBox.addValueChangeHandler(event -> {
+ if (presenter != null) {
+ presenter.onAssetTypeSelected(event.getValue());
+ }
+ });
+
+ UI ui = GWT.create(UI.class);
+ initWidget(ui.createAndBindUi(this));
+
+ splitPanel.setOnResize(() -> mapWidget.resize());
+ }
+
+ @Override
+ public void setPresenter(Presenter presenter) {
+ this.presenter = presenter;
+
+ // Restore initial state of view
+ sidebarContainer.clear();
+ headlineLabel.setText(null);
+ setFormBusy(true);
+ nameGroup.setError(false);
+ nameInput.setReadOnly(false);
+ nameInput.setValue(null);
+ createdOnOutput.setText(null);
+ parentAssetSelector.init();
+ locationOutput.setText(null);
+ centerMapButton.setEnabled(false);
+ typeGroup.setError(false);
+ typeListBox.setValue(null);
+ typeListBox.setAcceptableValues(new ArrayList<>());
+ typeListBox.setEnabled(true);
+ typeInput.setVisible(false);
+ customTypeInfoLabel.setVisible(false);
+ showFeaturesSelection(GeoJSON.EMPTY_FEATURE_COLLECTION);
+ hideMapPopup();
+ setOpaque(false);
+ attributesEditorContainer.clear();
+ attributesEditor = null;
+
+ if (presenter != null) {
+ assetBrowser.asWidget().removeFromParent();
+ sidebarContainer.add(assetBrowser.asWidget());
+ }
+ }
+
+ @Override
+ public void setFormBusy(boolean busy) {
+ super.setFormBusy(busy);
+ attributesForm.setBusy(busy);
+ submitForm.setBusy(busy);
+ }
+
+ @UiHandler("viewButton")
+ void viewClicked(ClickEvent e) {
+ if (presenter != null)
+ presenter.view();
+ }
+
+ /* ############################################################################ */
+
+ @Override
+ public void setName(String name) {
+ nameInput.setValue(name);
+ }
+
+ @Override
+ public String getName() {
+ return nameInput.getValue().length() > 0 ? nameInput.getValue() : null;
+ }
+
+ @Override
+ public void setNameError(boolean error) {
+ nameGroup.setError(error);
+ }
+
+ @Override
+ public void setCreatedOn(Date createdOn) {
+ createdOnOutput.setText(
+ createdOn != null ? DateTimeFormat.getFormat(Constants.DEFAULT_DATETIME_FORMAT).format(createdOn) : ""
+ );
+ }
+
+ @Override
+ public void setParentNode(BrowserTreeNode treeNode) {
+ parentAssetSelector.setSelectedNode(treeNode);
+ }
+
+ @Override
+ public void setLocation(double[] coordinates) {
+ if (locationOutput.setCoordinates(managerMessages.selectLocation(), coordinates)) {
+ centerMapButton.setEnabled(true);
+ } else {
+ centerMapButton.setEnabled(false);
+ }
+ }
+
+ @Override
+ public void initialiseMap(JsonObject mapOptions) {
+ mapWidget.initialise(mapOptions, () -> {
+ });
+ mapWidget.addNavigationControl();
+ mapWidget.setClickListener((lng, lat) -> {
+ presenter.onMapClicked(lng, lat);
+ });
+ }
+
+ @Override
+ public boolean isMapInitialised() {
+ return mapWidget.isInitialised();
+ }
+
+ @Override
+ public void showMapPopup(double lng, double lat, String text) {
+ mapWidget.showPopup(lng, lat, text);
+ }
+
+ @Override
+ public void hideMapPopup() {
+ mapWidget.hidePopup();
+ }
+
+ @Override
+ public void showFeaturesSelection(GeoJSON mapFeatures) {
+ mapWidget.showFeatures(MapWidget.FEATURES_SOURCE_SELECTION, mapFeatures);
+ }
+
+ @Override
+ public void flyTo(double[] coordinates) {
+ mapWidget.flyTo(coordinates);
+ }
+
+ @UiHandler("centerMapButton")
+ void centerMapClicked(ClickEvent e) {
+ if (presenter != null)
+ presenter.centerMap();
+ }
+
+ /* ############################################################################ */
+
+ @Override
+ public void setTypeSelectionEnabled(boolean enabled) {
+ typeListBox.setEnabled(enabled);
+ }
+
+ @Override
+ public void setAvailableTypes(AssetType[] assetTypes) {
+ typeListBox.setAcceptableValues(Arrays.asList(assetTypes));
+ }
+
+ @Override
+ public void selectType(AssetType assetType) {
+ typeListBox.setValue(assetType);
+ }
+
+ @Override
+ public void setTypeInputVisible(boolean visible) {
+ typeInput.setVisible(visible);
+ customTypeInfoLabel.setVisible(visible);
+ }
+
+ @Override
+ public void setType(String type) {
+ typeInput.setValue(type);
+ }
+
+ @Override
+ public String getType() {
+ return typeInput.getValue().length() > 0 ? typeInput.getValue() : null;
+ }
+
+ @Override
+ public void setTypeError(boolean error) {
+ typeGroup.setError(error);
+ }
+
+ @Override
+ public AttributesEditor.Container getAttributesEditorContainer() {
+ return new AttributesEditor.Container() {
+ @Override
+ public AttributesEditor.Style getStyle() {
+ return attributesEditorStyle;
+ }
+
+ @Override
+ public InsertPanel getPanel() {
+ return attributesEditorContainer;
+ }
+
+ @Override
+ public ManagerMessages getMessages() {
+ return managerMessages;
+ }
+ };
+ }
+
+ @Override
+ public void setAttributesEditor(AttributesEditor editor) {
+ this.attributesEditor = editor;
+ attributesEditorContainer.clear();
+ }
+
+ /* ############################################################################ */
+
+ @Override
+ public void enableCreate(boolean enable) {
+ createButton.setVisible(enable);
+ headlineLabel.setText(enable ? managerMessages.createAsset() : managerMessages.editAsset());
+ }
+
+ @Override
+ public void enableUpdate(boolean enable) {
+ viewButton.setVisible(enable);
+ updateButton.setVisible(enable);
+ headlineLabel.setText(enable ? managerMessages.editAsset() : managerMessages.createAsset());
+ }
+
+ @Override
+ public void enableDelete(boolean enable) {
+ deleteButton.setVisible(enable);
+ }
+
+ @UiHandler("updateButton")
+ void updateClicked(ClickEvent e) {
+ if (presenter != null)
+ presenter.update();
+ }
+
+ @UiHandler("createButton")
+ void createClicked(ClickEvent e) {
+ if (presenter != null)
+ presenter.create();
+ }
+
+ @UiHandler("deleteButton")
+ void deleteClicked(ClickEvent e) {
+ if (presenter != null)
+ presenter.delete();
+ }
+
+ /* ############################################################################ */
+
+ protected void setOpaque(boolean opaque) {
+ nameGroup.setOpaque(opaque);
+ createdOnGroup.setOpaque(opaque);
+ locationGroup.setOpaque(opaque);
+ mapWidget.setOpaque(opaque);
+ typeGroup.setOpaque(opaque);
+ if (attributesEditor != null)
+ attributesEditor.setOpaque(opaque);
+ submitButtonGroup.setOpaque(opaque);
+ }
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.ui.xml
new file mode 100644
index 000000000..4b8551331
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.ui.xml
@@ -0,0 +1,217 @@
+<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
+ xmlns:g="urn:import:com.google.gwt.user.client.ui"
+ xmlns:w="urn:import:org.openremote.manager.client.widget"
+ xmlns:assetBrowser="urn:import:org.openremote.manager.client.assets.browser">
+
+ <ui:with field="managerMessages" type="org.openremote.manager.client.i18n.ManagerMessages"/>
+ <ui:with field="widgetStyle" type="org.openremote.manager.client.style.WidgetStyle"/>
+
+ <ui:style field="style" type="org.openremote.manager.client.assets.asset.AssetEditImpl.Style">
+ .navItem {
+ margin: 0 1em;
+ }
+
+ .formMessages {
+ max-width: 30em;
+ }
+
+ .mapWidget {
+ margin-left: 2em;
+ width: 44%;
+ height: 12.5em;
+ }
+ </ui:style>
+
+ <ui:style field="attributesEditorStyle"
+ type="org.openremote.manager.client.assets.asset.AssetEditImpl.AttributesEditorStyle">
+ .stringEditor {
+ width: 100%;
+ }
+
+ .integerEditor {
+ width: 5em;
+ }
+
+ .decimalEditor {
+ width: 5em;
+ }
+
+ .booleanEditor {
+ }
+ </ui:style>
+
+ <w:FlexSplitPanel ui:field="splitPanel"
+ handleStyle="{widgetStyle.SplitPanelHandle}"
+ firstPanelWidth="250"
+ firstPanelMinWidth="250"
+ secondPanelMinWidth="1000">
+
+ <w:first>
+ <g:HTMLPanel ui:field="sidebarContainer"
+ styleName="flex layout vertical {widgetStyle.SidebarContent}"/>
+ </w:first>
+
+ <w:second>
+ <g:HTMLPanel styleName="flex layout vertical">
+ <g:HTMLPanel
+ styleName="layout horizontal center end-justified {widgetStyle.SecondaryNavHorizontal}">
+
+ <w:Hyperlink
+ addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
+ icon="dashboard"
+ targetHistoryToken="assets:"
+ text="{managerMessages.showDashboard}"/>
+
+ <w:Hyperlink
+ addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
+ icon="plus-square"
+ targetHistoryToken="assetEdit:"
+ text="{managerMessages.createAsset}"/>
+
+ </g:HTMLPanel>
+
+ <div class="flex layout vertical {widgetStyle.MainContent}">
+
+ <div class="flex-none layout horizontal">
+ <div class="{widgetStyle.Headline1} flex">
+ <g:InlineLabel ui:field="headlineLabel"/>
+ </div>
+ <div>
+ <w:FormButton ui:field="viewButton"
+ text="{managerMessages.viewAsset}"
+ visible="false"
+ icon="eye"/>
+ </div>
+ </div>
+
+ <g:FlowPanel
+ styleName="flex-none layout horizontal {style.formMessages} {widgetStyle.FormMessages} success"
+ visible="false">
+ <w:IconLabel icon="check"
+ addStyleNames="{widgetStyle.MessagesIcon}"/>
+ <g:FlowPanel ui:field="formMessagesSuccess"/>
+ </g:FlowPanel>
+
+ <g:FlowPanel
+ styleName="flex-none layout horizontal {style.formMessages} {widgetStyle.FormMessages} error"
+ visible="false">
+ <w:IconLabel icon="warning"
+ addStyleNames="{widgetStyle.MessagesIcon}"/>
+ <g:FlowPanel ui:field="formMessagesError"/>
+ </g:FlowPanel>
+
+ <g:HTMLPanel styleName="flex-none layout horizontal">
+ <w:Form ui:field="form" addStyleNames="flex">
+ <w:FormGroup ui:field="nameGroup">
+ <w:label>
+ <w:FormLabel text="{managerMessages.assetName}"/>
+ </w:label>
+ <w:field>
+ <w:FormField addStyleNames="larger">
+ <w:FormInputText ui:field="nameInput" addStyleNames="flex"/>
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
+
+ <w:FormGroup ui:field="createdOnGroup">
+ <w:label>
+ <w:FormLabel text="{managerMessages.createdOn}"/>
+ </w:label>
+ <w:field>
+ <w:FormField>
+ <w:FormOutputText ui:field="createdOnOutput"/>
+ </w:FormField>
+ </w:field>
+ <w:actions>
+ <w:FormGroupActions>
+ <w:FormButton ui:field="showHistoryButton"
+ text="{managerMessages.showHistory}"
+ enabled="false"
+ icon="history"/>
+ </w:FormGroupActions>
+ </w:actions>
+ </w:FormGroup>
+
+ <assetBrowser:AssetSelector ui:field="parentAssetSelector"/>
+
+ <w:FormGroup ui:field="locationGroup">
+ <w:label>
+ <w:FormLabel text="{managerMessages.location}"/>
+ </w:label>
+ <w:field>
+ <w:FormField>
+ <w:FormOutputLocation ui:field="locationOutput"/>
+ </w:FormField>
+ </w:field>
+ <w:actions>
+ <w:FormGroupActions>
+ <w:FormButton ui:field="centerMapButton"
+ enabled="false"
+ text="{managerMessages.centerMap}"
+ icon="location-arrow"/>
+ </w:FormGroupActions>
+ </w:actions>
+ </w:FormGroup>
+ </w:Form>
+
+ <w:MapWidget ui:field="mapWidget"
+ addStyleNames="{style.mapWidget} {widgetStyle.ItemWithBorder}"/>
+ </g:HTMLPanel>
+
+ <g:HTMLPanel styleName="flex-none layout horizontal">
+ <w:Form ui:field="attributesForm" addStyleNames="flex">
+
+ <w:FormGroup ui:field="typeGroup">
+ <w:label>
+ <w:FormLabel text="{managerMessages.assetType}"/>
+ </w:label>
+ <w:field>
+ <w:FormField addStyleNames="larger">
+ <g:FlowPanel styleName="flex layout horizontal center">
+ <w:FormValueListBox ui:field="typeListBox"/>
+ <w:FormInputText ui:field="typeInput"
+ addStyleNames="flex"
+ visible="false"/>
+ </g:FlowPanel>
+ </w:FormField>
+ </w:field>
+ <w:info>
+ <g:Label ui:field="customTypeInfoLabel" visible="false"
+ text="{managerMessages.enterCustomAssetType}"/>
+ </w:info>
+
+ </w:FormGroup>
+
+ <g:FlowPanel ui:field="attributesEditorContainer"/>
+
+ </w:Form>
+ </g:HTMLPanel>
+
+ <g:HTMLPanel styleName="flex-none layout horizontal">
+ <w:Form ui:field="submitForm" addStyleNames="flex">
+ <w:FormGroup ui:field="submitButtonGroup">
+ <w:field>
+ <w:FormField>
+ <w:FormButton ui:field="updateButton" primary="true"
+ text="{managerMessages.updateAsset}" visible="false"
+ icon="save"/>
+ <w:FormButton ui:field="createButton" primary="true"
+ text="{managerMessages.createAsset}" visible="false"
+ icon="save"/>
+ <w:FormButton ui:field="deleteButton" danger="true"
+ text="{managerMessages.deleteAsset}" visible="false"
+ icon="trash"/>
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
+ </w:Form>
+ </g:HTMLPanel>
+
+ </div>
+
+ </g:HTMLPanel>
+ </w:second>
+
+ </w:FlexSplitPanel>
+
+</ui:UiBinder>
\ No newline at end of file
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditPlace.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditPlace.java
new file mode 100644
index 000000000..cf52dc66c
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditPlace.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.client.assets.asset;
+
+import com.google.gwt.place.shared.PlaceTokenizer;
+import com.google.gwt.place.shared.Prefix;
+
+public class AssetEditPlace extends AssetPlace {
+
+ public AssetEditPlace(String assetId) {
+ super(assetId);
+ }
+
+ public AssetEditPlace() {
+ }
+
+ @Prefix("assetEdit")
+ public static class Tokenizer implements PlaceTokenizer<AssetEditPlace> {
+
+ @Override
+ public AssetEditPlace getPlace(String token) {
+ return new AssetEditPlace(token != null && token.length() > 0 ? token : null);
+ }
+
+ @Override
+ public String getToken(AssetEditPlace place) {
+ return place.getAssetId() != null ? place.getAssetId() : "";
+ }
+ }
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetPlace.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetPlace.java
index 349a723d8..37a81847c 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetPlace.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetPlace.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016, OpenRemote Inc.
+ * Copyright 2017, OpenRemote Inc.
*
* See the CONTRIBUTORS.txt file in the distribution for a
* full listing of individual contributors.
@@ -19,12 +19,9 @@
*/
package org.openremote.manager.client.assets.asset;
-import com.google.gwt.place.shared.Place;
-import com.google.gwt.place.shared.PlaceTokenizer;
-import com.google.gwt.place.shared.Prefix;
import org.openremote.manager.client.assets.AssetsPlace;
-public class AssetPlace extends Place implements AssetsPlace {
+public abstract class AssetPlace extends AssetsPlace {
final String assetId;
@@ -40,20 +37,6 @@ public class AssetPlace extends Place implements AssetsPlace {
return assetId;
}
- @Prefix("asset")
- public static class Tokenizer implements PlaceTokenizer<AssetPlace> {
-
- @Override
- public AssetPlace getPlace(String token) {
- return new AssetPlace(token != null && token.length() > 0 ? token : null);
- }
-
- @Override
- public String getToken(AssetPlace place) {
- return place.getAssetId() != null ? place.getAssetId() : "";
- }
- }
-
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java
index 12a744437..7f27f14c8 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java
@@ -21,40 +21,26 @@ package org.openremote.manager.client.assets.asset;
import com.google.gwt.user.client.ui.IsWidget;
import elemental.json.JsonObject;
+import org.openremote.manager.client.assets.attributes.AttributesBrowser;
import org.openremote.manager.client.assets.browser.BrowserTreeNode;
-import org.openremote.manager.client.assets.editor.AttributesEditor;
-import org.openremote.manager.client.widget.FormView;
import org.openremote.manager.shared.map.GeoJSON;
-import org.openremote.model.asset.AssetType;
import java.util.Date;
-public interface AssetView extends FormView, IsWidget {
+public interface AssetView extends IsWidget {
interface Presenter {
- void onParentSelection(BrowserTreeNode treeNode);
-
void centerMap();
- void onMapClicked(double lng, double lat);
-
- void onAssetTypeSelected(AssetType value);
-
- void update();
-
- void create();
-
- void delete();
+ void edit();
}
void setPresenter(Presenter presenter);
- void setName(String name);
-
- String getName();
+ void setFormBusy(boolean busy);
- void setNameError(boolean error);
+ void setName(String name);
void setCreatedOn(Date createdOn);
@@ -66,42 +52,13 @@ public interface AssetView extends FormView, IsWidget {
void setLocation(double[] coordinates);
- void refreshMap();
-
- void showMapPopup(double lng, double lat, String text);
-
- void hideMapPopup();
-
void showFeaturesSelection(GeoJSON mapFeatures);
- void hideFeaturesSelection();
-
void flyTo(double[] coordinates);
- void setTypeSelectionEnabled(boolean enabled);
-
- void setEditable(boolean editable);
-
- void setAvailableTypes(AssetType[] assetTypes);
-
- void selectType(AssetType assetType);
-
- void setTypeInputVisible(boolean visible);
-
void setType(String type);
- String getType();
-
- void setTypeError(boolean error);
-
- AttributesEditor.Container<AttributesEditor.Style> getAttributesEditorContainer();
-
- void setAttributesEditor(AttributesEditor attributesEditor);
-
- void enableCreate(boolean enable);
-
- void enableUpdate(boolean enable);
-
- void enableDelete(boolean enable);
+ AttributesBrowser.Container getAttributesBrowserContainer();
+ void setAttributesBrowser(AttributesBrowser attributesBrowser);
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.java
new file mode 100644
index 000000000..8cc95516f
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.client.assets.asset;
+
+import com.google.gwt.user.client.ui.AcceptsOneWidget;
+import elemental.json.Json;
+import elemental.json.JsonValue;
+import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.admin.TenantMapper;
+import org.openremote.manager.client.assets.AssetMapper;
+import org.openremote.manager.client.assets.attributes.AttributesBrowser;
+import org.openremote.manager.client.assets.browser.AssetBrowser;
+import org.openremote.manager.client.assets.browser.AssetBrowserSelection;
+import org.openremote.manager.client.assets.browser.AssetTreeNode;
+import org.openremote.manager.client.assets.browser.TenantTreeNode;
+import org.openremote.manager.client.assets.tenant.AssetsTenantPlace;
+import org.openremote.manager.client.event.bus.EventBus;
+import org.openremote.manager.client.event.bus.EventRegistration;
+import org.openremote.manager.client.interop.elemental.JsonObjectMapper;
+import org.openremote.manager.client.map.MapView;
+import org.openremote.manager.shared.asset.AssetResource;
+import org.openremote.manager.shared.http.EntityWriter;
+import org.openremote.manager.shared.map.MapResource;
+import org.openremote.manager.shared.security.Tenant;
+import org.openremote.manager.shared.security.TenantResource;
+import org.openremote.model.Attribute;
+import org.openremote.model.Attributes;
+import org.openremote.model.Runnable;
+import org.openremote.model.asset.AssetType;
+
+import javax.inject.Inject;
+import java.util.Collection;
+
+import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;
+
+public class AssetViewActivity
+ extends AbstractAssetActivity<AssetViewPlace>
+ implements AssetView.Presenter {
+
+ final AssetView view;
+ final AssetResource assetResource;
+ final AssetMapper assetMapper;
+ final MapResource mapResource;
+ final JsonObjectMapper jsonObjectMapper;
+ final TenantResource tenantResource;
+ final TenantMapper tenantMapper;
+
+ AttributesBrowser attributesBrowser;
+
+ @Inject
+ public AssetViewActivity(Environment environment,
+ AssetBrowser.Presenter assetBrowserPresenter,
+ AssetView view,
+ AssetResource assetResource,
+ AssetMapper assetMapper,
+ MapResource mapResource,
+ JsonObjectMapper jsonObjectMapper,
+ TenantResource tenantResource,
+ TenantMapper tenantMapper) {
+ super(environment, assetBrowserPresenter);
+ this.view = view;
+ this.assetResource = assetResource;
+ this.assetMapper = assetMapper;
+ this.mapResource = mapResource;
+ this.jsonObjectMapper = jsonObjectMapper;
+ this.tenantResource = tenantResource;
+ this.tenantMapper = tenantMapper;
+ }
+
+ @Override
+ public void start(AcceptsOneWidget container, EventBus eventBus, Collection<EventRegistration> registrations) {
+ view.setPresenter(this);
+ container.setWidget(view.asWidget());
+
+ registrations.add(eventBus.register(
+ AssetBrowserSelection.class, event -> {
+ if (event.getSelectedNode() instanceof TenantTreeNode) {
+ environment.getPlaceController().goTo(
+ new AssetsTenantPlace(event.getSelectedNode().getId())
+ );
+ } else if (event.getSelectedNode() instanceof AssetTreeNode) {
+ if (this.assetId == null || !this.assetId.equals(event.getSelectedNode().getId())) {
+ environment.getPlaceController().goTo(
+ new AssetViewPlace(event.getSelectedNode().getId())
+ );
+ }
+ }
+ }
+ ));
+
+ if (!view.isMapInitialised()) {
+ environment.getRequestService().execute(
+ jsonObjectMapper,
+ mapResource::getSettings,
+ 200,
+ view::initialiseMap,
+ ex -> handleRequestException(ex, environment)
+ );
+ }
+
+ asset = null;
+ if (assetId != null) {
+ assetBrowserPresenter.loadAsset(assetId, loadedAsset -> {
+ this.asset = loadedAsset;
+ assetBrowserPresenter.selectAsset(asset);
+ writeAssetToView();
+ writeAttributesBrowserToView();
+ if (asset.getParentId() != null) {
+ assetBrowserPresenter.loadAsset(asset.getParentId(), loadedParentAsset -> {
+ this.parentAsset = loadedParentAsset;
+ writeParentToView();
+ view.setFormBusy(false);
+ });
+ } else {
+ writeParentToView();
+ view.setFormBusy(false);
+ }
+ });
+ }
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ if (attributesBrowser != null) {
+ attributesBrowser.close();
+ }
+ view.setPresenter(null);
+ }
+
+ @Override
+ public void centerMap() {
+ view.flyTo(asset.getCoordinates());
+ }
+
+ @Override
+ public void edit() {
+ environment.getPlaceController().goTo(new AssetEditPlace(assetId));
+ }
+
+ protected void writeAssetToView() {
+ view.setName(asset.getName());
+ view.setCreatedOn(asset.getCreatedOn());
+ view.setLocation(asset.getCoordinates());
+ view.showFeaturesSelection(MapView.getFeature(asset));
+ view.flyTo(asset.getCoordinates());
+ view.setType(asset.getWellKnownType() != AssetType.CUSTOM ? asset.getWellKnownType().name() : asset.getType());
+ }
+
+ protected void writeParentToView() {
+ if (parentAsset != null) {
+ view.setParentNode(
+ new AssetTreeNode(parentAsset, parentAsset.getTenantDisplayName())
+ );
+ } else {
+ view.setParentNode(
+ new TenantTreeNode(
+ new Tenant(asset.getRealmId(), asset.getTenantRealm(), asset.getTenantDisplayName(), true)
+ )
+ );
+ }
+ }
+
+ protected void writeAttributesBrowserToView() {
+ attributesBrowser = new AttributesBrowser(
+ environment,
+ view.getAttributesBrowserContainer(),
+ new Attributes(asset.getAttributes())
+ ) {
+ @Override
+ protected void readAttributeValue(Attribute attribute, Runnable onSuccess) {
+ environment.getRequestService().execute(
+ value -> value,
+ requestParams -> assetResource.readAttributeValue(requestParams, assetId, attribute.getName()),
+ 200,
+ result -> {
+ JsonValue value = Json.instance().parse(result);
+ // TODO Bug in Elemental, can't check this value for null etc.
+ attribute.setValueUnchecked(value);
+ showInfo(container.getMessages().attributeValueRefreshed(attribute.getName()));
+ onSuccess.run();
+ },
+ ex -> handleRequestException(ex, environment)
+ );
+ }
+
+ @Override
+ protected void writeAttributeValue(Attribute attribute) {
+ environment.getRequestService().execute(
+ (EntityWriter<String>) value -> value,
+ requestParams -> assetResource.writeAttributeValue(
+ requestParams, assetId, attribute.getName(), attribute.getValue().toJson()
+ ),
+ 204,
+ () -> showSuccess(container.getMessages().attributeValueStored(attribute.getName())),
+ ex -> handleRequestException(ex, environment)
+ );
+ }
+ };
+ view.setAttributesBrowser(attributesBrowser);
+ attributesBrowser.build();
+ }
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.java
index 9e4a84a30..20b05a9e7 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.java
@@ -23,7 +23,6 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.resources.client.CssResource;
-import com.google.gwt.text.shared.AbstractRenderer;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
@@ -31,26 +30,20 @@ import com.google.gwt.user.client.ui.*;
import com.google.inject.Provider;
import elemental.json.JsonObject;
import org.openremote.manager.client.app.dialog.ConfirmationDialog;
+import org.openremote.manager.client.assets.attributes.AttributesBrowser;
import org.openremote.manager.client.assets.browser.AssetBrowser;
import org.openremote.manager.client.assets.browser.AssetSelector;
import org.openremote.manager.client.assets.browser.BrowserTreeNode;
-import org.openremote.manager.client.assets.editor.AttributesEditor;
import org.openremote.manager.client.i18n.ManagerMessages;
+import org.openremote.manager.client.style.WidgetStyle;
import org.openremote.manager.client.widget.*;
-import org.openremote.manager.client.widget.PushButton;
import org.openremote.manager.shared.map.GeoJSON;
import org.openremote.model.Constants;
-import org.openremote.model.Runnable;
-import org.openremote.model.asset.AssetType;
import javax.inject.Inject;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Date;
-public class AssetViewImpl extends FormViewImpl implements AssetView {
+public class AssetViewImpl extends Composite implements AssetView {
interface UI extends UiBinder<FlexSplitPanel, AssetViewImpl> {
}
@@ -59,14 +52,10 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
String navItem();
- String formMessages();
-
String mapWidget();
-
- String typeInput();
}
- interface AttributesEditorStyle extends CssResource, AttributesEditor.Style {
+ interface AttributesBrowserStyle extends CssResource, AttributesBrowser.Style {
String integerEditor();
@@ -77,11 +66,17 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
String booleanEditor();
}
+ @UiField
+ public WidgetStyle widgetStyle;
+
+ @UiField
+ public ManagerMessages managerMessages;
+
@UiField
Style style;
@UiField
- AttributesEditorStyle attributesEditorStyle;
+ AttributesBrowserStyle attributesBrowserStyle;
@UiField
FlexSplitPanel splitPanel;
@@ -89,12 +84,16 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
@UiField
HTMLPanel sidebarContainer;
- /* ############################################################################ */
+ @UiField
+ InlineLabel headlineLabel;
@UiField
- FormGroup nameGroup;
+ FormButton editButton;
+
+ /* ############################################################################ */
+
@UiField
- TextBox nameInput;
+ public Form form;
@UiField
FormGroup createdOnGroup;
@@ -103,15 +102,20 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
@UiField
FormButton showHistoryButton;
- @UiField(provided = true)
- AssetSelector parentAssetSelector;
+ @UiField
+ FormGroup parentGroup;
+ @UiField
+ FormOutputText tenantDisplayName;
+ @UiField
+ FormInputText parentAssetName;
@UiField
FormGroup locationGroup;
@UiField
- FormOutputText locationOutput;
+ FormOutputLocation locationOutput;
@UiField
FormButton centerMapButton;
+
@UiField
MapWidget mapWidget;
@@ -119,86 +123,35 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
@UiField
Form attributesForm;
+
@UiField
FormGroup typeGroup;
- @UiField(provided = true)
- FormValueListBox<AssetType> typeListBox;
- @UiField
- FormInputText typeInput;
+
@UiField
- Label customTypeInfoLabel;
+ FormInputText typeLabel;
+
@UiField
- FlowPanel attributesEditorContainer;
+ FlowPanel attributesBrowserContainer;
/* ############################################################################ */
- @UiField
- Form submitForm;
- @UiField
- FormGroup submitButtonGroup;
- @UiField
- PushButton createButton;
- @UiField
- PushButton updateButton;
- @UiField
- PushButton deleteButton;
-
final AssetBrowser assetBrowser;
+ final Provider<ConfirmationDialog> confirmationDialogProvider;
Presenter presenter;
- AttributesEditor attributesEditor;
+ AttributesBrowser attributesBrowser;
@Inject
public AssetViewImpl(AssetBrowser assetBrowser,
- Provider<ConfirmationDialog> confirmationDialogProvider,
- ManagerMessages managerMessages) {
- super(confirmationDialogProvider);
+ Provider<ConfirmationDialog> confirmationDialogProvider) {
this.assetBrowser = assetBrowser;
-
- parentAssetSelector = new AssetSelector(
- assetBrowser.getPresenter(),
- managerMessages,
- managerMessages.parentAsset(),
- managerMessages.selectAssetDescription(),
- treeNode -> {
- if (presenter != null) {
- presenter.onParentSelection(treeNode);
- }
- }
- ) {
- @Override
- public void beginSelection() {
- AssetViewImpl.this.setOpaque(true);
- super.beginSelection();
- }
-
- @Override
- public void endSelection() {
- super.endSelection();
- AssetViewImpl.this.setOpaque(false);
- }
- };
-
- typeListBox = new FormValueListBox<>(
- new AbstractRenderer<AssetType>() {
- @Override
- public String render(AssetType assetType) {
- if (assetType == null)
- assetType = AssetType.CUSTOM;
- return managerMessages.assetTypeLabel(assetType.name());
- }
- }
- );
-
- typeListBox.addValueChangeHandler(event -> {
- if (presenter != null) {
- presenter.onAssetTypeSelected(event.getValue());
- }
- });
+ this.confirmationDialogProvider = confirmationDialogProvider;
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
- splitPanel.setOnResize(this::refreshMap);
+ splitPanel.setOnResize(() -> mapWidget.resize());
+
+ setFormBusy(true);
}
@Override
@@ -207,24 +160,18 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
// Restore initial state of view
sidebarContainer.clear();
- nameGroup.setError(false);
- nameInput.setReadOnly(false);
- nameInput.setValue(null);
- createdOnOutput.setText("");
- parentAssetSelector.init();
- locationOutput.setText("");
- centerMapButton.setEnabled(false);
- typeGroup.setError(false);
- typeListBox.setValue(null);
- typeListBox.setAcceptableValues(new ArrayList<>());
- typeListBox.setEnabled(true);
- typeInput.setVisible(false);
- customTypeInfoLabel.setVisible(false);
- hideFeaturesSelection();
- hideMapPopup();
- setOpaque(false);
- attributesEditorContainer.clear();
- attributesEditor = null;
+ setFormBusy(true);
+ headlineLabel.setText(null);
+ createdOnOutput.setText(null);
+ tenantDisplayName.setText(null);
+ parentAssetName.setText(null);
+ locationGroup.setVisible(false);
+ locationOutput.setText(null);
+ mapWidget.setVisible(false);
+ showFeaturesSelection(GeoJSON.EMPTY_FEATURE_COLLECTION);
+ typeLabel.setText(null);
+ attributesBrowserContainer.clear();
+ attributesBrowser = null;
if (presenter != null) {
assetBrowser.asWidget().removeFromParent();
@@ -234,26 +181,21 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
@Override
public void setFormBusy(boolean busy) {
- super.setFormBusy(busy);
+ form.setBusy(busy);
attributesForm.setBusy(busy);
- submitForm.setBusy(busy);
}
/* ############################################################################ */
@Override
public void setName(String name) {
- nameInput.setValue(name);
- }
-
- @Override
- public String getName() {
- return nameInput.getValue().length() > 0 ? nameInput.getValue() : null;
+ headlineLabel.setText(name);
}
- @Override
- public void setNameError(boolean error) {
- nameGroup.setError(error);
+ @UiHandler("editButton")
+ void editClicked(ClickEvent e) {
+ if (presenter != null)
+ presenter.edit();
}
@Override
@@ -265,35 +207,28 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
@Override
public void setParentNode(BrowserTreeNode treeNode) {
- parentAssetSelector.setSelectedNode(treeNode);
+ AssetSelector.renderTreeNode(managerMessages, treeNode, tenantDisplayName, parentAssetName);
}
+ /* ############################################################################ */
+
@Override
public void setLocation(double[] coordinates) {
- if (coordinates != null && coordinates.length == 2) {
- // TODO: This assumes 0 is Lng and 1 is Lat, which is true for PostGIS backend
- // TODO: Because Lat/Lng is the 'right way', we flip it here for display
- // TODO: Rounding to 5 decimals gives us precision of about 1 meter, should be enough
- locationOutput.setText(round(coordinates[1], 5) + " " + round(coordinates[0], 5) + " Lat|Lng");
- centerMapButton.setEnabled(true);
+ if (locationOutput.setCoordinates(managerMessages.selectLocation(), coordinates)) {
+ locationGroup.setVisible(true);
+ mapWidget.setVisible(true);
+ mapWidget.resize();
} else {
- locationOutput.setText(managerMessages.selectLocation());
- centerMapButton.setEnabled(false);
+ locationGroup.setVisible(false);
+ mapWidget.setVisible(false);
}
}
@Override
public void initialiseMap(JsonObject mapOptions) {
- mapWidget.setVisible(false);
mapWidget.initialise(mapOptions, () -> {
- mapWidget.resize();
- mapWidget.setVisible(true);
});
mapWidget.addNavigationControl();
-
- mapWidget.setClickListener((lng, lat) -> {
- presenter.onMapClicked(lng, lat);
- });
}
@Override
@@ -301,31 +236,11 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
return mapWidget.isInitialised();
}
- @Override
- public void refreshMap() {
- mapWidget.resize();
- }
-
- @Override
- public void showMapPopup(double lng, double lat, String text) {
- mapWidget.showPopup(lng, lat, text);
- }
-
- @Override
- public void hideMapPopup() {
- mapWidget.hidePopup();
- }
-
@Override
public void showFeaturesSelection(GeoJSON mapFeatures) {
mapWidget.showFeatures(MapWidget.FEATURES_SOURCE_SELECTION, mapFeatures);
}
- @Override
- public void hideFeaturesSelection() {
- showFeaturesSelection(GeoJSON.EMPTY_FEATURE_COLLECTION);
- }
-
@Override
public void flyTo(double[] coordinates) {
mapWidget.flyTo(coordinates);
@@ -339,74 +254,23 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
/* ############################################################################ */
- @Override
- public void setTypeSelectionEnabled(boolean enabled) {
- typeListBox.setEnabled(enabled);
- }
-
- @Override
- public void setEditable(boolean editable) {
- parentAssetSelector.setEnabled(editable);
- nameInput.setReadOnly(!editable);
- }
-
- @Override
- public void setAvailableTypes(AssetType[] assetTypes) {
- typeListBox.setAcceptableValues(Arrays.asList(assetTypes));
- }
-
- @Override
- public void selectType(AssetType assetType) {
- typeListBox.setValue(assetType);
- }
-
- @Override
- public void setTypeInputVisible(boolean visible) {
- typeInput.setVisible(visible);
- customTypeInfoLabel.setVisible(visible);
- }
-
@Override
public void setType(String type) {
- typeInput.setValue(type);
+ typeLabel.setText(type);
}
@Override
- public String getType() {
- return typeInput.getValue().length() > 0 ? typeInput.getValue() : null;
- }
+ public AttributesBrowser.Container getAttributesBrowserContainer() {
+ return new AttributesBrowser.Container() {
- @Override
- public void setTypeError(boolean error) {
- typeGroup.setError(error);
- }
-
- @Override
- public AttributesEditor.Container<AttributesEditor.Style> getAttributesEditorContainer() {
- return new AttributesEditor.Container<AttributesEditor.Style>() {
@Override
- public FormView getFormView() {
- return AssetViewImpl.this;
- }
-
- @Override
- public AttributesEditor.Style getStyle() {
- return attributesEditorStyle;
+ public AttributesBrowser.Style getStyle() {
+ return attributesBrowserStyle;
}
@Override
public InsertPanel getPanel() {
- return attributesEditorContainer;
- }
-
- @Override
- public void showConfirmation(String title, String text, Runnable onConfirm) {
- AssetViewImpl.this.showConfirmation(title, text, onConfirm);
- }
-
- @Override
- public void showConfirmation(String title, String text, Runnable onConfirm, Runnable onCancel) {
- AssetViewImpl.this.showConfirmation(title, text, onConfirm, onCancel);
+ return attributesBrowserContainer;
}
@Override
@@ -417,60 +281,8 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
}
@Override
- public void setAttributesEditor(AttributesEditor editor) {
- this.attributesEditor = editor;
- attributesEditorContainer.clear();
- }
-
- /* ############################################################################ */
-
- @Override
- public void enableCreate(boolean enable) {
- createButton.setVisible(enable);
- }
-
- @Override
- public void enableUpdate(boolean enable) {
- updateButton.setVisible(enable);
- }
-
- @Override
- public void enableDelete(boolean enable) {
- deleteButton.setVisible(enable);
- }
-
- @UiHandler("updateButton")
- void updateClicked(ClickEvent e) {
- if (presenter != null)
- presenter.update();
- }
-
- @UiHandler("createButton")
- void createClicked(ClickEvent e) {
- if (presenter != null)
- presenter.create();
- }
-
- @UiHandler("deleteButton")
- void deleteClicked(ClickEvent e) {
- if (presenter != null)
- presenter.delete();
- }
-
- /* ############################################################################ */
-
- protected void setOpaque(boolean opaque) {
- nameGroup.setOpaque(opaque);
- createdOnGroup.setOpaque(opaque);
- locationGroup.setOpaque(opaque);
- mapWidget.setOpaque(opaque);
- typeGroup.setOpaque(opaque);
- if (attributesEditor != null)
- attributesEditor.setOpaque(opaque);
- submitButtonGroup.setOpaque(opaque);
- }
-
- protected String round(double d, int places) {
- return new BigDecimal(d).setScale(places, RoundingMode.HALF_UP).toString();
+ public void setAttributesBrowser(AttributesBrowser browser) {
+ this.attributesBrowser = browser;
+ attributesBrowserContainer.clear();
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml
index f1fb61c86..ac80ae7f1 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml
@@ -11,14 +11,6 @@
margin: 0 1em;
}
- .formMessages {
- max-width: 30em;
- }
-
- .typeInput {
- width: 17em;
- }
-
.mapWidget {
margin-left: 2em;
width: 44%;
@@ -26,8 +18,8 @@
}
</ui:style>
- <ui:style field="attributesEditorStyle"
- type="org.openremote.manager.client.assets.asset.AssetViewImpl.AttributesEditorStyle">
+ <ui:style field="attributesBrowserStyle"
+ type="org.openremote.manager.client.assets.asset.AssetViewImpl.AttributesBrowserStyle">
.stringEditor {
width: 100%;
}
@@ -69,41 +61,26 @@
<w:Hyperlink
addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
icon="plus-square"
- targetHistoryToken="asset:"
+ targetHistoryToken="assetEdit:"
text="{managerMessages.createAsset}"/>
</g:HTMLPanel>
<div class="flex layout vertical {widgetStyle.MainContent}">
- <g:FlowPanel
- styleName="flex-none layout horizontal {style.formMessages} {widgetStyle.FormMessages} success"
- visible="false">
- <w:IconLabel icon="check"
- addStyleNames="{widgetStyle.MessagesIcon}"/>
- <g:FlowPanel ui:field="formMessagesSuccess"/>
- </g:FlowPanel>
-
- <g:FlowPanel
- styleName="flex-none layout horizontal {style.formMessages} {widgetStyle.FormMessages} error"
- visible="false">
- <w:IconLabel icon="warning"
- addStyleNames="{widgetStyle.MessagesIcon}"/>
- <g:FlowPanel ui:field="formMessagesError"/>
- </g:FlowPanel>
-
- <g:HTMLPanel styleName="flex-none layout horizontal">
+ <div class="flex-none layout horizontal">
+ <div class="{widgetStyle.Headline1} flex">
+ <g:InlineLabel ui:field="headlineLabel"/>
+ </div>
+ <div>
+ <w:FormButton ui:field="editButton"
+ text="{managerMessages.editAsset}"
+ icon="edit"/>
+ </div>
+ </div>
+
+ <div class="flex-none layout horizontal">
<w:Form ui:field="form" addStyleNames="flex">
- <w:FormGroup ui:field="nameGroup">
- <w:label>
- <w:FormLabel text="{managerMessages.assetName}"/>
- </w:label>
- <w:field>
- <w:FormField addStyleNames="larger">
- <w:FormInputText ui:field="nameInput" addStyleNames="flex"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
<w:FormGroup ui:field="createdOnGroup">
<w:label>
@@ -124,7 +101,19 @@
</w:actions>
</w:FormGroup>
- <assetBrowser:AssetSelector ui:field="parentAssetSelector"/>
+ <w:FormGroup ui:field="parentGroup" alignStart="true">
+ <w:label>
+ <w:FormLabel text="{managerMessages.parentAsset}"/>
+ </w:label>
+ <w:field>
+ <w:FormField>
+ <g:HTMLPanel styleName="layout vertical">
+ <w:FormOutputText ui:field="tenantDisplayName"/>
+ <w:FormInputText ui:field="parentAssetName" readOnly="true"/>
+ </g:HTMLPanel>
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
<w:FormGroup ui:field="locationGroup">
<w:label>
@@ -132,70 +121,39 @@
</w:label>
<w:field>
<w:FormField>
- <w:FormOutputText ui:field="locationOutput"/>
+ <w:FormOutputLocation ui:field="locationOutput"/>
</w:FormField>
</w:field>
<w:actions>
<w:FormGroupActions>
<w:FormButton ui:field="centerMapButton"
- enabled="false"
text="{managerMessages.centerMap}"
icon="location-arrow"/>
</w:FormGroupActions>
</w:actions>
</w:FormGroup>
- </w:Form>
-
- <w:MapWidget ui:field="mapWidget"
- addStyleNames="{style.mapWidget} {widgetStyle.ItemWithBorder}"/>
- </g:HTMLPanel>
-
- <g:HTMLPanel styleName="flex-none layout horizontal">
- <w:Form ui:field="attributesForm" addStyleNames="flex">
<w:FormGroup ui:field="typeGroup">
<w:label>
<w:FormLabel text="{managerMessages.assetType}"/>
</w:label>
<w:field>
- <w:FormField addStyleNames="larger">
- <g:FlowPanel styleName="flex layout horizontal center">
- <w:FormValueListBox ui:field="typeListBox"/>
- <w:FormInputText ui:field="typeInput"
- addStyleNames="flex"
- visible="false"/>
- </g:FlowPanel>
+ <w:FormField>
+ <w:FormInputText ui:field="typeLabel" addStyleNames="flex" readOnly="true"/>
</w:FormField>
</w:field>
- <w:info>
- <g:Label ui:field="customTypeInfoLabel" visible="false"
- text="{managerMessages.enterCustomAssetType}"/>
- </w:info>
-
</w:FormGroup>
- <g:FlowPanel ui:field="attributesEditorContainer"/>
-
</w:Form>
- </g:HTMLPanel>
+
+ <w:MapWidget ui:field="mapWidget"
+ visible="false"
+ addStyleNames="{style.mapWidget} {widgetStyle.ItemWithBorder}"/>
+ </div>
<g:HTMLPanel styleName="flex-none layout horizontal">
- <w:Form ui:field="submitForm" addStyleNames="flex">
- <w:FormGroup ui:field="submitButtonGroup">
- <w:field>
- <w:FormField>
- <w:FormButton ui:field="updateButton" primary="true"
- text="{managerMessages.updateAsset}" visible="false"
- icon="save"/>
- <w:FormButton ui:field="createButton" primary="true"
- text="{managerMessages.createAsset}" visible="false"
- icon="save"/>
- <w:FormButton ui:field="deleteButton" danger="true"
- text="{managerMessages.deleteAsset}" visible="false"
- icon="trash"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
+ <w:Form ui:field="attributesForm" addStyleNames="flex">
+ <g:FlowPanel ui:field="attributesBrowserContainer"/>
</w:Form>
</g:HTMLPanel>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewPlace.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewPlace.java
new file mode 100644
index 000000000..e5c6a584d
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewPlace.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.client.assets.asset;
+
+import com.google.gwt.place.shared.PlaceTokenizer;
+import com.google.gwt.place.shared.Prefix;
+
+public class AssetViewPlace extends AssetPlace {
+
+ public AssetViewPlace(String assetId) {
+ super(assetId);
+ }
+
+ public AssetViewPlace() {
+ }
+
+ @Prefix("asset")
+ public static class Tokenizer implements PlaceTokenizer<AssetViewPlace> {
+
+ @Override
+ public AssetViewPlace getPlace(String token) {
+ return new AssetViewPlace(token != null && token.length() > 0 ? token : null);
+ }
+
+ @Override
+ public String getToken(AssetViewPlace place) {
+ return place.getAssetId() != null ? place.getAssetId() : "";
+ }
+ }
+
+}
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.java
new file mode 100644
index 000000000..0dabf84b9
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.client.assets.attributes;
+
+import com.google.gwt.user.client.ui.Image;
+import com.google.gwt.user.client.ui.IsWidget;
+import com.google.gwt.user.client.ui.Widget;
+import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.widget.*;
+import org.openremote.model.Attribute;
+import org.openremote.model.Attributes;
+import org.openremote.model.Runnable;
+
+public abstract class AttributesBrowser extends AttributesView<AttributesBrowser.Container, AttributesBrowser.Style> {
+
+ public interface Container extends AttributesView.Container<AttributesBrowser.Style> {
+
+ }
+
+ public interface Style extends AttributesView.Style {
+
+ }
+
+ protected FormGroup liveUpdatesGroup;
+
+ public AttributesBrowser(Environment environment, Container container, Attributes attributes) {
+ super(environment, container, attributes);
+ }
+
+ @Override
+ protected void createAttributeGroups() {
+ liveUpdatesGroup = createLiveUpdatesGroup();
+ container.getPanel().add(liveUpdatesGroup);
+ super.createAttributeGroups();
+ }
+
+ @Override
+ protected void addAttributeActions(Attribute attribute,
+ FormGroup formGroup,
+ FormField formField,
+ FormGroupActions formGroupActions,
+ IsWidget editor) {
+
+ // Allow direct read/write of attribute if we understand attribute type (have an editor)
+ if (editor != null) {
+ if (!attribute.isReadOnly()) {
+ FormButton writeValueButton = new FormButton();
+ 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, () -> {
+ if (formField.getWidgetCount() > 0) {
+ formField.getWidget(0).removeFromParent();
+ }
+ IsWidget refreshedEditor = createEditor(attribute, formGroup);
+ if (refreshedEditor == null)
+ refreshedEditor = createUnsupportedEditor(attribute);
+ formField.add(refreshedEditor);
+ }));
+ formGroupActions.add(readValueButton);
+ }
+ }
+
+ @Override
+ protected void addAttributeExtensions(Attribute attribute,
+ FormGroup formGroup) {
+ formGroup.addExtension(createDatapointBrowser(attribute));
+ }
+
+ /* ####################################################################### */
+
+ protected FormGroup createLiveUpdatesGroup() {
+ FormGroup formGroup = new FormGroup();
+
+ FormLabel formLabel = new FormLabel("Show live updates");
+ formGroup.addFormLabel(formLabel);
+
+ FormField formField = new FormField();
+ formGroup.addFormField(formField);
+
+ FormCheckBox liveUpdatesCheckBox = new FormCheckBox();
+ liveUpdatesCheckBox.addValueChangeHandler(event -> showInfo("TODO: Not implemented"));
+ formField.add(liveUpdatesCheckBox);
+
+ if (attributes.get().length > 0) {
+ FormGroupActions formGroupActions = new FormGroupActions();
+
+ FormButton readAllButton = new FormButton();
+ readAllButton.setText("Read and refresh all attributes");
+ readAllButton.addClickHandler(event -> showInfo("TODO: Not implemented"));
+ formGroupActions.add(readAllButton);
+
+ formGroup.addFormGroupActions(formGroupActions);
+ }
+
+ return formGroup;
+ }
+
+ protected Widget createDatapointBrowser(Attribute attribute) {
+ // TODO
+ return new Image("/static/img/Example%20Chart%20Big.png");
+ }
+
+ /* ####################################################################### */
+
+ abstract protected void readAttributeValue(Attribute attribute, Runnable onSuccess);
+
+ abstract protected void writeAttributeValue(Attribute 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.java
new file mode 100644
index 000000000..d6aeaca9f
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java
@@ -0,0 +1,402 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.client.assets.attributes;
+
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.event.dom.client.DomEvent;
+import com.google.gwt.regexp.shared.RegExp;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.IsWidget;
+import elemental.json.Json;
+import elemental.json.JsonType;
+import elemental.json.JsonValue;
+import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.util.JsUtil;
+import org.openremote.manager.client.widget.*;
+import org.openremote.model.*;
+import org.openremote.model.asset.AssetMeta;
+
+public class AttributesEditor
+ extends AttributesView<AttributesEditor.Container, AttributesEditor.Style> {
+
+ protected final RegExp attributeNameRegExp = RegExp.compile(Attribute.ATTRIBUTE_NAME_PATTERN);
+
+ public interface Container extends AttributesView.Container<AttributesEditor.Style> {
+
+ }
+
+ public interface Style extends AttributesView.Style {
+
+ }
+
+ final protected boolean isCreate;
+ protected FormGroup newAttributeGroup;
+
+ public AttributesEditor(Environment environment, Container container, Attributes attributes, boolean isCreate) {
+ super(environment, container, attributes);
+ this.isCreate = isCreate;
+ }
+
+ @Override
+ protected void createAttributeGroups() {
+ newAttributeGroup = createNewAttributeEditor();
+ container.getPanel().add(newAttributeGroup);
+ super.createAttributeGroups();
+ }
+
+ @Override
+ protected void addAttributeActions(Attribute attribute,
+ FormGroup formGroup,
+ FormField formField,
+ FormGroupActions formGroupActions,
+ IsWidget editor) {
+
+ FormButton deleteButton = new FormButton();
+ deleteButton.setText(container.getMessages().deleteAttribute());
+ deleteButton.setIcon("remove");
+ deleteButton.addClickHandler(clickEvent -> {
+ removeAttribute(attribute);
+ showInfo(environment.getMessages().attributeDeleted(attribute.getName()));
+ });
+ formGroupActions.add(deleteButton);
+ }
+
+ @Override
+ protected void addAttributeExtensions(Attribute attribute, FormGroup formGroup) {
+ formGroup.addExtension(new MetaEditor(attribute));
+ }
+
+ /* ####################################################################### */
+
+ protected FormGroup createNewAttributeEditor() {
+ Attribute attribute = new Attribute();
+
+ FormGroup formGroup = createAttributeNameEditor(attribute);
+
+ FormGroupActions formGroupActions = new FormGroupActions();
+ FormButton addButton = new FormButton();
+ addButton.setText(container.getMessages().addAttribute());
+ addButton.setIcon("plus");
+ addButton.addClickHandler(clickEvent -> {
+ if (attribute.isValid()) {
+ formGroup.setError(false);
+ // TODO This is necessary because JSON elemental behavior is weird
+ Attribute storedAttribute = new Attribute(attribute.getName(), Json.parse(attribute.getJsonObject().toJson()));
+ attributes.put(storedAttribute);
+ showInfo(environment.getMessages().attributeAdded(attribute.getName()));
+ build();
+ } else {
+ formGroup.setError(true);
+ showValidationError(environment.getMessages().enterNameAndSelectType());
+ }
+ });
+ formGroupActions.add(addButton);
+ formGroup.addFormGroupActions(formGroupActions);
+
+ return formGroup;
+ }
+
+ protected FormGroup createAttributeNameEditor(Attribute attribute) {
+ FormGroup formGroup = new FormGroup();
+
+ FormLabel label = new FormLabel(environment.getMessages().newAttribute());
+ label.addStyleName("larger");
+ formGroup.addFormLabel(label);
+
+ FormField formField = new FormField();
+ formGroup.addFormField(formField);
+
+ FormInputText nameInput = createFormInputText(container.getStyle().stringEditor());
+ nameInput.setPlaceholder(environment.getMessages().attributeName());
+ nameInput.addValueChangeHandler(event -> {
+ if (!attributeNameRegExp.test(event.getValue())) {
+ formGroup.setError(true);
+ showValidationError(environment.getMessages().invalidAttributeName());
+ } else {
+ formGroup.setError(false);
+ attribute.setName(event.getValue());
+ }
+ });
+ formField.add(nameInput);
+
+ FormListBox typeListBox = new FormListBox();
+ typeListBox.addItem(environment.getMessages().selectType());
+ for (AttributeType attributeType : AttributeType.values()) {
+ typeListBox.addItem(attributeType.getValue());
+ }
+ typeListBox.addChangeHandler(event -> {
+ AttributeType attributeType =
+ typeListBox.getSelectedIndex() > 0
+ ? AttributeType.values()[typeListBox.getSelectedIndex() - 1]
+ : null;
+ attribute.setType(attributeType);
+ });
+ formField.add(typeListBox);
+
+ return formGroup;
+ }
+
+ /* ####################################################################### */
+
+ public class MetaEditor extends FlowPanel {
+
+ final protected Attribute attribute;
+ final protected FormSectionLabel itemListSectionLabel = new FormSectionLabel(environment.getMessages().metaItems());
+ final protected FlowPanel itemListPanel = new FlowPanel();
+ final protected FormSectionLabel itemEditorSectionLabel = new FormSectionLabel(environment.getMessages().newItem());
+ final protected FlowPanel itemEditorPanel = new FlowPanel();
+
+ public MetaEditor(Attribute attribute) {
+ this.attribute = attribute;
+
+ add(itemListSectionLabel);
+ add(itemListPanel);
+ buildItemList();
+
+ add(itemEditorSectionLabel);
+ add(itemEditorPanel);
+ buildItemEditor();
+ }
+
+ protected void buildItemList() {
+ itemListPanel.clear();
+
+ if (!attribute.hasMeta() || attribute.getMeta().all().length == 0) {
+ itemListSectionLabel.setVisible(false);
+ return;
+ }
+ itemListSectionLabel.setVisible(true);
+
+ MetaItem[] items = attribute.getMeta().all();
+ for (int i = 0; i < items.length; i++) {
+ MetaItem item = items[i];
+ FormGroup formGroup = new FormGroup();
+
+ FormLabel label = new FormLabel(item.getName());
+ label.addStyleName("largest");
+ formGroup.addFormLabel(label);
+
+ FormField formField = new FormField();
+
+ // Determine editor based on JSON raw value type
+ JsonValue value = item.getValue();
+ JsonType valueType;
+ // TODO https://github.com/gwtproject/gwt/issues/9484
+ String jsType = JsUtil.typeOf(value);
+ switch (jsType) {
+ case "number":
+ valueType = JsonType.NUMBER;
+ break;
+ case "boolean":
+ valueType = JsonType.BOOLEAN;
+ break;
+ default:
+ valueType = value.getType();
+ break;
+ }
+ formField.add(createEditor(item, valueType, false, formGroup));
+ formGroup.addFormField(formField);
+
+ FormGroupActions formGroupActions = new FormGroupActions();
+
+ FormButton deleteButton = new FormButton();
+ deleteButton.setText(container.getMessages().deleteItem());
+ deleteButton.setIcon("remove");
+ int index = i;
+ deleteButton.addClickHandler(clickEvent -> {
+ attribute.getMeta().remove(index);
+ buildItemList();
+ });
+ formGroupActions.add(deleteButton);
+
+ formGroup.addFormGroupActions(formGroupActions);
+
+ itemListPanel.add(formGroup);
+ }
+ }
+
+ protected void buildItemEditor() {
+ itemEditorPanel.clear();
+
+ MetaItem item = new MetaItem();
+
+ FormListBox valueTypeListBox = new FormListBox();
+ FormGroup itemNameEditorGroup = createItemNameEditor(item, valueTypeListBox);
+ itemEditorPanel.add(itemNameEditorGroup);
+
+ FormGroup itemValueEditorGroup = createItemValueEditor(item, valueTypeListBox);
+ itemEditorPanel.add(itemValueEditorGroup);
+
+ FormGroupActions formGroupActions = new FormGroupActions();
+ FormButton addButton = new FormButton();
+ addButton.setText(container.getMessages().addItem());
+ addButton.setIcon("plus");
+ addButton.addClickHandler(clickEvent -> {
+ if (item.isValid()) {
+ itemNameEditorGroup.setError(false);
+ itemValueEditorGroup.setError(false);
+ // TODO This is necessary because JSON elemental behavior is weird
+ MetaItem storedItem = new MetaItem(Json.parse(item.getJsonObject().toJson()));
+ if (!attribute.hasMeta()) {
+ attribute.setMeta(new Meta());
+ }
+ attribute.getMeta().add(storedItem);
+ buildItemList();
+ buildItemEditor();
+ } else {
+ itemNameEditorGroup.setError(true);
+ itemValueEditorGroup.setError(true);
+ showValidationError(environment.getMessages().enterNameAndValue());
+ }
+ });
+ formGroupActions.add(addButton);
+ itemValueEditorGroup.addFormGroupActions(formGroupActions);
+ }
+
+ protected IsWidget createEditor(MetaItem item, JsonType valueType, boolean forceEditable, FormGroup formGroup) {
+ IsWidget editor;
+
+ AttributesEditor.Style style = container.getStyle();
+ Consumer<String> errorConsumer = msg -> {
+ formGroup.setError(true);
+ showValidationError(msg);
+ };
+ // For some meta items we know if we can edit them or not... custom items are always editable
+ Boolean isEditable = AssetMeta.isEditable(item.getName());
+
+ // TODO: We should support more JSON types, and have special editors for well-known meta items
+ // Default to STRING editor if value is empty/no type available
+ if (valueType == null || valueType.equals(JsonType.STRING)) {
+ String currentValue = item.getValueAsString();
+ Consumer<String> updateConsumer = isEditable == null || isEditable || forceEditable ? value -> {
+ formGroup.setError(false);
+ item.setValueAsString(value);
+ } : null;
+ editor = createStringEditor(style, currentValue, null, updateConsumer);
+ } else if (valueType.equals(JsonType.NUMBER)) {
+ Double currentValue = item.getValueAsDecimal();
+ Consumer<Double> updateConsumer = isEditable == null || isEditable || forceEditable ? value -> {
+ formGroup.setError(false);
+ item.setValueAsDecimal(value);
+ } : null;
+ editor = createDecimalEditor(style, currentValue, null, updateConsumer, errorConsumer);
+ } else if (valueType.equals(JsonType.BOOLEAN)) {
+ Boolean currentValue = item.getValueAsBoolean();
+ Consumer<Boolean> updateConsumer = isEditable == null || isEditable || forceEditable ? value -> {
+ formGroup.setError(false);
+ item.setValueAsBoolean(value);
+ } : null;
+ editor = createBooleanEditor(style, currentValue, null, updateConsumer);
+ } else {
+ FormField unsupportedField = new FormField();
+ unsupportedField.add(new FormOutputText(
+ environment.getMessages().unsupportedMetaItemType(valueType.name())
+ ));
+ editor = unsupportedField;
+ }
+ return editor;
+ }
+
+ protected FormGroup createItemNameEditor(MetaItem item, FormListBox typeListBox) {
+ FormGroup formGroup = new FormGroup();
+
+ FormLabel label = new FormLabel(environment.getMessages().itemName());
+ label.addStyleName("largest");
+ formGroup.addFormLabel(label);
+
+ FormField formField = new FormField();
+ formGroup.addFormField(formField);
+
+ FormListBox wellknownListBox = new FormListBox();
+ wellknownListBox.addItem(environment.getMessages().selectItem());
+ for (AssetMeta wellknown : AssetMeta.editable()) {
+ wellknownListBox.addItem(wellknown.name());
+ }
+ formField.add(wellknownListBox);
+
+ formField.add(new FormOutputText(environment.getMessages().or()));
+
+ FormInputText itemNameInput = createFormInputText(container.getStyle().stringEditor());
+ itemNameInput.setPlaceholder(environment.getMessages().enterCustomAssetAttributeMetaName());
+ itemNameInput.addValueChangeHandler(event -> item.setName(event.getValue()));
+ formField.add(itemNameInput);
+
+ wellknownListBox.addChangeHandler(event -> {
+ if (wellknownListBox.getSelectedIndex() > 0) {
+ AssetMeta assetMeta = AssetMeta.editable()[wellknownListBox.getSelectedIndex() - 1];
+ itemNameInput.setText(assetMeta.getName());
+ item.setName(assetMeta.getName());
+ AssetMeta.ValueType valueType = AssetMeta.ValueType.byValueType(assetMeta.getValueType());
+ typeListBox.setSelectedIndex(
+ valueType != null ? valueType.ordinal() + 1 : 0
+ );
+ } else {
+ itemNameInput.setText(null);
+ item.setName(null);
+ typeListBox.setSelectedIndex(0);
+ }
+ DomEvent.fireNativeEvent(Document.get().createChangeEvent(), typeListBox);
+ });
+
+ return formGroup;
+ }
+
+ protected FormGroup createItemValueEditor(MetaItem item, FormListBox typeListBox) {
+ FormGroup formGroup = new FormGroup();
+
+ FormLabel label = new FormLabel(environment.getMessages().value());
+ label.addStyleName("largest");
+ formGroup.addFormLabel(label);
+
+ FormField formField = new FormField();
+ formGroup.addFormField(formField);
+
+ typeListBox.addItem(environment.getMessages().selectType());
+ for (AssetMeta.ValueType metaValueType : AssetMeta.ValueType.values()) {
+ typeListBox.addItem(metaValueType.name, metaValueType.name());
+ }
+ typeListBox.addChangeHandler(event -> resetItemValueEditor(item, formGroup, formField, typeListBox));
+
+ formField.add(typeListBox);
+
+ // Initial state
+ resetItemValueEditor(item, formGroup, formField, typeListBox);
+
+ return formGroup;
+ }
+
+ protected void resetItemValueEditor(MetaItem item, FormGroup formGroup, FormField formField, FormListBox typeListBox) {
+ // Remove the last used editor (last widget in form field)
+ if (formField.getWidgetCount() > 1)
+ formField.remove(formField.getWidget(formField.getWidgetCount() - 1));
+
+ // Create and add new editor, default to empty STRING
+ item.clearValue();
+ JsonType valueType = typeListBox.getSelectedIndex() > 0
+ ? AssetMeta.ValueType.valueOf(typeListBox.getSelectedValue()).valueType
+ : JsonType.STRING;
+ if (valueType == JsonType.BOOLEAN) {
+ item.setValueAsBoolean(false); // Special case boolean editor, has an "initial" state, there is always a value
+ }
+ IsWidget editor = createEditor(item, valueType, true, formGroup);
+ formField.add(editor);
+ }
+ }
+}
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.java
new file mode 100644
index 000000000..6fafdfc04
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java
@@ -0,0 +1,377 @@
+/*
+ * Copyright 2016, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.client.assets.attributes;
+
+import com.google.gwt.user.client.ui.InsertPanel;
+import com.google.gwt.user.client.ui.IsWidget;
+import com.google.gwt.user.client.ui.Label;
+import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.event.ShowFailureEvent;
+import org.openremote.manager.client.event.ShowInfoEvent;
+import org.openremote.manager.client.event.ShowSuccessEvent;
+import org.openremote.manager.client.i18n.ManagerMessages;
+import org.openremote.manager.client.util.CollectionsUtil;
+import org.openremote.manager.client.util.TextUtil;
+import org.openremote.manager.client.widget.*;
+import org.openremote.model.*;
+import org.openremote.model.asset.AssetMeta;
+
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+
+public abstract class AttributesView<C extends AttributesView.Container<S>, S extends AttributesView.Style> {
+
+ public interface Container<S extends AttributesView.Style> {
+ S getStyle();
+
+ InsertPanel getPanel();
+
+ ManagerMessages getMessages();
+ }
+
+ public interface Style {
+
+ String stringEditor();
+
+ String integerEditor();
+
+ String decimalEditor();
+
+ String booleanEditor();
+ }
+
+ final protected Environment environment;
+ final protected C container;
+ final protected Attributes attributes;
+ final protected LinkedHashMap<Attribute, FormGroup> attributeGroups = new LinkedHashMap<>();
+
+ public AttributesView(Environment environment, C container, Attributes attributes) {
+ this.environment = environment;
+ this.container = container;
+ this.attributes = attributes;
+ }
+
+ public Attributes getAttributes() {
+ return attributes;
+ }
+
+ public void clear() {
+ while (container.getPanel().getWidgetCount() > 0) {
+ container.getPanel().remove(0);
+ }
+ attributeGroups.clear();
+ }
+ public void build() {
+ clear();
+ createAttributeGroups();
+ }
+
+ public void setOpaque(boolean opaque) {
+ for (FormGroup formGroup : attributeGroups.values()) {
+ formGroup.setOpaque(opaque);
+ }
+ }
+
+ public void close() {
+ // Subclasses can manage lifecycle
+ }
+
+ /* ####################################################################### */
+
+ protected void addAttributeActions(Attribute attribute,
+ FormGroup formGroup,
+ FormField formField,
+ FormGroupActions formGroupActions,
+ IsWidget editor) {}
+
+ protected void addAttributeExtensions(Attribute attribute,
+ FormGroup formGroup) {}
+
+ /* ####################################################################### */
+
+ protected void createAttributeGroups() {
+ for (Attribute attribute : attributes.get()) {
+ FormGroup formGroup = createAttributeGroup(attribute);
+ if (formGroup != null) {
+ attributeGroups.put(attribute, formGroup);
+ }
+ }
+ // Sort form groups by label text ascending
+ CollectionsUtil.sortMap(attributeGroups, Comparator.comparing(a -> a.getFormLabel().getText()));
+
+ for (FormGroup attributeGroup : attributeGroups.values()) {
+ container.getPanel().add(attributeGroup);
+ }
+ }
+
+ protected FormGroup createAttributeGroup(Attribute attribute) {
+
+ FormGroup formGroup = new FormGroup();
+
+ FormLabel formLabel = createAttributeLabel(attribute);
+ formGroup.addFormLabel(formLabel);
+
+ MetaItem description = AssetMeta.getFirst(attribute, AssetMeta.DESCRIPTION);
+ if (description != null) {
+ formGroup.addInfolabel(new Label(description.getValueAsString()));
+ }
+
+ FormGroupActions formGroupActions = new FormGroupActions();
+
+ FormField formField = new FormField();
+
+ IsWidget editor = createEditor(attribute, formGroup);
+
+ addAttributeActions(attribute, formGroup, formField, formGroupActions, editor);
+
+ if (editor == null)
+ editor = createUnsupportedEditor(attribute);
+ formField.add(editor);
+
+ formGroup.addFormField(formField);
+ formGroup.addFormGroupActions(formGroupActions);
+
+ addAttributeExtensions(attribute, formGroup);
+
+ return formGroup;
+ }
+
+ protected FormLabel createAttributeLabel(Attribute attribute) {
+ String label = attribute.getName();
+ MetaItem labelItem = AssetMeta.getFirst(attribute, AssetMeta.LABEL);
+ if (labelItem != null) {
+ label = labelItem.getValueAsString();
+ }
+ FormLabel formLabel = new FormLabel(TextUtil.ellipsize(label, 30));
+ formLabel.addStyleName("larger");
+
+ return formLabel;
+ }
+
+ protected IsWidget createEditor(Attribute attribute, FormGroup formGroup) {
+ IsWidget editor;
+ S style = container.getStyle();
+ MetaItem defaultValueItem = AssetMeta.getFirst(attribute, AssetMeta.DEFAULT);
+ Consumer<String> errorConsumer = msg -> {
+ formGroup.setError(true);
+ showValidationError(msg);
+ };
+
+ if (attribute.getType().equals(AttributeType.STRING)) {
+ String currentValue = attribute.getValueAsString();
+ String defaultValue = defaultValueItem != null ? defaultValueItem.getValueAsString() : null;
+ Consumer<String> updateConsumer = isDefaultReadOnly(attribute) ? null : value -> {
+ formGroup.setError(false);
+ attribute.setValueAsString(value);
+ };
+ editor = createStringEditor(style, currentValue, defaultValue, updateConsumer);
+ } else if (attribute.getType().equals(AttributeType.INTEGER)) {
+ Integer currentValue = attribute.getValueAsInteger();
+ Integer defaultValue = defaultValueItem != null ? defaultValueItem.getValueAsInteger() : null;
+ Consumer<Integer> updateConsumer = isDefaultReadOnly(attribute) ? null : value -> {
+ formGroup.setError(false);
+ attribute.setValueAsInteger(value);
+ };
+ editor = createIntegerEditor(style, currentValue, defaultValue, updateConsumer, errorConsumer);
+ } else if (attribute.getType().equals(AttributeType.DECIMAL)) {
+ Double currentValue = attribute.getValueAsDecimal();
+ Double defaultValue = defaultValueItem != null ? defaultValueItem.getValueAsDecimal() : null;
+ Consumer<Double> updateConsumer = isDefaultReadOnly(attribute) ? null : value -> {
+ formGroup.setError(false);
+ attribute.setValueAsDecimal(value);
+ };
+ editor = createDecimalEditor(style, currentValue, defaultValue, updateConsumer, errorConsumer);
+ } else if (attribute.getType().equals(AttributeType.BOOLEAN)) {
+ Boolean currentValue = attribute.getValueAsBoolean();
+ Boolean defaultValue = defaultValueItem != null ? defaultValueItem.getValueAsBoolean() : null;
+ Consumer<Boolean> updateConsumer = isDefaultReadOnly(attribute) ? null : value -> {
+ formGroup.setError(false);
+ attribute.setValueAsBoolean(value);
+ };
+ editor = createBooleanEditor(style, currentValue, defaultValue, updateConsumer);
+ } else {
+ return null;
+ }
+ return editor;
+ }
+
+ protected IsWidget createUnsupportedEditor(Attribute attribute) {
+ FormField unsupportedField = new FormField();
+ unsupportedField.add(new FormOutputText(
+ environment.getMessages().unsupportedAttributeType(attribute.getType().getValue())
+ ));
+ return unsupportedField;
+ }
+
+ protected FormInputText createStringEditor(S style,
+ String currentValue,
+ String defaultValue,
+ Consumer<String> updateConsumer) {
+ FormInputText input = createFormInputText(style.stringEditor());
+
+ if (currentValue != null) {
+ input.setValue(currentValue);
+ } else if ((defaultValue) != null) {
+ input.setValue(defaultValue);
+ }
+
+ if (updateConsumer != null) {
+ input.addValueChangeHandler(
+ event -> {
+ updateConsumer.accept(
+ event.getValue() != null && event.getValue().length() > 0
+ ? event.getValue()
+ : null
+ );
+ }
+ );
+ } else {
+ input.setReadOnly(true);
+ }
+ return input;
+ }
+
+ protected FormInputNumber createIntegerEditor(S style,
+ Integer currentValue,
+ Integer defaultValue,
+ Consumer<Integer> updateConsumer,
+ Consumer<String> errorConsumer) {
+ FormInputNumber input = createFormInputNumber(style.integerEditor());
+
+ if (currentValue != null) {
+ input.setValue(currentValue.toString());
+ } else if (defaultValue != null) {
+ input.setValue(defaultValue.toString());
+ }
+
+ if (updateConsumer != null) {
+ input.addValueChangeHandler(event -> {
+ try {
+ updateConsumer.accept(
+ event.getValue() != null && event.getValue().length() > 0
+ ? Integer.valueOf(event.getValue())
+ : null
+ );
+ } catch (NumberFormatException ex) {
+ errorConsumer.accept(environment.getMessages().enterOnlyNumbers());
+ }
+ });
+ } else {
+ input.setReadOnly(true);
+ }
+ return input;
+ }
+
+ protected FormInputText createDecimalEditor(S style,
+ Double currentValue,
+ Double defaultValue,
+ Consumer<Double> updateConsumer,
+ Consumer<String> errorConsumer) {
+ FormInputText input = createFormInputText(style.decimalEditor());
+
+ if (currentValue != null) {
+ input.setValue(currentValue.toString());
+ } else if (defaultValue != null) {
+ input.setValue(defaultValue.toString());
+ }
+
+ if (updateConsumer != null) {
+ input.addValueChangeHandler(event -> {
+ try {
+ updateConsumer.accept(
+ event.getValue() != null && event.getValue().length() > 0
+ ? Double.valueOf(event.getValue())
+ : null
+ );
+ } catch (NumberFormatException ex) {
+ errorConsumer.accept(environment.getMessages().enterOnlyDecimals());
+ }
+ });
+ } else {
+ input.setReadOnly(true);
+ }
+ return input;
+ }
+
+ protected FormCheckBox createBooleanEditor(S style,
+ Boolean currentValue,
+ Boolean defaultValue,
+ Consumer<Boolean> updateConsumer) {
+ FormCheckBox input = createFormInputCheckBox(style.booleanEditor());
+
+ Boolean value = null;
+ if (currentValue != null) {
+ value = currentValue;
+ } else if (defaultValue != null) {
+ value = defaultValue;
+ }
+
+ input.setValue(value);
+
+ if (updateConsumer != null) {
+ input.addValueChangeHandler(event -> updateConsumer.accept(input.getValue()));
+ } else {
+ input.setEnabled(false);
+ }
+ return input;
+ }
+
+ protected FormInputText createFormInputText(String formFieldStyleName) {
+ FormInputText input = new FormInputText();
+ input.addStyleName(formFieldStyleName);
+ return input;
+ }
+
+ protected FormInputNumber createFormInputNumber(String formFieldStyleName) {
+ FormInputNumber input = new FormInputNumber();
+ input.addStyleName(formFieldStyleName);
+ return input;
+ }
+
+ protected FormCheckBox createFormInputCheckBox(String formFieldStyleName) {
+ FormCheckBox input = new FormCheckBox();
+ input.addStyleName(formFieldStyleName);
+ return input;
+ }
+
+ protected boolean isDefaultReadOnly(Attribute attribute) {
+ return false;
+ }
+
+ protected void removeAttribute(Attribute attribute) {
+ attributes.remove(attribute.getName());
+ int attributeGroupIndex = container.getPanel().getWidgetIndex(attributeGroups.get(attribute));
+ container.getPanel().remove(attributeGroupIndex);
+ attributeGroups.remove(attribute);
+ }
+
+ protected void showInfo(String text) {
+ environment.getEventBus().dispatch(new ShowInfoEvent(text));
+ }
+
+ protected void showSuccess(String text) {
+ environment.getEventBus().dispatch(new ShowSuccessEvent(text));
+ }
+
+ protected void showValidationError(String error) {
+ environment.getEventBus().dispatch(new ShowFailureEvent(error, 3000));
+ }
+
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelector.java b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelector.java
index 1659d3c19..8bd50034d 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelector.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelector.java
@@ -93,14 +93,7 @@ public abstract class AssetSelector extends FormGroup {
public void setSelectedNode(BrowserTreeNode selectedNode) {
this.selectedNode = selectedNode;
- if (selectedNode instanceof TenantTreeNode) {
- outputTenantDisplayName.setText(selectedNode.getLabel());
- outputAssetName.setText(managerMessages.assetHasNoParent());
- } else if (selectedNode instanceof AssetTreeNode) {
- AssetTreeNode assetTreeNode = (AssetTreeNode) selectedNode;
- outputTenantDisplayName.setText(assetTreeNode.getTenantDisplayName());
- outputAssetName.setText(selectedNode.getLabel());
- }
+ renderTreeNode(managerMessages, selectedNode, outputTenantDisplayName, outputAssetName);
}
public void endSelection() {
@@ -126,4 +119,19 @@ public abstract class AssetSelector extends FormGroup {
public void setEnabled(boolean enabled) {
selectAssetButton.setEnabled(enabled);
}
+
+ public static void renderTreeNode(ManagerMessages managerMessages,
+ BrowserTreeNode treeNode,
+ FormOutputText outputTenantDisplayName,
+ FormInputText outputAssetName) {
+
+ if (treeNode instanceof TenantTreeNode) {
+ outputTenantDisplayName.setText(treeNode.getLabel());
+ outputAssetName.setText(managerMessages.assetHasNoParent());
+ } else if (treeNode instanceof AssetTreeNode) {
+ AssetTreeNode assetTreeNode = (AssetTreeNode) treeNode;
+ outputTenantDisplayName.setText(assetTreeNode.getTenantDisplayName());
+ outputAssetName.setText(treeNode.getLabel());
+ }
+ }
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/editor/AttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/editor/AttributesEditor.java
deleted file mode 100644
index 6cbed7a85..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/editor/AttributesEditor.java
+++ /dev/null
@@ -1,746 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.client.assets.editor;
-
-import com.google.gwt.dom.client.Document;
-import com.google.gwt.event.dom.client.DomEvent;
-import com.google.gwt.regexp.shared.RegExp;
-import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.InsertPanel;
-import com.google.gwt.user.client.ui.IsWidget;
-import com.google.gwt.user.client.ui.Label;
-import elemental.json.Json;
-import elemental.json.JsonType;
-import elemental.json.JsonValue;
-import org.openremote.manager.client.Environment;
-import org.openremote.manager.client.event.ShowFailureEvent;
-import org.openremote.manager.client.event.ShowInfoEvent;
-import org.openremote.manager.client.event.ShowSuccessEvent;
-import org.openremote.manager.client.i18n.ManagerMessages;
-import org.openremote.manager.client.util.CollectionsUtil;
-import org.openremote.manager.client.util.JsUtil;
-import org.openremote.manager.client.util.TextUtil;
-import org.openremote.manager.client.widget.*;
-import org.openremote.model.*;
-import org.openremote.model.Runnable;
-import org.openremote.model.asset.AssetMeta;
-
-import java.util.Comparator;
-import java.util.LinkedHashMap;
-import java.util.logging.Logger;
-
-public abstract class AttributesEditor<S extends AttributesEditor.Style> {
-
- private static final Logger LOG = Logger.getLogger(AttributesEditor.class.getName());
-
- protected final RegExp attributeNameRegExp = RegExp.compile(Attribute.ATTRIBUTE_NAME_PATTERN);
-
- public interface Container<S extends AttributesEditor.Style> {
- FormView getFormView();
-
- S getStyle();
-
- InsertPanel getPanel();
-
- void showConfirmation(String title, String text, Runnable onConfirm);
-
- void showConfirmation(String title, String text, Runnable onConfirm, Runnable onCancel);
-
- ManagerMessages getMessages();
- }
-
- public interface Style {
-
- String stringEditor();
-
- String integerEditor();
-
- String decimalEditor();
-
- String booleanEditor();
- }
-
- final protected Environment environment;
- final protected Container<S> container;
- final protected Attributes attributes;
- final protected boolean isCreate;
- protected FormGroup attributeEditorGroup;
- final protected LinkedHashMap<Attribute, FormGroup> attributeGroups = new LinkedHashMap<>();
-
- public AttributesEditor(Environment environment, Container<S> container, Attributes attributes, boolean isCreate) {
- this.environment = environment;
- this.container = container;
- this.attributes = attributes;
- this.isCreate = isCreate;
- }
-
- public Attributes getAttributes() {
- return attributes;
- }
-
- public void build() {
- while (container.getPanel().getWidgetCount() > 0) {
- container.getPanel().remove(0);
- }
-
- attributeEditorGroup = createAttributeEditor();
- container.getPanel().add(attributeEditorGroup);
-
- attributeGroups.clear();
- for (Attribute attribute : attributes.get()) {
- FormGroup formGroup = createAttributeGroup(attribute);
- if (formGroup != null) {
- attributeGroups.put(attribute, formGroup);
- }
- }
-
- // Sort form groups by label text ascending
- CollectionsUtil.sortMap(attributeGroups, Comparator.comparing(a -> a.getFormLabel().getText()));
-
- for (FormGroup attributeGroup : attributeGroups.values()) {
- container.getPanel().add(attributeGroup);
- }
- }
-
- public void setOpaque(boolean opaque) {
- for (FormGroup formGroup : attributeGroups.values()) {
- formGroup.setOpaque(opaque);
- }
- attributeEditorGroup.setOpaque(opaque);
- }
-
- public void close() {
- // Subclasses can manage lifecycle
- }
-
- /* ####################################################################### */
-
- abstract protected void readAttributeValue(Attribute attribute, Runnable onSuccess);
-
- abstract protected void writeAttributeValue(Attribute attribute);
-
- /* ####################################################################### */
-
- protected FormGroup createAttributeEditor() {
- Attribute attribute = new Attribute();
-
- FormGroup formGroup = createAttributeNameEditor(attribute);
-
- FormGroupActions formGroupActions = new FormGroupActions();
- FormButton addButton = new FormButton();
- addButton.setText(container.getMessages().addAttribute());
- addButton.setIcon("plus");
- addButton.addClickHandler(clickEvent -> {
- if (attribute.isValid()) {
- formGroup.setError(false);
- // TODO This is necessary because JSON elemental behavior is weird
- Attribute storedAttribute = new Attribute(attribute.getName(), Json.parse(attribute.getJsonObject().toJson()));
- attributes.put(storedAttribute);
- showInfo(environment.getMessages().attributeAdded(attribute.getName()));
- build();
- } else {
- formGroup.setError(true);
- showValidationError(environment.getMessages().enterNameAndSelectType());
- }
- });
- formGroupActions.add(addButton);
- formGroup.addFormGroupActions(formGroupActions);
-
- return formGroup;
- }
-
- protected FormGroup createAttributeNameEditor(Attribute attribute) {
- FormGroup formGroup = new FormGroup();
-
- FormLabel label = new FormLabel(environment.getMessages().newAttribute());
- formGroup.addFormLabel(label);
-
- FormField formField = new FormField();
- formGroup.addFormField(formField);
-
- FormInputText nameInput = createFormInputText(container.getStyle().stringEditor());
- nameInput.setPlaceholder(environment.getMessages().attributeName());
- nameInput.addValueChangeHandler(event -> {
- if (!attributeNameRegExp.test(event.getValue())) {
- formGroup.setError(true);
- showValidationError(environment.getMessages().invalidAttributeName());
- } else {
- formGroup.setError(false);
- attribute.setName(event.getValue());
- }
- });
- formField.add(nameInput);
-
- FormListBox typeListBox = new FormListBox();
- typeListBox.addItem(environment.getMessages().selectType());
- for (AttributeType attributeType : AttributeType.values()) {
- typeListBox.addItem(attributeType.getValue());
- }
- typeListBox.addChangeHandler(event -> {
- AttributeType attributeType =
- typeListBox.getSelectedIndex() > 0
- ? AttributeType.values()[typeListBox.getSelectedIndex() - 1]
- : null;
- attribute.setType(attributeType);
- });
- formField.add(typeListBox);
-
- return formGroup;
- }
-
- protected FormGroup createAttributeGroup(Attribute attribute) {
-
- FormGroup formGroup = new FormGroup();
-
- FormLabel formLabel = createAttributeLabel(attribute);
- formGroup.addFormLabel(formLabel);
-
- MetaItem description = AssetMeta.getFirst(attribute, AssetMeta.DESCRIPTION);
- if (description != null) {
- formGroup.addInfolabel(new Label(description.getValueAsString()));
- }
-
- FormGroupActions formGroupActions = new FormGroupActions();
-
- FormField formField = new FormField();
-
- IsWidget editor = createEditor(attribute, formGroup);
-
- // Allow direct read/write of attribute value if asset exists in database and we understand attribute type
- if (!isCreate && editor != null) {
- FormButton writeValueButton = new FormButton();
- 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, () -> {
- if (formField.getWidgetCount() > 0) {
- formField.getWidget(0).removeFromParent();
- }
- IsWidget refreshedEditor = createEditor(attribute, formGroup);
- if (refreshedEditor == null)
- refreshedEditor = createUnsupportedEditor(attribute);
- formField.add(refreshedEditor);
- });
- });
- formGroupActions.add(readValueButton);
- }
-
- FormButton deleteButton = new FormButton();
- deleteButton.setText(container.getMessages().deleteAttribute());
- deleteButton.setIcon("remove");
- deleteButton.addClickHandler(clickEvent -> {
- removeAttribute(attribute);
- showInfo(environment.getMessages().attributeDeleted(attribute.getName()));
- });
- formGroupActions.add(deleteButton);
-
- if (editor == null)
- editor = createUnsupportedEditor(attribute);
- formField.add(editor);
-
- formGroup.addFormField(formField);
- formGroup.addFormGroupActions(formGroupActions);
- formGroup.addExtension(createMetaEditor(attribute));
-
- return formGroup;
- }
-
- protected FormLabel createAttributeLabel(Attribute attribute) {
- String label = attribute.getName();
- MetaItem labelItem = AssetMeta.getFirst(attribute, AssetMeta.LABEL);
- if (labelItem != null) {
- label = labelItem.getValueAsString();
- }
- FormLabel formLabel = new FormLabel(TextUtil.ellipsize(label, 30));
- formLabel.addStyleName("larger");
-
- return formLabel;
- }
-
- protected FlowPanel createMetaEditor(Attribute attribute) {
- return new MetaEditor(attribute);
- }
-
- protected IsWidget createEditor(Attribute attribute, FormGroup formGroup) {
- IsWidget editor;
- S style = container.getStyle();
- MetaItem defaultValueItem = AssetMeta.getFirst(attribute, AssetMeta.DEFAULT);
- Consumer<String> errorConsumer = msg -> {
- formGroup.setError(true);
- showValidationError(msg);
- };
-
- if (attribute.getType().equals(AttributeType.STRING)) {
- String currentValue = attribute.getValueAsString();
- String defaultValue = defaultValueItem != null ? defaultValueItem.getValueAsString() : null;
- Consumer<String> updateConsumer = isDefaultReadOnly(attribute) ? null : value -> {
- formGroup.setError(false);
- attribute.setValueAsString(value);
- };
- editor = createStringEditor(style, currentValue, defaultValue, updateConsumer);
- } else if (attribute.getType().equals(AttributeType.INTEGER)) {
- Integer currentValue = attribute.getValueAsInteger();
- Integer defaultValue = defaultValueItem != null ? defaultValueItem.getValueAsInteger() : null;
- Consumer<Integer> updateConsumer = isDefaultReadOnly(attribute) ? null : value -> {
- formGroup.setError(false);
- attribute.setValueAsInteger(value);
- };
- editor = createIntegerEditor(style, currentValue, defaultValue, updateConsumer, errorConsumer);
- } else if (attribute.getType().equals(AttributeType.DECIMAL)) {
- Double currentValue = attribute.getValueAsDecimal();
- Double defaultValue = defaultValueItem != null ? defaultValueItem.getValueAsDecimal() : null;
- Consumer<Double> updateConsumer = isDefaultReadOnly(attribute) ? null : value -> {
- formGroup.setError(false);
- attribute.setValueAsDecimal(value);
- };
- editor = createDecimalEditor(style, currentValue, defaultValue, updateConsumer, errorConsumer);
- } else if (attribute.getType().equals(AttributeType.BOOLEAN)) {
- Boolean currentValue = attribute.getValueAsBoolean();
- Boolean defaultValue = defaultValueItem != null ? defaultValueItem.getValueAsBoolean() : null;
- Consumer<Boolean> updateConsumer = isDefaultReadOnly(attribute) ? null : value -> {
- formGroup.setError(false);
- attribute.setValueAsBoolean(value);
- };
- editor = createBooleanEditor(style, currentValue, defaultValue, updateConsumer);
- } else {
- return null;
- }
- return editor;
- }
-
- protected IsWidget createUnsupportedEditor(Attribute attribute) {
- FormField unsupportedField = new FormField();
- unsupportedField.add(new FormOutputText(
- environment.getMessages().unsupportedAttributeType(attribute.getType().getValue())
- ));
- return unsupportedField;
- }
-
- protected IsWidget createEditor(MetaItem item, JsonType valueType, boolean forceEditable, FormGroup formGroup) {
- IsWidget editor;
-
- S style = container.getStyle();
- Consumer<String> errorConsumer = msg -> {
- formGroup.setError(true);
- showValidationError(msg);
- };
- // For some meta items we know if we can edit them or not... custom items are always editable
- Boolean isEditable = AssetMeta.isEditable(item.getName());
-
- // TODO: We should support more JSON types, and have special editors for well-known meta items
- // Default to STRING editor if value is empty/no type available
- if (valueType == null || valueType.equals(JsonType.STRING)) {
- String currentValue = item.getValueAsString();
- Consumer<String> updateConsumer = isEditable == null || isEditable || forceEditable ? value -> {
- formGroup.setError(false);
- item.setValueAsString(value);
- } : null;
- editor = createStringEditor(style, currentValue, null, updateConsumer);
- } else if (valueType.equals(JsonType.NUMBER)) {
- Double currentValue = item.getValueAsDecimal();
- Consumer<Double> updateConsumer = isEditable == null || isEditable || forceEditable ? value -> {
- formGroup.setError(false);
- item.setValueAsDecimal(value);
- } : null;
- editor = createDecimalEditor(style, currentValue, null, updateConsumer, errorConsumer);
- } else if (valueType.equals(JsonType.BOOLEAN)) {
- Boolean currentValue = item.getValueAsBoolean();
- Consumer<Boolean> updateConsumer = isEditable == null || isEditable || forceEditable ? value -> {
- formGroup.setError(false);
- item.setValueAsBoolean(value);
- } : null;
- editor = createBooleanEditor(style, currentValue, null, updateConsumer);
- } else {
- FormField unsupportedField = new FormField();
- unsupportedField.add(new FormOutputText(
- environment.getMessages().unsupportedMetaItemType(valueType.name())
- ));
- editor = unsupportedField;
- }
- return editor;
- }
-
- protected FormInputText createStringEditor(S style,
- String currentValue,
- String defaultValue,
- Consumer<String> updateConsumer) {
- FormInputText input = createFormInputText(style.stringEditor());
-
- if (currentValue != null) {
- input.setValue(currentValue);
- } else if ((defaultValue) != null) {
- input.setValue(defaultValue);
- }
-
- if (updateConsumer != null) {
- input.addValueChangeHandler(
- event -> {
- updateConsumer.accept(
- event.getValue() != null && event.getValue().length() > 0
- ? event.getValue()
- : null
- );
- }
- );
- } else {
- input.setReadOnly(true);
- }
- return input;
- }
-
- protected FormInputNumber createIntegerEditor(S style,
- Integer currentValue,
- Integer defaultValue,
- Consumer<Integer> updateConsumer,
- Consumer<String> errorConsumer) {
- FormInputNumber input = createFormInputNumber(style.integerEditor());
-
- if (currentValue != null) {
- input.setValue(currentValue.toString());
- } else if (defaultValue != null) {
- input.setValue(defaultValue.toString());
- }
-
- if (updateConsumer != null) {
- input.addValueChangeHandler(event -> {
- try {
- updateConsumer.accept(
- event.getValue() != null && event.getValue().length() > 0
- ? Integer.valueOf(event.getValue())
- : null
- );
- } catch (NumberFormatException ex) {
- errorConsumer.accept(environment.getMessages().enterOnlyNumbers());
- }
- });
- } else {
- input.setReadOnly(true);
- }
- return input;
- }
-
- protected FormInputText createDecimalEditor(S style,
- Double currentValue,
- Double defaultValue,
- Consumer<Double> updateConsumer,
- Consumer<String> errorConsumer) {
- FormInputText input = createFormInputText(style.decimalEditor());
-
- if (currentValue != null) {
- input.setValue(currentValue.toString());
- } else if (defaultValue != null) {
- input.setValue(defaultValue.toString());
- }
-
- if (updateConsumer != null) {
- input.addValueChangeHandler(event -> {
- try {
- updateConsumer.accept(
- event.getValue() != null && event.getValue().length() > 0
- ? Double.valueOf(event.getValue())
- : null
- );
- } catch (NumberFormatException ex) {
- errorConsumer.accept(environment.getMessages().enterOnlyDecimals());
- }
- });
- } else {
- input.setReadOnly(true);
- }
- return input;
- }
-
- protected FormCheckBox createBooleanEditor(S style,
- Boolean currentValue,
- Boolean defaultValue,
- Consumer<Boolean> updateConsumer) {
- FormCheckBox input = createFormInputCheckBox(style.booleanEditor());
-
- Boolean value = null;
- if (currentValue != null) {
- value = currentValue;
- } else if (defaultValue != null) {
- value = defaultValue;
- }
-
- input.setValue(value);
-
- if (updateConsumer != null) {
- input.addValueChangeHandler(event -> updateConsumer.accept(input.getValue()));
- } else {
- input.setEnabled(false);
- }
- return input;
- }
-
- protected FormInputText createFormInputText(String formFieldStyleName) {
- FormInputText input = new FormInputText();
- input.addStyleName(formFieldStyleName);
- return input;
- }
-
- protected FormInputNumber createFormInputNumber(String formFieldStyleName) {
- FormInputNumber input = new FormInputNumber();
- input.addStyleName(formFieldStyleName);
- return input;
- }
-
- protected FormCheckBox createFormInputCheckBox(String formFieldStyleName) {
- FormCheckBox input = new FormCheckBox();
- input.addStyleName(formFieldStyleName);
- return input;
- }
-
- protected boolean isDefaultReadOnly(Attribute attribute) {
- return false;
- }
-
- protected void removeAttribute(Attribute attribute) {
- attributes.remove(attribute.getName());
- int attributeGroupIndex = container.getPanel().getWidgetIndex(attributeGroups.get(attribute));
- container.getPanel().remove(attributeGroupIndex);
- attributeGroups.remove(attribute);
- }
-
- protected void showInfo(String text) {
- environment.getEventBus().dispatch(new ShowInfoEvent(text));
- }
-
- protected void showSuccess(String text) {
- environment.getEventBus().dispatch(new ShowSuccessEvent(text));
- }
-
- protected void showValidationError(String error) {
- environment.getEventBus().dispatch(new ShowFailureEvent(error, 3000));
- }
-
- /* ####################################################################### */
-
- public class MetaEditor extends FlowPanel {
-
- final protected Attribute attribute;
- final protected FormSectionLabel itemListSectionLabel = new FormSectionLabel(environment.getMessages().metaItems());
- final protected FlowPanel itemListPanel = new FlowPanel();
- final protected FormSectionLabel itemEditorSectionLabel = new FormSectionLabel(environment.getMessages().newItem());
- final protected FlowPanel itemEditorPanel = new FlowPanel();
-
- public MetaEditor(Attribute attribute) {
- this.attribute = attribute;
-
- add(itemListSectionLabel);
- add(itemListPanel);
- buildItemList();
-
- add(itemEditorSectionLabel);
- add(itemEditorPanel);
- buildItemEditor();
- }
-
- protected void buildItemList() {
- itemListPanel.clear();
-
- if (!attribute.hasMeta() || attribute.getMeta().all().length == 0) {
- itemListSectionLabel.setVisible(false);
- return;
- }
- itemListSectionLabel.setVisible(true);
-
- MetaItem[] items = attribute.getMeta().all();
- for (int i = 0; i < items.length; i++) {
- MetaItem item = items[i];
- FormGroup formGroup = new FormGroup();
-
- FormLabel label = new FormLabel(item.getName());
- label.addStyleName("largest");
- formGroup.addFormLabel(label);
-
- FormField formField = new FormField();
-
- // Determine editor based on JSON raw value type
- JsonValue value = item.getValue();
- JsonType valueType;
- // TODO https://github.com/gwtproject/gwt/issues/9484
- String jsType = JsUtil.typeOf(value);
- switch (jsType) {
- case "number":
- valueType = JsonType.NUMBER;
- break;
- case "boolean":
- valueType = JsonType.BOOLEAN;
- break;
- default:
- valueType = value.getType();
- break;
- }
- formField.add(createEditor(item, valueType, false, formGroup));
- formGroup.addFormField(formField);
-
- FormGroupActions formGroupActions = new FormGroupActions();
-
- FormButton deleteButton = new FormButton();
- deleteButton.setText(container.getMessages().deleteItem());
- deleteButton.setIcon("remove");
- int index = i;
- deleteButton.addClickHandler(clickEvent -> {
- attribute.getMeta().remove(index);
- buildItemList();
- });
- formGroupActions.add(deleteButton);
-
- formGroup.addFormGroupActions(formGroupActions);
-
- itemListPanel.add(formGroup);
- }
- }
-
- protected void buildItemEditor() {
- itemEditorPanel.clear();
-
- MetaItem item = new MetaItem();
-
- FormListBox valueTypeListBox = new FormListBox();
- FormGroup itemNameEditorGroup = createItemNameEditor(item, valueTypeListBox);
- itemEditorPanel.add(itemNameEditorGroup);
-
- FormGroup itemValueEditorGroup = createItemValueEditor(item, valueTypeListBox);
- itemEditorPanel.add(itemValueEditorGroup);
-
- FormGroupActions formGroupActions = new FormGroupActions();
- FormButton addButton = new FormButton();
- addButton.setText(container.getMessages().addItem());
- addButton.setIcon("plus");
- addButton.addClickHandler(clickEvent -> {
- if (item.isValid()) {
- itemNameEditorGroup.setError(false);
- itemValueEditorGroup.setError(false);
- // TODO This is necessary because JSON elemental behavior is weird
- MetaItem storedItem = new MetaItem(Json.parse(item.getJsonObject().toJson()));
- if (!attribute.hasMeta()) {
- attribute.setMeta(new Meta());
- }
- attribute.getMeta().add(storedItem);
- buildItemList();
- buildItemEditor();
- } else {
- itemNameEditorGroup.setError(true);
- itemValueEditorGroup.setError(true);
- showValidationError(environment.getMessages().enterNameAndValue());
- }
- });
- formGroupActions.add(addButton);
- itemValueEditorGroup.addFormGroupActions(formGroupActions);
- }
-
- protected FormGroup createItemNameEditor(MetaItem item, FormListBox typeListBox) {
- FormGroup formGroup = new FormGroup();
-
- FormLabel label = new FormLabel(environment.getMessages().itemName());
- label.addStyleName("largest");
- formGroup.addFormLabel(label);
-
- FormField formField = new FormField();
- formGroup.addFormField(formField);
-
- FormListBox wellknownListBox = new FormListBox();
- wellknownListBox.addItem(environment.getMessages().selectItem());
- for (AssetMeta wellknown : AssetMeta.editable()) {
- wellknownListBox.addItem(wellknown.name());
- }
- formField.add(wellknownListBox);
-
- formField.add(new FormOutputText(environment.getMessages().or()));
-
- FormInputText itemNameInput = createFormInputText(container.getStyle().stringEditor());
- itemNameInput.setPlaceholder(environment.getMessages().enterCustomAssetAttributeMetaName());
- itemNameInput.addValueChangeHandler(event -> {
- item.setName(event.getValue());
- });
- formField.add(itemNameInput);
-
- wellknownListBox.addChangeHandler(event -> {
- if (wellknownListBox.getSelectedIndex() > 0) {
- AssetMeta assetMeta = AssetMeta.editable()[wellknownListBox.getSelectedIndex() - 1];
- itemNameInput.setText(assetMeta.getName());
- item.setName(assetMeta.getName());
- typeListBox.setSelectedIndex(
- AssetMeta.ValueType.byValueType(assetMeta.getValueType()).ordinal() + 1
- );
- } else {
- itemNameInput.setText(null);
- item.setName(null);
- typeListBox.setSelectedIndex(0);
- }
- DomEvent.fireNativeEvent(Document.get().createChangeEvent(), typeListBox);
- });
-
- return formGroup;
- }
-
- protected FormGroup createItemValueEditor(MetaItem item, FormListBox typeListBox) {
- FormGroup formGroup = new FormGroup();
-
- FormLabel label = new FormLabel(environment.getMessages().value());
- label.addStyleName("largest");
- formGroup.addFormLabel(label);
-
- FormField formField = new FormField();
- formGroup.addFormField(formField);
-
- typeListBox.addItem(environment.getMessages().selectType());
- for (AssetMeta.ValueType metaValueType : AssetMeta.ValueType.values()) {
- typeListBox.addItem(metaValueType.name, metaValueType.name());
- }
- typeListBox.addChangeHandler(event -> resetItemValueEditor(item, formGroup, formField, typeListBox));
-
- formField.add(typeListBox);
-
- // Initial state
- resetItemValueEditor(item, formGroup, formField, typeListBox);
-
- return formGroup;
- }
-
- protected void resetItemValueEditor(MetaItem item, FormGroup formGroup, FormField formField, FormListBox typeListBox) {
- // Remove the last used editor (last widget in form field)
- if (formField.getWidgetCount() > 1)
- formField.remove(formField.getWidget(formField.getWidgetCount() - 1));
-
- // Create and add new editor, default to empty STRING
- item.clearValue();
- JsonType valueType = typeListBox.getSelectedIndex() > 0
- ? AssetMeta.ValueType.valueOf(typeListBox.getSelectedValue()).valueType
- : JsonType.STRING;
- if (valueType == JsonType.BOOLEAN) {
- item.setValueAsBoolean(false); // Special case boolean editor, has an "initial" state, there is always a value
- }
- IsWidget editor = createEditor(item, valueType, true, formGroup);
- formField.add(editor);
- }
- }
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantActivity.java
index c945ca0cf..ae3e79c02 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantActivity.java
@@ -22,7 +22,7 @@ package org.openremote.manager.client.assets.tenant;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import org.openremote.manager.client.Environment;
import org.openremote.manager.client.assets.AssetBrowsingActivity;
-import org.openremote.manager.client.assets.asset.AssetPlace;
+import org.openremote.manager.client.assets.asset.AssetViewPlace;
import org.openremote.manager.client.assets.browser.AssetBrowser;
import org.openremote.manager.client.assets.browser.AssetBrowserSelection;
import org.openremote.manager.client.assets.browser.AssetTreeNode;
@@ -66,7 +66,7 @@ public class AssetsTenantActivity extends AssetBrowsingActivity<AssetsTenantPlac
);
} else if (event.getSelectedNode() instanceof AssetTreeNode) {
environment.getPlaceController().goTo(
- new AssetPlace(event.getSelectedNode().getId())
+ new AssetViewPlace(event.getSelectedNode().getId())
);
}
}));
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantImpl.ui.xml
index 5cd35493c..4059fd793 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantImpl.ui.xml
@@ -42,7 +42,7 @@
<w:Hyperlink
addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
icon="plus-square"
- targetHistoryToken="asset:"
+ targetHistoryToken="assetEdit:"
text="{managerMessages.createAsset}"/>
</g:HTMLPanel>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantPlace.java b/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantPlace.java
index 440fa51fd..35c071dad 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantPlace.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/tenant/AssetsTenantPlace.java
@@ -19,12 +19,11 @@
*/
package org.openremote.manager.client.assets.tenant;
-import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
import org.openremote.manager.client.assets.AssetsPlace;
-public class AssetsTenantPlace extends Place implements AssetsPlace {
+public class AssetsTenantPlace extends AssetsPlace {
final String realmId;
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.java
index 31d85a78e..a3e2fc4dd 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
@@ -302,4 +302,8 @@ public interface ManagerMessages extends Messages {
String attributeValueStored(String name);
String invalidAttributeName();
+
+ String editAsset();
+
+ String viewAsset();
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.java b/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.java
index 22545efcb..868285a6a 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.java
@@ -65,9 +65,6 @@ public class MapViewImpl extends Composite implements MapView {
@UiField
HTMLPanel sidebarContainer;
- @UiField
- Label mapLoadingLabel;
-
@UiField
MapWidget mapWidget;
@@ -86,15 +83,10 @@ public class MapViewImpl extends Composite implements MapView {
initWidget(ui.createAndBindUi(this));
splitPanel.setOnResize(() -> {
- if (mapWidget.isInitialised()) {
- mapWidget.resize();
- showInfoPanel();
- }
+ mapWidget.resize();
+ showInfoPanel();
});
- mapLoadingLabel.setVisible(true);
- mapWidget.setVisible(false);
-
infoPanel = infoPanelProvider.get();
infoPanel.addStyleName(style.infoPanel());
}
@@ -116,10 +108,7 @@ public class MapViewImpl extends Composite implements MapView {
@Override
public void initialiseMap(JsonObject mapOptions) {
- mapLoadingLabel.setVisible(false);
mapWidget.initialise(mapOptions, () -> {
- mapWidget.resize();
- mapWidget.setVisible(true);
showInfoPanel();
});
mapWidget.addNavigationControl();
diff --git a/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml
index e392ce861..7760f22af 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/map/MapViewImpl.ui.xml
@@ -51,15 +51,11 @@
<w:Hyperlink
addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
icon="plus-square"
- targetHistoryToken="asset:"
+ targetHistoryToken="assetEdit:"
text="{managerMessages.createAsset}"/>
</g:HTMLPanel>
- <g:Label ui:field="mapLoadingLabel"
- text="{managerMessages.mapLoading}"
- addStyleNames="{style.mapLoadingLabel}"/>
-
<w:MapWidget ui:field="mapWidget"
addStyleNames="{style.mapWidget}"/>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormOutputLocation.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormOutputLocation.java
new file mode 100644
index 000000000..db20316a7
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormOutputLocation.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.client.widget;
+
+import com.google.gwt.user.client.ui.Label;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+public class FormOutputLocation extends Label {
+
+ public FormOutputLocation() {
+ setStyleName("or-FormControl or-FormOutputText");
+ }
+
+ public boolean setCoordinates(String noLocationText, double[] coordinates) {
+ // Rounding to 5 decimals gives us precision of about 1 meter, should be enough
+ return setCoordinates(noLocationText, coordinates, 5);
+ }
+
+ public boolean setCoordinates(String noLocationText, double[] coordinates, int roundDecimalPlaces) {
+ if (coordinates != null && coordinates.length == 2) {
+ // TODO: This assumes 0 is Lng and 1 is Lat, which is true for PostGIS backend
+ // TODO: Because Lat/Lng is the 'right way', we flip it here for display
+ setText(round(coordinates[1], roundDecimalPlaces) + " " + round(coordinates[0], roundDecimalPlaces) + " Lat|Lng");
+ return true;
+ }
+ setText(noLocationText);
+ return false;
+ }
+
+ protected String round(double d, int places) {
+ return new BigDecimal(d).setScale(places, RoundingMode.HALF_UP).toString();
+ }
+
+}
\ No newline at end of file
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/MapWidget.java b/manager/client/src/main/java/org/openremote/manager/client/widget/MapWidget.java
index b676b73fa..63436330b 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/MapWidget.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/MapWidget.java
@@ -166,12 +166,15 @@ public class MapWidget extends ComplexPanel {
host = new FlowPanel();
host.getElement().getStyle().setHeight(100, Style.Unit.PCT);
host.getElement().setId(hostElementId);
+ host.setVisible(false);
add(host, (Element) getElement());
mapOptions.put("container", hostElementId);
mapboxMap = new MapboxMap(mapOptions);
mapboxMap.on(EventType.LOAD, eventData -> {
+ host.setVisible(true);
+ resize();
if (onLoad != null)
onLoad.run();
addFeaturesOnLoad();
@@ -194,10 +197,6 @@ public class MapWidget extends ComplexPanel {
if (mapboxMap == null)
return;
mapboxMap.resize();
- // We need to do this again asynchronous, sometimes the layout isn't ready
- Browser.getWindow().setTimeout(() -> {
- mapboxMap.resize();
- }, 10);
}
public void setOpaque(boolean opaque) {
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.properties
index b3b15a259..7e570a5f5 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
@@ -155,4 +155,6 @@ editAssetRuleset=Edit asset ruleset: {0}
attributeValueRefreshed=Attribute value refreshed: {0}
attributeValueStored=Attribute value stored: {0}
invalidAttributeName=Invalid attribute name, use only alphanumeric and underscore characters.
+editAsset=Edit asset
+viewAsset=View asset
diff --git a/manager/client/src/main/webapp/img/Example Chart Big.png b/manager/client/src/main/webapp/img/Example Chart Big.png
new file mode 100644
index 000000000..3f5ac4c1c
Binary files /dev/null and b/manager/client/src/main/webapp/img/Example Chart Big.png differ
diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
index f2437d938..7b495e58d 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
@@ -293,7 +293,6 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
ServerAsset apartment1LivingroomThermostat = new ServerAsset(apartment1Livingroom);
apartment1LivingroomThermostat.setName("Livingroom Thermostat");
- apartment1LivingroomThermostat.setLocation(geometryFactory.createPoint(new Coordinate(5.469751699216005, 51.44760787406028)));
apartment1LivingroomThermostat.setType(AssetType.THING);
ThingAttributes apartment1LivingroomThermostatAttributes = new ThingAttributes(apartment1LivingroomThermostat);
apartment1LivingroomThermostatAttributes.put(
diff --git a/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy b/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy
index 00c5d228d..cafc64d8d 100644
--- a/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy
@@ -162,6 +162,7 @@ class AdminTenantsActivityTest extends Specification implements ManagerContainer
{},
{},
{},
+ {},
{
adminTenantsActivity = new AdminTenantsActivity(
environment, adminView, adminNavigationPresenter, adminTenantsView, tenantResource, tenantArrayMapper
diff --git a/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy b/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy
index d840b01e2..3329e67bc 100644
--- a/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy
@@ -179,6 +179,7 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTr
{},
{},
{},
+ {},
{
adminUsersActivity = new AdminUsersActivity(
environment, adminView, adminNavigationPresenter, adminUsersView, tenantResource, tenantArrayMapper, userResource, userArrayMapper
diff --git a/model/src/main/java/org/openremote/model/asset/AssetType.java b/model/src/main/java/org/openremote/model/asset/AssetType.java
index 8f9ce7e0b..e3d2484c9 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetType.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetType.java
@@ -27,6 +27,7 @@ import org.openremote.model.Attributes;
import org.openremote.model.Meta;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@@ -89,12 +90,10 @@ public enum AssetType {
THING(ASSET_NAMESPACE + ":thing", true, null);
final protected String value;
- final protected boolean editable;
final protected JsonObject defaultAttributes;
AssetType(String value, boolean editable, JsonObject defaultAttributes) {
this.value = value;
- this.editable = editable;
this.defaultAttributes = defaultAttributes;
}
@@ -102,20 +101,12 @@ public enum AssetType {
return value;
}
- public boolean isEditable() {
- return editable;
- }
-
public JsonObject getDefaultAttributes() {
return defaultAttributes;
}
- public static AssetType[] editable() {
- List<AssetType> list = new ArrayList<>();
- for (AssetType assetType : values()) {
- if (assetType.isEditable())
- list.add(assetType);
- }
+ public static AssetType[] valuesSorted() {
+ List<AssetType> list = new ArrayList<>(Arrays.asList(values()));
list.sort(Comparator.comparing(Enum::name));
if (list.contains(CUSTOM)) {