root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / TableOperations.java @ 24759
History | View | Annotate | Download (16.7 KB)
1 | 1103 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | 312 | fernando | package com.iver.cit.gvsig; |
42 | |||
43 | 22477 | vcaballero | import java.awt.Component; |
44 | 6736 | caballero | import java.awt.Dimension; |
45 | 22477 | vcaballero | import java.util.Iterator; |
46 | 1830 | fernando | |
47 | 22477 | vcaballero | import javax.swing.JOptionPane; |
48 | |||
49 | 24759 | jmvivo | import org.gvsig.fmap.dal.DataManager; |
50 | import org.gvsig.fmap.dal.exception.DataException; |
||
51 | import org.gvsig.fmap.dal.exception.ReadException; |
||
52 | import org.gvsig.fmap.dal.feature.Feature; |
||
53 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
54 | 22941 | jmvivo | import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
55 | 24759 | jmvivo | import org.opengis.feature.FeatureCollection; |
56 | 20994 | jmvivo | |
57 | 855 | fernando | import com.iver.andami.PluginServices; |
58 | import com.iver.andami.messages.NotificationManager; |
||
59 | 596 | fernando | import com.iver.andami.plugins.Extension; |
60 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
61 | 855 | fernando | import com.iver.cit.gvsig.gui.filter.ExpressionListener; |
62 | 9532 | caballero | import com.iver.cit.gvsig.project.Project; |
63 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.table.FieldSelectionModel; |
64 | import com.iver.cit.gvsig.project.documents.table.ObjectSelectionStep; |
||
65 | import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
||
66 | 7379 | caballero | import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
67 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.table.TableSelectionModel; |
68 | import com.iver.cit.gvsig.project.documents.table.gui.AndamiWizard; |
||
69 | import com.iver.cit.gvsig.project.documents.table.gui.Table; |
||
70 | 1830 | fernando | import com.iver.utiles.swing.objectSelection.SelectionException; |
71 | import com.iver.utiles.swing.wizard.WizardControl; |
||
72 | import com.iver.utiles.swing.wizard.WizardEvent; |
||
73 | import com.iver.utiles.swing.wizard.WizardListener; |
||
74 | 312 | fernando | |
75 | |||
76 | /**
|
||
77 | 1219 | vcaballero | * Extensi?n que controla las operaciones realizadas sobre las tablas.
|
78 | 312 | fernando | *
|
79 | * @author Fernando Gonz?lez Cort?s
|
||
80 | */
|
||
81 | 5005 | jorpiell | public class TableOperations extends Extension implements ExpressionListener { |
82 | 21665 | vcaballero | private FeatureStore featureStore = null; |
83 | 2183 | fernando | //private Table vista;
|
84 | 312 | fernando | |
85 | 1219 | vcaballero | /**
|
86 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
87 | 1219 | vcaballero | */
|
88 | public void execute(String actionCommand) { |
||
89 | 9532 | caballero | ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
90 | Project project=pe.getProject(); |
||
91 | 22931 | jmvivo | ProjectTable[] pts = project.getDocumentsByType(ProjectTableFactory.registerName)
|
92 | 9532 | caballero | .toArray(new ProjectTable[0]); |
93 | 2183 | fernando | if ("JOIN".equals(actionCommand)) { |
94 | 1830 | fernando | try {
|
95 | final ObjectSelectionStep sourceTable = new ObjectSelectionStep(); |
||
96 | sourceTable.setModel(new TableSelectionModel(pts,
|
||
97 | 2337 | fernando | PluginServices.getText(this, "seleccione_tabla_origen"))); |
98 | 312 | fernando | |
99 | 1830 | fernando | final ObjectSelectionStep targetTable = new ObjectSelectionStep(); |
100 | targetTable.setModel(new TableSelectionModel(pts,
|
||
101 | 2337 | fernando | PluginServices.getText(this, "seleccione_tabla_a_enlazar"))); |
102 | 312 | fernando | |
103 | 1830 | fernando | final ObjectSelectionStep firstTableField = new ObjectSelectionStep(); |
104 | final ObjectSelectionStep secondTableField = new ObjectSelectionStep(); |
||
105 | 2337 | fernando | final AndamiWizard wiz = new AndamiWizard(PluginServices.getText(this, "back"), PluginServices.getText(this, "next"), PluginServices.getText(this, "finish"), PluginServices.getText(this, "cancel")); |
106 | 6736 | caballero | wiz.setSize(new Dimension(450,200)); |
107 | 1830 | fernando | wiz.addStep(sourceTable); |
108 | wiz.addStep(firstTableField); |
||
109 | wiz.addStep(targetTable); |
||
110 | wiz.addStep(secondTableField); |
||
111 | |||
112 | wiz.addWizardListener(new WizardListener() {
|
||
113 | public void cancel(WizardEvent w) { |
||
114 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(wiz); |
115 | 1830 | fernando | } |
116 | |||
117 | public void finished(WizardEvent w) { |
||
118 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(wiz); |
119 | 1830 | fernando | |
120 | ProjectTable sourceProjectTable = (ProjectTable) sourceTable.getSelected(); |
||
121 | 22932 | jmvivo | FeatureStore fs1 = sourceProjectTable.getModel(); |
122 | 22477 | vcaballero | String tableName1 = fs1.getName();
|
123 | 1830 | fernando | |
124 | ProjectTable targetProjectTable = (ProjectTable) targetTable.getSelected(); |
||
125 | 22932 | jmvivo | FeatureStore fs2 = targetProjectTable.getModel(); |
126 | 1830 | fernando | |
127 | 22477 | vcaballero | String tableName2 = fs2.getName();
|
128 | 1830 | fernando | |
129 | String field1 = (String) firstTableField.getSelected(); |
||
130 | String field2 = (String) secondTableField.getSelected(); |
||
131 | |||
132 | 2183 | fernando | String sql =
|
133 | "custom com_iver_cit_gvsig_arcjoin tables '" +
|
||
134 | tableName1 + "', '" + tableName2 + "' values(" + |
||
135 | field1 + ", " + field2 + ");"; |
||
136 | 1830 | fernando | System.out.println(sql);
|
137 | |||
138 | try {
|
||
139 | 22477 | vcaballero | DataManager dm=DataManager.getManager(); |
140 | JoinFeatureStoreParameters jfsp=(JoinFeatureStoreParameters)dm.createDataStoreParameters(JoinFeatureStore.DATASTORE_NAME); |
||
141 | jfsp.setStorePrimary(fs1.getParameters()); |
||
142 | jfsp.setStoreSecondary(fs2.getParameters()); |
||
143 | jfsp.setDefaultGeometry(fs1.getDefaultFeatureType().getDefaultGeometry()); |
||
144 | jfsp.setFieldNamePrefix("Join_");
|
||
145 | jfsp.setLinkFieldPrimary(field1); |
||
146 | jfsp.setLinkFieldSecondary(field2); |
||
147 | |||
148 | JoinFeatureStore jfs=(JoinFeatureStore)dm.createDataStore(jfsp); |
||
149 | featureStore=jfs; |
||
150 | 1830 | fernando | ProjectTable projectTable = (ProjectTable) sourceTable.getSelected(); |
151 | 22932 | jmvivo | FeatureStore original = projectTable.getModel(); |
152 | 22477 | vcaballero | projectTable.setModel(jfs); |
153 | 22932 | jmvivo | |
154 | 22941 | jmvivo | if (projectTable.getAssociatedTable() != null) { |
155 | projectTable.getAssociatedTable().setDataStore( |
||
156 | jfs); |
||
157 | } |
||
158 | |||
159 | 22932 | jmvivo | original.dispose(); |
160 | |||
161 | 22717 | vcaballero | IWindow[] windows=PluginServices.getMDIManager().getAllWindows();
|
162 | 22931 | jmvivo | Table tableWindow; |
163 | 22717 | vcaballero | for (int i = 0; i < windows.length; i++) { |
164 | if (windows[i] instanceof Table){ |
||
165 | 22931 | jmvivo | tableWindow = (Table) windows[i]; |
166 | if (tableWindow.getModel().equals(
|
||
167 | projectTable)) { |
||
168 | tableWindow.setModel(projectTable); |
||
169 | 22717 | vcaballero | } |
170 | } |
||
171 | } |
||
172 | 21665 | vcaballero | } catch (ReadException e) {
|
173 | 1830 | fernando | NotificationManager.addError("Error leyendo del driver",
|
174 | e); |
||
175 | 22941 | jmvivo | } catch (LoadLayerException e) {
|
176 | NotificationManager.addError(e); |
||
177 | 22477 | vcaballero | } |
178 | 1830 | fernando | } |
179 | |||
180 | public void next(WizardEvent w) { |
||
181 | WizardControl wiz = w.wizard; |
||
182 | wiz.enableBack(true);
|
||
183 | 2183 | fernando | wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
|
184 | |||
185 | 1830 | fernando | if (w.currentStep == 1) { |
186 | ProjectTable pt = (ProjectTable) sourceTable.getSelected(); |
||
187 | |||
188 | try {
|
||
189 | firstTableField.setModel(new FieldSelectionModel(
|
||
190 | 22932 | jmvivo | pt.getModel(), |
191 | 2337 | fernando | PluginServices.getText(this, "seleccione_campo_enlace"), |
192 | 22477 | vcaballero | null));
|
193 | 1830 | fernando | } catch (SelectionException e) {
|
194 | NotificationManager.addError("Error obteniendo los campos de la tabla",
|
||
195 | e); |
||
196 | } |
||
197 | } else if (w.currentStep == 3) { |
||
198 | try {
|
||
199 | //tabla
|
||
200 | ProjectTable pt = (ProjectTable) sourceTable.getSelected(); |
||
201 | |||
202 | //?ndice del campo
|
||
203 | 22932 | jmvivo | FeatureStore fs = pt.getModel(); |
204 | 1830 | fernando | String fieldName = (String) firstTableField.getSelected(); |
205 | 22477 | vcaballero | String type = fs.getDefaultFeatureType().get(fieldName).getDataType();
|
206 | 1830 | fernando | |
207 | 22477 | vcaballero | |
208 | 1830 | fernando | secondTableField.setModel(new FieldSelectionModel(
|
209 | 22932 | jmvivo | ((ProjectTable) targetTable |
210 | .getSelected()) |
||
211 | .getModel(), |
||
212 | 2337 | fernando | PluginServices.getText(this, "seleccione_campo_enlace"), |
213 | 1830 | fernando | type)); |
214 | } catch (SelectionException e) {
|
||
215 | NotificationManager.addError("Error obteniendo los campos de la tabla",
|
||
216 | e); |
||
217 | } |
||
218 | } |
||
219 | } |
||
220 | |||
221 | public void back(WizardEvent w) { |
||
222 | WizardControl wiz = w.wizard; |
||
223 | wiz.enableBack(true);
|
||
224 | 2183 | fernando | wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
|
225 | 1830 | fernando | } |
226 | }); |
||
227 | 9532 | caballero | project.setModified(true);
|
228 | 6880 | cesar | PluginServices.getMDIManager().addWindow(wiz); |
229 | 1830 | fernando | } catch (SelectionException e) {
|
230 | NotificationManager.addError("Error abriendo el asistente", e);
|
||
231 | } |
||
232 | 2183 | fernando | }else if ("LINK".equals(actionCommand)) { |
233 | try {
|
||
234 | final ObjectSelectionStep sourceTable = new ObjectSelectionStep(); |
||
235 | sourceTable.setModel(new TableSelectionModel(pts,
|
||
236 | 2337 | fernando | PluginServices.getText(this, "seleccione_tabla_origen"))); |
237 | 2183 | fernando | |
238 | final ObjectSelectionStep targetTable = new ObjectSelectionStep(); |
||
239 | targetTable.setModel(new TableSelectionModel(pts,
|
||
240 | 2337 | fernando | PluginServices.getText(this, "seleccione_tabla_a_enlazar"))); |
241 | 2183 | fernando | |
242 | final ObjectSelectionStep firstTableField = new ObjectSelectionStep(); |
||
243 | final ObjectSelectionStep secondTableField = new ObjectSelectionStep(); |
||
244 | 2337 | fernando | final AndamiWizard wiz = new AndamiWizard(PluginServices.getText(this, "back"), PluginServices.getText(this, "next"), PluginServices.getText(this, "finish"), PluginServices.getText(this, "cancel")); |
245 | 6736 | caballero | wiz.setSize(new Dimension(450,200)); |
246 | 2183 | fernando | wiz.addStep(sourceTable); |
247 | wiz.addStep(firstTableField); |
||
248 | wiz.addStep(targetTable); |
||
249 | wiz.addStep(secondTableField); |
||
250 | |||
251 | wiz.addWizardListener(new WizardListener() {
|
||
252 | public void cancel(WizardEvent w) { |
||
253 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(wiz); |
254 | 2183 | fernando | } |
255 | |||
256 | public void finished(WizardEvent w) { |
||
257 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(wiz); |
258 | 2183 | fernando | |
259 | ProjectTable sourceProjectTable = (ProjectTable) sourceTable.getSelected(); |
||
260 | 22932 | jmvivo | FeatureStore sds1 = sourceProjectTable.getModel(); |
261 | 2183 | fernando | |
262 | ProjectTable targetProjectTable = (ProjectTable) targetTable.getSelected(); |
||
263 | 22932 | jmvivo | FeatureStore sds2 = targetProjectTable.getModel(); |
264 | 2183 | fernando | |
265 | String field1 = (String) firstTableField.getSelected(); |
||
266 | String field2 = (String) secondTableField.getSelected(); |
||
267 | sourceProjectTable.setLinkTable(sds2.getName(),field1,field2); |
||
268 | ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject().setLinkTable(); |
||
269 | 22717 | vcaballero | |
270 | 2183 | fernando | } |
271 | |||
272 | public void next(WizardEvent w) { |
||
273 | WizardControl wiz = w.wizard; |
||
274 | wiz.enableBack(true);
|
||
275 | wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
|
||
276 | |||
277 | if (w.currentStep == 1) { |
||
278 | ProjectTable pt = (ProjectTable) sourceTable.getSelected(); |
||
279 | |||
280 | try {
|
||
281 | firstTableField.setModel(new FieldSelectionModel(
|
||
282 | 22932 | jmvivo | pt.getModel(), |
283 | 2337 | fernando | PluginServices.getText(this, "seleccione_campo_enlace"), |
284 | 22477 | vcaballero | null));
|
285 | 2183 | fernando | } catch (SelectionException e) {
|
286 | NotificationManager.addError("Error obteniendo los campos de la tabla",
|
||
287 | e); |
||
288 | } |
||
289 | } else if (w.currentStep == 3) { |
||
290 | try {
|
||
291 | //tabla
|
||
292 | ProjectTable pt = (ProjectTable) sourceTable.getSelected(); |
||
293 | |||
294 | //?ndice del campo
|
||
295 | 22932 | jmvivo | FeatureStore fs = pt.getModel(); |
296 | 2183 | fernando | String fieldName = (String) firstTableField.getSelected(); |
297 | 22477 | vcaballero | String type = fs.getDefaultFeatureType().get(fieldName).getDataType();
|
298 | 2183 | fernando | |
299 | secondTableField.setModel(new FieldSelectionModel(
|
||
300 | 22932 | jmvivo | ((ProjectTable) targetTable |
301 | .getSelected()) |
||
302 | .getModel(), |
||
303 | 2337 | fernando | PluginServices.getText(this, "seleccione_campo_enlace"), |
304 | 2183 | fernando | type)); |
305 | } catch (SelectionException e) {
|
||
306 | NotificationManager.addError("Error obteniendo los campos de la tabla",
|
||
307 | e); |
||
308 | } |
||
309 | } |
||
310 | } |
||
311 | |||
312 | public void back(WizardEvent w) { |
||
313 | WizardControl wiz = w.wizard; |
||
314 | wiz.enableBack(true);
|
||
315 | wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
|
||
316 | } |
||
317 | }); |
||
318 | 9532 | caballero | project.setModified(true);
|
319 | 6880 | cesar | PluginServices.getMDIManager().addWindow(wiz); |
320 | 2183 | fernando | } catch (SelectionException e) {
|
321 | NotificationManager.addError("Error abriendo el asistente", e);
|
||
322 | } |
||
323 | 3940 | caballero | } |
324 | 1219 | vcaballero | } |
325 | 312 | fernando | |
326 | 1219 | vcaballero | /**
|
327 | 855 | fernando | * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#newSet(java.lang.String)
|
328 | 312 | fernando | */
|
329 | 22353 | jmvivo | public void newSet(String expression) throws DataException { |
330 | 22477 | vcaballero | // By Pablo: if no filter expression -> no element selected
|
331 | 9494 | ppiqueras | if (! this.filterExpressionFromWhereIsEmpty(expression)) { |
332 | 22477 | vcaballero | try {
|
333 | FeatureCollection sel = doSet(expression); |
||
334 | 9532 | caballero | |
335 | 22477 | vcaballero | if (sel == null) { |
336 | throw new RuntimeException("Not a 'where' clause?"); |
||
337 | } |
||
338 | featureStore.setSelection(sel); |
||
339 | }catch(Exception e){ |
||
340 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), "Asegurate de que la consulta es correcta."); |
||
341 | 9494 | ppiqueras | } |
342 | 1219 | vcaballero | } |
343 | 9494 | ppiqueras | else {
|
344 | // By Pablo: if no expression -> no element selected
|
||
345 | 21665 | vcaballero | featureStore.getSelection().clear(); |
346 | 884 | fernando | } |
347 | 312 | fernando | } |
348 | 1219 | vcaballero | |
349 | 312 | fernando | /**
|
350 | 855 | fernando | * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#newSet(java.lang.String)
|
351 | 312 | fernando | */
|
352 | 22477 | vcaballero | private FeatureCollection doSet(String expression) throws ReadException { |
353 | return (FeatureCollection)featureStore.getDataCollection(featureStore.getDefaultFeatureType(),expression,null); |
||
354 | 312 | fernando | } |
355 | 1219 | vcaballero | /**
|
356 | * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#addToSet(java.lang.String)
|
||
357 | */
|
||
358 | 22353 | jmvivo | public void addToSet(String expression) throws DataException { |
359 | 22477 | vcaballero | // By Pablo: if no filter expression -> don't add more elements to set
|
360 | 9494 | ppiqueras | if (! this.filterExpressionFromWhereIsEmpty(expression)) { |
361 | 22477 | vcaballero | FeatureCollection sel=null;
|
362 | try {
|
||
363 | sel = doSet(expression); |
||
364 | } catch (ReadException e) {
|
||
365 | throw new DataException("Expression",e); |
||
366 | } |
||
367 | 9532 | caballero | |
368 | 9494 | ppiqueras | if (sel == null) { |
369 | throw new RuntimeException("Not a 'where' clause?"); |
||
370 | } |
||
371 | 22477 | vcaballero | FeatureCollection oldSelection=(FeatureCollection)featureStore.getSelection(); |
372 | sel.addAll(oldSelection); |
||
373 | featureStore.setSelection(sel); |
||
374 | 1219 | vcaballero | } |
375 | } |
||
376 | 312 | fernando | |
377 | 1219 | vcaballero | /**
|
378 | * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#fromSet(java.lang.String)
|
||
379 | */
|
||
380 | 22353 | jmvivo | public void fromSet(String expression) throws DataException { |
381 | 22477 | vcaballero | // By Pablo: if no filter expression -> no element selected
|
382 | if (! this.filterExpressionFromWhereIsEmpty(expression)) { |
||
383 | 9532 | caballero | |
384 | 22477 | vcaballero | FeatureCollection sel=null;
|
385 | sel = doSet(expression); |
||
386 | 9532 | caballero | |
387 | 22477 | vcaballero | if (sel == null) { |
388 | throw new RuntimeException("Not a 'where' clause?"); |
||
389 | } |
||
390 | FeatureCollection oldSelection=(FeatureCollection)featureStore.getSelection(); |
||
391 | 9532 | caballero | |
392 | 22477 | vcaballero | MemoryFeatureCollection mfc=new MemoryFeatureCollection(featureStore);
|
393 | Iterator iterator=sel.iterator();
|
||
394 | while (iterator.hasNext()) {
|
||
395 | Feature feature = (Feature) iterator.next(); |
||
396 | if (oldSelection.contains(feature)){
|
||
397 | mfc.add(feature); |
||
398 | } |
||
399 | } |
||
400 | featureStore.setSelection(mfc); |
||
401 | } else {
|
||
402 | // By Pablo: if no expression -> no element selected
|
||
403 | featureStore.setSelection(featureStore.createSelection()); |
||
404 | } |
||
405 | 1219 | vcaballero | } |
406 | 9532 | caballero | |
407 | 9494 | ppiqueras | /**
|
408 | * Returns true if the WHERE subconsultation of the filterExpression is empty ("")
|
||
409 | 9532 | caballero | *
|
410 | 9494 | ppiqueras | * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
411 | * @param expression An string
|
||
412 | 9532 | caballero | * @return A boolean value
|
413 | 9494 | ppiqueras | */
|
414 | private boolean filterExpressionFromWhereIsEmpty(String expression) { |
||
415 | String subExpression = expression.trim();
|
||
416 | 9532 | caballero | int pos;
|
417 | |||
418 | 9494 | ppiqueras | // Remove last ';' if exists
|
419 | 22931 | jmvivo | if (subExpression.charAt(subExpression.length() -1) == ';') { |
420 | 9494 | ppiqueras | subExpression = subExpression.substring(0, subExpression.length() -1).trim(); |
421 | 22931 | jmvivo | } |
422 | 9532 | caballero | |
423 | 9494 | ppiqueras | // If there is no 'where' clause
|
424 | 22931 | jmvivo | if ((pos = subExpression.indexOf("where")) == -1) { |
425 | 9494 | ppiqueras | return false; |
426 | 22931 | jmvivo | } |
427 | 9532 | caballero | |
428 | 9494 | ppiqueras | // If there is no subexpression in the WHERE clause -> true
|
429 | subExpression = subExpression.substring(pos + 5, subExpression.length()).trim(); // + 5 is the length of 'where' |
||
430 | 22931 | jmvivo | if ( subExpression.length() == 0 ) { |
431 | 9494 | ppiqueras | return true; |
432 | 22931 | jmvivo | } else {
|
433 | 9494 | ppiqueras | return false; |
434 | 22931 | jmvivo | } |
435 | 9494 | ppiqueras | } |
436 | 312 | fernando | |
437 | /**
|
||
438 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
439 | 312 | fernando | */
|
440 | public boolean isVisible() { |
||
441 | 6880 | cesar | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
442 | 312 | fernando | |
443 | 855 | fernando | if (v == null) { |
444 | 312 | fernando | return false; |
445 | } |
||
446 | 1219 | vcaballero | |
447 | 5900 | jorpiell | if (v instanceof Table) { |
448 | 312 | fernando | return true; |
449 | 2183 | fernando | } /*else {
|
450 | 1219 | vcaballero | if (v instanceof com.iver.cit.gvsig.gui.View) {
|
451 | 855 | fernando | com.iver.cit.gvsig.gui.View view = (com.iver.cit.gvsig.gui.View) v;
|
452 | ProjectView pv = view.getModel();
|
||
453 | 1219 | vcaballero | FLayer[] seleccionadas = pv.getMapContext().getLayers()
|
454 | .getActives();
|
||
455 | |||
456 | if (seleccionadas.length == 1) {
|
||
457 | if (seleccionadas[0] instanceof AlphanumericData) {
|
||
458 | 855 | fernando | return true;
|
459 | }
|
||
460 | 312 | fernando | }
|
461 | }
|
||
462 | 2183 | fernando | */
|
463 | 312 | fernando | return false; |
464 | 2183 | fernando | //}
|
465 | 312 | fernando | } |
466 | |||
467 | 596 | fernando | /**
|
468 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
469 | 596 | fernando | */
|
470 | 5005 | jorpiell | public void initialize() { |
471 | 14821 | jmvivo | registerIcons(); |
472 | 22477 | vcaballero | org.gvsig.fmap.data.feature.joinstore.Register.selfRegister(); |
473 | |||
474 | |||
475 | 596 | fernando | } |
476 | |||
477 | 14821 | jmvivo | private void registerIcons(){ |
478 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
479 | 14821 | jmvivo | "table-join",
|
480 | this.getClass().getClassLoader().getResource("images/tablejoin.png") |
||
481 | ); |
||
482 | |||
483 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
484 | 14821 | jmvivo | "table-link",
|
485 | this.getClass().getClassLoader().getResource("images/tablelink.png") |
||
486 | ); |
||
487 | } |
||
488 | |||
489 | 596 | fernando | /**
|
490 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
491 | 596 | fernando | */
|
492 | public boolean isEnabled() { |
||
493 | 855 | fernando | return true; |
494 | 596 | fernando | } |
495 | 2183 | fernando | |
496 | 3940 | caballero | |
497 | 312 | fernando | } |