Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectTable.java @ 5152

History | View | Annotate | Download (20.7 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.cit.gvsig.fmap.DriverException;
59
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
60
import com.iver.cit.gvsig.fmap.edition.EditionException;
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()];
192
                alias = new String[esModel.getRecordset().getFieldCount()];
193
                for (int i = 0; i < esModel.getRecordset().getFieldCount(); i++) {
194
                        mapping[i] = i;
195
                        alias[i] = esModel.getRecordset().getFieldName(i);
196
                }
197
        }
198

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

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

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

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

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

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

    
291
                                                return;
292
                                        }
293
                                }
294

    
295
                                lyr.setRecordset((SelectableDataSource) original.getRecordset());
296

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

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

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

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

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

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

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

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

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

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

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

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

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

    
385
                        ProjectView vista = project.getViewByName(xml
386
                                        .getStringProperty("viewName"));
387
                        FLayer layer = vista.getMapContext().getLayers()
388
                                        .getLayer(layerName);
389

    
390
                        esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
391
                        associatedTable = (AlphanumericData) layer;
392

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

    
406
                        setSelectableDataSource03(xml);
407
                }
408

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

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

    
432
                        setSelectableDataSource(xml);
433

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

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

    
455
                        if (xml.contains("mapping")) {
456
                                mapping = (int[]) xml.getIntArrayProperty("mapping");
457
                                alias = (String[]) xml.getStringArrayProperty("aliases");
458
                        } else {
459
                                try {
460
                                        createAlias();
461
                                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
462
                                        throw new XMLException(e);
463
                                }
464
                        }
465
                } catch (Exception e) {
466
                        throw new OpenException(e, this.getClass().getName());
467
                }
468
                columns.clear();
469
                // for (int i=1;i<xml.getNumChild();i++){
470
                // columns.add(Column.createColumn(xml.getChild(i)));
471
                // }
472
                if (xml.contains("columns")) {
473
                        columns = Columns
474
                                        .createColumns(xml.getChild(xml.getNumChild() - 1));
475
                }
476

    
477
        }
478

    
479
        /**
480
         * DOCUMENT ME!
481
         * 
482
         * @param xml
483
         *            DOCUMENT ME!
484
         * 
485
         * @throws XMLException
486
         *             DOCUMENT ME!
487
         * @throws DriverException
488
         *             DOCUMENT ME!
489
         */
490
        private void setSelectableDataSource03(XMLEntity xml) throws XMLException,
491
                        DriverException {
492
                String layerName = null;
493

    
494
                if (xml.contains("layerName")) {
495
                        layerName = xml.getStringProperty("layerName");
496
                }
497

    
498
                if (layerName == null) {
499
                        DataSource dataSource;
500

    
501
                        try {
502
                                dataSource = LayerFactory.getDataSourceFactory()
503
                                                .createRandomDataSource(
504
                                                                xml.getStringProperty("gdbmsname"),
505
                                                                DataSourceFactory.AUTOMATIC_OPENING);
506

    
507
                                SelectableDataSource sds = new SelectableDataSource(dataSource);
508

    
509
                                sds.setXMLEntity03(xml.getChild(0));
510
                                EditableAdapter auxea = new EditableAdapter();
511
                                auxea.setOriginalDataSource(sds);
512
                                setDataSource(auxea);
513
                        } catch (NoSuchTableException e) {
514
                                throw new XMLException(e);
515
                        } catch (DriverLoadException e) {
516
                                throw new XMLException(e);
517
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
518
                                throw new XMLException(e);
519
                        }
520

    
521
                } else {
522
                        ProjectView vista = project.getViewByName(xml
523
                                        .getStringProperty("viewName"));
524
                        FLayer layer = vista.getMapContext().getLayers()
525
                                        .getLayer(layerName);
526

    
527
                        esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
528
                        associatedTable = (AlphanumericData) layer;
529
                }
530
        }
531

    
532
        /**
533
         * DOCUMENT ME!
534
         * 
535
         * @param xml
536
         *            DOCUMENT ME!
537
         * 
538
         * @throws XMLException
539
         *             DOCUMENT ME!
540
         * @throws DriverException
541
         *             DOCUMENT ME!
542
         */
543
        private void setSelectableDataSource(XMLEntity xml) throws XMLException,
544
                        DriverException {
545
                String layerName = null;
546
                boolean bNeedToReplace = false;
547
                XMLEntity xmlAux = null;
548

    
549
                try {
550
                        EditableAdapter es;
551

    
552
                        if (xml.contains("layerName")) {
553
                                layerName = xml.getStringProperty("layerName");
554

    
555
                                ProjectView vista = project.getViewByName(xml
556
                                                .getStringProperty("viewName"));
557
                                FLayer layer = getLayer(vista.getMapContext().getLayers(),
558
                                                layerName);
559
                                EditableAdapter ea = new EditableAdapter();
560
                                SelectableDataSource sds = ((FLyrVect) layer).getRecordset();
561
                                // sds.setSelectionSupport(((FLyrVect)
562
                                // layer).getSelectionSupport());
563
                                ea.setOriginalDataSource(sds);
564

    
565
                                es = ea;
566
                        } else {
567
                                es = new EditableAdapter();
568
                                es.setOriginalDataSource(SelectableDataSource
569
                                                .createSelectableDataSource(xml.getChild(0)));
570
                        }
571

    
572
                        setDataSource(es);
573

    
574
                        if (xml.getNumChild() == 2 && !(xml.contains("columns"))
575
                                        || (xml.contains("columns") && (xml.getNumChild() == 3))) {
576
                                bNeedToReplace = true;
577
                                xmlAux = xml.getChild(1);
578
                                es = new EditableAdapter();
579
                                // es.setRecordSet(SelectableDataSource.createSelectableDataSource(xmlAux));
580

    
581
                                // replaceDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(1)));
582
                        }
583

    
584
                        if (bNeedToReplace) {
585
                                if (layerName != null) {
586
                                        ProjectView vista = project.getViewByName(xml
587
                                                        .getStringProperty("viewName"));
588
                                        FLayer layer = getLayer(vista.getMapContext().getLayers(),
589
                                                        layerName);
590

    
591
                                        // modelo = ((AlphanumericData) layer).getRecordset();
592
                                        associatedTable = (AlphanumericData) layer;
593
                                }
594

    
595
                                EditableAdapter auxea = new EditableAdapter();
596
                                auxea.setOriginalDataSource(SelectableDataSource
597
                                                .createSelectableDataSource(xmlAux));
598
                                replaceDataSource(auxea);
599
                        }
600
                } catch (DriverLoadException e) {
601
                        throw new DriverException(e);
602
                } catch (NoSuchTableException e) {
603
                        throw new DriverException(e);
604
                } catch (ParseException e) {
605
                        throw new DriverException(e);
606
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
607
                        throw new DriverException(e);
608
                } catch (SemanticException e) {
609
                        throw new DriverException(e);
610
                } catch (IOException e) {
611
                        throw new DriverException(e);
612
                } catch (XMLException e) {
613
                        throw new DriverException(e);
614
                }
615
        }
616

    
617
        private FLayer getLayer(FLayers layers, String name) {
618
                for (int i = 0; i < layers.getLayersCount(); i++) {
619
                        if (layers.getLayer(i) instanceof FLayers) {
620
                                return getLayer((FLayers) layers.getLayer(i), name);
621
                        } else if (layers.getLayer(i).getName().equals(name)) {
622
                                return layers.getLayer(i);
623
                        }
624
                }
625
                return null;
626
        }
627

    
628
        /**
629
         * DOCUMENT ME!
630
         * 
631
         * @return DOCUMENT ME!
632
         */
633
        public AlphanumericData getAssociatedTable() {
634
                return associatedTable;
635
        }
636

    
637
        /**
638
         * DOCUMENT ME!
639
         * 
640
         * @param associatedTable
641
         *            DOCUMENT ME!
642
         */
643
        public void setAssociatedTable(AlphanumericData associatedTable) {
644
                this.associatedTable = associatedTable;
645
        }
646

    
647
        /**
648
         * Obtiene la fuente de datos original de la tabla si se ha invocado
649
         * replaceDataSource. Si no se invoc? este m?todo o se invoc? posteriormente
650
         * restoreDataSource se devuelve null
651
         * 
652
         * @return Returns the original.
653
         */
654
        public IEditableSource getOriginal() {
655
                return original;
656
        }
657

    
658
        /**
659
         * Devuelve el identificador de la tabla que contiene el link.
660
         * 
661
         * @return identificador ?nico de la tabla.
662
         */
663
        public String getLinkTable() {
664
                return linkTable;
665
        }
666

    
667
        /**
668
         * Devuelve el nombre del campo de la tabla a enlazar.
669
         * 
670
         * @return Nombre del campo de la tabla a enlazar.
671
         */
672
        public String getField1() {
673
                return field1;
674
        }
675

    
676
        /**
677
         * Devuelve el nombre del campo de la tabla enlazada.
678
         * 
679
         * @return Nombre del campo de la tabla enlazada.
680
         */
681
        public String getField2() {
682
                return field2;
683
        }
684

    
685
        /**
686
         * Inserta el identificador de la tabla, el campo de la primera tabla y el
687
         * campo de la segunda tabla.
688
         * 
689
         * @param lt
690
         *            identificado de la tabla.
691
         * @param f1
692
         *            nombre del campo de la primera tabla.
693
         * @param f2
694
         *            nombre del campo de la segunda tabla.
695
         */
696
        public void setLinkTable(String lt, String f1, String f2) {
697
                linkTable = lt;
698
                field1 = f1;
699
                field2 = f2;
700
        }
701

    
702
        /**
703
         * Borra el identificador de la tabla y elimina del array de listener los
704
         * listener que sean del tipo: LinkSelectionListenr
705
         */
706
        public void removeLinkTable() {
707
                linkTable = null;
708
                try {
709
                        ((SelectableDataSource) getModelo().getRecordset())
710
                                        .removeLinksSelectionListener();
711
                } catch (DriverLoadException e) {
712
                        e.printStackTrace();
713
                }
714
        }
715

    
716
        public String[] getAliases() {
717
                return alias;
718
        }
719

    
720
        public void setAliases(String[] alias) {
721
                this.alias = alias;
722
        }
723

    
724
        public int[] getMapping() {
725
                return mapping;
726
        }
727

    
728
        public void setMapping(int[] mapping) {
729
                this.mapping = mapping;
730
        }
731

    
732
        public void setModel(IEditableSource ies) {
733
                esModel = ies;
734
                SelectableDataSource sds = esModel.getRecordset();
735
                if (columns.size() == 0) {
736
                        columns.clear();
737
                        try {
738
                                for (int i = 0; i < sds.getFieldCount(); i++) {
739
                                        addColumn(new Column());
740
                                }
741
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
742
                                e.printStackTrace();
743
                        }
744
                }
745
        }
746

    
747
        public Column getColumn(int i) {
748
                return (Column) columns.get(i);
749
        }
750

    
751
        public void addColumn(Column column) {
752
                columns.add(column);
753
        }
754

    
755
        public int getColumnCount() {
756
                return columns.size();
757
        }
758
}