From c69cbc10be5a4f8f577fd69f948149d0e3a578f8 Mon Sep 17 00:00:00 2001 From: Slav Korolev Date: Mon, 24 Nov 2014 09:44:29 -0500 Subject: [PATCH] Omaha #3841 - Updated the dialogs for adding and editing a new zone/station. Former-commit-id: 8763f67abf5211622fe5e19009cc7b4e87633ae7 [formerly 5a7e13b6a6db5ca766da3ad957c12077470359e7] Former-commit-id: dc1722a8b7b25f74f238e7a75406e48f342468c6 --- .../dialogs/FogMonitoringAreaConfigDlg.java | 20 +- .../ui/dialogs/SSMonitoringAreaConfigDlg.java | 14 +- .../dialogs/SnowMonitoringAreaConfigDlg.java | 12 +- .../uf/viz/monitor/data/TableUtil.java | 32 +++- .../monitor/ui/dialogs/AddNewStationDlg.java | 5 +- .../viz/monitor/ui/dialogs/AddNewZoneDlg.java | 70 +++---- .../monitor/ui/dialogs/DeleteStationDlg.java | 5 +- .../monitor/ui/dialogs/EditNewZoneDlg.java | 171 ++++++++++-------- .../ui/dialogs/MonitoringAreaConfigDlg.java | 95 ++++++++-- .../uf/common/monitor/MonitorAreaUtils.java | 8 +- .../FSSObsMonitorConfigurationManager.java | 49 +++-- 11 files changed, 285 insertions(+), 196 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 fec8226307..07b4932d45 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 @@ -50,6 +50,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback; * Sep 19, 2014 2757 skorolev Updated handlers for dialog buttons. * Oct 16, 2014 3220 skorolev Corrected getInstance() method. * Oct 27, 2014 3667 skorolev Cleaned code. + * Nov 21, 2014 3841 skorolev Corrected handleOkBtnSelection. * * * @@ -85,13 +86,8 @@ public class FogMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { "Fog Monitor Confirm Changes", "Save changes?"); if (choice == SWT.YES) { // Save the config xml file. - resetAndSave(); - /** - * DR#11279: re-initialize threshold manager and the monitor - * using new monitor area configuration - */ + saveConfigs(); FogThresholdMgr.reInitialize(); - fireConfigUpdateEvent(); // Open Threshold Dialog if zones/stations are added. if ((!configMgr.getAddedZones().isEmpty()) || (!configMgr.getAddedStations().isEmpty())) { @@ -101,19 +97,19 @@ public class FogMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { fogMonitorDlg.setCloseCallback(new ICloseCallback() { @Override public void dialogClosed(Object returnValue) { - // Clean added zones and stations. Close dialog. - configMgr.getAddedZones().clear(); - configMgr.getAddedStations().clear(); setReturnValue(true); close(); } }); fogMonitorDlg.open(); } - // Clean added zones and stations. - configMgr.getAddedZones().clear(); - configMgr.getAddedStations().clear(); } + /** + * DR#11279: re-initialize threshold manager and the monitor + * using new monitor area configuration + */ + fireConfigUpdateEvent(); + resetParams(); } else { // Return back to continue edit. return; } 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 9ae677f9a4..db2422c0de 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 @@ -50,6 +50,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback; * Sep 19, 2014 2757 skorolev Updated handlers for dialog buttons. * Oct 16, 2014 3220 skorolev Corrected getInstance() method. * Oct 27, 2014 3667 skorolev Cleaned code. + * Nov 21, 2014 3841 skorolev Corrected handleOkBtnSelection. * * * @@ -80,12 +81,11 @@ public class SSMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { "SAFESEAS Monitor Confirm Changes", "Save changes?"); if (choice == SWT.YES) { // Save the config xml file. - resetAndSave(); + saveConfigs(); SSThresholdMgr.reInitialize(); - fireConfigUpdateEvent(); - // Open Threshold Dialog if zones/stations are added. if ((!configMgr.getAddedZones().isEmpty()) || (!configMgr.getAddedStations().isEmpty())) { + // Open Threshold Dialog if zones/stations are added. if (editDialog() == SWT.YES) { ssMonitorDlg = new SSDispMonThreshDlg(shell, CommonConfig.AppName.SAFESEAS, @@ -93,19 +93,15 @@ public class SSMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { ssMonitorDlg.setCloseCallback(new ICloseCallback() { @Override public void dialogClosed(Object returnValue) { - // Clean added zones and stations. Close dialog. - configMgr.getAddedZones().clear(); - configMgr.getAddedStations().clear(); setReturnValue(true); close(); } }); ssMonitorDlg.open(); } - // Clean added zones and stations. - configMgr.getAddedZones().clear(); - configMgr.getAddedStations().clear(); } + fireConfigUpdateEvent(); + resetParams(); } else { // Return back to continue edit. return; } 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 9cebab2fb8..25801c9121 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 @@ -50,6 +50,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback; * Sep 19, 2014 2757 skorolev Updated handlers for dialog buttons. * Oct 16, 2014 3220 skorolev Corrected getInstance() method. * Oct 27, 2014 3667 skorolev Cleaned code. + * Nov 21, 2014 3841 skorolev Corrected handleOkBtnSelection. * * * @@ -85,9 +86,8 @@ public class SnowMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { "SNOW Monitor Confirm Changes", "Save changes?"); if (choice == SWT.YES) { // Save the config xml file. - resetAndSave(); + saveConfigs(); SnowThresholdMgr.reInitialize(); - fireConfigUpdateEvent(); // Open Threshold Dialog if zones/stations are added. if ((!configMgr.getAddedZones().isEmpty()) || (!configMgr.getAddedStations().isEmpty())) { @@ -102,19 +102,15 @@ public class SnowMonitoringAreaConfigDlg extends MonitoringAreaConfigDlg { @Override public void dialogClosed(Object returnValue) { - // Clean added zones and stations. Close dialog. - configMgr.getAddedZones().clear(); - configMgr.getAddedStations().clear(); setReturnValue(true); close(); } }); snowMonitorDlg.open(); } - // Clean added zones and stations. - configMgr.getAddedZones().clear(); - configMgr.getAddedStations().clear(); } + fireConfigUpdateEvent(); + resetParams(); } else { // Return back to continue edit. return; } diff --git a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/data/TableUtil.java b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/data/TableUtil.java index 3f5cf9ffce..9dbfbf0fbd 100644 --- a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/data/TableUtil.java +++ b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/data/TableUtil.java @@ -25,10 +25,12 @@ import java.util.Date; import com.raytheon.uf.common.geospatial.ISpatialQuery; import com.raytheon.uf.common.geospatial.SpatialQueryFactory; import com.raytheon.uf.common.monitor.MonitorAreaUtils; +import com.raytheon.uf.common.monitor.config.FSSObsMonitorConfigurationManager; import com.raytheon.uf.common.monitor.data.CommonConfig; import com.raytheon.uf.common.monitor.data.CommonConfig.AppName; import com.raytheon.uf.common.monitor.data.ObConst; import com.raytheon.uf.common.monitor.data.ObConst.DataUsageKey; +import com.raytheon.uf.common.monitor.xml.AreaIdXML; import com.raytheon.uf.viz.monitor.config.CommonTableConfig; import com.raytheon.uf.viz.monitor.config.CommonTableConfig.CellType; import com.raytheon.uf.viz.monitor.config.CommonTableConfig.ObsHistType; @@ -50,6 +52,7 @@ import com.raytheon.uf.viz.monitor.util.MonitorConfigConstants; * May 23, 2012 14410 zhao Modified getCellTypeForBlizWarn and getCellTypeForHsnowWarn modules * Feb 28, 2013 14410 zhao Modified getCellTypeForBlizWarn * May 23, 2014 3086 skorolev Corrected ObsHistType. Cleaned code. + * Nov 21, 2014 3841 skorolev Added coordinates in the hover text for a newly added zones. * * * @@ -112,7 +115,11 @@ public final class TableUtil { String hoverText = null; if (isZone) { - hoverText = getZoneHoverText(areaId); + AreaIdXML zoneXML = FSSObsMonitorConfigurationManager + .getSsObsManager().getAreaXml(zone); + if (zoneXML != null) { + hoverText = getZoneHoverText(zoneXML); + } } else { hoverText = getStationHoverText(areaId); } @@ -320,7 +327,8 @@ public final class TableUtil { * dialog) * @param zone * @param report - * @param tm Abstract Threshold Manager + * @param tm + * Abstract Threshold Manager * @param fogCellType * @return */ @@ -338,7 +346,11 @@ public final class TableUtil { String hoverText = null; if (isZone) { - hoverText = getZoneHoverText(areaId); + AreaIdXML zoneXML = FSSObsMonitorConfigurationManager + .getSsObsManager().getAreaXml(zone); + if (zoneXML != null) { + hoverText = getZoneHoverText(zoneXML); + } } else { hoverText = getStationHoverText(areaId); } @@ -639,7 +651,11 @@ public final class TableUtil { String hoverText = null; if (isZone) { - hoverText = getZoneHoverText(areaId); + AreaIdXML zoneXML = FSSObsMonitorConfigurationManager + .getSsObsManager().getAreaXml(zone); + if (zoneXML != null) { + hoverText = getZoneHoverText(zoneXML); + } } else { hoverText = getStationHoverText(areaId); } @@ -884,8 +900,9 @@ public final class TableUtil { * @param zone * @return */ - private static String getZoneHoverText(String zone) { + private static String getZoneHoverText(AreaIdXML zoneXML) { + String zone = zoneXML.getAreaId(); ISpatialQuery sq = null; String sql = null; String hoverText = zone.substring(0, 2) + ", "; @@ -914,6 +931,11 @@ public final class TableUtil { } else { hoverText += (String) results[0].toString(); } + } else { + if (zoneXML.getCLat() != null) { + hoverText += "(" + zoneXML.getCLat() + ", " + + zoneXML.getCLon() + ")"; + } } } catch (Exception e) { e.printStackTrace(); 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 a1b6dd37b2..9e5d768b4d 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 @@ -56,6 +56,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * Nov 20, 2012 1297 skorolev Changes for non-blocking dialog. * Apr 23, 2014 3054 skorolev Added MESONET handling. * Apr 28, 2014 3086 skorolev Removed local getAreaConfigMgr method. + * Nov 21, 2014 3841 skorolev Corrected handleAddNewStation method. * * * @@ -261,8 +262,8 @@ public class AddNewStationDlg extends CaveSWTDialog { return; } macDlg.addNewStationAction(stn); - macDlg.getInstance().addStation(area, stn, type, false); - macDlg.getInstance().getStations().add(stn); + macDlg.configMgr.addStation(area, stn, type, false); + macDlg.configMgr.getStations().add(stn); } /** 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 4b5a8c87a2..02766e0a78 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 @@ -28,7 +28,6 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Layout; -import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; @@ -49,6 +48,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * Nov 20, 2012 1297 skorolev Changes for non-blocking dialog. * Apr 23, 2014 3054 skorolev Deleted unnecessary parameter in addArea method. * Apr 28, 2014 3086 skorolev Removed local getAreaConfigMgr method. + * Nov 21, 2014 3841 skorolev Corrected handleAddNewAction method. * * * @@ -234,9 +234,12 @@ public class AddNewZoneDlg extends CaveSWTDialog { addBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { + String areaId = idTF.getText(); String latString = centroidLatTF.getText(); String lonString = centroidLonTF.getText(); - handleAddNewAction(latString, lonString); + if (macDlg.formIsValid(areaId, latString, lonString)) { + handleAddNewAction(areaId, latString, lonString); + } } }); @@ -256,61 +259,32 @@ public class AddNewZoneDlg extends CaveSWTDialog { /** * Adds a new zone. * + * @param areaId * @param latString * @param lonString + * @throws NumberFormatException */ - private void handleAddNewAction(String latString, String lonString) { - String areaId = idTF.getText(); - if (areaId.equals("") || areaId.length() != 6 - || (areaId.charAt(2) != 'C' && areaId.charAt(2) != 'Z')) { - displayInputErrorMsg("Invalid Area ID = '" + areaId - + "' entered. Please enter a correctly formatted Area ID."); - return; - } + private void handleAddNewAction(String areaId, String latString, + String lonString) throws NumberFormatException { if (macDlg.isExistingZone(areaId)) { - displayInputErrorMsg("The Area ID, " + macDlg.displayInputErrorMsg("The Area ID, " + areaId + ", is already in your Monitoring Area or among your Additional Zones."); return; } - if (latString == null || latString.isEmpty() || lonString == null - || lonString.isEmpty()) { - macDlg.latLonErrorMsg(latString, lonString); - return; - } else { - try { - double lat = Double.parseDouble(latString.trim()); - double lon = Double.parseDouble(lonString.trim()); - ZoneType type = ZoneType.REGULAR; - if (appName != AppName.SNOW) { - if (marineZoneRdo.getSelection()) { - type = ZoneType.MARITIME; - } - } - if (lat > 90.0 || lat < -90.0 || lon > 180.0 || lon < -180.0) { - macDlg.latLonErrorMsg(latString, lonString); - return; - } - macDlg.configMgr.addArea(areaId, lat, lon, type); - macDlg.addNewZoneAction(areaId, centroidLatTF.getText(), - centroidLonTF.getText()); - } catch (NumberFormatException e) { - macDlg.latLonErrorMsg(latString, lonString); - return; + double lat = Double.parseDouble(latString.trim()); + double lon = Double.parseDouble(lonString.trim()); + ZoneType type = ZoneType.REGULAR; + if (appName != AppName.SNOW) { + if (marineZoneRdo.getSelection() || idTF.getText().charAt(2) == 'Z') { + type = ZoneType.MARITIME; } } - } - - /** - * Displays Input Error Message - * - * @param msg - */ - private void displayInputErrorMsg(String msg) { - MessageBox messageBox = new MessageBox(shell, SWT.ICON_INFORMATION - | SWT.OK); - messageBox.setText("Invalid input"); - messageBox.setMessage(msg); - messageBox.open(); + if (lat > 90.0 || lat < -90.0 || lon > 180.0 || lon < -180.0) { + macDlg.latLonErrorMsg(latString, lonString); + return; + } + macDlg.configMgr.addArea(areaId, lat, lon, type); + macDlg.addZoneToMA(areaId); } } 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 c7955eef71..1148f91e7d 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 @@ -50,6 +50,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * Nov 20, 2012 1297 skorolev Changes for non-blocking dialog. * Apr 23, 2014 3054 skorolev Fixed issue with deleting a new station. * Apr 28, 2014 3086 skorolev Removed local getAreaConfigMgr method. + * Nov 21, 2014 3841 skorolev Corrected deleteSelected method. * * * @@ -189,8 +190,8 @@ public class DeleteStationDlg extends CaveSWTDialog { if (stationList.getSelectionIndex() != -1) { int idx = stationList.getSelectionIndex(); String selection = stationList.getItem(idx); - retval = configMgr.getAddedStations().get(idx); - configMgr.getAddedStations().remove(idx); + retval = macDlg.configMgr.getAddedStations().get(idx); + macDlg.configMgr.getAddedStations().remove(idx); stationList.remove(selection); populate(); } else { 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 d3822667e7..71e0ff92c6 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 @@ -19,6 +19,8 @@ **/ package com.raytheon.uf.viz.monitor.ui.dialogs; +import java.util.ArrayList; + import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -37,6 +39,7 @@ import org.eclipse.swt.widgets.Text; import com.raytheon.uf.common.monitor.data.CommonConfig.AppName; import com.raytheon.uf.common.monitor.xml.AreaIdXML; import com.raytheon.uf.common.monitor.xml.AreaIdXML.ZoneType; +import com.raytheon.uf.common.monitor.xml.StationIdXML; import com.raytheon.viz.ui.dialogs.CaveSWTDialog; /** @@ -53,6 +56,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * Apr 23, 2014 3054 skorolev Fixed issues with removing a new zone from list. * Apr 28, 2014 3086 skorolev Removed local getAreaConfigMgr method. * Nov 10, 2014 3741 skorolev Fixed configXML issue. + * Nov 21, 2014 3841 skorolev Content of ID field made an editable. * * * @@ -85,17 +89,11 @@ public class EditNewZoneDlg extends CaveSWTDialog { /** Control font. */ private Font controlFont; - /** Marine station radio button. */ - private Button marineRdo; - - /** None Marine station radio button. */ - private Button nonMarineRdo; - /** Bottom label */ private Label bottomLbl; /** Deleted zone */ - private String delZone; + private boolean delZone = false; /** * Constructor. @@ -227,21 +225,6 @@ public class EditNewZoneDlg extends CaveSWTDialog { lonTF = new Text(textButtonComp, SWT.BORDER); lonTF.setLayoutData(gd); - gd = new GridData(); - gd.horizontalSpan = 2; - gd.verticalIndent = 15; - marineRdo = new Button(textButtonComp, SWT.RADIO); - marineRdo.setLayoutData(gd); - marineRdo.setSelection(false); - marineRdo.setText("Marine Station"); - - gd = new GridData(); - gd.horizontalSpan = 2; - nonMarineRdo = new Button(textButtonComp, SWT.RADIO); - nonMarineRdo.setLayoutData(gd); - nonMarineRdo.setSelection(true); - nonMarineRdo.setText("Non-Marine Station"); - gd = new GridData(SWT.CENTER, SWT.DEFAULT, false, true); gd.widthHint = 80; gd.verticalIndent = 5; @@ -251,7 +234,17 @@ public class EditNewZoneDlg extends CaveSWTDialog { saveBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - saveSelected(); + if (zoneList.getItemCount() != 0) { + String area = zoneList.getItem(zoneList.getSelectionIndex()); + String areaStr = idTF.getText(); + String latStr = latTF.getText(); + String lonStr = lonTF.getText(); + if (macDlg.formIsValid(areaStr, latStr, lonStr)) { + saveSelected(area, areaStr, latStr, lonStr); + } + } else { + bottomLbl.setText("No zones have been edited."); + } } }); gd = new GridData(SWT.CENTER, SWT.DEFAULT, false, true); @@ -310,7 +303,21 @@ public class EditNewZoneDlg extends CaveSWTDialog { * Populate list of added zones. */ private void populate() { - java.util.List newList = macDlg.configMgr.getAddedZones(); + java.util.List newList = new ArrayList(); + java.util.List maList = macDlg.configMgr.getConfigXml() + .getAreaIds(); + for (AreaIdXML maZone : maList) { + if (maZone.getCLat() != null) { + newList.add(maZone.getAreaId()); + } + } + java.util.List adtnlList = macDlg.configMgr + .getAdjAreaConfigXml().getAreaIds(); + for (AreaIdXML aZone : adtnlList) { + if (aZone.getCLat() != null) { + newList.add(aZone.getAreaId()); + } + } zoneList.setItems(newList.toArray(new String[newList.size()])); } @@ -320,26 +327,25 @@ public class EditNewZoneDlg extends CaveSWTDialog { private void handleZoneSelection() { String zone = zoneList.getItem(zoneList.getSelectionIndex()); AreaIdXML areaXml = macDlg.configMgr.getAreaXml(zone); + AreaIdXML adjAreaXml = macDlg.configMgr.getAdjAreaXML(zone); // DR #7343: a null areaXml causes an "Unhandled event loop exception" if (areaXml != null) { idTF.setText(areaXml.getAreaId()); - idTF.setEnabled(false); + // idTF.setEnabled(false); latTF.setText(String.valueOf(areaXml.getCLat())); lonTF.setText(String.valueOf(areaXml.getCLon())); - if (areaXml.getType() == ZoneType.REGULAR) { - nonMarineRdo.setSelection(true); - marineRdo.setSelection(false); - } else { - nonMarineRdo.setSelection(false); - marineRdo.setSelection(true); - } + } else if (adjAreaXml != null) { + idTF.setText(adjAreaXml.getAreaId()); + // idTF.setEnabled(false); + latTF.setText(String.valueOf(adjAreaXml.getCLat())); + lonTF.setText(String.valueOf(adjAreaXml.getCLon())); } } /** * Delete selected zones. */ - private String deleteSelected() { + private Boolean deleteSelected() { if (zoneList.getItemCount() != 0) { if (zoneList.getSelectionIndex() == -1) { MessageBox messageBox = new MessageBox(shell, @@ -348,62 +354,81 @@ public class EditNewZoneDlg extends CaveSWTDialog { messageBox.setMessage("Please select zone to be deleted."); messageBox.open(); zoneList.select(0); - return null; + return false; } String area = zoneList.getItem(zoneList.getSelectionIndex()); zoneList.remove(zoneList.getSelectionIndex()); - macDlg.configMgr.removeArea(area); idTF.setText(""); latTF.setText(""); lonTF.setText(""); - return area; + if (macDlg.getMaZones().contains(area)) { + macDlg.getMaZones().remove(area); + macDlg.configMgr.removeArea(area); + } + if (macDlg.getAdditionalZones().contains(area)) { + macDlg.getAdditionalZones().remove(area); + macDlg.configMgr.removeAdjArea(area); + } + macDlg.maZonesRemoved = true; + return true; } else { bottomLbl.setText("No zones have been deleted."); } - return null; + return false; } /** * Save selected zones. */ - private void saveSelected() { + /** + * @param area + * Original zone ID + * @param areaStr + * New zone ID + * @param latStr + * Latitude + * @param lonStr + * Longitude + * @throws NumberFormatException + */ + private void saveSelected(String area, String areaStr, String latStr, + String lonStr) throws NumberFormatException { - if (zoneList.getItemCount() != 0) { - String area = zoneList.getItem(zoneList.getSelectionIndex()); - String latStr = latTF.getText(); - String lontStr = lonTF.getText(); - if (latStr == null || latStr.isEmpty() || lontStr == null - || lontStr.isEmpty()) { - macDlg.latLonErrorMsg(latStr, lontStr); - return; - } else { - 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; - } - // Replace previously added zone - macDlg.configMgr.removeArea(area); - macDlg.configMgr.removeAddedArea(area); - macDlg.configMgr.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; - } - } - } else { - bottomLbl.setText("No zones have been edited."); + ArrayList stationIds = macDlg.configMgr.getAreaXml(area) + .getStationIds(); + + double lat = Double.parseDouble(latStr); + double lon = Double.parseDouble(lonStr); + if (lat > 90.0 || lat < -90.0 || lon > 180.0 || lon < -180.0) { + macDlg.latLonErrorMsg(latStr, lonStr); + return; } + ZoneType type = ZoneType.REGULAR; + if (areaStr.charAt(2) != 'C') { + type = (ZoneType.MARITIME); + } + AreaIdXML areaXML = new AreaIdXML(); + areaXML.setAreaId(areaStr); + areaXML.setCLat(lat); + areaXML.setCLon(lon); + areaXML.setType(type); + areaXML.setStationIds(stationIds); + // Replace previously added zone + if (macDlg.configMgr.getAreaList().contains(area)) { + if (macDlg.getMaZones().contains(area)) { + macDlg.getMaZones().remove(area); + } + macDlg.configMgr.removeAddedArea(area); + macDlg.configMgr.removeArea(area); + macDlg.configMgr.addArea(areaXML); + } else if (macDlg.getAdditionalZones().contains(area)) { + macDlg.getAdditionalZones().remove(area); + macDlg.configMgr.removeAdjArea(area); + macDlg.configMgr.addAdjArea(areaXML); + } + populate(); + // Return cursor to the list. + zoneList.select(zoneList.indexOf(areaStr)); } /* 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 6550918196..cd63a81cbd 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 @@ -45,7 +45,7 @@ import org.eclipse.swt.widgets.Text; import com.raytheon.uf.common.monitor.config.FSSObsMonitorConfigurationManager; import com.raytheon.uf.common.monitor.data.CommonConfig; import com.raytheon.uf.common.monitor.data.CommonConfig.AppName; -import com.raytheon.uf.common.monitor.xml.AreaIdXML.ZoneType; +import com.raytheon.uf.common.monitor.xml.AreaIdXML; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -78,6 +78,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback; * Sep 24, 2014 2757 skorolev Fixed problem with adding and removing zones. * Oct 27, 2014 3667 skorolev Corrected functionality of dialog. Cleaned code. * Nov 12, 2014 3650 skorolev Added confirmation box for unsaved changes in the dialog. + * Nov 21, 2014 3841 skorolev Added formIsValid method. * * * @@ -877,6 +878,7 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements * Handles the Add New button click. */ private void handleAddNewAction() { + // Zone configure if (zoneRdo.getSelection() == true) { if (addNewZoneDlg == null) { addNewZoneDlg = new AddNewZoneDlg(shell, appName, this); @@ -892,9 +894,9 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements }); } addNewZoneDlg.open(); - } else { - if (associatedList.getSelectionIndex() != -1) { - String area = associatedList.getItem(associatedList + } else { // Station configure + if (maRegionalList.getSelectionIndex() != -1) { + String area = maRegionalList.getItem(maRegionalList .getSelectionIndex()); if (addNewStnDlg == null) { addNewStnDlg = new AddNewStationDlg(shell, appName, area, @@ -915,9 +917,9 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements MessageBox messageBox = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.NONE); messageBox.setText("Selection error."); - messageBox.setMessage("Please select associated zone."); + messageBox.setMessage("Please select a monitoring zone."); messageBox.open(); - associatedList.select(0); + maRegionalList.select(0); } } } @@ -932,10 +934,8 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements editDlg.setCloseCallback(new ICloseCallback() { @Override public void dialogClosed(Object returnValue) { - if (returnValue instanceof String) { + if ((boolean) returnValue) { // Update the edit dialog - String selectedZone = returnValue.toString(); - maZones.remove(selectedZone); populateLeftLists(); } editDlg = null; @@ -1084,6 +1084,7 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements if (mode == Mode.Zone) { String zone = additionalList.getItem(additionalList .getSelectionIndex()); + AreaIdXML zoneXML = configMgr.getAdjAreaXML(zone); additionalList.remove(additionalList.getSelectionIndex()); maZones.add(zone); Collections.sort(maZones); @@ -1092,8 +1093,7 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements monitorAreaList.setSelection(maZones.indexOf(zone)); handleMonitorAreaListSelection(); additionalZones.remove(zone); - configMgr.addArea(zone, zone.charAt(2) == 'Z' ? ZoneType.MARITIME - : ZoneType.REGULAR); + configMgr.addArea(zoneXML); if (!configMgr.getAddedZones().contains(zone)) { configMgr.getAddedZones().add(zone); } @@ -1142,6 +1142,8 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements monitorAreaList.remove(monitorAreaList.getSelectionIndex()); associatedList.removeAll(); if (mode == Mode.Zone) { + // entry is a zone to remove. + AreaIdXML zoneXML = configMgr.getAreaXml(entry); if (!additionalZones.contains(entry)) { additionalZones.add(entry); } @@ -1154,11 +1156,9 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements if (configMgr.getAddedZones().contains(entry)) { configMgr.getAddedZones().remove(entry); } - - configMgr.addAdjArea(entry, - entry.charAt(2) == 'Z' ? ZoneType.MARITIME - : ZoneType.REGULAR); + configMgr.addAdjArea(zoneXML); } else { // Station mode + // entry is a station to remove. additionalStns.add(entry); Collections.sort(additionalStns); additionalList.setItems(additionalStns @@ -1237,13 +1237,12 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements } else { // Station mode if (regionalRdo.getSelection()) { // entry is a zone selected from additional zones + AreaIdXML zoneXML = configMgr.getAdjAreaXML(entry); maZones.add(entry); Collections.sort(maZones); additionalZones.remove(entry); maRegionalList.remove(maRegionalList.getSelectionIndex()); - configMgr.addArea(entry, - entry.charAt(2) == 'Z' ? ZoneType.MARITIME - : ZoneType.REGULAR); + configMgr.addArea(zoneXML); } String stn = monitorAreaList.getItem(monitorAreaList .getSelectionIndex()); @@ -1334,11 +1333,17 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements } /** - * Reset and Saving configuration parameters. + * Reset configuration parameters. */ - protected void resetAndSave() { + protected void resetParams() { getValues(); resetStatus(); + } + + /** + * Saving configuration parameters. + */ + protected void saveConfigs() { configMgr.saveConfigXml(); configMgr.saveAdjacentAreaConfigXml(); } @@ -1407,6 +1412,27 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements return false; } + public boolean formIsValid(String area, String latString, String lonString) { + boolean retVal = true; + if (area.equals("") || area.length() != 6 + || (area.charAt(2) != 'C' && area.charAt(2) != 'Z')) { + displayInputErrorMsg("Invalid Area ID = '" + + area + + "' entered.\n" + + "Please enter a correctly formatted Area ID:\n" + + "Zone ID must have six characters.\n" + + "A third character should be C for county and Z for marine zone.\n" + + "Use only capital characters."); + retVal = false; + } + if (latString == null || latString.isEmpty() || lonString == null + || lonString.isEmpty()) { + latLonErrorMsg(latString, lonString); + retVal = false; + } + return retVal; + } + /* * (non-Javadoc) * @@ -1534,6 +1560,35 @@ public abstract class MonitoringAreaConfigDlg extends CaveSWTDialog implements return state; } + public java.util.List getMaZones() { + return maZones; + } + + public java.util.List getMaStations() { + return maStations; + } + + public java.util.List getAdditionalZones() { + return additionalZones; + } + + public java.util.List getAdditionalStns() { + return additionalStns; + } + + /** + * Displays Input Error Message + * + * @param msg + */ + public void displayInputErrorMsg(String msg) { + MessageBox messageBox = new MessageBox(shell, SWT.ICON_INFORMATION + | SWT.OK); + messageBox.setText("Invalid input"); + messageBox.setMessage(msg); + messageBox.open(); + } + /** * Gets Configuration manager. * diff --git a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/MonitorAreaUtils.java b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/MonitorAreaUtils.java index e5ed56f511..c0b203e847 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/MonitorAreaUtils.java +++ b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/MonitorAreaUtils.java @@ -35,6 +35,7 @@ import com.vividsolutions.jts.io.WKTWriter; * Apr 30, 2014 3086 skorolev Replaced MonitorConfigurationManager with FSSObsMonitorConfigurationManager * Oct 17, 2014 2757 skorolev Corrected SQL in the getAdjacentZones to avoid duplicates. * Nov 03, 2014 3741 skorolev Updated getZoneCenter and added getStationCenter methods. + * Dec 02, 2014 3841 skorolev Fixed possible duplicates in SQL expression. * * * @@ -191,7 +192,8 @@ public class MonitorAreaUtils { + zoneEnvelope + "', -1), the_geom) " + "and (catalogtype = 1 or catalogtype = 33 or catalogtype = 32 or catalogtype = 1000) order by stationid asc"; - + // 1= CAT_TYPE_ICAO, 33=CAT_TYPE_CMAN , + // 32=CAT_TYPE_BUOY_FXD 1000=CAT_TYPE_MESONET see ObStation.java ISpatialQuery sq = SpatialQueryFactory.create(); Object[] results = sq.dbRequest(sql, META_DB); if (results.length != 0) { @@ -599,7 +601,9 @@ public class MonitorAreaUtils { Coordinate stnCenter = null; ISpatialQuery sq = null; String sql = "select AsBinary(the_geom) from common_obs_spatial where stationid = '" - + stationid + "'"; + + stationid + + "'" + + "and (catalogtype = 1 or catalogtype = 33 or catalogtype = 32 or catalogtype = 1000)"; sq = SpatialQueryFactory.create(); Object results[] = sq.dbRequest(sql, "metadata"); if (results.length > 0) { diff --git a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FSSObsMonitorConfigurationManager.java b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FSSObsMonitorConfigurationManager.java index 4048b766db..bf097dab20 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FSSObsMonitorConfigurationManager.java +++ b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FSSObsMonitorConfigurationManager.java @@ -67,6 +67,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority; * May 13 2014 3133 njensen getStationType returns String instead of ObsHistType * May 15 2014 3086 skorolev Renamed from MonitorConfigurationManager. Replaces three separate area configuration managers with one. * Sep 04 2014 3220 skorolev Added fileUpdated method. + * Nov 21 2014 3841 skorolev Corrected addArea, addAdjArea and added getAdjAreaConfigXml. * * * @@ -357,21 +358,18 @@ public class FSSObsMonitorConfigurationManager implements * @param type * Type of zone */ - public void addArea(String areaId, ZoneType type) { + public void addArea(AreaIdXML areaXML) { List areaXmlList = configXml.getAreaIds(); boolean areaExists = false; + String areaId = areaXML.getAreaId(); for (AreaIdXML area : areaXmlList) { if (area.getAreaId().equals(areaId)) { - area.setType(type); areaExists = true; break; } } if (areaExists == false) { - AreaIdXML area = new AreaIdXML(); - area.setAreaId(areaId); - area.setType(type); - configXml.addAreaId(area); + configXml.addAreaId(areaXML); if (!addedZones.contains(areaId)) { addedZones.add(areaId); } @@ -674,6 +672,23 @@ public class FSSObsMonitorConfigurationManager implements return null; } + /** + * Gets an AdjAreaXml. + * + * @param zone + * from additional list + * @return + */ + public AreaIdXML getAdjAreaXML(String zone) { + List areaList = adjAreaConfigXml.getAreaIds(); + for (AreaIdXML adjAreaXml : areaList) { + if (adjAreaXml.getAreaId().equals(zone)) { + return adjAreaXml; + } + } + return null; + } + /** * Removes an area from the monitoring area. * @@ -777,6 +792,15 @@ public class FSSObsMonitorConfigurationManager implements return configXml; } + /** + * Gets Adjacent Configuration Xml + * + * @return the adjAreaConfigXml + */ + public MonAreaConfigXML getAdjAreaConfigXml() { + return adjAreaConfigXml; + } + /** * Gets Added Zones * @@ -960,24 +984,19 @@ public class FSSObsMonitorConfigurationManager implements /** * Add Adjacent Area. * - * @param areaId - * @param type + * @param area */ - public void addAdjArea(String areaId, ZoneType type) { + public void addAdjArea(AreaIdXML areaXML) { List adjAreaList = adjAreaConfigXml.getAreaIds(); boolean areaExists = false; for (AreaIdXML area : adjAreaList) { - if (area.getAreaId().equals(areaId)) { - area.setType(type); + if (area.getAreaId().equals(areaXML.getAreaId())) { areaExists = true; break; } } if (areaExists == false) { - AreaIdXML area = new AreaIdXML(); - area.setAreaId(areaId); - area.setType(type); - adjAreaConfigXml.addAreaId(area); + adjAreaConfigXml.addAreaId(areaXML); } }