Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / table / ProjectTable.java @ 7738

History | View | Annotate | Download (23.6 KB)

1
/* 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
package com.iver.cit.gvsig.project.documents.table;
42

    
43
import java.io.IOException;
44
import java.text.DateFormat;
45
import java.util.Date;
46

    
47
import javax.swing.JOptionPane;
48

    
49
import com.hardcode.driverManager.DriverLoadException;
50
import com.hardcode.gdbms.engine.data.DataSource;
51
import com.hardcode.gdbms.engine.data.DataSourceFactory;
52
import com.hardcode.gdbms.engine.data.NoSuchTableException;
53
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
54
import com.hardcode.gdbms.engine.instruction.SemanticException;
55
import com.hardcode.gdbms.parser.ParseException;
56
import com.iver.andami.PluginServices;
57
import com.iver.andami.messages.NotificationManager;
58
import com.iver.andami.ui.mdiManager.IWindow;
59
import com.iver.cit.gvsig.fmap.DriverException;
60
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
61
import com.iver.cit.gvsig.fmap.edition.IEditableSource;
62
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
63
import com.iver.cit.gvsig.fmap.layers.FLayer;
64
import com.iver.cit.gvsig.fmap.layers.FLayers;
65
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
66
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
67
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
68
import com.iver.cit.gvsig.fmap.layers.XMLException;
69
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
70
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
71
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend;
72
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
73
import com.iver.cit.gvsig.gui.tables.Column;
74
import com.iver.cit.gvsig.gui.tables.Columns;
75
import com.iver.cit.gvsig.project.Project;
76
import com.iver.cit.gvsig.project.documents.ProjectDocument;
77
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
78
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
79
import com.iver.cit.gvsig.project.documents.table.gui.TableProperties;
80
import com.iver.cit.gvsig.project.documents.view.ProjectView;
81
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory;
82
import com.iver.utiles.XMLEntity;
83

    
84
/**
85
 * Tabla del proyecto
86
 *
87
 * @author Fernando Gonz?lez Cort?s
88
 */
89
public class ProjectTable extends ProjectDocument {
90
        public static int numTables = 0;
91

    
92
        private IEditableSource esModel;
93

    
94
        private IEditableSource original;
95

    
96
        private String linkTable;
97

    
98
        private String field1;
99

    
100
        private String field2;
101

    
102
        /* No es necesaria para operar, s?lo para guardar el proyecto */
103
        private AlphanumericData associatedTable;
104

    
105
        private int[] mapping;
106

    
107
        private String[] alias;
108

    
109
        private Columns columns = new Columns();
110

    
111
        /**
112
         * Establece a true el bit index-?simo del bitmap de campos visibles. Los
113
         * campos cuyos bits est?n a true se considerar?n visibles y viceversa
114
         *
115
         * @param index
116
         *            indice del bit que se quiere establecer a true
117
         */
118
        public void set(int index) {
119
                // TODO implementar bien
120
                // modelo.set(index);
121

    
122
                change.firePropertyChange("visibles", true, true);
123
        }
124

    
125
        /**
126
         * Obtiene el valor del bit index-?simo del bitmap de campos visibles
127
         *
128
         * @param index
129
         *            indice del bit que se quiere obtener
130
         *
131
         * @return devuelve true si el campo index-?simo es visible y false en caso
132
         *         contrario
133
         */
134
        public boolean get(int index) {
135
                // TODO implementar bien
136
                // return modelo.get(index);
137
                return false;
138
        }
139

    
140
        /**
141
         * Obtiene el modelo de la Tabla. Es decir, una clase con capacidad para
142
         * leer la informaci?n de la tabla
143
         *
144
         * @return
145
         */
146
        public IEditableSource getModelo() {
147
                return esModel;
148
        }
149

    
150
        /**
151
         * Establece el valor del bit index-?simo al valor 'value'
152
         *
153
         * @param bitIndex
154
         *            indice del bit que se quiere tocar
155
         * @param value
156
         *            valor que se quiere establecer en el bit indicado
157
         */
158
        public void set(int bitIndex, boolean value) {
159
                // TODO implementar bien
160
                // modelo.set(bitIndex, value);
161
                change.firePropertyChange("visibles", value, value);
162
        }
163

    
164

    
165

    
166
        public void createAlias()
167
                        throws com.hardcode.gdbms.engine.data.driver.DriverException,
168
                        DriverLoadException {
169
                SelectableDataSource sds = esModel.getRecordset();
170
//                mapping = new int[sds.getFieldCount()+1];
171
//                alias = new String[sds.getFieldCount()+1];
172
//                for (int i = 0; i < sds.getFieldCount()+1; i++) {
173
//                mapping = new int[sds.getFieldCount()];
174
                alias = new String[sds.getFieldCount()];
175
                for (int i = 0; i < sds.getFieldCount(); i++) {
176
//                        mapping[i]=i;
177
                        alias[i]=sds.getFieldName(i);
178

    
179
//                        if (i==0){
180
//                                mapping[i]=i;
181
//                                alias[i]=" ";
182
//                        }else{
183
//
184
//                                mapping[i] = i;
185
//                                alias[i] = sds.getFieldName(i-1);
186
//                        }
187
                }
188
                recalculateColumnsFromAliases();
189

    
190
        }
191

    
192
        public void recalculateColumnsFromAliases()
193
        {
194
                columns.clear();
195
                for (int i = 0; i < alias.length; i++) {
196
                        addColumn(new Column());
197
                }
198

    
199
        }
200

    
201
        /**
202
         * DOCUMENT ME!
203
         *
204
         * @param sds
205
         *            DOCUMENT ME!
206
         * @throws DriverLoadException
207
         */
208
        public void setDataSource(IEditableSource es) throws DriverLoadException {
209
                setModel(es);
210

    
211
                setName(esModel.getRecordset().getName());
212
                setCreationDate(DateFormat.getInstance().format(new Date()));
213
                change.firePropertyChange("model", esModel, esModel);
214
        }
215

    
216
        /**
217
         * DOCUMENT ME!
218
         *
219
         * @param ds
220
         *            DOCUMENT ME!
221
         * @throws com.hardcode.gdbms.engine.data.driver.DriverException
222
         */
223
        public void replaceDataSource(IEditableSource es)
224
                        throws com.hardcode.gdbms.engine.data.driver.DriverException {
225
                if (original == null) {
226
                        original = esModel;
227
                }
228
                setModel(es);
229
                try {
230
                         es.getRecordset().setSelectionSupport((original
231
                                                        .getRecordset()).getSelectionSupport());
232

    
233
                        createAlias();
234
                } catch (DriverLoadException e1) {
235
                        throw new com.hardcode.gdbms.engine.data.driver.DriverException(e1);
236
                }
237
                // FJP:
238
                // Si la tabla proviene de un layer, cambiamos su recordset
239
                if (associatedTable != null) {
240
                        if (associatedTable instanceof FLyrVect) {
241
                                try {
242
                                        // ((EditableAdapter)((FLyrVect)
243
                                        // associatedTable).getSource()).setRecordSet((SelectableDataSource)es.getRecordset());
244
                                        FLyrVect lyrVect = (FLyrVect) associatedTable;
245
                                        lyrVect.setRecordset(es.getRecordset());
246
                                        ((FLyrVect) associatedTable).setIsJoined(true);
247
                                } catch (DriverLoadException e) {
248
                                        throw new com.hardcode.gdbms.engine.data.driver.DriverException(
249
                                                        e);
250
                                }
251
                        }
252
                }
253

    
254
                change.firePropertyChange("model", original, esModel);
255
        }
256

    
257
        /**
258
         * DOCUMENT ME!
259
         *
260
         * @throws com.hardcode.gdbms.engine.data.driver.DriverException
261
         * @throws DriverLoadException
262
         */
263
        public void restoreDataSource()
264
                        throws com.hardcode.gdbms.engine.data.driver.DriverException,
265
                        DriverLoadException {
266
                // FJP:
267
                // Si la tabla proviene de un layer, cambiamos su recordset
268
                if (associatedTable != null) {
269
                        if (associatedTable instanceof FLyrVect) {
270
                                // Miramos si la leyenda que est? usando es una
271
                                // leyenda basada en un campo de los de la uni?n.
272
                                // Si lo es, no dejamos pegarle el cambiazo al recordset
273
                                FLyrVect lyr = ((FLyrVect) associatedTable);
274
                                if (lyr.getLegend() instanceof ClassifiedLegend) {
275
                                        ClassifiedLegend legend = (ClassifiedLegend) lyr
276
                                                        .getLegend();
277
                                        VectorialLegend aux = (VectorialLegend) legend;
278
                                        String fieldName = legend.getFieldName();
279
                                        int idField = original.getRecordset().getFieldIndexByName(
280
                                                        fieldName);
281
                                        int idLabelField = -2;
282
                                        if (aux.getLabelField() != null) {
283
                                                idLabelField = original.getRecordset()
284
                                                                .getFieldIndexByName(aux.getLabelField());
285
                                        }
286
                                        if ((idField == -1) || (idLabelField == -1)) {
287
                                                // No se ha encontrado ese campo, o se est? etiquetando
288
                                                // por ese campo
289
                                                JOptionPane.showMessageDialog(null, PluginServices
290
                                                                .getText(this, "leyenda_campo_unido"));
291

    
292
                                                return;
293
                                        }
294
                                }
295

    
296
                                lyr.setRecordset(original.getRecordset());
297

    
298
                                lyr.setIsJoined(false);
299
                        }
300
                }
301

    
302
                setModel(original);
303
                original = null;
304
                createAlias();
305

    
306
                change.firePropertyChange("model", original, esModel);
307
        }
308

    
309
        /**
310
         * DOCUMENT ME!
311
         *
312
         * @return DOCUMENT ME!
313
         * @throws SaveException
314
         *
315
         * @throws XMLException
316
         */
317
        public XMLEntity getXMLEntity() throws SaveException {
318
                XMLEntity xml = super.getXMLEntity();
319
                try {
320
                        // xml.putProperty("nameClass", this.getClass().getName());
321
                        xml.putProperty("numTables", numTables);
322

    
323
                        if (getLinkTable() != null) {
324
                                xml.putProperty("linkTable", linkTable);
325
                                xml.putProperty("field1", field1);
326
                                xml.putProperty("field2", field2);
327
                        }
328

    
329
                        if (getOriginal() != null) {
330
                                xml.addChild(getOriginal().getRecordset().getXMLEntity());
331
                        }
332
                        xml.addChild(esModel.getRecordset().getXMLEntity());
333

    
334
//                        Object di = LayerFactory.getDataSourceFactory().getDriverInfo(
335
//                                        esModel.getRecordset().getName());
336

    
337
                        if (associatedTable != null) {
338
                                xml.putProperty("layerName", ((FLayer) associatedTable)
339
                                                .getName());
340
                                xml.putProperty("viewName", project
341
                                                .getView((FLayer) associatedTable));
342
                        }
343

    
344
                        xml.putProperty("mapping", mapping);
345
                        xml.putProperty("aliases", alias);
346
                } catch (Exception e) {
347
                        throw new SaveException(e, this.getClass().getName());
348
                }
349

    
350
                // for (int i=0;i<columns.size();i++){
351
                // Column column=(Column)columns.get(i);
352
                // xml.addChild(column.getXMLEntity());
353
                // }
354
                xml.addChild(columns.getXMLEntity());
355
                xml.putProperty("columns", true);
356
                return xml;
357
        }
358

    
359
        /**
360
         * DOCUMENT ME!
361
         *
362
         * @param xml
363
         *            DOCUMENT ME!
364
         * @param p
365
         *            DOCUMENT ME!
366
         *
367
         * @throws XMLException
368
         * @throws DriverException
369
         *
370
         * @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
371
         */
372
        public void setXMLEntity03(XMLEntity xml, Project p) throws XMLException,
373
                        DriverException {
374
                numTables = xml.getIntProperty("numTables");
375

    
376
                if (xml.getStringProperty("type").equals("otherDriverFile")) {
377
                        LayerFactory.getDataSourceFactory().addFileDataSource(
378
                                        xml.getStringProperty("driverName"),
379
                                        xml.getStringProperty("gdbmsname"),
380
                                        xml.getStringProperty("file"));
381

    
382
                        setSelectableDataSource03(xml);
383
                } else if (xml.getStringProperty("type").equals("sameDriverFile")) {
384
                        String layerName = xml.getStringProperty("layerName");
385

    
386
                        ProjectView vista =(ProjectView) project.getProjectDocumentByName(xml
387
                                        .getStringProperty("viewName"), ProjectViewFactory.registerName);
388
                        FLayer layer = vista.getMapContext().getLayers()
389
                                        .getLayer(layerName);
390

    
391
                        setTheModel((VectorialEditableAdapter) ((FLyrVect) layer).getSource());
392
                        associatedTable = (AlphanumericData) layer;
393

    
394
                        LayerFactory.getDataSourceFactory().addDataSource(
395
                                        (ObjectDriver) ((SingleLayer) layer).getSource()
396
                                                        .getDriver(), xml.getStringProperty("gdbmsname"));
397
                } else if (xml.getStringProperty("type").equals("db")) {
398
                        LayerFactory.getDataSourceFactory().addDBDataSourceByTable(
399
                                        xml.getStringProperty("gdbmsname"),
400
                                        xml.getStringProperty("host"), xml.getIntProperty("port"),
401
                                        xml.getStringProperty("user"),
402
                                        xml.getStringProperty("password"),
403
                                        xml.getStringProperty("dbName"),
404
                                        xml.getStringProperty("tableName"),
405
                                        xml.getStringProperty("driverInfo"));
406

    
407
                        setSelectableDataSource03(xml);
408
                }
409

    
410
                setName(xml.getStringProperty("name"));
411
        }
412

    
413
        /**
414
         * DOCUMENT ME!
415
         *
416
         * @param xml
417
         *            DOCUMENT ME!
418
         * @param p
419
         *            DOCUMENT ME!
420
         *
421
         * @throws XMLException
422
         * @throws DriverException
423
         * @throws OpenException
424
         *
425
         * @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
426
         */
427
        public void setXMLEntity(XMLEntity xml, Project p) throws XMLException,
428
                        DriverException, OpenException {
429
                try {
430
                        setName(xml.getStringProperty("name"));
431
                        numTables = xml.getIntProperty("numTables");
432

    
433
                        setSelectableDataSource(xml);
434

    
435
                        /*
436
                         * if (xml.getStringProperty("type").equals("otherDriverFile")) { }
437
                         * else if (xml.getStringProperty("type").equals("sameDriverFile")) {
438
                         * String layerName = xml.getStringProperty("layerName");
439
                         * ProjectView vista = project.getViewByName(xml.getStringProperty(
440
                         * "viewName")); FLayer layer =
441
                         * vista.getMapContext().getLayers().getLayer(layerName);
442
                         *
443
                         * modelo = ((AlphanumericData) layer).getRecordset();
444
                         * associatedTable = (AlphanumericData) layer; } else if
445
                         * (xml.getStringProperty("type").equals("db")) {
446
                         * setSelectableDataSource(xml); }
447
                         */
448
                        setName(xml.getStringProperty("name"));
449

    
450
                        if (xml.contains("linkTable")) {
451
                                setLinkTable(xml.getStringProperty("linkTable"), xml
452
                                                .getStringProperty("field1"), xml
453
                                                .getStringProperty("field2"));
454
                        }
455

    
456
                        if (xml.contains("mapping")) {
457
                                mapping = xml.getIntArrayProperty("mapping");
458
                                alias = xml.getStringArrayProperty("aliases");
459
                                // we check if all fields are real there (may be some external program has changed them.
460
                                // If we detect any change, we discard all mapping and aliases.
461
                                if (mapping.length != getModelo().getRecordset().getFieldCount())
462
                                {
463
                                        createAlias();
464
//                                        columns.clear();
465
//                                        for (int i = 0; i < esModel.getRecordset().getFieldCount(); i++) {
466
//                                                addColumn(new Column());
467
//                                        }
468
                                        return;
469

    
470
                                }
471

    
472
                        } else {
473
                                try {
474
                                        createAlias();
475
                                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
476
                                        throw new XMLException(e);
477
                                }
478
                        }
479
                } catch (Exception e) {
480
                        throw new OpenException(e, this.getClass().getName());
481
                }
482

    
483
                // for (int i=1;i<xml.getNumChild();i++){
484
                // columns.add(Column.createColumn(xml.getChild(i)));
485
                // }
486
                if (xml.contains("columns")) {
487
                        columns.clear();
488
                        columns = Columns
489
                                        .createColumns(xml.getChild(xml.getChildrenCount() - 1));
490
                }
491

    
492

    
493
        }
494

    
495
        /**
496
         * DOCUMENT ME!
497
         *
498
         * @param xml
499
         *            DOCUMENT ME!
500
         *
501
         * @throws XMLException
502
         *             DOCUMENT ME!
503
         * @throws DriverException
504
         *             DOCUMENT ME!
505
         */
506
        private void setSelectableDataSource03(XMLEntity xml) throws XMLException {
507
                String layerName = null;
508

    
509
                if (xml.contains("layerName")) {
510
                        layerName = xml.getStringProperty("layerName");
511
                }
512

    
513
                if (layerName == null) {
514
                        DataSource dataSource;
515

    
516
                        try {
517
                                dataSource = LayerFactory.getDataSourceFactory()
518
                                                .createRandomDataSource(
519
                                                                xml.getStringProperty("gdbmsname"),
520
                                                                DataSourceFactory.AUTOMATIC_OPENING);
521

    
522
                                SelectableDataSource sds = new SelectableDataSource(dataSource);
523

    
524
                                sds.setXMLEntity03(xml.getChild(0));
525
                                EditableAdapter auxea = new EditableAdapter();
526
                                auxea.setOriginalDataSource(sds);
527
                                setDataSource(auxea);
528
                        } catch (NoSuchTableException e) {
529
                                throw new XMLException(e);
530
                        } catch (DriverLoadException e) {
531
                                throw new XMLException(e);
532
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
533
                                throw new XMLException(e);
534
                        }
535

    
536
                } else {
537
                        ProjectView vista = (ProjectView) project.getProjectDocumentByName(xml
538
                                        .getStringProperty("viewName"), ProjectViewFactory.registerName);
539
                        FLayer layer = vista.getMapContext().getLayers()
540
                                        .getLayer(layerName);
541

    
542
                        setTheModel((VectorialEditableAdapter) ((FLyrVect) layer).getSource());
543
                        associatedTable = (AlphanumericData) layer;
544
                }
545
        }
546

    
547
        /**
548
         * DOCUMENT ME!
549
         *
550
         * @param xml
551
         *            DOCUMENT ME!
552
         *
553
         * @throws XMLException
554
         *             DOCUMENT ME!
555
         * @throws DriverException
556
         *             DOCUMENT ME!
557
         */
558
        private void setSelectableDataSource(XMLEntity xml) throws DriverException {
559
                String layerName = null;
560
                boolean bNeedToReplace = false;
561
                XMLEntity xmlAux = null;
562

    
563
                try {
564
                        EditableAdapter es;
565

    
566
                        if (xml.contains("layerName")) {
567
                                layerName = xml.getStringProperty("layerName");
568

    
569
                                ProjectView vista = (ProjectView) project.getProjectDocumentByName(xml
570
                                                .getStringProperty("viewName"), ProjectViewFactory.registerName);
571
                                FLayer layer = getLayer(vista.getMapContext().getLayers(),
572
                                                layerName);
573
                                EditableAdapter ea = new EditableAdapter();
574
                                SelectableDataSource sds = ((FLyrVect) layer).getRecordset();
575
                                // sds.setSelectionSupport(((FLyrVect)
576
                                // layer).getSelectionSupport());
577
                                ea.setOriginalDataSource(sds);
578
                                associatedTable = (AlphanumericData) layer;
579

    
580
                                es = ea;
581
                        } else {
582
                                es = new EditableAdapter();
583
                                es.setOriginalDataSource(SelectableDataSource
584
                                                .createSelectableDataSource(xml.getChild(0)));
585
                        }
586

    
587
                        setDataSource(es);
588

    
589
                        if (xml.getChildrenCount() == 2 && !(xml.contains("columns"))
590
                                        || (xml.contains("columns") && (xml.getChildrenCount() == 3))) {
591
                                bNeedToReplace = true;
592
                                xmlAux = xml.getChild(1);
593
                                es = new EditableAdapter();
594
                                // es.setRecordSet(SelectableDataSource.createSelectableDataSource(xmlAux));
595

    
596
                                // replaceDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(1)));
597
                        }
598

    
599
                        if (bNeedToReplace) {
600
                                if (layerName != null) {
601
                                        ProjectView vista = (ProjectView) project.getProjectDocumentByName(xml
602
                                                        .getStringProperty("viewName"), ProjectViewFactory.registerName);
603
                                        FLayer layer = getLayer(vista.getMapContext().getLayers(),
604
                                                        layerName);
605

    
606
                                        // modelo = ((AlphanumericData) layer).getRecordset();
607
                                        associatedTable = (AlphanumericData) layer;
608
                                }
609

    
610
                                EditableAdapter auxea = new EditableAdapter();
611
                                auxea.setOriginalDataSource(SelectableDataSource
612
                                                .createSelectableDataSource(xmlAux));
613
                                replaceDataSource(auxea);
614
                        }
615
                } catch (DriverLoadException e) {
616
                        throw new DriverException(e);
617
                } catch (NoSuchTableException e) {
618
                        throw new DriverException(e);
619
                } catch (ParseException e) {
620
                        throw new DriverException(e);
621
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
622
                        throw new DriverException(e);
623
                } catch (SemanticException e) {
624
                        throw new DriverException(e);
625
                } catch (IOException e) {
626
                        throw new DriverException(e);
627
                } catch (XMLException e) {
628
                        throw new DriverException(e);
629
                }
630
        }
631

    
632
        private FLayer getLayer(FLayers layers, String name) {
633
                for (int i = 0; i < layers.getLayersCount(); i++) {
634
                        if (layers.getLayer(i) instanceof FLayers) {
635
                                return getLayer((FLayers) layers.getLayer(i), name);
636
                        } else if (layers.getLayer(i).getName().equals(name)) {
637
                                return layers.getLayer(i);
638
                        }
639
                }
640
                return null;
641
        }
642

    
643
        /**
644
         * DOCUMENT ME!
645
         *
646
         * @return DOCUMENT ME!
647
         */
648
        public AlphanumericData getAssociatedTable() {
649
                return associatedTable;
650
        }
651

    
652
        /**
653
         * DOCUMENT ME!
654
         *
655
         * @param associatedTable
656
         *            DOCUMENT ME!
657
         */
658
        public void setAssociatedTable(AlphanumericData associatedTable) {
659
                this.associatedTable = associatedTable;
660
        }
661

    
662
        /**
663
         * Obtiene la fuente de datos original de la tabla si se ha invocado
664
         * replaceDataSource. Si no se invoc? este m?todo o se invoc? posteriormente
665
         * restoreDataSource se devuelve null
666
         *
667
         * @return Returns the original.
668
         */
669
        public IEditableSource getOriginal() {
670
                return original;
671
        }
672

    
673
        /**
674
         * Devuelve el identificador de la tabla que contiene el link.
675
         *
676
         * @return identificador ?nico de la tabla.
677
         */
678
        public String getLinkTable() {
679
                return linkTable;
680
        }
681

    
682
        /**
683
         * Devuelve el nombre del campo de la tabla a enlazar.
684
         *
685
         * @return Nombre del campo de la tabla a enlazar.
686
         */
687
        public String getField1() {
688
                return field1;
689
        }
690

    
691
        /**
692
         * Devuelve el nombre del campo de la tabla enlazada.
693
         *
694
         * @return Nombre del campo de la tabla enlazada.
695
         */
696
        public String getField2() {
697
                return field2;
698
        }
699

    
700
        /**
701
         * Inserta el identificador de la tabla, el campo de la primera tabla y el
702
         * campo de la segunda tabla.
703
         *
704
         * @param lt
705
         *            identificado de la tabla.
706
         * @param f1
707
         *            nombre del campo de la primera tabla.
708
         * @param f2
709
         *            nombre del campo de la segunda tabla.
710
         */
711
        public void setLinkTable(String lt, String f1, String f2) {
712
                linkTable = lt;
713
                field1 = f1;
714
                field2 = f2;
715
        }
716

    
717
        /**
718
         * Borra el identificador de la tabla y elimina del array de listener los
719
         * listener que sean del tipo: LinkSelectionListenr
720
         */
721
        public void removeLinkTable() {
722
                linkTable = null;
723
                try {
724
                        getModelo().getRecordset()
725
                                        .removeLinksSelectionListener();
726
                } catch (DriverLoadException e) {
727
                        e.printStackTrace();
728
                }
729
        }
730

    
731
        public String[] getAliases() {
732
                return alias;
733
        }
734

    
735
        public void setAliases(String[] alias) {
736
                this.alias = alias;
737
        }
738

    
739
        public int[] getMapping() {
740
                return mapping;
741
        }
742

    
743
        public void setMapping(int[] mapping) {
744
                this.mapping = mapping;
745
        }
746

    
747
        public void setModel(IEditableSource ies) {
748
                setTheModel(ies);
749
                try {
750
                        createAlias();
751
                } catch (DriverLoadException e) {
752
                        e.printStackTrace();
753
                        NotificationManager.addError(e);
754
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
755
                        e.printStackTrace();
756
                        NotificationManager.addError(e);
757
                }
758
        }
759

    
760
        public Column getColumn(int i) {
761
//                if (i==0){
762
//                        Column column=new Column();
763
//                        column.setWidth(45);
764
//                        return column;
765
//                }
766
//                i--;
767
                return (Column) columns.get(mapping[i]);
768
        }
769

    
770
        public void addColumn(Column column) {
771
                columns.add(column);
772
        }
773

    
774
        public int getColumnCount() {
775
                return columns.size();
776
        }
777

    
778
        public IWindow createWindow() {
779
                com.iver.cit.gvsig.project.documents.table.gui.Table table = new com.iver.cit.gvsig.project.documents.table.gui.Table();
780
                table.setModel(this);
781
                return table;
782
        }
783
        public IWindow getProperties() {
784
                try {
785
                        return new TableProperties(this);
786
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
787
                        e.printStackTrace();
788
                }
789
                return null;
790
        }
791

    
792
        public void afterRemove() {
793
                // TODO Auto-generated method stub
794

    
795
        }
796

    
797
        public void afterAdd() {
798
                // TODO Auto-generated method stub
799

    
800
        }
801

    
802
        private void setTheModel(IEditableSource es) {
803
                this.esModel = es;
804

    
805
        }
806

    
807

    
808
//        public int computeSignature() {
809
//                int result = 17;
810
//
811
//                Class clazz = getClass();
812
//                Field[] fields = clazz.getDeclaredFields();
813
//                for (int i = 0; i < fields.length; i++) {
814
//                        try {
815
//                                String type = fields[i].getType().getName();
816
//                                if (type.equals("boolean")) {
817
//                                        result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
818
//                                } else if (type.equals("java.lang.String")) {
819
//                                        Object v = fields[i].get(this);
820
//                                        if (v == null) {
821
//                                                result += 37;
822
//                                                continue;
823
//                                        }
824
//                                        char[] chars = ((String) v).toCharArray();
825
//                                        for (int j = 0; j < chars.length; j++) {
826
//                                                result += 37 + (int) chars[i];
827
//                                        }
828
//                                } else if (type.equals("byte")) {
829
//                                        result += 37 + (int) fields[i].getByte(this);
830
//                                } else if (type.equals("char")) {
831
//                                        result += 37 + (int) fields[i].getChar(this);
832
//                                } else if (type.equals("short")) {
833
//                                        result += 37 + (int) fields[i].getShort(this);
834
//                                } else if (type.equals("int")) {
835
//                                        result += 37 + fields[i].getInt(this);
836
//                                } else if (type.equals("long")) {
837
//                                        long f = fields[i].getLong(this) ;
838
//                                        result += 37 + (f ^ (f >>> 32));
839
//                                } else if (type.equals("float")) {
840
//                                        result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
841
//                                } else if (type.equals("double")) {
842
//                                        long f = Double.doubleToLongBits(fields[i].getDouble(this));
843
//                                        result += 37 + (f ^ (f >>> 32));
844
//                                } else {
845
//                                        Object obj = fields[i].get(this);
846
//                                        result += 37 + ((obj != null)? obj.hashCode() : 0);
847
//                                }
848
//                        } catch (Exception e) { e.printStackTrace(); }
849
//
850
//                }
851
//                return result;
852
//        }
853
}