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.project.ui.tool.selection.provider;
16:
17: import net.refractions.udig.project.AdaptableFeature;
18: import net.refractions.udig.project.EditManagerEvent;
19: import net.refractions.udig.project.IEditManagerListener;
20: import net.refractions.udig.project.IMap;
21: import net.refractions.udig.project.ui.tool.IMapEditorSelectionProvider;
22:
23: import org.eclipse.jface.viewers.StructuredSelection;
24: import org.eclipse.ui.IEditorPart;
25:
26: /**
27: * A selection provider that provides as the current selection the currently selected feature.
28: * (map.getEditManager().getEditFeature()). The feature will be an Adaptable feature that adapts
29: * to the layer that the feature is from.
30: *
31: * @author Jesse
32: * @since 1.1.0
33: */
34: public class EditFeatureSelectionProvider extends
35: AbstractMapEditorSelectionProvider implements
36: IMapEditorSelectionProvider {
37:
38: public void setActiveMap(IMap map, IEditorPart editor) {
39: AdaptableFeature selectedFeature = (AdaptableFeature) map
40: .getEditManager().getEditFeature();
41: if (selectedFeature == null)
42: selection = new StructuredSelection();
43: else {
44: selection = new StructuredSelection(selectedFeature);
45: }
46:
47: map.getEditManager().addListener(new IEditManagerListener() {
48:
49: public void changed(EditManagerEvent event) {
50: if (event.getType() == EditManagerEvent.EDIT_FEATURE) {
51: AdaptableFeature selectedFeature = (AdaptableFeature) event
52: .getNewValue();
53: if (selectedFeature == null)
54: selection = new StructuredSelection();
55: else {
56: selection = new StructuredSelection(
57: selectedFeature);
58: }
59: notifyListeners();
60: }
61: }
62:
63: });
64: }
65:
66: }
|