Statistics
| Revision:

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

History | View | Annotate | Download (21.3 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
        private void createAlias()
189
                        throws com.hardcode.gdbms.engine.data.driver.DriverException,
190
                        DriverLoadException {
191
                mapping = new int[esModel.getRecordset().getFieldCount()+1];
192
                alias = new String[esModel.getRecordset().getFieldCount()+1];
193
                for (int i = 0; i < esModel.getRecordset().getFieldCount()+1; i++) {
194
                        if (i==0){
195
                                mapping[i]=i;
196
                                alias[i]=" ";
197
                        }else{
198

    
199
                                mapping[i] = i;
200
                                alias[i] = esModel.getRecordset().getFieldName(i-1);
201
                        }
202
                }
203
        }
204

    
205
        /**
206
         * DOCUMENT ME!
207
         *
208
         * @param sds
209
         *            DOCUMENT ME!
210
         * @throws DriverLoadException
211
         */
212
        public void setDataSource(IEditableSource es) throws DriverLoadException {
213
                setModel(es);
214

    
215
                setName(esModel.getRecordset().getName());
216
                setCreationDate(DateFormat.getInstance().format(new Date()));
217
                change.firePropertyChange("model", esModel, esModel);
218
        }
219

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

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

    
259
                change.firePropertyChange("model", original, esModel);
260
        }
261

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

    
297
                                                return;
298
                                        }
299
                                }
300

    
301
                                lyr.setRecordset((SelectableDataSource) original.getRecordset());
302

    
303
                                lyr.setIsJoined(false);
304
                        }
305
                }
306

    
307
                setModel(original);
308
                original = null;
309
                createAlias();
310

    
311
                change.firePropertyChange("model", original, esModel);
312
        }
313

    
314
        /**
315
         * DOCUMENT ME!
316
         *
317
         * @return DOCUMENT ME!
318
         * @throws SaveException
319
         *
320
         * @throws XMLException
321
         */
322
        public XMLEntity getXMLEntity() throws SaveException {
323
                XMLEntity xml = super.getXMLEntity();
324
                try {
325
                        // xml.putProperty("nameClass", this.getClass().getName());
326
                        xml.putProperty("numTables", numTables);
327

    
328
                        if (getLinkTable() != null) {
329
                                xml.putProperty("linkTable", linkTable);
330
                                xml.putProperty("field1", field1);
331
                                xml.putProperty("field2", field2);
332
                        }
333

    
334
                        if (getOriginal() != null) {
335
                                xml.addChild(getOriginal().getRecordset().getXMLEntity());
336
                        }
337
                        xml.addChild(esModel.getRecordset().getXMLEntity());
338

    
339
                        Object di = LayerFactory.getDataSourceFactory().getDriverInfo(
340
                                        esModel.getRecordset().getName());
341

    
342
                        if (associatedTable != null) {
343
                                xml.putProperty("layerName", ((FLayer) associatedTable)
344
                                                .getName());
345
                                xml.putProperty("viewName", project
346
                                                .getView((FLayer) associatedTable));
347
                        }
348

    
349
                        xml.putProperty("mapping", mapping);
350
                        xml.putProperty("aliases", alias);
351
                } catch (Exception e) {
352
                        throw new SaveException(e, this.getClass().getName());
353
                }
354

    
355
                // for (int i=0;i<columns.size();i++){
356
                // Column column=(Column)columns.get(i);
357
                // xml.addChild(column.getXMLEntity());
358
                // }
359
                xml.addChild(columns.getXMLEntity());
360
                xml.putProperty("columns", true);
361
                return xml;
362
        }
363

    
364
        /**
365
         * DOCUMENT ME!
366
         *
367
         * @param xml
368
         *            DOCUMENT ME!
369
         * @param p
370
         *            DOCUMENT ME!
371
         *
372
         * @throws XMLException
373
         * @throws DriverException
374
         *
375
         * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
376
         */
377
        public void setXMLEntity03(XMLEntity xml, Project p) throws XMLException,
378
                        DriverException {
379
                numTables = xml.getIntProperty("numTables");
380

    
381
                if (xml.getStringProperty("type").equals("otherDriverFile")) {
382
                        LayerFactory.getDataSourceFactory().addFileDataSource(
383
                                        xml.getStringProperty("driverName"),
384
                                        xml.getStringProperty("gdbmsname"),
385
                                        xml.getStringProperty("file"));
386

    
387
                        setSelectableDataSource03(xml);
388
                } else if (xml.getStringProperty("type").equals("sameDriverFile")) {
389
                        String layerName = xml.getStringProperty("layerName");
390

    
391
                        ProjectView vista = project.getViewByName(xml
392
                                        .getStringProperty("viewName"));
393
                        FLayer layer = vista.getMapContext().getLayers()
394
                                        .getLayer(layerName);
395

    
396
                        esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
397
                        associatedTable = (AlphanumericData) layer;
398

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

    
412
                        setSelectableDataSource03(xml);
413
                }
414

    
415
                setName(xml.getStringProperty("name"));
416
        }
417

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

    
438
                        setSelectableDataSource(xml);
439

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

    
455
                        if (xml.contains("linkTable")) {
456
                                setLinkTable(xml.getStringProperty("linkTable"), xml
457
                                                .getStringProperty("field1"), xml
458
                                                .getStringProperty("field2"));
459
                        }
460

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

    
475
                                }
476
                                
477
                        } else {
478
                                try {
479
                                        createAlias();
480
                                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
481
                                        throw new XMLException(e);
482
                                }
483
                        }
484
                } catch (Exception e) {
485
                        throw new OpenException(e, this.getClass().getName());
486
                }
487
                columns.clear();
488
                // for (int i=1;i<xml.getNumChild();i++){
489
                // columns.add(Column.createColumn(xml.getChild(i)));
490
                // }
491
                if (xml.contains("columns")) {
492
                        columns = Columns
493
                                        .createColumns(xml.getChild(xml.getNumChild() - 1));
494
                }
495
                
496

    
497
        }
498

    
499
        /**
500
         * DOCUMENT ME!
501
         *
502
         * @param xml
503
         *            DOCUMENT ME!
504
         *
505
         * @throws XMLException
506
         *             DOCUMENT ME!
507
         * @throws DriverException
508
         *             DOCUMENT ME!
509
         */
510
        private void setSelectableDataSource03(XMLEntity xml) throws XMLException,
511
                        DriverException {
512
                String layerName = null;
513

    
514
                if (xml.contains("layerName")) {
515
                        layerName = xml.getStringProperty("layerName");
516
                }
517

    
518
                if (layerName == null) {
519
                        DataSource dataSource;
520

    
521
                        try {
522
                                dataSource = LayerFactory.getDataSourceFactory()
523
                                                .createRandomDataSource(
524
                                                                xml.getStringProperty("gdbmsname"),
525
                                                                DataSourceFactory.AUTOMATIC_OPENING);
526

    
527
                                SelectableDataSource sds = new SelectableDataSource(dataSource);
528

    
529
                                sds.setXMLEntity03(xml.getChild(0));
530
                                EditableAdapter auxea = new EditableAdapter();
531
                                auxea.setOriginalDataSource(sds);
532
                                setDataSource(auxea);
533
                        } catch (NoSuchTableException e) {
534
                                throw new XMLException(e);
535
                        } catch (DriverLoadException e) {
536
                                throw new XMLException(e);
537
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
538
                                throw new XMLException(e);
539
                        }
540

    
541
                } else {
542
                        ProjectView vista = project.getViewByName(xml
543
                                        .getStringProperty("viewName"));
544
                        FLayer layer = vista.getMapContext().getLayers()
545
                                        .getLayer(layerName);
546

    
547
                        esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
548
                        associatedTable = (AlphanumericData) layer;
549
                }
550
        }
551

    
552
        /**
553
         * DOCUMENT ME!
554
         *
555
         * @param xml
556
         *            DOCUMENT ME!
557
         *
558
         * @throws XMLException
559
         *             DOCUMENT ME!
560
         * @throws DriverException
561
         *             DOCUMENT ME!
562
         */
563
        private void setSelectableDataSource(XMLEntity xml) throws XMLException,
564
                        DriverException {
565
                String layerName = null;
566
                boolean bNeedToReplace = false;
567
                XMLEntity xmlAux = null;
568

    
569
                try {
570
                        EditableAdapter es;
571

    
572
                        if (xml.contains("layerName")) {
573
                                layerName = xml.getStringProperty("layerName");
574

    
575
                                ProjectView vista = project.getViewByName(xml
576
                                                .getStringProperty("viewName"));
577
                                FLayer layer = getLayer(vista.getMapContext().getLayers(),
578
                                                layerName);
579
                                EditableAdapter ea = new EditableAdapter();
580
                                SelectableDataSource sds = ((FLyrVect) layer).getRecordset();
581
                                // sds.setSelectionSupport(((FLyrVect)
582
                                // layer).getSelectionSupport());
583
                                ea.setOriginalDataSource(sds);
584

    
585
                                es = ea;
586
                        } else {
587
                                es = new EditableAdapter();
588
                                es.setOriginalDataSource(SelectableDataSource
589
                                                .createSelectableDataSource(xml.getChild(0)));
590
                        }
591

    
592
                        setDataSource(es);
593

    
594
                        if (xml.getNumChild() == 2 && !(xml.contains("columns"))
595
                                        || (xml.contains("columns") && (xml.getNumChild() == 3))) {
596
                                bNeedToReplace = true;
597
                                xmlAux = xml.getChild(1);
598
                                es = new EditableAdapter();
599
                                // es.setRecordSet(SelectableDataSource.createSelectableDataSource(xmlAux));
600

    
601
                                // replaceDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(1)));
602
                        }
603

    
604
                        if (bNeedToReplace) {
605
                                if (layerName != null) {
606
                                        ProjectView vista = project.getViewByName(xml
607
                                                        .getStringProperty("viewName"));
608
                                        FLayer layer = getLayer(vista.getMapContext().getLayers(),
609
                                                        layerName);
610

    
611
                                        // modelo = ((AlphanumericData) layer).getRecordset();
612
                                        associatedTable = (AlphanumericData) layer;
613
                                }
614

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

    
637
        private FLayer getLayer(FLayers layers, String name) {
638
                for (int i = 0; i < layers.getLayersCount(); i++) {
639
                        if (layers.getLayer(i) instanceof FLayers) {
640
                                return getLayer((FLayers) layers.getLayer(i), name);
641
                        } else if (layers.getLayer(i).getName().equals(name)) {
642
                                return layers.getLayer(i);
643
                        }
644
                }
645
                return null;
646
        }
647

    
648
        /**
649
         * DOCUMENT ME!
650
         *
651
         * @return DOCUMENT ME!
652
         */
653
        public AlphanumericData getAssociatedTable() {
654
                return associatedTable;
655
        }
656

    
657
        /**
658
         * DOCUMENT ME!
659
         *
660
         * @param associatedTable
661
         *            DOCUMENT ME!
662
         */
663
        public void setAssociatedTable(AlphanumericData associatedTable) {
664
                this.associatedTable = associatedTable;
665
        }
666

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

    
678
        /**
679
         * Devuelve el identificador de la tabla que contiene el link.
680
         *
681
         * @return identificador ?nico de la tabla.
682
         */
683
        public String getLinkTable() {
684
                return linkTable;
685
        }
686

    
687
        /**
688
         * Devuelve el nombre del campo de la tabla a enlazar.
689
         *
690
         * @return Nombre del campo de la tabla a enlazar.
691
         */
692
        public String getField1() {
693
                return field1;
694
        }
695

    
696
        /**
697
         * Devuelve el nombre del campo de la tabla enlazada.
698
         *
699
         * @return Nombre del campo de la tabla enlazada.
700
         */
701
        public String getField2() {
702
                return field2;
703
        }
704

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

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

    
736
        public String[] getAliases() {
737
                return alias;
738
        }
739

    
740
        public void setAliases(String[] alias) {
741
                this.alias = alias;
742
        }
743

    
744
        public int[] getMapping() {
745
                return mapping;
746
        }
747

    
748
        public void setMapping(int[] mapping) {
749
                this.mapping = mapping;
750
        }
751

    
752
        public void setModel(IEditableSource ies) {
753
                esModel = ies;
754
                SelectableDataSource sds = esModel.getRecordset();
755
//                if (columns.size() == 0) {
756
                        columns.clear();
757
                        try {
758
                                createAlias();                        
759
                                for (int i = 0; i < sds.getFieldCount(); i++) {
760
                                        addColumn(new Column());
761
                                }
762
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
763
                                e.printStackTrace();
764
                                NotificationManager.addError(e);
765
                        }                        
766
//                }
767
        }
768

    
769
        public Column getColumn(int i) {
770
                if (i==0){
771
                        Column column=new Column();
772
                        column.setWidth(45);
773
                        return column;
774
                }
775
                i--;
776
                return (Column) columns.get(mapping[i]);
777
        }
778

    
779
        public void addColumn(Column column) {
780
                columns.add(column);
781
        }
782

    
783
        public int getColumnCount() {
784
                return columns.size()+1;
785
        }
786
}