Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / TableOperations.java @ 18046

History | View | Annotate | Download (17.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 6736 caballero
import java.awt.Dimension;
44 1830 fernando
import java.io.IOException;
45
46 1219 vcaballero
import com.hardcode.driverManager.DriverLoadException;
47 10626 caballero
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
48 884 fernando
import com.hardcode.gdbms.engine.data.DataSource;
49
import com.hardcode.gdbms.engine.data.DataSourceFactory;
50 2217 fernando
import com.hardcode.gdbms.engine.instruction.EvaluationException;
51 884 fernando
import com.hardcode.gdbms.engine.instruction.SemanticException;
52
import com.hardcode.gdbms.parser.ParseException;
53 855 fernando
import com.iver.andami.PluginServices;
54
import com.iver.andami.messages.NotificationManager;
55 596 fernando
import com.iver.andami.plugins.Extension;
56 6877 cesar
import com.iver.andami.ui.mdiManager.IWindow;
57 3940 caballero
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
58 884 fernando
import com.iver.cit.gvsig.fmap.layers.FBitSet;
59 1774 fernando
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
60 855 fernando
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
61
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 855 fernando
        private SelectableDataSource dataSource = 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
                ProjectTable[] pts = (ProjectTable[]) project.getDocumentsByType(ProjectTableFactory.registerName)
92
                        .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 3940 caballero
                                                        SelectableDataSource sds=null;
122
                                                        try {
123 7304 caballero
                                                                sds = sourceProjectTable.getModelo().getRecordset();
124 10626 caballero
                                                        } catch (ReadDriverException e) {
125
                                                                e.printStackTrace();
126 3940 caballero
                                                        }
127 1830 fernando
                                                        String tableName1 = sds.getName();
128
129
                                                        ProjectTable targetProjectTable = (ProjectTable) targetTable.getSelected();
130 3940 caballero
                                                        try {
131 7304 caballero
                                                                sds = targetProjectTable.getModelo().getRecordset();
132 10626 caballero
                                                        } catch (ReadDriverException e) {
133
                                                                e.printStackTrace();
134 3940 caballero
                                                        }
135 1830 fernando
136
                                                        String tableName2 = sds.getName();
137
138
                                                        String field1 = (String) firstTableField.getSelected();
139
                                                        String field2 = (String) secondTableField.getSelected();
140
141 2183 fernando
                                                        String sql =
142
                                                                "custom com_iver_cit_gvsig_arcjoin tables '" +
143
                                                                tableName1 + "', '" + tableName2 + "' values(" +
144
                                                                field1 + ", " + field2 + ");";
145 1830 fernando
                                                        System.out.println(sql);
146
147
                                                        try {
148 2183 fernando
                                                                SelectableDataSource result = new SelectableDataSource(LayerFactory.getDataSourceFactory()
149
                                                                                                                                                                                                   .executeSQL(sql,
150 2758 fernando
                                                                                        DataSourceFactory.AUTOMATIC_OPENING));
151 1830 fernando
                                                                ProjectTable projectTable = (ProjectTable) sourceTable.getSelected();
152 3940 caballero
                                                                EditableAdapter auxea=new EditableAdapter();
153
                                                                auxea.setOriginalDataSource(result);
154
                                                                projectTable.replaceDataSource(auxea);
155 1830 fernando
                                                        } catch (ParseException e) {
156
                                                                throw new RuntimeException(e);
157
                                                        } catch (DriverLoadException e) {
158
                                                                NotificationManager.addError("Error con la carga de drivers",
159
                                                                        e);
160 10626 caballero
                                                        } catch (ReadDriverException e) {
161 1830 fernando
                                                                NotificationManager.addError("Error leyendo del driver",
162
                                                                        e);
163
                                                        } catch (SemanticException e) {
164
                                                                throw new RuntimeException(e);
165 2217 fernando
                                                        } catch (EvaluationException e) {
166
                                                                NotificationManager.addError("Error de evaluaci?n de la expresi?n",
167
                                                                                e);
168
                            }
169 1830 fernando
                                                }
170
171
                                                public void next(WizardEvent w) {
172
                                                        WizardControl wiz = w.wizard;
173
                                                        wiz.enableBack(true);
174 2183 fernando
                                                        wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
175
176 1830 fernando
                                                        if (w.currentStep == 1) {
177
                                                                ProjectTable pt = (ProjectTable) sourceTable.getSelected();
178
179
                                                                try {
180
                                                                        firstTableField.setModel(new FieldSelectionModel(
181 3940 caballero
                                                                                        pt.getModelo().getRecordset(),
182 2337 fernando
                                                                                        PluginServices.getText(this, "seleccione_campo_enlace"),
183 1830 fernando
                                                                                        -1));
184
                                                                } catch (SelectionException e) {
185
                                                                        NotificationManager.addError("Error obteniendo los campos de la tabla",
186
                                                                                e);
187 10626 caballero
                                                                } catch (ReadDriverException e) {
188
                                                                        NotificationManager.addError("Error obteniendo los campos de la tabla",
189
                                                                                        e);
190 1830 fernando
                                                                }
191
                                                        } else if (w.currentStep == 3) {
192
                                                                try {
193
                                                                        //tabla
194
                                                                        ProjectTable pt = (ProjectTable) sourceTable.getSelected();
195
196
                                                                        //?ndice del campo
197 7304 caballero
                                                                        SelectableDataSource sds = pt.getModelo().getRecordset();
198 1830 fernando
                                                                        String fieldName = (String) firstTableField.getSelected();
199
                                                                        int fieldIndex = sds.getFieldIndexByName(fieldName);
200
                                                                        int type = sds.getFieldType(fieldIndex);
201
202
                                                                        secondTableField.setModel(new FieldSelectionModel(
203 3940 caballero
                                                                                        ((ProjectTable) targetTable.getSelected()).getModelo().getRecordset(),
204 2337 fernando
                                                                                        PluginServices.getText(this, "seleccione_campo_enlace"),
205 1830 fernando
                                                                                        type));
206
                                                                } catch (SelectionException e) {
207
                                                                        NotificationManager.addError("Error obteniendo los campos de la tabla",
208
                                                                                e);
209 10626 caballero
                                                                } catch (ReadDriverException e) {
210 1830 fernando
                                                                        NotificationManager.addError("Error obteniendo los campos de la tabla",
211
                                                                                e);
212
                                                                }
213
                                                        }
214
                                                }
215
216
                                                public void back(WizardEvent w) {
217
                                                        WizardControl wiz = w.wizard;
218
                                                        wiz.enableBack(true);
219 2183 fernando
                                                        wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
220 1830 fernando
                                                }
221
                                        });
222 9532 caballero
                                project.setModified(true);
223 6880 cesar
                                PluginServices.getMDIManager().addWindow(wiz);
224 1830 fernando
                        } catch (SelectionException e) {
225
                                NotificationManager.addError("Error abriendo el asistente", e);
226
                        }
227 2183 fernando
                }else if ("LINK".equals(actionCommand)) {
228
                        try {
229
                                final ObjectSelectionStep sourceTable = new ObjectSelectionStep();
230
                                sourceTable.setModel(new TableSelectionModel(pts,
231 2337 fernando
                                                PluginServices.getText(this, "seleccione_tabla_origen")));
232 2183 fernando
233
                                final ObjectSelectionStep targetTable = new ObjectSelectionStep();
234
                                targetTable.setModel(new TableSelectionModel(pts,
235 2337 fernando
                                        PluginServices.getText(this, "seleccione_tabla_a_enlazar")));
236 2183 fernando
237
                                final ObjectSelectionStep firstTableField = new ObjectSelectionStep();
238
                                final ObjectSelectionStep secondTableField = new ObjectSelectionStep();
239 2337 fernando
                                final AndamiWizard wiz = new AndamiWizard(PluginServices.getText(this, "back"), PluginServices.getText(this, "next"), PluginServices.getText(this, "finish"), PluginServices.getText(this, "cancel"));
240 6736 caballero
                                wiz.setSize(new Dimension(450,200));
241 2183 fernando
                                wiz.addStep(sourceTable);
242
                                wiz.addStep(firstTableField);
243
                                wiz.addStep(targetTable);
244
                                wiz.addStep(secondTableField);
245
246
                                wiz.addWizardListener(new WizardListener() {
247
                                                public void cancel(WizardEvent w) {
248 6880 cesar
                                                        PluginServices.getMDIManager().closeWindow(wiz);
249 2183 fernando
                                                }
250
251
                                                public void finished(WizardEvent w) {
252 6880 cesar
                                                        PluginServices.getMDIManager().closeWindow(wiz);
253 2183 fernando
254
                                                        ProjectTable sourceProjectTable = (ProjectTable) sourceTable.getSelected();
255 3940 caballero
                                                        SelectableDataSource sds1=null;;
256
                                                        try {
257 7304 caballero
                                                                sds1 = sourceProjectTable.getModelo().getRecordset();
258 10626 caballero
                                                        } catch (ReadDriverException e) {
259 3940 caballero
                                                                e.printStackTrace();
260
                                                        }
261 7304 caballero
                                                        //String tableName1 = sds1.getName();
262 2183 fernando
263
                                                        ProjectTable targetProjectTable = (ProjectTable) targetTable.getSelected();
264 3940 caballero
                                                        SelectableDataSource sds2=null;
265
                                                        try {
266 7304 caballero
                                                                sds2 = targetProjectTable.getModelo().getRecordset();
267 10626 caballero
                                                        } catch (ReadDriverException e) {
268 3940 caballero
                                                                e.printStackTrace();
269
                                                        }
270 2183 fernando
271 7304 caballero
                                                        //String tableName2 = sds2.getName();
272 2183 fernando
273
                                                        String field1 = (String) firstTableField.getSelected();
274
                                                        String field2 = (String) secondTableField.getSelected();
275
                                                        sourceProjectTable.setLinkTable(sds2.getName(),field1,field2);
276
                                                        ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject().setLinkTable();
277
                                                }
278
279
                                                public void next(WizardEvent w) {
280
                                                        WizardControl wiz = w.wizard;
281
                                                        wiz.enableBack(true);
282
                                                        wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
283
284
                                                        if (w.currentStep == 1) {
285
                                                                ProjectTable pt = (ProjectTable) sourceTable.getSelected();
286
287
                                                                try {
288
                                                                        firstTableField.setModel(new FieldSelectionModel(
289 3940 caballero
                                                                                        pt.getModelo().getRecordset(),
290 2337 fernando
                                                                                        PluginServices.getText(this, "seleccione_campo_enlace"),
291 2183 fernando
                                                                                        -1));
292
                                                                } catch (SelectionException e) {
293
                                                                        NotificationManager.addError("Error obteniendo los campos de la tabla",
294
                                                                                e);
295 10626 caballero
                                                                } catch (ReadDriverException e) {
296 3940 caballero
                                                                        e.printStackTrace();
297 2183 fernando
                                                                }
298
                                                        } else if (w.currentStep == 3) {
299
                                                                try {
300
                                                                        //tabla
301
                                                                        ProjectTable pt = (ProjectTable) sourceTable.getSelected();
302
303
                                                                        //?ndice del campo
304 7304 caballero
                                                                        SelectableDataSource sds = pt.getModelo().getRecordset();
305 2183 fernando
                                                                        String fieldName = (String) firstTableField.getSelected();
306
                                                                        int fieldIndex = sds.getFieldIndexByName(fieldName);
307
                                                                        int type = sds.getFieldType(fieldIndex);
308
309
                                                                        secondTableField.setModel(new FieldSelectionModel(
310 3940 caballero
                                                                                        ((ProjectTable) targetTable.getSelected()).getModelo().getRecordset(),
311 2337 fernando
                                                                                        PluginServices.getText(this, "seleccione_campo_enlace"),
312 2183 fernando
                                                                                        type));
313
                                                                } catch (SelectionException e) {
314
                                                                        NotificationManager.addError("Error obteniendo los campos de la tabla",
315
                                                                                e);
316 10626 caballero
                                                                } catch (ReadDriverException e) {
317 2183 fernando
                                                                        NotificationManager.addError("Error obteniendo los campos de la tabla",
318
                                                                                e);
319
                                                                }
320
                                                        }
321
                                                }
322
323
                                                public void back(WizardEvent w) {
324
                                                        WizardControl wiz = w.wizard;
325
                                                        wiz.enableBack(true);
326
                                                        wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
327
                                                }
328
                                        });
329 9532 caballero
                                project.setModified(true);
330 6880 cesar
                                PluginServices.getMDIManager().addWindow(wiz);
331 2183 fernando
                        } catch (SelectionException e) {
332
                                NotificationManager.addError("Error abriendo el asistente", e);
333
                        }
334 3940 caballero
              }
335 1219 vcaballero
        }
336 312 fernando
337 1219 vcaballero
        /**
338 855 fernando
         * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#newSet(java.lang.String)
339 312 fernando
         */
340
        public void newSet(String expression) {
341 9494 ppiqueras
                // By Pablo: if no expression -> no element selected
342
                if (! this.filterExpressionFromWhereIsEmpty(expression)) {
343
                        long[] sel = doSet(expression);
344 9532 caballero
345 9494 ppiqueras
                        if (sel == null) {
346
                                throw new RuntimeException("Not a 'where' clause?");
347
                        }
348 9532 caballero
349 9494 ppiqueras
                        FBitSet selection = new FBitSet();
350 9532 caballero
351 9494 ppiqueras
                        for (int i = 0; i < sel.length; i++) {
352
                                selection.set((int) sel[i]);
353
                        }
354 9532 caballero
355 9494 ppiqueras
                        dataSource.clearSelection();
356
                        dataSource.setSelection(selection);
357 1219 vcaballero
                }
358 9494 ppiqueras
                else {
359
                        // By Pablo: if no expression -> no element selected
360
                        dataSource.clearSelection();
361 884 fernando
                }
362 312 fernando
        }
363 1219 vcaballero
364 312 fernando
        /**
365 855 fernando
         * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#newSet(java.lang.String)
366 312 fernando
         */
367 884 fernando
        private long[] doSet(String expression) {
368
                try {
369 2183 fernando
                        DataSource ds = LayerFactory.getDataSourceFactory().executeSQL(expression,
370 2667 fernando
                                        DataSourceFactory.MANUAL_OPENING);
371 1219 vcaballero
372 884 fernando
                        return ds.getWhereFilter();
373
                } catch (DriverLoadException e) {
374
                        NotificationManager.addError("Error cargando el driver", e);
375 10626 caballero
                } catch (ReadDriverException e) {
376 884 fernando
                        NotificationManager.addError("Error accediendo al driver", e);
377
                } catch (ParseException e) {
378
                        NotificationManager.addError("Parse error", e);
379
                } catch (SemanticException e) {
380
                        NotificationManager.addError(e.getMessage(), e);
381
                } catch (IOException e) {
382
                        NotificationManager.addError("GDBMS internal error", e);
383 2217 fernando
                } catch (EvaluationException e) {
384
                        NotificationManager.addError("Error con la expresi?n", e);
385
        }
386 1219 vcaballero
387 884 fernando
                return null;
388 312 fernando
        }
389
390 1219 vcaballero
        /**
391
         * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#addToSet(java.lang.String)
392
         */
393
        public void addToSet(String expression) {
394 9494 ppiqueras
                // By Pablo: if no expression -> don't add more elements to set
395
                if (! this.filterExpressionFromWhereIsEmpty(expression)) {
396
                        long[] sel = doSet(expression);
397 9532 caballero
398 9494 ppiqueras
                        if (sel == null) {
399
                                throw new RuntimeException("Not a 'where' clause?");
400
                        }
401 9532 caballero
402 9494 ppiqueras
                        FBitSet selection = new FBitSet();
403 9532 caballero
404 9494 ppiqueras
                        for (int i = 0; i < sel.length; i++) {
405
                                selection.set((int) sel[i]);
406
                        }
407 9532 caballero
408 9494 ppiqueras
                        FBitSet fbs = dataSource.getSelection();
409
                        fbs.or(selection);
410
                        dataSource.setSelection(fbs);
411 1219 vcaballero
                }
412
        }
413 312 fernando
414 1219 vcaballero
        /**
415
         * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#fromSet(java.lang.String)
416
         */
417
        public void fromSet(String expression) {
418 9494 ppiqueras
                // By Pablo: if no expression -> no element selected
419
                if (! this.filterExpressionFromWhereIsEmpty(expression)) {
420
                        long[] sel = doSet(expression);
421 9532 caballero
422 9494 ppiqueras
                        if (sel == null) {
423
                                throw new RuntimeException("Not a 'where' clause?");
424
                        }
425 9532 caballero
426 9494 ppiqueras
                        FBitSet selection = new FBitSet();
427 9532 caballero
428 9494 ppiqueras
                        for (int i = 0; i < sel.length; i++) {
429
                                selection.set((int) sel[i]);
430
                        }
431 9532 caballero
432 9494 ppiqueras
                        FBitSet fbs = dataSource.getSelection();
433
                        fbs.and(selection);
434
                        dataSource.setSelection(fbs);
435 1219 vcaballero
                }
436 9494 ppiqueras
                else {
437
                        // By Pablo: if no expression -> no element selected
438
                        dataSource.clearSelection();
439 312 fernando
                }
440 1219 vcaballero
        }
441 9532 caballero
442 9494 ppiqueras
        /**
443
         * Returns true if the WHERE subconsultation of the filterExpression is empty ("")
444 9532 caballero
         *
445 9494 ppiqueras
         * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
446
         * @param expression An string
447 9532 caballero
         * @return A boolean value
448 9494 ppiqueras
         */
449
        private boolean filterExpressionFromWhereIsEmpty(String expression) {
450
                String subExpression = expression.trim();
451 9532 caballero
                int pos;
452
453 9494 ppiqueras
                // Remove last ';' if exists
454
                if (subExpression.charAt(subExpression.length() -1) == ';')
455
                        subExpression = subExpression.substring(0, subExpression.length() -1).trim();
456 9532 caballero
457 9494 ppiqueras
                // If there is no 'where' clause
458
                if ((pos = subExpression.indexOf("where")) == -1)
459
                        return false;
460 9532 caballero
461 9494 ppiqueras
                // If there is no subexpression in the WHERE clause -> true
462
                subExpression = subExpression.substring(pos + 5, subExpression.length()).trim(); // + 5 is the length of 'where'
463
                if ( subExpression.length() == 0 )
464
                        return true;
465
                else
466
                        return false;
467
        }
468 312 fernando
469
        /**
470 5005 jorpiell
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
471 312 fernando
         */
472
        public boolean isVisible() {
473 6880 cesar
                IWindow v = PluginServices.getMDIManager().getActiveWindow();
474 312 fernando
475 855 fernando
                if (v == null) {
476 312 fernando
                        return false;
477
                }
478 1219 vcaballero
479 5900 jorpiell
                if (v instanceof Table) {
480 312 fernando
                        return true;
481 2183 fernando
                } /*else {
482 1219 vcaballero
                        if (v instanceof com.iver.cit.gvsig.gui.View) {
483 855 fernando
                                com.iver.cit.gvsig.gui.View view = (com.iver.cit.gvsig.gui.View) v;
484
                                ProjectView pv = view.getModel();
485 1219 vcaballero
                                FLayer[] seleccionadas = pv.getMapContext().getLayers()
486
                                                                                   .getActives();
487

488
                                if (seleccionadas.length == 1) {
489
                                        if (seleccionadas[0] instanceof AlphanumericData) {
490 855 fernando
                                                return true;
491
                                        }
492 312 fernando
                                }
493
                        }
494 2183 fernando
*/
495 312 fernando
                        return false;
496 2183 fernando
                //}
497 312 fernando
        }
498
499 596 fernando
        /**
500 5005 jorpiell
         * @see com.iver.andami.plugins.IExtension#initialize()
501 596 fernando
         */
502 5005 jorpiell
        public void initialize() {
503 14821 jmvivo
                registerIcons();
504 596 fernando
        }
505
506 14821 jmvivo
        private void registerIcons(){
507 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
508 14821 jmvivo
                                "table-join",
509
                                this.getClass().getClassLoader().getResource("images/tablejoin.png")
510
                        );
511
512 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
513 14821 jmvivo
                                "table-link",
514
                                this.getClass().getClassLoader().getResource("images/tablelink.png")
515
                        );
516
        }
517
518 596 fernando
        /**
519 5005 jorpiell
         * @see com.iver.andami.plugins.IExtension#isEnabled()
520 596 fernando
         */
521
        public boolean isEnabled() {
522 855 fernando
                return true;
523 596 fernando
        }
524 2183 fernando
525 3940 caballero
526 312 fernando
}