svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / evalexpression / notifierfactory / CurrentLayerSelectionChangedFactory.java @ 47733
History | View | Annotate | Download (2.88 KB)
1 | 47733 | jjdelcerro | package org.gvsig.app.extension.evalexpression.notifierfactory; |
---|---|---|---|
2 | |||
3 | import org.gvsig.app.ApplicationLocator; |
||
4 | import org.gvsig.app.ApplicationManager; |
||
5 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
6 | import org.gvsig.app.project.documents.view.ViewManager; |
||
7 | import org.gvsig.fmap.dal.DataStoreNotification; |
||
8 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
9 | import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
||
10 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
11 | import org.gvsig.tools.observer.BaseNotification; |
||
12 | import org.gvsig.tools.observer.Observable; |
||
13 | import org.gvsig.tools.observer.Observer; |
||
14 | |||
15 | /**
|
||
16 | *
|
||
17 | * @author jjdelcerro
|
||
18 | */
|
||
19 | public class CurrentLayerSelectionChangedFactory extends AbstractUpdaterFactory { |
||
20 | |||
21 | private static class CurrentLayerSelectionChangedUpdater extends AbstractUpdater { |
||
22 | |||
23 | private final Observer selectionListener; |
||
24 | private FLyrVect layer;
|
||
25 | |||
26 | @SuppressWarnings("Convert2Lambda") |
||
27 | public CurrentLayerSelectionChangedUpdater(UpdaterFactory factory, Observer observer, FLyrVect layer) { |
||
28 | super(factory, observer);
|
||
29 | if( layer == null ) { |
||
30 | throw new IllegalArgumentException(); |
||
31 | } |
||
32 | Updater updater = this;
|
||
33 | this.layer = layer;
|
||
34 | this.selectionListener = new Observer() { |
||
35 | @Override
|
||
36 | public void update(Observable observable, Object notification) { |
||
37 | FeatureStoreNotification n = (FeatureStoreNotification) notification; |
||
38 | if( n.isOfType(DataStoreNotification.SELECTION_CHANGE) ) {
|
||
39 | updater.update(); |
||
40 | } |
||
41 | } |
||
42 | }; |
||
43 | } |
||
44 | |||
45 | @Override
|
||
46 | public void add() { |
||
47 | FeatureStore store = layer.getFeatureStore(); |
||
48 | if (store != null) { |
||
49 | store.deleteObserver(this.selectionListener);
|
||
50 | store.addObserver(this.selectionListener);
|
||
51 | } |
||
52 | } |
||
53 | |||
54 | @Override
|
||
55 | public void remove() { |
||
56 | FeatureStore store = layer.getFeatureStore(); |
||
57 | if (store != null) { |
||
58 | store.deleteObserver(this.selectionListener);
|
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | |||
63 | public CurrentLayerSelectionChangedFactory() {
|
||
64 | super("CurrentLayerSelectionChanged", "Actualizar cuando cambie la seleccion de la capa activa"); |
||
65 | } |
||
66 | |||
67 | @Override
|
||
68 | public Updater create(Observer observer) { |
||
69 | ApplicationManager application = ApplicationLocator.getApplicationManager(); |
||
70 | ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
||
71 | if (viewdoc != null) { |
||
72 | FLyrVect layer = viewdoc.getMapContext().getLayers().getFirstActiveVectorLayer(); |
||
73 | Updater updater = new CurrentLayerSelectionChangedUpdater(this, observer, layer); |
||
74 | return updater;
|
||
75 | } |
||
76 | return null; |
||
77 | } |
||
78 | |||
79 | } |