]> git.argeo.org Git - lgpl/argeo-commons.git/blob - gis/plugins/org.argeo.gis.ui/src/main/java/org/argeo/gis/ui/editors/MapFormPage.java
Improve GIS
[lgpl/argeo-commons.git] / gis / plugins / org.argeo.gis.ui / src / main / java / org / argeo / gis / ui / editors / MapFormPage.java
1 package org.argeo.gis.ui.editors;
2
3 import javax.jcr.Node;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.argeo.gis.ui.MapControlCreator;
8 import org.argeo.gis.ui.MapViewer;
9 import org.argeo.gis.ui.MapViewerListener;
10 import org.eclipse.swt.SWT;
11 import org.eclipse.swt.layout.FillLayout;
12 import org.eclipse.swt.layout.GridData;
13 import org.eclipse.swt.layout.GridLayout;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.ui.forms.AbstractFormPart;
16 import org.eclipse.ui.forms.IManagedForm;
17 import org.eclipse.ui.forms.editor.FormEditor;
18 import org.eclipse.ui.forms.editor.FormPage;
19 import org.eclipse.ui.forms.widgets.FormToolkit;
20
21 /** A form editor page to edit geographical data. */
22 public class MapFormPage extends FormPage {
23 private final static Log log = LogFactory.getLog(MapFormPage.class);
24
25 private Node context;
26 private MapViewer mapViewer;
27 private MapControlCreator mapControlCreator;
28
29 public MapFormPage(FormEditor editor, String id, String title,
30 Node context, MapControlCreator mapControlCreator) {
31 super(editor, id, title);
32 this.context = context;
33 this.mapControlCreator = mapControlCreator;
34 }
35
36 @Override
37 protected void createFormContent(IManagedForm managedForm) {
38 Composite parent = managedForm.getForm().getBody();
39 parent.setLayout(new FillLayout());
40
41 FormToolkit tk = managedForm.getToolkit();
42
43 Composite mapArea = new Composite(parent, SWT.NONE);
44 GridLayout layout = new GridLayout();
45 layout.marginHeight = 0;
46 layout.marginWidth = 0;
47 mapArea.setLayout(layout);
48 mapViewer = mapControlCreator.createMapControl(context, mapArea);
49 mapViewer.getControl().setLayoutData(
50 new GridData(SWT.FILL, SWT.FILL, true, true));
51
52 // form part
53 MapFormPart mapFormPart = new MapFormPart();
54 getManagedForm().addPart(mapFormPart);
55 mapViewer.addMapViewerListener(mapFormPart);
56
57 tk.adapt(mapViewer.getControl());
58 }
59
60 public void setFocus() {
61 super.setFocus();
62 mapViewer.getControl().setFocus();
63 }
64
65 public MapViewer getMapViewer() {
66 return mapViewer;
67 }
68
69 private static class MapFormPart extends AbstractFormPart implements
70 MapViewerListener {
71
72 public void featureSelected(String layerId, String featureId) {
73 if (log.isDebugEnabled())
74 log.debug("Selected feature '" + featureId + "' of layer '"
75 + layerId + "'");
76 markDirty();
77 }
78
79 public void featureUnselected(String layerId, String featureId) {
80 if (log.isDebugEnabled())
81 log.debug("Unselected feature '" + featureId + "' of layer '"
82 + layerId + "'");
83
84 markDirty();
85 }
86
87 }
88 }