Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectTable.java @ 8745

History | View | Annotate | Download (23 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;
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.WindowInfo;
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.project.OpenException;
74
import com.iver.cit.gvsig.gui.project.SaveException;
75
import com.iver.cit.gvsig.gui.tables.Column;
76
import com.iver.cit.gvsig.gui.tables.Columns;
77
import com.iver.utiles.XMLEntity;
78

    
79
/**
80
 * Tabla del proyecto
81
 *
82
 * @author Fernando Gonz?lez Cort?s
83
 */
84
public class ProjectTable extends ProjectElement {
85
        private static int numTables = 0;
86

    
87
        private IEditableSource esModel;
88

    
89
        private IEditableSource original;
90

    
91
        private String linkTable;
92

    
93
        private String field1;
94

    
95
        private String field2;
96

    
97
        /* No es necesaria para operar, s?lo para guardar el proyecto */
98
        private AlphanumericData associatedTable;
99

    
100
        private int[] mapping;
101

    
102
        private String[] alias;
103

    
104
        private Columns columns = new Columns();
105

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

    
117
                change.firePropertyChange("visibles", true, true);
118
        }
119

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

    
135
        /**
136
         * Obtiene el modelo de la Tabla. Es decir, una clase con capacidad para
137
         * leer la informaci?n de la tabla
138
         *
139
         * @return
140
         */
141
        public IEditableSource getModelo() {
142
                return esModel;
143
        }
144

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

    
159
        /**
160
         * DOCUMENT ME!
161
         *
162
         * @param name
163
         *            DOCUMENT ME!
164
         * @param sds
165
         *            DOCUMENT ME!
166
         *
167
         * @return
168
         * @throws com.hardcode.gdbms.engine.data.driver.DriverException
169
         */
170
        public static ProjectTable createTable(String name, IEditableSource es)
171
                        throws com.hardcode.gdbms.engine.data.driver.DriverException {
172
                ProjectTable t = new ProjectTable();
173
                t.setModel(es);
174

    
175
                try {
176
                        t.createAlias();
177
                } catch (DriverLoadException e) {
178
                        e.printStackTrace();
179
                }
180

    
181
                t.setName(name);
182
                t.setCreationDate(DateFormat.getInstance().format(new Date()));
183
                numTables++;
184

    
185
                return t;
186
        }
187

    
188
        public void createAlias()
189
                        throws com.hardcode.gdbms.engine.data.driver.DriverException,
190
                        DriverLoadException {
191
                SelectableDataSource sds = esModel.getRecordset();
192
//                mapping = new int[sds.getFieldCount()+1];
193
//                alias = new String[sds.getFieldCount()+1];
194
//                for (int i = 0; i < sds.getFieldCount()+1; i++) {
195
                mapping = new int[sds.getFieldCount()];
196
                alias = new String[sds.getFieldCount()];
197
                for (int i = 0; i < sds.getFieldCount(); i++) {
198
                        mapping[i]=i;
199
                        alias[i]=sds.getFieldName(i);
200

    
201
//                        if (i==0){
202
//                                mapping[i]=i;
203
//                                alias[i]=" ";
204
//                        }else{
205
//
206
//                                mapping[i] = i;
207
//                                alias[i] = sds.getFieldName(i-1);
208
//                        }
209
                }
210
                recalculateColumnsFromAliases();
211

    
212
        }
213

    
214
        public void recalculateColumnsFromAliases()
215
        {
216
                columns.clear();
217
                for (int i = 0; i < alias.length; i++) {
218
                        addColumn(new Column());
219
                }
220

    
221
        }
222

    
223
        /**
224
         * DOCUMENT ME!
225
         *
226
         * @param sds
227
         *            DOCUMENT ME!
228
         * @throws DriverLoadException
229
         */
230
        public void setDataSource(IEditableSource es) throws DriverLoadException {
231
                setModel(es);
232

    
233
                setName(esModel.getRecordset().getName());
234
                setCreationDate(DateFormat.getInstance().format(new Date()));
235
                change.firePropertyChange("model", esModel, esModel);
236
        }
237

    
238
        /**
239
         * DOCUMENT ME!
240
         *
241
         * @param ds
242
         *            DOCUMENT ME!
243
         * @throws com.hardcode.gdbms.engine.data.driver.DriverException
244
         */
245
        public void replaceDataSource(IEditableSource es)
246
                        throws com.hardcode.gdbms.engine.data.driver.DriverException {
247
                if (original == null) {
248
                        original = esModel;
249
                }
250
                setModel(es);
251
                try {
252
                        ((SelectableDataSource) es.getRecordset())
253
                                        .setSelectionSupport(((SelectableDataSource) original
254
                                                        .getRecordset()).getSelectionSupport());
255

    
256
                        createAlias();
257
                } catch (DriverLoadException e1) {
258
                        throw new com.hardcode.gdbms.engine.data.driver.DriverException(e1);
259
                }
260
                // FJP:
261
                // Si la tabla proviene de un layer, cambiamos su recordset
262
                if (associatedTable != null) {
263
                        if (associatedTable instanceof FLyrVect) {
264
                                try {
265
                                        // ((EditableAdapter)((FLyrVect)
266
                                        // associatedTable).getSource()).setRecordSet((SelectableDataSource)es.getRecordset());
267
                                        FLyrVect lyrVect = (FLyrVect) associatedTable;
268
                                        lyrVect.setRecordset(es.getRecordset());
269
                                        ((FLyrVect) associatedTable).setIsJoined(true);
270
                                } catch (DriverLoadException e) {
271
                                        throw new com.hardcode.gdbms.engine.data.driver.DriverException(
272
                                                        e);
273
                                }
274
                        }
275
                }
276

    
277
                change.firePropertyChange("model", original, esModel);
278
        }
279

    
280
        /**
281
         * DOCUMENT ME!
282
         *
283
         * @throws com.hardcode.gdbms.engine.data.driver.DriverException
284
         * @throws DriverLoadException
285
         */
286
        public void restoreDataSource()
287
                        throws com.hardcode.gdbms.engine.data.driver.DriverException,
288
                        DriverLoadException {
289
                // FJP:
290
                // Si la tabla proviene de un layer, cambiamos su recordset
291
                if (associatedTable != null) {
292
                        if (associatedTable instanceof FLyrVect) {
293
                                // Miramos si la leyenda que est? usando es una
294
                                // leyenda basada en un campo de los de la uni?n.
295
                                // Si lo es, no dejamos pegarle el cambiazo al recordset
296
                                FLyrVect lyr = ((FLyrVect) associatedTable);
297
                                if (lyr.getLegend() instanceof ClassifiedLegend) {
298
                                        ClassifiedLegend legend = (ClassifiedLegend) lyr
299
                                                        .getLegend();
300
                                        VectorialLegend aux = (VectorialLegend) legend;
301
                                        String fieldName = legend.getFieldName();
302
                                        int idField = original.getRecordset().getFieldIndexByName(
303
                                                        fieldName);
304
                                        int idLabelField = -2;
305
                                        if (aux.getLabelField() != null) {
306
                                                idLabelField = original.getRecordset()
307
                                                                .getFieldIndexByName(aux.getLabelField());
308
                                        }
309
                                        if ((idField == -1) || (idLabelField == -1)) {
310
                                                // No se ha encontrado ese campo, o se est? etiquetando
311
                                                // por ese campo
312
                                                JOptionPane.showMessageDialog(null, PluginServices
313
                                                                .getText(this, "leyenda_campo_unido"));
314

    
315
                                                return;
316
                                        }
317
                                }
318

    
319
                                lyr.setRecordset((SelectableDataSource) original.getRecordset());
320

    
321
                                lyr.setIsJoined(false);
322
                        }
323
                }
324

    
325
                setModel(original);
326
                original = null;
327
                createAlias();
328

    
329
                change.firePropertyChange("model", original, esModel);
330
        }
331

    
332
        /**
333
         * DOCUMENT ME!
334
         *
335
         * @return DOCUMENT ME!
336
         * @throws SaveException
337
         *
338
         * @throws XMLException
339
         */
340
        public XMLEntity getXMLEntity() throws SaveException {
341
                XMLEntity xml = super.getXMLEntity();
342
                try {
343
                        // xml.putProperty("nameClass", this.getClass().getName());
344
                        xml.putProperty("numTables", numTables);
345

    
346
                        if (getLinkTable() != null) {
347
                                xml.putProperty("linkTable", linkTable);
348
                                xml.putProperty("field1", field1);
349
                                xml.putProperty("field2", field2);
350
                        }
351

    
352
                        if (getOriginal() != null) {
353
                                xml.addChild(getOriginal().getRecordset().getXMLEntity());
354
                        }
355
                        xml.addChild(esModel.getRecordset().getXMLEntity());
356

    
357
                        Object di = LayerFactory.getDataSourceFactory().getDriverInfo(
358
                                        esModel.getRecordset().getName());
359

    
360
                        if (associatedTable != null) {
361
                                xml.putProperty("layerName", ((FLayer) associatedTable)
362
                                                .getName());
363
                                xml.putProperty("viewName", project
364
                                                .getView((FLayer) associatedTable));
365
                        }
366

    
367
                        xml.putProperty("mapping", mapping);
368
                        xml.putProperty("aliases", alias);
369
                } catch (Exception e) {
370
                        throw new SaveException(e, this.getClass().getName());
371
                }
372

    
373
                xml.addChild(columns.getXMLEntity());
374
                xml.putProperty("columns", true);
375
                
376
                return xml;
377
        }
378

    
379
        /**
380
         * DOCUMENT ME!
381
         *
382
         * @param xml
383
         *            DOCUMENT ME!
384
         * @param p
385
         *            DOCUMENT ME!
386
         *
387
         * @throws XMLException
388
         * @throws DriverException
389
         *
390
         * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
391
         */
392
        public void setXMLEntity03(XMLEntity xml, Project p) throws XMLException,
393
                        DriverException {
394
                numTables = xml.getIntProperty("numTables");
395

    
396
                if (xml.getStringProperty("type").equals("otherDriverFile")) {
397
                        LayerFactory.getDataSourceFactory().addFileDataSource(
398
                                        xml.getStringProperty("driverName"),
399
                                        xml.getStringProperty("gdbmsname"),
400
                                        xml.getStringProperty("file"));
401

    
402
                        setSelectableDataSource03(xml);
403
                } else if (xml.getStringProperty("type").equals("sameDriverFile")) {
404
                        String layerName = xml.getStringProperty("layerName");
405

    
406
                        ProjectView vista = project.getViewByName(xml
407
                                        .getStringProperty("viewName"));
408
                        FLayer layer = vista.getMapContext().getLayers()
409
                                        .getLayer(layerName);
410

    
411
                        esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
412
                        associatedTable = (AlphanumericData) layer;
413

    
414
                        LayerFactory.getDataSourceFactory().addDataSource(
415
                                        (ObjectDriver) ((SingleLayer) layer).getSource()
416
                                                        .getDriver(), xml.getStringProperty("gdbmsname"));
417
                } else if (xml.getStringProperty("type").equals("db")) {
418
                        LayerFactory.getDataSourceFactory().addDBDataSourceByTable(
419
                                        xml.getStringProperty("gdbmsname"),
420
                                        xml.getStringProperty("host"), xml.getIntProperty("port"),
421
                                        xml.getStringProperty("user"),
422
                                        xml.getStringProperty("password"),
423
                                        xml.getStringProperty("dbName"),
424
                                        xml.getStringProperty("tableName"),
425
                                        xml.getStringProperty("driverInfo"));
426

    
427
                        setSelectableDataSource03(xml);
428
                }
429

    
430
                setName(xml.getStringProperty("name"));
431
        }
432

    
433
        /**
434
         * DOCUMENT ME!
435
         *
436
         * @param xml
437
         *            DOCUMENT ME!
438
         * @param p
439
         *            DOCUMENT ME!
440
         *
441
         * @throws XMLException
442
         * @throws DriverException
443
         * @throws OpenException
444
         *
445
         * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
446
         */
447
        public void setXMLEntity(XMLEntity xml, Project p) throws XMLException,
448
                        DriverException, OpenException {
449
                try {
450
                        setName(xml.getStringProperty("name"));
451
                        numTables = xml.getIntProperty("numTables");
452

    
453
                        setSelectableDataSource(xml);
454

    
455
                        /*
456
                         * if (xml.getStringProperty("type").equals("otherDriverFile")) { }
457
                         * else if (xml.getStringProperty("type").equals("sameDriverFile")) {
458
                         * String layerName = xml.getStringProperty("layerName");
459
                         * ProjectView vista = project.getViewByName(xml.getStringProperty(
460
                         * "viewName")); FLayer layer =
461
                         * vista.getMapContext().getLayers().getLayer(layerName);
462
                         *
463
                         * modelo = ((AlphanumericData) layer).getRecordset();
464
                         * associatedTable = (AlphanumericData) layer; } else if
465
                         * (xml.getStringProperty("type").equals("db")) {
466
                         * setSelectableDataSource(xml); }
467
                         */
468
                        setName(xml.getStringProperty("name"));
469

    
470
                        if (xml.contains("linkTable")) {
471
                                setLinkTable(xml.getStringProperty("linkTable"), xml
472
                                                .getStringProperty("field1"), xml
473
                                                .getStringProperty("field2"));
474
                        }
475

    
476
                        if (xml.contains("mapping")) {
477
                                mapping = (int[]) xml.getIntArrayProperty("mapping");
478
                                alias = (String[]) xml.getStringArrayProperty("aliases");
479
                                // we check if all fields are real there (may be some external program has changed them.
480
                                // If we detect any change, we discard all mapping and aliases.
481
                                if (mapping.length != getModelo().getRecordset().getFieldCount())
482
                                {
483
                                        createAlias();
484
//                                        columns.clear();
485
//                                        for (int i = 0; i < esModel.getRecordset().getFieldCount(); i++) {
486
//                                                addColumn(new Column());
487
//                                        }
488
                                        return;
489

    
490
                                }
491

    
492
                        } else {
493
                                try {
494
                                        createAlias();
495
                                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
496
                                        throw new XMLException(e);
497
                                }
498
                        }
499
                } catch (Exception e) {
500
                        throw new OpenException(e, this.getClass().getName());
501
                }
502

    
503
                if (xml.contains("columns")) {
504
                        columns.clear();
505
                        columns = Columns
506
                                        .createColumns(xml.getChild(xml.getChildrenCount() - 1));
507
                }
508
        }
509

    
510
        /**
511
         * DOCUMENT ME!
512
         *
513
         * @param xml
514
         *            DOCUMENT ME!
515
         *
516
         * @throws XMLException
517
         *             DOCUMENT ME!
518
         * @throws DriverException
519
         *             DOCUMENT ME!
520
         */
521
        private void setSelectableDataSource03(XMLEntity xml) throws XMLException,
522
                        DriverException {
523
                String layerName = null;
524

    
525
                if (xml.contains("layerName")) {
526
                        layerName = xml.getStringProperty("layerName");
527
                }
528

    
529
                if (layerName == null) {
530
                        DataSource dataSource;
531

    
532
                        try {
533
                                dataSource = LayerFactory.getDataSourceFactory()
534
                                                .createRandomDataSource(
535
                                                                xml.getStringProperty("gdbmsname"),
536
                                                                DataSourceFactory.AUTOMATIC_OPENING);
537

    
538
                                SelectableDataSource sds = new SelectableDataSource(dataSource);
539

    
540
                                sds.setXMLEntity03(xml.getChild(0));
541
                                EditableAdapter auxea = new EditableAdapter();
542
                                auxea.setOriginalDataSource(sds);
543
                                setDataSource(auxea);
544
                        } catch (NoSuchTableException e) {
545
                                throw new XMLException(e);
546
                        } catch (DriverLoadException e) {
547
                                throw new XMLException(e);
548
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
549
                                throw new XMLException(e);
550
                        }
551

    
552
                } else {
553
                        ProjectView vista = project.getViewByName(xml
554
                                        .getStringProperty("viewName"));
555
                        FLayer layer = vista.getMapContext().getLayers()
556
                                        .getLayer(layerName);
557

    
558
                        esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
559
                        associatedTable = (AlphanumericData) layer;
560
                }
561
        }
562

    
563
        /**
564
         * DOCUMENT ME!
565
         *
566
         * @param xml
567
         *            DOCUMENT ME!
568
         *
569
         * @throws XMLException
570
         *             DOCUMENT ME!
571
         * @throws DriverException
572
         *             DOCUMENT ME!
573
         */
574
        private void setSelectableDataSource(XMLEntity xml) throws XMLException,
575
                        DriverException {
576
                String layerName = null;
577
                boolean bNeedToReplace = false;
578
                XMLEntity xmlAux = null;
579

    
580
                try {
581
                        EditableAdapter es;
582

    
583
                        if (xml.contains("layerName")) {
584
                                layerName = xml.getStringProperty("layerName");
585

    
586
                                ProjectView vista = project.getViewByName(xml
587
                                                .getStringProperty("viewName"));
588
                                FLayer layer = getLayer(vista.getMapContext().getLayers(),
589
                                                layerName);
590
                                EditableAdapter ea = new EditableAdapter();
591
                                SelectableDataSource sds = ((FLyrVect) layer).getRecordset();
592
                                // sds.setSelectionSupport(((FLyrVect)
593
                                // layer).getSelectionSupport());
594
                                ea.setOriginalDataSource(sds);
595
                                associatedTable = (AlphanumericData) layer;
596

    
597
                                es = ea;
598
                        } else {
599
                                es = new EditableAdapter();
600
                                es.setOriginalDataSource(SelectableDataSource
601
                                                .createSelectableDataSource(xml.getChild(0)));
602
                        }
603

    
604
                        setDataSource(es);
605

    
606
                        if (xml.getChildrenCount() == 2 && !(xml.contains("columns"))
607
                                        || (xml.contains("columns") && (xml.getChildrenCount() == 3))) {
608
                                bNeedToReplace = true;
609
                                xmlAux = xml.getChild(1);
610
                                es = new EditableAdapter();
611
                                // es.setRecordSet(SelectableDataSource.createSelectableDataSource(xmlAux));
612

    
613
                                // replaceDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(1)));
614
                        }
615

    
616
                        if (bNeedToReplace) {
617
                                if (layerName != null) {
618
                                        ProjectView vista = project.getViewByName(xml
619
                                                        .getStringProperty("viewName"));
620
                                        FLayer layer = getLayer(vista.getMapContext().getLayers(),
621
                                                        layerName);
622

    
623
                                        // modelo = ((AlphanumericData) layer).getRecordset();
624
                                        associatedTable = (AlphanumericData) layer;
625
                                }
626

    
627
                                EditableAdapter auxea = new EditableAdapter();
628
                                auxea.setOriginalDataSource(SelectableDataSource
629
                                                .createSelectableDataSource(xmlAux));
630
                                replaceDataSource(auxea);
631
                        }
632
                } catch (DriverLoadException e) {
633
                        throw new DriverException(e);
634
                } catch (NoSuchTableException e) {
635
                        throw new DriverException(e);
636
                } catch (ParseException e) {
637
                        throw new DriverException(e);
638
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
639
                        throw new DriverException(e);
640
                } catch (SemanticException e) {
641
                        throw new DriverException(e);
642
                } catch (IOException e) {
643
                        throw new DriverException(e);
644
                } catch (XMLException e) {
645
                        throw new DriverException(e);
646
                }
647
        }
648

    
649
        private FLayer getLayer(FLayers layers, String name) {
650
                for (int i = 0; i < layers.getLayersCount(); i++) {
651
                        if (layers.getLayer(i) instanceof FLayers) {
652
                                return getLayer((FLayers) layers.getLayer(i), name);
653
                        } else if (layers.getLayer(i).getName().equals(name)) {
654
                                return layers.getLayer(i);
655
                        }
656
                }
657
                return null;
658
        }
659

    
660
        /**
661
         * DOCUMENT ME!
662
         *
663
         * @return DOCUMENT ME!
664
         */
665
        public AlphanumericData getAssociatedTable() {
666
                return associatedTable;
667
        }
668

    
669
        /**
670
         * DOCUMENT ME!
671
         *
672
         * @param associatedTable
673
         *            DOCUMENT ME!
674
         */
675
        public void setAssociatedTable(AlphanumericData associatedTable) {
676
                this.associatedTable = associatedTable;
677
        }
678

    
679
        /**
680
         * Obtiene la fuente de datos original de la tabla si se ha invocado
681
         * replaceDataSource. Si no se invoc? este m?todo o se invoc? posteriormente
682
         * restoreDataSource se devuelve null
683
         *
684
         * @return Returns the original.
685
         */
686
        public IEditableSource getOriginal() {
687
                return original;
688
        }
689

    
690
        /**
691
         * Devuelve el identificador de la tabla que contiene el link.
692
         *
693
         * @return identificador ?nico de la tabla.
694
         */
695
        public String getLinkTable() {
696
                return linkTable;
697
        }
698

    
699
        /**
700
         * Devuelve el nombre del campo de la tabla a enlazar.
701
         *
702
         * @return Nombre del campo de la tabla a enlazar.
703
         */
704
        public String getField1() {
705
                return field1;
706
        }
707

    
708
        /**
709
         * Devuelve el nombre del campo de la tabla enlazada.
710
         *
711
         * @return Nombre del campo de la tabla enlazada.
712
         */
713
        public String getField2() {
714
                return field2;
715
        }
716

    
717
        /**
718
         * Inserta el identificador de la tabla, el campo de la primera tabla y el
719
         * campo de la segunda tabla.
720
         *
721
         * @param lt
722
         *            identificado de la tabla.
723
         * @param f1
724
         *            nombre del campo de la primera tabla.
725
         * @param f2
726
         *            nombre del campo de la segunda tabla.
727
         */
728
        public void setLinkTable(String lt, String f1, String f2) {
729
                linkTable = lt;
730
                field1 = f1;
731
                field2 = f2;
732
        }
733

    
734
        /**
735
         * Borra el identificador de la tabla y elimina del array de listener los
736
         * listener que sean del tipo: LinkSelectionListenr
737
         */
738
        public void removeLinkTable() {
739
                linkTable = null;
740
                try {
741
                        ((SelectableDataSource) getModelo().getRecordset())
742
                                        .removeLinksSelectionListener();
743
                } catch (DriverLoadException e) {
744
                        e.printStackTrace();
745
                }
746
        }
747

    
748
        public String[] getAliases() {
749
                return alias;
750
        }
751

    
752
        public void setAliases(String[] alias) {
753
                this.alias = alias;
754
        }
755

    
756
        public int[] getMapping() {
757
                return mapping;
758
        }
759

    
760
        public void setMapping(int[] mapping) {
761
                this.mapping = mapping;
762
        }
763

    
764
        public void setModel(IEditableSource ies) {
765
                esModel = ies;
766
                try {
767
                        createAlias();
768
                } catch (DriverLoadException e) {
769
                        e.printStackTrace();
770
                        NotificationManager.addError(e);
771
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
772
                        e.printStackTrace();
773
                        NotificationManager.addError(e);
774
                }
775
        }
776

    
777
        public Column getColumn(int i) {
778
//                if (i==0){
779
//                        Column column=new Column();
780
//                        column.setWidth(45);
781
//                        return column;
782
//                }
783
//                i--;
784
                return (Column) columns.get(mapping[i]);
785
        }
786

    
787
        public void addColumn(Column column) {
788
                columns.add(column);
789
        }
790

    
791
        public int getColumnCount() {
792
                return columns.size();
793
        }
794

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