1 package org
.argeo
.gis
.ui
.editors
;
3 import org
.argeo
.gis
.ui
.MapContextProvider
;
4 import org
.argeo
.gis
.ui
.MapControlCreator
;
5 import org
.argeo
.gis
.ui
.views
.LayersView
;
6 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
7 import org
.eclipse
.swt
.SWT
;
8 import org
.eclipse
.swt
.layout
.GridLayout
;
9 import org
.eclipse
.swt
.widgets
.Composite
;
10 import org
.eclipse
.ui
.IEditorInput
;
11 import org
.eclipse
.ui
.IEditorSite
;
12 import org
.eclipse
.ui
.PartInitException
;
13 import org
.eclipse
.ui
.part
.EditorPart
;
14 import org
.geotools
.data
.FeatureSource
;
15 import org
.geotools
.map
.MapContext
;
16 import org
.opengis
.feature
.simple
.SimpleFeature
;
17 import org
.opengis
.feature
.simple
.SimpleFeatureType
;
19 /** A generic map editor */
20 public class DefaultMapEditor
extends EditorPart
implements MapContextProvider
{
21 public final static String ID
= "org.argeo.gis.ui.defaultMapEditor";
23 private MapContext mapContext
;
24 private Composite map
;
25 private MapControlCreator mapControlCreator
;
28 public void init(IEditorSite site
, IEditorInput input
)
29 throws PartInitException
{
30 if (input
instanceof MapContextProvider
) {
31 mapContext
= ((MapContextProvider
) input
).getMapContext();
34 setPartName(input
.getName());
36 throw new PartInitException("Support only "
37 + MapContextProvider
.class + " inputs");
42 public void createPartControl(Composite parent
) {
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 map
= mapControlCreator
.createMapControl(mapArea
, this);
52 FeatureSource
<SimpleFeatureType
, SimpleFeature
> featureSource
) {
53 // TODO: deal with style
54 mapContext
.addLayer(featureSource
, null);
58 public void doSave(IProgressMonitor monitor
) {
62 public void doSaveAs() {
66 public boolean isDirty() {
71 public boolean isSaveAsAllowed() {
76 public void setFocus() {
77 LayersView layersView
= (LayersView
) getEditorSite()
78 .getWorkbenchWindow().getActivePage().findView(LayersView
.ID
);
79 layersView
.setMapContext(getMapContext());
83 public MapContext
getMapContext() {
87 public void setMapControlCreator(MapControlCreator mapControlCreator
) {
88 this.mapControlCreator
= mapControlCreator
;