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 | 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 | 21354 | vcaballero | |
50 | 25089 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
51 | 24759 | jmvivo | import org.gvsig.fmap.dal.exception.ReadException; |
52 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
53 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.layers.FLayer; |
54 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
55 | 24962 | vcaballero | 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 | 20994 | jmvivo | |
59 | 2267 | fernando | 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 | 18345 | vcaballero | import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
64 | 2267 | fernando | |
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 | 18345 | vcaballero | BaseView f = (BaseView) 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 | 21893 | vcaballero | if (selected[i].isAvailable() && selected[i] instanceof FLyrVect) { |
88 | FLyrVect co = (FLyrVect) selected[i]; |
||
89 | 3940 | caballero | |
90 | 2267 | fernando | try {
|
91 | 21354 | vcaballero | if (co.getFeatureStore() != null) { |
92 | 2267 | fernando | algunaTabla = true;
|
93 | } |
||
94 | 21354 | vcaballero | } catch (ReadException e) {
|
95 | 10626 | caballero | return false; |
96 | 3435 | caballero | }catch(NullPointerException e){ |
97 | return false; |
||
98 | 2267 | fernando | } |
99 | } |
||
100 | } |
||
101 | |||
102 | return algunaTabla;
|
||
103 | } |
||
104 | |||
105 | /**
|
||
106 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isVisible()
|
107 | 2267 | fernando | */
|
108 | public boolean isVisible() { |
||
109 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
110 | 6880 | cesar | .getActiveWindow(); |
111 | 2267 | fernando | |
112 | if (f == null) { |
||
113 | return false; |
||
114 | } |
||
115 | |||
116 | 18345 | vcaballero | return (f instanceof BaseView); |
117 | 2267 | fernando | } |
118 | |||
119 | /**
|
||
120 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
121 | 2267 | fernando | */
|
122 | public void execute(String s) { |
||
123 | 18345 | vcaballero | BaseView vista = (BaseView) PluginServices.getMDIManager().getActiveWindow(); |
124 | 7304 | caballero | FLayer[] actives = vista.getModel().getMapContext().getLayers()
|
125 | 2267 | fernando | .getActives(); |
126 | |||
127 | try {
|
||
128 | for (int i = 0; i < actives.length; i++) { |
||
129 | 21893 | vcaballero | if (actives[i] instanceof FLyrVect) { |
130 | FLyrVect co = (FLyrVect) actives[i]; |
||
131 | 2267 | fernando | |
132 | 3960 | caballero | //SelectableDataSource dataSource;
|
133 | //dataSource = co.getRecordset();
|
||
134 | 2267 | fernando | |
135 | ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
||
136 | |||
137 | 24962 | vcaballero | FeatureTableDocument projectTable = ext.getProject().getTable(co); |
138 | 21354 | vcaballero | 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 | 3942 | caballero | |
148 | 2267 | fernando | if (projectTable == null) { |
149 | 5503 | cesar | projectTable = ProjectFactory.createTable(PluginServices.getText(this, "Tabla_de_Atributos") + ": " + actives[i].getName(), |
150 | 21354 | vcaballero | fs); |
151 | 24962 | vcaballero | projectTable.setProjectDocumentFactory(new FeatureTableDocumentFactory());
|
152 | projectTable.setAssociatedLayer(co); |
||
153 | 7304 | caballero | ext.getProject().addDocument(projectTable); |
154 | 2267 | fernando | } |
155 | 25068 | vcaballero | projectTable.setStore(fs); |
156 | 25907 | vcaballero | FeatureTableDocumentPanel t = new FeatureTableDocumentPanel(projectTable);
|
157 | 9532 | caballero | t.getModel().setModified(true);
|
158 | 6880 | cesar | PluginServices.getMDIManager().addWindow(t); |
159 | 2267 | fernando | } |
160 | } |
||
161 | 25089 | jmvivo | } catch (DataException e) {
|
162 | 5258 | jmvivo | NotificationManager.addError(PluginServices.getText(this,"No_se_pudo_obtener_la_tabla_de_la_capa"), e); |
163 | 10626 | caballero | } |
164 | 2267 | fernando | } |
165 | |||
166 | /**
|
||
167 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
168 | 2267 | fernando | */
|
169 | 5005 | jorpiell | public void initialize() { |
170 | 14821 | jmvivo | registerIcons(); |
171 | 2267 | fernando | } |
172 | 14821 | jmvivo | |
173 | private void registerIcons(){ |
||
174 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
175 | 14821 | jmvivo | "layer-show-attribute-table",
|
176 | this.getClass().getClassLoader().getResource("images/ResultConsulta.png") |
||
177 | ); |
||
178 | } |
||
179 | 2267 | fernando | } |