diff options
Diffstat (limited to 'src/org/traccar/web/client/controller')
7 files changed, 0 insertions, 710 deletions
diff --git a/src/org/traccar/web/client/controller/ArchiveController.java b/src/org/traccar/web/client/controller/ArchiveController.java deleted file mode 100644 index 9a0c18d0..00000000 --- a/src/org/traccar/web/client/controller/ArchiveController.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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 java.util.Date; -import java.util.List; - -import org.traccar.web.client.Application; -import org.traccar.web.client.model.BaseAsyncCallback; -import org.traccar.web.client.model.PositionProperties; -import org.traccar.web.client.view.ArchiveView; -import org.traccar.web.shared.model.Device; -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; -import com.sencha.gxt.widget.core.client.box.AlertMessageBox; - -public class ArchiveController implements ContentController, ArchiveView.ArchiveHandler { - - public interface ArchiveHandler { - public void onSelected(Position position); - } - - private ArchiveHandler archiveHandler; - - private ListStore<Position> positionStore; - - private ArchiveView archiveView; - - public ArchiveController(ArchiveHandler archiveHandler, ListStore<Device> deviceStore) { - this.archiveHandler = archiveHandler; - PositionProperties positionProperties = GWT.create(PositionProperties.class); - positionStore = new ListStore<Position>(positionProperties.id()); - archiveView = new ArchiveView(this, positionStore, deviceStore); - } - - public ListStore<Position> getPositionStore() { - return positionStore; - } - - @Override - public ContentPanel getView() { - return archiveView.getView(); - } - - @Override - public void run() { - } - - @Override - public void onSelected(Position position) { - archiveHandler.onSelected(position); - } - - @Override - public void onLoad(Device device, Date from, Date to) { - if (device != null && from != null && to != null) { - Application.getDataService().getPositions(device, from, to, new BaseAsyncCallback<List<Position>>() { - @Override - public void onSuccess(List<Position> result) { - positionStore.clear(); - if (result.isEmpty()) { - new AlertMessageBox("Error", "No results found for selected period").show(); - } else { - positionStore.addAll(result); - } - } - }); - } else { - new AlertMessageBox("Error", "All form fields must be filled first").show(); - } - } - - @Override - public void onClear() { - positionStore.clear(); - } - - public void selectPosition(Position position) { - archiveView.selectPosition(position); - } - -} diff --git a/src/org/traccar/web/client/controller/ContentController.java b/src/org/traccar/web/client/controller/ContentController.java deleted file mode 100644 index 4fdea7c8..00000000 --- a/src/org/traccar/web/client/controller/ContentController.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 com.sencha.gxt.widget.core.client.ContentPanel; - -public interface ContentController { - - public ContentPanel getView(); - - public void run(); - -} diff --git a/src/org/traccar/web/client/controller/DeviceController.java b/src/org/traccar/web/client/controller/DeviceController.java deleted file mode 100644 index 599f7565..00000000 --- a/src/org/traccar/web/client/controller/DeviceController.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * 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 java.util.List; - -import org.traccar.web.client.Application; -import org.traccar.web.client.model.BaseAsyncCallback; -import org.traccar.web.client.model.DeviceProperties; -import org.traccar.web.client.view.DeviceDialog; -import org.traccar.web.client.view.DeviceView; -import org.traccar.web.shared.model.Device; - -import com.google.gwt.core.client.GWT; -import com.sencha.gxt.data.shared.ListStore; -import com.sencha.gxt.widget.core.client.ContentPanel; -import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton; -import com.sencha.gxt.widget.core.client.box.AlertMessageBox; -import com.sencha.gxt.widget.core.client.box.ConfirmMessageBox; -import com.sencha.gxt.widget.core.client.event.DialogHideEvent; - -public class DeviceController implements ContentController, DeviceView.DeviceHandler { - - public interface DeviceHandler { - public void onSelected(Device device); - } - - private DeviceHandler deviceHandler; - - private ListStore<Device> deviceStore; - - private DeviceView deviceView; - - public DeviceController(DeviceHandler deviceHandler, DeviceView.SettingsHandler settingsHandler) { - this.deviceHandler = deviceHandler; - DeviceProperties deviceProperties = GWT.create(DeviceProperties.class); - deviceStore = new ListStore<Device>(deviceProperties.id()); - deviceView = new DeviceView(this, settingsHandler, deviceStore); - } - - public ListStore<Device> getDeviceStore() { - return deviceStore; - } - - @Override - public ContentPanel getView() { - return deviceView.getView(); - } - - @Override - public void run() { - Application.getDataService().getDevices(new BaseAsyncCallback<List<Device>>() { - @Override - public void onSuccess(List<Device> result) { - deviceStore.addAll(result); - } - }); - } - - @Override - public void onSelected(Device device) { - deviceHandler.onSelected(device); - } - - @Override - public void onAdd() { - new DeviceDialog(new Device(), new DeviceDialog.DeviceHandler() { - @Override - public void onSave(Device device) { - Application.getDataService().addDevice(device, new BaseAsyncCallback<Device>() { - @Override - public void onSuccess(Device result) { - deviceStore.add(result); - } - @Override - public void onFailure(Throwable caught) { - new AlertMessageBox("Error", "Device with this Unique ID already exists").show(); - } - }); - } - }).show(); - } - - @Override - public void onEdit(Device device) { - new DeviceDialog(new Device(device), new DeviceDialog.DeviceHandler() { - @Override - public void onSave(Device device) { - Application.getDataService().updateDevice(device, new BaseAsyncCallback<Device>() { - @Override - public void onSuccess(Device result) { - deviceStore.update(result); - } - @Override - public void onFailure(Throwable caught) { - new AlertMessageBox("Error", "Device with this Unique ID already exists").show(); - } - }); - } - }).show(); - } - - @Override - public void onRemove(final Device device) { - final ConfirmMessageBox dialog = new ConfirmMessageBox("Confirm", "Are you sure you want remove device?"); - dialog.addDialogHideHandler(new DialogHideEvent.DialogHideHandler() { - @Override - public void onDialogHide(DialogHideEvent event) { - if (event.getHideButton() == PredefinedButton.YES) { - Application.getDataService().removeDevice(device, new BaseAsyncCallback<Device>() { - @Override - public void onSuccess(Device result) { - deviceStore.remove(device); - } - }); - } - } - }); - dialog.show(); - } - - public void selectDevice(Device device) { - deviceView.selectDevice(device); - } - -} diff --git a/src/org/traccar/web/client/controller/LoginController.java b/src/org/traccar/web/client/controller/LoginController.java deleted file mode 100644 index 1aa152b8..00000000 --- a/src/org/traccar/web/client/controller/LoginController.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.Application; -import org.traccar.web.client.ApplicationContext; -import org.traccar.web.client.model.BaseAsyncCallback; -import org.traccar.web.client.view.LoginDialog; -import org.traccar.web.shared.model.User; - -import com.sencha.gxt.widget.core.client.box.AlertMessageBox; - -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; - - Application.getDataService().authenticated(new BaseAsyncCallback<User>() { - @Override - public void onSuccess(User result) { - ApplicationContext.getInstance().setUser(result); - loginHandler.onLogin(); - } - @Override - public void onFailure(Throwable caught) { - dialog = new LoginDialog(LoginController.this); - dialog.show(); - } - }); - } - - private boolean validate(String login, String password) { - if (login == null || login.isEmpty() || password == null || password.isEmpty()) { - new AlertMessageBox("Error", "User name and password must not be empty").show(); - return false; - } - return true; - } - - @Override - public void onLogin(String login, String password) { - if (validate(login, password)) { - Application.getDataService().login(login, password, new BaseAsyncCallback<User>() { - @Override - public void onSuccess(User result) { - ApplicationContext.getInstance().setUser(result); - if (loginHandler != null) { - dialog.hide(); - loginHandler.onLogin(); - } - } - @Override - public void onFailure(Throwable caught) { - new AlertMessageBox("Error", "User name or password is invalid").show(); - } - }); - } - } - - @Override - public void onRegister(String login, String password) { - if (validate(login, password)) { - Application.getDataService().register(login, password, new BaseAsyncCallback<User>() { - @Override - public void onSuccess(User result) { - ApplicationContext.getInstance().setUser(result); - if (loginHandler != null) { - dialog.hide(); - loginHandler.onLogin(); - } - } - @Override - public void onFailure(Throwable caught) { - new AlertMessageBox("Error", "Username is already taken").show(); - } - }); - } - } - -} diff --git a/src/org/traccar/web/client/controller/MapController.java b/src/org/traccar/web/client/controller/MapController.java deleted file mode 100644 index 13c736f5..00000000 --- a/src/org/traccar/web/client/controller/MapController.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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 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; -import org.traccar.web.shared.model.Device; -import org.traccar.web.shared.model.Position; - -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, 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(MapHandler mapHandler) { - this.mapHandler = mapHandler; - mapView = new MapView(this); - } - - @Override - public ContentPanel getView() { - return mapView.getView(); - } - - private Timer updateTimer; - - @Override - public void run() { - updateTimer = new Timer() { - @Override - public void run() { - update(); - } - }; - 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 - public void onFailure(Throwable caught) { - updateTimer.schedule(UPDATE_INTERVAL); - } - }); - } - - public void selectDevice(Device device) { - mapView.selectDevice(device); - } - - public void showArchivePositions(List<Position> positions) { - List<Position> sortedPositions = new LinkedList<Position>(positions); - Collections.sort(sortedPositions, new Comparator<Position>() { - @Override - public int compare(Position o1, Position o2) { - return o1.getTime().compareTo(o2.getTime()); - } - }); - mapView.showArchivePositions(sortedPositions); - } - - public void selectArchivePosition(Position position) { - 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/SettingsController.java b/src/org/traccar/web/client/controller/SettingsController.java deleted file mode 100644 index bd20288b..00000000 --- a/src/org/traccar/web/client/controller/SettingsController.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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 java.util.List; - -import org.traccar.web.client.Application; -import org.traccar.web.client.ApplicationContext; -import org.traccar.web.client.model.BaseAsyncCallback; -import org.traccar.web.client.model.UserProperties; -import org.traccar.web.client.view.ApplicationSettingsDialog; -import org.traccar.web.client.view.DeviceView; -import org.traccar.web.client.view.UserDialog; -import org.traccar.web.client.view.UserSettingsDialog; -import org.traccar.web.client.view.UsersDialog; -import org.traccar.web.shared.model.ApplicationSettings; -import org.traccar.web.shared.model.User; -import org.traccar.web.shared.model.UserSettings; - -import com.google.gwt.core.client.GWT; -import com.sencha.gxt.data.shared.ListStore; -import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton; -import com.sencha.gxt.widget.core.client.box.AlertMessageBox; -import com.sencha.gxt.widget.core.client.box.ConfirmMessageBox; -import com.sencha.gxt.widget.core.client.event.DialogHideEvent; - -public class SettingsController implements DeviceView.SettingsHandler { - - @Override - public void onAccountSelected() { - new UserDialog( - ApplicationContext.getInstance().getUser(), - new UserDialog.UserHandler() { - @Override - public void onSave(User user) { - Application.getDataService().updateUser(user, new BaseAsyncCallback<User>() { - @Override - public void onSuccess(User result) { - ApplicationContext.getInstance().setUser(result); - } - }); - } - }).show(); - } - - @Override - public void onPreferencesSelected() { - new UserSettingsDialog( - ApplicationContext.getInstance().getUserSettings(), - new UserSettingsDialog.UserSettingsHandler() { - @Override - public void onSave(UserSettings userSettings) { - ApplicationContext.getInstance().setUserSettings(userSettings); - User user = ApplicationContext.getInstance().getUser(); - Application.getDataService().updateUser(user, new BaseAsyncCallback<User>() { - @Override - public void onSuccess(User result) { - ApplicationContext.getInstance().setUser(result); - } - }); - } - }).show(); - } - - @Override - public void onUsersSelected() { - Application.getDataService().getUsers(new BaseAsyncCallback<List<User>>() { - @Override - public void onSuccess(List<User> result) { - UserProperties userProperties = GWT.create(UserProperties.class); - final ListStore<User> userStore = new ListStore<User>(userProperties.id()); - userStore.addAll(result); - - new UsersDialog(userStore, new UsersDialog.UserHandler() { - - @Override - public void onAdd() { - new UserDialog( - new User(), - new UserDialog.UserHandler() { - @Override - public void onSave(User user) { - Application.getDataService().addUser(user, new BaseAsyncCallback<User>() { - @Override - public void onSuccess(User result) { - userStore.add(result); - } - @Override - public void onFailure(Throwable caught) { - new AlertMessageBox("Error", "Username is already taken").show(); - } - }); - } - }).show(); - } - - @Override - public void onRemove(final User user) { - final ConfirmMessageBox dialog = new ConfirmMessageBox("Confirm", "Are you sure you want remove user?"); - dialog.addDialogHideHandler(new DialogHideEvent.DialogHideHandler() { - @Override - public void onDialogHide(DialogHideEvent event) { - if (event.getHideButton() == PredefinedButton.YES) { - Application.getDataService().removeUser(user, new BaseAsyncCallback<User>() { - @Override - public void onSuccess(User result) { - userStore.remove(user); - } - }); - } - } - }); - dialog.show(); - } - - }).show(); - } - }); - } - - @Override - public void onApplicationSelected() { - new ApplicationSettingsDialog( - ApplicationContext.getInstance().getApplicationSettings(), - new ApplicationSettingsDialog.ApplicationSettingsHandler() { - @Override - public void onSave(ApplicationSettings applicationSettings) { - Application.getDataService().updateApplicationSettings(applicationSettings, new BaseAsyncCallback<ApplicationSettings>() { - @Override - public void onSuccess(ApplicationSettings result) { - ApplicationContext.getInstance().setApplicationSettings(result); - } - }); - } - }).show(); - } - -} diff --git a/src/org/traccar/web/client/controller/StateController.java b/src/org/traccar/web/client/controller/StateController.java deleted file mode 100644 index a19bec81..00000000 --- a/src/org/traccar/web/client/controller/StateController.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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(); - } - } - -} |