aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-01-02 14:44:52 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-01-02 14:44:52 +1300
commit7032c42fb017582f1343128466b8df51c155f78d (patch)
tree387e03f5ee6137513c6798c5e6558ed51af0d019 /src
parent65913d45863159b9652865bc4f23eb62120d9b62 (diff)
downloadtrackermap-web-7032c42fb017582f1343128466b8df51c155f78d.tar.gz
trackermap-web-7032c42fb017582f1343128466b8df51c155f78d.tar.bz2
trackermap-web-7032c42fb017582f1343128466b8df51c155f78d.zip
Finished devices panel
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/web/client/Style.java4
-rw-r--r--src/main/java/org/traccar/web/client/Traccar.java120
-rw-r--r--src/main/java/org/traccar/web/client/controller/ArchiveController.java14
-rw-r--r--src/main/java/org/traccar/web/client/controller/DeviceController.java94
-rw-r--r--src/main/java/org/traccar/web/client/controller/LoginController.java84
-rw-r--r--src/main/java/org/traccar/web/client/controller/MapController.java14
-rw-r--r--src/main/java/org/traccar/web/client/controller/PanelController.java9
-rw-r--r--src/main/java/org/traccar/web/client/database/BaseAsyncCallback.java19
-rw-r--r--src/main/java/org/traccar/web/client/database/DatabaseService.java6
-rw-r--r--src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java6
-rw-r--r--src/main/java/org/traccar/web/client/database/GlobalDatabaseService.java13
-rw-r--r--src/main/java/org/traccar/web/client/i18n/ApplicationConstants.java14
-rw-r--r--src/main/java/org/traccar/web/client/login/LoginController.java87
-rw-r--r--src/main/java/org/traccar/web/client/view/DeviceDialog.java87
-rw-r--r--src/main/java/org/traccar/web/client/view/DevicePanel.java140
-rw-r--r--src/main/java/org/traccar/web/client/view/LoginDialog.java (renamed from src/main/java/org/traccar/web/client/login/LoginDialog.java)41
-rw-r--r--src/main/java/org/traccar/web/client/view/MapPanel.java10
-rw-r--r--src/main/java/org/traccar/web/server/database/DatabaseServiceImpl.java53
-rw-r--r--src/main/java/org/traccar/web/shared/model/Device.java19
-rw-r--r--src/main/java/org/traccar/web/shared/model/Position.java2
-rw-r--r--src/main/java/org/traccar/web/shared/model/User.java2
21 files changed, 596 insertions, 242 deletions
diff --git a/src/main/java/org/traccar/web/client/Style.java b/src/main/java/org/traccar/web/client/Style.java
index 83673906..4f2c1fd4 100644
--- a/src/main/java/org/traccar/web/client/Style.java
+++ b/src/main/java/org/traccar/web/client/Style.java
@@ -10,4 +10,8 @@ public class Style {
return 5;
}
+ public static String getNoBorder() {
+ return "0px";
+ }
+
}
diff --git a/src/main/java/org/traccar/web/client/Traccar.java b/src/main/java/org/traccar/web/client/Traccar.java
index 2bb84f4a..6da9e011 100644
--- a/src/main/java/org/traccar/web/client/Traccar.java
+++ b/src/main/java/org/traccar/web/client/Traccar.java
@@ -1,15 +1,19 @@
package org.traccar.web.client;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.traccar.web.client.login.LoginController;
-import org.traccar.web.client.view.ArchivePanel;
-import org.traccar.web.client.view.DevicePanel;
-import org.traccar.web.client.view.MapPanel;
-import org.traccar.web.shared.model.Device;
+import org.traccar.web.client.controller.ArchiveController;
+import org.traccar.web.client.controller.DeviceController;
+import org.traccar.web.client.controller.LoginController;
+import org.traccar.web.client.controller.MapController;
+import org.traccar.web.client.database.DatabaseService;
+import org.traccar.web.client.database.DatabaseServiceAsync;
+import org.traccar.web.client.i18n.ApplicationConstants;
import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.core.client.GWT;
+import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
@@ -18,9 +22,17 @@ import com.smartgwt.client.widgets.layout.VLayout;
*/
public class Traccar implements EntryPoint, LoginController.LoginHandler {
- private DevicePanel devicePanel;
- private ArchivePanel archivePanel;
- private MapPanel mapPanel;
+ private static final ApplicationConstants constants = GWT.create(ApplicationConstants.class);
+
+ public static ApplicationConstants getConstants() {
+ return constants;
+ }
+
+ private static final DatabaseServiceAsync databaseService = GWT.create(DatabaseService.class);
+
+ public static DatabaseServiceAsync getDatabaseService() {
+ return databaseService;
+ }
/**
* Entry point method
@@ -28,69 +40,53 @@ public class Traccar implements EntryPoint, LoginController.LoginHandler {
@Override
public void onModuleLoad() {
new LoginController().login(this);
- //onLogin(); // TODO: remove from production
-
- /*try {
- GlobalDatabaseService.getInstance().getPositions(
- new Device(1), new Date(1325430000000L), new Date(1325437200000L),
- new AsyncCallback<List<Position>>() {
- @Override
- public void onFailure(Throwable throwable) {
- SC.warn("onFailure");
- }
- @Override
- public void onSuccess(List<Position> positions) {
- SC.warn("onSuccess");
- }
- });
- } catch (Exception error) {
- SC.warn(error.getMessage());
- }*/
-
- }
-
- private List<Device> testDevices() {
- List<Device> devices = new LinkedList<Device>();
-
- Device device = new Device(1);
- device.setName("test1");
- device.setUniqueId("11111");
- devices.add(device);
-
- device = new Device(2);
- device.setName("test2");
- device.setUniqueId("22222");
- devices.add(device);
-
- return devices;
}
@Override
public void onLogin() {
- devicePanel = new DevicePanel();
- devicePanel.setWidth("20%");
- devicePanel.setShowResizeBar(true);
+ createLayout();
+ }
+
+ private MapController mapController;
+ private DeviceController deviceController;
+ private ArchiveController archiveController;
- //devicePanel.updateDevices(testDevices()); // TODO: remove from production
+ private void createLayout() {
+ mapController = new MapController();
+ deviceController = new DeviceController();
+ archiveController = new ArchiveController();
- mapPanel = new MapPanel();
- mapPanel.setWidth("80%");
+ Canvas mainPanel = mapController.getView();
+ mainPanel.setWidth("80%");
- HLayout hLayout = new HLayout();
- hLayout.setHeight("70%");
- hLayout.addMember(devicePanel);
- hLayout.addMember(mapPanel);
- hLayout.setShowResizeBar(true);
- hLayout.setResizeBarTarget("next");
+ Canvas leftPanel = deviceController.getView();
+ leftPanel.setWidth("20%");
+ leftPanel.setShowResizeBar(true);
- archivePanel = new ArchivePanel();
- archivePanel.setHeight("30%");
+ Canvas bottomPanel = archiveController.getView();
+ bottomPanel.setHeight("30%");
+
+ HLayout topLayout = new HLayout();
+ topLayout.setHeight("70%");
+ topLayout.addMember(leftPanel);
+ topLayout.addMember(mainPanel);
+ topLayout.setShowResizeBar(true);
+ topLayout.setResizeBarTarget("next");
VLayout mainLayout = new VLayout();
mainLayout.setWidth100();
mainLayout.setHeight100();
- mainLayout.addMember(hLayout);
- mainLayout.addMember(archivePanel);
+ mainLayout.addMember(topLayout);
+ mainLayout.addMember(bottomPanel);
+
+ deviceController.setSettingsClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ SC.say("Coming soon...");
+ }
+ });
+
mainLayout.draw();
}
+
}
diff --git a/src/main/java/org/traccar/web/client/controller/ArchiveController.java b/src/main/java/org/traccar/web/client/controller/ArchiveController.java
new file mode 100644
index 00000000..acd8252e
--- /dev/null
+++ b/src/main/java/org/traccar/web/client/controller/ArchiveController.java
@@ -0,0 +1,14 @@
+package org.traccar.web.client.controller;
+
+import org.traccar.web.client.view.ArchivePanel;
+
+import com.smartgwt.client.widgets.Canvas;
+
+public class ArchiveController implements PanelController {
+
+ @Override
+ public Canvas getView() {
+ return new ArchivePanel();
+ }
+
+}
diff --git a/src/main/java/org/traccar/web/client/controller/DeviceController.java b/src/main/java/org/traccar/web/client/controller/DeviceController.java
new file mode 100644
index 00000000..6bf73b01
--- /dev/null
+++ b/src/main/java/org/traccar/web/client/controller/DeviceController.java
@@ -0,0 +1,94 @@
+package org.traccar.web.client.controller;
+
+import java.util.List;
+
+import org.traccar.web.client.Traccar;
+import org.traccar.web.client.database.BaseAsyncCallback;
+import org.traccar.web.client.view.DeviceDialog;
+import org.traccar.web.client.view.DevicePanel;
+import org.traccar.web.shared.model.Device;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.events.ClickHandler;
+
+public class DeviceController implements PanelController, DevicePanel.DeviceHandler, DeviceDialog.SaveHandler {
+
+ public interface DeviceHandler {
+ public void onChanged();
+ }
+
+ private DeviceHandler deviceHandler;
+
+ public void setHandler(DeviceHandler deviceHandler) {
+ this.deviceHandler = deviceHandler;
+ }
+
+ private final DevicePanel devicePanel;
+
+ public DeviceController() {
+ devicePanel = new DevicePanel();
+ devicePanel.setDeviceHandler(this);
+ Traccar.getDatabaseService().getDevices(updateCallback);
+ }
+
+ @Override
+ public Canvas getView() {
+ return devicePanel;
+ }
+
+ public void setSettingsClickHandler(ClickHandler handler) {
+ if (devicePanel != null) {
+ devicePanel.setSettingsClickHandler(handler);
+ }
+ }
+
+ DeviceDialog dialog;
+
+ @Override
+ public void onAdd() {
+ onEdit(new Device());
+ }
+
+ @Override
+ public void onEdit(Device device) {
+ dialog = new DeviceDialog();
+ dialog.setSaveHandler(this);
+ dialog.setDevice(device);
+ dialog.draw();
+ dialog.centerInPage();
+ }
+
+ @Override
+ public void onRemove(Device device) {
+ Traccar.getDatabaseService().removeDevice(device, saveCallback);
+ }
+
+ @Override
+ public void onSave(Device device) {
+ Traccar.getDatabaseService().storeDevice(device, saveCallback);
+ }
+
+ private AsyncCallback<Boolean> saveCallback = new BaseAsyncCallback<Boolean>() {
+ @Override
+ public void onSuccess(Boolean result) {
+ if (result) {
+ if (dialog != null) {
+ dialog.destroy();
+ dialog = null;
+ }
+ Traccar.getDatabaseService().getDevices(updateCallback);
+ }
+ }
+ };
+
+ private AsyncCallback<List<Device>> updateCallback = new BaseAsyncCallback<List<Device>>() {
+ @Override
+ public void onSuccess(List<Device> result) {
+ devicePanel.updateDevices(result);
+ if (deviceHandler != null) {
+ deviceHandler.onChanged();
+ }
+ }
+ };
+}
diff --git a/src/main/java/org/traccar/web/client/controller/LoginController.java b/src/main/java/org/traccar/web/client/controller/LoginController.java
new file mode 100644
index 00000000..b3193a19
--- /dev/null
+++ b/src/main/java/org/traccar/web/client/controller/LoginController.java
@@ -0,0 +1,84 @@
+package org.traccar.web.client.controller;
+
+import org.traccar.web.client.Traccar;
+import org.traccar.web.client.database.BaseAsyncCallback;
+import org.traccar.web.client.view.LoginDialog;
+
+import com.smartgwt.client.util.SC;
+
+public class LoginController implements LoginDialog.LoginHandler {
+
+ private LoginDialog dialog;
+
+ public interface LoginHandler {
+ public void onLogin();
+ }
+
+ private LoginHandler loginHandler;
+
+ public void login(final LoginHandler loginHandler) {
+ this.loginHandler = loginHandler;
+
+ Traccar.getDatabaseService().authenticated(new BaseAsyncCallback<Boolean>() {
+ @Override
+ public void onSuccess(Boolean result) {
+
+ if (result) {
+ loginHandler.onLogin();
+ } else {
+ dialog = new LoginDialog();
+ dialog.setLoginHandler(LoginController.this);
+ dialog.draw();
+ dialog.centerInPage();
+ }
+ }
+ });
+ }
+
+ private boolean validate(String login, String password) {
+ if (login == null || login.isEmpty() || password == null || password.isEmpty()) {
+ SC.warn(Traccar.getConstants().blankLoginPassword());
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void onLogin(String login, String password) {
+ if (validate(login, password)) {
+ Traccar.getDatabaseService().authenticate(login, password, new BaseAsyncCallback<Boolean>() {
+ @Override
+ public void onSuccess(Boolean result) {
+ if (result) {
+ if (loginHandler != null) {
+ dialog.destroy();
+ loginHandler.onLogin();
+ }
+ } else {
+ SC.warn(Traccar.getConstants().invalidLoginPassword());
+ }
+ }
+ });
+ }
+ }
+
+ @Override
+ public void onRegister(String login, String password) {
+ if (validate(login, password)) {
+ Traccar.getDatabaseService().register(login, password, new BaseAsyncCallback<Boolean>() {
+ @Override
+ public void onSuccess(Boolean result) {
+ if (result) {
+ if (loginHandler != null) {
+ dialog.destroy();
+ loginHandler.onLogin();
+ }
+ } else {
+ SC.warn(Traccar.getConstants().registrationError());
+ }
+ }
+ });
+ }
+ }
+
+}
diff --git a/src/main/java/org/traccar/web/client/controller/MapController.java b/src/main/java/org/traccar/web/client/controller/MapController.java
new file mode 100644
index 00000000..64938830
--- /dev/null
+++ b/src/main/java/org/traccar/web/client/controller/MapController.java
@@ -0,0 +1,14 @@
+package org.traccar.web.client.controller;
+
+import org.traccar.web.client.view.MapPanel;
+
+import com.smartgwt.client.widgets.Canvas;
+
+public class MapController implements PanelController {
+
+ @Override
+ public Canvas getView() {
+ return new MapPanel();
+ }
+
+}
diff --git a/src/main/java/org/traccar/web/client/controller/PanelController.java b/src/main/java/org/traccar/web/client/controller/PanelController.java
new file mode 100644
index 00000000..6f2492aa
--- /dev/null
+++ b/src/main/java/org/traccar/web/client/controller/PanelController.java
@@ -0,0 +1,9 @@
+package org.traccar.web.client.controller;
+
+import com.smartgwt.client.widgets.Canvas;
+
+public interface PanelController {
+
+ Canvas getView();
+
+}
diff --git a/src/main/java/org/traccar/web/client/database/BaseAsyncCallback.java b/src/main/java/org/traccar/web/client/database/BaseAsyncCallback.java
new file mode 100644
index 00000000..bcc8c370
--- /dev/null
+++ b/src/main/java/org/traccar/web/client/database/BaseAsyncCallback.java
@@ -0,0 +1,19 @@
+package org.traccar.web.client.database;
+
+import org.traccar.web.client.Traccar;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.util.SC;
+
+public class BaseAsyncCallback<T> implements AsyncCallback<T> {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ SC.warn(Traccar.getConstants().remoteProcedureCallError());
+ }
+
+ @Override
+ public void onSuccess(T result) {
+ }
+
+}
diff --git a/src/main/java/org/traccar/web/client/database/DatabaseService.java b/src/main/java/org/traccar/web/client/database/DatabaseService.java
index 3c6cf095..646f7a62 100644
--- a/src/main/java/org/traccar/web/client/database/DatabaseService.java
+++ b/src/main/java/org/traccar/web/client/database/DatabaseService.java
@@ -12,12 +12,18 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("databaseService")
public interface DatabaseService extends RemoteService {
+ boolean authenticated();
+
boolean authenticate(String login, String password);
boolean register(String login, String password);
List<Device> getDevices();
+ boolean storeDevice(Device device);
+
+ boolean removeDevice(Device device);
+
List<Position> getPositions(Device device, Date from, Date to);
}
diff --git a/src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java b/src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java
index c68a35f7..7a700beb 100644
--- a/src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java
+++ b/src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java
@@ -10,12 +10,18 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
public interface DatabaseServiceAsync {
+ void authenticated(AsyncCallback<Boolean> callback);
+
void authenticate(String login, String password, AsyncCallback<Boolean> callback);
void register(String login, String password, AsyncCallback<Boolean> callback);
void getDevices(AsyncCallback<List<Device>> callback);
+ void storeDevice(Device device, AsyncCallback<Boolean> callback);
+
+ void removeDevice(Device device, AsyncCallback<Boolean> callback);
+
void getPositions(Device device, Date from, Date to, AsyncCallback<List<Position>> callback);
}
diff --git a/src/main/java/org/traccar/web/client/database/GlobalDatabaseService.java b/src/main/java/org/traccar/web/client/database/GlobalDatabaseService.java
deleted file mode 100644
index 138fa48b..00000000
--- a/src/main/java/org/traccar/web/client/database/GlobalDatabaseService.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.traccar.web.client.database;
-
-import com.google.gwt.core.client.GWT;
-
-public class GlobalDatabaseService {
-
- private static final DatabaseServiceAsync databaseService = GWT.create(DatabaseService.class);
-
- public static DatabaseServiceAsync getInstance() {
- return databaseService;
- }
-
-}
diff --git a/src/main/java/org/traccar/web/client/i18n/ApplicationConstants.java b/src/main/java/org/traccar/web/client/i18n/ApplicationConstants.java
index d11781b0..2e7c0067 100644
--- a/src/main/java/org/traccar/web/client/i18n/ApplicationConstants.java
+++ b/src/main/java/org/traccar/web/client/i18n/ApplicationConstants.java
@@ -31,6 +31,9 @@ public interface ApplicationConstants extends Constants {
@DefaultStringValue("Devices")
String devices();
+ @DefaultStringValue("Device")
+ String device();
+
@DefaultStringValue("Add")
String add();
@@ -43,13 +46,22 @@ public interface ApplicationConstants extends Constants {
@DefaultStringValue("Settings")
String settings();
+ @DefaultStringValue("Are you sure you want to remove selected device?")
+ String removeDeviceConfirmation();
+
@DefaultStringValue("Object")
String object();
@DefaultStringValue("Unique Identifier")
- String id();
+ String uniqueId();
@DefaultStringValue("Name")
String name();
+ @DefaultStringValue("Save")
+ String save();
+
+ @DefaultStringValue("Cancel")
+ String cancel();
+
}
diff --git a/src/main/java/org/traccar/web/client/login/LoginController.java b/src/main/java/org/traccar/web/client/login/LoginController.java
deleted file mode 100644
index 840bde5e..00000000
--- a/src/main/java/org/traccar/web/client/login/LoginController.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package org.traccar.web.client.login;
-
-import org.traccar.web.client.database.GlobalDatabaseService;
-import org.traccar.web.client.i18n.ApplicationConstants;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.util.SC;
-
-public class LoginController implements LoginDialog.LoginHandler {
-
- private static final ApplicationConstants constants = GWT.create(ApplicationConstants.class);
-
- private LoginDialog dialog;
-
- public interface LoginHandler {
- public void onLogin();
- }
-
- private LoginHandler loginHandler;
-
- public void login(LoginHandler loginHandler) {
- this.loginHandler = loginHandler;
-
- dialog = new LoginDialog();
- dialog.setLoginHandler(this);
- dialog.draw();
- dialog.centerInPage();
- }
-
- private boolean validate(String login, String password) {
- if (login == null || login.isEmpty() || password == null || password.isEmpty()) {
- SC.warn(constants.blankLoginPassword());
- return false;
- }
- return true;
- }
-
- private static abstract class AsyncCallbackHandler implements AsyncCallback<Boolean> {
- @Override
- public void onFailure(Throwable caught) {
- SC.warn(constants.remoteProcedureCallError());
- }
- }
-
- private final AsyncCallback<Boolean> loginCallback = new AsyncCallbackHandler() {
- @Override
- public void onSuccess(Boolean result) {
- if (result) {
- if (loginHandler != null) {
- dialog.destroy();
- loginHandler.onLogin();
- }
- } else {
- SC.warn(constants.invalidLoginPassword());
- }
- }
- };
-
- @Override
- public void onLogin(String login, String password) {
- if (validate(login, password)) {
- GlobalDatabaseService.getInstance().authenticate(login, password, loginCallback);
- }
- }
-
- private final AsyncCallback<Boolean> registerCallback = new AsyncCallbackHandler() {
- @Override
- public void onSuccess(Boolean result) {
- if (result) {
- if (loginHandler != null) {
- dialog.destroy();
- loginHandler.onLogin();
- }
- } else {
- SC.warn(constants.registrationError());
- }
- }
- };
-
- @Override
- public void onRegister(String login, String password) {
- if (validate(login, password)) {
- GlobalDatabaseService.getInstance().register(login, password, registerCallback);
- }
- }
-}
diff --git a/src/main/java/org/traccar/web/client/view/DeviceDialog.java b/src/main/java/org/traccar/web/client/view/DeviceDialog.java
new file mode 100644
index 00000000..119564ad
--- /dev/null
+++ b/src/main/java/org/traccar/web/client/view/DeviceDialog.java
@@ -0,0 +1,87 @@
+package org.traccar.web.client.view;
+
+import org.traccar.web.client.Style;
+import org.traccar.web.client.Traccar;
+import org.traccar.web.shared.model.Device;
+
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.widgets.IButton;
+import com.smartgwt.client.widgets.Window;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.TextItem;
+import com.smartgwt.client.widgets.form.fields.ToolbarItem;
+import com.smartgwt.client.widgets.layout.Layout;
+
+public class DeviceDialog extends Window {
+
+ public interface SaveHandler {
+ public void onSave(Device device);
+ }
+
+ private SaveHandler saveHandler;
+
+ public void setSaveHandler(SaveHandler saveHandler) {
+ this.saveHandler = saveHandler;
+ }
+
+ private Device device;
+
+ TextItem nameEdit;
+ TextItem uniqueIdEdit;
+
+ public void setDevice(Device device) {
+ this.device = device;
+ nameEdit.setValue(device.getName());
+ uniqueIdEdit.setValue(device.getUniqueId());
+ }
+
+ public DeviceDialog() {
+ setTitle(Traccar.getConstants().device());
+ setAutoSize(true);
+ setIsModal(true);
+
+ // Form
+ final DynamicForm form = new DynamicForm();
+ form.setHeight100();
+ form.setWidth100();
+
+ nameEdit = new TextItem();
+ nameEdit.setTitle(Traccar.getConstants().name());
+ uniqueIdEdit = new TextItem();
+ uniqueIdEdit.setTitle(Traccar.getConstants().uniqueId());
+
+ final ToolbarItem toolbarItem = new ToolbarItem();
+ toolbarItem.setButtons(
+ new IButton(Traccar.getConstants().save(), new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ if (saveHandler != null) {
+ device.setName(nameEdit.getValueAsString());
+ device.setUniqueId(uniqueIdEdit.getValueAsString());
+ saveHandler.onSave(device);
+ }
+ }
+ }),
+ new IButton(Traccar.getConstants().cancel(), new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ destroy();
+ }
+ }));
+ toolbarItem.setAlign(Alignment.RIGHT);
+ toolbarItem.setColSpan(3);
+
+ form.setFields(nameEdit, uniqueIdEdit, toolbarItem);
+ form.setCellPadding(Style.getCellPadding());
+
+ final Layout layout = new Layout();
+ layout.setPadding(Style.getPadding());
+
+ layout.addMember(form);
+
+ addItem(layout);
+ }
+
+}
diff --git a/src/main/java/org/traccar/web/client/view/DevicePanel.java b/src/main/java/org/traccar/web/client/view/DevicePanel.java
index 4296a25a..2052c996 100644
--- a/src/main/java/org/traccar/web/client/view/DevicePanel.java
+++ b/src/main/java/org/traccar/web/client/view/DevicePanel.java
@@ -4,14 +4,18 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.traccar.web.client.i18n.ApplicationConstants;
+import org.traccar.web.client.Traccar;
import org.traccar.web.shared.model.Device;
-import com.google.gwt.core.client.GWT;
import com.smartgwt.client.data.Record;
+import com.smartgwt.client.util.BooleanCallback;
+import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.events.SelectionChangedHandler;
+import com.smartgwt.client.widgets.grid.events.SelectionEvent;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
@@ -22,90 +26,134 @@ import com.smartgwt.client.widgets.toolbar.ToolStripButton;
*/
public class DevicePanel extends SectionStack {
- private static final ApplicationConstants constants = GWT.create(ApplicationConstants.class);
-
- private static final String COLUMN_OBJECT = "object";
- private static final String COLUMN_NAME = "name";
private static final String COLUMN_ID = "id";
+ private static final String COLUMN_NAME = "name";
+ private static final String COLUMN_UNIQUE_ID = "uniqueId";
+
+ public interface DeviceHandler {
+ public void onAdd();
+ public void onEdit(Device device);
+ public void onRemove(Device device);
+ }
- private ToolStrip toolbar;
+ private DeviceHandler deviceHandler;
- private ToolStripButton buttonAdd;
- private ToolStripButton buttonRemove;
- private ToolStripButton buttonEdit;
- private ToolStripButton buttonSettings;
+ public void setDeviceHandler(DeviceHandler deviceHandler) {
+ this.deviceHandler = deviceHandler;
+ }
+
+ ToolStripButton addButton;
+ ToolStripButton removeButton;
+ ToolStripButton editButton;
+ private ToolStripButton settingsButton;
private ListGrid list;
+ private Map<Long, Device> deviceMap = new HashMap<Long, Device>();
+
public DevicePanel() {
- SectionStackSection section = new SectionStackSection(constants.devices());
+ SectionStackSection section = new SectionStackSection(Traccar.getConstants().devices());
section.setCanCollapse(false);
section.setExpanded(true);
- toolbar = new ToolStrip();
+ ToolStrip toolbar = new ToolStrip();
toolbar.setWidth100();
- buttonAdd = new ToolStripButton();
- buttonAdd.setTitle(constants.add());
- toolbar.addButton(buttonAdd);
-
- buttonRemove = new ToolStripButton();
- buttonRemove.setTitle(constants.remove());
- toolbar.addButton(buttonRemove);
-
- buttonEdit = new ToolStripButton();
- buttonEdit.setTitle(constants.edit());
- toolbar.addButton(buttonEdit);
+ addButton = new ToolStripButton();
+ addButton.setTitle(Traccar.getConstants().add());
+ addButton.addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ if (deviceHandler != null) {
+ deviceHandler.onAdd();
+ }
+ }
+ });
+
+ removeButton = new ToolStripButton();
+ removeButton.setTitle(Traccar.getConstants().remove());
+ removeButton.setVisible(false);
+ removeButton.addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ SC.ask(Traccar.getConstants().removeDeviceConfirmation(), new BooleanCallback() {
+ @Override
+ public void execute(Boolean value) {
+ if (value && deviceHandler != null && list.anySelected()) {
+ deviceHandler.onRemove(deviceMap.get(list.getSelectedRecord().getAttributeAsLong(COLUMN_ID)));
+ }
+ }
+ });
+ }
+ });
+
+ editButton = new ToolStripButton();
+ editButton.setVisible(false);
+ editButton.setTitle(Traccar.getConstants().edit());
+ editButton.addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ if (deviceHandler != null && list.anySelected()) {
+ deviceHandler.onEdit(deviceMap.get(list.getSelectedRecord().getAttributeAsLong(COLUMN_ID)));
+ }
+ }
+ });
+
+ toolbar.addButton(addButton);
+ toolbar.addButton(removeButton);
+ toolbar.addButton(editButton);
toolbar.addFill();
toolbar.addSeparator();
- buttonSettings = new ToolStripButton();
- buttonSettings.setTitle(constants.settings());
- toolbar.addButton(buttonSettings);
+ settingsButton = new ToolStripButton();
+ settingsButton.setTitle(Traccar.getConstants().settings());
+ toolbar.addButton(settingsButton);
list = new ListGrid();
list.setFields(
- new ListGridField(COLUMN_NAME, constants.name()),
- new ListGridField(COLUMN_ID, constants.id()));
+ new ListGridField(COLUMN_NAME, Traccar.getConstants().name()),
+ new ListGridField(COLUMN_UNIQUE_ID, Traccar.getConstants().uniqueId()));
list.setCanSort(false);
list.setShowHeaderContextMenu(false);
list.setShowHeaderMenuButton(false);
+ list.addSelectionChangedHandler(new SelectionChangedHandler() {
+ @Override
+ public void onSelectionChanged(SelectionEvent event) {
+ removeButton.setVisible(list.anySelected());
+ editButton.setVisible(list.anySelected());
+ }
+ });
+
section.setItems(toolbar, list);
setSections(section);
}
- public void setAddClickHandler(ClickHandler handler) {
- buttonAdd.addClickHandler(handler);
- }
-
- public void setRemoveClickHandler(ClickHandler handler) {
- buttonRemove.addClickHandler(handler);
- }
-
- public void setEditClickHandler(ClickHandler handler) {
- buttonEdit.addClickHandler(handler);
- }
-
public void setSettingsClickHandler(ClickHandler handler) {
- buttonSettings.addClickHandler(handler);
+ settingsButton.addClickHandler(handler);
}
public void updateDevices(List<Device> devices) {
- // TODO: clear
+ deviceMap.clear();
+ for (Record record : list.getRecords()) {
+ list.removeData(record);
+ }
+ removeButton.setVisible(list.anySelected());
+ editButton.setVisible(list.anySelected());
for (Device device : devices) {
+ deviceMap.put(device.getId(), device);
+
Map<String, Object> map = new HashMap<String, Object>();
- //map.put(COLUMN_OBJECT, device);
+ map.put(COLUMN_ID, device.getId());
map.put(COLUMN_NAME, device.getName());
- map.put(COLUMN_ID, device.getUniqueId());
+ map.put(COLUMN_UNIQUE_ID, device.getUniqueId());
Record record = new Record(map);
list.addData(record);
}
}
-
}
diff --git a/src/main/java/org/traccar/web/client/login/LoginDialog.java b/src/main/java/org/traccar/web/client/view/LoginDialog.java
index 4e40f699..625a29b5 100644
--- a/src/main/java/org/traccar/web/client/login/LoginDialog.java
+++ b/src/main/java/org/traccar/web/client/view/LoginDialog.java
@@ -1,9 +1,9 @@
-package org.traccar.web.client.login;
+package org.traccar.web.client.view;
import org.traccar.web.client.Style;
-import org.traccar.web.client.i18n.ApplicationConstants;
+import org.traccar.web.client.Traccar;
-import com.google.gwt.core.client.GWT;
+import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
@@ -16,28 +16,38 @@ import com.smartgwt.client.widgets.layout.Layout;
public class LoginDialog extends Window {
- private static final ApplicationConstants constants = GWT.create(ApplicationConstants.class);
+ public interface LoginHandler {
+ public void onLogin(String login, String password);
+ public void onRegister(String login, String password);
+ }
+
+ private LoginHandler loginHandler;
+
+ public void setLoginHandler(LoginHandler loginHandler) {
+ this.loginHandler = loginHandler;
+ }
public LoginDialog() {
// Window properties
- setTitle(constants.userAuthentication());
+ setTitle(Traccar.getConstants().userAuthentication());
setShowCloseButton(false);
setShowMinimizeButton(false);
setAutoSize(true);
+ setIsModal(true);
// Login form
final DynamicForm form = new DynamicForm();
form.setHeight100();
form.setWidth100();
final TextItem loginEdit = new TextItem();
- loginEdit.setTitle(constants.login());
+ loginEdit.setTitle(Traccar.getConstants().login());
final PasswordItem passwordEdit = new PasswordItem();
- passwordEdit.setTitle(constants.password());
+ passwordEdit.setTitle(Traccar.getConstants().password());
final ToolbarItem toolbarItem = new ToolbarItem();
toolbarItem.setButtons(
- new IButton(constants.login(), new ClickHandler() {
+ new IButton(Traccar.getConstants().login(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (loginHandler != null) {
@@ -46,7 +56,7 @@ public class LoginDialog extends Window {
}
}
}),
- new IButton(constants.register(), new ClickHandler() {
+ new IButton(Traccar.getConstants().register(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (loginHandler != null) {
@@ -55,6 +65,8 @@ public class LoginDialog extends Window {
}
}
}));
+ toolbarItem.setAlign(Alignment.RIGHT);
+ toolbarItem.setColSpan(3);
form.setFields(loginEdit, passwordEdit, toolbarItem);
form.setCellPadding(Style.getCellPadding());
@@ -67,15 +79,4 @@ public class LoginDialog extends Window {
addItem(layout);
}
- public interface LoginHandler {
- public void onLogin(String login, String password);
- public void onRegister(String login, String password);
- }
-
- private LoginHandler loginHandler;
-
- public void setLoginHandler(LoginHandler loginHandler) {
- this.loginHandler = loginHandler;
- }
-
}
diff --git a/src/main/java/org/traccar/web/client/view/MapPanel.java b/src/main/java/org/traccar/web/client/view/MapPanel.java
index 1b883760..06bf45cc 100644
--- a/src/main/java/org/traccar/web/client/view/MapPanel.java
+++ b/src/main/java/org/traccar/web/client/view/MapPanel.java
@@ -23,7 +23,7 @@ import com.smartgwt.client.widgets.layout.SectionStackSection;
*/
public class MapPanel extends SectionStack {
- private final static int BORDER_SIZE = 1;
+ //private final static int BORDER_SIZE = 1;
private MapWidget mapWidget;
private WidgetCanvas mapWrapper;
@@ -35,10 +35,10 @@ public class MapPanel extends SectionStack {
MapWidget mapWidget = new MapWidget("100%", "100%", defaultMapOptions);
// Google layer
- /*GoogleV3Options layerOptiond = new GoogleV3Options();
- layerOptiond.setIsBaseLayer(true);
- layerOptiond.setType(GoogleV3MapType.G_NORMAL_MAP);
- GoogleV3 layer = new GoogleV3("Google", layerOptiond);*/
+ /*GoogleV3Options layerOptions = new GoogleV3Options();
+ layerOptions.setIsBaseLayer(true);
+ layerOptions.setType(GoogleV3MapType.G_NORMAL_MAP);
+ GoogleV3 layer = new GoogleV3("Google", layerOptions);*/
// Open Street Map layer
OSM layer = OSM.Mapnik("Mapnik");
diff --git a/src/main/java/org/traccar/web/server/database/DatabaseServiceImpl.java b/src/main/java/org/traccar/web/server/database/DatabaseServiceImpl.java
index 8ee9d63d..335cc171 100644
--- a/src/main/java/org/traccar/web/server/database/DatabaseServiceImpl.java
+++ b/src/main/java/org/traccar/web/server/database/DatabaseServiceImpl.java
@@ -19,6 +19,8 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class DatabaseServiceImpl extends RemoteServiceServlet implements DatabaseService {
+ private static final long serialVersionUID = 1;
+
private static final String PERSISTENCE_UNIT = "traccar";
private static final String ATTRIBUTE_USER = "user";
@@ -41,6 +43,11 @@ public class DatabaseServiceImpl extends RemoteServiceServlet implements Databas
}
@Override
+ public boolean authenticated() {
+ return (getUser() != null);
+ }
+
+ @Override
public boolean authenticate(String login, String password) {
TypedQuery<User> query = entityManager.createQuery(
"SELECT x FROM User x WHERE x.login = :login", User.class);
@@ -60,8 +67,11 @@ public class DatabaseServiceImpl extends RemoteServiceServlet implements Databas
user.setLogin(login);
user.setPassword(password);
entityManager.getTransaction().begin();
- entityManager.persist(user);
- entityManager.getTransaction().commit();
+ try {
+ entityManager.persist(user);
+ } finally {
+ entityManager.getTransaction().commit();
+ }
setUser(user);
return true;
}
@@ -69,14 +79,41 @@ public class DatabaseServiceImpl extends RemoteServiceServlet implements Databas
@Override
public List<Device> getDevices() {
User user = getUser();
- if (user != null) {
- List<Device> devices = new LinkedList<Device>();
- for (Device device : user.getDevices()) {
- devices.add(device);
+ List<Device> devices = new LinkedList<Device>();
+ for (Device device : user.getDevices()) {
+ devices.add(device);
+ }
+ return devices;
+ }
+
+ @Override
+ public boolean storeDevice(Device device) {
+ User user = getUser();
+ boolean isNew = device.getId() == 0;
+ entityManager.getTransaction().begin();
+ try {
+ device = entityManager.merge(device);
+ if (isNew) {
+ user.getDevices().add(device);
}
- return devices;
+ } finally {
+ entityManager.getTransaction().commit();
}
- return null;
+ return true;
+ }
+
+ @Override
+ public boolean removeDevice(Device device) {
+ User user = getUser();
+ entityManager.getTransaction().begin();
+ try {
+ device = entityManager.merge(device);
+ user.getDevices().remove(device);
+ entityManager.remove(device);
+ } finally {
+ entityManager.getTransaction().commit();
+ }
+ return true;
}
@Override
diff --git a/src/main/java/org/traccar/web/shared/model/Device.java b/src/main/java/org/traccar/web/shared/model/Device.java
index 3a7b05eb..32f1c1f0 100644
--- a/src/main/java/org/traccar/web/shared/model/Device.java
+++ b/src/main/java/org/traccar/web/shared/model/Device.java
@@ -12,6 +12,21 @@ import javax.persistence.Table;
@Table(name = "devices")
public class Device implements Serializable {
+ private static final long serialVersionUID = 1;
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null || obj.getClass() != this.getClass()) {
+ return false;
+ }
+ return id == ((Device) obj).id;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) id;
+ }
+
public Device() {
}
@@ -24,6 +39,10 @@ public class Device implements Serializable {
@GeneratedValue
private long id;
+ public long getId() {
+ return id;
+ }
+
@Column(unique = true)
private String uniqueId;
diff --git a/src/main/java/org/traccar/web/shared/model/Position.java b/src/main/java/org/traccar/web/shared/model/Position.java
index 17db3713..5a918cfc 100644
--- a/src/main/java/org/traccar/web/shared/model/Position.java
+++ b/src/main/java/org/traccar/web/shared/model/Position.java
@@ -15,6 +15,8 @@ import org.hibernate.annotations.Index;
@Table(name = "positions")
public class Position implements Serializable {
+ private static final long serialVersionUID = 1;
+
public Position() {
}
diff --git a/src/main/java/org/traccar/web/shared/model/User.java b/src/main/java/org/traccar/web/shared/model/User.java
index 61d6a364..181a09b6 100644
--- a/src/main/java/org/traccar/web/shared/model/User.java
+++ b/src/main/java/org/traccar/web/shared/model/User.java
@@ -14,6 +14,8 @@ import javax.persistence.Table;
@Table(name="users")
public class User implements Serializable {
+ private static final long serialVersionUID = 1;
+
public User() {
}