Skip to content

armgit / core

Public Imported from GitHub
0

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

Type-based asset editors, migrated agent CRUD

Christian Bauer10fd6ef9ab23
diff --git a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java
index ce670bb69..835def49b 100644
--- a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java
+++ b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java
@@ -40,18 +40,18 @@ public class Controller2Component extends UriEndpointComponent implements Connec
public static final String HEADER_COMMAND_VALUE = Controller2Component.class.getCanonicalName() + ".HEADER_COMMAND_VALUE";
protected final Controller2Adapter.Manager adapterManager;
- protected static final Attributes settings;
+ public static final Attributes SETTINGS;
static {
- settings = new Attributes();
- settings.add(ConnectorUtil.buildConnectorSetting(
+ SETTINGS = new Attributes();
+ SETTINGS.put(ConnectorUtil.buildConnectorSetting(
"host",
AttributeType.STRING,
"Host/IP Address",
"The OR Controller network hostname or IP address",
true
));
- settings.add(ConnectorUtil.buildConnectorSetting(
+ SETTINGS.put(ConnectorUtil.buildConnectorSetting(
"port",
AttributeType.INTEGER,
"Port",
@@ -60,14 +60,14 @@ public class Controller2Component extends UriEndpointComponent implements Connec
"8868",
null
));
- settings.add(ConnectorUtil.buildConnectorSetting(
+ SETTINGS.put(ConnectorUtil.buildConnectorSetting(
"username",
AttributeType.STRING,
"Username",
"The OR Controller Username",
false
));
- settings.add(ConnectorUtil.buildConnectorSetting(
+ SETTINGS.put(ConnectorUtil.buildConnectorSetting(
"password",
AttributeType.STRING,
"Password",
@@ -129,7 +129,7 @@ public class Controller2Component extends UriEndpointComponent implements Connec
@Override
public Attributes getConnectorSettings() {
- return settings;
+ return SETTINGS;
}
@Override
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 0aa455230..7629e3f1e 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
@@ -22,10 +22,6 @@ package org.openremote.manager.client;
import com.google.gwt.place.shared.Place;
import com.google.inject.Inject;
import com.google.inject.Provider;
-import org.openremote.manager.client.admin.agent.AdminAgentActivity;
-import org.openremote.manager.client.admin.agent.AdminAgentPlace;
-import org.openremote.manager.client.admin.agent.AdminAgentsActivity;
-import org.openremote.manager.client.admin.agent.AdminAgentsPlace;
import org.openremote.manager.client.admin.overview.AdminOverviewActivity;
import org.openremote.manager.client.admin.overview.AdminOverviewPlace;
import org.openremote.manager.client.admin.tenant.AdminTenantActivity;
@@ -72,8 +68,6 @@ public class ManagerActivityMapper implements AppActivityMapper {
protected final Provider<AdminTenantActivity> adminTenantActivityProvider;
protected final Provider<AdminUsersActivity> adminUsersActivityProvider;
protected final Provider<AdminUserActivity> adminUserActivityProvider;
- protected final Provider<AdminAgentsActivity> adminAgentsActivityProvider;
- protected final Provider<AdminAgentActivity> adminAgentActivityProvider;
protected final Provider<UserAccountActivity> userProfileActivityProvider;
@Inject
@@ -89,8 +83,6 @@ public class ManagerActivityMapper implements AppActivityMapper {
Provider<AdminTenantActivity> adminTenantActivityProvider,
Provider<AdminUsersActivity> adminUsersActivityProvider,
Provider<AdminUserActivity> adminUserActivityProvider,
- Provider<AdminAgentsActivity> adminAgentsActivityProvider,
- Provider<AdminAgentActivity> adminAgentActivityProvider,
Provider<UserAccountActivity> userProfileActivityProvider) {
this.securityService = securityService;
this.eventBus = eventBus;
@@ -104,8 +96,6 @@ public class ManagerActivityMapper implements AppActivityMapper {
this.adminTenantActivityProvider = adminTenantActivityProvider;
this.adminUsersActivityProvider = adminUsersActivityProvider;
this.adminUserActivityProvider = adminUserActivityProvider;
- this.adminAgentsActivityProvider = adminAgentsActivityProvider;
- this.adminAgentActivityProvider = adminAgentActivityProvider;
this.userProfileActivityProvider = userProfileActivityProvider;
}
@@ -138,12 +128,6 @@ public class ManagerActivityMapper implements AppActivityMapper {
if (place instanceof AdminUserPlace) {
return adminUserActivityProvider.get().init(securityService, (AdminUserPlace) place);
}
- if (place instanceof AdminAgentsPlace) {
- return adminAgentsActivityProvider.get().init(securityService, (AdminAgentsPlace) place);
- }
- if (place instanceof AdminAgentPlace) {
- return adminAgentActivityProvider.get().init(securityService, (AdminAgentPlace) place);
- }
if (place instanceof UserAccountPlace) {
return userProfileActivityProvider.get().init(securityService, (UserAccountPlace) 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 42745eccc..97fe4244b 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
@@ -21,8 +21,6 @@ package org.openremote.manager.client;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.gwt.place.shared.WithTokenizers;
-import org.openremote.manager.client.admin.agent.AdminAgentPlace;
-import org.openremote.manager.client.admin.agent.AdminAgentsPlace;
import org.openremote.manager.client.admin.overview.AdminOverviewPlace;
import org.openremote.manager.client.admin.tenant.AdminTenantPlace;
import org.openremote.manager.client.admin.tenant.AdminTenantsPlace;
@@ -45,8 +43,6 @@ import org.openremote.manager.client.user.UserAccountPlace;
AdminTenantPlace.Tokenizer.class,
AdminUsersPlace.Tokenizer.class,
AdminUserPlace.Tokenizer.class,
- AdminAgentsPlace.Tokenizer.class,
- AdminAgentPlace.Tokenizer.class,
UserAccountPlace.Tokenizer.class
}
)
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/AdminModule.java b/manager/client/src/main/java/org/openremote/manager/client/admin/AdminModule.java
index bb5ded846..fb96f05a9 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/AdminModule.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/AdminModule.java
@@ -22,7 +22,6 @@ package org.openremote.manager.client.admin;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
-import org.openremote.manager.client.admin.agent.*;
import org.openremote.manager.client.admin.navigation.AdminNavigation;
import org.openremote.manager.client.admin.navigation.AdminNavigationImpl;
import org.openremote.manager.client.admin.navigation.AdminNavigationPresenter;
@@ -31,8 +30,6 @@ import org.openremote.manager.client.admin.overview.AdminOverviewActivity;
import org.openremote.manager.client.admin.overview.AdminOverviewImpl;
import org.openremote.manager.client.admin.tenant.*;
import org.openremote.manager.client.admin.users.*;
-import org.openremote.manager.shared.agent.AgentResource;
-import org.openremote.manager.shared.connector.ConnectorResource;
import org.openremote.manager.shared.security.TenantResource;
import org.openremote.manager.shared.security.UserResource;
@@ -57,11 +54,6 @@ public class AdminModule extends AbstractGinModule {
bind(AdminUsersActivity.class);
bind(AdminUser.class).to(AdminUserImpl.class).in(Singleton.class);
bind(AdminUserActivity.class);
-
- bind(AdminAgents.class).to(AdminAgentsImpl.class).in(Singleton.class);
- bind(AdminAgentsActivity.class);
- bind(AdminAgent.class).to(AdminAgentImpl.class).in(Singleton.class);
- bind(AdminAgentActivity.class);
}
@Provides
@@ -84,24 +76,4 @@ public class AdminModule extends AbstractGinModule {
return $wnd.UserResource;
}-*/;
- @Provides
- @Singleton
- public ConnectorResource getConnectorResource() {
- return getNativeConnectorResource();
- }
-
- public static native ConnectorResource getNativeConnectorResource() /*-{
- return $wnd.ConnectorResource;
- }-*/;
-
- @Provides
- @Singleton
- public AgentResource getAgentResource() {
- return getNativeAgentResource();
- }
-
- public static native AgentResource getNativeAgentResource() /*-{
- return $wnd.AgentResource;
- }-*/;
-
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgent.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgent.java
deleted file mode 100644
index 9bcdfc992..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgent.java
+++ /dev/null
@@ -1,70 +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.admin.agent;
-
-import org.openremote.manager.client.admin.AdminContent;
-import org.openremote.manager.client.widget.FormView;
-import org.openremote.manager.shared.connector.Connector;
-
-public interface AdminAgent extends AdminContent, FormView {
-
- interface Presenter {
-
- void create();
-
- void update();
-
- void delete();
-
- void cancel();
-
- void onConnectorSelected(Connector connector);
- }
-
- void setPresenter(Presenter presenter);
-
- void setConnectors(Connector[] connectors);
-
- void setAssignedConnector(Connector connector);
-
- void setName(String name);
-
- String getName();
-
- void setNameError(boolean error);
-
- void setDescription(String description);
-
- String getDescription();
-
- void setDescriptionError(boolean error);
-
- void setAgentEnabled(Boolean enabled);
-
- boolean getAgentEnabled();
-
- void setAgentEnabledError(boolean error);
-
- void enableCreate(boolean enable);
-
- void enableUpdate(boolean enable);
-
- void enableDelete(boolean enable);
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentActivity.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentActivity.java
deleted file mode 100644
index 917107bb2..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentActivity.java
+++ /dev/null
@@ -1,296 +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.admin.agent;
-
-import com.google.gwt.user.client.ui.AcceptsOneWidget;
-import org.openremote.manager.client.Environment;
-import org.openremote.manager.client.admin.AbstractAdminActivity;
-import org.openremote.manager.client.admin.AdminView;
-import org.openremote.manager.client.admin.navigation.AdminNavigation;
-import org.openremote.manager.client.event.bus.EventBus;
-import org.openremote.manager.client.event.bus.EventRegistration;
-import org.openremote.manager.client.mvp.AppActivity;
-import org.openremote.manager.shared.Runnable;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.agent.AgentResource;
-import org.openremote.manager.shared.connector.Connector;
-import org.openremote.manager.shared.connector.ConnectorResource;
-import org.openremote.manager.shared.event.ui.ShowInfoEvent;
-
-import javax.inject.Inject;
-import java.util.Collection;
-import java.util.logging.Logger;
-
-import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;
-
-public class AdminAgentActivity
- extends AbstractAdminActivity<AdminAgentPlace, AdminAgent>
- implements AdminAgent.Presenter {
-
- private static final Logger LOG = Logger.getLogger(AdminAgentActivity.class.getName());
-
- final protected Environment environment;
- final protected ConnectorResource connectorResource;
- final protected AgentResource agentResource;
- final protected AgentMapper agentMapper;
- final protected ConnectorArrayMapper connectorArrayMapper;
-
- protected String id;
- protected Connector[] connectors;
- protected Agent agent;
- protected Connector assignedConnector;
-
- // This is a dummy we use when the Agent's assigned connector is not installed
- protected final Connector notFoundConnector = new Connector();
- protected final String notFoundConnectorType = "NOT_FOUND_CONNECTOR";
-
- @Inject
- public AdminAgentActivity(Environment environment,
- AdminView adminView,
- AdminNavigation.Presenter adminNavigationPresenter,
- AdminAgent view,
- ConnectorResource connectorResource,
- AgentResource agentResource,
- AgentMapper agentMapper,
- ConnectorArrayMapper connectorArrayMapper) {
- super(adminView, adminNavigationPresenter, view);
- this.environment = environment;
- this.connectorResource = connectorResource;
- this.agentResource = agentResource;
- this.agentMapper = agentMapper;
- this.connectorArrayMapper = connectorArrayMapper;
-
- notFoundConnector.setType(notFoundConnectorType);
- }
-
- @Override
- protected String[] getRequiredRoles() {
- return new String[]{"read:admin", "write:admin"};
- }
-
- @Override
- protected AppActivity<AdminAgentPlace> init(AdminAgentPlace place) {
- id = place.getId();
- return super.init(place);
- }
-
- @Override
- public void start(AcceptsOneWidget container, EventBus eventBus, Collection<EventRegistration> registrations) {
- super.start(container, eventBus, registrations);
-
- adminContent.setPresenter(this);
-
- adminContent.clearFormMessages();
- clearViewFieldErrors();
- adminContent.enableCreate(false);
- adminContent.enableUpdate(false);
- adminContent.enableDelete(false);
-
- adminContent.setFormBusy(true);
- if (id != null) {
- loadConnectors(() -> loadAgent(() -> {
- writeToView();
- adminContent.setFormBusy(false);
- adminContent.enableCreate(false);
- adminContent.enableUpdate(true);
- adminContent.enableDelete(true);
- }));
- } else {
- loadConnectors(() -> {
- agent = new Agent();
- writeToView();
- adminContent.setFormBusy(false);
- adminContent.enableCreate(true);
- });
- }
- }
-
- @Override
- public void onStop() {
- super.onStop();
- adminContent.setPresenter(null);
- adminContent.clearFormMessages();
- clearViewFieldErrors();
- }
-
- @Override
- public void create() {
- adminContent.setFormBusy(true);
- adminContent.clearFormMessages();
- clearViewFieldErrors();
- readFromView();
- environment.getRequestService().execute(
- agentMapper,
- requestParams -> {
- agentResource.create(requestParams, agent);
- },
- 204,
- () -> {
- adminContent.setFormBusy(false);
- environment.getEventBus().dispatch(new ShowInfoEvent(
- environment.getMessages().agentCreated(agent.getName())
- ));
- environment.getPlaceController().goTo(new AdminAgentsPlace());
- },
- ex -> handleRequestException(ex, environment)
- );
- }
-
- @Override
- public void update() {
- adminContent.setFormBusy(true);
- adminContent.clearFormMessages();
- clearViewFieldErrors();
- readFromView();
- environment.getRequestService().execute(
- agentMapper,
- requestParams -> {
- agentResource.update(requestParams, id, agent);
- },
- 204,
- () -> {
- adminContent.setFormBusy(false);
- environment.getEventBus().dispatch(new ShowInfoEvent(
- environment.getMessages().agentUpdated(agent.getName())
- ));
- environment.getPlaceController().goTo(new AdminAgentPlace(id));
- },
- ex -> handleRequestException(ex, environment)
- );
- }
-
- @Override
- public void delete() {
- adminContent.showConfirmation(
- environment.getMessages().confirmation(),
- environment.getMessages().confirmationDelete(agent.getName()),
- () -> {
- adminContent.setFormBusy(true);
- adminContent.clearFormMessages();
- clearViewFieldErrors();
- environment.getRequestService().execute(
- requestParams -> {
- agentResource.delete(requestParams, this.id);
- },
- 204,
- () -> {
- adminContent.setFormBusy(false);
- environment.getEventBus().dispatch(new ShowInfoEvent(
- environment.getMessages().agentDeleted(agent.getName())
- ));
- environment.getPlaceController().goTo(new AdminAgentsPlace());
- },
- ex -> handleRequestException(ex, environment)
- );
- }
- );
- }
-
- @Override
- public void cancel() {
- environment.getPlaceController().goTo(new AdminAgentsPlace());
- }
-
- @Override
- public void onConnectorSelected(Connector connector) {
- assignedConnector = connector;
- adminContent.setAssignedConnector(connector);
- }
-
- protected void loadConnectors(Runnable onSuccess) {
- environment.getRequestService().execute(
- connectorArrayMapper,
- connectorResource::getConnectors,
- 200,
- connectors -> {
- this.connectors = connectors;
- onSuccess.run();
- },
- ex -> handleRequestException(ex, environment)
- );
- }
-
- protected void loadAgent(Runnable onSuccess) {
- environment.getRequestService().execute(
- agentMapper,
- requestParams -> agentResource.get(requestParams, id),
- 200,
- agent -> {
- this.agent = agent;
- this.id = agent.getId();
- onSuccess.run();
- },
- ex -> handleRequestException(ex, environment)
- );
- }
-
- protected void writeToView() {
- findAssignedConnector();
- adminContent.setConnectors(connectors);
- adminContent.setAssignedConnector(assignedConnector);
- adminContent.setName(agent.getName());
- adminContent.setDescription(agent.getDescription());
- adminContent.setAgentEnabled(agent.isEnabled());
- }
-
- protected void readFromView() {
- setAssignedConnector();
- agent.setName(adminContent.getName());
- agent.setDescription(adminContent.getDescription());
- agent.setEnabled(adminContent.getAgentEnabled());
- }
-
- protected void findAssignedConnector() {
- assignedConnector = null;
- if (agent != null && agent.getConnectorType() != null) {
- for (Connector connector : connectors) {
- if (connector.getType().equals(agent.getConnectorType())) {
- assignedConnector = connector;
- break;
- }
- }
- if (assignedConnector != null) {
- assignedConnector.readSettings(agent);
- } else if (!Agent.NO_CONNECTOR_ASSIGNED_TYPE.equals(agent.getConnectorType())){
- notFoundConnector.setName(
- agent.getConnectorType() +
- " (" + environment.getMessages().connectorNotInstalled() + ")"
- );
- assignedConnector = notFoundConnector;
- }
- }
- }
-
- protected void setAssignedConnector() {
- if (assignedConnector != null && !assignedConnector.getType().equals(notFoundConnectorType)) {
- agent.setConnectorType(assignedConnector.getType());
- assignedConnector.writeSettings(agent);
- } else {
- agent.setConnectorType(null);
- agent.setConnectorSettings(null);
- }
- }
-
- protected void clearViewFieldErrors() {
- adminContent.setNameError(false);
- adminContent.setDescriptionError(false);
- adminContent.setAgentEnabledError(false);
- }
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentImpl.java
deleted file mode 100644
index f791d2166..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentImpl.java
+++ /dev/null
@@ -1,243 +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.admin.agent;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.dom.client.ClickEvent;
-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 org.openremote.manager.client.app.dialog.ConfirmationDialog;
-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.connector.Connector;
-
-import javax.inject.Inject;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.logging.Logger;
-
-public class AdminAgentImpl extends AttributesFormViewImpl implements AdminAgent {
-
- private static final Logger LOG = Logger.getLogger(AdminAgentImpl.class.getName());
-
- interface UI extends UiBinder<HTMLPanel, AdminAgentImpl> {
- }
-
- interface Style extends CssResource, AttributesFormStyle {
-
- String formMessages();
-
- String nameInput();
-
- String descriptionInput();
-
- String attributeIntegerEditor();
-
- String attributeFloatEditor();
-
- String attributeStringEditor();
-
- String attributeBooleanEditor();
- }
-
- @UiField
- Style style;
-
- @UiField
- FormGroup nameGroup;
- @UiField
- TextBox nameInput;
-
- @UiField
- FormGroup descriptionGroup;
- @UiField
- TextBox descriptionInput;
-
- @UiField
- FormGroup enabledGroup;
- @UiField
- FormCheckBox enabledCheckBox;
-
- @UiField(provided = true)
- ValueListBox<Connector> connectorListBox;
-
- @UiField
- FlowPanel attributesContainer;
-
- @UiField
- PushButton createButton;
-
- @UiField
- PushButton updateButton;
-
- @UiField
- PushButton deleteButton;
-
- @UiField
- PushButton cancelButton;
-
- protected Presenter presenter;
-
- @Inject
- public AdminAgentImpl(ManagerMessages managerMessages, Provider<ConfirmationDialog> confirmationDialogProvider) {
- super(confirmationDialogProvider);
-
- connectorListBox = new ValueListBox<>(new AbstractRenderer<Connector>() {
- @Override
- public String render(Connector connector) {
- if (connector == null)
- return managerMessages.noConnectorAssigned();
- return connector.getName();
- }
- });
-
- UI ui = GWT.create(UI.class);
- initWidget(ui.createAndBindUi(this));
-
- connectorListBox.addValueChangeHandler(event -> {
- Connector connector = event.getValue();
- if (presenter != null) {
- presenter.onConnectorSelected(connector);
- }
- });
- }
-
- @Override
- public void setPresenter(Presenter presenter) {
- this.presenter = presenter;
- if (presenter == null) {
- nameInput.setValue(null);
- descriptionInput.setValue(null);
- enabledCheckBox.setValue(false);
- connectorListBox.setValue(null);
- connectorListBox.setAcceptableValues(new ArrayList<>());
- }
- }
-
- @Override
- public void setConnectors(Connector[] connectors) {
- connectorListBox.setAcceptableValues(Arrays.asList(connectors));
- }
-
- @Override
- public void setAssignedConnector(Connector connector) {
- connectorListBox.setValue(connector);
-
- attributesContainer.clear();
-
- if (connector != null) {
- FormGroup[] attributeFormGroups =
- createAttributeFormGroups(style, connector.getSettings());
- for (FormGroup attributeFormGroup : attributeFormGroups) {
- attributesContainer.add(attributeFormGroup);
- }
- }
- }
-
- @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 setDescription(String description) {
- descriptionInput.setValue(description);
- }
-
- @Override
- public String getDescription() {
- return descriptionInput.getValue().length() > 0 ? descriptionInput.getValue() : null;
- }
-
- @Override
- public void setDescriptionError(boolean error) {
- descriptionGroup.setError(error);
- }
-
- @Override
- public void setAgentEnabled(Boolean enabled) {
- enabledCheckBox.setValue(enabled != null ? enabled : false);
- }
-
- @Override
- public boolean getAgentEnabled() {
- return enabledCheckBox.getValue();
- }
-
- @Override
- public void setAgentEnabledError(boolean error) {
- enabledGroup.setError(error);
- }
-
- @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();
- }
-
- @UiHandler("cancelButton")
- void cancelClicked(ClickEvent e) {
- if (presenter != null)
- presenter.cancel();
- }
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentImpl.ui.xml
deleted file mode 100644
index f6a050e85..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentImpl.ui.xml
+++ /dev/null
@@ -1,127 +0,0 @@
-<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">
-
- <ui:with field="managerMessages" type="org.openremote.manager.client.i18n.ManagerMessages"/>
- <ui:with field="widgetStyle" type="org.openremote.manager.client.style.WidgetStyle"/>
-
- <ui:style type="org.openremote.manager.client.admin.agent.AdminAgentImpl.Style">
- .formMessages {
- max-width: 30em;
- }
-
- .nameInput,
- .descriptionInput {
- width: 30em;
- }
-
- .attributeStringEditor {
- width: 30em;
- }
-
- .attributeIntegerEditor {
- width: 10em;
- }
-
- .attributeFloatEditor {
- width: 5em;
- }
-
- .attributeBooleanEditor {
-
- }
- </ui:style>
-
- <g:HTMLPanel styleName="flex layout vertical">
-
- <g:FlowPanel
- styleName="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="layout horizontal {style.formMessages} {widgetStyle.FormMessages} error"
- visible="false">
- <w:IconLabel icon="warning" addStyleNames="{widgetStyle.MessagesIcon}"/>
- <g:FlowPanel ui:field="formMessagesError"/>
- </g:FlowPanel>
-
- <div class="{widgetStyle.Headline1}">
- <g:InlineLabel text="{managerMessages.editAgent}"/>
- </div>
-
- <div class="{widgetStyle.HeadlineSub}">
- <span class="required">*</span>
- <g:InlineLabel text="{managerMessages.requiredFields}"/>
- </div>
-
- <w:Form ui:field="form">
- <w:FormGroup ui:field="nameGroup">
- <w:label>
- <w:FormLabel text="{managerMessages.agentName}" required="true"/>
- </w:label>
- <w:field>
- <w:FormField>
- <w:FormInputText ui:field="nameInput" addStyleNames="{style.nameInput}"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
-
- <w:FormGroup ui:field="descriptionGroup">
- <w:label>
- <w:FormLabel text="{managerMessages.description}" required="false"/>
- </w:label>
- <w:field>
- <w:FormField>
- <w:FormInputText ui:field="descriptionInput" addStyleNames="{style.descriptionInput}"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
-
- <w:FormGroup ui:field="enabledGroup">
- <w:label>
- <w:FormLabel text="{managerMessages.enabled}"/>
- </w:label>
- <w:field>
- <w:FormField>
- <w:FormCheckBox ui:field="enabledCheckBox"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
-
- <w:FormGroup>
- <w:label>
- <w:FormLabel text="{managerMessages.connectorType}"/>
- </w:label>
- <w:field>
- <w:FormField>
- <g:ValueListBox ui:field="connectorListBox"
- addStyleNames="{widgetStyle.FormControl} {widgetStyle.FormDropDown}"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
-
- <g:FlowPanel ui:field="attributesContainer"/>
-
- <w:FormGroup centerJustified="true">
- <w:field>
- <w:FormField>
- <w:FormButton ui:field="updateButton" primary="true" text="{managerMessages.updateAgent}"
- visible="false" icon="save"/>
- <w:FormButton ui:field="createButton" primary="true" text="{managerMessages.createAgent}"
- visible="false" icon="save"/>
- <w:FormButton ui:field="deleteButton" text="{managerMessages.deleteAgent}" visible="false"
- icon="trash"/>
- <w:FormButton ui:field="cancelButton" danger="true" text="{managerMessages.cancel}"
- icon="close"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
-
- </w:Form>
-
- </g:HTMLPanel>
-
-</ui:UiBinder>
\ No newline at end of file
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentPlace.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentPlace.java
deleted file mode 100644
index 1c26fe5cb..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentPlace.java
+++ /dev/null
@@ -1,62 +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.admin.agent;
-
-import com.google.gwt.place.shared.PlaceTokenizer;
-import com.google.gwt.place.shared.Prefix;
-import org.openremote.manager.client.admin.AdminPlace;
-
-public class AdminAgentPlace extends AdminPlace {
-
- final String id;
-
- public AdminAgentPlace() {
- id = null;
- }
-
- public AdminAgentPlace(String id) {
- this.id = id;
- }
-
- public String getId() {
- return id;
- }
-
- @Prefix("agent")
- public static class Tokenizer implements PlaceTokenizer<AdminAgentPlace> {
-
- @Override
- public AdminAgentPlace getPlace(String token) {
- return new AdminAgentPlace(token != null && token.length() > 0 ? token : null);
- }
-
- @Override
- public String getToken(AdminAgentPlace place) {
- return place.getId() != null ? place.getId() : "";
- }
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "id='" + id + '\'' +
- "}";
- }
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgents.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgents.java
deleted file mode 100644
index 8b1627a46..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgents.java
+++ /dev/null
@@ -1,39 +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.admin.agent;
-
-import org.openremote.manager.client.admin.AdminContent;
-import org.openremote.manager.shared.agent.Agent;
-
-public interface AdminAgents extends AdminContent {
-
- interface Presenter {
-
- void onAgentSelected(Agent agent);
-
- void createAgent();
-
- }
-
- void setPresenter(Presenter presenter);
-
- void setAgents(Agent[] agents);
-
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsActivity.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsActivity.java
deleted file mode 100644
index 10c6898e8..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsActivity.java
+++ /dev/null
@@ -1,96 +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.admin.agent;
-
-import com.google.gwt.user.client.ui.AcceptsOneWidget;
-import org.openremote.manager.client.Environment;
-import org.openremote.manager.client.admin.AbstractAdminActivity;
-import org.openremote.manager.client.admin.AdminView;
-import org.openremote.manager.client.admin.navigation.AdminNavigation;
-import org.openremote.manager.client.event.bus.EventBus;
-import org.openremote.manager.client.event.bus.EventRegistration;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.agent.AgentResource;
-
-import javax.inject.Inject;
-import java.util.Collection;
-import java.util.logging.Logger;
-
-import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;
-
-public class AdminAgentsActivity
- extends AbstractAdminActivity<AdminAgentsPlace, AdminAgents>
- implements AdminAgents.Presenter {
-
- private static final Logger LOG = Logger.getLogger(AdminAgentsActivity.class.getName());
-
- final protected Environment environment;
- final protected AgentResource agentResource;
- final protected AgentArrayMapper agentArrayMapper;
-
- @Inject
- public AdminAgentsActivity(Environment environment,
- AdminView adminView,
- AdminNavigation.Presenter adminNavigationPresenter,
- AdminAgents view,
- AgentResource agentResource,
- AgentArrayMapper agentArrayMapper) {
- super(adminView, adminNavigationPresenter, view);
- this.environment = environment;
- this.agentResource = agentResource;
- this.agentArrayMapper = agentArrayMapper;
- }
-
- @Override
- protected String[] getRequiredRoles() {
- return new String[]{"read:admin"};
- }
-
- @Override
- public void start(AcceptsOneWidget container, EventBus eventBus, Collection<EventRegistration> registrations) {
- super.start(container, eventBus, registrations);
- adminContent.setPresenter(this);
-
- environment.getRequestService().execute(
- agentArrayMapper,
- agentResource::getAll,
- 200,
- adminContent::setAgents,
- ex -> handleRequestException(ex, environment)
- );
-
- }
-
- @Override
- public void onStop() {
- super.onStop();
- adminContent.setPresenter(null);
- }
-
- @Override
- public void onAgentSelected(Agent agent) {
- environment.getPlaceController().goTo(new AdminAgentPlace(agent.getId()));
- }
-
- @Override
- public void createAgent() {
- environment.getPlaceController().goTo(new AdminAgentPlace());
- }
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsImpl.java
deleted file mode 100644
index 5b9583913..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsImpl.java
+++ /dev/null
@@ -1,100 +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.admin.agent;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.dom.client.ClickEvent;
-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.Composite;
-import com.google.gwt.user.client.ui.HTMLPanel;
-import com.google.gwt.user.client.ui.SimplePanel;
-import org.openremote.manager.client.i18n.ManagerMessages;
-import org.openremote.manager.client.style.FormTableStyle;
-import org.openremote.manager.client.style.WidgetStyle;
-import org.openremote.manager.client.widget.PushButton;
-import org.openremote.manager.shared.agent.Agent;
-
-import javax.inject.Inject;
-import java.util.ArrayList;
-import java.util.Arrays;
-
-public class AdminAgentsImpl extends Composite implements AdminAgents {
-
- interface UI extends UiBinder<HTMLPanel, AdminAgentsImpl> {
- }
-
- @UiField
- ManagerMessages managerMessages;
-
- @UiField
- WidgetStyle widgetStyle;
-
- @UiField
- AdminAgentsTable.Style agentsTableStyle;
-
- @UiField
- PushButton createButton;
-
- @UiField
- SimplePanel tableContainer;
-
- final AdminAgentsTable table;
- Presenter presenter;
-
- @Inject
- public AdminAgentsImpl(FormTableStyle formTableStyle) {
- UI ui = GWT.create(UI.class);
- initWidget(ui.createAndBindUi(this));
-
- table = new AdminAgentsTable(managerMessages, agentsTableStyle, formTableStyle);
- table.getSelectionModel().addSelectionChangeHandler(event -> {
- Agent selected;
- if ((selected = table.getSelectedObject()) != null
- && presenter != null) {
- presenter.onAgentSelected(selected);
- }
- }
- );
- tableContainer.add(table);
- }
-
- @Override
- public void setPresenter(Presenter presenter) {
- this.presenter = presenter;
- if (presenter == null) {
- table.setRowData(new ArrayList<>());
- table.flush();
- }
- }
-
- @Override
- public void setAgents(Agent[] agents) {
- tableContainer.setVisible(agents.length > 0);
- table.setRowData(Arrays.asList(agents));
- table.flush();
- }
-
- @UiHandler("createButton")
- void createClicked(ClickEvent e) {
- presenter.createAgent();
- }
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsImpl.ui.xml
deleted file mode 100644
index 372e50bc3..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsImpl.ui.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-<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">
-
- <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="agentsTableStyle" type="org.openremote.manager.client.admin.agent.AdminAgentsTable.Style">
- .nameColumn {
- width: 20em;
- }
-
- .descriptionColumn {
- width: 30em;
- }
-
- .connectorColumn {
- width: 30em;
- }
-
- .enabledColumn {
- width: 4em;
- }
- </ui:style>
-
- <g:HTMLPanel styleName="flex layout vertical">
-
- <div class="{widgetStyle.Headline1}">
- <g:InlineLabel text="{managerMessages.configureAgents}"/>
- </div>
-
- <w:Form>
- <w:FormGroup>
- <w:field>
- <w:FormField>
- <w:FormButton ui:field="createButton" primary="true" text="{managerMessages.newAgent}"
- icon="plus-square"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
-
- <g:SimplePanel ui:field="tableContainer"/>
- </w:Form>
-
- </g:HTMLPanel>
-
-</ui:UiBinder>
\ No newline at end of file
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsPlace.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsPlace.java
deleted file mode 100644
index ba370df35..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsPlace.java
+++ /dev/null
@@ -1,42 +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.admin.agent;
-
-import com.google.gwt.place.shared.PlaceTokenizer;
-import com.google.gwt.place.shared.Prefix;
-import org.openremote.manager.client.admin.AdminPlace;
-
-public class AdminAgentsPlace extends AdminPlace {
-
- @Prefix("agents")
- public static class Tokenizer implements PlaceTokenizer<AdminAgentsPlace> {
-
- @Override
- public AdminAgentsPlace getPlace(String token) {
- return new AdminAgentsPlace();
- }
-
- @Override
- public String getToken(AdminAgentsPlace place) {
- return "";
- }
- }
-
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsTable.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsTable.java
deleted file mode 100644
index 4face67e1..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentsTable.java
+++ /dev/null
@@ -1,115 +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.admin.agent;
-
-import com.google.gwt.resources.client.CssResource;
-import com.google.gwt.user.cellview.client.Column;
-import com.google.gwt.user.cellview.client.TextColumn;
-import com.google.gwt.user.client.ui.HasHorizontalAlignment;
-import com.google.gwt.view.client.SingleSelectionModel;
-import org.openremote.manager.client.i18n.ManagerMessages;
-import org.openremote.manager.client.style.FormTableStyle;
-import org.openremote.manager.client.widget.FormTable;
-import org.openremote.manager.client.widget.IconCell;
-import org.openremote.manager.shared.agent.Agent;
-
-public class AdminAgentsTable extends FormTable<Agent> {
-
- public interface Style extends CssResource {
- String nameColumn();
-
- String descriptionColumn();
-
- String connectorColumn();
-
- String enabledColumn();
- }
-
- final protected Style style;
-
- final protected SingleSelectionModel<Agent> selectionModel = new SingleSelectionModel<>();
-
- final protected TextColumn<Agent> nameColumn = new TextColumn<Agent>() {
- @Override
- public String getValue(Agent agent) {
- return agent.getName();
- }
- };
-
- final protected TextColumn<Agent> descriptionColumn = new TextColumn<Agent>() {
- @Override
- public String getValue(Agent agent) {
- return agent.getDescription();
- }
- };
-
- final protected TextColumn<Agent> connectorColumn = new TextColumn<Agent>() {
- @Override
- public String getValue(Agent agent) {
- if (agent.getConnectorType() == null
- || Agent.NO_CONNECTOR_ASSIGNED_TYPE.equals(agent.getConnectorType()))
- return "-";
- return agent.getConnectorType();
- }
- };
-
- final protected Column<Agent, String> enabledColumn = new Column<Agent, String>(new IconCell()) {
- @Override
- public String getValue(Agent agent) {
- return agent.isEnabled() ? "check-circle" : "circle-thin";
- }
- };
-
- public AdminAgentsTable(ManagerMessages managerMessages,
- Style style,
- FormTableStyle formTableStyle) {
- super(Integer.MAX_VALUE, formTableStyle);
-
- this.style = style;
-
- setSelectionModel(selectionModel);
-
- applyStyleCellText(nameColumn);
- addColumn(nameColumn, createHeader(managerMessages.agentName()));
- addColumnStyleName(0, style.nameColumn());
-
- applyStyleCellText(descriptionColumn);
- addColumn(descriptionColumn, createHeader(managerMessages.description()));
- addColumnStyleName(1, style.descriptionColumn());
-
- applyStyleCellText(connectorColumn);
- addColumn(connectorColumn, createHeader(managerMessages.connectorType()));
- addColumnStyleName(2, style.connectorColumn());
-
- addColumn(enabledColumn, createHeader(managerMessages.enabled()));
- addColumnStyleName(3, style.enabledColumn());
- enabledColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- }
-
- @Override
- public SingleSelectionModel<Agent> getSelectionModel() {
- return selectionModel;
- }
-
- public Agent getSelectedObject() {
- return getSelectionModel().getSelectedObject();
- }
-
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AgentArrayMapper.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AgentArrayMapper.java
deleted file mode 100644
index abd6d22a5..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AgentArrayMapper.java
+++ /dev/null
@@ -1,35 +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.admin.agent;
-
-import com.github.nmorel.gwtjackson.client.ObjectMapper;
-import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
-import org.openremote.manager.client.interop.jackson.DefaultJsonMixin;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.http.EntityReader;
-import org.openremote.manager.shared.http.EntityWriter;
-
-@JsonMixIns({@JsonMixIns.JsonMixIn(target = Agent.class, mixIn = DefaultJsonMixin.class)})
-public interface AgentArrayMapper
- extends ObjectMapper<Agent[]>,
- EntityReader<Agent[]>,
- EntityWriter<Agent[]> {
-}
-
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AgentMapper.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AgentMapper.java
deleted file mode 100644
index f658d1955..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AgentMapper.java
+++ /dev/null
@@ -1,34 +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.admin.agent;
-
-import com.github.nmorel.gwtjackson.client.ObjectMapper;
-import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
-import org.openremote.manager.client.interop.jackson.DefaultJsonMixin;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.http.EntityReader;
-import org.openremote.manager.shared.http.EntityWriter;
-
-@JsonMixIns({@JsonMixIns.JsonMixIn(target = Agent.class, mixIn = DefaultJsonMixin.class)})
-public interface AgentMapper
- extends ObjectMapper<Agent>,
- EntityReader<Agent>,
- EntityWriter<Agent> {
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AttributesMapper.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AttributesMapper.java
deleted file mode 100644
index 0e096354a..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AttributesMapper.java
+++ /dev/null
@@ -1,34 +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.admin.agent;
-
-import com.github.nmorel.gwtjackson.client.ObjectMapper;
-import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
-import org.openremote.manager.client.interop.jackson.DefaultJsonMixin;
-import org.openremote.manager.shared.attribute.Attributes;
-import org.openremote.manager.shared.http.EntityReader;
-import org.openremote.manager.shared.http.EntityWriter;
-
-@JsonMixIns({@JsonMixIns.JsonMixIn(target = Attributes.class, mixIn = DefaultJsonMixin.class)})
-public interface AttributesMapper
- extends ObjectMapper<Attributes>,
- EntityReader<Attributes>,
- EntityWriter<Attributes> {
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigation.java b/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigation.java
index b970c153d..69a82a9ce 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigation.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigation.java
@@ -34,8 +34,6 @@ public interface AdminNavigation extends IsWidget {
String getAdminUsersPlaceToken();
- String getAdminAgentsPlaceToken();
-
void setActivePlace(AdminPlace place);
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.java
index 4a22c94e9..33c4cd19a 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.java
@@ -26,8 +26,6 @@ import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import org.openremote.manager.client.admin.AdminPlace;
-import org.openremote.manager.client.admin.agent.AdminAgentPlace;
-import org.openremote.manager.client.admin.agent.AdminAgentsPlace;
import org.openremote.manager.client.admin.tenant.AdminTenantPlace;
import org.openremote.manager.client.admin.tenant.AdminTenantsPlace;
import org.openremote.manager.client.admin.users.AdminUserPlace;
@@ -51,9 +49,6 @@ public class AdminNavigationImpl extends Composite implements AdminNavigation {
@UiField
Hyperlink usersLink;
- @UiField
- Hyperlink agentsLink;
-
@Inject
public AdminNavigationImpl() {
UI ui = GWT.create(UI.class);
@@ -67,7 +62,6 @@ public class AdminNavigationImpl extends Composite implements AdminNavigation {
overviewLink.setTargetHistoryToken(presenter.getAdminOverviewPlaceToken());
tenantsLink.setTargetHistoryToken(presenter.getAdminTenantsPlaceToken());
usersLink.setTargetHistoryToken(presenter.getAdminUsersPlaceToken());
- agentsLink.setTargetHistoryToken(presenter.getAdminAgentsPlaceToken());
}
@Override
@@ -75,7 +69,6 @@ public class AdminNavigationImpl extends Composite implements AdminNavigation {
overviewLink.removeStyleName("active");
tenantsLink.removeStyleName("active");
usersLink.removeStyleName("active");
- agentsLink.removeStyleName("active");
if (adminPlace instanceof AdminTenantsPlace) {
tenantsLink.addStyleName("active");
@@ -85,10 +78,6 @@ public class AdminNavigationImpl extends Composite implements AdminNavigation {
usersLink.addStyleName("active");
} else if (adminPlace instanceof AdminUserPlace) {
usersLink.addStyleName("active");
- } else if (adminPlace instanceof AdminAgentsPlace) {
- agentsLink.addStyleName("active");
- } else if (adminPlace instanceof AdminAgentPlace) {
- agentsLink.addStyleName("active");
} else {
overviewLink.addStyleName("active");
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.ui.xml
index a931ca70e..ef70d4237 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationImpl.ui.xml
@@ -28,11 +28,6 @@
icon="user"
text="{managerMessages.manageUsers}"/>
- <w:Hyperlink ui:field="agentsLink"
- addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
- icon="gear"
- text="{managerMessages.configureAgents}"/>
-
</g:HTMLPanel>
</ui:UiBinder>
\ No newline at end of file
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationPresenter.java b/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationPresenter.java
index 51cd825a5..b117a7f91 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationPresenter.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/navigation/AdminNavigationPresenter.java
@@ -22,7 +22,6 @@ package org.openremote.manager.client.admin.navigation;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.inject.Inject;
import org.openremote.manager.client.admin.AdminPlace;
-import org.openremote.manager.client.admin.agent.AdminAgentsPlace;
import org.openremote.manager.client.admin.overview.AdminOverviewPlace;
import org.openremote.manager.client.admin.tenant.AdminTenantsPlace;
import org.openremote.manager.client.admin.users.AdminUsersPlace;
@@ -61,11 +60,6 @@ public class AdminNavigationPresenter implements AdminNavigation.Presenter {
return historyMapper.getToken(new AdminUsersPlace());
}
- @Override
- public String getAdminAgentsPlaceToken() {
- return historyMapper.getToken(new AdminAgentsPlace());
- }
-
@Override
public void setActivePlace(AdminPlace place) {
view.onPlaceChange(place);
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 e708aa13c..f978e18be 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
@@ -29,6 +29,7 @@ import org.openremote.manager.client.assets.browser.AssetBrowser;
import org.openremote.manager.client.assets.browser.AssetBrowserImpl;
import org.openremote.manager.client.assets.browser.AssetBrowserPresenter;
import org.openremote.manager.shared.asset.AssetResource;
+import org.openremote.manager.shared.connector.ConnectorResource;
public class AssetsModule extends AbstractGinModule {
@@ -54,4 +55,16 @@ public class AssetsModule extends AbstractGinModule {
return $wnd.AssetResource;
}-*/;
+
+ @Provides
+ @Singleton
+ public ConnectorResource getConnectorResource() {
+ return getNativeConnectorResource();
+ }
+
+ public static native ConnectorResource getNativeConnectorResource() /*-{
+ return $wnd.ConnectorResource;
+ }-*/;
+
+
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/agent/AgentAttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/agent/AgentAttributesEditor.java
new file mode 100644
index 000000000..e1a75e8a6
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/agent/AgentAttributesEditor.java
@@ -0,0 +1,213 @@
+/*
+ * 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.agent;
+
+import com.google.gwt.text.shared.AbstractRenderer;
+import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.widget.*;
+import org.openremote.manager.shared.Consumer;
+import org.openremote.manager.shared.attribute.Attribute;
+import org.openremote.manager.shared.attribute.AttributeType;
+import org.openremote.manager.shared.attribute.Attributes;
+import org.openremote.manager.shared.connector.Connector;
+import org.openremote.manager.shared.connector.ConnectorResource;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;
+import static org.openremote.manager.shared.connector.Connector.ASSET_ATTRIBUTE_CONNECTOR;
+
+public class AgentAttributesEditor extends AttributesEditor {
+
+ final protected ConnectorResource connectorResource;
+ final protected ConnectorArrayMapper connectorArrayMapper;
+
+ final protected FormGroup connectorDropDownGroup = new FormGroup();
+ final protected FormDropDown<Connector> connectorDropDown;
+
+ // This is a dummy we use when the Agent's assigned connector is not installed
+ protected final String notFoundConnectorType = "NOT_FOUND_CONNECTOR";
+ protected final Connector notFoundConnector = new Connector(notFoundConnectorType);
+
+ protected List<Connector> availableConnectors;
+
+ public AgentAttributesEditor(Environment environment, Container container, Attributes attributes,
+ ConnectorResource connectorResource, ConnectorArrayMapper connectorArrayMapper) {
+ super(environment, container, attributes);
+ this.connectorResource = connectorResource;
+ this.connectorArrayMapper = connectorArrayMapper;
+
+ connectorDropDown = createConnectorDropDown();
+ FormLabel connectorDropDownLabel = new FormLabel();
+ connectorDropDownLabel.setText(environment.getMessages().connector());
+ FormField connectorDropDownField = new FormField();
+ connectorDropDownField.add(connectorDropDown);
+ connectorDropDownGroup.addFormLabel(connectorDropDownLabel);
+ connectorDropDownGroup.addFormField(connectorDropDownField);
+
+ container.getFormView().setFormBusy(true);
+ loadConnectors(connectors -> {
+ availableConnectors = Arrays.asList(connectors);
+
+ connectorDropDown.setValue(null);
+ connectorDropDown.setAcceptableValues(availableConnectors);
+
+ Connector connector = getConnector();
+ if (connector != null) {
+ connectorDropDown.setValue(connector);
+ writeConnectorSettingsToAttributes(connector);
+ } else if (getConnectorType() != null) {
+ notFoundConnector.setName(
+ getConnectorType() +
+ " (" + environment.getMessages().connectorNotInstalled() + ")"
+ );
+ connectorDropDown.setValue(notFoundConnector);
+ }
+
+ container.getFormView().setFormBusy(false);
+ refresh();
+ });
+ }
+
+ @Override
+ protected FormGroup createFormGroup(Attribute attribute) {
+ if (attribute.getName().equals(ASSET_ATTRIBUTE_CONNECTOR))
+ return null;
+ return super.createFormGroup(attribute);
+ }
+
+ @Override
+ public void buildAttributeFormGroups() {
+ if (availableConnectors != null) {
+ super.buildAttributeFormGroups();
+ }
+ }
+
+ @Override
+ public void render() {
+ container.getPanel().add(connectorDropDownGroup);
+ super.render();
+ }
+
+ @Override
+ public void setOpaque(boolean opaque) {
+ super.setOpaque(opaque);
+ connectorDropDownGroup.setOpaque(opaque);
+ }
+
+ protected FormDropDown<Connector> createConnectorDropDown() {
+ FormDropDown<Connector> connectorDropDown = new FormDropDown<>(
+ new AbstractRenderer<Connector>() {
+ @Override
+ public String render(Connector connector) {
+ if (connector == null)
+ return environment.getMessages().noConnectorAssigned();
+ return connector.getName();
+ }
+ }
+ );
+ connectorDropDown.addValueChangeHandler(event -> {
+ Connector connector = event.getValue();
+ onConnectorSelected(connector);
+ });
+ return connectorDropDown;
+ }
+
+ protected void onConnectorSelected(Connector connector) {
+ if (connector != null) {
+ setConnectorType(connector.getType());
+ writeConnectorSettingsToAttributes(getConnector());
+ } else {
+ Connector oldConnector = getConnector();
+ removeConnectorSettingsFromAttributes(oldConnector);
+ removeConnectorTypeAttribute();
+ }
+ refresh();
+ }
+
+ protected void loadConnectors(Consumer<Connector[]> onSuccess) {
+ environment.getRequestService().execute(
+ connectorArrayMapper,
+ connectorResource::getConnectors,
+ 200,
+ onSuccess::accept,
+ ex -> handleRequestException(ex, environment)
+ );
+ }
+
+ protected Attribute getOrCreateConnectorTypeAttribute() {
+ if (attributes.hasAttribute(ASSET_ATTRIBUTE_CONNECTOR)) {
+ return attributes.get(ASSET_ATTRIBUTE_CONNECTOR);
+ } else {
+ Attribute attribute = new Attribute(ASSET_ATTRIBUTE_CONNECTOR, AttributeType.STRING);
+ attributes.put(attribute);
+ return attribute;
+ }
+ }
+
+ protected void removeConnectorTypeAttribute() {
+ attributes.remove(ASSET_ATTRIBUTE_CONNECTOR);
+ }
+
+ protected String getConnectorType() {
+ return getOrCreateConnectorTypeAttribute().getValueAsString();
+ }
+
+ protected void setConnectorType(String connectorType) {
+ getOrCreateConnectorTypeAttribute().setValue(connectorType);
+ }
+
+ protected Connector getConnector() {
+ Connector assignedConnector = null;
+ for (Connector connector : availableConnectors) {
+ if (connector.getType().equals(getConnectorType())) {
+ assignedConnector = connector;
+ break;
+ }
+ }
+ return assignedConnector;
+ }
+
+ protected void writeConnectorSettingsToAttributes(Connector connector) {
+ if (connector == null)
+ return;
+ for (Attribute setting : connector.getSettings().get()) {
+ Attribute attribute = attributes.get(setting.getName());
+ // If the connector setting still has the same type as the agent's attribute, only update metadata
+ if (attribute != null && attribute.getType().equals(setting.getType())) {
+ attribute.setMetadata(setting.getMetadata().copy());
+ } else {
+ // The agent does not have the connector setting or it's now a different type, replace/create attribute
+ attribute = new Attribute(setting.getName(), setting.getType());
+ attribute.setMetadata(setting.getMetadata().copy());
+ attributes.put(attribute);
+ }
+ }
+ }
+
+ protected void removeConnectorSettingsFromAttributes(Connector connector) {
+ if (connector == null)
+ return;
+ for (Attribute setting : connector.getSettings().get()) {
+ attributes.remove(setting.getName());
+ }
+ }
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/ConnectorArrayMapper.java b/manager/client/src/main/java/org/openremote/manager/client/assets/agent/ConnectorArrayMapper.java
similarity index 96%
rename from manager/client/src/main/java/org/openremote/manager/client/admin/agent/ConnectorArrayMapper.java
rename to manager/client/src/main/java/org/openremote/manager/client/assets/agent/ConnectorArrayMapper.java
index e8d26494b..a80912f62 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/ConnectorArrayMapper.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/agent/ConnectorArrayMapper.java
@@ -17,7 +17,7 @@
* 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.admin.agent;
+package org.openremote.manager.client.assets.agent;
import com.github.nmorel.gwtjackson.client.ObjectMapper;
import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
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/AssetActivity.java
index e9a068a9f..d397b7e2f 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/AssetActivity.java
@@ -21,18 +21,23 @@ package org.openremote.manager.client.assets.asset;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.assets.agent.ConnectorArrayMapper;
import org.openremote.manager.client.assets.AssetMapper;
import org.openremote.manager.client.assets.AssetsDashboardPlace;
import org.openremote.manager.client.assets.browser.AssetBrowser;
import org.openremote.manager.client.assets.browser.AssetBrowsingActivity;
+import org.openremote.manager.client.assets.agent.AgentAttributesEditor;
+import org.openremote.manager.client.assets.device.DeviceAttributesEditor;
import org.openremote.manager.client.assets.event.AssetsModifiedEvent;
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.widget.AttributesEditor;
import org.openremote.manager.shared.asset.Asset;
import org.openremote.manager.shared.asset.AssetResource;
import org.openremote.manager.shared.asset.AssetType;
import org.openremote.manager.shared.attribute.Attributes;
+import org.openremote.manager.shared.connector.ConnectorResource;
import org.openremote.manager.shared.event.ui.ShowInfoEvent;
import org.openremote.manager.shared.map.MapResource;
@@ -49,12 +54,17 @@ public class AssetActivity
private static final Logger LOG = Logger.getLogger(AssetActivity.class.getName());
- final MapResource mapResource;
- final JsonObjectMapper jsonObjectMapper;
+ final protected MapResource mapResource;
+ final protected JsonObjectMapper jsonObjectMapper;
+ final protected ConnectorArrayMapper connectorArrayMapper;
+ final protected ConnectorResource connectorResource;
+
+ protected boolean isCreateAsset;
protected double[] selectedCoordinates;
protected Asset parentAsset;
protected boolean isParentSelection;
+ protected AttributesEditor attributesEditor;
@Inject
public AssetActivity(Environment environment,
@@ -63,10 +73,14 @@ public class AssetActivity
AssetResource assetResource,
AssetMapper assetMapper,
MapResource mapResource,
- JsonObjectMapper jsonObjectMapper) {
+ JsonObjectMapper jsonObjectMapper,
+ ConnectorArrayMapper connectorArrayMapper,
+ ConnectorResource connectorResource) {
super(environment, view, assetBrowserPresenter, assetResource, assetMapper);
this.mapResource = mapResource;
this.jsonObjectMapper = jsonObjectMapper;
+ this.connectorArrayMapper = connectorArrayMapper;
+ this.connectorResource = connectorResource;
}
@Override
@@ -84,40 +98,46 @@ public class AssetActivity
} else {
view.refreshMap();
}
+
+ view.setAvailableTypes(AssetType.editable());
}
@Override
protected void startCreateAsset() {
super.startCreateAsset();
-
+ isCreateAsset = true;
view.setFormBusy(true);
-
asset = new Asset();
asset.setName("My New Asset");
- asset.setType(AssetType.GENERIC);
-
+ asset.setType(AssetType.CUSTOM);
writeToView();
clearViewFieldErrors();
view.clearFormMessages();
- setEditMode(true);
+ writeParentToView();
+ view.setTypeSelectionEnabled(true);
+ writeTypeToView();
+ writeAttributesEditorToView();
view.setFormBusy(false);
- writeParentAssetToView();
}
@Override
protected void onAssetLoaded() {
+ isCreateAsset = false;
writeToView();
clearViewFieldErrors();
view.clearFormMessages();
- setEditMode(false);
- view.setFormBusy(false);
+ view.setTypeSelectionEnabled(false);
+ writeTypeToView();
+ writeAttributesEditorToView();
if (asset.getParentId() != null) {
loadAsset(asset.getParentId(), loadedParentAsset -> {
this.parentAsset = loadedParentAsset;
- writeParentAssetToView();
+ writeParentToView();
+ view.setFormBusy(false);
});
} else {
- writeParentAssetToView();
+ writeParentToView();
+ view.setFormBusy(false);
}
}
@@ -135,7 +155,7 @@ public class AssetActivity
);
} else {
parentAsset = loadedParentAsset;
- writeParentAssetToView();
+ writeParentToView();
}
});
} else {
@@ -164,6 +184,13 @@ public class AssetActivity
view.setLocation(getLocation(selectedCoordinates));
}
+ @Override
+ public void onAssetTypeSelected(AssetType type) {
+ asset.setType(type);
+ writeTypeToView();
+ writeAttributesEditorToView();
+ }
+
@Override
public void update() {
view.setFormBusy(true);
@@ -264,7 +291,7 @@ public class AssetActivity
@Override
public void setRootParentSelection() {
this.parentAsset = null;
- writeParentAssetToView();
+ writeParentToView();
}
@Override
@@ -275,16 +302,23 @@ public class AssetActivity
if (asset.getParentId() != null) {
loadAsset(asset.getParentId(), loadedParentAsset -> {
this.parentAsset = loadedParentAsset;
- writeParentAssetToView();
+ writeParentToView();
});
}
}
+ @Override
+ public void centerMap() {
+ if (selectedCoordinates != null) {
+ view.flyTo(selectedCoordinates);
+ } else if (asset.getCoordinates() != null) {
+ view.flyTo(asset.getCoordinates());
+ }
+ }
+
protected void writeToView() {
view.setName(asset.getName());
- view.setType(asset.getType());
view.setCreatedOn(asset.getCreatedOn());
- view.setAttributes(new Attributes(asset.getAttributes()));
view.setLocation(getLocation(asset.getCoordinates()));
if (asset != null && asset.getId() != null) {
view.showFeaturesSelection(getFeature(asset));
@@ -292,21 +326,64 @@ public class AssetActivity
} else {
view.hideFeaturesSelection();
}
+ view.enableCreate(isCreateAsset);
+ view.enableUpdate(!isCreateAsset);
+ view.enableDelete(!isCreateAsset);
}
- protected void writeParentAssetToView() {
- view.setParentAsset(
+ protected void writeParentToView() {
+ view.setParent(
parentAsset != null ? parentAsset.getName() : environment.getMessages().assetHasNoParent()
);
}
+ protected void writeTypeToView() {
+ AssetType assetType = asset.getWellKnownType();
+ view.selectType(assetType);
+ view.setTypeInputVisible(AssetType.CUSTOM.equals(assetType));
+ view.setType(asset.getType());
+ }
+
+ protected void writeAttributesEditorToView() {
+ switch(asset.getWellKnownType()) {
+ case DEVICE:
+ attributesEditor = new DeviceAttributesEditor(
+ environment,
+ view.getAttributesEditorContainer(),
+ new Attributes(asset.getAttributes())
+ );
+ break;
+ case AGENT:
+ attributesEditor = new AgentAttributesEditor(
+ environment,
+ view.getAttributesEditorContainer(),
+ new Attributes(asset.getAttributes()),
+ connectorResource,
+ connectorArrayMapper
+ );
+ break;
+ default:
+ attributesEditor = new AttributesEditor(
+ environment,
+ view.getAttributesEditorContainer(),
+ new Attributes(asset.getAttributes())
+ );
+ }
+ view.setAttributesEditor(attributesEditor);
+ }
+
protected void readFromView() {
asset.setName(view.getName());
- asset.setType(view.getType());
+ if (AssetType.CUSTOM.equals(asset.getWellKnownType())) {
+ asset.setType(view.getType());
+ }
if (selectedCoordinates != null) {
asset.setCoordinates(selectedCoordinates);
}
asset.setParentId(parentAsset != null ? parentAsset.getId() : null);
+ asset.setAttributes(
+ attributesEditor != null ? attributesEditor.getAttributes().getJsonObject() : null
+ );
}
protected void clearViewFieldErrors() {
@@ -317,12 +394,7 @@ public class AssetActivity
if (coordinates != null && coordinates.length == 2) {
return coordinates[0] + " " + coordinates[1];
}
- return environment.getMessages().selectLocation();
+ return null;
}
- protected void setEditMode(boolean enableCreate) {
- view.enableCreate(enableCreate);
- view.enableUpdate(!enableCreate);
- view.enableDelete(!enableCreate);
- }
}
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 5748cfe44..edfac8bb4 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
@@ -19,9 +19,13 @@
*/
package org.openremote.manager.client.assets.asset;
+import com.google.gwt.user.client.ui.InsertPanel;
import elemental.json.JsonObject;
import org.openremote.manager.client.assets.browser.AssetBrowsingView;
+import org.openremote.manager.client.widget.AttributesEditor;
+import org.openremote.manager.client.widget.Form;
import org.openremote.manager.client.widget.FormView;
+import org.openremote.manager.shared.asset.AssetType;
import org.openremote.manager.shared.attribute.Attributes;
import org.openremote.manager.shared.map.GeoJSON;
@@ -31,14 +35,6 @@ public interface AssetView extends AssetBrowsingView<AssetView.Presenter>, FormV
interface Presenter extends AssetBrowsingView.Presenter {
- void onMapClicked(double lng, double lat);
-
- void update();
-
- void create();
-
- void delete();
-
void beginParentSelection();
void confirmParentSelection();
@@ -47,6 +43,18 @@ public interface AssetView extends AssetBrowsingView<AssetView.Presenter>, FormV
void resetParentSelection();
+ void centerMap();
+
+ void onMapClicked(double lng, double lat);
+
+ void onAssetTypeSelected(AssetType value);
+
+ void update();
+
+ void create();
+
+ void delete();
+
}
void setName(String name);
@@ -55,22 +63,16 @@ public interface AssetView extends AssetBrowsingView<AssetView.Presenter>, FormV
void setCreatedOn(Date createdOn);
- void setType(String type);
-
- String getType();
-
- void setLocation(String location);
-
- void setParentAsset(String name);
+ void setParent(String name);
void setParentSelection(boolean isSelecting);
- void setAttributes(Attributes attributes);
-
void initialiseMap(JsonObject mapOptions);
boolean isMapInitialised();
+ void setLocation(String location);
+
void refreshMap();
void showMapPopup(double lng, double lat, String text);
@@ -83,6 +85,22 @@ public interface AssetView extends AssetBrowsingView<AssetView.Presenter>, FormV
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();
+
+ AttributesEditor.Container getAttributesEditorContainer();
+
+ void setAttributesEditor(AttributesEditor attributesEditor);
+
void enableCreate(boolean enable);
void enableUpdate(boolean enable);
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 611992592..23bd8a0c3 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,6 +23,7 @@ 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;
@@ -33,28 +34,31 @@ import org.openremote.manager.client.app.dialog.ConfirmationDialog;
import org.openremote.manager.client.assets.browser.AssetBrowser;
import org.openremote.manager.client.widget.*;
import org.openremote.manager.client.widget.PushButton;
-import org.openremote.manager.shared.attribute.Attributes;
+import org.openremote.manager.shared.asset.AssetType;
import org.openremote.manager.shared.map.GeoJSON;
import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
+import java.util.logging.Logger;
-public class AssetViewImpl extends AttributesFormViewImpl implements AssetView {
+public class AssetViewImpl extends FormViewImpl implements AssetView {
+
+ private static final Logger LOG = Logger.getLogger(AssetViewImpl.class.getName());
interface UI extends UiBinder<FlexSplitPanel, AssetViewImpl> {
}
- interface Style extends CssResource, AttributesFormStyle{
+ interface Style extends CssResource, AttributesEditor.Style {
String navItem();
String formMessages();
- String nameTextBox();
-
String mapWidget();
- String typeTextBox();
+ String typeInput();
String attributeIntegerEditor();
@@ -74,6 +78,8 @@ public class AssetViewImpl extends AttributesFormViewImpl implements AssetView {
@UiField
HTMLPanel sidebarContainer;
+ /* ############################################################################ */
+
@UiField
FormGroup nameGroup;
@UiField
@@ -83,57 +89,85 @@ public class AssetViewImpl extends AttributesFormViewImpl implements AssetView {
FormGroup createdOnGroup;
@UiField
Label createdOnLabel;
+ @UiField
+ FormButton showHistoryButton;
@UiField
- FormGroup typeGroup;
+ TextBox parentLabel;
+ @UiField
+ PushButton selectParentButton;
+ @UiField
+ PushButton setRootParentSelectionButton;
+ @UiField
+ PushButton confirmParentSelectionButton;
@UiField
- TextBox typeInput;
+ PushButton resetParentSelectionButton;
+ @UiField
+ Label selectParentInfoLabel;
@UiField
FormGroup locationGroup;
@UiField
Label locationLabel;
-
@UiField
- TextBox parentAssetLabel;
+ FormButton centerMapButton;
+ @UiField
+ MapWidget mapWidget;
+
+ /* ############################################################################ */
@UiField
- PushButton selectParentButton;
+ Form attributesForm;
@UiField
- PushButton setRootParentSelectionButton;
+ FormGroup typeGroup;
+ @UiField(provided = true)
+ FormDropDown<AssetType> typeDropDown;
@UiField
- PushButton confirmParentSelectionButton;
+ FormInputText typeInput;
@UiField
- PushButton resetParentSelectionButton;
+ Label customTypeInfoLabel;
@UiField
- Label selectParentInfoLabel;
+ FlowPanel attributesEditorContainer;
- @UiField
- FlowPanel attributesContainer;
+ /* ############################################################################ */
+ @UiField
+ Form submitForm;
@UiField
FormGroup submitButtonGroup;
-
@UiField
PushButton createButton;
-
@UiField
PushButton updateButton;
-
@UiField
PushButton deleteButton;
- @UiField
- MapWidget mapWidget;
-
final AssetBrowser assetBrowser;
Presenter presenter;
- FormGroup[] attributeFormGroups = new FormGroup[0];
+ AttributesEditor attributesEditor;
@Inject
public AssetViewImpl(AssetBrowser assetBrowser, Provider<ConfirmationDialog> confirmationDialogProvider) {
super(confirmationDialogProvider);
this.assetBrowser = assetBrowser;
+
+ typeDropDown = new FormDropDown<>(
+ new AbstractRenderer<AssetType>() {
+ @Override
+ public String render(AssetType assetType) {
+ if (assetType == null)
+ return managerMessages.noTypeSelected();
+ return managerMessages.assetTypeLabel(assetType.name());
+ }
+ }
+ );
+
+ typeDropDown.addValueChangeHandler(event -> {
+ if (presenter != null) {
+ presenter.onAssetTypeSelected(event.getValue());
+ }
+ });
+
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
@@ -143,38 +177,45 @@ public class AssetViewImpl extends AttributesFormViewImpl implements AssetView {
@Override
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
+
+ // Restore initial state of view
+ sidebarContainer.clear();
+ nameInput.setValue(null);
+ createdOnLabel.setText("");
+ parentLabel.setText("");
+ selectParentButton.setVisible(true);
+ confirmParentSelectionButton.setVisible(false);
+ resetParentSelectionButton.setVisible(false);
+ setRootParentSelectionButton.setVisible(false);
+ selectParentInfoLabel.setVisible(false);
+ locationLabel.setText("");
+ centerMapButton.setEnabled(false);
+ typeDropDown.setValue(null);
+ typeDropDown.setAcceptableValues(new ArrayList<>());
+ typeDropDown.setEnabled(true);
+ typeInput.setVisible(false);
+ customTypeInfoLabel.setVisible(false);
+ hideFeaturesSelection();
+ hideMapPopup();
+ setOpaque(false);
+ attributesEditorContainer.clear();
+ attributesEditor = null;
+
if (presenter != null) {
assetBrowser.asWidget().removeFromParent();
sidebarContainer.add(assetBrowser.asWidget());
- } else {
- sidebarContainer.clear();
- nameInput.setValue(null);
- typeInput.setValue(null);
- createdOnLabel.setText("");
- locationLabel.setText("");
- parentAssetLabel.setText("");
- hideFeaturesSelection();
- hideMapPopup();
- selectParentButton.setVisible(true);
- confirmParentSelectionButton.setVisible(false);
- resetParentSelectionButton.setVisible(false);
- setRootParentSelectionButton.setVisible(false);
- selectParentInfoLabel.setVisible(false);
- createButton.setEnabled(true);
- updateButton.setEnabled(true);
- deleteButton.setEnabled(true);
- nameGroup.setOpaque(true);
- createdOnGroup.setOpaque(true);
- typeGroup.setOpaque(true);
- locationGroup.setOpaque(true);
- submitButtonGroup.setOpaque(true);
- mapWidget.setOpaque(true);
- for (FormGroup attributeFormGroup : attributeFormGroups) {
- attributeFormGroup.setOpaque(true);
- }
}
}
+ @Override
+ public void setFormBusy(boolean busy) {
+ super.setFormBusy(busy);
+ attributesForm.setBusy(busy);
+ submitForm.setBusy(busy);
+ }
+
+ /* ############################################################################ */
+
@Override
public void setName(String name) {
nameInput.setValue(name);
@@ -193,27 +234,8 @@ public class AssetViewImpl extends AttributesFormViewImpl implements AssetView {
}
@Override
- public void setType(String type) {
- typeInput.setValue(type);
- }
-
- @Override
- public String getType() {
- return typeInput.getValue().length() > 0 ? typeInput.getValue() : null;
- }
-
- @Override
- public void setLocation(String location) {
- locationLabel.setText(
- location != null ? location : "-"
- );
- }
-
- @Override
- public void setParentAsset(String name) {
- parentAssetLabel.setText(
- name != null ? name : "-"
- );
+ public void setParent(String name) {
+ parentLabel.setText(name != null ? name : "");
}
@Override
@@ -223,39 +245,13 @@ public class AssetViewImpl extends AttributesFormViewImpl implements AssetView {
resetParentSelectionButton.setVisible(isSelecting);
setRootParentSelectionButton.setVisible(isSelecting);
selectParentInfoLabel.setVisible(isSelecting);
- nameGroup.setOpaque(!isSelecting);
- createdOnGroup.setOpaque(!isSelecting);
- typeGroup.setOpaque(!isSelecting);
- locationGroup.setOpaque(!isSelecting);
- submitButtonGroup.setOpaque(!isSelecting);
- mapWidget.setOpaque(!isSelecting);
- for (FormGroup attributeFormGroup : attributeFormGroups) {
- attributeFormGroup.setOpaque(!isSelecting);
- }
+ setOpaque(isSelecting);
}
@Override
- public void setAttributes(Attributes attributes) {
- attributesContainer.clear();
- attributeFormGroups = createAttributeFormGroups(style, attributes);
- for (FormGroup attributeFormGroup : attributeFormGroups) {
- attributesContainer.add(attributeFormGroup);
- }
- }
-
- @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);
+ public void setLocation(String location) {
+ locationLabel.setText(location != null ? location : managerMessages.selectLocation());
+ centerMapButton.setEnabled(location != null);
}
@Override
@@ -303,24 +299,6 @@ public class AssetViewImpl extends AttributesFormViewImpl implements AssetView {
mapWidget.flyTo(coordinates);
}
- @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();
- }
-
@UiHandler("selectParentButton")
void selectParentClicked(ClickEvent e) {
if (presenter != null)
@@ -344,4 +322,118 @@ public class AssetViewImpl extends AttributesFormViewImpl implements AssetView {
if (presenter != null)
presenter.resetParentSelection();
}
+
+ @UiHandler("centerMapButton")
+ void centerMapClicked(ClickEvent e) {
+ if (presenter != null)
+ presenter.centerMap();
+ }
+
+ /* ############################################################################ */
+
+ @Override
+ public void setTypeSelectionEnabled(boolean enabled) {
+ typeDropDown.setEnabled(enabled);
+ }
+
+ @Override
+ public void setAvailableTypes(AssetType[] assetTypes) {
+ typeDropDown.setAcceptableValues(Arrays.asList(assetTypes));
+ }
+
+ @Override
+ public void selectType(AssetType assetType) {
+ typeDropDown.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 AttributesEditor.Container getAttributesEditorContainer() {
+ return new AttributesEditor.Container() {
+ @Override
+ public FormView getFormView() {
+ return AssetViewImpl.this;
+ }
+
+ @Override
+ public AttributesEditor.Style getStyle() {
+ return style;
+ }
+
+ @Override
+ public InsertPanel getPanel() {
+ return attributesEditorContainer;
+ }
+ };
+ }
+
+ @Override
+ public void setAttributesEditor(AttributesEditor editor) {
+ this.attributesEditor = editor;
+ attributesEditorContainer.clear();
+ editor.render();
+ }
+
+ /* ############################################################################ */
+
+ @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);
+ }
}
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 6c53aabdd..b0d3ea7af 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
@@ -14,23 +14,22 @@
max-width: 30em;
}
- .nameTextBox,
- .typeTextBox {
- width: 100%;
+ .typeInput {
+ width: 30em;
}
.mapWidget {
margin-left: 2em;
width: 44%;
- height: 24em;
+ height: 13em;
}
.attributeStringEditor {
- width: 100%;
+ width: 26em;
}
.attributeIntegerEditor {
- width: 10em;
+ width: 5em;
}
.attributeFloatEditor {
@@ -72,145 +71,161 @@
</g:HTMLPanel>
- <div class="flex {widgetStyle.MainContent}">
-
- <g:HTMLPanel styleName="flex layout horizontal">
-
- <g:HTMLPanel styleName="flex layout vertical">
-
- <g:FlowPanel
- styleName="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="layout horizontal {style.formMessages} {widgetStyle.FormMessages} error"
- visible="false">
- <w:IconLabel icon="warning"
- addStyleNames="{widgetStyle.MessagesIcon}"/>
- <g:FlowPanel ui:field="formMessagesError"/>
- </g:FlowPanel>
-
- <div class="{widgetStyle.Headline1}">
- <g:InlineLabel text="{managerMessages.editAsset}"/>
- </div>
-
- <div class="{widgetStyle.HeadlineSub}">
- <span class="required">*</span>
- <g:InlineLabel text="{managerMessages.requiredFields}"/>
- </div>
-
- <w:Form ui:field="form" addStyleNames="flex">
- <w:FormGroup ui:field="nameGroup">
- <w:label>
- <w:FormLabel text="{managerMessages.assetName}" required="true"/>
- </w:label>
- <w:field>
- <w:FormField addStyleNames="larger">
- <w:FormInputText ui:field="nameInput" addStyleNames="{style.nameTextBox}"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
-
- <w:FormGroup ui:field="createdOnGroup">
- <w:label>
- <w:FormLabel text="{managerMessages.createdOn}"/>
- </w:label>
- <w:field>
- <w:FormField>
+ <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 center">
+ <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>
+ <g:FlowPanel styleName="flex layout horizontal center">
<g:Label ui:field="createdOnLabel"
- addStyleNames="{widgetStyle.FormControl} {widgetStyle.FormValueLabel}"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
-
- <w:FormGroup>
- <w:label>
- <w:FormLabel text="{managerMessages.parentAsset}"/>
- </w:label>
- <w:field>
- <w:FormField addStyleNames="larger">
- <g:FlowPanel styleName="layout horizontal center">
- <w:FormInputText ui:field="parentAssetLabel" readOnly="true"
- addStyleNames="{style.typeTextBox}"/>
- <w:FormButton ui:field="selectParentButton"
- text="{managerMessages.selectParentAsset}"
- icon="external-link-square"/>
- <w:FormButton ui:field="setRootParentSelectionButton" visible="false"
- text="{managerMessages.setRootParentAsset}"
- icon="minus-square"/>
- <w:FormButton ui:field="confirmParentSelectionButton" primary="true"
- visible="false" text="{managerMessages.OK}" icon="check"/>
- <w:FormButton ui:field="resetParentSelectionButton" visible="false"
- text="{managerMessages.reset}" icon="undo"/>
- </g:FlowPanel>
- </w:FormField>
- </w:field>
- <w:info>
- <g:Label ui:field="selectParentInfoLabel"
- visible="false"
- text="{managerMessages.selectParentInAssetTree}"/>
- </w:info>
- </w:FormGroup>
-
- <w:FormGroup ui:field="typeGroup">
- <w:label>
- <w:FormLabel text="{managerMessages.assetType}" required="true"/>
- </w:label>
- <w:field>
- <w:FormField addStyleNames="larger">
- <w:FormInputText ui:field="typeInput" readOnly="true"
- addStyleNames="{style.typeTextBox}"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
-
- <w:FormGroup ui:field="locationGroup">
- <w:label>
- <w:FormLabel text="{managerMessages.location}"/>
- </w:label>
- <w:field>
- <w:FormField>
+ addStyleNames="flex {widgetStyle.FormControl} {widgetStyle.FormValueLabel}"/>
+ <w:FormButton ui:field="showHistoryButton"
+ text="{managerMessages.showHistory}"
+ enabled="false"
+ icon="history"/>
+ </g:FlowPanel>
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
+
+ <w:FormGroup>
+ <w:label>
+ <w:FormLabel text="{managerMessages.parentAsset}"/>
+ </w:label>
+ <w:field>
+ <w:FormField addStyleNames="larger">
+ <g:FlowPanel styleName="flex layout horizontal center">
+ <w:FormInputText ui:field="parentLabel" readOnly="true"
+ addStyleNames="flex"/>
+ <w:FormButton ui:field="selectParentButton"
+ text="{managerMessages.selectParentAsset}"
+ icon="external-link-square"/>
+ <w:FormButton ui:field="setRootParentSelectionButton" visible="false"
+ text="{managerMessages.setRootParentAsset}"
+ icon="minus-square"/>
+ <w:FormButton ui:field="resetParentSelectionButton" visible="false"
+ text="{managerMessages.reset}" icon="undo"/>
+ <w:FormButton ui:field="confirmParentSelectionButton" primary="true"
+ visible="false" text="{managerMessages.OK}" icon="check"/>
+ </g:FlowPanel>
+ </w:FormField>
+ </w:field>
+ <w:info>
+ <g:Label ui:field="selectParentInfoLabel"
+ visible="false"
+ text="{managerMessages.selectParentInAssetTree}"/>
+ </w:info>
+ </w:FormGroup>
+
+ <w:FormGroup ui:field="locationGroup">
+ <w:label>
+ <w:FormLabel text="{managerMessages.location}"/>
+ </w:label>
+ <w:field>
+ <w:FormField>
+ <g:FlowPanel styleName="flex layout horizontal center">
<g:Label ui:field="locationLabel"
- addStyleNames="{widgetStyle.FormControl} {widgetStyle.FormValueLabel}"/>
- </w:FormField>
- </w:field>
- </w:FormGroup>
-
- <g:FlowPanel ui:field="attributesContainer"/>
-
- <w:FormGroup ui:field="submitButtonGroup" centerJustified="true">
- <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>
-
+ addStyleNames="flex {widgetStyle.FormControl} {widgetStyle.FormValueLabel}"/>
+ <w:FormButton ui:field="centerMapButton"
+ enabled="false"
+ text="{managerMessages.centerMap}"
+ icon="location-arrow"/>
+ </g:FlowPanel>
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
+ </w:Form>
<w:MapWidget ui:field="mapWidget"
addStyleNames="{style.mapWidget} {widgetStyle.ItemWithBorder}"/>
+ </g:HTMLPanel>
+
+ <div class="{widgetStyle.Divider}"/>
+
+ <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="layout horizontal center">
+ <w:FormDropDown ui:field="typeDropDown"/>
+ <w:FormInputText ui:field="typeInput" addStyleNames="{style.typeInput}"
+ 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" centerJustified="true">
+ <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>
+ </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/browser/AssetBrowserImpl.java b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.java
index 36a76a255..145c01236 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.java
@@ -30,6 +30,7 @@ import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextBox;
import org.openremote.manager.client.i18n.ManagerMessages;
import org.openremote.manager.client.style.FormTreeStyle;
+import org.openremote.manager.client.widget.FormInputText;
import org.openremote.manager.client.widget.PushButton;
import org.openremote.manager.shared.asset.AssetInfo;
@@ -52,11 +53,14 @@ public class AssetBrowserImpl extends Composite implements AssetBrowser {
SimplePanel assetTreeContainer;
@UiField
- TextBox searchInput;
+ FormInputText searchInput;
@UiField
PushButton filterButton;
+ @UiField
+ PushButton sortButton;
+
final FormTreeStyle formTreeStyle;
Presenter presenter;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.ui.xml
index 9a9d75825..d5f4a4019 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserImpl.ui.xml
@@ -10,19 +10,20 @@
}
.navItem {
- margin-right: 1.2em;
+ margin-right: 0.8em;
}
.navItemFirst {
margin-left: 0.2em !important;
+ margin-right: 0.8em !important;
}
.searchInput {
border-radius: 0.4em;
font-size: smaller !important;
padding: 0.4em !important;
- width: 75%;
height: 0.8em;
+ min-width: 7em;
}
.assetTreeContainer {
@@ -36,18 +37,21 @@
<g:HTMLPanel
styleName="layout horizontal center {widgetStyle.SecondaryNavHorizontal}">
- <div class="flex">
- <w:FormInputText ui:field="searchInput"
- addStyleNames="{style.navItemFirst} {style.searchInput} {widgetStyle.FormControl} {widgetStyle.FormInputText}"
- autofocus="true"
- placeholder="{managerMessages.search}..."/>
- </div>
+ <w:FormInputText ui:field="searchInput"
+ addStyleNames="flex {style.navItemFirst} {style.searchInput}"
+ autofocus="true"
+ placeholder="{managerMessages.search}..."/>
<w:PushButton ui:field="filterButton"
addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
text="{managerMessages.filter}"
icon="filter"/>
+ <w:PushButton ui:field="sortButton"
+ addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
+ text="{managerMessages.sort}"
+ icon="sort"/>
+
</g:HTMLPanel>
<g:SimplePanel ui:field="assetTreeContainer" addStyleNames="{style.assetTreeContainer}"/>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetCell.java b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetCell.java
index c74325a14..0cf0c3415 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetCell.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetCell.java
@@ -28,12 +28,13 @@ import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.text.shared.SafeHtmlRenderer;
import org.openremote.manager.client.util.TextUtil;
import org.openremote.manager.shared.asset.AssetInfo;
+import org.openremote.manager.shared.asset.AssetType;
class AssetCell extends AbstractSafeHtmlCell<AssetInfo> {
public interface AssetTemplates extends SafeHtmlTemplates {
- @Template("<div id=\"asset-{0}\">{1}</div>")
- SafeHtml assetItem(String assetId, String name);
+ @Template("<div id=\"asset-{0}\"><span class=\"or-FormTreeIcon fa fa-{2}\"></span>{1}</div>")
+ SafeHtml assetItem(String assetId, String name, String icon);
}
private static final AssetTemplates TEMPLATES = GWT.create(AssetTemplates.class);
@@ -59,8 +60,9 @@ class AssetCell extends AbstractSafeHtmlCell<AssetInfo> {
public void render(AssetInfo asset, SafeHtmlBuilder appendable) {
appendable.append(TEMPLATES.assetItem(
asset.getId(),
- TextUtil.ellipsize(asset.getName(), maxNameLength))
- );
+ TextUtil.ellipsize(asset.getName(), maxNameLength),
+ getIcon(asset.getWellKnownType())
+ ));
}
}
@@ -74,6 +76,21 @@ class AssetCell extends AbstractSafeHtmlCell<AssetInfo> {
sb.append(value);
}
}
+
+ static protected String getIcon(AssetType assetType) {
+ switch (assetType) {
+ case BUILDING:
+ return "building";
+ case FLOOR:
+ return "server";
+ case AGENT:
+ return "cubes";
+ case DEVICE:
+ return "gear";
+ default:
+ return "cube";
+ }
+ }
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/device/DeviceAttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/device/DeviceAttributesEditor.java
new file mode 100644
index 000000000..71eef42be
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/device/DeviceAttributesEditor.java
@@ -0,0 +1,66 @@
+/*
+ * 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.device;
+
+import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.widget.*;
+import org.openremote.manager.shared.asset.AssetAttributeType;
+import org.openremote.manager.shared.attribute.Attribute;
+import org.openremote.manager.shared.attribute.Attributes;
+
+public class DeviceAttributesEditor extends AttributesEditor {
+
+ public DeviceAttributesEditor(Environment environment, Container container, Attributes attributes) {
+ super(environment, container, attributes);
+ }
+
+ @Override
+ protected FormLabel buildFormLabel(Attribute attribute) {
+ FormLabel formLabel = super.buildFormLabel(attribute);
+
+ if (AssetAttributeType.isSensor(attribute)) {
+ formLabel.setIcon("sign-out");
+ } else if (AssetAttributeType.isActuator(attribute)) {
+ formLabel.setIcon("sign-in");
+ }
+
+ return formLabel;
+ }
+
+ @Override
+ protected FormInputText createStringEditor(Style style, Attribute attribute, boolean readOnly) {
+ return super.createStringEditor(style, attribute, AssetAttributeType.isSensor(attribute));
+ }
+
+ @Override
+ protected FormInputNumber createIntegerEditor(Style style, Attribute attribute, boolean readOnly) {
+ return super.createIntegerEditor(style, attribute, AssetAttributeType.isSensor(attribute));
+ }
+
+ @Override
+ protected FormInputText createFloatEditor(Style style, Attribute attribute, boolean readOnly) {
+ return super.createFloatEditor(style, attribute, AssetAttributeType.isSensor(attribute));
+ }
+
+ @Override
+ protected FormCheckBox createBooleanEditor(Style style, Attribute attribute, boolean readOnly) {
+ return super.createBooleanEditor(style, attribute, AssetAttributeType.isSensor(attribute));
+ }
+}
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 9b0ef3c70..aee2fb7e4 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
@@ -147,21 +147,7 @@ public interface ManagerMessages extends Messages {
String emptyAsset();
- String agentName();
-
- String connectorType();
-
- String configureAgents();
-
- String newAgent();
-
- String editAgent();
-
- String updateAgent();
-
- String createAgent();
-
- String deleteAgent();
+ String connector();
String description();
@@ -169,20 +155,12 @@ public interface ManagerMessages extends Messages {
String connectorNotInstalled();
- String agentUpdated(String name);
-
- String agentCreated(String name);
-
- String agentDeleted(String name);
-
String unsupportedAttributeType(String name);
String loadingAssets();
String assetName();
- String editAsset();
-
String updateAsset();
String createAsset();
@@ -226,4 +204,16 @@ public interface ManagerMessages extends Messages {
String reset();
String invalidAssetParent();
+
+ String centerMap();
+
+ String showHistory();
+
+ String sort();
+
+ String assetTypeLabel(@Select String name);
+
+ String noTypeSelected();
+
+ String enterCustomAssetType();
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.java b/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.java
index b6f107dcc..bb826ee79 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.java
@@ -69,6 +69,10 @@ public class WidgetStyle {
return "or-UnorderedList";
}
+ public String Divider() {
+ return "or-Divider";
+ }
+
public String Toast() {
return "or-Toast";
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesEditor.java
new file mode 100644
index 000000000..750f1c0ec
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesEditor.java
@@ -0,0 +1,319 @@
+/*
+ * 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.widget;
+
+import com.google.gwt.user.client.ui.InsertPanel;
+import com.google.gwt.user.client.ui.Label;
+import elemental.json.Json;
+import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.util.TextUtil;
+import org.openremote.manager.shared.attribute.Attribute;
+import org.openremote.manager.shared.attribute.AttributeType;
+import org.openremote.manager.shared.attribute.Attributes;
+import org.openremote.manager.shared.attribute.MetadataElement;
+
+import java.util.*;
+import java.util.logging.Logger;
+
+public class AttributesEditor {
+
+ private static final Logger LOG = Logger.getLogger(AttributesEditor.class.getName());
+
+ public interface Container {
+ FormView getFormView();
+
+ Style getStyle();
+
+ InsertPanel getPanel();
+ }
+
+ public interface Style {
+
+ String attributeStringEditor();
+
+ String attributeIntegerEditor();
+
+ String attributeFloatEditor();
+
+ String attributeBooleanEditor();
+ }
+
+ final protected Environment environment;
+ final protected Container container;
+ final protected Attributes attributes;
+ final protected Map<Attribute, FormGroup> formGroups = new LinkedHashMap<>();
+
+ public AttributesEditor(Environment environment, Container container, Attributes attributes) {
+ this.environment = environment;
+ this.container = container;
+ this.attributes = attributes;
+
+ buildAttributeFormGroups();
+ }
+
+ public Attributes getAttributes() {
+ return attributes;
+ }
+
+ public void buildAttributeFormGroups() {
+ if (attributes == null) {
+ formGroups.clear();
+ return;
+ }
+ List<Attribute> attributeList = Arrays.asList(attributes.get());
+ Collections.sort(attributeList, (o1, o2) -> o1.getName().compareTo(o2.getName()));
+ for (Attribute attribute : attributeList) {
+ LOG.fine("Building form group for attribute: " + attribute.getName());
+ FormGroup formGroup = createFormGroup(attribute);
+ if (formGroup != null) {
+ formGroups.put(attribute, formGroup);
+ }
+ }
+ }
+
+ /* TODO Finish attribute add/remove, metadata editing
+
+ public void buildActionsFormGroup() {
+ FormGroup formGroup = new FormGroup();
+ FormButton addButton = new FormButton();
+ FormInputText newAttributeNameInput =new FormInputText();
+ addButton.addClickHandler(event -> {
+ if (newAttributeNameInput.getValue() != null) {
+ String attributeName = newAttributeNameInput.getValue();
+ if (!attributes.hasAttribute(attributeName)) {
+ Attribute newAttribute = new Attribute(attributeName, AttributeType.STRING);
+ attributes.add(newAttribute);
+ FormGroup newAttributeFormGroup = createFormGroup(newAttribute);
+ formGroups.add(newAttributeFormGroup);
+ container.add(newAttributeFormGroup);
+ }
+ }
+ });
+ }
+ */
+
+ public void render() {
+ for (FormGroup formGroup : formGroups.values()) {
+ container.getPanel().add(formGroup);
+ }
+ }
+
+ public void refresh() {
+ formGroups.clear();
+ buildAttributeFormGroups();
+ clearContainer();
+ render();
+ }
+
+ public void setOpaque(boolean opaque) {
+ for (FormGroup formGroup : formGroups.values()) {
+ formGroup.setOpaque(opaque);
+ }
+ }
+
+ /* ####################################################################### */
+
+ protected void clearContainer() {
+ while(container.getPanel().getWidgetCount() > 0) {
+ container.getPanel().remove(0);
+ }
+ }
+
+ protected FormGroup createFormGroup(Attribute attribute) {
+
+ FormGroup formGroup = new FormGroup();
+
+ FormLabel formLabel = buildFormLabel(attribute);
+ formGroup.addFormLabel(formLabel);
+
+ FormField attributeField = new FormField();
+ formGroup.addFormField(attributeField);
+
+ if (attribute.getType().equals(AttributeType.STRING)) {
+ formGroup.getFormField().add(createStringEditor(container.getStyle(), attribute, false));
+ } else if (attribute.getType().equals(AttributeType.INTEGER)) {
+ formGroup.getFormField().add(createIntegerEditor(container.getStyle(), attribute, false));
+ } else if (attribute.getType().equals(AttributeType.FLOAT)) {
+ formGroup.getFormField().add(createFloatEditor(container.getStyle(), attribute, false));
+ } else if (attribute.getType().equals(AttributeType.BOOLEAN)) {
+ formGroup.getFormField().add(createBooleanEditor(container.getStyle(), attribute, false));
+ } else {
+ formGroup.getFormField().add(
+ new Label(environment.getMessages().unsupportedAttributeType(attribute.getType().getValue()))
+ );
+ }
+
+ String description = getDescription(attribute);
+ if (description != null) {
+ formGroup.addInfolabel(new Label(description));
+ }
+
+ return formGroup;
+ }
+
+ protected FormLabel buildFormLabel(Attribute attribute) {
+ FormLabel formLabel = new FormLabel();
+ String label = attribute.getName();
+ if (attribute.hasMetadataElement("label")) {
+ MetadataElement metadataLabel = attribute.getMetadata().getElement("label");
+ if (metadataLabel.getType().equals(AttributeType.STRING.getValue())) {
+ label = metadataLabel.getValue().asString();
+ }
+ }
+ formLabel.setText(TextUtil.ellipsize(label, 30));
+ formLabel.addStyleName("larger");
+
+ return formLabel;
+ }
+
+ /* ####################################################################### */
+
+ protected FormInputText createStringEditor(Style style, Attribute attribute, boolean readOnly) {
+ FormInputText input = createFormInputText(style.attributeStringEditor());
+
+ MetadataElement defaultValue;
+ if (attribute.getValue() != null) {
+ input.setValue(attribute.getValue().asString());
+ } else if ((defaultValue = getDefaultValue(attribute)) != null) {
+ input.setValue(defaultValue.getValue().asString());
+ }
+
+ if (readOnly) {
+ input.setReadOnly(true);
+ } else {
+ input.addValueChangeHandler(
+ event -> attribute.setValue(
+ Json.create(event.getValue())
+ )
+ );
+ }
+ return input;
+ }
+
+ protected FormInputNumber createIntegerEditor(Style style, Attribute attribute, boolean readOnly) {
+ FormInputNumber input = createFormInputNumber(style.attributeIntegerEditor());
+
+ MetadataElement defaultValue;
+ if (attribute.getValue() != null) {
+ input.setValue(attribute.getValue().asString());
+ } else if ((defaultValue = getDefaultValue(attribute)) != null) {
+ input.setValue(defaultValue.getValue().asString());
+ }
+
+ if (readOnly) {
+ input.setReadOnly(true);
+ } else {
+ input.addValueChangeHandler(event -> {
+ try {
+ Integer value = Integer.valueOf(event.getValue());
+ attribute.setValue(Json.create(value));
+ } catch (NumberFormatException ex) {
+ // TODO Do nothing? can we hook this up into validation?
+ }
+ });
+ }
+ return input;
+ }
+
+ protected FormInputText createFloatEditor(Style style, Attribute attribute, boolean readOnly) {
+ FormInputText input = createFormInputText(style.attributeFloatEditor());
+
+ MetadataElement defaultValue;
+ if (attribute.getValue() != null) {
+ input.setValue(attribute.getValue().asString());
+ } else if ((defaultValue = getDefaultValue(attribute)) != null) {
+ input.setValue(defaultValue.getValue().asString());
+ }
+
+ if (readOnly) {
+ input.setReadOnly(true);
+ } else {
+ input.addValueChangeHandler(event -> {
+ try {
+ Double value = Double.valueOf(event.getValue());
+ attribute.setValue(Json.create(value));
+ } catch (NumberFormatException ex) {
+ // TODO Do nothing? can we hook this up into validation?
+ }
+ });
+ }
+ return input;
+ }
+
+ protected FormCheckBox createBooleanEditor(Style style, Attribute attribute, boolean readOnly) {
+ FormCheckBox input = createFormInputCheckBox(style.attributeBooleanEditor());
+
+ MetadataElement defaultValue;
+ if (attribute.getValue() != null) {
+ boolean value = attribute.getValue().asBoolean();
+ input.setValue(value);
+ } else if ((defaultValue = getDefaultValue(attribute)) != null) {
+ input.setValue(defaultValue.getValue().asBoolean());
+ }
+
+ if (readOnly) {
+ input.setEnabled(false);
+ } else {
+ input.addValueChangeHandler(event -> {
+ attribute.setValue(Json.create(input.getValue()));
+ });
+ }
+ 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 String getDescription(Attribute attribute) {
+ if (attribute.hasMetadataElement("description")) {
+ MetadataElement metadataDescription = attribute.getMetadata().getElement("description");
+ if (metadataDescription.getType().equals(AttributeType.STRING.getValue())) {
+ return metadataDescription.getValue().asString();
+ }
+ }
+ return null;
+ }
+
+ protected MetadataElement getDefaultValue(Attribute attribute) {
+ if (attribute.hasMetadataElement("defaultValue")) {
+ return attribute.getMetadata().getElement("defaultValue");
+ }
+ return null;
+ }
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesFormViewImpl.java b/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesFormViewImpl.java
deleted file mode 100644
index 6fa975de4..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesFormViewImpl.java
+++ /dev/null
@@ -1,223 +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.widget;
-
-import com.google.gwt.user.client.ui.Label;
-import com.google.inject.Provider;
-import elemental.json.Json;
-import org.openremote.manager.client.app.dialog.ConfirmationDialog;
-import org.openremote.manager.client.util.TextUtil;
-import org.openremote.manager.shared.asset.AssetAttributeType;
-import org.openremote.manager.shared.attribute.Attribute;
-import org.openremote.manager.shared.attribute.AttributeType;
-import org.openremote.manager.shared.attribute.Attributes;
-import org.openremote.manager.shared.attribute.MetadataElement;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.logging.Logger;
-
-public class AttributesFormViewImpl extends FormViewImpl {
-
- private static final Logger LOG = Logger.getLogger(AttributesFormViewImpl.class.getName());
-
- public AttributesFormViewImpl(Provider<ConfirmationDialog> confirmationDialogProvider) {
- super(confirmationDialogProvider);
- }
-
- public FormGroup[] createAttributeFormGroups(AttributesFormStyle style, Attributes attributes) {
- if (attributes == null)
- return new FormGroup[0];
- List<FormGroup> list = new ArrayList<>();
- List<Attribute> attributeList = Arrays.asList(attributes.get());
- Collections.sort(attributeList, (o1, o2) -> o1.getName().compareTo(o2.getName()));
- for (Attribute attribute : attributeList) {
-
- FormGroup formGroup = createAttributeFormGroup(attribute);
-
- if (attribute.getType().equals(AttributeType.STRING)) {
- formGroup.getFormField().add(createStringEditor(style, attribute));
- } else if (attribute.getType().equals(AttributeType.INTEGER)) {
- formGroup.getFormField().add(createIntegerEditor(style, attribute));
- } else if (attribute.getType().equals(AttributeType.FLOAT)) {
- formGroup.getFormField().add(createFloatEditor(style, attribute));
- } else if (attribute.getType().equals(AttributeType.BOOLEAN)) {
- formGroup.getFormField().add(createBooleanEditor(style, attribute));
- } else {
- formGroup.getFormField().add(
- new Label(managerMessages.unsupportedAttributeType(attribute.getType().getValue()))
- );
- }
-
- String description = getDescription(attribute);
- if (description != null) {
- formGroup.addInfolabel(new Label(description));
- }
-
- list.add(formGroup);
- }
- return list.toArray(new FormGroup[list.size()]);
- }
-
- public FormGroup createAttributeFormGroup(Attribute attribute) {
- FormGroup formGroup = new FormGroup();
-
- FormLabel formLabel = new FormLabel();
- String label = attribute.getName();
- if (attribute.getMetadata().hasElement("label")) {
- MetadataElement metadataLabel = attribute.getMetadata().getElement("label");
- if (metadataLabel.getType().equals(AttributeType.STRING.getValue())) {
- label = metadataLabel.getValue().asString();
- }
- }
- formLabel.setText(TextUtil.ellipsize(label, 30));
- formLabel.addStyleName("larger");
-
- if (AssetAttributeType.isSensor(attribute)) {
- formLabel.setIcon("sign-out");
- } else if (AssetAttributeType.isActuator(attribute)) {
- formLabel.setIcon("sign-in");
- }
-
- formGroup.addFormLabel(formLabel);
-
- FormField attributeField = new FormField();
- formGroup.addFormField(attributeField);
-
- return formGroup;
- }
-
- /* ####################################################################### */
-
- protected FormInputText createStringEditor(AttributesFormStyle style, Attribute attribute) {
- FormInputText input = createFormInputText(style.attributeStringEditor());
-
- if (attribute.getValue() != null) {
- input.setValue(attribute.getValue().asString());
- }
-
- if (AssetAttributeType.isSensor(attribute)) {
- input.setReadOnly(true);
- } else {
- input.addValueChangeHandler(
- event -> attribute.setValue(
- Json.create(event.getValue())
- )
- );
- }
- return input;
- }
-
- protected FormInputNumber createIntegerEditor(AttributesFormStyle style, Attribute attribute) {
- FormInputNumber input = createFormInputNumber(style.attributeIntegerEditor());
-
- if (attribute.getValue() != null) {
- input.setValue(attribute.getValue().asString());
- }
-
- if (AssetAttributeType.isSensor(attribute)) {
- input.setReadOnly(true);
- } else {
- input.addValueChangeHandler(event -> {
- try {
- Integer value = Integer.valueOf(event.getValue());
- attribute.setValue(Json.create(value));
- } catch (NumberFormatException ex) {
- // TODO Do nothing? can we hook this up into validation?
- }
- });
- }
- return input;
- }
-
- protected FormInputText createFloatEditor(AttributesFormStyle style, Attribute attribute) {
- FormInputText input = createFormInputText(style.attributeFloatEditor());
-
- if (attribute.getValue() != null) {
- input.setValue(attribute.getValue().asString());
- }
-
- if (AssetAttributeType.isSensor(attribute)) {
- input.setReadOnly(true);
- } else {
- input.addValueChangeHandler(event -> {
- try {
- Double value = Double.valueOf(event.getValue());
- attribute.setValue(Json.create(value));
- } catch (NumberFormatException ex) {
- // TODO Do nothing? can we hook this up into validation?
- }
- });
- }
- return input;
- }
-
- protected FormCheckBox createBooleanEditor(AttributesFormStyle style, Attribute attribute) {
- FormCheckBox input = createFormInputCheckBox(style.attributeBooleanEditor());
-
- if (attribute.getValue() != null) {
- boolean value = attribute.getValue().asBoolean();
- input.setValue(value);
- }
-
- if (AssetAttributeType.isSensor(attribute)) {
- input.setEnabled(false);
- } else {
- input.addValueChangeHandler(event -> {
- attribute.setValue(Json.create(input.getValue()));
- });
- }
- 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 String getDescription(Attribute attribute) {
- if (attribute.getMetadata().hasElement("description")) {
- MetadataElement metadataDescription = attribute.getMetadata().getElement("description");
- if (metadataDescription.getType().equals(AttributeType.STRING.getValue())) {
- return metadataDescription.getValue().asString();
- }
- }
- return null;
- }
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesFormStyle.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormDropDown.java
similarity index 58%
rename from manager/client/src/main/java/org/openremote/manager/client/widget/AttributesFormStyle.java
rename to manager/client/src/main/java/org/openremote/manager/client/widget/FormDropDown.java
index 5fef75fe2..aba9f6088 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesFormStyle.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormDropDown.java
@@ -19,13 +19,23 @@
*/
package org.openremote.manager.client.widget;
-public interface AttributesFormStyle {
+import com.google.gwt.text.shared.Renderer;
+import com.google.gwt.user.client.ui.ValueListBox;
+import com.google.gwt.view.client.ProvidesKey;
- String attributeStringEditor();
+public class FormDropDown<T> extends ValueListBox<T> {
- String attributeIntegerEditor();
+ public FormDropDown(Renderer<? super T> renderer) {
+ super(renderer);
+ setStyleName("or-FormControl or-FormDropDown");
+ }
- String attributeFloatEditor();
+ public FormDropDown(Renderer<? super T> renderer, ProvidesKey<T> keyProvider) {
+ super(renderer, keyProvider);
+ setStyleName("or-FormControl or-FormDropDown");
+ }
- String attributeBooleanEditor();
+ public FormDropDown() {
+ setStyleName("or-FormControl or-FormDropDown");
+ }
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormField.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormField.java
index 29f87e174..00456763d 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormField.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormField.java
@@ -28,7 +28,7 @@ public class FormField extends FlowPanel implements HasWidgets {
protected String formFieldId;
public FormField() {
- getElement().addClassName("or-FormField");
+ getElement().addClassName("flex layout horizontal or-FormField");
}
public void setFormFieldId(String formFieldId) {
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java
index a45697654..11246c3c4 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java
@@ -23,8 +23,10 @@ import com.google.gwt.dom.client.Style;
import com.google.gwt.uibinder.client.UiChild;
import com.google.gwt.user.client.ui.*;
-import java.util.Iterator;
-
+/**
+ * A form has form groups, each group is a combination of label,
+ * control field, etc. typically rendered in a single line/block.
+ */
public class FormGroup extends FlowPanel implements HasWidgets {
protected FlowPanel groupPanel = new FlowPanel();
@@ -109,7 +111,7 @@ public class FormGroup extends FlowPanel implements HasWidgets {
public void setOpaque(boolean opaque) {
getElement().removeClassName("opaque");
- if (!opaque) {
+ if (opaque) {
getElement().addClassName("opaque");
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormLabel.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormLabel.java
index a6ed5a20b..675e4d3df 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormLabel.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormLabel.java
@@ -35,7 +35,7 @@ public class FormLabel extends ComplexPanel {
getElement().addClassName("or-FormLabel layout horizontal center");
iconElement = (SpanElement) Document.get().createElement(SpanElement.TAG);
- iconElement.addClassName("flex or-FormLabelIcon");
+ iconElement.addClassName("or-FormLabelIcon");
iconElement.getStyle().setTextAlign(Style.TextAlign.RIGHT);
labelElement = (LabelElement) Document.get().createElement(LabelElement.TAG);
@@ -79,7 +79,7 @@ public class FormLabel extends ComplexPanel {
iconElement.removeClassName("fa");
iconElement.removeClassName("fa-" + icon);
} else {
- getElement().insertAfter(iconElement, requiredElement);
+ getElement().insertBefore(iconElement, labelElement);
}
this.icon = icon;
if (icon != null) {
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 5183eac67..79a0ac0eb 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
@@ -197,7 +197,7 @@ public class MapWidget extends ComplexPanel {
if (mapboxMap == null)
return;
host.removeStyleName("opaque");
- if (!opaque) {
+ if (opaque) {
host.addStyleName("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 a24bb05d8..bd4764904 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
@@ -64,24 +64,13 @@ noteRolesAfterCreate = You can assign access roles after creating the user.
showMoreAssets=Show more assets
emptyAsset= No assets found.
sessionTimedOut = Your session timed out. Please close or reload this browser window.
-agentName=Agent name
-connectorType= Connector type
-configureAgents= Configure agents
-newAgent=New agent
-editAgent=Edit agent
-updateAgent=Update agent
-createAgent=Create agent
-deleteAgent=Delete agent
+connector= Connector
description=Description
noConnectorAssigned= No connector assigned
connectorNotInstalled= CONNECTOR NOT INSTALLED
-agentUpdated= Agent updated: {0}
-agentCreated= Agent created: {0}
-agentDeleted= Agent deleted: {0}
unsupportedAttributeType= Unsupported attribute type: {0}
loadingAssets=Loading assets...
assetName= Asset name
-editAsset=Edit asset
updateAsset=Update asset
createAsset=Create asset
deleteAsset=Delete asset
@@ -104,4 +93,16 @@ setRootParentAsset=No parent
selectParentInAssetTree=Please select a parent on the left-hand side asset tree.
reset=Reset
invalidAssetParent= Invalid asset parent, please change your selection.
+centerMap=Center map
+showHistory=Show history
+sort=Sort
+assetTypeLabel = Unknown asset type
+assetTypeLabel[CUSTOM] = Custom
+assetTypeLabel[AGENT] = Agent
+assetTypeLabel[DEVICE] = Device
+assetTypeLabel[BUILDING] = Building
+assetTypeLabel[FLOOR] = Floor
+assetTypeLabel[ROOM] = Room
+noTypeSelected= No type selected
+enterCustomAssetType=Please enter a custom asset type (e.g. "urn:mydomain:mytype")
diff --git a/manager/client/src/main/webapp/css/style.html b/manager/client/src/main/webapp/css/style.html
index 002dbdf0d..922004388 100644
--- a/manager/client/src/main/webapp/css/style.html
+++ b/manager/client/src/main/webapp/css/style.html
@@ -87,6 +87,7 @@
border-radius: 0.15em;
font-weight: 600;
display: inline-block;
+ white-space: nowrap;
}
.or-PushButton,
@@ -108,17 +109,22 @@
margin-right: 0.4em;
}
- .or-PushButton.gwt-PushButton-up-disabled {
+ .or-PushButton.or-PushButton-up-disabled {
cursor: not-allowed;
opacity: .44;
}
- .or-PushButton.gwt-PushButton-up-disabled:hover,
- .or-PushButton.gwt-PushButton-up-disabled:active {
+ .or-PushButton.or-PushButton-up-disabled:hover,
+ .or-PushButton.or-PushButton-up-disabled:active {
-webkit-filter: inherit;
filter: inherit;
}
+ .or-Divider {
+ min-height: 0.1em;
+ margin: 1em 0;
+ }
+
.or-Hyperlink {
display: inline-block;
}
@@ -203,7 +209,7 @@
.or-FormGroup {
margin-bottom: 0.6em;
- min-height: 2.6em;
+ min-height: 2.75em;
}
.or-FormGroup.opaque .or-FormLabel,
@@ -390,6 +396,11 @@
font-weight: 600;
}
+ .or-FormTreeIcon {
+ margin-left: 0.4em;
+ width: 1.6em;
+ }
+
.or-FormMessages,
.or-Toast {
font-size: smaller;
diff --git a/manager/client/src/main/webapp/css/theme.html b/manager/client/src/main/webapp/css/theme.html
index 9b328e9fd..631d75935 100644
--- a/manager/client/src/main/webapp/css/theme.html
+++ b/manager/client/src/main/webapp/css/theme.html
@@ -180,6 +180,15 @@
border-color: var(--theme-black);
}
+ .or-Divider {
+ background-image: -webkit-linear-gradient(left, var(--theme-white), var(--theme-lightgreen), var(--theme-white));
+ background-image: -moz-linear-gradient(left, var(--theme-white), var(--theme-lightgreen), var(--theme-white));
+ }
+
+ .or-PushButton-up-disabled:focus {
+ border-color: transparent;
+ }
+
.or-FormDropDown {
border-color: var(--theme-darkgrey);
}
@@ -239,6 +248,10 @@
color: var(--theme-lightgreen);
}
+ .or-FormTreeIcon {
+ color: var(--theme-mediumgrey);
+ }
+
.or-ToastInfo {
background-color: var(--theme-lightgreen);
color: var(--theme-black);
@@ -277,7 +290,7 @@
}
.or-ItemWithBorder {
- border-color: var(--theme-black);
+ border-color: var(--theme-lightgrey);
}
</style>
\ No newline at end of file
diff --git a/manager/server/src/main/java/org/openremote/manager/server/SampleDataService.java b/manager/server/src/main/java/org/openremote/manager/server/SampleDataService.java
index 6bd79a842..c9fe2aa60 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/SampleDataService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/SampleDataService.java
@@ -26,6 +26,7 @@ import org.apache.log4j.Logger;
import org.keycloak.admin.client.resource.*;
import org.keycloak.common.enums.SslRequired;
import org.keycloak.representations.idm.*;
+import org.openremote.agent.controller2.Controller2Component;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.container.persistence.PersistenceService;
@@ -35,10 +36,10 @@ import org.openremote.manager.server.agent.ConnectorService;
import org.openremote.manager.server.asset.AssetService;
import org.openremote.manager.server.asset.ServerAsset;
import org.openremote.manager.server.security.ManagerIdentityService;
-import org.openremote.manager.shared.agent.Agent;
import org.openremote.manager.shared.asset.AssetAttributeType;
import org.openremote.manager.shared.asset.AssetType;
import org.openremote.manager.shared.attribute.*;
+import org.openremote.manager.shared.connector.Connector;
import rx.Observable;
import javax.ws.rs.core.UriBuilder;
@@ -47,7 +48,6 @@ import java.util.Arrays;
import java.util.List;
import static org.openremote.manager.shared.Constants.*;
-import static org.openremote.manager.shared.attribute.AttributeType.INTEGER;
import static org.openremote.manager.shared.attribute.AttributeType.STRING;
import static rx.Observable.fromCallable;
@@ -100,7 +100,6 @@ public class SampleDataService implements ContainerService {
configureMasterRealm(accessToken);
registerClientApplications(accessToken);
addRolesAndTestUsers(accessToken);
- storeSampleAgent();
storeSampleAssets();
}
@@ -246,61 +245,20 @@ public class SampleDataService implements ContainerService {
}
- protected void storeSampleAgent() {
- Agent controller2Agent = new Agent();
- controller2Agent.setName("OpenRemote Controller2 Test Agent");
- controller2Agent.setDescription("A test agent for OpenRemote Controller version 2.x");
- controller2Agent.setEnabled(true);
- controller2Agent.setConnectorType("urn:openremote:connector:controller2");
-
- Attributes connectorSettings = new Attributes();
- connectorSettings.add(new Attribute("host", STRING, Json.create("192.168.0.0")));
- connectorSettings.add(new Attribute("port", INTEGER, Json.create(8080)));
- controller2Agent.setConnectorSettings(connectorSettings.getJsonObject());
-
- persistenceService.doTransaction(em -> {
- em.persist(controller2Agent);
- });
-
- /*
- // TODO Remove tests
- persistenceService.doTransaction(em -> {
- List<String> hosts = em.createNativeQuery(
- "SELECT text(a.CONNECTOR_SETTINGS #> '{host,value}') FROM AGENT a " +
- "WHERE a.CONNECTOR_SETTINGS #> '{port,value}' = '8080'"
- ).getResultList();
-
- if (hosts.size() == 0) {
- throw new RuntimeException("Text query failed! TODO Remove this test...");
- }
-
- List<Agent> agents = em.createNativeQuery(
- "SELECT a.* FROM AGENT a " +
- "WHERE a.CONNECTOR_SETTINGS #> '{port,value}' = '8080'",
- Agent.class
- ).getResultList();
-
- if (agents.size() == 0) {
- throw new RuntimeException("Text query failed! TODO Remove this test...");
- }
- });
- */
- }
-
protected void storeSampleAssets() {
GeometryFactory geometryFactory = new GeometryFactory();
- ServerAsset videoLab = new ServerAsset();
- videoLab.setName("Videolab");
- videoLab.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
- videoLab.setType(AssetType.BUILDING);
- assetService.create(videoLab);
+ ServerAsset smartOffice = new ServerAsset();
+ smartOffice.setName("Smart Office");
+ smartOffice.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
+ smartOffice.setType(AssetType.BUILDING);
+ assetService.create(smartOffice);
ServerAsset floor;
ServerAsset floor6 = null;
for (int i = 0; i < 7; i++) {
- floor = new ServerAsset(videoLab);
+ floor = new ServerAsset(smartOffice);
floor.setName("Floor " + (i + 1));
floor.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
floor.setType(AssetType.FLOOR);
@@ -316,7 +274,24 @@ public class SampleDataService implements ContainerService {
room = new ServerAsset(floor6);
room.setName("6.00" + (i + 1));
room.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
- room.setType(AssetType.ROOM);
+
+ if (i == 2) {
+ // This is our sample agent
+ room.setType(AssetType.AGENT);
+ Attributes room3Attributes = new Attributes();
+ room3Attributes.put(
+ new Attribute(Connector.ASSET_ATTRIBUTE_CONNECTOR, STRING, Json.create("urn:openremote:connector:controller2"))
+ );
+ for (Attribute connectorSetting : Controller2Component.SETTINGS.get()) {
+ room3Attributes.put(connectorSetting.copy());
+ }
+ room3Attributes.get("host").setValue("192.168.123.123");
+ room3Attributes.get("port").setValue(8080);
+ room.setAttributes(room3Attributes.getJsonObject());
+ } else {
+ room.setType(AssetType.ROOM);
+ }
+
assetService.create(room);
if (i == 2)
@@ -328,7 +303,7 @@ public class SampleDataService implements ContainerService {
wallpanel.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
wallpanel.setType(AssetType.DEVICE);
Attributes wallpanelAttributes = new Attributes();
- wallpanelAttributes.add(
+ wallpanelAttributes.put(
new Attribute("temperature", AttributeType.FLOAT, Json.create(21.3))
.setMetadata(new Metadata()
.addElement(new MetadataElement("type", AttributeType.STRING.getValue(), AssetAttributeType.SENSOR.getJsonValue()))
@@ -366,7 +341,7 @@ public class SampleDataService implements ContainerService {
presence.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
presence.setType(AssetType.DEVICE);
Attributes presenceAttributes = new Attributes();
- presenceAttributes.add(
+ presenceAttributes.put(
new Attribute("presence", AttributeType.BOOLEAN, Json.create(false))
.setMetadata(new Metadata()
.addElement(new MetadataElement("type", AttributeType.STRING.getValue(), AssetAttributeType.SENSOR.getJsonValue()))
@@ -381,7 +356,7 @@ public class SampleDataService implements ContainerService {
windows.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
windows.setType(AssetType.DEVICE);
Attributes windowsAttributes = new Attributes();
- windowsAttributes.add(
+ windowsAttributes.put(
new Attribute("status", AttributeType.BOOLEAN, Json.create(false))
.setMetadata(new Metadata()
.addElement(new MetadataElement("type", AttributeType.STRING.getValue(), AssetAttributeType.SENSOR.getJsonValue()))
@@ -396,7 +371,7 @@ public class SampleDataService implements ContainerService {
valve.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
valve.setType(AssetType.DEVICE);
Attributes valveAttributes = new Attributes();
- valveAttributes.add(
+ valveAttributes.put(
new Attribute("status", AttributeType.BOOLEAN, Json.create(true))
.setMetadata(new Metadata()
.addElement(new MetadataElement("type", AttributeType.STRING.getValue(), AssetAttributeType.SENSOR.getJsonValue()))
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentResourceImpl.java
deleted file mode 100644
index f7f43d584..000000000
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentResourceImpl.java
+++ /dev/null
@@ -1,62 +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.server.agent;
-
-import org.openremote.container.web.WebResource;
-import org.openremote.manager.shared.agent.AgentResource;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.http.RequestParams;
-
-import javax.ws.rs.BeanParam;
-
-public class AgentResourceImpl extends WebResource implements AgentResource {
-
- protected final AgentService agentService;
-
- public AgentResourceImpl(AgentService agentService) {
- this.agentService = agentService;
- }
-
- @Override
- public Agent[] getAll(@BeanParam RequestParams requestParams) {
- return agentService.getAll(false);
- }
-
- @Override
- public Agent get(@BeanParam RequestParams requestParams, String agentId) {
- return agentService.get(agentId);
- }
-
- @Override
- public void create(@BeanParam RequestParams requestParams, Agent agent) {
- agentService.create(agent);
- }
-
- @Override
- public void update(@BeanParam RequestParams requestParams, String agentId, Agent agent) {
- agentService.update(agent);
-
- }
-
- @Override
- public void delete(@BeanParam RequestParams requestParams, String agentId) {
- agentService.delete(agentId);
- }
-}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
index ac5fe533a..27b5a0ec9 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
@@ -24,10 +24,9 @@ import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.container.message.MessageBrokerService;
import org.openremote.container.persistence.PersistenceService;
-import org.openremote.container.web.WebService;
-import org.openremote.manager.shared.agent.Agent;
+import org.openremote.manager.shared.asset.Asset;
+import org.openremote.manager.shared.asset.AssetType;
-import java.util.*;
import java.util.logging.Logger;
import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_EVENT_HEADER;
@@ -37,8 +36,6 @@ public class AgentService implements ContainerService {
private static final Logger LOG = Logger.getLogger(AgentService.class.getName());
- final protected Map<String, Agent> activeAgents = new LinkedHashMap<>();
-
protected MessageBrokerService messageBrokerService;
protected PersistenceService persistenceService;
protected ConnectorService connectorService;
@@ -53,7 +50,11 @@ public class AgentService implements ContainerService {
@Override
public void configure() throws Exception {
from(PERSISTENCE_EVENT_TOPIC)
- .filter(body().isInstanceOf(Agent.class))
+ .filter(body().isInstanceOf(Asset.class))
+ .filter(exchange -> {
+ Asset asset = exchange.getIn().getBody(Asset.class);
+ return AssetType.AGENT.equals(asset.getWellKnownType());
+ })
.process(exchange -> {
LOG.info("### AGENT PERSISTENCE EVENT: " + exchange.getIn().getHeader(PERSISTENCE_EVENT_HEADER));
LOG.info("### AGENT: " + exchange.getIn().getBody());
@@ -66,14 +67,11 @@ public class AgentService implements ContainerService {
@Override
public void configure(Container container) throws Exception {
- container.getService(WebService.class).getApiSingletons().add(
- new AgentResourceImpl(this)
- );
}
@Override
public void start(Container container) throws Exception {
- reconfigureAgents();
+ // TODO On startup, load all enabled agents and reconfigureAgents();
}
@Override
@@ -81,64 +79,8 @@ public class AgentService implements ContainerService {
}
- public Agent[] getActive() {
- synchronized (activeAgents) {
- return activeAgents.values().toArray(new Agent[activeAgents.size()]);
- }
- }
-
- public Agent[] getAll(boolean onlyEnabled) {
- return persistenceService.doTransaction(em -> {
- List<Agent> result =
- em.createQuery(
- onlyEnabled
- ? "select a from Agent a where a.enabled = true order by a.createdOn desc"
- : "select a from Agent a order by a.createdOn desc"
- , Agent.class
- ).getResultList();
- return result.toArray(new Agent[result.size()]);
- });
- }
-
- public Agent get(String agentId) {
- return persistenceService.doTransaction(em -> {
- return em.find(Agent.class, agentId);
- });
- }
-
- public void create(Agent agent) {
- persistenceService.doTransaction(em -> {
- em.persist(agent);
- });
- }
-
- public void update(Agent agent) {
- persistenceService.doTransaction(em -> {
- em.merge(agent);
- });
- }
-
- public void delete(String agentId) {
- persistenceService.doTransaction(em -> {
- Agent agent = em.find(Agent.class, agentId);
- if (agent != null) {
- em.remove(agent);
- }
- });
- }
-
protected void reconfigureAgents() {
- synchronized (activeAgents) {
- // TODO Implement route restart etc.
- LOG.info("### RECONFIGURE AGENTS");
- }
- }
-
- protected void startAgent(Agent agent) {
-
+ LOG.info("############################### TODO: RECONFIGURE AGENTS");
}
- protected void stopAgent(Agent agent) {
-
- }
}
\ No newline at end of file
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetService.java
index e5d61b1d0..f94d2fb43 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetService.java
@@ -26,10 +26,8 @@ import org.openremote.container.ContainerService;
import org.openremote.container.message.MessageBrokerService;
import org.openremote.container.persistence.PersistenceService;
import org.openremote.container.web.WebService;
-import org.openremote.manager.shared.agent.Agent;
import org.openremote.manager.shared.asset.Asset;
import org.openremote.manager.shared.asset.AssetInfo;
-import org.openremote.manager.shared.ngsi.Entity;
import javax.persistence.EntityManager;
import java.sql.PreparedStatement;
diff --git a/manager/server/src/main/resources/META-INF/persistence.xml b/manager/server/src/main/resources/META-INF/persistence.xml
index 4c840975b..b32dc87d3 100644
--- a/manager/server/src/main/resources/META-INF/persistence.xml
+++ b/manager/server/src/main/resources/META-INF/persistence.xml
@@ -9,7 +9,6 @@
<class>org.openremote.container.persistence</class>
- <class>org.openremote.manager.shared.agent.Agent</class>
<class>org.openremote.manager.server.asset.ServerAsset</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
diff --git a/manager/server/src/main/resources/logging.properties b/manager/server/src/main/resources/logging.properties
index 6e1b9d3cb..e9ef64462 100644
--- a/manager/server/src/main/resources/logging.properties
+++ b/manager/server/src/main/resources/logging.properties
@@ -21,5 +21,5 @@ org.apache.http.level=WARNING
org.apache.http.impl.conn.DefaultClientConnection.level=WARNING
# Set this to FINEST to log SQL execution
-org.hibernate.SQL.level=FINEST
-org.hibernate.type.descriptor.sql.BasicBinder.level=FINEST
+#org.hibernate.SQL.level=FINEST
+#org.hibernate.type.descriptor.sql.BasicBinder.level=FINEST
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/Agent.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/Agent.java
deleted file mode 100644
index 8ba928786..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/Agent.java
+++ /dev/null
@@ -1,141 +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.shared.agent;
-
-import elemental.json.JsonObject;
-
-import javax.persistence.*;
-import javax.validation.constraints.NotNull;
-import java.util.Date;
-
-import static org.openremote.manager.shared.Constants.PERSISTENCE_JSON_OBJECT_TYPE;
-import static org.openremote.manager.shared.Constants.PERSISTENCE_UNIQUE_ID_GENERATOR;
-
-@Entity
-@Table(name = "AGENT")
-public class Agent {
-
- public static final String NO_CONNECTOR_ASSIGNED_TYPE = "urn:openremote:connector:none";
- public static final String NO_DESCRIPTION = "-";
-
- @Id
- @Column(name = "ID", length = 22)
- @GeneratedValue(generator = PERSISTENCE_UNIQUE_ID_GENERATOR)
- protected String id;
-
- @Version
- @Column(name = "OBJ_VERSION", nullable = false)
- protected long version;
-
- @Temporal(TemporalType.TIMESTAMP)
- @Column(name = "CREATED_ON", updatable = false, nullable = false)
- @org.hibernate.annotations.CreationTimestamp
- protected Date createdOn;
-
- @NotNull
- @Column(name = "NAME", nullable = false)
- protected String name;
-
- @NotNull
- @Column(name = "DESCRIPTION", nullable = false)
- protected String description = NO_DESCRIPTION;
-
- @NotNull
- @Column(name = "ENABLED", nullable = false)
- protected boolean enabled;
-
- @NotNull
- @Column(name = "CONNECTOR_TYPE", nullable = false)
- protected String connectorType = NO_CONNECTOR_ASSIGNED_TYPE;
-
- @Column(name = "CONNECTOR_SETTINGS", columnDefinition = "jsonb")
- @org.hibernate.annotations.Type(type = PERSISTENCE_JSON_OBJECT_TYPE)
- protected JsonObject connectorSettings;
-
- public Agent() {
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public long getVersion() {
- return version;
- }
-
- public Date getCreatedOn() {
- return createdOn;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public String getConnectorType() {
- return connectorType;
- }
-
- public void setConnectorType(String connectorType) {
- this.connectorType = connectorType;
- }
-
- public JsonObject getConnectorSettings() {
- return connectorSettings;
- }
-
- public void setConnectorSettings(JsonObject connectorSettings) {
- this.connectorSettings = connectorSettings;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "id='" + id + '\'' +
- ", name='" + name + '\'' +
- ", enabled=" + enabled +
- ", connectorType='" + connectorType + '\'' +
- ", connectorSettings='" + (connectorSettings != null ? connectorSettings.toJson() : "null") + '\'' +
- '}';
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentResource.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentResource.java
deleted file mode 100644
index 83c4668b4..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentResource.java
+++ /dev/null
@@ -1,69 +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.shared.agent;
-
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.http.RequestParams;
-import org.openremote.manager.shared.http.SuccessStatusCode;
-
-import javax.ws.rs.*;
-
-import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
-
-@Path("agent")
-@JsType(isNative = true)
-public interface AgentResource {
-
- @GET
- @Produces(APPLICATION_JSON)
- @SuccessStatusCode(200)
- // TODO Implement admin roles on server
- //@RolesAllowed({"read:admin"})
- Agent[] getAll(@BeanParam RequestParams requestParams);
-
- @GET
- @Path("{agentId}")
- @Produces(APPLICATION_JSON)
- @SuccessStatusCode(200)
- Agent get(@BeanParam RequestParams requestParams, @PathParam("agentId") String agentId);
-
- @POST
- @Consumes(APPLICATION_JSON)
- @SuccessStatusCode(204)
- // TODO Implement admin roles on server
- //@RolesAllowed({"write:admin"})
- void create(@BeanParam RequestParams requestParams, Agent agent);
-
- @PUT
- @Path("{agentId}")
- @Consumes(APPLICATION_JSON)
- @SuccessStatusCode(204)
- // TODO Implement admin roles on server
- //@RolesAllowed({"read:admin"})
- void update(@BeanParam RequestParams requestParams, @PathParam("agentId") String agentId, Agent agent);
-
- @DELETE
- @Path("{agentId}")
- @Produces(APPLICATION_JSON)
- @SuccessStatusCode(204)
- // TODO Implement admin roles on server
- //@RolesAllowed({"read:admin"})
- void delete(@BeanParam RequestParams requestParams, @PathParam("agentId") String agentId);
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/asset/Asset.java b/manager/shared/src/main/java/org/openremote/manager/shared/asset/Asset.java
index a37bc1f11..4a2f8588f 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/asset/Asset.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/asset/Asset.java
@@ -112,12 +112,16 @@ public class Asset {
return type;
}
+ public AssetType getWellKnownType() {
+ return AssetType.getByValue(getType());
+ }
+
public void setType(String type) {
this.type = type;
}
public void setType(AssetType type) {
- setType(type.getValue());
+ setType(type != null ? type.getValue() : null);
}
public String getParentId() {
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetAttributeType.java b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetAttributeType.java
index 937724828..026a498fa 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetAttributeType.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetAttributeType.java
@@ -31,7 +31,6 @@ import org.openremote.manager.shared.attribute.MetadataElement;
*/
public enum AssetAttributeType {
-
SENSOR("urn:openremote:asset:sensor"),
ACTUATOR("urn:openremote:asset:actuator");
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetInfo.java b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetInfo.java
index 1f04980e9..22b2c75f3 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetInfo.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetInfo.java
@@ -67,6 +67,10 @@ public class AssetInfo {
return type;
}
+ public AssetType getWellKnownType() {
+ return AssetType.getByValue(getType());
+ }
+
public void setType(String type) {
this.type = type;
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetType.java b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetType.java
index dfce3b965..dce31c8c5 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetType.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetType.java
@@ -3,30 +3,62 @@ package org.openremote.manager.shared.asset;
import elemental.json.Json;
import elemental.json.JsonString;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Asset type is an arbitrary string. It should be URI. This enum contains
* the well-known URIs for functionality we want to depend on in our platform.
*/
public enum AssetType {
- GENERIC("urn:openremote:asset:generic"),
+ CUSTOM(null),
AGENT("urn:openremote:asset:agent"),
+ DEVICE("urn:openremote:asset:device", false),
BUILDING("urn:openremote:asset:building"),
FLOOR("urn:openremote:asset:floor"),
- ROOM("urn:openremote:asset:room"),
- DEVICE("urn:openremote:asset:device");
+ ROOM("urn:openremote:asset:room");
final protected String value;
+ final protected boolean editable;
- AssetType(String value) {
+ AssetType(String value, boolean editable) {
this.value = value;
+ this.editable = editable;
+ }
+
+ AssetType(String value) {
+ this(value, true);
}
public String getValue() {
return value;
}
+ public boolean isEditable() {
+ return editable;
+ }
+
public JsonString getJsonValue() {
return Json.create(getValue());
}
+
+ public static AssetType[] editable() {
+ List<AssetType> list = new ArrayList<>();
+ for (AssetType assetType : values()) {
+ if (assetType.isEditable())
+ list.add(assetType);
+ }
+ return list.toArray(new AssetType[list.size()]);
+ }
+
+ public static AssetType getByValue(String value) {
+ if (value == null)
+ return CUSTOM;
+ for (AssetType assetType : values()) {
+ if (value.equals(assetType.getValue()))
+ return assetType;
+ }
+ return CUSTOM;
+ }
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attribute.java b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attribute.java
index 6310e76c6..ab5d0f0a2 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attribute.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attribute.java
@@ -19,6 +19,7 @@
*/
package org.openremote.manager.shared.attribute;
+import elemental.json.Json;
import elemental.json.JsonObject;
import elemental.json.JsonValue;
@@ -28,8 +29,7 @@ public class Attribute {
final protected JsonObject jsonObject;
public Attribute(String name) {
- this.name = name;
- jsonObject = elemental.json.Json.createObject();
+ this(name, Json.createObject());
}
public Attribute(String name, AttributeType type) {
@@ -70,6 +70,10 @@ public class Attribute {
return jsonObject.hasKey("value") ? jsonObject.get("value") : null;
}
+ public String getValueAsString() {
+ return jsonObject.hasKey("value") ? jsonObject.get("value").asString() : null;
+ }
+
public JsonObject getValueAsObject() {
return jsonObject.hasKey("value") ? jsonObject.getObject("value") : null;
}
@@ -79,10 +83,30 @@ public class Attribute {
return this;
}
+ public Attribute setValue(String value) {
+ return setValue(Json.create(value));
+ }
+
+ public Attribute setValue(Integer value) {
+ return setValue(Json.create(value));
+ }
+
+ public Attribute setValue(double value) {
+ return setValue(Json.create(value));
+ }
+
+ public Attribute setValue(boolean value) {
+ return setValue(Json.create(value));
+ }
+
public boolean hasMetadata() {
return jsonObject.hasKey("metadata");
}
+ public boolean hasMetadataElement(String name) {
+ return hasMetadata() && getMetadata().hasElement(name);
+ }
+
public Metadata getMetadata() {
return hasMetadata() ? new Metadata(jsonObject.getObject("metadata")) : null;
}
@@ -92,6 +116,10 @@ public class Attribute {
return this;
}
+ public Attribute copy() {
+ return new Attribute(getName(), Json.parse(getJsonObject().toJson()));
+ }
+
@Override
public String toString() {
return jsonObject.toJson();
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attributes.java b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attributes.java
index 6cfef1de9..e4c55d78f 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attributes.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attributes.java
@@ -22,10 +22,10 @@ package org.openremote.manager.shared.attribute;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import elemental.json.Json;
import elemental.json.JsonObject;
-import java.util.LinkedHashSet;
-import java.util.Set;
+import java.util.*;
@JsonSerialize(using = AttributesSerializer.class)
@JsonDeserialize(using = AttributesDeserializer.class)
@@ -33,12 +33,12 @@ public class Attributes {
final protected JsonObject jsonObject;
public Attributes() {
- this(elemental.json.Json.createObject());
+ this(Json.createObject());
}
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public Attributes(JsonObject jsonObject) {
- this.jsonObject = jsonObject;
+ this.jsonObject = jsonObject != null ? jsonObject : Json.createObject();
}
public JsonObject getJsonObject() {
@@ -69,7 +69,7 @@ public class Attributes {
return hasAttribute(name) ? new Attribute(name, jsonObject.getObject(name)) : null;
}
- public Attributes add(Attribute... attributes) {
+ public Attributes put(Attribute... attributes) {
if (attributes != null)
for (Attribute attribute : attributes) {
jsonObject.put(attribute.getName(), attribute.getJsonObject());
@@ -84,13 +84,21 @@ public class Attributes {
return this;
}
- public Attributes clear() {
+ public Attributes clear(String... excludeAttributes) {
+ List<String> excluded =
+ excludeAttributes != null ? Arrays.asList(excludeAttributes) : new ArrayList<>();
for (Attribute attribute : get()) {
- remove(attribute.getName());
+ if (!excluded.contains(attribute.getName())) {
+ remove(attribute.getName());
+ }
}
return this;
}
+ public Attributes copy() {
+ return new Attributes(Json.parse(getJsonObject().toJson()));
+ }
+
@Override
public String toString() {
return jsonObject.toJson();
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Metadata.java b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Metadata.java
index c2b58ccc4..adb6db442 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Metadata.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Metadata.java
@@ -66,6 +66,10 @@ public class Metadata {
return this;
}
+ public Metadata copy() {
+ return new Metadata(Json.parse(getJsonObject().toJson()));
+ }
+
@Override
public String toString() {
return jsonObject.toJson();
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/MetadataElement.java b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/MetadataElement.java
index bf45b85bf..4f9efdcea 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/MetadataElement.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/MetadataElement.java
@@ -74,6 +74,10 @@ public class MetadataElement {
return this;
}
+ public MetadataElement copy() {
+ return new MetadataElement(getName(), Json.parse(getJsonObject().toJson()));
+ }
+
@Override
public String toString() {
return jsonObject.toJson();
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java
index d369d27ae..1191b5771 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java
@@ -1,11 +1,11 @@
package org.openremote.manager.shared.connector;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.attribute.Attribute;
import org.openremote.manager.shared.attribute.Attributes;
public class Connector {
+ public static final String ASSET_ATTRIBUTE_CONNECTOR = "connector";
+
protected String name;
protected String type;
protected Attributes settings;
@@ -13,6 +13,10 @@ public class Connector {
public Connector() {
}
+ public Connector(String type) {
+ this.type = type;
+ }
+
public Connector(String name, String type, Attributes settings) {
this.name = name;
this.type = type;
@@ -43,48 +47,6 @@ public class Connector {
this.settings = settings;
}
- /**
- * Copy all settings which have a value into the {@link Agent}, keeping the value
- * of each attribute but not the attribute metadata.
- */
- public void writeSettings(Agent agent) {
- if (getSettings() == null) {
- agent.setConnectorSettings(null);
- return;
- }
- Attributes settings = getSettings();
- Attributes agentConnectorSettings = new Attributes();
- for (Attribute attribute : settings.get()) {
- if (attribute.getValue() == null)
- continue;
- Attribute agentConnectorAttribute = new Attribute(attribute.getName(), attribute.getType());
- agentConnectorAttribute.setValue(attribute.getValue());
- agentConnectorSettings.add(agentConnectorAttribute);
- }
- agent.setConnectorSettings(agentConnectorSettings.getJsonObject());
- }
-
- /**
- * Read the value for each settings attribute from the {@link Agent}, skipping any
- * unknown attribute or attribute that doesn't have the right type. The
- * {@link Agent#connectorSettings} can be "cleaned up" so they match a {@link Connector}
- * by calling {@link #readSettings(Agent)} followed by {@link #writeSettings(Agent)}.
- */
- public void readSettings(Agent agent) {
- if (agent.getConnectorSettings() == null)
- return;
-
- Attributes settings = getSettings();
- Attributes agentConnectorSettings = new Attributes(agent.getConnectorSettings());
- for (Attribute agentConnectorAttribute : agentConnectorSettings.get()) {
- Attribute settingsAttribute = settings.get(agentConnectorAttribute.getName());
- if (settingsAttribute != null
- && settingsAttribute.getType().equals(agentConnectorAttribute.getType())) {
- settingsAttribute.setValue(agentConnectorAttribute.getValue());
- }
- }
- }
-
@Override
public String toString() {
return getClass().getSimpleName() + "{" +