Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ShowTable.java @ 28248

History | View | Annotate | Download (5.53 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
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
50
import com.iver.andami.PluginServices;
51
import com.iver.andami.messages.NotificationManager;
52
import com.iver.andami.plugins.Extension;
53
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
54
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
55
import com.iver.cit.gvsig.fmap.layers.FLayer;
56
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
57
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
58
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
59
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
60
import com.iver.cit.gvsig.project.ProjectFactory;
61
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
62
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
63
import com.iver.cit.gvsig.project.documents.table.gui.Table;
64
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
65

    
66

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

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

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

    
85
                boolean algunaTabla = false;
86

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

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

    
103
                return algunaTabla;
104
        }
105

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

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

    
117
                return (f instanceof BaseView);
118
        }
119

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

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

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

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

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

    
149
                                        if (projectTable == null) {
150
                                                projectTable = ProjectFactory.createTable(PluginServices.getText(this, "Tabla_de_Atributos") + ": " + actives[i].getName(),
151
                                                                ea);
152
                                                projectTable.setProjectDocumentFactory(new ProjectTableFactory());
153
                                                projectTable.setAssociatedTable(co);
154
                                                ext.getProject().addDocument(projectTable);
155
                                                projectTable.setModel(ea);
156
                                        }
157
                                        Table t = new Table();
158
                                        t.setModel(projectTable);
159
                                        if (ea.isEditing())
160
                                                ea.getCommandRecord().addCommandListener(t);
161
                                        t.getModel().setModified(true);
162
                                        PluginServices.getMDIManager().addWindow(t);
163
                                }
164
                        }
165
                } catch (ReadDriverException e) {
166
            NotificationManager.addError(PluginServices.getText(this,"No_se_pudo_obtener_la_tabla_de_la_capa"), e);
167
        }
168
        }
169

    
170
        /**
171
         * @see com.iver.andami.plugins.IExtension#initialize()
172
         */
173
        public void initialize() {
174
                registerIcons();
175
        }
176

    
177
        private void registerIcons(){
178
                PluginServices.getIconTheme().registerDefault(
179
                                "layer-show-attribute-table",
180
                                this.getClass().getClassLoader().getResource("images/ResultConsulta.png")
181
                        );
182
        }
183
}