Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / ShowTable.java @ 28546

History | View | Annotate | Download (5.28 KB)

1
/*
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
package com.iver.cit.gvsig;
48

    
49

    
50
import org.gvsig.fmap.dal.exception.DataException;
51
import org.gvsig.fmap.dal.exception.ReadException;
52
import org.gvsig.fmap.dal.feature.FeatureStore;
53
import org.gvsig.fmap.mapcontext.layers.FLayer;
54
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
55
import org.gvsig.project.document.table.FeatureTableDocument;
56
import org.gvsig.project.document.table.FeatureTableDocumentFactory;
57
import org.gvsig.project.document.table.gui.FeatureTableDocumentPanel;
58

    
59
import com.iver.andami.PluginServices;
60
import com.iver.andami.messages.NotificationManager;
61
import com.iver.andami.plugins.Extension;
62
import com.iver.cit.gvsig.project.ProjectFactory;
63
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
64

    
65

    
66
/**
67
 * Extensi?n que abre las tablas asociadas a las vistas.
68
 *
69
 * @author Vicente Caballero Navarro
70
 */
71
public class ShowTable extends Extension {
72
        /**
73
         * @see com.iver.andami.plugins.IExtension#isEnabled()
74
         */
75
        public boolean isEnabled() {
76
                BaseView f = (BaseView) PluginServices.getMDIManager().getActiveWindow();
77

    
78
                if (f == null) {
79
                        return false;
80
                }
81

    
82
                FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
83

    
84
                boolean algunaTabla = false;
85

    
86
                for (int i = 0; i < selected.length; i++) {
87
                        if (selected[i].isAvailable() && selected[i] instanceof FLyrVect) {
88
                                FLyrVect co = (FLyrVect) selected[i];
89

    
90
                                try {
91
                                        if (co.getFeatureStore() != null) {
92
                                                algunaTabla = true;
93
                                        }
94
                                } catch (ReadException e) {
95
                                        return false;
96
                                }catch(NullPointerException e){
97
                                        return false;
98
                                }
99
                        }
100
                }
101

    
102
                return algunaTabla;
103
        }
104

    
105
        /**
106
         * @see com.iver.andami.plugins.IExtension#isVisible()
107
         */
108
        public boolean isVisible() {
109
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
110
                                                                                                                         .getActiveWindow();
111

    
112
                if (f == null) {
113
                        return false;
114
                }
115

    
116
                return (f instanceof BaseView);
117
        }
118

    
119
        /**
120
         * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
121
         */
122
        public void execute(String s) {
123
                BaseView vista = (BaseView) PluginServices.getMDIManager().getActiveWindow();
124
                FLayer[] actives = vista.getModel().getMapContext().getLayers()
125
                                                        .getActives();
126

    
127
                try {
128
                        for (int i = 0; i < actives.length; i++) {
129
                                if (actives[i] instanceof FLyrVect) {
130
                                        FLyrVect co = (FLyrVect) actives[i];
131

    
132
                                        //SelectableDataSource dataSource;
133
                                        //dataSource = co.getRecordset();
134

    
135
                                        ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
136

    
137
                                        FeatureTableDocument projectTable = ext.getProject().getTable(co);
138
                                        FeatureStore fs=((FLyrVect)actives[i]).getFeatureStore();
139
//                                        ReadableVectorial rv=((FLyrVect)actives[i]).getSource();
140
//                                        if (rv instanceof VectorialEditableAdapter){
141
//                                                ea=(EditableAdapter)((FLyrVect)actives[i]).getSource();
142
//                                        }else{
143
//                                                ea=new EditableAdapter();
144
//                                                SelectableDataSource sds=((FLyrVect)actives[i]).getRecordset();
145
//                                                ea.setOriginalDataSource(sds);
146
//                                        }
147

    
148
                                        if (projectTable == null) {
149
                                                projectTable = ProjectFactory.createTable(PluginServices.getText(this, "Tabla_de_Atributos") + ": " + actives[i].getName(),
150
                                                                fs);
151
                                                projectTable.setProjectDocumentFactory(new FeatureTableDocumentFactory());
152
                                                projectTable.setAssociatedLayer(co);
153
                                                ext.getProject().addDocument(projectTable);
154
                                        }
155
                                        projectTable.setStore(fs);
156
                                        FeatureTableDocumentPanel t = new FeatureTableDocumentPanel(projectTable);
157
                                        t.getModel().setModified(true);
158
                                        PluginServices.getMDIManager().addWindow(t);
159
                                }
160
                        }
161
                } catch (DataException e) {
162
            NotificationManager.addError(PluginServices.getText(this,"No_se_pudo_obtener_la_tabla_de_la_capa"), e);
163
        }
164
        }
165

    
166
        /**
167
         * @see com.iver.andami.plugins.IExtension#initialize()
168
         */
169
        public void initialize() {
170
                registerIcons();
171
        }
172

    
173
        private void registerIcons(){
174
                PluginServices.getIconTheme().registerDefault(
175
                                "layer-show-attribute-table",
176
                                this.getClass().getClassLoader().getResource("images/ResultConsulta.png")
177
                        );
178
        }
179
}