Issue #3041 - added dispose check to runAsync call and cleaned up code.

Change-Id: I50e6ce1a214a884221fbc256a133e57e579862da

Former-commit-id: ed2fc05f61861efe6c70b8fc73ad10d27bb73c12
This commit is contained in:
Lee Venable 2014-04-21 13:42:07 -05:00
parent 750c054ab0
commit 3c45a24efb
2 changed files with 282 additions and 232 deletions

View file

@ -38,6 +38,7 @@ import com.raytheon.viz.awipstools.ui.layer.HomeToolLayer;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------- -------- ----------- -------------------------- * ------------- -------- ----------- --------------------------
* Sep 03, 2013 2310 bsteffen Rewritten to extend HomeToolAction. * Sep 03, 2013 2310 bsteffen Rewritten to extend HomeToolAction.
* Apr 21, 2014 3041 lvenable Added dispose check.
* *
* </pre> * </pre>
* *
@ -50,12 +51,10 @@ public class PutHomeCursorAction extends HomeToolAction {
@Override @Override
public Object execute(ExecutionEvent arg0) throws ExecutionException { public Object execute(ExecutionEvent arg0) throws ExecutionException {
if (putHomeCursorDialog == null if (putHomeCursorDialog == null || putHomeCursorDialog.isDisposed()) {
|| putHomeCursorDialog.getShell() == null) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell(); .getShell();
putHomeCursorDialog = new PutHomeCursorDialog(shell); putHomeCursorDialog = new PutHomeCursorDialog(shell);
putHomeCursorDialog.setBlockOnOpen(false);
putHomeCursorDialog.open(); putHomeCursorDialog.open();
} }

View file

@ -19,6 +19,38 @@
**/ **/
package com.raytheon.viz.awipstools.ui.dialog; package com.raytheon.viz.awipstools.ui.dialog;
import java.util.List;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.pointdata.spatial.ObStation;
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.VizApp;
import com.raytheon.uf.viz.core.catalog.DirectDbQuery;
import com.raytheon.uf.viz.points.IPointChangedListener;
import com.raytheon.uf.viz.points.PointsDataManager;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKBReader;
import com.vividsolutions.jts.io.WKTWriter;
/** /**
* Creates the Put Cursor Home Dialog. * Creates the Put Cursor Home Dialog.
* *
@ -26,7 +58,7 @@ package com.raytheon.viz.awipstools.ui.dialog;
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------- -------- ----------- -------------------------- * ------------- -------- ----------- --------------------------
* Dec 05, 2007 Eric Babin Initial Creation * Dec 05, 2007 Eric Babin Initial Creation
* Dec 10, 2007 598 Eric Babin Added city, state query. * Dec 10, 2007 598 Eric Babin Added city, state query.
* Dec 20, 2007 656 Eric Babin Updated to refresh location after * Dec 20, 2007 656 Eric Babin Updated to refresh location after
* clicking GO. * clicking GO.
@ -42,315 +74,317 @@ package com.raytheon.viz.awipstools.ui.dialog;
* and the query by city, state. * and the query by city, state.
* Sep 03, 2013 2310 bsteffen Extend IPointChangedListener instead of * Sep 03, 2013 2310 bsteffen Extend IPointChangedListener instead of
* IResourceDataChanged. * IResourceDataChanged.
* * Apr 21, 2014 3041 lvenable Added dispose check to runAsync call and cleaned up
* code. Wrote ticket #3047 for common_obs_spatial
* for the city/state issues.
*
* </pre> * </pre>
* *
* @author ebabin * @author ebabin
* @version 1.0 * @version 1.0
*/ */
public class PutHomeCursorDialog extends CaveSWTDialog implements
// TODO: the code that performs the queries will need to be cleaned up once we have
// time to cleanup, complete the common_obs_spatial table
import java.util.List;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.pointdata.spatial.ObStation;
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.VizApp;
import com.raytheon.uf.viz.core.catalog.DirectDbQuery;
import com.raytheon.uf.viz.points.IPointChangedListener;
import com.raytheon.uf.viz.points.PointsDataManager;
import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKBReader;
import com.vividsolutions.jts.io.WKTWriter;
public class PutHomeCursorDialog extends CaveJFACEDialog implements
IPointChangedListener { IPointChangedListener {
private static final transient IUFStatusHandler statusHandler = UFStatus private final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(PutHomeCursorDialog.class); .getHandler(PutHomeCursorDialog.class);
private static final String DIST_QRY_FMT = "SELECT icao, name, state FROM common_obs_spatial " private final String DIST_QRY_FMT = "SELECT icao, name, state FROM common_obs_spatial "
+ "WHERE ST_DWithin(the_geom, ST_GeomFromText('%s'), %4.1f) AND" + "WHERE ST_DWithin(the_geom, ST_GeomFromText('%s'), %4.1f) AND"
+ " catalogtype = %d ORDER BY ST_Distance(the_geom, ST_GeomFromText('%1$s'))"; + " catalogtype = %d ORDER BY ST_Distance(the_geom, ST_GeomFromText('%1$s'))";
private static final String ICAO_QRY_FMT = "SELECT AsBinary(the_geom) FROM common_obs_spatial " private final String ICAO_QRY_FMT = "SELECT AsBinary(the_geom) FROM common_obs_spatial "
+ "WHERE catalogtype = %d and icao = '%s'"; + "WHERE catalogtype = %d and icao = '%s'";
private static final String CITY_QRY_FMT = "SELECT AsBinary(the_geom) FROM common_obs_spatial " private final String CITY_QRY_FMT = "SELECT AsBinary(the_geom) FROM common_obs_spatial "
+ "WHERE catalogtype = %d AND name = '%s' AND state = '%s'"; + "WHERE catalogtype = %d AND name = '%s' AND state = '%s'";
private static final String CITY_DB_QRY_FMT = "SELECT AsBinary(the_geom) FROM mapdata.city " private final String CITY_DB_QRY_FMT = "SELECT AsBinary(the_geom) FROM mapdata.city "
+ "WHERE name = '%s' AND st = '%s'"; + "WHERE name = '%s' AND st = '%s'";
private static final String AIRPORT_DB_QRY_FMT = "SELECT AsBinary(the_geom) FROM mapdata.airport " private final String AIRPORT_DB_QRY_FMT = "SELECT AsBinary(the_geom) FROM mapdata.airport "
+ "WHERE city = '%s' AND state = '%s'"; + "WHERE city = '%s' AND state = '%s'";
private Composite top = null; /** Station radio button. */
private Button stationRadio; private Button stationRadio;
/** City radio button. */
private Button cityRadio; private Button cityRadio;
/** Lat/Lon radio button. */
private Button latLonRadio; private Button latLonRadio;
/** Station label. */
private Label stationLabel;
/** Station text field. */
private Text stationTextField; private Text stationTextField;
/** City label. */
private Label citylabel;
/** City text field. */
private Text cityTextField; private Text cityTextField;
/** State label. */
private Label stateLabel;
/** State text field. */
private Text stateTextField; private Text stateTextField;
/** Latitude label. */
private Label latLabel;
/** Latitude text field */
private Text latTextField; private Text latTextField;
/** Longitude label. */
private Label lonLabel;
/** Longitude text field. */
private Text lonTextField; private Text lonTextField;
private Button goButton, closeButton; /** Go button. */
private Button goBtn;
public PutHomeCursorDialog(Shell shell) { /** Close button. */
super(shell); private Button closeBtn;
this.setBlockOnOpen(false);
this.setShellStyle(SWT.TITLE | SWT.MODELESS | SWT.CLOSE);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
* .Composite)
*/
@Override
public Control createDialogArea(Composite parent) {
top = (Composite) super.createDialogArea(parent);
// Create the main layout for the shell.
GridLayout gridLayout = new GridLayout(1, true);
top.setLayout(gridLayout);
// Initialize all of the menus, controls, and layouts
initializeComponents();
return top;
}
/** /**
* Initializes the components. * Constructor.
*
* @param shell
* Parent shell.
*/ */
private void initializeComponents() { public PutHomeCursorDialog(Shell shell) {
createSelectionChoices(); super(shell, SWT.DIALOG_TRIM, CAVE.DO_NOT_BLOCK);
createStationChoice();
createCityChoice(); setText("Put Home Cursor");
createLatLonChoice(); PointsDataManager.getInstance().addHomeChangedListener(this);
}
@Override
protected Layout constructShellLayout() {
GridLayout gridLayout = new GridLayout(1, false);
return gridLayout;
}
@Override
protected Object constructShellLayoutData() {
// TODO Auto-generated method stub
return super.constructShellLayoutData();
}
@Override
protected void initializeComponents(Shell shell) {
Group locSelectionGroup = new Group(shell, SWT.NONE);
GridData gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
locSelectionGroup.setLayoutData(gridData);
locSelectionGroup.setText("Location selection via:");
GridLayout rowLayout = new GridLayout(1, false);
locSelectionGroup.setLayout(rowLayout);
createSelectionChoices(locSelectionGroup);
Composite controlsComp = new Composite(locSelectionGroup, SWT.NONE);
controlsComp.setLayout(new GridLayout(2, false));
controlsComp.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true,
false));
createStationChoice(controlsComp);
createCityChoice(controlsComp);
createLatLonChoice(controlsComp);
createActionButtons();
try { try {
updateStationInfo(PointsDataManager.getInstance().getHome()); updateStationInfo(PointsDataManager.getInstance().getHome());
} catch (Exception e) { } catch (Exception e) {
} }
// @TODO Not currently no data for city, state. So disabled for now.
stationRadio.setSelection(true); enableDisableControls();
cityTextField.setEnabled(false); }
stateTextField.setEnabled(false);
latTextField.setEnabled(false); @Override
lonTextField.setEnabled(false); protected void disposed() {
stationTextField.setEnabled(true); PointsDataManager.getInstance().removeHomeChangedListener(
PutHomeCursorDialog.this);
} }
/** /**
* Creates the selection composite. * Creates the selection composite.
*
* @param selectionGroup
* Group container.
*/ */
private void createSelectionChoices() { private void createSelectionChoices(Group selectionGroup) {
Group selectionGroup = new Group(top, SWT.NONE | SWT.FILL);
GridData gridData = new GridData(); /*
gridData.horizontalAlignment = GridData.FILL; * Composite for the location radio buttons.
gridData.grabExcessHorizontalSpace = true; */
selectionGroup.setLayoutData(gridData); Composite locationComp = new Composite(selectionGroup, SWT.BORDER);
locationComp.setLayout(new GridLayout(3, true));
RowLayout rowLayout = new RowLayout(); /*
rowLayout.type = SWT.VERTICAL; * Station radio button selection
selectionGroup.setLayout(rowLayout); */
Label label = new Label(selectionGroup, SWT.NONE | SWT.CENTER);
label.setText("Location selection via:");
Composite locationComp = new Composite(selectionGroup, SWT.None);
locationComp.setLayout(new RowLayout());
stationRadio = new Button(locationComp, SWT.RADIO); stationRadio = new Button(locationComp, SWT.RADIO);
stationRadio.setText("Station");
stationRadio.setSelection(true);
stationRadio.addSelectionListener(new SelectionAdapter() { stationRadio.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
cityTextField.setEnabled(false); if (stationRadio.getSelection() == false) {
stateTextField.setEnabled(false); return;
latTextField.setEnabled(false); }
lonTextField.setEnabled(false); enableDisableControls();
stationTextField.setEnabled(true);
} }
}); });
stationRadio.setText("Station"); /*
* City radio button selection
*/
cityRadio = new Button(locationComp, SWT.RADIO); cityRadio = new Button(locationComp, SWT.RADIO);
cityRadio.setText("City/State"); cityRadio.setText("City/State");
cityRadio.addSelectionListener(new SelectionAdapter() { cityRadio.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
cityTextField.setEnabled(true); if (cityRadio.getSelection() == false) {
stateTextField.setEnabled(true); return;
latTextField.setEnabled(false); }
lonTextField.setEnabled(false); enableDisableControls();
stationTextField.setEnabled(false);
} }
}); });
/*
* Lat/Lon radio button selection
*/
latLonRadio = new Button(locationComp, SWT.RADIO); latLonRadio = new Button(locationComp, SWT.RADIO);
latLonRadio.setText("Lat/Lon");
latLonRadio.addSelectionListener(new SelectionAdapter() { latLonRadio.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
cityTextField.setEnabled(false); if (latLonRadio.getSelection() == false) {
stateTextField.setEnabled(false); return;
latTextField.setEnabled(true); }
lonTextField.setEnabled(true); enableDisableControls();
stationTextField.setEnabled(false);
} }
}); });
latLonRadio.setText("Lat/Lon");
} }
/** /**
* Creates station choice composite. * Creates station choice controls.
*
* @param controlsComp
* Composite containing the controls.
*/ */
private void createStationChoice() { private void createStationChoice(Composite controlsComp) {
Group comp = new Group(top, SWT.None);
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
comp.setLayoutData(gridData); stationLabel = new Label(controlsComp, SWT.NONE);
comp.setLayout(new GridLayout(3, true)); stationLabel.setText("Station:");
Label label = new Label(comp, SWT.NONE);
label.setText("Station:"); stationTextField = new Text(controlsComp, SWT.BORDER);
stationTextField = new Text(comp, SWT.BORDER); GridData data = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
| GridData.GRAB_HORIZONTAL);
data.horizontalSpan = 2;
stationTextField.setLayoutData(data); stationTextField.setLayoutData(data);
// Add a separator line.
addSeparator(controlsComp);
} }
/** /**
* Creates city choice composite. * Creates city choice controls.
*
* @param controlsComp
* Composite containing the controls.
*/ */
private void createCityChoice() { private void createCityChoice(Composite controlsComp) {
Group comp = new Group(top, SWT.None);
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
comp.setLayoutData(gridData);
comp.setLayout(new GridLayout(3, true));
Label citylabel = new Label(comp, SWT.NONE); citylabel = new Label(controlsComp, SWT.NONE);
citylabel.setText("City:"); citylabel.setText("City:");
cityTextField = new Text(comp, SWT.BORDER);
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
| GridData.GRAB_HORIZONTAL);
data.horizontalSpan = 2;
cityTextField.setLayoutData(data);
Label stateLabel = new Label(comp, SWT.NONE); cityTextField = new Text(controlsComp, SWT.BORDER);
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
cityTextField.setLayoutData(gd);
stateLabel = new Label(controlsComp, SWT.NONE);
stateLabel.setText("State:"); stateLabel.setText("State:");
stateLabel.setToolTipText("Two Letter Abbreviation"); stateLabel.setToolTipText("Two Letter Abbreviation");
stateTextField = new Text(comp, SWT.BORDER); gd = new GridData(50, SWT.DEFAULT);
stateTextField = new Text(controlsComp, SWT.BORDER);
stateTextField.setTextLimit(2); stateTextField.setTextLimit(2);
stateTextField.setLayoutData(gd);
stateTextField.setEnabled(false); // Add a separator line.
cityTextField.setEnabled(false); addSeparator(controlsComp);
} }
/** /**
* Creates lat/lon choice composite. * Creates lat/lon choice controls.
*
* @param controlsComp
* Composite containing the controls.
*/ */
private void createLatLonChoice() { private void createLatLonChoice(Composite controlsComp) {
Group comp = new Group(top, SWT.None);
GridData gridData = new GridData(); latLabel = new Label(controlsComp, SWT.NONE);
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
comp.setLayoutData(gridData);
comp.setLayout(new GridLayout(2, true));
Label latLabel = new Label(comp, SWT.NONE);
latLabel.setText("Latitude:"); latLabel.setText("Latitude:");
latTextField = new Text(comp, SWT.BORDER);
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
latTextField = new Text(controlsComp, SWT.BORDER);
latTextField.setLayoutData(new GridData(80, SWT.DEFAULT)); latTextField.setLayoutData(new GridData(80, SWT.DEFAULT));
Label longLabel = new Label(comp, SWT.NONE); latTextField.setLayoutData(gd);
longLabel.setText("Longitude:");
lonTextField = new Text(comp, SWT.BORDER); lonLabel = new Label(controlsComp, SWT.NONE);
lonLabel.setText("Longitude:");
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
lonTextField = new Text(controlsComp, SWT.BORDER);
lonTextField.setLayoutData(new GridData(80, SWT.DEFAULT)); lonTextField.setLayoutData(new GridData(80, SWT.DEFAULT));
lonTextField.setLayoutData(gd);
Coordinate point = PointsDataManager.getInstance().getHome(); Coordinate point = PointsDataManager.getInstance().getHome();
lonTextField.setText(String.valueOf(point.x)); lonTextField.setText(String.valueOf(point.x));
latTextField.setText(String.valueOf(point.y)); latTextField.setText(String.valueOf(point.y));
}
/* // Add a separator line.
* (non-Javadoc) addSeparator(controlsComp);
*
* @see
* org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets
* .Shell)
*/
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
PointsDataManager.getInstance().addHomeChangedListener(this);
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
PointsDataManager.getInstance().removeHomeChangedListener(
PutHomeCursorDialog.this);
}
});
shell.setText("Put Home Cursor");
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
*/
@Override
protected Point getInitialSize() {
return new Point(300, 360);
} }
/** /**
* Exits the dialog. * Add a line separator to the given composite.
*
* @param parentComp
* Parent composite.
*/ */
private void exitDialog() { private void addSeparator(Composite parentComp) {
PointsDataManager.getInstance().removeHomeChangedListener(this); GridLayout gl = (GridLayout) parentComp.getLayout();
this.close();
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gd.horizontalSpan = gl.numColumns;
Label sepLbl = new Label(parentComp, SWT.SEPARATOR | SWT.HORIZONTAL);
sepLbl.setLayoutData(gd);
}
/**
* Enable or disable controls based on the radio button states.
*/
private void enableDisableControls() {
stationLabel.setEnabled(stationRadio.getSelection());
stationTextField.setEnabled(stationRadio.getSelection());
citylabel.setEnabled(cityRadio.getSelection());
cityTextField.setEnabled(cityRadio.getSelection());
stateLabel.setEnabled(cityRadio.getSelection());
stateTextField.setEnabled(cityRadio.getSelection());
latLabel.setEnabled(latLonRadio.getSelection());
latTextField.setEnabled(latLonRadio.getSelection());
lonLabel.setEnabled(latLonRadio.getSelection());
lonTextField.setEnabled(latLonRadio.getSelection());
} }
/** /**
@ -364,8 +398,7 @@ public class PutHomeCursorDialog extends CaveJFACEDialog implements
.trim(); .trim();
Coordinate c = runStationQuery(station); Coordinate c = runStationQuery(station);
if (c == null) { if (c == null) {
MessageDialog.openError(getParentShell(), MessageDialog.openError(shell, "Put Home Cursor Error",
"Put Home Cursor Error",
"Could not find that Metar station"); "Could not find that Metar station");
stationTextField.setFocus(); stationTextField.setFocus();
} else { } else {
@ -373,22 +406,19 @@ public class PutHomeCursorDialog extends CaveJFACEDialog implements
stationTextField.setText(station); stationTextField.setText(station);
} }
} else { } else {
MessageDialog.openError(getParentShell(), MessageDialog.openError(shell, "Put Home Cursor Error",
"Put Home Cursor Error",
"The input for the Station is empty. Please correct."); "The input for the Station is empty. Please correct.");
stationTextField.setFocus(); stationTextField.setFocus();
} }
} else if (cityRadio.getSelection()) { } else if (cityRadio.getSelection()) {
if (cityTextField.getText().isEmpty()) { if (cityTextField.getText().isEmpty()) {
MessageDialog.openError(getParentShell(), MessageDialog.openError(shell, "Put Home Cursor Error",
"Put Home Cursor Error",
"The input for the City is empty. Please correct."); "The input for the City is empty. Please correct.");
cityTextField.setFocus(); cityTextField.setFocus();
return; return;
} }
if (stateTextField.getText().length() != 2) { if (stateTextField.getText().length() != 2) {
MessageDialog.openError(getParentShell(), MessageDialog.openError(shell, "Put Home Cursor Error",
"Put Home Cursor Error",
"The input for the State is invalid. Please correct."); "The input for the State is invalid. Please correct.");
stateTextField.setFocus(); stateTextField.setFocus();
return; return;
@ -397,8 +427,8 @@ public class PutHomeCursorDialog extends CaveJFACEDialog implements
String state = stateTextField.getText().toUpperCase().trim(); String state = stateTextField.getText().toUpperCase().trim();
Coordinate c = runCityQuery(city, state); Coordinate c = runCityQuery(city, state);
if (c == null) { if (c == null) {
MessageDialog.openError(getParentShell(), MessageDialog.openError(shell, "Put Home Cursor Error",
"Put Home Cursor Error", "Could not find that city"); "Could not find that city");
cityTextField.setFocus(); cityTextField.setFocus();
} else { } else {
PointsDataManager.getInstance().setHome(c); PointsDataManager.getInstance().setHome(c);
@ -411,7 +441,7 @@ public class PutHomeCursorDialog extends CaveJFACEDialog implements
c.x = Float.parseFloat(lonTextField.getText()); c.x = Float.parseFloat(lonTextField.getText());
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
MessageDialog MessageDialog
.openError(getParentShell(), "Put Home Cursor Error", .openError(shell, "Put Home Cursor Error",
"The input for the Longitude not a number. Please correct."); "The input for the Longitude not a number. Please correct.");
lonTextField.setFocus(); lonTextField.setFocus();
return; return;
@ -437,23 +467,42 @@ public class PutHomeCursorDialog extends CaveJFACEDialog implements
} }
} }
@Override /**
protected void createButtonsForButtonBar(Composite parent) { * Create the action buttons at the bottom of the dialog.
*/
private void createActionButtons() {
Composite buttonComp = new Composite(shell, SWT.NONE);
GridLayout gl = new GridLayout(2, true);
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
buttonComp.setLayout(gl);
buttonComp.setLayoutData(gd);
int buttonWidth = 75;
// override, so can add calculate as default button. // override, so can add calculate as default button.
goButton = createButton(parent, SWT.OK, "Go", true); gd = new GridData(SWT.RIGHT, SWT.DEFAULT, true, false);
closeButton = createButton(parent, SWT.CLOSE, "Close", false); gd.widthHint = buttonWidth;
goButton.addListener(SWT.Selection, new Listener() { goBtn = new Button(buttonComp, SWT.PUSH);
public void handleEvent(Event event) { goBtn.setText("Go");
goBtn.setLayoutData(gd);
goBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateStation(); updateStation();
} }
}); });
closeButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) { gd = new GridData(SWT.LEFT, SWT.DEFAULT, true, false);
exitDialog(); gd.widthHint = buttonWidth;
closeBtn = new Button(buttonComp, SWT.PUSH);
closeBtn.setText("Close");
closeBtn.setLayoutData(gd);
closeBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
close();
} }
}); });
} }
/** /**
@ -585,9 +634,12 @@ public class PutHomeCursorDialog extends CaveJFACEDialog implements
@Override @Override
public void pointChanged() { public void pointChanged() {
VizApp.runAsync(new Runnable() { VizApp.runAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
if (isDisposed()) {
return;
}
Coordinate point = PointsDataManager.getInstance().getHome(); Coordinate point = PointsDataManager.getInstance().getHome();
lonTextField.setText(String.valueOf(point.x)); lonTextField.setText(String.valueOf(point.x));
latTextField.setText(String.valueOf(point.y)); latTextField.setText(String.valueOf(point.y));
@ -597,5 +649,4 @@ public class PutHomeCursorDialog extends CaveJFACEDialog implements
}); });
} }
} }