From ff31c11e02ca160933c32d834370330c413d950c Mon Sep 17 00:00:00 2001 From: Ron Anderson Date: Thu, 21 Aug 2014 09:25:14 -0500 Subject: [PATCH] Omaha #1664 Fixed invalid thread access in several GFE dialogs Change-Id: Ib40e6928c61a0f9e4f9fad9d8e7a06a66af292e3 Former-commit-id: 4178dac74145e3e25a0c972c73c31a1be1ad25bb [formerly 93aa457f4918cd16edd21422819cda12af26250f] Former-commit-id: bb124e7fa2e122b1c17770b141aca7c668b213d2 --- .../raytheon/viz/gfe/core/parm/ParmOp.java | 16 +++- .../viz/gfe/dialogs/DiscreteSetValue.java | 14 ++- .../viz/gfe/dialogs/FuzzValueDialog.java | 51 ++++++---- .../viz/gfe/dialogs/SetDeltaDialog.java | 58 +++++++++--- .../viz/gfe/dialogs/SetValueDialog.java | 94 ++++++++++--------- .../edex/plugin/gfe/server/GridParm.java | 4 +- 6 files changed, 150 insertions(+), 87 deletions(-) diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/parm/ParmOp.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/parm/ParmOp.java index 7d3c48f7cb..be29b4044c 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/parm/ParmOp.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/parm/ParmOp.java @@ -55,6 +55,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.SimulatedTime; import com.raytheon.uf.common.time.TimeRange; import com.raytheon.uf.common.time.util.TimeUtil; +import com.raytheon.uf.viz.core.VizApp; import com.raytheon.viz.core.mode.CAVEMode; import com.raytheon.viz.gfe.Activator; import com.raytheon.viz.gfe.GFEException; @@ -87,6 +88,7 @@ import com.raytheon.viz.gfe.core.wxvalue.WxValue; * 10/15/2013 #2445 randerso Removed expansion of publish time to span of * overlapping grids since this is now done on * the server side + * 08/20/2014 #1664 randerso Fixed invalid thread access * * * @@ -602,12 +604,16 @@ public class ParmOp { parm.getParmState().setCombineMode(editMode); } - // WeatherCombineModeChangedMsg::send(_msgHand, editMode); - ICommandService service = (ICommandService) PlatformUI.getWorkbench() - .getService(ICommandService.class); + VizApp.runAsync(new Runnable() { + @Override + public void run() { + ICommandService service = (ICommandService) PlatformUI + .getWorkbench().getService(ICommandService.class); - service.refreshElements("com.raytheon.viz.gfe.actions.setCombineMode", - null); + service.refreshElements( + "com.raytheon.viz.gfe.actions.setCombineMode", null); + } + }); return; } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/DiscreteSetValue.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/DiscreteSetValue.java index d3fe3c8193..efb253e7d1 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/DiscreteSetValue.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/DiscreteSetValue.java @@ -38,6 +38,7 @@ import com.raytheon.uf.common.dataplugin.gfe.DiscreteTerm; import com.raytheon.uf.common.dataplugin.gfe.discrete.DiscreteDefinition; import com.raytheon.uf.common.dataplugin.gfe.discrete.DiscreteKey; import com.raytheon.uf.common.dataplugin.gfe.discrete.DiscreteKeyDef; +import com.raytheon.uf.viz.core.VizApp; import com.raytheon.viz.gfe.core.msgs.ICombineModeChangedListener; import com.raytheon.viz.gfe.core.parm.Parm; import com.raytheon.viz.gfe.core.parm.ParmState.CombineMode; @@ -51,7 +52,8 @@ import com.raytheon.viz.gfe.core.wxvalue.DiscreteWxValue; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Jun 22, 2009 #1318 randerso Initial creation + * Jun 22, 2009 #1318 randerso Initial creation + * Aug 20, 2014 #1664 randerso Fixed invalid thread access * * * @@ -224,9 +226,15 @@ public class DiscreteSetValue extends AbstractSetValue implements * com.raytheon.viz.gfe.core.parm.ParmState.CombineMode) */ @Override - public void combineModeChanged(Parm parm, CombineMode mode) { + public void combineModeChanged(Parm parm, final CombineMode mode) { // Parm Client notification - combineButton.setSelection(mode.equals(CombineMode.COMBINE)); + VizApp.runAsync(new Runnable() { + + @Override + public void run() { + combineButton.setSelection(mode.equals(CombineMode.COMBINE)); + } + }); } protected void addToSession() { diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/FuzzValueDialog.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/FuzzValueDialog.java index ab03b0c361..522694e5bd 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/FuzzValueDialog.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/FuzzValueDialog.java @@ -34,6 +34,7 @@ import org.eclipse.swt.widgets.Scale; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; +import com.raytheon.uf.viz.core.VizApp; import com.raytheon.viz.gfe.core.DataManager; import com.raytheon.viz.gfe.core.msgs.IActivatedParmChangedListener; import com.raytheon.viz.gfe.core.msgs.IDisplayedParmListChangedListener; @@ -60,8 +61,9 @@ import com.raytheon.viz.ui.dialogs.CaveJFACEDialog; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Mar 10, 2008 Eric Babin Initial Creation + * Mar 10, 2008 Eric Babin Initial Creation * Nov 10, 2012 1298 rferrel Changes for non-blocking dialog. + * Aug 20, 2014 #1664 randerso Fixed invalid thread access * * * @@ -95,7 +97,8 @@ public class FuzzValueDialog extends CaveJFACEDialog implements private static FuzzValueDialog dialog; public static void openDialog(DataManager dataManager) { - if (dialog == null || dialog.getShell() == null || dialog.isDisposed()) { + if ((dialog == null) || (dialog.getShell() == null) + || dialog.isDisposed()) { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getShell(); @@ -113,8 +116,6 @@ public class FuzzValueDialog extends CaveJFACEDialog implements this.setShellStyle(SWT.DIALOG_TRIM | SWT.MODELESS); this.dataManager = dataManager; this.parm = dataManager.getSpatialDisplayManager().getActivatedParm(); - this.minimum = parm.getGridInfo().getMinValue(); - this.maximum = parm.getGridInfo().getMaxValue(); } @Override @@ -134,40 +135,34 @@ public class FuzzValueDialog extends CaveJFACEDialog implements } private void initializeComponents() { - GridData data = new GridData(GridData.FILL_HORIZONTAL); + GridData data = new GridData(SWT.FILL, SWT.DEFAULT, true, false); data.horizontalSpan = 2; - data.horizontalAlignment = SWT.CENTER; - lab = new Label(top, SWT.BORDER); - lab.setText(this.parm.getParmID().getParmName() + " Fuzz"); + lab = new Label(top, SWT.CENTER); lab.setLayoutData(data); data = new GridData(200, SWT.DEFAULT); data.horizontalAlignment = SWT.CENTER; fuzzSlider = new Scale(top, SWT.HORIZONTAL); fuzzSlider.setLayoutData(data); - - int precision = parm.getGridInfo().getPrecision(); - resolution = Math.pow(10, precision); + fuzzSlider.setMinimum(0); scaleSlider = new Label(top, SWT.NONE); data = new GridData(40, SWT.DEFAULT); data.horizontalAlignment = SWT.CENTER; scaleSlider.setLayoutData(data); - fuzzSlider.setMinimum(0); - fuzzSlider.setMaximum((int) (maximum - minimum) / 5 * (int) resolution); - fuzzSlider.setSelection((int) (resolution * this.parm.getParmState() - .getFuzzValue())); + updateDialog(); fuzzSlider.addSelectionListener(new SelectionListener() { + @Override public void widgetDefaultSelected(SelectionEvent arg0) { } + @Override public void widgetSelected(SelectionEvent arg0) { setValues(); } }); - setValues(); } private void setValues() { @@ -225,19 +220,33 @@ public class FuzzValueDialog extends CaveJFACEDialog implements @Override public void activatedParmChanged(Parm newParm) { parm = newParm; + VizApp.runAsync(new Runnable() { + @Override + public void run() { + updateDialog(); + } + }); + } + + /** + * + */ + private void updateDialog() { if (parm != null) { - lab.setText(parm.getParmID().getParmName() + " Delta"); + lab.setText(parm.getParmID().getParmName() + " Fuzz"); minimum = parm.getGridInfo().getMinValue(); maximum = parm.getGridInfo().getMaxValue(); int precision = parm.getGridInfo().getPrecision(); resolution = Math.pow(10, precision); - fuzzSlider.setMaximum((int) (maximum - minimum) / 5 + fuzzSlider.setMaximum(((int) (maximum - minimum) / 5) * (int) resolution); fuzzSlider.setSelection((int) (resolution * this.parm .getParmState().getDeltaValue())); + fuzzSlider.setEnabled(true); setValues(); } else { lab.setText("No active weather element"); + fuzzSlider.setEnabled(false); } } @@ -255,6 +264,12 @@ public class FuzzValueDialog extends CaveJFACEDialog implements if (parm != null) { if (Arrays.asList(deletions).contains(parm)) { parm = null; + VizApp.runAsync(new Runnable() { + @Override + public void run() { + updateDialog(); + } + }); } } } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/SetDeltaDialog.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/SetDeltaDialog.java index a6c272af19..411f7d0028 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/SetDeltaDialog.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/SetDeltaDialog.java @@ -19,6 +19,8 @@ **/ package com.raytheon.viz.gfe.dialogs; +import java.util.Arrays; + import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -33,6 +35,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; +import com.raytheon.uf.viz.core.VizApp; import com.raytheon.viz.gfe.Activator; import com.raytheon.viz.gfe.core.DataManager; import com.raytheon.viz.gfe.core.DataManagerUIFactory; @@ -52,9 +55,10 @@ import com.raytheon.viz.ui.dialogs.CaveJFACEDialog; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Sep 16, 2011 dgilling Initial creation + * Sep 16, 2011 dgilling Initial creation * Nov 13, 2012 1298 rferrel Code clean up for non-blocking dialog. * Mar 29, 2013 1790 rferrel Bug fix for non-blocking dialogs. + * Aug 20, 2014 #1664 randerso Fixed invalid thread access * * * @@ -194,6 +198,20 @@ public class SetDeltaDialog extends CaveJFACEDialog implements newShell.setText("Delta Value"); } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.ui.dialogs.CaveJFACEDialog#createContents(org.eclipse + * .swt.widgets.Composite) + */ + @Override + protected Control createContents(Composite parent) { + Control contents = super.createContents(parent); + setUpDialog(); + return contents; + } + @Override protected Control createDialogArea(Composite parent) { dialogFrame = (Composite) super.createDialogArea(parent); @@ -201,11 +219,10 @@ public class SetDeltaDialog extends CaveJFACEDialog implements GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); dialogFrame.setLayout(layout); dialogFrame.setLayoutData(data); - setUpDialog(dialogFrame); return dialogFrame; } - private void setUpDialog(Composite master) { + private void setUpDialog() { // remove any existing ones first if (label != null) { label.dispose(); @@ -229,7 +246,7 @@ public class SetDeltaDialog extends CaveJFACEDialog implements // Set up the display for setting delta value GridData data = new GridData(SWT.FILL, SWT.DEFAULT, true, false); data.horizontalSpan = 2; - label = new Label(master, SWT.CENTER); + label = new Label(dialogFrame, SWT.CENTER); label.setText("No active weather element"); label.setLayoutData(data); @@ -251,7 +268,7 @@ public class SetDeltaDialog extends CaveJFACEDialog implements .getGridInfo().getMinValue()) / 5; } - scale = new Scale(master, SWT.HORIZONTAL); + scale = new Scale(dialogFrame, SWT.HORIZONTAL); scale.setMinimum(0); scale.setMaximum((int) (maxLimit / res)); scale.setIncrement((int) (1 / res)); @@ -262,20 +279,23 @@ public class SetDeltaDialog extends CaveJFACEDialog implements scale.setLayoutData(data); scale.addSelectionListener(scaleListener); - entryLabel = new Label(master, SWT.NONE); + entryLabel = new Label(dialogFrame, SWT.NONE); data = new GridData(SWT.RIGHT, SWT.CENTER, false, false); entryLabel.setText("Enter Value:"); entryLabel.setLayoutData(data); data = new GridData(80, SWT.DEFAULT); - entryField = new Text(master, SWT.BORDER); + entryField = new Text(dialogFrame, SWT.BORDER); entryField.setText(String.format("%-6." + (prec + 1) + "f", origValue).trim()); entryField.setLayoutData(data); entryField.addSelectionListener(entryListener); - } - master.layout(); + } + getButton(ADJUST_UP).setEnabled(parm != null); + getButton(ADJUST_DOWN).setEnabled(parm != null); + + dialogFrame.layout(); getShell().pack(true); } @@ -298,7 +318,12 @@ public class SetDeltaDialog extends CaveJFACEDialog implements @Override public void activatedParmChanged(Parm newParm) { parm = newParm; - setUpDialog(dialogFrame); + VizApp.runAsync(new Runnable() { + @Override + public void run() { + setUpDialog(); + } + }); } /* @@ -313,11 +338,14 @@ public class SetDeltaDialog extends CaveJFACEDialog implements public void displayedParmListChanged(Parm[] parms, Parm[] deletions, Parm[] additions) { if (parm != null) { - for (Parm deleted : deletions) { - if (parm.equals(deleted)) { - parm = null; - setUpDialog(dialogFrame); - } + if (Arrays.asList(deletions).contains(parm)) { + parm = null; + VizApp.runAsync(new Runnable() { + @Override + public void run() { + setUpDialog(); + } + }); } } } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/SetValueDialog.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/SetValueDialog.java index b6bd653644..5420a7f4c1 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/SetValueDialog.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/SetValueDialog.java @@ -36,6 +36,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord.GridType; +import com.raytheon.uf.viz.core.VizApp; import com.raytheon.viz.gfe.core.DataManager; import com.raytheon.viz.gfe.core.DataManagerUIFactory; import com.raytheon.viz.gfe.core.msgs.IActivatedParmChangedListener; @@ -56,6 +57,7 @@ import com.raytheon.viz.ui.dialogs.CaveJFACEDialog; * Jun 18, 2009 #1318 randerso Ported AWIPS I pickup value dialogs * Nov 13, 2012 #1298 rferrel Changes for non-blocking dialog. * Mar 29, 2013 #1790 rferrel Bug fix for non-blocking dialogs. + * Aug 20, 2014 #1664 randerso Fixed invalid thread access * * * @@ -167,7 +169,6 @@ public class SetValueDialog extends CaveJFACEDialog implements valueFrame.setLayoutData(layoutData); setValue = null; - setSetValueOrder(); dataManager.getParmManager().addDisplayedParmListChangedListener(this); dataManager.getSpatialDisplayManager().addActivatedParmChangedListener( @@ -187,9 +188,7 @@ public class SetValueDialog extends CaveJFACEDialog implements protected Control createContents(Composite parent) { Control contents = super.createContents(parent); - Point size = getInitialSize(); - getShell().setSize(size); - getShell().setLocation(getInitialLocation(size)); + setSetValueOrder(); return contents; } @@ -240,9 +239,8 @@ public class SetValueDialog extends CaveJFACEDialog implements origin = Geometry.getLocation(monitorBounds); } - return new Point(origin.x + 50, Math.max( - monitorBounds.y, - Math.min(origin.y + 550, monitorBounds.y + monitorBounds.height + return new Point(origin.x + 50, Math.max(monitorBounds.y, Math.min( + origin.y + 550, (monitorBounds.y + monitorBounds.height) - initialSize.y))); } @@ -260,7 +258,12 @@ public class SetValueDialog extends CaveJFACEDialog implements if (activeParm != null) { if (Arrays.asList(deletions).contains(activeParm)) { activeParm = null; - setSetValueOrder(); + VizApp.runAsync(new Runnable() { + @Override + public void run() { + setSetValueOrder(); + } + }); } } } @@ -274,11 +277,17 @@ public class SetValueDialog extends CaveJFACEDialog implements @Override public void activatedParmChanged(Parm newParm) { activeParm = newParm; - setSetValueOrder(); + VizApp.runAsync(new Runnable() { + @Override + public void run() { + setSetValueOrder(); + } + }); } private void setSetValueOrder() { // no active parm case + getButton(ASSIGN_ID).setEnabled(activeParm != null); if (activeParm == null) { pnLabel.setText("No active weather element"); if (setValue != null) { @@ -286,42 +295,39 @@ public class SetValueDialog extends CaveJFACEDialog implements setValue.dispose(); setValue = null; } - return; + } else { + + // no change in parm + if ((setValue != null) && (setValue.getParm() == activeParm)) { + return; + } + + // change in parm + if (setValue != null) { + setValue.dispose(); + setValue = null; + } + + pnLabel.setText(activeParm.getParmID().compositeNameUI()); + + GridType gridType = activeParm.getGridInfo().getGridType(); + if (gridType.equals(GridType.SCALAR)) { + setValue = new ScalarSetValue(valueFrame, activeParm); + + } else if (gridType.equals(GridType.VECTOR)) { + setValue = new VectorSetValue(valueFrame, activeParm); + + } else if (gridType.equals(GridType.WEATHER)) { + setValue = new WxSetValue(valueFrame, activeParm, true, true, + true); + + } else if (gridType.equals(GridType.DISCRETE)) { + setValue = new DiscreteSetValue(valueFrame, activeParm, true, + true, true); + } + + setValue.pack(true); } - - // no change in parm - if (setValue != null && setValue.getParm() == activeParm) { - return; - } - - // change in parm - if (setValue != null) { - // delete the old one - // setValue.pack_forget(); - // setValue.unregister(); - // setValue.destroy(); - setValue.dispose(); - setValue = null; - } - - pnLabel.setText(activeParm.getParmID().compositeNameUI()); - - GridType gridType = activeParm.getGridInfo().getGridType(); - if (gridType.equals(GridType.SCALAR)) { - setValue = new ScalarSetValue(valueFrame, activeParm); - - } else if (gridType.equals(GridType.VECTOR)) { - setValue = new VectorSetValue(valueFrame, activeParm); - - } else if (gridType.equals(GridType.WEATHER)) { - setValue = new WxSetValue(valueFrame, activeParm, true, true, true); - - } else if (gridType.equals(GridType.DISCRETE)) { - setValue = new DiscreteSetValue(valueFrame, activeParm, true, true, - true); - } - - setValue.pack(true); valueFrame.layout(); valueFrame.setSize(valueFrame.computeSize(SWT.DEFAULT, SWT.DEFAULT)); getShell().layout(); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParm.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParm.java index b211138f39..d8271c6cb9 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParm.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParm.java @@ -75,7 +75,7 @@ import com.raytheon.uf.edex.database.plugin.PluginFactory; * 04/23/13 #1949 rjpeter Removed excess validation on retrieval, added * inventory for a given time range. * 06/13/13 #2044 randerso Refactored to use non-singleton LockManager - * 07/01/2014 #3149 randerso Removed unit conversion (unused) + * 07/01/2014 #3149 randerso Removed unit conversion (unused) * * * @author bphillip @@ -111,7 +111,7 @@ public class GridParm { * Creates a new empty GridParm */ public GridParm() { - + this.id = new ParmID(); } /**