Issue #2088 changes for non-blocking RatingCurveDlg, FindReplaceDlg and TextEditorDlg.

Change-Id: I8d651254e862a45c1dad33c0d4991b29f1611828

Former-commit-id: 5884bb5692 [formerly d620283c3b] [formerly 5884bb5692 [formerly d620283c3b] [formerly 3eacead9bb [formerly d71b87606a93f744984f45aec8887dbc0052bb4e]]]
Former-commit-id: 3eacead9bb
Former-commit-id: 19ef062429 [formerly c556150c27]
Former-commit-id: a0b46a31ba
This commit is contained in:
Roger Ferrel 2013-07-16 10:20:50 -05:00
parent 6b5bb6c22c
commit adec97370a
9 changed files with 485 additions and 355 deletions

View file

@ -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.
*
* </pre>
*
@ -53,17 +54,23 @@ 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) {
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);
mb.setText("File Error");

View file

@ -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.
*
* </pre>
*
@ -50,6 +55,8 @@ import com.raytheon.viz.hydrocommon.ratingcurve.RatingCurveDlg;
*
*/
public class RatingCurveAction extends AbstractHandler {
private Map<String, RatingCurveDlg> ratingCurveDlgMap = new HashMap<String, RatingCurveDlg>();
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();
RatingCurveDlg ratingCurveDlg = ratingCurveDlgMap.get(lid);
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);
}
String displayString = " - "
+ lid
+ ((name != null && name.compareTo("") != 0) ? " - " + name
: "");
ratingCurveDlg = new RatingCurveDlg(shell, lid,
displayString.toString(), false);
ratingCurveDlg.setCloseCallback(new ICloseCallback() {
RatingCurveDlg ratingCurveDlg = new RatingCurveDlg(shell, lid,
displayString, false);
@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;

View file

@ -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.
*
* </pre>
*
@ -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()) {
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 + "."

View file

@ -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.
*
* </pre>
*
@ -352,6 +353,11 @@ public class HydroBaseDlg extends CaveSWTDialog implements IGetSortType,
*/
private final Map<String, LowWaterStatementDlg> lowWaterStmntDlgMap = new HashMap<String, LowWaterStatementDlg>();
/**
* Allow one instance per station.
*/
private final Map<String, RatingCurveDlg> ratingCurveDlgMap = new HashMap<String, RatingCurveDlg>();
/**
* 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.
*

View file

@ -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.
*
* </pre>
*
@ -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<File, TextEditorDlg> textEditorDlgMap = new HashMap<File, TextEditorDlg>();
/**
* 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);
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);
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<Coordinate> getPointsFromArea(GeoAreaData data) {
ArrayList<Coordinate> points = new ArrayList<Coordinate>();
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++;
}
}

View file

@ -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.
*
* </pre>
*
@ -134,6 +135,7 @@ public class RatingCurveCanvasComp extends Canvas {
* Minimum flow KCFS value.
*/
private double minFlowKcfs = 0.0;
/**
* Divisor for the flow value.
*/
@ -152,7 +154,7 @@ public class RatingCurveCanvasComp extends Canvas {
/**
* Array of curve data.
*/
private ArrayList<RatingCurveData> curveDataArray;
private List<RatingCurveData> curveDataArray;
/**
* Number of hashes on the vertical graph line.
@ -229,7 +231,7 @@ public class RatingCurveCanvasComp extends Canvas {
* Record value.
*/
public RatingCurveCanvasComp(Composite parent, RatingCurveDlg parentDlg,
ArrayList<RatingCurveData> curveDataArray, double floodVal,
List<RatingCurveData> 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<RatingCurveData> curveDataArray,
public void updateCurveData(List<RatingCurveData> curveDataArray,
double floodVal, double recordDbl, double shiftAmount) {
floodValDbl = floodVal;
recordValDbl = recordDbl;
@ -331,7 +333,6 @@ public class RatingCurveCanvasComp extends Canvas {
minStageFeet = 0.0;
minFlowKcfs = 0.0;
if (curveDataArray != null) {
for (RatingCurveData curveData : curveDataArray) {
if (curveData.getStage() > maxStageFeet) {
@ -376,8 +377,10 @@ public class RatingCurveCanvasComp extends Canvas {
}
}
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,8 +388,9 @@ 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);
@ -473,7 +477,8 @@ public class RatingCurveCanvasComp extends Canvas {
yCoord);
// draw label
gc.drawString(String.format("%5.1f", minStageFeetLabelVal + (x * 10)),
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(
@ -549,18 +548,16 @@ public class RatingCurveCanvasComp extends Canvas {
gc.drawOval(xCoord - circleWidth / 2, yCoord - circleHeight / 2,
circleWidth, circleHeight);
// Region r = new Region();
oldX = xCoord;
oldY = yCoord;
}
}
/**
* 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,18 +596,21 @@ 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)));
}
}

View file

@ -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.
* </pre>
*
* @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<RatingCurveData> noShiftCurveArray;
private java.util.List<RatingCurveData> noShiftCurveArray;
/**
* Array of rating curve data (with shift curve).
*/
private ArrayList<RatingCurveData> shiftCurveArray;
private java.util.List<RatingCurveData> shiftCurveArray;
/**
* Shift Data if available
*/
private ArrayList<RatingCurveShiftData> shiftData;
private java.util.List<RatingCurveShiftData> 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<RatingCurveData> removedPoints = null;
private ArrayList<RatingCurveData> addedPoints = null;
private java.util.List<RatingCurveData> removedPoints = null;
/**
* rating curve shift points
* Rating curve added points.
*/
private ArrayList<RatingCurveShiftData> removedCurveShifts = null;
private java.util.List<RatingCurveData> addedPoints = null;
private ArrayList<RatingCurveShiftData> addedCurveShifts = null;
/**
* Rating curve remove shift points.
*/
private java.util.List<RatingCurveShiftData> removedCurveShifts = null;
/**
* Rating curve added shift points.
*/
private java.util.List<RatingCurveShiftData> 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<RatingCurveShiftData>();
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
@ -521,7 +546,8 @@ public class RatingCurveDlg extends CaveSWTDialog {
@Override
public void widgetSelected(SelectionEvent event) {
final String tokenizedDir = "whfs_import_dir";
String importRating= AppsDefaults.getInstance().getToken(tokenizedDir);
String importRating = AppsDefaults.getInstance().getToken(
tokenizedDir);
FileDialog fd = new FileDialog(shell, SWT.OPEN);
fd.setFilterPath(importRating);
String[] filterExt = { "*." + extension };
@ -543,9 +569,11 @@ 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) {
@ -565,8 +593,8 @@ public class RatingCurveDlg extends CaveSWTDialog {
dischargeTF.setText("");
selectedRatingShift = null;
ratingCurveCanvas.updateCurveData(noShiftCurveArray, floodDbl,
recordDbl, shiftAmount);
ratingCurveCanvas.updateCurveData(noShiftCurveArray,
floodDbl, recordDbl, shiftAmount);
}
}
});
@ -634,11 +662,16 @@ public class RatingCurveDlg extends CaveSWTDialog {
}
}
/**
* 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) {
for (RatingCurveData d : noShiftCurveArray) {
if (d.getStage() == rcd.getStage()) {
data = d;
break;
@ -665,15 +698,14 @@ public class RatingCurveDlg extends CaveSWTDialog {
generateShiftList(shiftData.get(index));
ratingCurveCanvas.updateCurveData(shiftCurveArray,
floodDbl, recordDbl, shiftAmount);
} else {
ratingCurveCanvas.updateCurveData(
noShiftCurveArray, floodDbl, recordDbl,
shiftAmount);
}
} else {
ratingCurveCanvas.updateCurveData(noShiftCurveArray,
floodDbl, recordDbl, shiftAmount);
}
} else {
ratingCurveCanvas.updateCurveData(noShiftCurveArray, floodDbl,
recordDbl, shiftAmount);
}
}
}
@ -700,7 +732,8 @@ 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) {
@ -724,8 +757,7 @@ 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()));
}
});
@ -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);
}
}
@ -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;
@ -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,11 +1200,11 @@ 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) {
for (RatingCurveShiftData sd : shiftData) {
if (rcsd.toString().equals(sd.toString())) {
sd.setActive(rcsd.isActive());
sd.setDate(rcsd.getDate());
@ -1194,7 +1227,7 @@ public class RatingCurveDlg extends CaveSWTDialog {
shiftDataList.removeAll();
Collections.sort(shiftData);
for (RatingCurveShiftData sd: shiftData) {
for (RatingCurveShiftData sd : shiftData) {
shiftDataList.add(getShiftListString(sd));
}
@ -1214,20 +1247,27 @@ public class RatingCurveDlg extends CaveSWTDialog {
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) {
String selection = shiftDataList.getItem(shiftDataList
.getSelectionIndex());
for (RatingCurveShiftData sd : shiftData) {
if (getShiftListString(sd).equals(selection)) {
removedCurveShifts.add(sd);
break;
@ -1248,8 +1288,8 @@ public class RatingCurveDlg extends CaveSWTDialog {
shiftAmount = 0;
}
ratingCurveCanvas.updateCurveData(noShiftCurveArray,
floodDbl, recordDbl, shiftAmount);
ratingCurveCanvas.updateCurveData(noShiftCurveArray, floodDbl,
recordDbl, shiftAmount);
if (shiftData.size() > 0) {
RatingCurveShiftData currentShift = shiftData.get(0);
@ -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;
}
@ -1347,7 +1388,8 @@ public class RatingCurveDlg extends CaveSWTDialog {
if (noShiftCurveDataList.getItemCount() > 0) {
if (index >= noShiftCurveDataList.getItemCount()) {
noShiftCurveDataList.select(noShiftCurveDataList.getItemCount() - 1);
noShiftCurveDataList
.select(noShiftCurveDataList.getItemCount() - 1);
} else if (index >= 0 && index < noShiftCurveArray.size()) {
noShiftCurveDataList.select(index);
} else {
@ -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
*/

View file

@ -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.
*
* </pre>
*
@ -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()) {
while (findWhatText()) {
replaceText();
} else {
break;
}
}
}
public void bringToFront() {
shell.setActive();
}
}

View file

@ -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.
*
* </pre>
*
@ -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<String>();
@ -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();
}
}