From e78c6edb8c7638d763cb9849f1e990e3753b1653 Mon Sep 17 00:00:00 2001 From: Slav Korolev Date: Wed, 23 Apr 2014 17:18:46 -0400 Subject: [PATCH] Issue #3054 - Fix issues in the Fog, SAFESEAS and SNOW Area configuration dialogs. Former-commit-id: 689930c4849bbf4066ff08b7bccc750b34a6615c [formerly 879a50a60209abf95752c178a0266cdd42bde012] Former-commit-id: f458f75ecf28039dfa4ca06e5146cd655e6e8c54 --- .../dialogs/FogMonitoringAreaConfigDlg.java | 28 +--- .../ui/dialogs/SSMonitoringAreaConfigDlg.java | 27 +--- .../dialogs/SnowMonitoringAreaConfigDlg.java | 21 +-- .../monitor/ui/dialogs/AddNewStationDlg.java | 75 +++-------- .../viz/monitor/ui/dialogs/AddNewZoneDlg.java | 29 ++-- .../monitor/ui/dialogs/DeleteStationDlg.java | 30 +++-- .../monitor/ui/dialogs/EditNewZoneDlg.java | 72 ++++++---- .../monitor/ui/dialogs/INewZoneStnAction.java | 27 ++-- .../ui/dialogs/MonitoringAreaConfigDlg.java | 125 +++++++++++++++--- .../config/MonitorConfigurationManager.java | 14 +- 10 files changed, 243 insertions(+), 205 deletions(-) diff --git a/cave/com.raytheon.uf.viz.monitor.fog/src/com/raytheon/uf/viz/monitor/fog/ui/dialogs/FogMonitoringAreaConfigDlg.java b/cave/com.raytheon.uf.viz.monitor.fog/src/com/raytheon/uf/viz/monitor/fog/ui/dialogs/FogMonitoringAreaConfigDlg.java index 5ea6744e5d..e3dedafe2c 100644 --- a/cave/com.raytheon.uf.viz.monitor.fog/src/com/raytheon/uf/viz/monitor/fog/ui/dialogs/FogMonitoringAreaConfigDlg.java +++ b/cave/com.raytheon.uf.viz.monitor.fog/src/com/raytheon/uf/viz/monitor/fog/ui/dialogs/FogMonitoringAreaConfigDlg.java @@ -41,6 +41,7 @@ import com.raytheon.uf.viz.monitor.ui.dialogs.MonitoringAreaConfigDlg; * Jan 5, 2010 mpduff Initial creation * Nov 27, 2012 1351 skorolev Changes for non-blocking dialog. * Jan 29, 2014 2757 skorolev Changed OK button handler. + * Apr 23, 2014 3054 skorolev Fixed issue with removing a new station from list. * * * @@ -66,22 +67,16 @@ public class FogMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { @Override protected void handleOkBtnSelection() { // Check for changes in the data - if (!configManager.getAddedZones().isEmpty() - || !configManager.getAddedStations().isEmpty() - || this.timeWindowChanged || this.shipDistanceChanged - || this.fogChkChanged || this.maZonesRemoved) { + if (dataIsChanged()) { int choice = showMessage(shell, SWT.OK | SWT.CANCEL, "Fog Monitor Confirm Changes", "Want to Update Fog Monitor's Setup files?"); if (choice == SWT.OK) { // Save the config xml file configManager.setTimeWindow(timeWindow.getSelection()); - this.timeWindowChanged = false; configManager.setShipDistance(shipDistance.getSelection()); - this.shipDistanceChanged = false; configManager.setUseAlgorithms(fogChk.getSelection()); - this.fogChkChanged = false; - this.maZonesRemoved = false; + resetStatus(); configManager.saveConfigData(); /** * DR#11279: re-initialize threshold manager and the monitor @@ -92,22 +87,7 @@ public class FogMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { if ((!configManager.getAddedZones().isEmpty()) || (!configManager.getAddedStations().isEmpty())) { - String message = "New zones have been added, the display " - + "thresholds for the new zones are set to " - + "default values, you may edit them with the display " - + "thresholds editor which can be launched from Fog Monitor " - + "zone table.\n\nIf Fog Monitor is running anywhere within " - + "the office, clear it.\n"; - - showMessage(shell, SWT.ICON_INFORMATION | SWT.OK, - "Fog Monitor Confirm Changes", message); - - String message2 = "New zones have been added, and their monitoring thresholds " - + "have been set to default values; would you like to modify " - + "their threshold values now?"; - int yesno = showMessage(shell, SWT.ICON_QUESTION | SWT.YES - | SWT.NO, "Edit Thresholds Now?", message2); - if (yesno == SWT.YES) { + if (editDialog() == SWT.YES) { FogMonDispThreshDlg fogMonitorDlg = new FogMonDispThreshDlg( shell, CommonConfig.AppName.FOG, DataUsageKey.MONITOR); diff --git a/cave/com.raytheon.uf.viz.monitor.safeseas/src/com/raytheon/uf/viz/monitor/safeseas/ui/dialogs/SSMonitoringAreaConfigDlg.java b/cave/com.raytheon.uf.viz.monitor.safeseas/src/com/raytheon/uf/viz/monitor/safeseas/ui/dialogs/SSMonitoringAreaConfigDlg.java index 2e3280a6ad..7f21dbd69a 100644 --- a/cave/com.raytheon.uf.viz.monitor.safeseas/src/com/raytheon/uf/viz/monitor/safeseas/ui/dialogs/SSMonitoringAreaConfigDlg.java +++ b/cave/com.raytheon.uf.viz.monitor.safeseas/src/com/raytheon/uf/viz/monitor/safeseas/ui/dialogs/SSMonitoringAreaConfigDlg.java @@ -41,6 +41,7 @@ import com.raytheon.uf.viz.monitor.ui.dialogs.MonitoringAreaConfigDlg; * Jan 5, 2010 mpduff Initial creation * Nov 27, 2012 1351 skorolev Changes for non-blocking dialog. * Jan 29, 2014 2757 skorolev Changed OK button handler. + * Apr 23, 2014 3054 skorolev Fixed issue with removing a new station from list. * * * @@ -73,22 +74,16 @@ public class SSMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { @Override protected void handleOkBtnSelection() { // Check for changes in the data - if (!configManager.getAddedZones().isEmpty() - || !configManager.getAddedStations().isEmpty() - || this.timeWindowChanged || this.shipDistanceChanged - || this.fogChkChanged || this.maZonesRemoved) { + if (dataIsChanged()) { int choice = showMessage(shell, SWT.OK | SWT.CANCEL, "SAFESEAS Monitor Confirm Changes", "Want to update the SAFESEAS setup files?"); if (choice == SWT.OK) { // Save the config xml file configManager.setTimeWindow(timeWindow.getSelection()); - this.timeWindowChanged = false; configManager.setShipDistance(shipDistance.getSelection()); - this.shipDistanceChanged = false; configManager.setUseAlgorithms(fogChk.getSelection()); - this.fogChkChanged = false; - this.maZonesRemoved = false; + resetStatus(); configManager.saveConfigData(); /** * DR#11279: re-initialize threshold manager and the monitor @@ -98,21 +93,7 @@ public class SSMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { SafeSeasMonitor.reInitialize(); if ((!configManager.getAddedZones().isEmpty()) || (!configManager.getAddedStations().isEmpty())) { - - String message = "You're updating the SAFESEAS monitoring settings." - + "\n\nIf SAFESEAS is running anywhere within " - + "the office, please clear it.\n"; - - showMessage(shell, SWT.OK, "SAFESEAS Config Change", - message); - - String message2 = "New zones have been added, and their monitoring thresholds " - + "have been set to default values; would you like to modify " - + "their threshold values now?"; - - int yesno = showMessage(shell, SWT.ICON_QUESTION | SWT.YES - | SWT.NO, "Edit Thresholds Now?", message2); - if (yesno == SWT.YES) { + if (editDialog() == SWT.YES) { SSDispMonThreshDlg ssMonitorDlg = new SSDispMonThreshDlg( shell, CommonConfig.AppName.SAFESEAS, DataUsageKey.MONITOR); diff --git a/cave/com.raytheon.uf.viz.monitor.snow/src/com/raytheon/uf/viz/monitor/snow/ui/dialogs/SnowMonitoringAreaConfigDlg.java b/cave/com.raytheon.uf.viz.monitor.snow/src/com/raytheon/uf/viz/monitor/snow/ui/dialogs/SnowMonitoringAreaConfigDlg.java index 74fc07479f..066f6bfc82 100644 --- a/cave/com.raytheon.uf.viz.monitor.snow/src/com/raytheon/uf/viz/monitor/snow/ui/dialogs/SnowMonitoringAreaConfigDlg.java +++ b/cave/com.raytheon.uf.viz.monitor.snow/src/com/raytheon/uf/viz/monitor/snow/ui/dialogs/SnowMonitoringAreaConfigDlg.java @@ -41,6 +41,7 @@ import com.raytheon.uf.viz.monitor.ui.dialogs.MonitoringAreaConfigDlg; * Jan 5, 2010 mpduff Initial creation * Nov 27, 2012 1351 skorolev Changes for non-blocking dialog. * Jan 29, 2014 2757 skorolev Changed OK button handler. + * Apr 23, 2014 3054 skorolev Fixed issue with removing a new station from list. * * * @@ -67,17 +68,14 @@ public class SnowMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { @Override protected void handleOkBtnSelection() { // Check for changes in the data - if (!configManager.getAddedZones().isEmpty() - || !configManager.getAddedStations().isEmpty() - || this.timeWindowChanged || this.maZonesRemoved) { + if (dataIsChanged()) { int choice = showMessage(shell, SWT.OK | SWT.CANCEL, "SNOW Monitor Confirm Changes", "Want to update the SNOW setup files?"); if (choice == SWT.OK) { // Save the config xml file configManager.setTimeWindow(timeWindow.getSelection()); - this.timeWindowChanged = false; - this.maZonesRemoved = false; + resetStatus(); configManager.saveConfigData(); /** * DR#11279: re-initialize threshold manager and the monitor @@ -88,18 +86,7 @@ public class SnowMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { if ((!configManager.getAddedZones().isEmpty()) || (!configManager.getAddedStations().isEmpty())) { - showMessage(shell, SWT.ICON_INFORMATION | SWT.OK, - "SNOW Config Change", - "You're updating the SNOW monitoring settings." - + "\n\nIf SNOW is running anywhere within " - + "the office, please clear it.\n"); - - String message2 = "New zones have been added, and their monitoring thresholds " - + "have been set to default values; would you like to modify " - + "their threshold values now?"; - int yesno = showMessage(shell, SWT.ICON_QUESTION | SWT.YES - | SWT.NO, "Edit Thresholds Now?", message2); - if (yesno == SWT.YES) { + if (editDialog() == SWT.YES) { SnowMonDispThreshDlg snowMonitorDlg = new SnowMonDispThreshDlg( shell, CommonConfig.AppName.SNOW, DataUsageKey.MONITOR); diff --git a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/AddNewStationDlg.java b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/AddNewStationDlg.java index 459e5c428a..08bf955ba2 100644 --- a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/AddNewStationDlg.java +++ b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/AddNewStationDlg.java @@ -58,6 +58,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * ------------ ---------- ----------- -------------------------- * Apr 2, 2009 lvenable Initial creation * Nov 20, 2012 1297 skorolev Changes for non-blocking dialog. + * Apr 23, 2014 3054 skorolev Added MESONET handling * * * @@ -159,7 +160,7 @@ public class AddNewStationDlg extends CaveSWTDialog { createTopLabelRadioControls(); createTextControls(); createBottomButtons(); - setStationLabel(); + stationLbl.setText("StationID:"); } /** @@ -183,30 +184,13 @@ public class AddNewStationDlg extends CaveSWTDialog { metarRdo = new Button(radioComp, SWT.RADIO); metarRdo.setText("Metar"); metarRdo.setSelection(true); - metarRdo.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent event) { - setStationLabel(); - } - }); - // TODO: Disable if area has no marine zones. + maritimeRdo = new Button(radioComp, SWT.RADIO); maritimeRdo.setText("Maritime"); maritimeRdo.setEnabled(appName != CommonConfig.AppName.SNOW); - maritimeRdo.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent event) { - setStationLabel(); - } - }); + mesonetRdo = new Button(radioComp, SWT.RADIO); mesonetRdo.setText("Mesonet"); - mesonetRdo.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent event) { - setStationLabel(); - } - }); } /** @@ -251,23 +235,22 @@ public class AddNewStationDlg extends CaveSWTDialog { if (metarRdo.getSelection()) { stationType = StationIdXML.METAR; } else if (mesonetRdo.getSelection()) { - String s = stationTF.getText(); - s = s.substring(s.indexOf("#") + 1, s.length()); - stationType = s.toUpperCase(); + stationType = StationIdXML.MESONET; // TODO need to verify the stationType exists. // was in SSmesonetStationInfo.txt in AWIPS1. } else { stationType = StationIdXML.MARITIME; } if (!stationTF.getText().isEmpty()) { - configManager.addStation(area, stationTF.getText(), - stationType, false); + configManager.addStation(area, stationTF.getText() + .toUpperCase(), stationType, false); /** * for DR #7854: add new station to Monitor Area Config GUI */ handleAddNewStation(); } else { - displayInputErrorMsg("Invalid Station ID entered: Please enter a valid Station ID for the selected Station Type"); + displayInputErrorMsg("No Station ID entered." + + "\nPlease enter a valid Station ID for the selected Station Type."); } } }); @@ -285,37 +268,28 @@ public class AddNewStationDlg extends CaveSWTDialog { }); } - /** - * Set the station label. - */ - private void setStationLabel() { - if (mesonetRdo.getSelection() == true) { - stationLbl.setText("StationID#Provider:"); - } else { - stationLbl.setText("StationID:"); - } - } - /** * Adds a new station. */ private void handleAddNewStation() { - if (!isValidStation()) { - displayInputErrorMsg("Invalid Station ID entered: Please enter a valid Station ID for the selected Station Type"); + String stn = stationTF.getText().toUpperCase(); + if (!isValidStation(stn)) { + displayInputErrorMsg("Invalid Station ID entered: " + + stn + + " \nPlease enter a valid Station ID for the selected Station Type."); return; } - String stn = stationTF.getText(); if (metarRdo.getSelection()) { stn = stn + "#METAR"; } else if (maritimeRdo.getSelection()) { stn = stn + "#MARITIME"; } else { - // TODO: Mesonet + stn = stn + "#MESONET"; } if (macDlg.isExistingStation(stn)) { - displayInputErrorMsg("The Station, " + displayInputErrorMsg("The Station '" + stn - + ", is already in your Monitoring Area or among your Additional Stations"); + + "' is already in your Monitoring Area or among your Additional Stations."); return; } macDlg.addNewStationAction(stn); @@ -325,13 +299,11 @@ public class AddNewStationDlg extends CaveSWTDialog { /** * Checks if station is valid. * + * @param stnId + * * @return boolean value */ - private boolean isValidStation() { - String stnId = stationTF.getText(); - if (stnId.contains("#") && !mesonetRdo.getSelection()) { - return false; - } + private boolean isValidStation(String stnId) { String catalogtypePhrase = ""; if (metarRdo.getSelection()) { catalogtypePhrase = "catalogtype = 1"; // METAR @@ -339,7 +311,6 @@ public class AddNewStationDlg extends CaveSWTDialog { catalogtypePhrase = "catalogtype = 33 or catalogtype = 32"; // MARITIME } else { catalogtypePhrase = "catalogtype = 1000"; // MESONET - stnId = stnId.substring(0, stnId.indexOf("#")); } try { String sql = "select stationid, catalogtype from common_obs_spatial where ( " @@ -353,11 +324,9 @@ public class AddNewStationDlg extends CaveSWTDialog { return false; } return true; - /** - * TODO: need to add code for handling Mesonet station type - */ } catch (Exception e) { - statusHandler.handle(Priority.ERROR, e.getMessage()); + statusHandler.handle(Priority.ERROR, "Can not get " + stnId + + " station in the database. ", e); } return false; } diff --git a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/AddNewZoneDlg.java b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/AddNewZoneDlg.java index d85858a9c0..96f554cb2a 100644 --- a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/AddNewZoneDlg.java +++ b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/AddNewZoneDlg.java @@ -51,6 +51,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * ------------ ---------- ----------- -------------------------- * Apr 2, 2009 lvenable Initial creation * Nov 20, 2012 1297 skorolev Changes for non-blocking dialog. + * Apr 23, 2014 3054 skorolev Deleted unnecessary parameter in addArea method. * * * @@ -225,7 +226,8 @@ public class AddNewZoneDlg extends CaveSWTDialog { gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); gd.horizontalSpan = 2; Label useDecimalLbl = new Label(textComp, SWT.CENTER); - useDecimalLbl.setText("Use Decimal Degrees, West Longitude negative"); + useDecimalLbl + .setText("Use Decimal Degrees. West Longitude is negative."); useDecimalLbl.setLayoutData(gd); } @@ -283,23 +285,19 @@ public class AddNewZoneDlg extends CaveSWTDialog { String areaId = idTF.getText(); if (areaId.equals("") || areaId.length() != 6 || (areaId.charAt(2) != 'C' && areaId.charAt(2) != 'Z')) { - displayInputErrorMsg("Invalid Area ID entered. Please enter a correctly formatted Area ID"); + displayInputErrorMsg("Invalid Area ID = '" + areaId + + "' entered. Please enter a correctly formatted Area ID."); return; } if (macDlg.isExistingZone(areaId)) { displayInputErrorMsg("The Area ID, " + areaId - + ", is already in your Monitoring Area or among your Additional Zones"); + + ", is already in your Monitoring Area or among your Additional Zones."); return; } if (latString == null || latString.isEmpty() || lonString == null || lonString.isEmpty()) { - MessageBox messageBox = new MessageBox(shell, SWT.ICON_INFORMATION - | SWT.OK); - messageBox.setText("Invalid Lat/Lon"); - messageBox - .setMessage("Invalid Lat/Lon entered. Please enter correctly formatted Lat and Lon values"); - messageBox.open(); + macDlg.latLonErrorMsg(latString, lonString); return; } else { try { @@ -311,16 +309,15 @@ public class AddNewZoneDlg extends CaveSWTDialog { type = ZoneType.MARITIME; } } - configMan.addArea(areaId, lat, lon, type, false); + if (lat > 90.0 || lat < -90.0 || lon > 180.0 || lon < -180.0) { + macDlg.latLonErrorMsg(latString, lonString); + return; + } + configMan.addArea(areaId, lat, lon, type); macDlg.addNewZoneAction(areaId, centroidLatTF.getText(), centroidLonTF.getText()); } catch (NumberFormatException e) { - MessageBox messageBox = new MessageBox(shell, - SWT.ICON_INFORMATION | SWT.OK); - messageBox.setText("Invalid Lat/Lon"); - messageBox - .setMessage("Invalid Lat/Lon entered. Please enter correctly formatted Lat and Lon values"); - messageBox.open(); + macDlg.latLonErrorMsg(latString, lonString); return; } } diff --git a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/DeleteStationDlg.java b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/DeleteStationDlg.java index 380ba8b80c..f4b55ab0bc 100644 --- a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/DeleteStationDlg.java +++ b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/DeleteStationDlg.java @@ -30,6 +30,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Layout; import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import com.raytheon.uf.common.monitor.config.FogMonitorConfigurationManager; @@ -50,6 +51,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * ------------ ---------- ----------- -------------------------- * Apr 2, 2009 lvenable Initial creation * Nov 20, 2012 1297 skorolev Changes for non-blocking dialog. + * Apr 23, 2014 3054 skorolev Fixed issue with deleting a new station. * * * @@ -155,7 +157,8 @@ public class DeleteStationDlg extends CaveSWTDialog { deleteBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - deleteSelected(); + String delStn = deleteSelected(); + setReturnValue(delStn); } }); @@ -166,7 +169,6 @@ public class DeleteStationDlg extends CaveSWTDialog { closeBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - setReturnValue(true); close(); } }); @@ -184,14 +186,26 @@ public class DeleteStationDlg extends CaveSWTDialog { /** * Delete stations from the list. */ - private void deleteSelected() { + private String deleteSelected() { + String retval = null; if (stationList.getItemCount() != 0) { - String selection = stationList.getItem(stationList - .getSelectionIndex()); - configMan.removeStation(selection); - stationList.remove(stationList.getSelectionIndex()); - populate(); + if (stationList.getSelectionIndex() != -1) { + int idx = stationList.getSelectionIndex(); + String selection = stationList.getItem(idx); + retval = configMan.getAddedStations().get(idx); + configMan.getAddedStations().remove(idx); + stationList.remove(selection); + populate(); + } else { + MessageBox messageBox = new MessageBox(shell, + SWT.ICON_INFORMATION | SWT.NONE); + messageBox.setText("Selection error."); + messageBox.setMessage("Please select station to delete."); + messageBox.open(); + stationList.select(0); + } } + return retval; } /** diff --git a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/EditNewZoneDlg.java b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/EditNewZoneDlg.java index 7dbe5dc72a..33789ed2cd 100644 --- a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/EditNewZoneDlg.java +++ b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/EditNewZoneDlg.java @@ -53,6 +53,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * ------------ ---------- ----------- -------------------------- * Apr 2, 2009 lvenable Initial creation * Nov 20, 2012 1297 skorolev Changes for non-blocking dialog. + * Apr 23, 2014 3054 skorolev Fixed issues with removing a new zone from list. * * * @@ -60,6 +61,12 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * @version 1.0 */ public class EditNewZoneDlg extends CaveSWTDialog { + + /** + * Call back interface. + */ + private INewZoneStnAction macDlg; + /** * Zone list control. */ @@ -115,6 +122,8 @@ public class EditNewZoneDlg extends CaveSWTDialog { */ private Label bottomLbl; + private String delZone; + /** * Constructor. * @@ -122,10 +131,13 @@ public class EditNewZoneDlg extends CaveSWTDialog { * Parent shell. * @param appName * Application name. + * @param monitoringAreaConfigDlg */ - public EditNewZoneDlg(Shell parent, AppName appName) { + public EditNewZoneDlg(Shell parent, AppName appName, + INewZoneStnAction macDlg) { super(parent, SWT.DIALOG_TRIM, CAVE.DO_NOT_BLOCK); setText(appName.toString() + ": Edit a Newly Added Zone"); + this.macDlg = macDlg; configMan = this.getConfigManager(appName); } @@ -279,7 +291,7 @@ public class EditNewZoneDlg extends CaveSWTDialog { deleteBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - deleteSelected(); + delZone = deleteSelected(); } }); } @@ -316,7 +328,7 @@ public class EditNewZoneDlg extends CaveSWTDialog { closeBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - setReturnValue(true); + setReturnValue(delZone); close(); } }); @@ -339,6 +351,7 @@ public class EditNewZoneDlg extends CaveSWTDialog { // DR #7343: a null areaXml causes an "Unhandled event loop exception" if (areaXml != null) { idTF.setText(areaXml.getAreaId()); + idTF.setEnabled(false); latTF.setText(String.valueOf(areaXml.getCLat())); lonTF.setText(String.valueOf(areaXml.getCLon())); if (areaXml.getType() == ZoneType.REGULAR) { @@ -354,8 +367,7 @@ public class EditNewZoneDlg extends CaveSWTDialog { /** * Delete selected zones. */ - // TODO: Delete zone from left list in the Area Configuration dialog. - private void deleteSelected() { + private String deleteSelected() { if (zoneList.getItemCount() != 0) { String area = zoneList.getItem(zoneList.getSelectionIndex()); zoneList.remove(zoneList.getSelectionIndex()); @@ -363,9 +375,11 @@ public class EditNewZoneDlg extends CaveSWTDialog { idTF.setText(""); latTF.setText(""); lonTF.setText(""); + return area; } else { bottomLbl.setText("No zones have been added."); } + return null; } /** @@ -375,28 +389,36 @@ public class EditNewZoneDlg extends CaveSWTDialog { if (zoneList.getItemCount() != 0) { String area = zoneList.getItem(zoneList.getSelectionIndex()); - double lat; - if (!latTF.getText().isEmpty()) { - lat = Double.parseDouble(latTF.getText()); + String latStr = latTF.getText(); + String lontStr = lonTF.getText(); + if (latStr == null || latStr.isEmpty() || lontStr == null + || lontStr.isEmpty()) { + macDlg.latLonErrorMsg(latStr, lontStr); + return; } else { - // wrong value will be filtered when save - lat = 9999.0; + try { + double lat = Double.parseDouble(latStr); + double lon = Double.parseDouble(lontStr); + if (lat > 90.0 || lat < -90.0 || lon > 180.0 + || lon < -180.0) { + macDlg.latLonErrorMsg(latStr, lontStr); + return; + } + ZoneType type = ZoneType.REGULAR; + if (marineRdo.getSelection()) { + type = ZoneType.MARITIME; + } + configMan.removeArea(area); + configMan.removeAddedArea(area); + configMan.addArea(area, lat, lon, type); + populate(); + // Return cursor to the top of the list. + zoneList.select(0); + } catch (NumberFormatException e) { + macDlg.latLonErrorMsg(latStr, lontStr); + return; + } } - double lon; - if (!lonTF.getText().isEmpty()) { - lon = Double.parseDouble(lonTF.getText()); - } else { - // wrong value will be filtered when save - lon = 9999.0; - } - ZoneType type = ZoneType.REGULAR; - if (marineRdo.getSelection()) { - type = ZoneType.MARITIME; - } - configMan.removeArea(area); - configMan.removeAddedArea(area); - configMan.addArea(idTF.getText(), lat, lon, type, false); - populate(); } else { bottomLbl.setText("No zones have been added."); } diff --git a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/INewZoneStnAction.java b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/INewZoneStnAction.java index e5272f9aa2..d17718dc9a 100644 --- a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/INewZoneStnAction.java +++ b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/INewZoneStnAction.java @@ -1,18 +1,19 @@ package com.raytheon.uf.viz.monitor.ui.dialogs; + /** - * Interface used for action callbacks for the Monitor Area - * Configure Dlg + * Interface used for action callbacks for the Monitor Area Configure Dlg * *
- *
+ * 
  * SOFTWARE HISTORY
- *
+ * 
  * Date         Ticket#      Engineer    Description
  * ------------ ----------   ----------- --------------------------
- * Feb 9, 2011  7854, 7855   zhao        Initial creation
- *
+ * Feb  9, 2011  7854, 7855   zhao        Initial creation
+ * Apr 24, 2014  3054         skorolev    Add an error message box action.
+ * 
  * 
- * + * * @author zhao * @version 1.0 */ @@ -21,11 +22,19 @@ public interface INewZoneStnAction { * Action to add a new zone to Monitor Area. */ public void addNewZoneAction(String id, String lat, String log); + public boolean isExistingZone(String id); - + /** * Action to add a new station to Monitor Area */ - public void addNewStationAction(String stnWithType); + public void addNewStationAction(String stnWithType); + public boolean isExistingStation(String stnWithType); + + /** + * Action to show an error message box for invalid Latitude and Longitude + * values. + */ + public void latLonErrorMsg(String latStr, String lonStr); } diff --git a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/MonitoringAreaConfigDlg.java b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/MonitoringAreaConfigDlg.java index 971b7f5cf8..274379e9ab 100644 --- a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/MonitoringAreaConfigDlg.java +++ b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/MonitoringAreaConfigDlg.java @@ -72,6 +72,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback; * Feb 06, 2013 1578 skorolev Fixed a cursor problem for checkboxes. * Oct 07, 2013 #2443 lvenable Fixed image memory leak. * Jan 29, 2014 2757 skorolev Added status variables. + * Apr 23, 2014 3054 skorolev Fixed issue with removing from list a new zone and a new station. * * * @author lvenable @@ -187,6 +188,9 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements /** monitor area stations **/ private java.util.List maStations = null; + /** monitor area stations status. */ + protected boolean maStationsRemoved = false; + /** monitor area additional zones **/ private java.util.List additionalZones = null; @@ -287,6 +291,7 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements " Error initiate Additional Zone/Stations list.", e); } Collections.sort(additionalStns); + mode = Mode.Zone; } /* @@ -565,6 +570,7 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements @Override public void widgetSelected(SelectionEvent event) { removeAssociated(); + maStationsRemoved = true; } }); /* @@ -864,25 +870,32 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements } addNewZoneDlg.open(); } else { - if (associatedList.getSelectionIndex() == -1) { - associatedList.setSelection(0); - } - String area = associatedList.getItem(associatedList - .getSelectionIndex()); - if (addNewStnDlg == null) { - addNewStnDlg = new AddNewStationDlg(shell, appName, area, this); - addNewStnDlg.setCloseCallback(new ICloseCallback() { - @Override - public void dialogClosed(Object returnValue) { - if ((Boolean) returnValue) { - // Update the dialog - populateLeftLists(); + if (associatedList.getSelectionIndex() != -1) { + String area = associatedList.getItem(associatedList + .getSelectionIndex()); + if (addNewStnDlg == null) { + addNewStnDlg = new AddNewStationDlg(shell, appName, area, + this); + addNewStnDlg.setCloseCallback(new ICloseCallback() { + @Override + public void dialogClosed(Object returnValue) { + if ((Boolean) returnValue) { + // Update the dialog + populateLeftLists(); + } + addNewStnDlg = null; } - addNewStnDlg = null; - } - }); + }); + } + addNewStnDlg.open(); + } else { + MessageBox messageBox = new MessageBox(shell, + SWT.ICON_INFORMATION | SWT.NONE); + messageBox.setText("Selection error."); + messageBox.setMessage("Please select associated zone."); + messageBox.open(); + associatedList.select(0); } - addNewStnDlg.open(); } } @@ -892,12 +905,14 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements private void handleEditDeleteAction() { if (zoneRdo.getSelection() == true) { if (editDlg == null) { - editDlg = new EditNewZoneDlg(shell, appName); + editDlg = new EditNewZoneDlg(shell, appName, this); editDlg.setCloseCallback(new ICloseCallback() { @Override public void dialogClosed(Object returnValue) { - if ((Boolean) returnValue) { - // Update the dialog + if (returnValue instanceof String) { + // Update the edit dialog + String selectedZone = returnValue.toString(); + maZones.remove(selectedZone); populateLeftLists(); } editDlg = null; @@ -911,8 +926,10 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements deleteStnDlg.setCloseCallback(new ICloseCallback() { @Override public void dialogClosed(Object returnValue) { - if ((Boolean) returnValue) { - // Update the dialog + if (returnValue instanceof String) { + // Update the delete dialog + String selectedStn = returnValue.toString(); + maStations.remove(selectedStn); populateLeftLists(); } deleteStnDlg = null; @@ -1385,4 +1402,68 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements arrowUpImg.dispose(); arrowDownImg.dispose(); } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.monitor.ui.dialogs.INewZoneStnAction#latLonErrorMsg() + */ + public void latLonErrorMsg(String latStr, String lonStr) { + MessageBox messageBox = new MessageBox(shell, SWT.ICON_INFORMATION + | SWT.OK); + messageBox.setText("Invalid Lat/Lon"); + StringBuilder errMsg = new StringBuilder("Invalid Lat/Lon entered:"); + errMsg.append("\nLatitude = "); + errMsg.append(latStr); + errMsg.append("\nLongitude = "); + errMsg.append(lonStr); + errMsg.append("\nPlease enter correctly formatted Lat and Lon values:"); + errMsg.append("\nLatitude should be between -90,90."); + errMsg.append("\nLongitude should be between -180,180."); + messageBox.setMessage(errMsg.toString()); + messageBox.open(); + } + + /** + * Reset data status. + */ + protected void resetStatus() { + this.timeWindowChanged = false; + this.maZonesRemoved = false; + this.maStationsRemoved = false; + this.shipDistanceChanged = false; + this.fogChkChanged = false; + } + + /** + * Check if data and data states have been changed. + * + * @return + */ + protected boolean dataIsChanged() { + if (!configMgr.getAddedZones().isEmpty() + || !configMgr.getAddedStations().isEmpty() + || this.timeWindowChanged || this.shipDistanceChanged + || this.fogChkChanged || this.maZonesRemoved + || this.maStationsRemoved) { + return true; + } + return false; + } + + protected int editDialog() { + showMessage(shell, SWT.ICON_INFORMATION | SWT.OK, appName + + " Config Change", "You're updating the " + appName + + " monitoring settings." + "\n\nIf " + appName + + " is running anywhere within " + + "the office, please clear it.\n"); + + String message2 = "New zones have been added, and their monitoring thresholds " + + "have been set to default values; would you like to modify " + + "their threshold values now?"; + int yesno = showMessage(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO, + "Edit Thresholds Now?", message2); + return yesno; + } } diff --git a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/MonitorConfigurationManager.java b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/MonitorConfigurationManager.java index 2a744b9cc6..b9822a1204 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/MonitorConfigurationManager.java +++ b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/MonitorConfigurationManager.java @@ -56,6 +56,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority; * Nov 20 2012 1297 skorolev Cleaned code * Oct 02 2013 2361 njensen Use JAXBManager for XML * Oct 17 2013 16682 zhao fixed a bug in readConfigXml() + * Apr 23 2014 3054 skorolev Removed unnecessary parameter in the addArea method. * * * @@ -325,11 +326,8 @@ public abstract class MonitorConfigurationManager { * The area longitude * @param type * The area type - * @param existingArea - * Does the area already exist */ - public void addArea(String areaId, double lat, double lon, ZoneType type, - boolean existingArea) { + public void addArea(String areaId, double lat, double lon, ZoneType type) { List areaXmlList = configXml.getAreaIds(); boolean areaExists = false; for (AreaIdXML area : areaXmlList) { @@ -343,10 +341,10 @@ public abstract class MonitorConfigurationManager { AreaIdXML area = new AreaIdXML(); area.setAreaId(areaId); area.setType(type); - if (lat < -90.0 || lat > 90.0) { + if (lat > -90.0 && lat < 90.0) { area.setCLat(lat); } - if (lon < -180.0 || lon > 180.0) { + if (lon > -180.0 && lon < 180.0) { area.setCLon(lon); } configXml.addAreaId(area); @@ -380,7 +378,7 @@ public abstract class MonitorConfigurationManager { stationXml.setName(stationId); stationXml.setType(type); area.addStationIdXml(stationXml); - addedStations.add(stationId); + addedStations.add(stationId + "#" + type); } } } @@ -586,7 +584,7 @@ public abstract class MonitorConfigurationManager { public AreaIdXML getAreaXml(String area) { List areaList = configXml.getAreaIds(); for (AreaIdXML areaXml : areaList) { - if (areaXml.equals(area)) { + if (areaXml.getAreaId().equals(area)) { return areaXml; } }