aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/client/view/ArchiveView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/web/client/view/ArchiveView.java')
-rw-r--r--src/org/traccar/web/client/view/ArchiveView.java88
1 files changed, 82 insertions, 6 deletions
diff --git a/src/org/traccar/web/client/view/ArchiveView.java b/src/org/traccar/web/client/view/ArchiveView.java
index 79621ba9..f61ffccc 100644
--- a/src/org/traccar/web/client/view/ArchiveView.java
+++ b/src/org/traccar/web/client/view/ArchiveView.java
@@ -4,7 +4,10 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
+import org.traccar.web.client.model.BaseStoreHandlers;
+import org.traccar.web.client.model.DeviceProperties;
import org.traccar.web.client.model.PositionProperties;
+import org.traccar.web.shared.model.Device;
import org.traccar.web.shared.model.Position;
import com.google.gwt.cell.client.DateCell;
@@ -12,15 +15,21 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
-import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Widget;
+import com.sencha.gxt.core.client.Style.SelectionMode;
import com.sencha.gxt.data.shared.ListStore;
+import com.sencha.gxt.data.shared.event.StoreHandlers;
import com.sencha.gxt.widget.core.client.ContentPanel;
+import com.sencha.gxt.widget.core.client.event.SelectEvent;
+import com.sencha.gxt.widget.core.client.form.ComboBox;
+import com.sencha.gxt.widget.core.client.form.DateField;
+import com.sencha.gxt.widget.core.client.form.TimeField;
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
import com.sencha.gxt.widget.core.client.grid.Grid;
-public class ArchiveView extends Composite {
+public class ArchiveView {
private static ArchiveViewUiBinder uiBinder = GWT.create(ArchiveViewUiBinder.class);
@@ -29,6 +38,8 @@ public class ArchiveView extends Composite {
public interface ArchiveHandler {
public void onSelected(Position position);
+ public void onLoad(Device device, Date from, Date to);
+ public void onClear();
}
private ArchiveHandler archiveHandler;
@@ -40,17 +51,40 @@ public class ArchiveView extends Composite {
return contentPanel;
}
+ ListStore<Device> deviceStore;
+
+ @UiField
+ DateField fromDate;
+
+ @UiField
+ TimeField fromTime;
+
+ @UiField
+ DateField toDate;
+
+ @UiField
+ TimeField toTime;
+
+ @UiField(provided = true)
+ ComboBox<Device> deviceCombo;
+
@UiField(provided = true)
ColumnModel<Position> columnModel;
@UiField(provided = true)
- ListStore<Position> store;
+ ListStore<Position> positionStore;
@UiField
Grid<Position> grid;
- public ArchiveView(ArchiveHandler archiveHandler) {
+ public ArchiveView(ArchiveHandler archiveHandler, ListStore<Position> positionStore, ListStore<Device> deviceStore) {
this.archiveHandler = archiveHandler;
+ this.positionStore = positionStore;
+ deviceStore.addStoreHandlers(deviceStoreHandlers);
+ this.deviceStore = deviceStore;
+
+ DeviceProperties deviceProperties = GWT.create(DeviceProperties.class);
+ deviceCombo = new ComboBox<Device>(deviceStore, deviceProperties.label());
PositionProperties positionProperties = GWT.create(PositionProperties.class);
@@ -71,9 +105,51 @@ public class ArchiveView extends Composite {
columnModel = new ColumnModel<Position>(columnConfigList);
- store = new ListStore<Position>(positionProperties.id());
-
uiBinder.createAndBindUi(this);
+
+ grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
+
+ // Initialize with current time
+ Date now = new Date();
+ fromDate.setValue(now);
+ fromTime.setValue(now);
+ toDate.setValue(now);
+ toTime.setValue(now);
+ }
+
+ @SuppressWarnings("deprecation")
+ private static Date getCombineDate(DateField dateField, TimeField timeField) {
+ Date result = null;
+ Date date = dateField.getValue();
+ Date time = timeField.getValue();
+ if (date != null && time != null) {
+ result = new Date(
+ date.getYear(), date.getMonth(), date.getDate(),
+ time.getHours(), time.getMinutes(), time.getSeconds());
+ }
+ return result;
+ }
+
+ @UiHandler("loadButton")
+ public void onLoadClicked(SelectEvent event) {
+ archiveHandler.onLoad(
+ deviceCombo.getValue(),
+ getCombineDate(fromDate, fromTime),
+ getCombineDate(toDate, toTime));
+ }
+
+ @UiHandler("clearButton")
+ public void onClearClicked(SelectEvent event) {
+ archiveHandler.onClear();
}
+ private StoreHandlers<Device> deviceStoreHandlers = new BaseStoreHandlers<Device>() {
+
+ @Override
+ public void onAnything() {
+ deviceCombo.setValue(deviceStore.findModel(deviceCombo.getValue()));
+ }
+
+ };
+
}