Issue #1790 Changes for non-blocking StationProfileDlg.

Change-Id: I669c9115dd1bb506acd025a451163aaf664593ef

Former-commit-id: d21cb5e2e8 [formerly 57eb492610a3cc2974badc6072c2a026f5640b79]
Former-commit-id: 0d269691e2
This commit is contained in:
Roger Ferrel 2013-03-29 17:08:19 -05:00
parent 611661ccc9
commit e1b40f9f2f
2 changed files with 148 additions and 85 deletions

View file

@ -22,6 +22,9 @@
*/
package com.raytheon.viz.hydro.stationprofile;
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;
@ -29,6 +32,7 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import com.raytheon.viz.hydrocommon.HydroDisplayManager;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
/**
* Action for unimplemented features. To be used temporarily until final
@ -42,6 +46,7 @@ import com.raytheon.viz.hydrocommon.HydroDisplayManager;
* ------------ ---------- ----------- --------------------------
* 6/27/06 lvenable Initial Creation.
* 17 Nov 2008 1628 dhladky Little update.
* 29 Mar 2013 1790 rferrel Changes for non-blocking StationProfileDlg.
*
* </pre>
*
@ -49,7 +54,18 @@ import com.raytheon.viz.hydrocommon.HydroDisplayManager;
*
*/
public class StationProfileAction extends AbstractHandler {
/**
* Keep track of open dialogs.
*/
Map<String, StationProfileDlg> dialogMap = new HashMap<String, StationProfileDlg>();
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
* .ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
@ -58,8 +74,30 @@ public class StationProfileAction extends AbstractHandler {
// get the name for this gage...gage has to be selected.
HydroDisplayManager manager = HydroDisplayManager.getInstance();
if (manager.isCurrentLidSelected(shell)) {
StationProfileDlg stationProfileDlg = new StationProfileDlg(shell, manager.getCurrentLid());
stationProfileDlg.open();
String currentLid = manager.getCurrentLid();
StationProfileDlg stationProfileDlg = dialogMap.get(currentLid);
if (stationProfileDlg == null) {
stationProfileDlg = new StationProfileDlg(shell, currentLid);
stationProfileDlg.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
if (returnValue instanceof String) {
String currentLid = returnValue.toString();
dialogMap.remove(currentLid);
}
}
});
Object o = stationProfileDlg.open();
if (o != null) {
// Dialog found data and properly opened.
dialogMap.put(currentLid, stationProfileDlg);
}
} else {
stationProfileDlg.setStation(currentLid);
stationProfileDlg.bringToTop();
}
}
// throws up dialog

View file

@ -22,11 +22,8 @@ package com.raytheon.viz.hydro.stationprofile;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import org.eclipse.swt.SWT;
@ -53,7 +50,6 @@ import com.raytheon.uf.common.dataplugin.shef.tables.Statprof;
import com.raytheon.viz.hydro.util.MaxObsFcst;
import com.raytheon.viz.hydrocommon.HydroConstants;
import com.raytheon.viz.hydrocommon.HydroDisplayManager;
import com.raytheon.viz.hydrocommon.data.RiverDataPoint;
import com.raytheon.viz.hydrocommon.datamanager.RiverDataManager;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
@ -68,6 +64,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* 15 Nov 2008 1628 dhladky Made it work.
* 15 Jun 2010 4304 mpduff Added some null checks.
* 30 Nov 2011 11253 lbousaidi used List instead of TreeMap
* 29 Mar 2013 1790 rferrel Make dialog non-blocking.
*
* </pre>
*
@ -231,8 +228,6 @@ public class StationProfileDlg extends CaveSWTDialog {
private Map<String, HydroDataReport> allReports = new HashMap<String, HydroDataReport>();
private LinkedHashMap<String, RiverDataPoint> riverPoints = null;
private List<Statprof> stationList = new ArrayList<Statprof>();
private boolean displayDlg = true;
@ -244,11 +239,11 @@ public class StationProfileDlg extends CaveSWTDialog {
* Parent shell.
*/
public StationProfileDlg(Shell parent, String selectedLid) {
super(parent);
super(parent, SWT.DIALOG_TRIM, CAVE.DO_NOT_BLOCK);
setText("Station Profile");
this.selectedLid = selectedLid;
setReturnValue(selectedLid);
loadStationProfileData();
if (stationProfData != null) {
calculateValues();
@ -257,21 +252,37 @@ public class StationProfileDlg extends CaveSWTDialog {
}
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#disposed()
*/
@Override
protected void disposed() {
font.dispose();
profileColor.dispose();
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#initializeComponents(org
* .eclipse.swt.widgets.Shell)
*/
@Override
protected void initializeComponents(Shell shell) {
setReturnValue(false);
profileColor = new Color(getDisplay(), 216, 212, 100);
font = new Font(shell.getDisplay(), "Monospace", 10, SWT.NORMAL);
initializeComponents();
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#shouldOpen()
*/
@Override
protected boolean shouldOpen() {
if (displayDlg) {
@ -281,6 +292,7 @@ public class StationProfileDlg extends CaveSWTDialog {
mb.setText("Data Not Available");
mb.setMessage("Unable to retrieve station information.");
mb.open();
setReturnValue(null);
return false;
}
}
@ -377,14 +389,10 @@ public class StationProfileDlg extends CaveSWTDialog {
gd = new GridData(100, SWT.DEFAULT);
stationCbo = new Combo(infoComp, SWT.DROP_DOWN | SWT.READ_ONLY);
populateStationCbo();
int j = 0;
for (int i = 0; i < stationCbo.getItemCount(); i++) {
if (stationCbo.getItem(i).equals(selectedLid)) {
j = i;
break;
}
}
int j = stationCbo.indexOf(selectedLid);
if (j >= 0) {
stationCbo.select(j);
}
stationCbo.setLayoutData(gd);
stationCbo.addSelectionListener(new SelectionAdapter() {
@Override
@ -674,7 +682,7 @@ public class StationProfileDlg extends CaveSWTDialog {
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
int i = 0;
for (Statprof station: stationList) {
for (Statprof station : stationList) {
// Skip gage if the river mile is not valid
if (station.getId().getMile() == HydroConstants.MISSING_VALUE) {
continue;
@ -689,27 +697,29 @@ public class StationProfileDlg extends CaveSWTDialog {
e.gc.drawLine(x, y, x, y + POINT_HASH);
/*
* determine color of staff, based on proximity to action
* or flood STAGE or DISCHARGE as appropriate.
* determine color of staff, based on proximity to action or
* flood STAGE or DISCHARGE as appropriate.
*/
HydroDataReport report = allReports.get(station.getId().getLid());
HydroDataReport report = allReports.get(station.getId()
.getLid());
RGB rgb = new RGB(0, 255, 0);
if (report != null) {
if (station.getId().getPrimaryPe().startsWith("H")) {
if ((report.getValue() > station.getId().getFs()) &&
(station.getId().getFs() > 0)) {
if ((report.getValue() > station.getId().getFs())
&& (station.getId().getFs() > 0)) {
rgb = new RGB(255, 0, 0);
} else if ((report.getValue() > station.getId().getWstg()) &&
(station.getId().getWstg() > 0)) {
} else if ((report.getValue() > station.getId()
.getWstg()) && (station.getId().getWstg() > 0)) {
rgb = new RGB(255, 255, 0);
} // else use default green
} else {
if ((report.getValue() > station.getId().getFq()) &&
(station.getId().getFs() > 0)) {
if ((report.getValue() > station.getId().getFq())
&& (station.getId().getFs() > 0)) {
rgb = new RGB(255, 0, 0);
} else if ((report.getValue() > station.getId().getActionFlow()) &&
(station.getId().getWstg() > 0)) {
} else if ((report.getValue() > station.getId()
.getActionFlow())
&& (station.getId().getWstg() > 0)) {
rgb = new RGB(255, 255, 0);
} // else use default green
}
@ -887,7 +897,7 @@ public class StationProfileDlg extends CaveSWTDialog {
int lastY = points.get(5);
// Get gage bar points
for (Statprof station: stationList) {
for (Statprof station : stationList) {
// Skip gage if the river mile is not valid
if (station.getId().getMile() == HydroConstants.MISSING_VALUE) {
continue;
@ -962,7 +972,7 @@ public class StationProfileDlg extends CaveSWTDialog {
* Populate the station combo box.
*/
private void populateStationCbo() {
if (stationList !=null) {
if (stationList != null) {
for (Statprof station : stationList) {
String stations = station.getId().getLid();
stationCbo.add(stations);
@ -974,16 +984,16 @@ public class StationProfileDlg extends CaveSWTDialog {
* Update the station profile information fields using the selected station.
*/
private void updateInformationFields() {
if (stationProfData != null) {
Statprof data = stationProfData.getStationData(stationCbo
.getText());
if (stationProfData != null && stationCbo.getSelectionIndex() >= 0) {
Statprof data = stationProfData
.getStationData(stationCbo.getText());
String name = null;
if (data.getId().getProximity() == null) {
name = String.format("%s %s %s", data.getId().getStream(), "AT",
data.getId().getName());
} else {
name = String.format("%s %s %s", data.getId().getStream(),
data.getId().getProximity(), data.getId().getName());
"AT", data.getId().getName());
} else {
name = String.format("%s %s %s", data.getId().getStream(), data
.getId().getProximity(), data.getId().getName());
}
if (name != null) {
@ -998,7 +1008,8 @@ public class StationProfileDlg extends CaveSWTDialog {
actionTF.setText(String.format("%5.2f", data.getId().getWstg()));
floodTF.setText(String.format("%5.2f", data.getId().getFs()));
} else {
actionTF.setText(String.format("%5.2f", data.getId().getActionFlow()));
actionTF.setText(String.format("%5.2f", data.getId()
.getActionFlow()));
floodTF.setText(String.format("%5.2f", data.getId().getFq()));
}
}
@ -1046,8 +1057,9 @@ public class StationProfileDlg extends CaveSWTDialog {
mileRange = MIN_RIVER_MILES;
}
for (Statprof station: stationList) {
stationProfData.addStationData(station.getId().getLid(), station);
for (Statprof station : stationList) {
stationProfData.addStationData(station.getId().getLid(),
station);
}
}
}
@ -1177,10 +1189,10 @@ public class StationProfileDlg extends CaveSWTDialog {
/**
* Load the data reports into memory.
*
* @param dataList - List of Statprof objects
* @param dataList
* - List of Statprof objects
*/
private void loadStatProfReports(
List<Statprof> dataList) {
private void loadStatProfReports(List<Statprof> dataList) {
int hoursBack = 72;
int fcstBasisHoursAgo = 72;
@ -1212,4 +1224,17 @@ public class StationProfileDlg extends CaveSWTDialog {
}
}
}
/**
* Select the desired station and update the display.
*
* @param station
*/
public void setStation(String station) {
if (stationCbo != null && !shell.isDisposed()) {
int j = stationCbo.indexOf(station);
stationCbo.select(j);
updateInformationFields();
}
}
}