Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / extension / ShowTable.java @ 36443

History | View | Annotate | Download (6.55 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
package org.gvsig.app.extension;
23

    
24
import org.gvsig.andami.PluginServices;
25
import org.gvsig.andami.plugins.Extension;
26
import org.gvsig.app.project.ProjectManager;
27
import org.gvsig.app.project.documents.table.TableDocument;
28
import org.gvsig.app.project.documents.table.TableManager;
29
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
30
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
31
import org.gvsig.fmap.dal.feature.FeatureStore;
32
import org.gvsig.fmap.mapcontext.layers.CancelationException;
33
import org.gvsig.fmap.mapcontext.layers.FLayer;
34
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent;
35
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener;
36
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent;
37
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
38

    
39
/**
40
 * Extensi?n que abre las tablas asociadas a las vistas.
41
 * 
42
 * @author Vicente Caballero Navarro
43
 */
44
public class ShowTable extends Extension implements LayerCollectionListener {
45

    
46
    /**
47
     * @see org.gvsig.andami.plugins.IExtension#isEnabled()
48
     */
49
    public boolean isEnabled() {
50
        AbstractViewPanel f =
51
            (AbstractViewPanel) PluginServices.getMDIManager()
52
                .getActiveWindow();
53

    
54
        if (f == null) {
55
            return false;
56
        }
57

    
58
        FLayer[] selected =
59
            f.getViewDocument().getMapContext().getLayers().getActives();
60

    
61
        boolean algunaTabla = false;
62

    
63
        for (int i = 0; i < selected.length; i++) {
64
            if (selected[i].isAvailable() && selected[i] instanceof FLyrVect) {
65
                FLyrVect co = (FLyrVect) selected[i];
66

    
67
                try {
68
                    if (co.getFeatureStore() != null) {
69
                        algunaTabla = true;
70
                    }
71
                    // } catch (ReadException e) {
72
                    // return false;
73
                } catch (NullPointerException e) {
74
                    return false;
75
                }
76
            }
77
        }
78

    
79
        return algunaTabla;
80
    }
81

    
82
    /**
83
     * @see org.gvsig.andami.plugins.IExtension#isVisible()
84
     */
85
    public boolean isVisible() {
86
        org.gvsig.andami.ui.mdiManager.IWindow f =
87
            PluginServices.getMDIManager().getActiveWindow();
88

    
89
        if (f == null) {
90
            return false;
91
        }
92

    
93
        return (f instanceof AbstractViewPanel);
94
    }
95

    
96
    /**
97
     * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
98
     */
99
    public void execute(String s) {
100
        AbstractViewPanel vista =
101
            (AbstractViewPanel) PluginServices.getMDIManager()
102
                .getActiveWindow();
103
        FLayer[] actives =
104
            vista.getViewDocument().getMapContext().getLayers().getActives();
105

    
106
        for (int i = 0; i < actives.length; i++) {
107
            if (actives[i] instanceof FLyrVect) {
108
                FLyrVect co = (FLyrVect) actives[i];
109

    
110
                ProjectManager projectManager = getProjectManager();
111
                TableManager tableManager = getTableManager();
112

    
113
                TableDocument projectTable = tableManager.getTableDocument(co);
114
                FeatureStore fs = ((FLyrVect) actives[i]).getFeatureStore();
115

    
116
                if (projectTable == null) {
117
                    projectTable =
118
                        (TableDocument) projectManager.createDocument(
119
                            TableManager.TYPENAME,
120
                            PluginServices.getText(this, "Tabla_de_Atributos")
121
                                + ": " + actives[i].getName());
122
                    projectTable.setStore(fs);
123
                    projectTable.setAssociatedLayer(co);
124
                    co.getParentLayer().addLayerCollectionListener(this);
125
                    projectManager.getCurrentProject().add(projectTable);
126
                }
127

    
128
                FeatureTableDocumentPanel featureTableDocumentPanel =
129
                    (FeatureTableDocumentPanel) projectTable.getFactory()
130
                        .getMainWindow(projectTable);
131

    
132
                featureTableDocumentPanel.getModel().setModified(true);
133
                PluginServices.getMDIManager().addWindow(
134
                    featureTableDocumentPanel);
135
            }
136
        }
137

    
138
    }
139

    
140
    private ProjectManager getProjectManager() {
141
        return ProjectManager.getInstance();
142
    }
143

    
144
    private TableManager getTableManager() {
145
        TableManager tableManager =
146
            (TableManager) getProjectManager().getDocumentManager(
147
                TableManager.TYPENAME);
148
        return tableManager;
149
    }
150

    
151
    /**
152
     * @see org.gvsig.andami.plugins.IExtension#initialize()
153
     */
154
    public void initialize() {
155
        registerIcons();
156
    }
157

    
158
    private void registerIcons() {
159
        PluginServices.getIconTheme().registerDefault(
160
            "layer-show-attribute-table",
161
            this.getClass().getClassLoader()
162
                .getResource("images/ResultConsulta.png"));
163
    }
164

    
165
    public void layerAdded(LayerCollectionEvent e) {
166
        // Nothing to do
167
    }
168

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

    
173
    public void layerRemoved(LayerCollectionEvent e) {
174
        FLayer layer = e.getAffectedLayer();
175
        if (layer instanceof FLyrVect) {
176
            getTableManager().removeTableDocument((FLyrVect) layer);
177
        }
178
    }
179

    
180
    public void layerAdding(LayerCollectionEvent e) throws CancelationException {
181
        // Nothing to do
182
    }
183

    
184
    public void layerMoving(LayerPositionEvent e) throws CancelationException {
185
        // Nothing to do
186
    }
187

    
188
    public void layerRemoving(LayerCollectionEvent e)
189
        throws CancelationException {
190
        // Nothing to do
191
    }
192

    
193
    public void visibilityChanged(LayerCollectionEvent e)
194
        throws CancelationException {
195
        // Nothing to do
196
    }
197
}