aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/web/client
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2012-11-18 22:49:30 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2012-11-18 22:49:30 +1300
commite081b313c717c1fb60a93f07613253f73b8cc933 (patch)
tree510c896ad15a18e6c150cd5cd0914052e4a10ad8 /src/main/java/org/traccar/web/client
parent3d63b73061d7ae7b56f6c1f5bfc265ef41981bbb (diff)
downloadtrackermap-web-e081b313c717c1fb60a93f07613253f73b8cc933.tar.gz
trackermap-web-e081b313c717c1fb60a93f07613253f73b8cc933.tar.bz2
trackermap-web-e081b313c717c1fb60a93f07613253f73b8cc933.zip
Persistence experiments
Diffstat (limited to 'src/main/java/org/traccar/web/client')
-rw-r--r--src/main/java/org/traccar/web/client/MapPanel.java29
-rw-r--r--src/main/java/org/traccar/web/client/Style.java13
-rw-r--r--src/main/java/org/traccar/web/client/Traccar.java61
-rw-r--r--src/main/java/org/traccar/web/client/database/DatabaseService.java8
-rw-r--r--src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java11
-rw-r--r--src/main/java/org/traccar/web/client/login/LoginDialog.java63
6 files changed, 138 insertions, 47 deletions
diff --git a/src/main/java/org/traccar/web/client/MapPanel.java b/src/main/java/org/traccar/web/client/MapPanel.java
index 72ed0d3b..81d842e7 100644
--- a/src/main/java/org/traccar/web/client/MapPanel.java
+++ b/src/main/java/org/traccar/web/client/MapPanel.java
@@ -1,35 +1,22 @@
package org.traccar.web.client;
-import com.smartgwt.client.widgets.layout.SectionStack;
-import com.smartgwt.client.widgets.layout.SectionStackSection;
-import com.smartgwt.client.widgets.Label;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.WidgetCanvas;
-import com.smartgwt.client.widgets.events.ResizedEvent;
-import com.smartgwt.client.widgets.events.ResizedHandler;
-import com.smartgwt.client.widgets.events.DragResizeStopEvent;
-import com.smartgwt.client.widgets.events.DragResizeStopHandler;
-import com.smartgwt.client.widgets.events.DrawEvent;
-import com.smartgwt.client.widgets.events.DrawHandler;
-import com.smartgwt.client.types.Overflow;
-
-import com.google.gwt.core.client.Scheduler;
-
import org.gwtopenmaps.openlayers.client.LonLat;
import org.gwtopenmaps.openlayers.client.Map;
import org.gwtopenmaps.openlayers.client.MapOptions;
import org.gwtopenmaps.openlayers.client.MapWidget;
import org.gwtopenmaps.openlayers.client.Projection;
-import org.gwtopenmaps.openlayers.client.control.LayerSwitcher;
-import org.gwtopenmaps.openlayers.client.control.OverviewMap;
import org.gwtopenmaps.openlayers.client.control.ScaleLine;
import org.gwtopenmaps.openlayers.client.layer.OSM;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
-
-import com.google.gwt.event.logical.shared.AttachEvent;
-import org.gwtopenmaps.openlayers.client.layer.*;
+import com.smartgwt.client.widgets.WidgetCanvas;
+import com.smartgwt.client.widgets.events.DrawEvent;
+import com.smartgwt.client.widgets.events.DrawHandler;
+import com.smartgwt.client.widgets.events.ResizedEvent;
+import com.smartgwt.client.widgets.events.ResizedHandler;
+import com.smartgwt.client.widgets.layout.SectionStack;
+import com.smartgwt.client.widgets.layout.SectionStackSection;
/**
* Map panel widget
@@ -90,7 +77,7 @@ public class MapPanel extends SectionStack {
e.getParentElement().getStyle().setProperty("width", "100%");
e.getParentElement().getStyle().setProperty("height", "100%");
}
- }
+ }
});
// Map resize handler
diff --git a/src/main/java/org/traccar/web/client/Style.java b/src/main/java/org/traccar/web/client/Style.java
new file mode 100644
index 00000000..83673906
--- /dev/null
+++ b/src/main/java/org/traccar/web/client/Style.java
@@ -0,0 +1,13 @@
+package org.traccar.web.client;
+
+public class Style {
+
+ public static int getPadding() {
+ return 10;
+ }
+
+ public static int getCellPadding() {
+ return 5;
+ }
+
+}
diff --git a/src/main/java/org/traccar/web/client/Traccar.java b/src/main/java/org/traccar/web/client/Traccar.java
index fdd8dac4..ca7cb3f4 100644
--- a/src/main/java/org/traccar/web/client/Traccar.java
+++ b/src/main/java/org/traccar/web/client/Traccar.java
@@ -1,7 +1,11 @@
package org.traccar.web.client;
+import java.util.List;
+
import org.traccar.web.client.database.DatabaseService;
import org.traccar.web.client.database.DatabaseServiceAsync;
+import org.traccar.web.client.login.LoginDialog;
+import org.traccar.web.shared.model.Device;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
@@ -20,25 +24,70 @@ public class Traccar implements EntryPoint {
/**
* Entry point method
*/
+ @Override
public void onModuleLoad() {
- DatabaseServiceAsync databaseService = GWT.create(DatabaseService.class);
+ final DatabaseServiceAsync databaseService = GWT.create(DatabaseService.class);
+
+ final AsyncCallback<List<Device>> callback2 = new AsyncCallback<List<Device>>() {
+ @Override
+ public void onFailure(Throwable caught) {
+ SC.say("onFailure2: " + caught.toString());
+ }
+ @Override
+ public void onSuccess(List<Device> result) {
+ String s = "";
+ if (result!= null) {
+ for (Device d : result) {
+ s += d.getName() + " ";
+ }
+ }
+ SC.say("Devices: " + s);
+ }
+ };
- AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
+ final AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
+ @Override
public void onFailure(Throwable caught) {
SC.say("onFailure: " + caught.toString());
}
+ @Override
public void onSuccess(Boolean result) {
- SC.say("onSuccess: " + result);
+ databaseService.getDevices(callback2);
}
};
- databaseService.authenticate("test", "test", callback);
+ final LoginDialog loginDialog = new LoginDialog();
+
+ loginDialog.setLoginHandler(new LoginDialog.LoginHandler() {
+ private boolean validate(String login, String password) {
+ if (login == null || login.isEmpty() || password == null || password.isEmpty()) {
+ SC.warn("Login and password fields must not be blank");
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void onLogin(String login, String password) {
+ if (validate(login, password)) {
+ loginDialog.destroy();
+ databaseService.authenticate(login, password, callback);
+ }
+ }
+
+ @Override
+ public void onRegister(String login, String password) {
+ if (validate(login, password)) {
+ loginDialog.destroy();
+ databaseService.register(login, password, callback);
+ }
+ }
+ });
- /*LoginDialog loginDialog = new LoginDialog();
loginDialog.draw();
- loginDialog.centerInPage();*/
+ loginDialog.centerInPage();
/*devicePanel = new DevicePanel();
devicePanel.setWidth("20%");
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 6d08a5ca..0a41ce90 100644
--- a/src/main/java/org/traccar/web/client/database/DatabaseService.java
+++ b/src/main/java/org/traccar/web/client/database/DatabaseService.java
@@ -1,5 +1,9 @@
package org.traccar.web.client.database;
+import java.util.List;
+
+import org.traccar.web.shared.model.Device;
+
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@@ -8,4 +12,8 @@ public interface DatabaseService extends RemoteService {
boolean authenticate(String login, String password);
+ boolean register(String login, String password);
+
+ List<Device> getDevices();
+
}
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 471edf00..6cf6fc48 100644
--- a/src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java
+++ b/src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java
@@ -1,10 +1,17 @@
package org.traccar.web.client.database;
+import java.util.List;
+
+import org.traccar.web.shared.model.Device;
+
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface DatabaseServiceAsync {
- void authenticate(String login, String password,
- 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);
}
diff --git a/src/main/java/org/traccar/web/client/login/LoginDialog.java b/src/main/java/org/traccar/web/client/login/LoginDialog.java
index 3ac01ccd..ba00cabc 100644
--- a/src/main/java/org/traccar/web/client/login/LoginDialog.java
+++ b/src/main/java/org/traccar/web/client/login/LoginDialog.java
@@ -1,50 +1,77 @@
package org.traccar.web.client.login;
+import org.traccar.web.client.Style;
+
+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.PasswordItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
-import com.smartgwt.client.widgets.form.fields.ButtonItem;
-import com.smartgwt.client.types.Alignment;
-import com.smartgwt.client.types.TitleOrientation;
-import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.form.fields.ToolbarItem;
-import com.smartgwt.client.widgets.IButton;
-import com.smartgwt.client.widgets.Button;
+import com.smartgwt.client.widgets.layout.Layout;
public class LoginDialog extends Window {
- private DynamicForm form;
-
- public LoginDialog() {
+ public LoginDialog() {
- // Window properties
+ // Window properties
setTitle("User Authentication");
setShowCloseButton(false);
setShowMinimizeButton(false);
setAutoSize(true);
// Login form
- form = new DynamicForm();
+ final DynamicForm form = new DynamicForm();
form.setHeight100();
form.setWidth100();
- TextItem loginEdit = new TextItem();
+ final TextItem loginEdit = new TextItem();
loginEdit.setTitle("Login");
- PasswordItem passwordEdit = new PasswordItem();
+ final PasswordItem passwordEdit = new PasswordItem();
passwordEdit.setTitle("Password");
- ToolbarItem toolbarItem = new ToolbarItem();
- toolbarItem.setButtons(new IButton("Login"), new IButton("Register"));
+ final ToolbarItem toolbarItem = new ToolbarItem();
+ toolbarItem.setButtons(
+ new IButton("Login", new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ if (loginHandler != null) {
+ loginHandler.onLogin(
+ loginEdit.getValueAsString(), passwordEdit.getValueAsString());
+ }
+ }
+ }),
+ new IButton("Register", new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ if (loginHandler != null) {
+ loginHandler.onRegister(
+ loginEdit.getValueAsString(), passwordEdit.getValueAsString());
+ }
+ }
+ }));
form.setFields(loginEdit, passwordEdit, toolbarItem);
- form.setCellPadding(5);
+ form.setCellPadding(Style.getCellPadding());
- Layout layout = new Layout();
- layout.setPadding(10);
+ final Layout layout = new Layout();
+ layout.setPadding(Style.getPadding());
layout.addMember(form);
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;
+ }
+
}