From 9cc6eebd2e4c95fa3ac633df7a4d1255a2f00c39 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 3 Nov 2012 11:02:30 +1300 Subject: Created project --- .../java/org/traccar/web/client/ArchivePanel.java | 64 ++++++++++++ .../java/org/traccar/web/client/DevicePanel.java | 54 +++++++++++ src/main/java/org/traccar/web/client/MapPanel.java | 108 +++++++++++++++++++++ src/main/java/org/traccar/web/client/Traccar.java | 49 ++++++++++ src/main/resources/org/traccar/web/Traccar.gwt.xml | 28 ++++++ .../classes/org/traccar/web/Traccar.gwt.xml | 26 +++++ .../org/traccar/web/client/Messages.properties | 2 + .../org/traccar/web/client/Messages_fr.properties | 2 + src/main/webapp/WEB-INF/jetty-web.xml | 10 ++ src/main/webapp/WEB-INF/web.xml | 33 +++++++ src/main/webapp/traccar.html | 20 ++++ .../org/traccar/web/client/GwtTestTraccar.java | 75 ++++++++++++++ src/test/realm.properties | 2 + .../resources/org/traccar/web/TraccarJUnit.gwt.xml | 9 ++ 14 files changed, 482 insertions(+) create mode 100644 src/main/java/org/traccar/web/client/ArchivePanel.java create mode 100644 src/main/java/org/traccar/web/client/DevicePanel.java create mode 100644 src/main/java/org/traccar/web/client/MapPanel.java create mode 100644 src/main/java/org/traccar/web/client/Traccar.java create mode 100644 src/main/resources/org/traccar/web/Traccar.gwt.xml create mode 100644 src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml create mode 100644 src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages.properties create mode 100644 src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages_fr.properties create mode 100644 src/main/webapp/WEB-INF/jetty-web.xml create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/traccar.html create mode 100644 src/test/java/org/traccar/web/client/GwtTestTraccar.java create mode 100644 src/test/realm.properties create mode 100644 src/test/resources/org/traccar/web/TraccarJUnit.gwt.xml (limited to 'src') diff --git a/src/main/java/org/traccar/web/client/ArchivePanel.java b/src/main/java/org/traccar/web/client/ArchivePanel.java new file mode 100644 index 00000000..d8f7ea77 --- /dev/null +++ b/src/main/java/org/traccar/web/client/ArchivePanel.java @@ -0,0 +1,64 @@ +package org.traccar.web.client; + +import com.smartgwt.client.widgets.toolbar.ToolStrip; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.layout.SectionStack; +import com.smartgwt.client.widgets.layout.SectionStackSection; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.DateTimeItem; +import com.smartgwt.client.widgets.toolbar.ToolStripButton; + +/** + * Archive widget + */ +public class ArchivePanel extends SectionStack { + + private ToolStrip toolbar; + private ListGrid list; + + public ArchivePanel() { + SectionStackSection section = new SectionStackSection("Archive"); + section.setCanCollapse(false); + section.setExpanded(true); + + toolbar = new ToolStrip(); + toolbar.setWidth100(); + + SelectItem deviceSelect = new SelectItem("device", "Device"); + //fontItem.setShowTitle(false); + //fontItem.setWidth(120); + toolbar.addFormItem(deviceSelect); + toolbar.addSeparator(); + + DateTimeItem from = new DateTimeItem("from", "From"); + toolbar.addFormItem(from); + toolbar.addSeparator(); + DateTimeItem to = new DateTimeItem("to", "To"); + toolbar.addFormItem(to); + toolbar.addSeparator(); + + ToolStripButton button = new ToolStripButton(); + button.setTitle("Load"); + toolbar.addButton(button); + + list = new ListGrid(); + list.setFields( + new ListGridField("deviceId", "Device Id"), + new ListGridField("time", "Time"), + new ListGridField("valid", "Valid"), + new ListGridField("latitude", "Latitude"), + new ListGridField("longitude", "Longitude"), + new ListGridField("speed", "Speed"), + new ListGridField("course", "Course"), + new ListGridField("power", "Power")); + + list.setCanSort(false); + list.setShowHeaderContextMenu(false); + list.setShowHeaderMenuButton(false); + + section.setItems(toolbar, list); + setSections(section); + } + +} diff --git a/src/main/java/org/traccar/web/client/DevicePanel.java b/src/main/java/org/traccar/web/client/DevicePanel.java new file mode 100644 index 00000000..ba30fefb --- /dev/null +++ b/src/main/java/org/traccar/web/client/DevicePanel.java @@ -0,0 +1,54 @@ +package org.traccar.web.client; + +import com.smartgwt.client.widgets.toolbar.ToolStrip; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.layout.SectionStack; +import com.smartgwt.client.widgets.layout.SectionStackSection; +import com.smartgwt.client.widgets.toolbar.ToolStripButton; + +/** + * Device list widget + */ +public class DevicePanel extends SectionStack { + + private ToolStrip toolbar; + private ListGrid list; + + public DevicePanel() { + SectionStackSection section = new SectionStackSection("Devices"); + section.setCanCollapse(false); + section.setExpanded(true); + + toolbar = new ToolStrip(); + toolbar.setWidth100(); + + ToolStripButton button = new ToolStripButton(); + button.setTitle("Add"); + toolbar.addButton(button); + button = new ToolStripButton(); + button.setTitle("Remove"); + toolbar.addButton(button); + button = new ToolStripButton(); + button.setTitle("Edit"); + toolbar.addButton(button); + toolbar.addFill(); + toolbar.addSeparator(); + button = new ToolStripButton(); + button.setTitle("Settings"); + toolbar.addButton(button); + + list = new ListGrid(); + list.setFields( + new ListGridField("id", "Id"), + new ListGridField("imei", "IMEI")); + + list.setCanSort(false); + list.setShowHeaderContextMenu(false); + list.setShowHeaderMenuButton(false); + + section.setItems(toolbar, list); + setSections(section); + } + +} diff --git a/src/main/java/org/traccar/web/client/MapPanel.java b/src/main/java/org/traccar/web/client/MapPanel.java new file mode 100644 index 00000000..72ed0d3b --- /dev/null +++ b/src/main/java/org/traccar/web/client/MapPanel.java @@ -0,0 +1,108 @@ +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.*; + +/** + * Map panel widget + */ +public class MapPanel extends SectionStack { + + private final static int BORDER_SIZE = 1; + + private MapWidget mapWidget; + private WidgetCanvas mapWrapper; + + private MapWidget createMapWidget() { + MapOptions defaultMapOptions = new MapOptions(); + defaultMapOptions.setNumZoomLevels(16); + + 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);*/ + + // Open Street Map layer + OSM layer = OSM.Mapnik("Mapnik"); + layer.setIsBaseLayer(true); + + Map map = mapWidget.getMap(); + map.addLayer(layer); + map.addControl(new ScaleLine()); + + // Default center + LonLat lonLat = new LonLat(12.5, 41.9); + lonLat.transform(new Projection("EPSG:4326").getProjectionCode(), map.getProjection()); + map.setCenter(lonLat, 1); + + return mapWidget; + } + + public MapPanel() { + SectionStackSection section = new SectionStackSection("Map"); + section.setCanCollapse(false); + section.setExpanded(true); + + mapWidget = createMapWidget(); + + mapWrapper = new WidgetCanvas(mapWidget); + mapWrapper.setStyleName("defaultBorder"); + mapWrapper.setHeight100(); + mapWrapper.setWidth100(); + + // Map widget size hack + mapWrapper.addDrawHandler(new DrawHandler() { + @Override + public void onDraw(DrawEvent event) { + Element e = DOM.getElementById(mapWrapper.getID() + "_widget"); + if (e.getParentNode() != null) { + e.getParentElement().getStyle().setProperty("width", "100%"); + e.getParentElement().getStyle().setProperty("height", "100%"); + } + } + }); + + // Map resize handler + mapWrapper.addResizedHandler(new ResizedHandler() { + @Override + public void onResized(ResizedEvent event) { + mapWidget.getMap().updateSize(); + } + }); + + section.setItems(mapWrapper); + setSections(section); + } + +} diff --git a/src/main/java/org/traccar/web/client/Traccar.java b/src/main/java/org/traccar/web/client/Traccar.java new file mode 100644 index 00000000..6c8cdf18 --- /dev/null +++ b/src/main/java/org/traccar/web/client/Traccar.java @@ -0,0 +1,49 @@ +package org.traccar.web.client; + +import com.google.gwt.core.client.EntryPoint; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.Overflow; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +/** + * Entry point class + */ +public class Traccar implements EntryPoint { + + private DevicePanel devicePanel; + private ArchivePanel archivePanel; + private MapPanel mapPanel; + + /** + * Entry point method + */ + public void onModuleLoad() { + + devicePanel = new DevicePanel(); + devicePanel.setWidth("20%"); + devicePanel.setShowResizeBar(true); + + mapPanel = new MapPanel(); + mapPanel.setWidth("80%"); + + HLayout hLayout = new HLayout(); + hLayout.setHeight("70%"); + hLayout.addMember(devicePanel); + hLayout.addMember(mapPanel); + hLayout.setShowResizeBar(true); + hLayout.setResizeBarTarget("next"); + + archivePanel = new ArchivePanel(); + archivePanel.setHeight("30%"); + + VLayout mainLayout = new VLayout(); + mainLayout.setWidth100(); + mainLayout.setHeight100(); + mainLayout.addMember(hLayout); + mainLayout.addMember(archivePanel); + mainLayout.draw(); + } +} diff --git a/src/main/resources/org/traccar/web/Traccar.gwt.xml b/src/main/resources/org/traccar/web/Traccar.gwt.xml new file mode 100644 index 00000000..086d2a48 --- /dev/null +++ b/src/main/resources/org/traccar/web/Traccar.gwt.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml b/src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml new file mode 100644 index 00000000..ff123394 --- /dev/null +++ b/src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages.properties b/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages.properties new file mode 100644 index 00000000..c222555b --- /dev/null +++ b/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages.properties @@ -0,0 +1,2 @@ +sendButton = Send +nameField = Enter your name \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages_fr.properties b/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages_fr.properties new file mode 100644 index 00000000..b4a76270 --- /dev/null +++ b/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages_fr.properties @@ -0,0 +1,2 @@ +sendButton = Envoyer +nameField = Entrez votre nom \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jetty-web.xml b/src/main/webapp/WEB-INF/jetty-web.xml new file mode 100644 index 00000000..f959e1b3 --- /dev/null +++ b/src/main/webapp/WEB-INF/jetty-web.xml @@ -0,0 +1,10 @@ + + + + + Test Realm + /src/test/realm.properties + + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..81fa375a --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + traccar.html + + + diff --git a/src/main/webapp/traccar.html b/src/main/webapp/traccar.html new file mode 100644 index 00000000..0bac1a44 --- /dev/null +++ b/src/main/webapp/traccar.html @@ -0,0 +1,20 @@ + + + + + Traccar + + + + + + + + + + diff --git a/src/test/java/org/traccar/web/client/GwtTestTraccar.java b/src/test/java/org/traccar/web/client/GwtTestTraccar.java new file mode 100644 index 00000000..2c6a4454 --- /dev/null +++ b/src/test/java/org/traccar/web/client/GwtTestTraccar.java @@ -0,0 +1,75 @@ +package org.traccar.web.client; + +import org.traccar.web.shared.FieldVerifier; +import com.google.gwt.core.client.GWT; +import com.google.gwt.junit.client.GWTTestCase; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.rpc.ServiceDefTarget; + +/** + * GWT JUnit integration tests must extend GWTTestCase. + * Using "GwtTest*" naming pattern exclude them from running with + * surefire during the test phase. + * + * If you run the tests using the Maven command line, you will have to + * navigate with your browser to a specific url given by Maven. + * See http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html + * for details. + */ +public class GwtTestTraccar extends GWTTestCase { + + /** + * Must refer to a valid module that sources this class. + */ + public String getModuleName() { + return "org.traccar.web.TraccarJUnit"; + } + + /** + * Tests the FieldVerifier. + */ + public void testFieldVerifier() { + assertFalse(FieldVerifier.isValidName(null)); + assertFalse(FieldVerifier.isValidName("")); + assertFalse(FieldVerifier.isValidName("a")); + assertFalse(FieldVerifier.isValidName("ab")); + assertFalse(FieldVerifier.isValidName("abc")); + assertTrue(FieldVerifier.isValidName("abcd")); + } + + /** + * This test will send a request to the server using the greetServer method in + * GreetingService and verify the response. + */ + public void testGreetingService() { + // Create the service that we will test. + GreetingServiceAsync greetingService = GWT.create(GreetingService.class); + ServiceDefTarget target = (ServiceDefTarget) greetingService; + target.setServiceEntryPoint(GWT.getModuleBaseURL() + "Traccar/greet"); + + // Since RPC calls are asynchronous, we will need to wait for a response + // after this test method returns. This line tells the test runner to wait + // up to 10 seconds before timing out. + delayTestFinish(10000); + + // Send a request to the server. + greetingService.greetServer("GWT User", new AsyncCallback() { + public void onFailure(Throwable caught) { + // The request resulted in an unexpected error. + fail("Request failure: " + caught.getMessage()); + } + + public void onSuccess(String result) { + // Verify that the response is correct. + assertTrue(result.startsWith("Hello, GWT User!")); + + // Now that we have received a response, we need to tell the test runner + // that the test is complete. You must call finishTest() after an + // asynchronous test finishes successfully, or the test will time out. + finishTest(); + } + }); + } + + +} diff --git a/src/test/realm.properties b/src/test/realm.properties new file mode 100644 index 00000000..9a068c7f --- /dev/null +++ b/src/test/realm.properties @@ -0,0 +1,2 @@ +admin: admin,admin +user: user,user diff --git a/src/test/resources/org/traccar/web/TraccarJUnit.gwt.xml b/src/test/resources/org/traccar/web/TraccarJUnit.gwt.xml new file mode 100644 index 00000000..4c957890 --- /dev/null +++ b/src/test/resources/org/traccar/web/TraccarJUnit.gwt.xml @@ -0,0 +1,9 @@ + + + + + + + + + -- cgit v1.2.3