svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ShowTable.java @ 4455
History | View | Annotate | Download (4.96 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.iver.andami.PluginServices; |
50 |
import com.iver.andami.messages.NotificationManager; |
51 |
import com.iver.andami.plugins.Extension; |
52 |
import com.iver.cit.gvsig.fmap.DriverException; |
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.SelectableDataSource; |
58 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
59 |
import com.iver.cit.gvsig.gui.Table; |
60 |
import com.iver.cit.gvsig.gui.View; |
61 |
import com.iver.cit.gvsig.project.ProjectFactory; |
62 |
import com.iver.cit.gvsig.project.ProjectTable; |
63 |
|
64 |
|
65 |
/**
|
66 |
* Extensi?n que abre las tablas asociadas a las vistas.
|
67 |
*
|
68 |
* @author Vicente Caballero Navarro
|
69 |
*/
|
70 |
public class ShowTable implements Extension { |
71 |
/**
|
72 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
73 |
*/
|
74 |
public boolean isEnabled() { |
75 |
View f = (View) PluginServices.getMDIManager().getActiveView(); |
76 |
|
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 |
if (selected[i] instanceof AlphanumericData) { |
87 |
AlphanumericData co = (AlphanumericData) selected[i]; |
88 |
|
89 |
try {
|
90 |
if (co.getRecordset() != null) { |
91 |
algunaTabla = true;
|
92 |
} |
93 |
} catch (DriverException e) {
|
94 |
}catch(NullPointerException e){ |
95 |
return false; |
96 |
} |
97 |
} |
98 |
} |
99 |
|
100 |
return algunaTabla;
|
101 |
} |
102 |
|
103 |
/**
|
104 |
* @see com.iver.andami.plugins.Extension#isVisible()
|
105 |
*/
|
106 |
public boolean isVisible() { |
107 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
108 |
.getActiveView(); |
109 |
|
110 |
if (f == null) { |
111 |
return false; |
112 |
} |
113 |
|
114 |
return (f.getClass() == View.class); |
115 |
} |
116 |
|
117 |
/**
|
118 |
* @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
|
119 |
*/
|
120 |
public void execute(String s) { |
121 |
View vista = (View) PluginServices.getMDIManager().getActiveView(); |
122 |
FLayer[] actives = ((View) vista).getModel().getMapContext().getLayers() |
123 |
.getActives(); |
124 |
|
125 |
try {
|
126 |
for (int i = 0; i < actives.length; i++) { |
127 |
if (actives[i] instanceof AlphanumericData) { |
128 |
AlphanumericData co = (AlphanumericData) actives[i]; |
129 |
|
130 |
//SelectableDataSource dataSource;
|
131 |
//dataSource = co.getRecordset();
|
132 |
|
133 |
ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
134 |
|
135 |
ProjectTable projectTable = ext.getProject().getTable(co); |
136 |
EditableAdapter ea=null;
|
137 |
if (((FLyrVect)actives[i]).getSource() instanceof VectorialEditableAdapter){ |
138 |
ea=(EditableAdapter)((FLyrVect)actives[i]).getSource(); |
139 |
}else{
|
140 |
ea=new EditableAdapter();
|
141 |
SelectableDataSource sds=((FLyrVect)actives[i]).getRecordset(); |
142 |
ea.setOriginalDataSource(sds); |
143 |
} |
144 |
|
145 |
if (projectTable == null) { |
146 |
projectTable = ProjectFactory.createTable(PluginServices.getText(this, "Tabla de Atributos") + ": " + actives[i].getName(), |
147 |
ea); |
148 |
projectTable.setAssociatedTable(co); |
149 |
ext.getProject().addTable(projectTable); |
150 |
} |
151 |
projectTable.setModel(ea); |
152 |
Table t = new Table();
|
153 |
t.setModel(projectTable); |
154 |
PluginServices.getMDIManager().addView(t); |
155 |
} |
156 |
} |
157 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
158 |
NotificationManager.addError("No se pudo obtener la tabla del tema", e);
|
159 |
} catch (DriverException e) {
|
160 |
e.printStackTrace(); |
161 |
NotificationManager.addError("No se pudo obtener la tabla del tema", e);
|
162 |
} |
163 |
} |
164 |
|
165 |
/**
|
166 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
167 |
*/
|
168 |
public void inicializar() { |
169 |
} |
170 |
} |