Revision 47557 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/ShowTable.java

View differences:

ShowTable.java
22 22
 */
23 23
package org.gvsig.app.extension;
24 24

  
25
import javax.swing.JComponent;
26 25
import javax.swing.JOptionPane;
27 26
import org.gvsig.andami.IconThemeHelper;
28 27
import org.gvsig.andami.plugins.Extension;
......
38 37
import org.gvsig.fmap.dal.feature.FeatureStore;
39 38
import org.gvsig.fmap.dal.feature.FeatureType;
40 39
import org.gvsig.fmap.mapcontext.MapContext;
41
import org.gvsig.fmap.mapcontext.layers.CancelationException;
42 40
import org.gvsig.fmap.mapcontext.layers.FLayer;
43 41
import org.gvsig.fmap.mapcontext.layers.FLayers;
42
import org.gvsig.fmap.mapcontext.layers.LayerCollectionAdapter;
44 43
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent;
45
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener;
46
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent;
47 44
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
48 45
import org.gvsig.tools.ToolsLocator;
49 46
import org.gvsig.tools.i18n.I18nManager;
......
57 54
 * Extensi?n que abre las tablas asociadas a las vistas.
58 55
 *
59 56
 */
60
public class ShowTable extends Extension implements LayerCollectionListener {
57
public class ShowTable extends Extension {
61 58

  
62 59
    @Override
63 60
    public boolean isEnabled() {
......
107 104
                    FLyrVect layerVect = (FLyrVect) layer;                    
108 105
                    TableDocument tableDoc = tableManager.getTableDocument(layerVect);
109 106
                    if (tableDoc == null) {
110
                        tableDoc = (TableDocument) tableManager.createDocument();
111
                        tableDoc.setName(layerVect.getName());
112
                        tableDoc.setStore(layerVect.getFeatureStore());
107
                        tableDoc = tableManager.getTableDocument(layerVect.getFeatureStore());
108
                        if (tableDoc == null) {
109
                            tableDoc = (TableDocument) tableManager.createDocument();
110
                            tableDoc.setName(layerVect.getName());
111
                            tableDoc.setStore(layerVect.getFeatureStore());
112
                            layerVect.getParentLayer().addLayerCollectionListener(new LayerCollectionAdapter() {
113
                                @Override
114
                                public void layerRemoved(LayerCollectionEvent e) {
115
                                    FLayer layer = e.getAffectedLayer();
116
                                    // Remove the related table document, if any
117
                                    if (layer == layerVect) {
118
                                        getTableManager().removeTableDocument((FLyrVect) layer);
119
                                        // If the parent layers has not other child layers, for sure there
120
                                        // are not related tables opened, don't need to listen
121
                                        // LayerCollectionEvents anymore.
122
                                        // TODO: remove us also when there are not any child layers with
123
                                        // related table documents
124
                                        FLayers layers = layer.getParentLayer();
125
                                        if (layers != null && layers.getLayersCount() == 0) {
126
                                            layers.removeLayerCollectionListener(this);
127
                                        }
128
                                    }
129
                                }
130
                            });
131
                            project.addDocument(tableDoc);
132
                        }
113 133
                        tableDoc.setAssociatedLayer(layerVect);
114
                        layerVect.getParentLayer().addLayerCollectionListener(this);
115
                        project.addDocument(tableDoc);
116 134
                    }
117 135
                    try {
118 136
                        FeatureStore store = tableDoc.getDataStore();
......
159 177
    public void initialize() {
160 178
        IconThemeHelper.registerIcon("action", "layer-show-attributes-table", this);
161 179
    }
162

  
163
    @Override
164
    public void layerAdded(LayerCollectionEvent e) {
165
        // Nothing to do
166
    }
167

  
168
    @Override
169
    public void layerMoved(LayerPositionEvent e) {
170
        // Nothing to do
171
    }
172

  
173
    @Override
174
    public void layerRemoved(LayerCollectionEvent e) {
175
        FLayer layer = e.getAffectedLayer();
176
        // Just in case we where listening to a group of layers being removed
177
        // remove us from there
178
        if (layer instanceof FLayers) {
179
            ((FLayers) layer).removeLayerCollectionListener(this);
180
        }
181
        // Remove the related table document, if any
182
        if (layer instanceof FLyrVect) {
183
            getTableManager().removeTableDocument((FLyrVect) layer);
184
            // If the parent layers has not other child layers, for sure there
185
            // are not related tables opened, don't need to listen
186
            // LayerCollectionEvents anymore.
187
            // TODO: remove us also when there are not any child layers with
188
            // related table documents
189
            FLayers layers = layer.getParentLayer();
190
            if (layers != null && layers.getLayersCount() == 0) {
191
                layers.removeLayerCollectionListener(this);
192
            }
193
        }
194
    }
195

  
196
    @Override
197
    public void layerAdding(LayerCollectionEvent e) throws CancelationException {
198
        // Nothing to do
199
    }
200

  
201
    @Override
202
    public void layerMoving(LayerPositionEvent e) throws CancelationException {
203
        // Nothing to do
204
    }
205

  
206
    @Override
207
    public void layerRemoving(LayerCollectionEvent e)
208
            throws CancelationException {
209
        // Nothing to do
210
    }
211

  
212
    @Override
213
    public void visibilityChanged(LayerCollectionEvent e)
214
            throws CancelationException {
215
        // Nothing to do
216
    }
217 180
}

Also available in: Unified diff