Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectTable.java @ 6356

History | View | Annotate | Download (21.5 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.ArrayList;
46
import java.util.Date;
47

    
48
import javax.swing.JOptionPane;
49

    
50
import com.hardcode.driverManager.DriverLoadException;
51
import com.hardcode.gdbms.engine.data.DataSource;
52
import com.hardcode.gdbms.engine.data.DataSourceFactory;
53
import com.hardcode.gdbms.engine.data.NoSuchTableException;
54
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
55
import com.hardcode.gdbms.engine.instruction.SemanticException;
56
import com.hardcode.gdbms.parser.ParseException;
57
import com.iver.andami.PluginServices;
58
import com.iver.andami.messages.NotificationManager;
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
                // for (int i=0;i<columns.size();i++){
374
                // Column column=(Column)columns.get(i);
375
                // xml.addChild(column.getXMLEntity());
376
                // }
377
                xml.addChild(columns.getXMLEntity());
378
                xml.putProperty("columns", true);
379
                return xml;
380
        }
381

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

    
399
                if (xml.getStringProperty("type").equals("otherDriverFile")) {
400
                        LayerFactory.getDataSourceFactory().addFileDataSource(
401
                                        xml.getStringProperty("driverName"),
402
                                        xml.getStringProperty("gdbmsname"),
403
                                        xml.getStringProperty("file"));
404

    
405
                        setSelectableDataSource03(xml);
406
                } else if (xml.getStringProperty("type").equals("sameDriverFile")) {
407
                        String layerName = xml.getStringProperty("layerName");
408

    
409
                        ProjectView vista = project.getViewByName(xml
410
                                        .getStringProperty("viewName"));
411
                        FLayer layer = vista.getMapContext().getLayers()
412
                                        .getLayer(layerName);
413

    
414
                        esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
415
                        associatedTable = (AlphanumericData) layer;
416

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

    
430
                        setSelectableDataSource03(xml);
431
                }
432

    
433
                setName(xml.getStringProperty("name"));
434
        }
435

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

    
456
                        setSelectableDataSource(xml);
457

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

    
473
                        if (xml.contains("linkTable")) {
474
                                setLinkTable(xml.getStringProperty("linkTable"), xml
475
                                                .getStringProperty("field1"), xml
476
                                                .getStringProperty("field2"));
477
                        }
478

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

    
493
                                }
494
                                
495
                        } else {
496
                                try {
497
                                        createAlias();
498
                                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
499
                                        throw new XMLException(e);
500
                                }
501
                        }
502
                } catch (Exception e) {
503
                        throw new OpenException(e, this.getClass().getName());
504
                }
505
                
506
                // for (int i=1;i<xml.getNumChild();i++){
507
                // columns.add(Column.createColumn(xml.getChild(i)));
508
                // }
509
                if (xml.contains("columns")) {
510
                        columns.clear();
511
                        columns = Columns
512
                                        .createColumns(xml.getChild(xml.getNumChild() - 1));
513
                }
514
                
515

    
516
        }
517

    
518
        /**
519
         * DOCUMENT ME!
520
         *
521
         * @param xml
522
         *            DOCUMENT ME!
523
         *
524
         * @throws XMLException
525
         *             DOCUMENT ME!
526
         * @throws DriverException
527
         *             DOCUMENT ME!
528
         */
529
        private void setSelectableDataSource03(XMLEntity xml) throws XMLException,
530
                        DriverException {
531
                String layerName = null;
532

    
533
                if (xml.contains("layerName")) {
534
                        layerName = xml.getStringProperty("layerName");
535
                }
536

    
537
                if (layerName == null) {
538
                        DataSource dataSource;
539

    
540
                        try {
541
                                dataSource = LayerFactory.getDataSourceFactory()
542
                                                .createRandomDataSource(
543
                                                                xml.getStringProperty("gdbmsname"),
544
                                                                DataSourceFactory.AUTOMATIC_OPENING);
545

    
546
                                SelectableDataSource sds = new SelectableDataSource(dataSource);
547

    
548
                                sds.setXMLEntity03(xml.getChild(0));
549
                                EditableAdapter auxea = new EditableAdapter();
550
                                auxea.setOriginalDataSource(sds);
551
                                setDataSource(auxea);
552
                        } catch (NoSuchTableException e) {
553
                                throw new XMLException(e);
554
                        } catch (DriverLoadException e) {
555
                                throw new XMLException(e);
556
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
557
                                throw new XMLException(e);
558
                        }
559

    
560
                } else {
561
                        ProjectView vista = project.getViewByName(xml
562
                                        .getStringProperty("viewName"));
563
                        FLayer layer = vista.getMapContext().getLayers()
564
                                        .getLayer(layerName);
565

    
566
                        esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
567
                        associatedTable = (AlphanumericData) layer;
568
                }
569
        }
570

    
571
        /**
572
         * DOCUMENT ME!
573
         *
574
         * @param xml
575
         *            DOCUMENT ME!
576
         *
577
         * @throws XMLException
578
         *             DOCUMENT ME!
579
         * @throws DriverException
580
         *             DOCUMENT ME!
581
         */
582
        private void setSelectableDataSource(XMLEntity xml) throws XMLException,
583
                        DriverException {
584
                String layerName = null;
585
                boolean bNeedToReplace = false;
586
                XMLEntity xmlAux = null;
587

    
588
                try {
589
                        EditableAdapter es;
590

    
591
                        if (xml.contains("layerName")) {
592
                                layerName = xml.getStringProperty("layerName");
593

    
594
                                ProjectView vista = project.getViewByName(xml
595
                                                .getStringProperty("viewName"));
596
                                FLayer layer = getLayer(vista.getMapContext().getLayers(),
597
                                                layerName);
598
                                EditableAdapter ea = new EditableAdapter();
599
                                SelectableDataSource sds = ((FLyrVect) layer).getRecordset();
600
                                // sds.setSelectionSupport(((FLyrVect)
601
                                // layer).getSelectionSupport());
602
                                ea.setOriginalDataSource(sds);
603

    
604
                                es = ea;
605
                        } else {
606
                                es = new EditableAdapter();
607
                                es.setOriginalDataSource(SelectableDataSource
608
                                                .createSelectableDataSource(xml.getChild(0)));
609
                        }
610

    
611
                        setDataSource(es);
612

    
613
                        if (xml.getNumChild() == 2 && !(xml.contains("columns"))
614
                                        || (xml.contains("columns") && (xml.getNumChild() == 3))) {
615
                                bNeedToReplace = true;
616
                                xmlAux = xml.getChild(1);
617
                                es = new EditableAdapter();
618
                                // es.setRecordSet(SelectableDataSource.createSelectableDataSource(xmlAux));
619

    
620
                                // replaceDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(1)));
621
                        }
622

    
623
                        if (bNeedToReplace) {
624
                                if (layerName != null) {
625
                                        ProjectView vista = project.getViewByName(xml
626
                                                        .getStringProperty("viewName"));
627
                                        FLayer layer = getLayer(vista.getMapContext().getLayers(),
628
                                                        layerName);
629

    
630
                                        // modelo = ((AlphanumericData) layer).getRecordset();
631
                                        associatedTable = (AlphanumericData) layer;
632
                                }
633

    
634
                                EditableAdapter auxea = new EditableAdapter();
635
                                auxea.setOriginalDataSource(SelectableDataSource
636
                                                .createSelectableDataSource(xmlAux));
637
                                replaceDataSource(auxea);
638
                        }
639
                } catch (DriverLoadException e) {
640
                        throw new DriverException(e);
641
                } catch (NoSuchTableException e) {
642
                        throw new DriverException(e);
643
                } catch (ParseException e) {
644
                        throw new DriverException(e);
645
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
646
                        throw new DriverException(e);
647
                } catch (SemanticException e) {
648
                        throw new DriverException(e);
649
                } catch (IOException e) {
650
                        throw new DriverException(e);
651
                } catch (XMLException e) {
652
                        throw new DriverException(e);
653
                }
654
        }
655

    
656
        private FLayer getLayer(FLayers layers, String name) {
657
                for (int i = 0; i < layers.getLayersCount(); i++) {
658
                        if (layers.getLayer(i) instanceof FLayers) {
659
                                return getLayer((FLayers) layers.getLayer(i), name);
660
                        } else if (layers.getLayer(i).getName().equals(name)) {
661
                                return layers.getLayer(i);
662
                        }
663
                }
664
                return null;
665
        }
666

    
667
        /**
668
         * DOCUMENT ME!
669
         *
670
         * @return DOCUMENT ME!
671
         */
672
        public AlphanumericData getAssociatedTable() {
673
                return associatedTable;
674
        }
675

    
676
        /**
677
         * DOCUMENT ME!
678
         *
679
         * @param associatedTable
680
         *            DOCUMENT ME!
681
         */
682
        public void setAssociatedTable(AlphanumericData associatedTable) {
683
                this.associatedTable = associatedTable;
684
        }
685

    
686
        /**
687
         * Obtiene la fuente de datos original de la tabla si se ha invocado
688
         * replaceDataSource. Si no se invoc? este m?todo o se invoc? posteriormente
689
         * restoreDataSource se devuelve null
690
         *
691
         * @return Returns the original.
692
         */
693
        public IEditableSource getOriginal() {
694
                return original;
695
        }
696

    
697
        /**
698
         * Devuelve el identificador de la tabla que contiene el link.
699
         *
700
         * @return identificador ?nico de la tabla.
701
         */
702
        public String getLinkTable() {
703
                return linkTable;
704
        }
705

    
706
        /**
707
         * Devuelve el nombre del campo de la tabla a enlazar.
708
         *
709
         * @return Nombre del campo de la tabla a enlazar.
710
         */
711
        public String getField1() {
712
                return field1;
713
        }
714

    
715
        /**
716
         * Devuelve el nombre del campo de la tabla enlazada.
717
         *
718
         * @return Nombre del campo de la tabla enlazada.
719
         */
720
        public String getField2() {
721
                return field2;
722
        }
723

    
724
        /**
725
         * Inserta el identificador de la tabla, el campo de la primera tabla y el
726
         * campo de la segunda tabla.
727
         *
728
         * @param lt
729
         *            identificado de la tabla.
730
         * @param f1
731
         *            nombre del campo de la primera tabla.
732
         * @param f2
733
         *            nombre del campo de la segunda tabla.
734
         */
735
        public void setLinkTable(String lt, String f1, String f2) {
736
                linkTable = lt;
737
                field1 = f1;
738
                field2 = f2;
739
        }
740

    
741
        /**
742
         * Borra el identificador de la tabla y elimina del array de listener los
743
         * listener que sean del tipo: LinkSelectionListenr
744
         */
745
        public void removeLinkTable() {
746
                linkTable = null;
747
                try {
748
                        ((SelectableDataSource) getModelo().getRecordset())
749
                                        .removeLinksSelectionListener();
750
                } catch (DriverLoadException e) {
751
                        e.printStackTrace();
752
                }
753
        }
754

    
755
        public String[] getAliases() {
756
                return alias;
757
        }
758

    
759
        public void setAliases(String[] alias) {
760
                this.alias = alias;
761
        }
762

    
763
        public int[] getMapping() {
764
                return mapping;
765
        }
766

    
767
        public void setMapping(int[] mapping) {
768
                this.mapping = mapping;
769
        }
770

    
771
        public void setModel(IEditableSource ies) {
772
                esModel = ies;
773
                try {
774
                        createAlias();
775
                } catch (DriverLoadException e) {
776
                        e.printStackTrace();
777
                        NotificationManager.addError(e);
778
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
779
                        e.printStackTrace();
780
                        NotificationManager.addError(e);
781
                }
782
        }
783

    
784
        public Column getColumn(int i) {
785
//                if (i==0){
786
//                        Column column=new Column();
787
//                        column.setWidth(45);
788
//                        return column;
789
//                }
790
//                i--;
791
                return (Column) columns.get(mapping[i]);
792
        }
793

    
794
        public void addColumn(Column column) {
795
                columns.add(column);
796
        }
797

    
798
        public int getColumnCount() {
799
                return columns.size();
800
        }
801
}