diff --git a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/actions/EditLocationShiftAction.java b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/actions/EditLocationShiftAction.java index 6dfcea6b1a..40e40961da 100644 --- a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/actions/EditLocationShiftAction.java +++ b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/actions/EditLocationShiftAction.java @@ -42,6 +42,7 @@ import com.raytheon.viz.hydrocommon.texteditor.TextEditorDlg; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Feb 18, 2010 2635 mpduff Initial creation + * Jul 16, 2013 2088 rferrel Changes for non-blocking TextEditorDlg. * * * @@ -53,16 +54,22 @@ public class EditLocationShiftAction extends AbstractHandler { /** The Location Shift Config file */ private static final String LOCATION_SHIFT_CONFIG = "hydro/config/pdc_loc_shift.txt"; + /** Allow single instance of editor. */ + private TextEditorDlg textDlg; + @Override public Object execute(ExecutionEvent event) throws ExecutionException { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getShell(); IPathManager pm = PathManagerFactory.getPathManager(); File file = pm.getStaticFile(LOCATION_SHIFT_CONFIG); - TextEditorDlg textDlg = null; if (file != null) { - textDlg = new TextEditorDlg(shell, false, file); - textDlg.open(); + if (textDlg == null || textDlg.isDisposed()) { + textDlg = new TextEditorDlg(shell, false, file); + textDlg.open(); + } else { + textDlg.bringToTop(); + } } else { MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); diff --git a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/ratingcurve/RatingCurveAction.java b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/ratingcurve/RatingCurveAction.java index 2fb8905a00..6a37a0f848 100644 --- a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/ratingcurve/RatingCurveAction.java +++ b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/ratingcurve/RatingCurveAction.java @@ -22,6 +22,9 @@ */ package com.raytheon.viz.hydro.ratingcurve; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; @@ -30,6 +33,7 @@ import org.eclipse.ui.PlatformUI; import com.raytheon.viz.hydrocommon.HydroDisplayManager; import com.raytheon.viz.hydrocommon.ratingcurve.RatingCurveDlg; +import com.raytheon.viz.ui.dialogs.ICloseCallback; /** * Action for unimplemented features. To be used temporarily until final @@ -43,6 +47,7 @@ import com.raytheon.viz.hydrocommon.ratingcurve.RatingCurveDlg; * ------------ ---------- ----------- -------------------------- * 6/27/06 lvenable Initial Creation. * 24 Nov 2008 1628 dhladky updated. + * 15 Jul 2013 2088 rferrel Changes for non-blocking RatingCurveDlg. * * * @@ -50,6 +55,8 @@ import com.raytheon.viz.hydrocommon.ratingcurve.RatingCurveDlg; * */ public class RatingCurveAction extends AbstractHandler { + private Map ratingCurveDlgMap = new HashMap(); + public Object execute(ExecutionEvent arg0) throws ExecutionException { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getShell(); @@ -57,16 +64,33 @@ public class RatingCurveAction extends AbstractHandler { HydroDisplayManager manager = HydroDisplayManager.getInstance(); if (manager.isCurrentLidSelected(shell)) { String lid = manager.getCurrentLid(); - String name = manager.getCurrentData().getName(); + RatingCurveDlg ratingCurveDlg = ratingCurveDlgMap.get(lid); - String displayString = " - " - + lid - + ((name != null && name.compareTo("") != 0) ? " - " + name - : ""); + if (ratingCurveDlg == null || ratingCurveDlg.isDisposed()) { + String name = manager.getCurrentData().getName(); + StringBuilder displayString = new StringBuilder(" - "); + displayString.append(lid); + if (name != null && name.length() > 0) { + displayString.append(" - ").append(name); + } - RatingCurveDlg ratingCurveDlg = new RatingCurveDlg(shell, lid, - displayString, false); - ratingCurveDlg.open(); + ratingCurveDlg = new RatingCurveDlg(shell, lid, + displayString.toString(), false); + ratingCurveDlg.setCloseCallback(new ICloseCallback() { + + @Override + public void dialogClosed(Object returnValue) { + if (returnValue instanceof String) { + String lid = returnValue.toString(); + ratingCurveDlgMap.remove(lid); + } + } + }); + ratingCurveDlg.open(); + ratingCurveDlgMap.put(lid, ratingCurveDlg); + } else { + ratingCurveDlg.bringToTop(); + } } return null; diff --git a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TabularTimeSeriesDlg.java b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TabularTimeSeriesDlg.java index 3223117d8d..34b51d2ace 100644 --- a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TabularTimeSeriesDlg.java +++ b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TabularTimeSeriesDlg.java @@ -128,6 +128,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * Code clean up for non-blocking dialog. * Feb 27,2013 1790 rferrel Bug fix for non-blocking dialogs. * Jun 07, 2013 1981 mpduff Set user's id on the OUPRequest as it is now protected. + * Jul 16, 2013 2088 rferrel Changes for non-blocking TextEditorDlg. * * * @@ -997,7 +998,6 @@ public class TabularTimeSeriesDlg extends CaveSWTDialog implements @Override public void widgetSelected(SelectionEvent event) { tabularShefEncode(); - // notYetImplemented(); } }); @@ -3012,7 +3012,8 @@ public class TabularTimeSeriesDlg extends CaveSWTDialog implements } out.close(); } catch (IOException e) { - statusHandler.handle(Priority.PROBLEM, "", e); + statusHandler.handle(Priority.PROBLEM, + "Unable to create shef file: ", e); showMessage(shell, SWT.ERROR | SWT.OK, "Unable to Save File", "File: " + SHEF_FILE_NAME + "." + getPid() + "\nUser does NOT have write permission."); @@ -3026,8 +3027,12 @@ public class TabularTimeSeriesDlg extends CaveSWTDialog implements if ((shefFileName != null) && (shefFileName.length() > 0)) { File shefFile = new File(shefFileName); if (shefFile.exists()) { - editor = new TextEditorDlg(shell, false, shefFile); - editor.open(); + if (editor == null || editor.isDisposed()) { + editor = new TextEditorDlg(shell, false, shefFile); + editor.open(); + } else { + editor.bringToTop(); + } } else { showMessage(shell, SWT.OK, "Unable to Open File", "Unable to open file:\n" + SHEF_FILE_NAME + "." diff --git a/cave/com.raytheon.viz.hydrobase/src/com/raytheon/viz/hydrobase/HydroBaseDlg.java b/cave/com.raytheon.viz.hydrobase/src/com/raytheon/viz/hydrobase/HydroBaseDlg.java index 6d7d4b5f01..4a9024a88a 100644 --- a/cave/com.raytheon.viz.hydrobase/src/com/raytheon/viz/hydrobase/HydroBaseDlg.java +++ b/cave/com.raytheon.viz.hydrobase/src/com/raytheon/viz/hydrobase/HydroBaseDlg.java @@ -165,6 +165,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback; * Changes for non-blocking DataSourcesDlg. * Changes for non-blocking ImpactStatementDlg. * Changes for non-blocking LowWaterStatementDlg. + * Changes for non-blocking RatingCurveDlg. * * * @@ -352,6 +353,11 @@ public class HydroBaseDlg extends CaveSWTDialog implements IGetSortType, */ private final Map lowWaterStmntDlgMap = new HashMap(); + /** + * Allow one instance per station. + */ + private final Map ratingCurveDlgMap = new HashMap(); + /** * Flood category menu item. */ @@ -938,10 +944,7 @@ public class HydroBaseDlg extends CaveSWTDialog implements IGetSortType, ratingCurveMI.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - RatingCurveDlg ratingCurveDlg = new RatingCurveDlg(shell, - getStationLid(), getStationAndName(), true); - ratingCurveDlg.open(); - + handleRatingCurveDlg(); } }); riverGageMenuItems.add(ratingCurveMI); @@ -1218,6 +1221,33 @@ public class HydroBaseDlg extends CaveSWTDialog implements IGetSortType, } } + /** + * Display Rating Curve Dialog for selected station. + */ + private void handleRatingCurveDlg() { + String lid = getStationLid(); + RatingCurveDlg ratingCurveDlg = ratingCurveDlgMap.get(lid); + + if (ratingCurveDlg == null || ratingCurveDlg.isDisposed()) { + ratingCurveDlg = new RatingCurveDlg(shell, lid, + getStationAndName(), true); + ratingCurveDlg.setCloseCallback(new ICloseCallback() { + + @Override + public void dialogClosed(Object returnValue) { + if (returnValue instanceof String) { + String lid = returnValue.toString(); + ratingCurveDlgMap.remove(lid); + } + } + }); + ratingCurveDlg.open(); + ratingCurveDlgMap.put(lid, ratingCurveDlg); + } else { + ratingCurveDlg.bringToTop(); + } + } + /** * Create the Reservoir menu. * diff --git a/cave/com.raytheon.viz.hydrobase/src/com/raytheon/viz/hydrobase/dialogs/ArealDefinitionsDlg.java b/cave/com.raytheon.viz.hydrobase/src/com/raytheon/viz/hydrobase/dialogs/ArealDefinitionsDlg.java index 42fe82d9fa..a54766bff9 100644 --- a/cave/com.raytheon.viz.hydrobase/src/com/raytheon/viz/hydrobase/dialogs/ArealDefinitionsDlg.java +++ b/cave/com.raytheon.viz.hydrobase/src/com/raytheon/viz/hydrobase/dialogs/ArealDefinitionsDlg.java @@ -28,12 +28,13 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; +import java.util.Map; import java.util.TimeZone; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -62,6 +63,7 @@ import com.raytheon.viz.hydrocommon.HydroConstants.ArealTypeSelection; import com.raytheon.viz.hydrocommon.texteditor.TextEditorDlg; import com.raytheon.viz.hydrocommon.whfslib.GeoUtil; import com.raytheon.viz.ui.dialogs.CaveSWTDialog; +import com.raytheon.viz.ui.dialogs.ICloseCallback; import com.vividsolutions.jts.geom.Coordinate; /** @@ -74,6 +76,7 @@ import com.vividsolutions.jts.geom.Coordinate; * 02 Sep 2008 lvenable Initial creation. * 09 Sep 2009 2772 mpduff Implemented Dialog. * 16 Apr 2013 1790 rferrel Made dialog non-blocking. + * 16 Jul 2013 2088 rferrel Changes for non-blocking TextEditorDlg. * * * @@ -147,9 +150,8 @@ public class ArealDefinitionsDlg extends CaveSWTDialog { /** Log file open flag */ private boolean logFileOpen = false; - private Cursor waitCursor = null; - - private Cursor arrowCursor = null; + /** Allow single instance of editor for a given file. */ + private final Map textEditorDlgMap = new HashMap(); /** * Constructor. @@ -160,9 +162,6 @@ public class ArealDefinitionsDlg extends CaveSWTDialog { public ArealDefinitionsDlg(Shell parent) { super(parent, SWT.DIALOG_TRIM, CAVE.DO_NOT_BLOCK); setText("Areal Definitions"); - - waitCursor = new Cursor(parent.getDisplay(), SWT.CURSOR_WAIT); - arrowCursor = new Cursor(parent.getDisplay(), SWT.CURSOR_ARROW); } /* @@ -335,8 +334,24 @@ public class ArealDefinitionsDlg extends CaveSWTDialog { public void widgetSelected(SelectionEvent event) { File f = getAreaFilename(); if (f != null) { - TextEditorDlg teDlg = new TextEditorDlg(shell, false, f); - teDlg.open(); + TextEditorDlg teDlg = textEditorDlgMap.get(f); + if (teDlg == null || teDlg.isDisposed()) { + teDlg = new TextEditorDlg(shell, false, f); + teDlg.setCloseCallback(new ICloseCallback() { + + @Override + public void dialogClosed(Object returnValue) { + if (returnValue instanceof File) { + File f = (File) returnValue; + textEditorDlgMap.remove(f); + } + } + }); + teDlg.open(); + textEditorDlgMap.put(f, teDlg); + } else { + teDlg.bringToTop(); + } } } }); @@ -444,14 +459,14 @@ public class ArealDefinitionsDlg extends CaveSWTDialog { } private void handleImport() { - shell.setCursor(waitCursor); + shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT)); File importFile = getAreaFilename(); /* * if the file was not accessible don't continue with the import */ if (importFile == null) { - shell.setCursor(arrowCursor); + shell.setCursor(null); return; } @@ -497,7 +512,7 @@ public class ArealDefinitionsDlg extends CaveSWTDialog { } } - shell.setCursor(arrowCursor); + shell.setCursor(null); } /** @@ -563,8 +578,24 @@ public class ArealDefinitionsDlg extends CaveSWTDialog { File f = getLogFilename(); if (f.exists()) { - TextEditorDlg ted = new TextEditorDlg(shell, true, f); - ted.open(); + TextEditorDlg ted = textEditorDlgMap.get(f); + if (ted == null || ted.isDisposed()) { + ted = new TextEditorDlg(shell, true, f); + ted.setCloseCallback(new ICloseCallback() { + + @Override + public void dialogClosed(Object returnValue) { + if (returnValue instanceof File) { + File f = (File) returnValue; + textEditorDlgMap.remove(f); + } + } + }); + ted.open(); + textEditorDlgMap.put(f, ted); + } else { + ted.bringToTop(); + } } else { MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); mb.setText("File Not Found"); @@ -852,11 +883,9 @@ public class ArealDefinitionsDlg extends CaveSWTDialog { return; } - int numBlock = 0; for (GeoAreaData data : geoDataList) { /* load the data into the database if good data */ if (data.isSaveDataBlock()) { - numBlock++; try { int status = dman.putGeoArea(data); if (status < 0) { @@ -926,11 +955,9 @@ public class ArealDefinitionsDlg extends CaveSWTDialog { */ private ArrayList getPointsFromArea(GeoAreaData data) { ArrayList points = new ArrayList(); - int pointCount = 0; /* init the first point */ Coordinate coord = new Coordinate(data.getLon()[0], data.getLat()[0]); - pointCount++; points.add(coord); double[] lat = data.getLat(); double[] lon = data.getLon(); @@ -945,7 +972,6 @@ public class ArealDefinitionsDlg extends CaveSWTDialog { if ((lat[i] != lat[i - 1]) || (lon[i] != lon[i - 1])) { coord = new Coordinate(lon[i], lat[i]); points.add(coord); - pointCount++; } } diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveCanvasComp.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveCanvasComp.java index 478558047b..079161915a 100644 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveCanvasComp.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveCanvasComp.java @@ -19,7 +19,7 @@ **/ package com.raytheon.viz.hydrocommon.ratingcurve; -import java.util.ArrayList; +import java.util.List; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseEvent; @@ -43,6 +43,7 @@ import org.eclipse.swt.widgets.Composite; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Sep 8, 2008 lvenable Initial creation + * Jul 15, 2013 2088 rferrel Code clean part of non-blocking dialogs. * * * @@ -54,7 +55,7 @@ public class RatingCurveCanvasComp extends Canvas { * Parent composite. */ private Composite parent; - + /** * Reference back to parent dialog. */ @@ -123,8 +124,8 @@ public class RatingCurveCanvasComp extends Canvas { /** * Minimum stage value in feet. */ - private double minStageFeet = 0.0; - + private double minStageFeet = 0.0; + /** * Maximum flow KCFS value. */ @@ -134,10 +135,11 @@ public class RatingCurveCanvasComp extends Canvas { * Minimum flow KCFS value. */ private double minFlowKcfs = 0.0; + /** * Divisor for the flow value. */ - private double FLOW_DIVISOR = 10000.0; + private double FLOW_DIVISOR = 10000.0; /** * Flood value. @@ -152,7 +154,7 @@ public class RatingCurveCanvasComp extends Canvas { /** * Array of curve data. */ - private ArrayList curveDataArray; + private List curveDataArray; /** * Number of hashes on the vertical graph line. @@ -163,9 +165,9 @@ public class RatingCurveCanvasComp extends Canvas { * Maximum stage feet label value. */ int maxStageFeetLabelVal = 0; - + private double minStageFeetLabelVal = 0; - + /** * Number of hashes on the horizontal graph line. */ @@ -210,7 +212,7 @@ public class RatingCurveCanvasComp extends Canvas { * Current Y location of mouse pointer. */ int currentY; - + /** * Shift amount */ @@ -229,7 +231,7 @@ public class RatingCurveCanvasComp extends Canvas { * Record value. */ public RatingCurveCanvasComp(Composite parent, RatingCurveDlg parentDlg, - ArrayList curveDataArray, double floodVal, + List curveDataArray, double floodVal, double recordDbl, double shiftAmount) { super(parent, SWT.DOUBLE_BUFFERED); @@ -252,7 +254,7 @@ public class RatingCurveCanvasComp extends Canvas { * @param floodVal * @param recordDbl */ - public void updateCurveData(ArrayList curveDataArray, + public void updateCurveData(List curveDataArray, double floodVal, double recordDbl, double shiftAmount) { floodValDbl = floodVal; recordValDbl = recordDbl; @@ -330,7 +332,6 @@ public class RatingCurveCanvasComp extends Canvas { maxFlowKcfs = 0.0; minStageFeet = 0.0; minFlowKcfs = 0.0; - if (curveDataArray != null) { for (RatingCurveData curveData : curveDataArray) { @@ -341,11 +342,11 @@ public class RatingCurveCanvasComp extends Canvas { if (curveData.getDischarge() > maxFlowKcfs) { maxFlowKcfs = curveData.getDischarge(); } - + if (curveData.getStage() < minStageFeet) { minStageFeet = curveData.getStage(); } - + if (curveData.getDischarge() < minFlowKcfs) { minFlowKcfs = curveData.getDischarge(); } @@ -355,11 +356,11 @@ public class RatingCurveCanvasComp extends Canvas { if (maxStageFeet < floodValDbl) { maxStageFeet = floodValDbl; } - + if (maxStageFeet < recordValDbl) { maxStageFeet = recordValDbl; } - + if (maxFlowKcfs > 100000) { FLOW_DIVISOR = 100000; } else if (maxFlowKcfs > 10000) { @@ -368,16 +369,18 @@ public class RatingCurveCanvasComp extends Canvas { FLOW_DIVISOR = 1000; } maxFlowKcfs /= FLOW_DIVISOR; - + if (minStageFeet >= 0) { minStageFeetLabelVal = 0; } else { minStageFeetLabelVal = Math.round((minStageFeet - 5) / 10) * 10; } } - - vNumHashs = Math.round((((maxStageFeet - minStageFeetLabelVal) / 10) + 0.5d)); - maxStageFeetLabelVal = (int) ((vNumHashs * 10) - Math.abs(minStageFeetLabelVal)); + + vNumHashs = Math + .round((((maxStageFeet - minStageFeetLabelVal) / 10) + 0.5d)); + maxStageFeetLabelVal = (int) ((vNumHashs * 10) - Math + .abs(minStageFeetLabelVal)); } /** @@ -385,9 +388,10 @@ public class RatingCurveCanvasComp extends Canvas { * lines. */ private void calcPixelsPerIncrement() { - vPixelsPerInc = VLINE_LENGTH / (maxStageFeetLabelVal - minStageFeetLabelVal); - vPixelsPerIncBase10 = (VLINE_LENGTH/vNumHashs); - + vPixelsPerInc = VLINE_LENGTH + / (maxStageFeetLabelVal - minStageFeetLabelVal); + vPixelsPerIncBase10 = (VLINE_LENGTH / vNumHashs); + hNumHashs = Math.round(((maxFlowKcfs - minFlowKcfs) + 0.5d)); maxKcfsLabelVal = (int) (hNumHashs * 10); hPixelsPerIncBase10 = HLINE_LENGTH / hNumHashs; @@ -473,8 +477,9 @@ public class RatingCurveCanvasComp extends Canvas { yCoord); // draw label - gc.drawString(String.format("%5.1f", minStageFeetLabelVal + (x * 10)), - STAGE_FEET_HASH_LABEL_X, yCoord - fontHeightMid, true); + gc.drawString( + String.format("%5.1f", minStageFeetLabelVal + (x * 10)), + STAGE_FEET_HASH_LABEL_X, yCoord - fontHeightMid, true); } } @@ -494,7 +499,8 @@ public class RatingCurveCanvasComp extends Canvas { gc.drawLine(xCoord, HLINE_YCOORD, xCoord, HLINE_YCOORD + HASH_MARK); - kcfsStr = String.format("%5.1f", (float) (x * FLOW_DIVISOR / 1000)); + kcfsStr = String.format("%5.1f", + (float) (x * FLOW_DIVISOR / 1000)); gc.drawString(kcfsStr, xCoord - ((kcfsStr.length() * fontAveWidth) / 2) - fontAveWidth, HLINE_YCOORD + HASH_MARK * 2, true); @@ -519,18 +525,13 @@ public class RatingCurveCanvasComp extends Canvas { .getDischarge() / FLOW_DIVISOR) * 10) * hPixelsPerInc))); int yCoord = 0; -// Math.round((i - 9) / 10) * 10 if (shiftAmount < 0) { - yCoord = (int) (HLINE_YCOORD - Math - .round(((curveData.getStage() - minStageFeetLabelVal) * vPixelsPerInc))); -// yCoord = (int) (HLINE_YCOORD - Math -// .round(((curveData.getStage() - shiftAmount) * vPixelsPerInc))); + yCoord = (int) (HLINE_YCOORD - Math.round(((curveData + .getStage() - minStageFeetLabelVal) * vPixelsPerInc))); } else { - yCoord = (int) (HLINE_YCOORD - Math - .round(((curveData.getStage()) * vPixelsPerInc))); + yCoord = (int) (HLINE_YCOORD - Math.round(((curveData + .getStage()) * vPixelsPerInc))); } -// int yCoord = (int) (HLINE_YCOORD - Math -// .round(((curveData.getStage() - shiftAmount) * vPixelsPerInc))); // TODO Add the shift back in if (firstTime) { oldX = xCoord; @@ -538,9 +539,7 @@ public class RatingCurveCanvasComp extends Canvas { firstTime = false; } - gc - .setForeground(parent.getDisplay().getSystemColor( - SWT.COLOR_CYAN)); + gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_CYAN)); gc.drawLine(oldX, oldY, xCoord, yCoord); gc.setForeground(parent.getDisplay().getSystemColor( @@ -548,8 +547,6 @@ public class RatingCurveCanvasComp extends Canvas { gc.drawOval(xCoord - circleWidth / 2, yCoord - circleHeight / 2, circleWidth, circleHeight); - -// Region r = new Region(); oldX = xCoord; oldY = yCoord; @@ -557,10 +554,10 @@ public class RatingCurveCanvasComp extends Canvas { } /** - * Draw the cross hairs on the graph when the left - * mouse button is clicked. + * Draw the cross hairs on the graph when the left mouse button is clicked. * - * @param gc The current GC + * @param gc + * The current GC */ private void drawCrossHairs(GC gc) { if ((currentX > VLINE_XCOORD) @@ -599,21 +596,24 @@ public class RatingCurveCanvasComp extends Canvas { } /** - * Update the Stage and KCFS labels when moving - * mouse and left mouse button is pressed. + * Update the Stage and KCFS labels when moving mouse and left mouse button + * is pressed. */ private void updateLabels() { if ((currentX > VLINE_XCOORD) && (currentX < VLINE_XCOORD + HLINE_LENGTH) && (currentY > HLINE_YCOORD - VLINE_LENGTH) && (currentY < HLINE_YCOORD)) { - double q = (((currentX - VLINE_XCOORD)/(hPixelsPerInc * 100) * FLOW_DIVISOR))/100; - double stage = (((currentY - (minStageFeetLabelVal*vPixelsPerInc) - HLINE_YCOORD)/vPixelsPerInc * -1)); - parentDlg.getStageDataLbl().setText(String.valueOf(String.format("%5.1f", stage))); - parentDlg.getKcfsDataLbl().setText(String.valueOf(String.format("%5.1f", q))); + double q = (((currentX - VLINE_XCOORD) / (hPixelsPerInc * 100) * FLOW_DIVISOR)) / 100; + double stage = (((currentY - (minStageFeetLabelVal * vPixelsPerInc) - HLINE_YCOORD) + / vPixelsPerInc * -1)); + parentDlg.getStageDataLbl().setText( + String.valueOf(String.format("%5.1f", stage))); + parentDlg.getKcfsDataLbl().setText( + String.valueOf(String.format("%5.1f", q))); } } - + private void handleMouseDownEvent(MouseEvent e) { isMouseDown = true; } @@ -622,7 +622,7 @@ public class RatingCurveCanvasComp extends Canvas { isMouseDown = false; redraw(); parentDlg.getStageDataLbl().setText(""); - parentDlg.getKcfsDataLbl().setText(""); + parentDlg.getKcfsDataLbl().setText(""); } private void handleMouseMoveEvent(MouseEvent e) { diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveDlg.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveDlg.java index 91956af3f9..feee4c17f8 100644 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveDlg.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveDlg.java @@ -34,7 +34,6 @@ import java.util.Calendar; import java.util.Collections; import java.util.TimeZone; -import org.eclipse.core.runtime.Status; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -53,11 +52,12 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import com.raytheon.uf.common.ohd.AppsDefaults; -import com.raytheon.uf.viz.core.VizApp; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.viz.hydrocommon.data.RiverDataPoint; import com.raytheon.viz.hydrocommon.datamanager.RiverDataManager; -import com.raytheon.viz.ui.UiPlugin; import com.raytheon.viz.ui.dialogs.CaveSWTDialog; /** @@ -76,12 +76,15 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * 26 Jul 2012 14711/963 mpduff Fix problems adding/removing shift points * 22 Jan 2013 15682 lbousaidi fix openfile problem and changed the path to * whfs_import_dir for "Import Curve" button. + * 15 Jul 2013 2088 rferrel Make dialog non-blocking. * * * @author lvenable * @version 1.0 */ public class RatingCurveDlg extends CaveSWTDialog { + private final IUFStatusHandler statusHandler = UFStatus + .getHandler(RatingCurveDlg.class); /** * Control font. @@ -136,17 +139,17 @@ public class RatingCurveDlg extends CaveSWTDialog { /** * Array of rating curve data (no shift curve). */ - private ArrayList noShiftCurveArray; + private java.util.List noShiftCurveArray; /** * Array of rating curve data (with shift curve). */ - private ArrayList shiftCurveArray; + private java.util.List shiftCurveArray; /** * Shift Data if available */ - private ArrayList shiftData; + private java.util.List shiftData; /** * Shift curve data list control. @@ -259,18 +262,24 @@ public class RatingCurveDlg extends CaveSWTDialog { private boolean newRatingCurve = false; /** - * rating curve points + * Rating curve remove points. */ - private ArrayList removedPoints = null; - - private ArrayList addedPoints = null; + private java.util.List removedPoints = null; /** - * rating curve shift points + * Rating curve added points. */ - private ArrayList removedCurveShifts = null; + private java.util.List addedPoints = null; - private ArrayList addedCurveShifts = null; + /** + * Rating curve remove shift points. + */ + private java.util.List removedCurveShifts = null; + + /** + * Rating curve added shift points. + */ + private java.util.List addedCurveShifts = null; /** * The current selected shift curve @@ -294,7 +303,7 @@ public class RatingCurveDlg extends CaveSWTDialog { */ public RatingCurveDlg(Shell parent, String lid, String titleInfo, boolean fullControls) { - super(parent); + super(parent, SWT.DIALOG_TRIM, CAVE.DO_NOT_BLOCK); setText("Rating Curve" + titleInfo); this.lid = lid; @@ -312,8 +321,14 @@ public class RatingCurveDlg extends CaveSWTDialog { addedCurveShifts = new ArrayList(); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); + setReturnValue(lid); } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#constructShellLayout() + */ @Override protected Layout constructShellLayout() { // Create the main layout for the shell. @@ -323,15 +338,25 @@ public class RatingCurveDlg extends CaveSWTDialog { return mainLayout; } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#disposed() + */ @Override protected void disposed() { controlFont.dispose(); } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#initializeComponents(org + * .eclipse.swt.widgets.Shell) + */ @Override protected void initializeComponents(Shell shell) { - setReturnValue(false); - controlFont = new Font(shell.getDisplay(), "Monospace", 10, SWT.NORMAL); // Initialize all of the controls and layouts @@ -491,7 +516,7 @@ public class RatingCurveDlg extends CaveSWTDialog { shftRemoveBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - removeShift(); + removeShift(); } }); @@ -520,8 +545,9 @@ public class RatingCurveDlg extends CaveSWTDialog { curveImportBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - final String tokenizedDir = "whfs_import_dir"; - String importRating= AppsDefaults.getInstance().getToken(tokenizedDir); + final String tokenizedDir = "whfs_import_dir"; + String importRating = AppsDefaults.getInstance().getToken( + tokenizedDir); FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setFilterPath(importRating); String[] filterExt = { "*." + extension }; @@ -529,10 +555,10 @@ public class RatingCurveDlg extends CaveSWTDialog { String filename = fd.open(); if (filename == null) { return; - } else { + } else { importCurveData(importRatingCurve(filename)); - } - + } + } }); @@ -543,30 +569,32 @@ public class RatingCurveDlg extends CaveSWTDialog { curveClearAllBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - MessageBox messageDialog = new MessageBox(shell, SWT.OK | SWT.CANCEL); + MessageBox messageDialog = new MessageBox(shell, SWT.OK + | SWT.CANCEL); messageDialog.setText("Clear Confirmation"); - messageDialog.setMessage("This will clear the list for " + lid + "."); + messageDialog.setMessage("This will clear the list for " + lid + + "."); int response = messageDialog.open(); if (response == SWT.OK) { - // get rid of every point - removedPoints = noShiftCurveArray; - noShiftCurveArray.clear(); - noShiftCurveDataList.removeAll(); - noShiftCurveDataList.redraw(); - - if (shiftCurveArray != null) { - shiftCurveArray.clear(); - } - shiftCurveDataList.removeAll(); - shiftCurveDataList.redraw(); - - stageTF.setText(""); - dischargeTF.setText(""); - selectedRatingShift = null; - - ratingCurveCanvas.updateCurveData(noShiftCurveArray, floodDbl, - recordDbl, shiftAmount); + // get rid of every point + removedPoints = noShiftCurveArray; + noShiftCurveArray.clear(); + noShiftCurveDataList.removeAll(); + noShiftCurveDataList.redraw(); + + if (shiftCurveArray != null) { + shiftCurveArray.clear(); + } + shiftCurveDataList.removeAll(); + shiftCurveDataList.redraw(); + + stageTF.setText(""); + dischargeTF.setText(""); + selectedRatingShift = null; + + ratingCurveCanvas.updateCurveData(noShiftCurveArray, + floodDbl, recordDbl, shiftAmount); } } }); @@ -579,28 +607,28 @@ public class RatingCurveDlg extends CaveSWTDialog { @Override public void widgetSelected(SelectionEvent event) { if (noShiftCurveDataList.getSelectionIndex() != -1) { - MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION - | SWT.OK | SWT.CANCEL); - mb.setText("Remove Base Rating Point Confirmation"); - mb.setMessage("This will remove the highlighted pair."); - int response = mb.open(); + MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION + | SWT.OK | SWT.CANCEL); + mb.setText("Remove Base Rating Point Confirmation"); + mb.setMessage("This will remove the highlighted pair."); + int response = mb.open(); - if (response == SWT.OK) { - // get rid of this point - int index = noShiftCurveDataList.getSelectionIndex(); - removedPoints.add(noShiftCurveArray.remove(index)); - remakeRatingCurveDataList(); + if (response == SWT.OK) { + // get rid of this point + int index = noShiftCurveDataList.getSelectionIndex(); + removedPoints.add(noShiftCurveArray.remove(index)); + remakeRatingCurveDataList(); - stageTF.setText(""); - dischargeTF.setText(""); + stageTF.setText(""); + dischargeTF.setText(""); - if (getEditingShiftData() != null) { - generateShiftList(getEditingShiftData()); - } + if (getEditingShiftData() != null) { + generateShiftList(getEditingShiftData()); + } - ratingCurveCanvas.updateCurveData(noShiftCurveArray, - floodDbl, recordDbl, shiftAmount); - } + ratingCurveCanvas.updateCurveData(noShiftCurveArray, + floodDbl, recordDbl, shiftAmount); + } } } }); @@ -616,7 +644,7 @@ public class RatingCurveDlg extends CaveSWTDialog { RatingCurveData rcd = new RatingCurveData(new Double( stageTF.getText().trim()), new Double(dischargeTF .getText().trim())); - insertBaseCurvePoint(rcd); + insertBaseCurvePoint(rcd); } } }); @@ -633,23 +661,28 @@ public class RatingCurveDlg extends CaveSWTDialog { shiftValueTF.setEditable(true); } } - - private void insertBaseCurvePoint(RatingCurveData rcd) { - if (!noShiftCurveArray.contains(rcd)) { - // Check for a matching stage value - RatingCurveData data = null; - for (RatingCurveData d: noShiftCurveArray) { - if (d.getStage() == rcd.getStage()) { - data = d; - break; - } - } - - if (data != null) { - noShiftCurveArray.remove(data); - } - noShiftCurveArray.add(rcd); + /** + * Insert Rating Curve Data removing any old reference to and old rcd. + * + * @param rcd + */ + private void insertBaseCurvePoint(RatingCurveData rcd) { + if (!noShiftCurveArray.contains(rcd)) { + // Check for a matching stage value + RatingCurveData data = null; + for (RatingCurveData d : noShiftCurveArray) { + if (d.getStage() == rcd.getStage()) { + data = d; + break; + } + } + + if (data != null) { + noShiftCurveArray.remove(data); + } + + noShiftCurveArray.add(rcd); if (!addedPoints.contains(rcd)) { addedPoints.add(rcd); } else { @@ -658,7 +691,7 @@ public class RatingCurveDlg extends CaveSWTDialog { } remakeRatingCurveDataList(); - + if (getEditingShiftData() != null) { if (getEditingShiftData().isActive()) { int index = shiftDataList.getSelectionIndex(); @@ -666,15 +699,14 @@ public class RatingCurveDlg extends CaveSWTDialog { ratingCurveCanvas.updateCurveData(shiftCurveArray, floodDbl, recordDbl, shiftAmount); } else { - ratingCurveCanvas.updateCurveData( - noShiftCurveArray, floodDbl, recordDbl, - shiftAmount); + ratingCurveCanvas.updateCurveData(noShiftCurveArray, + floodDbl, recordDbl, shiftAmount); } } else { - ratingCurveCanvas.updateCurveData(noShiftCurveArray, - floodDbl, recordDbl, shiftAmount); + ratingCurveCanvas.updateCurveData(noShiftCurveArray, floodDbl, + recordDbl, shiftAmount); } - } + } } /** @@ -700,12 +732,13 @@ public class RatingCurveDlg extends CaveSWTDialog { shiftCurveDataList.setFont(controlFont); shiftCurveDataList.setLayoutData(gd); shiftCurveDataList.deselectAll(); - shiftCurveDataList.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY)); + shiftCurveDataList.setForeground(Display.getCurrent().getSystemColor( + SWT.COLOR_DARK_GRAY)); shiftCurveDataList.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - shiftCurveDataList.deselectAll(); - } + @Override + public void widgetSelected(SelectionEvent e) { + shiftCurveDataList.deselectAll(); + } }); gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false); @@ -724,26 +757,25 @@ public class RatingCurveDlg extends CaveSWTDialog { RatingCurveData data = noShiftCurveArray .get(noShiftCurveDataList.getSelectionIndex()); stageTF.setText(String.format("%7.2f", data.getStage())); - dischargeTF - .setText(String.format("%7.1f", data.getDischarge())); + dischargeTF.setText(String.format("%7.1f", data.getDischarge())); } }); if (noShiftCurveArray != null) { // populate the list - RatingCurveShiftData currentShift = null; - if (shiftData != null && shiftData.size() > 0) { - if (shiftData.get(0).isActive()) { - currentShift = shiftData.get(0); - } - } - + RatingCurveShiftData currentShift = null; + if (shiftData != null && shiftData.size() > 0) { + if (shiftData.get(0).isActive()) { + currentShift = shiftData.get(0); + } + } + for (RatingCurveData curve : noShiftCurveArray) { noShiftCurveDataList.add(curve.toString()); } if (noShiftCurveDataList.getItemCount() > 0) { - noShiftCurveDataList.select(0); - generateShiftList(currentShift); + noShiftCurveDataList.select(0); + generateShiftList(currentShift); } } @@ -834,7 +866,7 @@ public class RatingCurveDlg extends CaveSWTDialog { @Override public void widgetSelected(SelectionEvent event) { save(); - shell.dispose(); + close(); } }); @@ -858,7 +890,7 @@ public class RatingCurveDlg extends CaveSWTDialog { closeBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - shell.dispose(); + close(); } }); @@ -894,9 +926,9 @@ public class RatingCurveDlg extends CaveSWTDialog { if (shiftData != null) { for (RatingCurveShiftData rcsd : shiftData) { String fmtStr = "%10S %10S %10S"; - String tmpStr = String.format(fmtStr, sdf.format(rcsd.getDate() - .getTime()), df.format(rcsd.getValue()), rcsd - .isActive()); + String tmpStr = String.format(fmtStr, + sdf.format(rcsd.getDate().getTime()), + df.format(rcsd.getValue()), rcsd.isActive()); shiftDataList.add(tmpStr); } } @@ -907,11 +939,11 @@ public class RatingCurveDlg extends CaveSWTDialog { if (label != null) { ratingLbl.setText(label); } - + if (noShiftCurveArray.size() > 0) { - RatingCurveData rcd = noShiftCurveArray.get(0); - this.stageTF.setText(String.valueOf(rcd.getStage())); - this.dischargeTF.setText(String.valueOf(rcd.getDischarge())); + RatingCurveData rcd = noShiftCurveArray.get(0); + this.stageTF.setText(String.valueOf(rcd.getStage())); + this.dischargeTF.setText(String.valueOf(rcd.getDischarge())); } } @@ -965,7 +997,8 @@ public class RatingCurveDlg extends CaveSWTDialog { recordDbl, shiftAmount); newRatingCurve = true; } catch (Exception e) { - e.printStackTrace(); + statusHandler.handle(Priority.PROBLEM, + "Unable to import curve data: ", e); } return newRatingCurve; @@ -993,7 +1026,7 @@ public class RatingCurveDlg extends CaveSWTDialog { // redraw for the full effect shiftCurveDataList.redraw(); } else { - // make the rating curve with no shift data + // make the rating curve with no shift data for (RatingCurveData curve : noShiftCurveArray) { shiftCurveDataList.add(curve.toString()); } @@ -1017,8 +1050,7 @@ public class RatingCurveDlg extends CaveSWTDialog { MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL); mb.setText("Directory Chosen!"); - mb - .setMessage("Cannot open a directory, choose a rating curve. EX: 'NBD1.rating'"); + mb.setMessage("Cannot open a directory, choose a rating curve. EX: 'NBD1.rating'"); mb.open(); } // if they choose just the file to import @@ -1027,17 +1059,15 @@ public class RatingCurveDlg extends CaveSWTDialog { try { curve = readFile(fileName); } catch (VizException ve) { - VizApp.logAndAlert(Status.ERROR, ve, - "Error reading in file: " + fileName, - "Error reading in file: " + fileName, UiPlugin - .getDefault(), UiPlugin.PLUGIN_ID); + statusHandler.handle(Priority.PROBLEM, + "Unable to import file \"" + fileName + "\": ", + ve); } } else { MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL); mb.setText("Invalid File format Chosen!"); - mb - .setMessage("Cannot open this file format, choose rating curve. EX: 'NBD1.rating'"); + mb.setMessage("Cannot open this file format, choose rating curve. EX: 'NBD1.rating'"); mb.open(); } } @@ -1159,6 +1189,9 @@ public class RatingCurveDlg extends CaveSWTDialog { return true; } + /** + * Update or insert curve data. + */ private void updateInsert() { try { if (verifyDate(shiftDateTF) && verifyDouble(shiftValueTF)) { @@ -1167,74 +1200,81 @@ public class RatingCurveDlg extends CaveSWTDialog { .getInstance(TimeZone.getTimeZone("GMT")); cal.setTime(sdf.parse(shiftDateTF.getText())); RatingCurveShiftData rcsd = new RatingCurveShiftData(lid, cal, - new Double(shiftValueTF.getText()), shiftActiveChk - .getSelection()); - + new Double(shiftValueTF.getText()), + shiftActiveChk.getSelection()); + if (shiftData.size() > 0 && shiftData.contains(rcsd)) { - for (RatingCurveShiftData sd: shiftData) { - if (rcsd.toString().equals(sd.toString())) { - sd.setActive(rcsd.isActive()); - sd.setDate(rcsd.getDate()); - sd.setLid(rcsd.getLid()); - sd.setValue(rcsd.getValue()); - break; - } - } + for (RatingCurveShiftData sd : shiftData) { + if (rcsd.toString().equals(sd.toString())) { + sd.setActive(rcsd.isActive()); + sd.setDate(rcsd.getDate()); + sd.setLid(rcsd.getLid()); + sd.setValue(rcsd.getValue()); + break; + } + } } else { - shiftData.add(rcsd); + shiftData.add(rcsd); } - + if (!addedCurveShifts.contains(rcsd)) { - addedCurveShifts.add(rcsd); + addedCurveShifts.add(rcsd); } else { - addedCurveShifts.remove(rcsd); - addedCurveShifts.add(rcsd); + addedCurveShifts.remove(rcsd); + addedCurveShifts.add(rcsd); } shiftDataList.removeAll(); Collections.sort(shiftData); - for (RatingCurveShiftData sd: shiftData) { - shiftDataList.add(getShiftListString(sd)); + for (RatingCurveShiftData sd : shiftData) { + shiftDataList.add(getShiftListString(sd)); } // Display the latest shift RatingCurveShiftData currentShift = shiftData.get(0); if (currentShift.isActive()) { - generateShiftList(currentShift); - ratingCurveCanvas.updateCurveData(shiftCurveArray, - floodDbl, recordDbl, currentShift.getValue()); + generateShiftList(currentShift); + ratingCurveCanvas.updateCurveData(shiftCurveArray, + floodDbl, recordDbl, currentShift.getValue()); } else { - ratingCurveCanvas.updateCurveData(noShiftCurveArray, - floodDbl, recordDbl, 0); + ratingCurveCanvas.updateCurveData(noShiftCurveArray, + floodDbl, recordDbl, 0); } } - + shiftValueTF.setText(""); shiftDateTF.setText(""); shiftActiveChk.setSelection(false); } catch (Exception e) { - e.printStackTrace(); + statusHandler.handle(Priority.PROBLEM, + "Unable to insert/update curve data: ", e); } } - + + /** + * Remove the selected entries from the shift data list. + */ private void removeShift() { - if (shiftDataList.getItemCount() > 0 && shiftDataList.getSelectionCount() > 0) { - MessageBox messageDialog = new MessageBox(shell, SWT.OK | SWT.CANCEL); + if (shiftDataList.getItemCount() > 0 + && shiftDataList.getSelectionCount() > 0) { + MessageBox messageDialog = new MessageBox(shell, SWT.OK + | SWT.CANCEL); messageDialog.setText("Shift Remove Confirmation"); messageDialog.setMessage("This will remove the highlighted shift."); int response = messageDialog.open(); if (response == SWT.OK) { - String selection = shiftDataList.getItem(shiftDataList.getSelectionIndex()); - for (RatingCurveShiftData sd: shiftData) { - if (getShiftListString(sd).equals(selection)) { - removedCurveShifts.add(sd); - break; - } - } - - shiftData.removeAll(removedCurveShifts); + String selection = shiftDataList.getItem(shiftDataList + .getSelectionIndex()); + for (RatingCurveShiftData sd : shiftData) { + if (getShiftListString(sd).equals(selection)) { + removedCurveShifts.add(sd); + break; + } + } + + shiftData.removeAll(removedCurveShifts); shiftDataList.removeAll(); Collections.sort(shiftData); for (RatingCurveShiftData rcsd : shiftData) { @@ -1243,26 +1283,26 @@ public class RatingCurveDlg extends CaveSWTDialog { shiftDataList.redraw(); if (shiftData.size() > 0) { - shiftAmount = shiftData.get(0).getValue(); + shiftAmount = shiftData.get(0).getValue(); } else { - shiftAmount = 0; + shiftAmount = 0; + } + + ratingCurveCanvas.updateCurveData(noShiftCurveArray, floodDbl, + recordDbl, shiftAmount); + + if (shiftData.size() > 0) { + RatingCurveShiftData currentShift = shiftData.get(0); + if (currentShift.isActive()) { + generateShiftList(currentShift); + } else { + generateShiftList(null); + } + } else { + generateShiftList(null); } - - ratingCurveCanvas.updateCurveData(noShiftCurveArray, - floodDbl, recordDbl, shiftAmount); - - if (shiftData.size() > 0) { - RatingCurveShiftData currentShift = shiftData.get(0); - if (currentShift.isActive()) { - generateShiftList(currentShift); - } else { - generateShiftList(null); - } - } else { - generateShiftList(null); - } } - } + } } /** @@ -1307,8 +1347,9 @@ public class RatingCurveDlg extends CaveSWTDialog { private String getShiftListString(RatingCurveShiftData rcsd) { String fmtStr = "%10S %10S %10S"; - String tmpStr = String.format(fmtStr, sdf.format(rcsd.getDate() - .getTime()), df.format(rcsd.getValue()), rcsd.isActive()); + String tmpStr = String.format(fmtStr, + sdf.format(rcsd.getDate().getTime()), + df.format(rcsd.getValue()), rcsd.isActive()); return tmpStr; } @@ -1326,34 +1367,35 @@ public class RatingCurveDlg extends CaveSWTDialog { * update the noShiftCurveDataList */ private void remakeRatingCurveDataList() { - Collections.sort(noShiftCurveArray); - int index = noShiftCurveDataList.getSelectionIndex(); + Collections.sort(noShiftCurveArray); + int index = noShiftCurveDataList.getSelectionIndex(); noShiftCurveDataList.removeAll(); shiftCurveDataList.removeAll(); for (RatingCurveData rcd : noShiftCurveArray) { noShiftCurveDataList.add(rcd.toString()); } - + if (shiftData.size() > 0) { - RatingCurveShiftData currentShift = shiftData.get(0); - if (currentShift.isActive()) { - generateShiftList(currentShift); - } else { - generateShiftList(null); - } + RatingCurveShiftData currentShift = shiftData.get(0); + if (currentShift.isActive()) { + generateShiftList(currentShift); + } else { + generateShiftList(null); + } } else { generateShiftList(null); } - + if (noShiftCurveDataList.getItemCount() > 0) { - if (index >= noShiftCurveDataList.getItemCount()) { - noShiftCurveDataList.select(noShiftCurveDataList.getItemCount() - 1); - } else if (index >= 0 && index < noShiftCurveArray.size()) { - noShiftCurveDataList.select(index); - } else { - noShiftCurveDataList.select(0); - } - noShiftCurveDataList.showSelection(); + if (index >= noShiftCurveDataList.getItemCount()) { + noShiftCurveDataList + .select(noShiftCurveDataList.getItemCount() - 1); + } else if (index >= 0 && index < noShiftCurveArray.size()) { + noShiftCurveDataList.select(index); + } else { + noShiftCurveDataList.select(0); + } + noShiftCurveDataList.showSelection(); } } @@ -1368,7 +1410,7 @@ public class RatingCurveDlg extends CaveSWTDialog { } /** - * Get an intance of the Stage data label + * Get an instance of the Stage data label * * @return the label */ diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/texteditor/FindReplaceDlg.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/texteditor/FindReplaceDlg.java index 8d6fef3a3e..62f2e5318f 100755 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/texteditor/FindReplaceDlg.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/texteditor/FindReplaceDlg.java @@ -43,6 +43,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 04 SEP 2008 lvenable Initial creation + * 15 JUL 2013 2088 rferrel Make dialog non-blocking. * * * @@ -90,12 +91,7 @@ public class FindReplaceDlg extends CaveSWTDialog { /** * Text Editor buffer with everything upper-case. */ - private StringBuffer editorTextBufUpcase; - - /** - * Number of characters. - */ - private int characterCount = -9999; + private final StringBuilder editorTextBufUpcase; /** * Found word index. @@ -111,12 +107,19 @@ public class FindReplaceDlg extends CaveSWTDialog { * Text editor containing the text to be searched. */ public FindReplaceDlg(Shell parent, StyledText textEditor) { - super(parent); + super(parent, SWT.DIALOG_TRIM, CAVE.DO_NOT_BLOCK); setText("Find and Replace"); this.textEditor = textEditor; + this.editorTextBufUpcase = new StringBuilder(textEditor.getText() + .length()); } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#constructShellLayout() + */ @Override protected Layout constructShellLayout() { GridLayout mainLayout = new GridLayout(1, false); @@ -125,6 +128,13 @@ public class FindReplaceDlg extends CaveSWTDialog { return mainLayout; } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#initializeComponents(org + * .eclipse.swt.widgets.Shell) + */ @Override protected void initializeComponents(Shell shell) { createSearchReplaceTextField(); @@ -232,7 +242,7 @@ public class FindReplaceDlg extends CaveSWTDialog { closeBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - shell.dispose(); + close(); } }); } @@ -251,11 +261,8 @@ public class FindReplaceDlg extends CaveSWTDialog { * Check if there has been updates to the text editor. */ private void checkForUpdates() { - if (characterCount != textEditor.getText().length()) { - characterCount = textEditor.getText().length(); - editorTextBufUpcase = new StringBuffer(textEditor.getText() - .toUpperCase()); - } + editorTextBufUpcase.setLength(0); + editorTextBufUpcase.append(textEditor.getText().toUpperCase()); if (caretPosition != textEditor.getCaretOffset()) { caretPosition = textEditor.getCaretOffset(); @@ -349,16 +356,8 @@ public class FindReplaceDlg extends CaveSWTDialog { * "Replace by" text field */ private void replaceAll() { - while (1 == 1) { - if (findWhatText()) { - replaceText(); - } else { - break; - } + while (findWhatText()) { + replaceText(); } } - - public void bringToFront() { - shell.setActive(); - } } diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/texteditor/TextEditorDlg.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/texteditor/TextEditorDlg.java index b07a3498c4..a958f48fe3 100644 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/texteditor/TextEditorDlg.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/texteditor/TextEditorDlg.java @@ -59,6 +59,8 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * ------------ ---------- ----------- -------------------------- * Sep 9, 2008 lvenable Initial creation * Sep 18, 2009 2772 mpduff Fixed NullPointer when opening in Read only. + * Jul 15, 2013 2088 rferrel Changes for non-blocking FindReplaceDlg. + * Make dialog non-blocking. * * * @@ -172,20 +174,6 @@ public class TextEditorDlg extends CaveSWTDialog { */ private Image findReplaceImage; - /** - * Constructor. - * - * @param parent - * Parent shell. - * @param readOnly - * Read only flag. - * @param fileName - * File name in string format. - */ - public TextEditorDlg(Shell parent, boolean readOnly, String fileName) { - this(parent, readOnly, new File(fileName)); - } - /** * Constructor. * @@ -197,19 +185,27 @@ public class TextEditorDlg extends CaveSWTDialog { * File to view/edit. */ public TextEditorDlg(Shell parent, boolean readOnly, File file) { - super(parent, SWT.DIALOG_TRIM | SWT.RESIZE); - if (textFile != null) { - if (readOnly == true) { - setText(textFile.getName() + " - (Read Only)"); - } else { - setText(textFile.getName()); - } - } - + super(parent, SWT.DIALOG_TRIM | SWT.RESIZE, CAVE.DO_NOT_BLOCK); textFile = file; this.readOnly = readOnly; + + if (textFile != null) { + StringBuilder sb = new StringBuilder("Text Editor - "); + sb.append(textFile.getName()); + if (readOnly == true) { + sb.append(" (Read Only)"); + } + setText(sb.toString()); + } + + setReturnValue(file); } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#constructShellLayout() + */ @Override protected Layout constructShellLayout() { // Create the main layout for the shell. @@ -220,6 +216,11 @@ public class TextEditorDlg extends CaveSWTDialog { return mainLayout; } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#disposed() + */ @Override protected void disposed() { controlFont.dispose(); @@ -233,9 +234,15 @@ public class TextEditorDlg extends CaveSWTDialog { redoImage.dispose(); } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#initializeComponents(org + * .eclipse.swt.widgets.Shell) + */ @Override protected void initializeComponents(Shell shell) { - setReturnValue(false); controlFont = new Font(shell.getDisplay(), "Monospace", 10, SWT.NORMAL); undoRedoArray = new ArrayList(); @@ -252,6 +259,11 @@ public class TextEditorDlg extends CaveSWTDialog { textST.setFocus(); } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#shouldOpen() + */ @Override protected boolean shouldOpen() { // Verify file name @@ -261,12 +273,10 @@ public class TextEditorDlg extends CaveSWTDialog { mb.setMessage("The following file does not exist:\n" + textFile.getAbsolutePath()); mb.open(); - setReturnValue(false); return false; } if (readFile() == false) { - setReturnValue(false); return false; } return true; @@ -281,7 +291,6 @@ public class TextEditorDlg extends CaveSWTDialog { createFileMenu(menuBar); createEditMenu(menuBar); createOptionsMenu(menuBar); - // createHelpMenu(menuBar); shell.setMenuBar(menuBar); } @@ -338,7 +347,7 @@ public class TextEditorDlg extends CaveSWTDialog { exitMI.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - shell.dispose(); + close(); } }); } @@ -652,8 +661,6 @@ public class TextEditorDlg extends CaveSWTDialog { br.close(); fr.close(); } catch (Exception e) { - e.printStackTrace(); - MessageBox mb = new MessageBox(getParent(), SWT.ICON_ERROR | SWT.OK); mb.setText("File Error"); mb.setMessage("An error occurred reading the file:\n" @@ -736,15 +743,14 @@ public class TextEditorDlg extends CaveSWTDialog { } /** - * DIsplay the find and replace dialog. + * Display the find and replace dialog. */ private void findReplaceText() { - if (findReplaceDlg == null) { + if (findReplaceDlg == null || findReplaceDlg.isDisposed()) { findReplaceDlg = new FindReplaceDlg(shell, textST); findReplaceDlg.open(); - findReplaceDlg = null; } else { - findReplaceDlg.bringToFront(); + findReplaceDlg.bringToTop(); } } @@ -754,27 +760,18 @@ public class TextEditorDlg extends CaveSWTDialog { private void saveFile() { FileWriter fw; - // IPathManager pm = PathManagerFactory.getPathManager(); - // LocalizationContext lc = - // pm.getContext(LocalizationType.COMMON_STATIC, - // LocalizationLevel.SITE); - // LocalizationFile newTextFile = pm.getLocalizationFile(lc, - // "hydro/" + textFile.getName()); - try { - // fw = new FileWriter(newTextFile.getFile(), false); fw = new FileWriter(textFile, false); fw.write(textST.getText()); fw.flush(); fw.close(); - // newTextFile.save(); } catch (IOException e) { - e.printStackTrace(); - // } catch (LocalizationCommunicationException e) { - // e.printStackTrace(); - // } catch (LocalizationOpFailedException e) { - // e.printStackTrace(); + MessageBox mb = new MessageBox(getParent(), SWT.ICON_ERROR | SWT.OK); + mb.setText("File Error"); + mb.setMessage("Unable to save file:\n" + textFile.getAbsolutePath() + + "\n" + e.getMessage()); + mb.open(); } }