Issue #1298 Testing for 1229 discovered existing bug in WeatherPlotDialog where dispose listener was being added in a non UI thread.

Change-Id: I2bced344aa83035fc62e36a377e8182bf3aebf7c

Former-commit-id: 5e7227d1b0 [formerly c34b777804 [formerly 0b87e0fdfd] [formerly 5e7227d1b0 [formerly bdf2bf3c1e3b907fb16acf82dda230f97a3cc517]]]
Former-commit-id: c34b777804 [formerly 0b87e0fdfd]
Former-commit-id: c34b777804
Former-commit-id: f945dbc58b
This commit is contained in:
Roger Ferrel 2012-11-26 12:35:27 -06:00
parent 8f414354eb
commit 31ecad567d
3 changed files with 55 additions and 44 deletions

View file

@ -32,6 +32,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.localization.IPathManager;
@ -55,6 +57,9 @@ import com.raytheon.viz.aviation.monitor.AvnPyUtil;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 19, 2011 8065 rferrel Initial creation
* Nov 11, 2012 1298 rferrel Non-blocking dialog discovered problem
* adding dispose listener when not on the
* UI thread.
*
* </pre>
*
@ -111,6 +116,8 @@ public class PythonCacheGuidanceJob extends
*/
boolean suspendJob;
private boolean disposeSet;
/**
* Obtain the singleton instance of this class.
*
@ -123,6 +130,12 @@ public class PythonCacheGuidanceJob extends
instance.setSystem(true);
instance.schedule();
}
// Only setup dispose listener first time on the UI thread.
if (instance.disposeSet == false && Display.getCurrent() != null) {
instance.setupDispose();
instance.disposeSet = true;
}
return instance;
}
@ -138,7 +151,7 @@ public class PythonCacheGuidanceJob extends
suspendMonitor = new Object();
suspendJob = false;
waitList = new ArrayList<CacheGuidanceRequest>();
setupDispose();
disposeSet = false;
}
/**
@ -191,14 +204,15 @@ public class PythonCacheGuidanceJob extends
* is running.
*/
private void setupDispose() {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()
.addDisposeListener(new DisposeListener() {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
shutdown();
}
});
@Override
public void widgetDisposed(DisposeEvent e) {
shutdown();
}
});
}
/**

View file

@ -40,6 +40,9 @@ import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.python.PyUtil;
import com.raytheon.uf.common.python.PythonScript;
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.catalog.CatalogQuery;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.aviation.cachedata.CacheGuidanceRequest;
@ -65,6 +68,8 @@ import com.raytheon.viz.aviation.xml.WxPlotCfg;
* only retrieves selected data.
* 28 FEB 2011 8188 rferrel Fixed getNam
* Apr 28, 2011 8065 rferrel Use cache data
* Nov 26, 2012 1298 rferrel Non-blocking dialog cleanup now use
* IUFStatusHandler for error messages.
*
* </pre>
*
@ -73,16 +78,18 @@ import com.raytheon.viz.aviation.xml.WxPlotCfg;
*/
public class WeatherPlotDataManager {
private final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(WeatherPlotDataManager.class);
/**
* The types used for each model.
*/
private final static Map<String, String> modelTypes = new HashMap<String, String>();
static {
modelTypes.put("etamos", "ETA");//
modelTypes.put("etamos", "ETA");
modelTypes.put("etabuf", "ETA");
modelTypes.put("gfsmos", "GFS");//
modelTypes.put("gfslamp", "LAMP");//
modelTypes.put("gfsmos", "GFS");
modelTypes.put("gfslamp", "LAMP");
}
private static WeatherPlotDataManager instance;
@ -158,7 +165,8 @@ public class WeatherPlotDataManager {
wxPlotCfg = JAXB.unmarshal(path, WxPlotCfg.class);
} catch (Exception e) {
e.printStackTrace();
statusHandler.handle(Priority.PROBLEM,
"Unable to read WxPlotCfg.xml", e);
}
}
@ -380,10 +388,10 @@ public class WeatherPlotDataManager {
TafRecord[] tafs = TafUtil.getLatestTafs(siteId, 99);
long keyTime = 0;
List<TafRecord> tlist = Arrays.asList(tafs);
Collections.reverse(tlist);
tlist.toArray(tafs);
if (tafs != null) {
List<TafRecord> tlist = Arrays.asList(tafs);
Collections.reverse(tlist);
tlist.toArray(tafs);
for (TafRecord taf : tafs) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("taf", TafUtil.safeFormatTaf(taf, false));
@ -455,8 +463,7 @@ public class WeatherPlotDataManager {
}
}
} catch (JepException e) {
// TODO Auto-generated catch block
e.printStackTrace();
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
} finally {
if (python != null) {
python.dispose();
@ -543,8 +550,7 @@ public class WeatherPlotDataManager {
}
}
} catch (JepException e) {
// TODO Auto-generated catch block
e.printStackTrace();
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
} finally {
if (python != null) {
python.dispose();
@ -703,7 +709,7 @@ public class WeatherPlotDataManager {
}
}
} catch (JepException e) {
e.printStackTrace();
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
} finally {
if (python != null) {
python.dispose();
@ -805,7 +811,7 @@ public class WeatherPlotDataManager {
}
}
} catch (JepException e) {
e.printStackTrace();
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
} finally {
if (python != null) {
python.dispose();
@ -1009,10 +1015,7 @@ public class WeatherPlotDataManager {
result = CatalogQuery.performQuery(fieldName, queryTerms);
Arrays.sort(result, Collections.reverseOrder());
} catch (VizException e) {
// TODO Auto-generated catch block. Please revise as appropriate.
// statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
// e);
e.printStackTrace();
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
}
return result;

View file

@ -88,6 +88,8 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
* 10/02/2012 1229 rferrel Made dialog non-blocking.
* 10/10/2012 1229 rferrel Changes for non-blocking TimeSelectorDlg.
* 10/15/2012 1229 rferrel Changes for non-blocking HelpUsageDlg.
* 11/26/2012 1298 rferrel Non-blocking dialog code cleanup.
*
*
* </pre>
*
@ -221,6 +223,8 @@ public class WeatherPlotDialog extends CaveSWTDialog {
private HelpUsageDlg usageDlg;
private WeatherPlotDataManager dataMgr;
/**
* Constructor.
*
@ -238,6 +242,7 @@ public class WeatherPlotDialog extends CaveSWTDialog {
this.msgType = msgType;
this.icaos = stationList;
this.dataMgr = WeatherPlotDataManager.getInstance();
}
@Override
@ -287,9 +292,8 @@ public class WeatherPlotDialog extends CaveSWTDialog {
}
private void initData() {
WeatherPlotDataManager mgr = WeatherPlotDataManager.getInstance();
mgr.getNewConfig();
wxPlotCfg = mgr.getWxPlotCfg();
dataMgr.getNewConfig();
wxPlotCfg = dataMgr.getWxPlotCfg();
}
/**
@ -418,8 +422,7 @@ public class WeatherPlotDialog extends CaveSWTDialog {
timesBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (timeDlg == null || timeDlg.getShell() == null
|| timeDlg.isDisposed()) {
if (timeDlg == null) {
timeDlg = new TimeSelectorDialog(shell, wxPlotCfg);
timeDlg.setCloseCallback(new ICloseCallback() {
@ -431,13 +434,11 @@ public class WeatherPlotDialog extends CaveSWTDialog {
displayData();
}
}
timeDlg = null;
}
});
timeDlg.open();
} else {
timeDlg.bringToTop();
}
timeDlg.open();
}
});
@ -470,14 +471,12 @@ public class WeatherPlotDialog extends CaveSWTDialog {
helpBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (mustCreate(usageDlg)) {
if (usageDlg == null) {
String description = "Help";
String helpText = "This dialog is used to display TAFs, METARs and guidance forecasts.\n\nMenus:\n Site ID - pulldown menu displaying list of all TAF sites.\n Selection of a site from the list redraws the window.\n zoom - zoom factor (time scale). \n\nButtons:\n Display - Redraws the window.\n Times - Displays forecast time selection window\n Print - Dumps an image of the window to a command specified in\n the configration file etc/wxplot.cfg.\n Close - Closes this dialog.\n Help - Displays this help.\n\nData Sources - selection of available data sources. ";
usageDlg = new HelpUsageDlg(shell, description, helpText);
usageDlg.open();
} else {
usageDlg.bringToTop();
}
usageDlg.open();
}
});
}
@ -727,15 +726,11 @@ public class WeatherPlotDialog extends CaveSWTDialog {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
WeatherPlotDataManager dataMgr = WeatherPlotDataManager
.getInstance();
dataMgr.loadCacheData(siteId);
if (isDisposed() == false) {
VizApp.runAsync(new Runnable() {
@Override
public void run() {
WeatherPlotDataManager dataMgr = WeatherPlotDataManager
.getInstance();
if (dataMgr.loadData(siteId, currentTime)) {
updateSiteTimeLabel();
displayData();
@ -753,13 +748,12 @@ public class WeatherPlotDialog extends CaveSWTDialog {
}
private void displayData() {
WeatherPlotDataManager dataMgr = WeatherPlotDataManager.getInstance();
if (dataMgr.havePendingCache()) {
setCursorBusy(true);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
WeatherPlotDataManager.getInstance().waitForCacheRequests();
dataMgr.waitForCacheRequests();
if (isDisposed() == false) {
VizApp.runAsync(new Runnable() {
@Override