svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / ShowTable.java @ 8745
History | View | Annotate | Download (5.08 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 | 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 | 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.gui.View; |
||
61 | 7421 | cesar | import com.iver.cit.gvsig.project.Project; |
62 | 2267 | fernando | import com.iver.cit.gvsig.project.ProjectFactory; |
63 | import com.iver.cit.gvsig.project.ProjectTable; |
||
64 | |||
65 | |||
66 | /**
|
||
67 | * Extensi?n que abre las tablas asociadas a las vistas.
|
||
68 | *
|
||
69 | * @author Vicente Caballero Navarro
|
||
70 | */
|
||
71 | 5005 | jorpiell | public class ShowTable extends Extension { |
72 | 2267 | fernando | /**
|
73 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
74 | 2267 | fernando | */
|
75 | public boolean isEnabled() { |
||
76 | 6880 | cesar | View f = (View) PluginServices.getMDIManager().getActiveWindow(); |
77 | 2267 | fernando | |
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 | 6778 | jmvivo | if (selected[i].isAvailable() && selected[i] instanceof AlphanumericData) { |
88 | 2267 | fernando | AlphanumericData co = (AlphanumericData) selected[i]; |
89 | 3940 | caballero | |
90 | 2267 | fernando | try {
|
91 | if (co.getRecordset() != null) { |
||
92 | algunaTabla = true;
|
||
93 | } |
||
94 | } catch (DriverException e) {
|
||
95 | 3435 | caballero | }catch(NullPointerException e){ |
96 | return false; |
||
97 | 2267 | fernando | } |
98 | } |
||
99 | } |
||
100 | |||
101 | return algunaTabla;
|
||
102 | } |
||
103 | |||
104 | /**
|
||
105 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isVisible()
|
106 | 2267 | fernando | */
|
107 | public boolean isVisible() { |
||
108 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
109 | 6880 | cesar | .getActiveWindow(); |
110 | 2267 | fernando | |
111 | if (f == null) { |
||
112 | return false; |
||
113 | } |
||
114 | |||
115 | 5900 | jorpiell | return (f instanceof View); |
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 | 6880 | cesar | View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
123 | 2267 | fernando | FLayer[] actives = ((View) vista).getModel().getMapContext().getLayers() |
124 | .getActives(); |
||
125 | |||
126 | try {
|
||
127 | for (int i = 0; i < actives.length; i++) { |
||
128 | if (actives[i] instanceof AlphanumericData) { |
||
129 | AlphanumericData co = (AlphanumericData) actives[i]; |
||
130 | |||
131 | 3960 | caballero | //SelectableDataSource dataSource;
|
132 | //dataSource = co.getRecordset();
|
||
133 | 2267 | fernando | |
134 | ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
||
135 | |||
136 | ProjectTable projectTable = ext.getProject().getTable(co); |
||
137 | 3960 | caballero | EditableAdapter ea=null;
|
138 | 4843 | caballero | ReadableVectorial rv=((FLyrVect)actives[i]).getSource(); |
139 | if (rv instanceof VectorialEditableAdapter){ |
||
140 | 3960 | caballero | ea=(EditableAdapter)((FLyrVect)actives[i]).getSource(); |
141 | 3942 | caballero | }else{
|
142 | 3960 | caballero | ea=new EditableAdapter();
|
143 | 3963 | caballero | SelectableDataSource sds=((FLyrVect)actives[i]).getRecordset(); |
144 | 3960 | caballero | ea.setOriginalDataSource(sds); |
145 | 3942 | caballero | } |
146 | |||
147 | 2267 | fernando | if (projectTable == null) { |
148 | 5503 | cesar | projectTable = ProjectFactory.createTable(PluginServices.getText(this, "Tabla_de_Atributos") + ": " + actives[i].getName(), |
149 | 3960 | caballero | ea); |
150 | 2267 | fernando | projectTable.setAssociatedTable(co); |
151 | ext.getProject().addTable(projectTable); |
||
152 | } |
||
153 | 3960 | caballero | projectTable.setModel(ea); |
154 | 7421 | cesar | Project.openTable(projectTable); |
155 | 2267 | fernando | } |
156 | } |
||
157 | 2565 | fernando | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
158 | 5258 | jmvivo | NotificationManager.addError(PluginServices.getText(this,"No_se_pudo_obtener_la_tabla_de_la_capa"), e); |
159 | 4455 | fjp | } catch (DriverException e) {
|
160 | e.printStackTrace(); |
||
161 | 5258 | jmvivo | NotificationManager.addError(PluginServices.getText(this,"No_se_pudo_obtener_la_tabla_de_la_capa"), e); |
162 | 4455 | fjp | } |
163 | 2267 | fernando | } |
164 | |||
165 | /**
|
||
166 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
167 | 2267 | fernando | */
|
168 | 5005 | jorpiell | public void initialize() { |
169 | 2267 | fernando | } |
170 | } |