Omaha #5338 - refresh the list of persistent resources in any mpe frames that exist whenever a

persistent polygon is deleted.


Former-commit-id: 9009c08d5fc90d4daab0ffb1305b22f702c0cf49
This commit is contained in:
Bryan Kowal 2016-02-15 16:47:16 -06:00
parent 0e1cdea4e3
commit 49e90a8217
5 changed files with 141 additions and 120 deletions

View file

@ -57,6 +57,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* displayed for polygons with
* the "sub" action.
* Jan 7, 2015 16954 cgobs Fix for cv_use issue - using getFieldName() in certain parts.
* Feb 15, 2016 5338 bkowal Keep track of any persistent polygons that are deleted.
* </pre>
*
* @author mpduff
@ -287,7 +288,7 @@ public class DeletePolygonDlg extends CaveSWTDialog {
polygonListBox.removeAll();
String type = displayManager.getDisplayFieldType().getFieldName();
productTF.setText(type);
polygonList = PolygonEditManager.getPolygonEdits(fieldData, editDate);
recreatePolygonListBox();
@ -348,8 +349,9 @@ public class DeletePolygonDlg extends CaveSWTDialog {
return;
}
// Remove selected from list and apply
polygonList.remove(polygonListBox.getSelectionIndex());
applyPolygonList();
RubberPolyData polygon = polygonList.remove(polygonListBox
.getSelectionIndex());
applyPolygonList(polygon.isPersistent());
}
/**
@ -357,8 +359,15 @@ public class DeletePolygonDlg extends CaveSWTDialog {
*/
private void deleteAll() {
// Clear the list and apply
boolean persistentRemoved = false;
for (RubberPolyData polygon : polygonList) {
if (polygon.isPersistent()) {
persistentRemoved = true;
break;
}
}
polygonList.clear();
applyPolygonList();
applyPolygonList(persistentRemoved);
}
/**
@ -374,15 +383,16 @@ public class DeletePolygonDlg extends CaveSWTDialog {
if (polygon >= 0 && polygon < polygonList.size()) {
RubberPolyData data = polygonList.get(polygon);
data.setVisible(display);
applyPolygonList();
applyPolygonList(false);
}
}
private void applyPolygonList() {
private void applyPolygonList(boolean persistentRemoved) {
MPEDisplayManager displayManager = MPEDisplayManager.getCurrent();
DisplayFieldData fieldData = displayManager.getDisplayFieldType();
Date editDate = displayManager.getCurrentEditDate();
PolygonEditManager.writePolygonEdits(fieldData, editDate, polygonList);
PolygonEditManager.writePolygonEdits(fieldData, editDate, polygonList,
persistentRemoved);
recreatePolygonListBox();
}

View file

@ -66,6 +66,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* Apr 28, 2014 16707 snaples Added code to save and set location of dialog box when moved.
* Jan 12, 2015 16993 snaples Restored code for Substitute Field Combo box.
* Feb 26, 2015 17209 cgobs Ensured that there is an initial selection of Substitution field, prevents empty selection.
* Feb 15, 2016 5338 bkowal Remove commented code. Cleanup.
*
* </pre>
*
@ -80,9 +81,10 @@ public class DrawPolygonDlg extends CaveSWTDialog {
private static final String MAKE_PERSISTENT = "Make Persistent";
private DisplayFieldData[] displayFieldDataArray;
private DisplayFieldData[] displayFieldDataArray;
private String[] displayTypeNameArray;
/**
* Bold Font.
*/
@ -96,8 +98,8 @@ public class DrawPolygonDlg extends CaveSWTDialog {
/**
* The field type selection Combo control.
*/
private Combo fieldTypeCombo = null;
private Combo fieldTypeCombo = null;
/**
* The precip value spinner control.
*/
@ -126,12 +128,12 @@ public class DrawPolygonDlg extends CaveSWTDialog {
/** The polygon resource */
private final MPEPolygonResource resource;
/** Point to hold location of dialog */
private static org.eclipse.swt.graphics.Point dlgLoc = null;
private static org.eclipse.swt.graphics.Point dlgLoc = null;
/** Status of dialog opened or not */
private boolean dialogOpened = false;
private boolean dialogOpened = false;
/**
* Constructor.
@ -170,21 +172,21 @@ public class DrawPolygonDlg extends CaveSWTDialog {
font = new Font(shell.getDisplay(), "Monospace", 10, SWT.NORMAL);
// Initialize all of the controls and layoutsendCal
initializeComponents();
shell.addControlListener(new ControlAdapter() {
@Override
public void controlMoved(ControlEvent e) {
if (!dialogOpened) {
return;
}
shell.addControlListener(new ControlAdapter() {
@Override
public void controlMoved(ControlEvent e) {
if (!dialogOpened) {
return;
}
if (dlgLoc == null) {
return;
}
if (dlgLoc == null) {
return;
}
dlgLoc.x = shell.getBounds().x;
dlgLoc.y = shell.getBounds().y;
}
});
dlgLoc.x = shell.getBounds().x;
dlgLoc.y = shell.getBounds().y;
}
});
}
/**
@ -196,17 +198,16 @@ public class DrawPolygonDlg extends CaveSWTDialog {
createCloseBtn();
}
@Override
protected void opened() {
if (dlgLoc == null) {
dlgLoc = new org.eclipse.swt.graphics.Point(shell.getBounds().x, shell.getBounds().y);
}
else {
shell.setLocation(dlgLoc);
}
dialogOpened = true;
}
@Override
protected void opened() {
if (dlgLoc == null) {
dlgLoc = new org.eclipse.swt.graphics.Point(shell.getBounds().x,
shell.getBounds().y);
} else {
shell.setLocation(dlgLoc);
}
dialogOpened = true;
}
/**
* Create the persistent group.
@ -361,7 +362,7 @@ public class DrawPolygonDlg extends CaveSWTDialog {
*/
private void createFieldCombo(Group groupComp) {
// Spacer
// Create a container to hold the label and the combo box.
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
Composite prodListComp = new Composite(shell, SWT.NONE);
@ -377,83 +378,58 @@ public class DrawPolygonDlg extends CaveSWTDialog {
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
fieldTypeCombo = new Combo(groupComp, SWT.LEFT | SWT.DROP_DOWN
| SWT.READ_ONLY);
if (displayFieldDataArray == null)
{
displayFieldDataArray = MPEDisplayManager.mpe_qpe_fields;
if (displayFieldDataArray == null) {
displayFieldDataArray = MPEDisplayManager.mpe_qpe_fields;
}
// Label spaceLabel = new Label(groupComp, SWT.NONE);
// spaceLabel.setText("***** ");
int selectedFieldIndex = 0;
boolean found = false;
//find the index of the selected field
for (selectedFieldIndex = 0; selectedFieldIndex < displayFieldDataArray.length; selectedFieldIndex++)
{
if (displayFieldDataArray[selectedFieldIndex] == subType)
{
// find the index of the selected field
for (selectedFieldIndex = 0; selectedFieldIndex < displayFieldDataArray.length; selectedFieldIndex++) {
if (displayFieldDataArray[selectedFieldIndex] == subType) {
found = true;
break;
}
}
if (!found)
{
if (!found) {
selectedFieldIndex = 0;
}
//create and initialize the display field type name array
// create and initialize the display field type name array
displayTypeNameArray = new String[displayFieldDataArray.length];
for (int i = 0; i < displayFieldDataArray.length; i++) {
String fieldName = displayFieldDataArray[i].toString();
// System.out.println("DrawPolygon.createFieldCombo(): FieldName = :" + fieldName + ":");
String fieldName = displayFieldDataArray[i].toString();
displayTypeNameArray[i] = fieldName;
}
//select the field
// select the field
fieldTypeCombo.setTextLimit(35);
fieldTypeCombo.setLayoutData(gd);
fieldTypeCombo.setItems(displayTypeNameArray);
// fieldTypeCombo.select(selectedFieldIndex);
fieldTypeCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
setSubstitutionField();
// String selectedFieldString = fieldTypeCombo.getText();
// System.out.println("DrawPolygon.createFieldCombo(): selectedFieldString = " +
// selectedFieldString);
// subType = DisplayFieldData.fromDisplayNameString(selectedFieldString);
// if (subType != null)
// {
// System.out.println("DrawPolygon.createFieldCombo(): subType = " +
// subType.toString());
// }
}
}
});
//select the substitution field
// select the substitution field
fieldTypeCombo.select(selectedFieldIndex);
setSubstitutionField();
}
private void setSubstitutionField()
{
private void setSubstitutionField() {
String selectedFieldString = fieldTypeCombo.getText();
subType = DisplayFieldData.fromDisplayNameString(selectedFieldString);
}
/**
* Process the selection.
@ -490,7 +466,7 @@ public class DrawPolygonDlg extends CaveSWTDialog {
.getPolygonEdits(displayedField, editDate);
polygonEdits.add(newEdit);
PolygonEditManager.writePolygonEdits(displayedField, editDate,
polygonEdits);
polygonEdits, false);
resource.clearPolygons();
dispMgr.setSavedData(false);
} finally {

View file

@ -34,6 +34,8 @@ import com.raytheon.viz.mpe.ui.DisplayFieldData;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 2, 2013 mschenke Initial creation
* Feb 15, 2016 5338 bkowal Updated to provide information about which
* persistent polygons remain after the edit.
*
* </pre>
*
@ -44,6 +46,7 @@ import com.raytheon.viz.mpe.ui.DisplayFieldData;
public interface IPolygonEditsChangedListener {
public void polygonEditsChanged(DisplayFieldData field, Date date,
List<RubberPolyData> polygonEdits);
List<RubberPolyData> polygonEdits,
List<RubberPolyData> persistentRemaining);
}

View file

@ -69,6 +69,8 @@ import com.raytheon.viz.mpe.ui.dialogs.polygon.RubberPolyData.PolygonEditAction;
* files are written.
* Jul 15, 2013 15963 snaples Removed polygon edit flag, and
* removed unneeded Constant for Backward compatibility.
* Feb 15, 2016 5338 bkowal Keep track of the remaining persistent polygons just
* in case a refresh is required.
*
*
* </pre>
@ -209,11 +211,12 @@ public class PolygonEditManager {
}
public static void writePolygonEdits(DisplayFieldData fieldData, Date date,
List<RubberPolyData> polygonEdits) {
List<RubberPolyData> polygonEdits, boolean persistentRemoved) {
orderPolygonEdits(polygonEdits);
File hourlyFile = getHourlyEditFile(fieldData, date);
StringBuilder hourlyBuffer = new StringBuilder();
List<RubberPolyData> persistentRemaining = new ArrayList<>();
File persistentFile = getPersistentEditFile(fieldData, date);
StringBuilder persistentBuffer = new StringBuilder();
@ -225,6 +228,7 @@ public class PolygonEditManager {
StringBuilder toUse = null;
int idx = 0;
if (polyEdit.isPersistent()) {
persistentRemaining.add(polyEdit);
persistOrder++;
toUse = persistentBuffer;
idx = persistOrder;
@ -290,9 +294,13 @@ public class PolygonEditManager {
toNotify = new LinkedHashSet<IPolygonEditsChangedListener>(
listeners);
}
if (!persistentRemoved) {
persistentRemaining = null;
}
for (IPolygonEditsChangedListener listener : toNotify) {
listener.polygonEditsChanged(fieldData, date,
new ArrayList<RubberPolyData>(polygonEdits));
new ArrayList<RubberPolyData>(polygonEdits),
persistentRemaining);
}
}
@ -354,8 +362,8 @@ public class PolygonEditManager {
DisplayFieldData subData = null;
for (DisplayFieldData fieldData : DisplayFieldData
.values()) {
if (fieldData.getFieldName()
.equalsIgnoreCase(subCvUse)) {
if (fieldData.getFieldName().equalsIgnoreCase(
subCvUse)) {
subData = fieldData;
break;
}

View file

@ -30,11 +30,13 @@ import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.measure.converter.UnitConverter;
import org.apache.commons.collections.CollectionUtils;
import org.eclipse.swt.graphics.RGB;
import com.raytheon.uf.common.colormap.prefs.ColorMapParameters;
@ -86,6 +88,8 @@ import com.raytheon.viz.mpe.ui.rsc.MPEFieldResourceData.MPEFieldFrame;
* Nov 05, 2015 18095 lbousaidi Fixed hour substitued for satellite field precip when drawing polygon.
* Dec 04, 2015 5165/14513 mduff Set this resource on the display manager if not set in the display manager.
* Dec 08, 2015 5180 bkowal Made the hour substitution special case precise.
* Feb 15, 2016 5338 bkowal Update the persistent set of polygons for an existing frame after one or
* all are deleted.
*
* </pre>
*
@ -455,8 +459,6 @@ public class MPEFieldResource extends
timeToLoad.getTime());
try {
long fileLength = file.getFile().length();
// System.out.printf("FileName = %s, length = %d\n",
// file.getFile().getPath(), fileLength);
if (fileLength > 0) {
file.load();
} else // can't read the file since it is empty
@ -557,13 +559,6 @@ public class MPEFieldResource extends
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.mpe.ui.rsc.AbstractGriddedMPEResource#createFrameContour
* (com.raytheon.viz.mpe.ui.rsc.AbstractMPEGriddedResourceData.Frame)
*/
@Override
protected GriddedContourDisplay createFrameContour(MPEFieldFrame frame)
throws VizException {
@ -582,13 +577,6 @@ public class MPEFieldResource extends
return display;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.mpe.ui.rsc.AbstractGriddedMPEResource#createFrameImage
* (com.raytheon.viz.mpe.ui.rsc.AbstractMPEGriddedResourceData.Frame)
*/
@Override
protected GriddedImageDisplay2 createFrameImage(MPEFieldFrame frame)
throws VizException {
@ -680,23 +668,59 @@ public class MPEFieldResource extends
return preferences;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.mpe.ui.dialogs.polygon.IPolygonEditsChangedListener#
* polygonEditsChanged(com.raytheon.viz.mpe.ui.DisplayFieldData,
* java.util.Date, java.util.List)
*/
@Override
public void polygonEditsChanged(DisplayFieldData field, Date date,
List<RubberPolyData> polygonEdits) {
List<RubberPolyData> polygonEdits,
List<RubberPolyData> persistentRemaining) {
if (field == resourceData.getFieldData()) {
MPEFieldFrame frame = frames.get(new DataTime(date));
if (frame != null) {
frame.setPolygonEdits(polygonEdits);
issueRefresh();
}
if (persistentRemaining == null) {
/*
* A persistent polygon has been removed. So, the lists of
* polygons for any existing frames will need to be rebuilt. The
* polygons are stored in a text file without any unique
* identifier and polygons with duplicate fields are allowed to
* exist. The polygons must currently remain stored in this
* format to maintain compatibility with legacy C++ mpe code.
* So, the only option (with the current implementation) is to
* remove any persistent polygons from the existing list and
* re-add the remaining set of persistent polygons. The lists of
* polygons cannot be replaced across all frames because the
* list of polygon edits passed to this method also contains
* frame/time specific polygons.
*/
return;
}
for (MPEFieldFrame otherFrame : frames.values()) {
if (otherFrame.getDate().equals(date)) {
// already updated this frame.
continue;
}
List<RubberPolyData> currentPolygonEdits = otherFrame
.getPolygonEdits();
if (CollectionUtils.isEmpty(currentPolygonEdits)) {
continue;
}
boolean persistentRemoved = false;
Iterator<RubberPolyData> persistentIter = currentPolygonEdits
.iterator();
while (persistentIter.hasNext()) {
if (persistentIter.next().isPersistent()) {
persistentIter.remove();
persistentRemoved = true;
}
}
if (!persistentRemoved) {
continue;
}
currentPolygonEdits.addAll(persistentRemaining);
otherFrame.setPolygonEdits(currentPolygonEdits);
}
}
}
}