01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.ui;
16:
17: import org.eclipse.jface.dialogs.Dialog;
18: import org.eclipse.jface.viewers.DialogCellEditor;
19: import org.eclipse.swt.widgets.Composite;
20: import org.eclipse.swt.widgets.Control;
21: import org.eclipse.swt.widgets.Tree;
22: import org.opengis.referencing.crs.CoordinateReferenceSystem;
23:
24: /**
25: * A dialog cell editor that opens a CRSChooser dialog.
26: *
27: * @author Jesse
28: * @since 1.1.0
29: */
30: public class CRSDialogCellEditor extends DialogCellEditor {
31: public CRSDialogCellEditor(Tree tree) {
32: super (tree);
33: }
34:
35: @Override
36: protected Object openDialogBox(Control cellEditorWindow) {
37: final CoordinateReferenceSystem[] result = new CoordinateReferenceSystem[1];
38:
39: final Dialog d = new Dialog(cellEditorWindow.getDisplay()
40: .getActiveShell()) {
41: final CRSChooser chooser = new CRSChooser();
42:
43: @Override
44: protected Control createDialogArea(Composite parent) {
45: chooser.setController(new Controller() {
46:
47: public void handleClose() {
48: close();
49: }
50:
51: public void handleOk() {
52: result[0] = chooser.getCRS();
53: }
54:
55: });
56: return chooser.createControl(parent,
57: (CoordinateReferenceSystem) getValue());
58: }
59:
60: @Override
61: public boolean close() {
62: result[0] = chooser.getCRS();
63: return super .close();
64: }
65: };
66: d.setBlockOnOpen(true);
67: d.open();
68: if (result[0] == null || result[0].equals(getValue()))
69: return null;
70: return result[0];
71: }
72: }
|