aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/client/controller
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-02-16 16:55:44 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-02-16 16:55:44 +1300
commit6d48729efb4bd1ac34bba003a8a4313a70a02cce (patch)
treeb834c03b8aeb3302bedb949a63f6b6d0ed4f2600 /src/org/traccar/web/client/controller
parent11b7037755c08654fba3b3781f83445244582d59 (diff)
downloadtrackermap-web-6d48729efb4bd1ac34bba003a8a4313a70a02cce.tar.gz
trackermap-web-6d48729efb4bd1ac34bba003a8a4313a70a02cce.tar.bz2
trackermap-web-6d48729efb4bd1ac34bba003a8a4313a70a02cce.zip
Handle clicks on markers (fix #8)
Diffstat (limited to 'src/org/traccar/web/client/controller')
-rw-r--r--src/org/traccar/web/client/controller/ArchiveController.java4
-rw-r--r--src/org/traccar/web/client/controller/DeviceController.java4
-rw-r--r--src/org/traccar/web/client/controller/MapController.java50
-rw-r--r--src/org/traccar/web/client/controller/StateController.java57
4 files changed, 112 insertions, 3 deletions
diff --git a/src/org/traccar/web/client/controller/ArchiveController.java b/src/org/traccar/web/client/controller/ArchiveController.java
index 11462520..553e6746 100644
--- a/src/org/traccar/web/client/controller/ArchiveController.java
+++ b/src/org/traccar/web/client/controller/ArchiveController.java
@@ -87,4 +87,8 @@ public class ArchiveController implements ContentController, ArchiveView.Archive
positionStore.clear();
}
+ public void selectPosition(Position position) {
+ archiveView.selectPosition(position);
+ }
+
}
diff --git a/src/org/traccar/web/client/controller/DeviceController.java b/src/org/traccar/web/client/controller/DeviceController.java
index 24ed2a17..75aa76fa 100644
--- a/src/org/traccar/web/client/controller/DeviceController.java
+++ b/src/org/traccar/web/client/controller/DeviceController.java
@@ -124,4 +124,8 @@ public class DeviceController implements ContentController, DeviceView.DeviceHan
dialog.show();
}
+ public void selectDevice(Device device) {
+ deviceView.selectDevice(device);
+ }
+
}
diff --git a/src/org/traccar/web/client/controller/MapController.java b/src/org/traccar/web/client/controller/MapController.java
index 44094f71..13c736f5 100644
--- a/src/org/traccar/web/client/controller/MapController.java
+++ b/src/org/traccar/web/client/controller/MapController.java
@@ -17,8 +17,10 @@ package org.traccar.web.client.controller;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import org.traccar.web.client.Application;
import org.traccar.web.client.view.MapView;
@@ -29,14 +31,22 @@ import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sencha.gxt.widget.core.client.ContentPanel;
-public class MapController implements ContentController {
+public class MapController implements ContentController, MapView.MapHandler {
private static final int UPDATE_INTERVAL = 15000;
+ public interface MapHandler {
+ public void onDeviceSelected(Device device);
+ public void onArchivePositionSelected(Position position);
+ }
+
+ private MapHandler mapHandler;
+
private MapView mapView;
- public MapController() {
- mapView = new MapView();
+ public MapController(MapHandler mapHandler) {
+ this.mapHandler = mapHandler;
+ mapView = new MapView(this);
}
@Override
@@ -57,12 +67,20 @@ public class MapController implements ContentController {
update();
}
+ private Map<Long, Position> latestPositionMap = new HashMap<Long, Position>();
+
public void update() {
updateTimer.cancel();
Application.getDataService().getLatestPositions(new AsyncCallback<List<Position>>() {
@Override
public void onSuccess(List<Position> result) {
mapView.showLatestPositions(result);
+ for (Position position : result) {
+ latestPositionMap.put(position.getDevice().getId(), position);
+ }
+ for (Map.Entry<Long, PositionUpdateHandler> entry : positionUpdateMap.entrySet()) {
+ entry.getValue().onUpdate(latestPositionMap.get(entry.getKey()));
+ }
updateTimer.schedule(UPDATE_INTERVAL);
}
@Override
@@ -91,4 +109,30 @@ public class MapController implements ContentController {
mapView.selectArchivePosition(position);
}
+ public interface PositionUpdateHandler {
+ public void onUpdate(Position position);
+ }
+
+ private Map<Long, PositionUpdateHandler> positionUpdateMap = new HashMap<Long, PositionUpdateHandler>();
+
+
+ public void registerPositionUpdate(Device device, PositionUpdateHandler handler) {
+ positionUpdateMap.put(device.getId(), handler);
+ handler.onUpdate(latestPositionMap.get(device.getId()));
+ }
+
+ public void unregisterPositionUpdate(Device device) {
+ positionUpdateMap.remove(device.getId());
+ }
+
+ @Override
+ public void onPositionSelected(Position position) {
+ mapHandler.onDeviceSelected(position.getDevice());
+ }
+
+ @Override
+ public void onArchivePositionSelected(Position position) {
+ mapHandler.onArchivePositionSelected(position);
+ }
+
}
diff --git a/src/org/traccar/web/client/controller/StateController.java b/src/org/traccar/web/client/controller/StateController.java
new file mode 100644
index 00000000..a19bec81
--- /dev/null
+++ b/src/org/traccar/web/client/controller/StateController.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.web.client.controller;
+
+import org.traccar.web.client.model.StateItem;
+import org.traccar.web.client.model.StateItemProperties;
+import org.traccar.web.client.model.StateReader;
+import org.traccar.web.client.view.StateView;
+import org.traccar.web.shared.model.Position;
+
+import com.google.gwt.core.client.GWT;
+import com.sencha.gxt.data.shared.ListStore;
+import com.sencha.gxt.widget.core.client.ContentPanel;
+
+public class StateController implements ContentController {
+
+ private ListStore<StateItem> stateStore;
+
+ private StateView stateView;
+
+ public StateController() {
+ StateItemProperties stateItemProperties = GWT.create(StateItemProperties.class);
+ stateStore = new ListStore<StateItem>(stateItemProperties.id());
+ stateView = new StateView(stateStore);
+ }
+
+ @Override
+ public ContentPanel getView() {
+ return stateView.getView();
+ }
+
+ @Override
+ public void run() {
+ }
+
+ public void showState(Position position) {
+ if (position != null) {
+ stateStore.replaceAll(StateReader.getState(position));
+ } else {
+ stateStore.clear();
+ }
+ }
+
+}