Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ShowTable.java @ 11359

History | View | Annotate | Download (5.21 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
package com.iver.cit.gvsig;
48
49 10626 caballero
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
50 2267 fernando
import com.iver.andami.PluginServices;
51
import com.iver.andami.messages.NotificationManager;
52
import com.iver.andami.plugins.Extension;
53 3960 caballero
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
54 3940 caballero
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
55 2267 fernando
import com.iver.cit.gvsig.fmap.layers.FLayer;
56 3940 caballero
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
57 4843 caballero
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
58 2267 fernando
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 7304 caballero
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
62 7343 caballero
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
63 7304 caballero
import com.iver.cit.gvsig.project.documents.table.gui.Table;
64
import com.iver.cit.gvsig.project.documents.view.gui.View;
65 2267 fernando
66
67
/**
68
 * Extensi?n que abre las tablas asociadas a las vistas.
69
 *
70
 * @author Vicente Caballero Navarro
71
 */
72 5005 jorpiell
public class ShowTable extends Extension {
73 2267 fernando
        /**
74 5005 jorpiell
         * @see com.iver.andami.plugins.IExtension#isEnabled()
75 2267 fernando
         */
76
        public boolean isEnabled() {
77 6880 cesar
                View f = (View) PluginServices.getMDIManager().getActiveWindow();
78 2267 fernando
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 7304 caballero
                        if (selected[i].isAvailable() && selected[i] instanceof AlphanumericData) {
89 2267 fernando
                                AlphanumericData co = (AlphanumericData) selected[i];
90 3940 caballero
91 2267 fernando
                                try {
92
                                        if (co.getRecordset() != null) {
93
                                                algunaTabla = true;
94
                                        }
95 10626 caballero
                                } catch (ReadDriverException e) {
96
                                        return false;
97 3435 caballero
                                }catch(NullPointerException e){
98
                                        return false;
99 2267 fernando
                                }
100
                        }
101
                }
102
103
                return algunaTabla;
104
        }
105
106
        /**
107 5005 jorpiell
         * @see com.iver.andami.plugins.IExtension#isVisible()
108 2267 fernando
         */
109
        public boolean isVisible() {
110 6877 cesar
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
111 6880 cesar
                                                                                                                         .getActiveWindow();
112 2267 fernando
113
                if (f == null) {
114
                        return false;
115
                }
116
117 5900 jorpiell
                return (f instanceof View);
118 2267 fernando
        }
119
120
        /**
121 5005 jorpiell
         * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
122 2267 fernando
         */
123
        public void execute(String s) {
124 6880 cesar
                View vista = (View) PluginServices.getMDIManager().getActiveWindow();
125 7304 caballero
                FLayer[] actives = vista.getModel().getMapContext().getLayers()
126 2267 fernando
                                                        .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 3960 caballero
                                        //SelectableDataSource dataSource;
134
                                        //dataSource = co.getRecordset();
135 2267 fernando
136
                                        ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
137
138
                                        ProjectTable projectTable = ext.getProject().getTable(co);
139 3960 caballero
                                        EditableAdapter ea=null;
140 4843 caballero
                                        ReadableVectorial rv=((FLyrVect)actives[i]).getSource();
141
                                        if (rv instanceof VectorialEditableAdapter){
142 3960 caballero
                                                ea=(EditableAdapter)((FLyrVect)actives[i]).getSource();
143 3942 caballero
                                        }else{
144 3960 caballero
                                                ea=new EditableAdapter();
145 3963 caballero
                                                SelectableDataSource sds=((FLyrVect)actives[i]).getRecordset();
146 3960 caballero
                                                ea.setOriginalDataSource(sds);
147 3942 caballero
                                        }
148
149 2267 fernando
                                        if (projectTable == null) {
150 5503 cesar
                                                projectTable = ProjectFactory.createTable(PluginServices.getText(this, "Tabla_de_Atributos") + ": " + actives[i].getName(),
151 3960 caballero
                                                                ea);
152 7343 caballero
                                                projectTable.setProjectDocumentFactory(new ProjectTableFactory());
153 2267 fernando
                                                projectTable.setAssociatedTable(co);
154 7304 caballero
                                                ext.getProject().addDocument(projectTable);
155 2267 fernando
                                        }
156 3960 caballero
                                        projectTable.setModel(ea);
157 2267 fernando
                                        Table t = new Table();
158
                                        t.setModel(projectTable);
159 9532 caballero
                                        t.getModel().setModified(true);
160 6880 cesar
                                        PluginServices.getMDIManager().addWindow(t);
161 2267 fernando
                                }
162
                        }
163 10626 caballero
                } catch (ReadDriverException e) {
164 5258 jmvivo
            NotificationManager.addError(PluginServices.getText(this,"No_se_pudo_obtener_la_tabla_de_la_capa"), e);
165 10626 caballero
        }
166 2267 fernando
        }
167
168
        /**
169 5005 jorpiell
         * @see com.iver.andami.plugins.IExtension#initialize()
170 2267 fernando
         */
171 5005 jorpiell
        public void initialize() {
172 2267 fernando
        }
173
}