Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / ShowTable.java @ 33281

History | View | Annotate | Download (5.27 KB)

1 2267 fernando
/*
2
 * Created on 02-mar-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47 29596 jpiera
package org.gvsig.app.extension;
48 2267 fernando
49 21354 vcaballero
50 29596 jpiera
import org.gvsig.andami.PluginServices;
51
import org.gvsig.andami.messages.NotificationManager;
52
import org.gvsig.andami.plugins.Extension;
53 31496 jjdelcerro
import org.gvsig.app.project.ProjectManager;
54
import org.gvsig.app.project.documents.table.TableDocument;
55
import org.gvsig.app.project.documents.table.TableManager;
56 29596 jpiera
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
57 31496 jjdelcerro
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
58 25089 jmvivo
import org.gvsig.fmap.dal.exception.DataException;
59 24759 jmvivo
import org.gvsig.fmap.dal.feature.FeatureStore;
60 20994 jmvivo
import org.gvsig.fmap.mapcontext.layers.FLayer;
61
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
62
63 2267 fernando
64
65
/**
66
 * Extensi?n que abre las tablas asociadas a las vistas.
67
 *
68
 * @author Vicente Caballero Navarro
69
 */
70 5005 jorpiell
public class ShowTable extends Extension {
71 2267 fernando
        /**
72 29596 jpiera
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
73 2267 fernando
         */
74
        public boolean isEnabled() {
75 31496 jjdelcerro
                AbstractViewPanel f = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
76 2267 fernando
77
                if (f == null) {
78
                        return false;
79
                }
80
81
                FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
82
83
                boolean algunaTabla = false;
84
85
                for (int i = 0; i < selected.length; i++) {
86 21893 vcaballero
                        if (selected[i].isAvailable() && selected[i] instanceof FLyrVect) {
87
                                FLyrVect co = (FLyrVect) selected[i];
88 3940 caballero
89 2267 fernando
                                try {
90 21354 vcaballero
                                        if (co.getFeatureStore() != null) {
91 2267 fernando
                                                algunaTabla = true;
92
                                        }
93 30049 cordinyana
//                                } catch (ReadException e) {
94
//                                        return false;
95 3435 caballero
                                }catch(NullPointerException e){
96
                                        return false;
97 2267 fernando
                                }
98
                        }
99
                }
100
101
                return algunaTabla;
102
        }
103
104
        /**
105 29596 jpiera
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
106 2267 fernando
         */
107
        public boolean isVisible() {
108 29596 jpiera
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
109 6880 cesar
                                                                                                                         .getActiveWindow();
110 2267 fernando
111
                if (f == null) {
112
                        return false;
113
                }
114
115 31496 jjdelcerro
                return (f instanceof AbstractViewPanel);
116 2267 fernando
        }
117
118
        /**
119 5005 jorpiell
         * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
120 2267 fernando
         */
121
        public void execute(String s) {
122 31496 jjdelcerro
                AbstractViewPanel vista = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
123 7304 caballero
                FLayer[] actives = vista.getModel().getMapContext().getLayers()
124 2267 fernando
                                                        .getActives();
125
126
                try {
127
                        for (int i = 0; i < actives.length; i++) {
128 21893 vcaballero
                                if (actives[i] instanceof FLyrVect) {
129
                                        FLyrVect co = (FLyrVect) actives[i];
130 2267 fernando
131 3960 caballero
                                        //SelectableDataSource dataSource;
132
                                        //dataSource = co.getRecordset();
133 2267 fernando
134
                                        ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
135
136 31496 jjdelcerro
                                        TableDocument projectTable = ext.getProject().getTable(co);
137 21354 vcaballero
                                        FeatureStore fs=((FLyrVect)actives[i]).getFeatureStore();
138
//                                        ReadableVectorial rv=((FLyrVect)actives[i]).getSource();
139
//                                        if (rv instanceof VectorialEditableAdapter){
140
//                                                ea=(EditableAdapter)((FLyrVect)actives[i]).getSource();
141
//                                        }else{
142
//                                                ea=new EditableAdapter();
143
//                                                SelectableDataSource sds=((FLyrVect)actives[i]).getRecordset();
144
//                                                ea.setOriginalDataSource(sds);
145
//                                        }
146 3942 caballero
147 2267 fernando
                                        if (projectTable == null) {
148 31496 jjdelcerro
                                                projectTable = (TableDocument) ProjectManager.getInstance().createDocument(
149
                                                                TableManager.TYPENAME,
150
                                                                PluginServices.getText(this, "Tabla_de_Atributos") + ": " + actives[i].getName()
151
                                                );
152
                                                projectTable.setStore(fs);
153 24962 vcaballero
                                                projectTable.setAssociatedLayer(co);
154 31496 jjdelcerro
                                                ext.getProject().add(projectTable);
155 2267 fernando
                                        }
156 32776 cordinyana
157 25907 vcaballero
                                        FeatureTableDocumentPanel t = new FeatureTableDocumentPanel(projectTable);
158 9532 caballero
                                        t.getModel().setModified(true);
159 6880 cesar
                                        PluginServices.getMDIManager().addWindow(t);
160 2267 fernando
                                }
161
                        }
162 25089 jmvivo
                } catch (DataException e) {
163 5258 jmvivo
            NotificationManager.addError(PluginServices.getText(this,"No_se_pudo_obtener_la_tabla_de_la_capa"), e);
164 10626 caballero
        }
165 2267 fernando
        }
166
167
        /**
168 29596 jpiera
         * @see org.gvsig.andami.plugins.IExtension#initialize()
169 2267 fernando
         */
170 5005 jorpiell
        public void initialize() {
171 14821 jmvivo
                registerIcons();
172 2267 fernando
        }
173 14821 jmvivo
174
        private void registerIcons(){
175 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
176 14821 jmvivo
                                "layer-show-attribute-table",
177
                                this.getClass().getClassLoader().getResource("images/ResultConsulta.png")
178
                        );
179
        }
180 2267 fernando
}