Statistics
| Revision:

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

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.Date;
46

    
47
import javax.swing.JOptionPane;
48

    
49
import com.hardcode.driverManager.DriverLoadException;
50
import com.hardcode.gdbms.engine.data.DataSource;
51
import com.hardcode.gdbms.engine.data.DataSourceFactory;
52
import com.hardcode.gdbms.engine.data.NoSuchTableException;
53
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
54
import com.hardcode.gdbms.engine.instruction.SemanticException;
55
import com.hardcode.gdbms.parser.ParseException;
56
import com.iver.andami.PluginServices;
57
import com.iver.cit.gvsig.fmap.DriverException;
58
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
59
import com.iver.cit.gvsig.fmap.edition.IEditableSource;
60
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
61
import com.iver.cit.gvsig.fmap.layers.FLayer;
62
import com.iver.cit.gvsig.fmap.layers.FLayers;
63
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
64
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
65
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
66
import com.iver.cit.gvsig.fmap.layers.XMLException;
67
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
68
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
69
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend;
70
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
71
import com.iver.cit.gvsig.gui.project.OpenException;
72
import com.iver.cit.gvsig.gui.project.SaveException;
73
import com.iver.cit.gvsig.gui.tables.Column;
74
import com.iver.cit.gvsig.gui.tables.Columns;
75
import com.iver.utiles.XMLEntity;
76

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

    
85
        private IEditableSource esModel;
86

    
87
        private IEditableSource original;
88

    
89
        private String linkTable;
90

    
91
        private String field1;
92

    
93
        private String field2;
94

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

    
98
        private int[] mapping;
99

    
100
        private String[] alias;
101

    
102
        private Columns columns = new Columns();
103

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

    
115
                change.firePropertyChange("visibles", true, true);
116
        }
117

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

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

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

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

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

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

    
183
                return t;
184
        }
185

    
186
        private void createAlias()
187
                        throws com.hardcode.gdbms.engine.data.driver.DriverException,
188
                        DriverLoadException {
189
                mapping = new int[esModel.getRecordset().getFieldCount()+1];
190
                alias = new String[esModel.getRecordset().getFieldCount()+1];
191
                for (int i = 0; i < esModel.getRecordset().getFieldCount()+1; i++) {
192
                        if (i==0){
193
                                mapping[i]=i;
194
                                alias[i]=" ";
195
                        }else{
196

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

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

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

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

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

    
257
                change.firePropertyChange("model", original, esModel);
258
        }
259

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

    
295
                                                return;
296
                                        }
297
                                }
298

    
299
                                lyr.setRecordset((SelectableDataSource) original.getRecordset());
300

    
301
                                lyr.setIsJoined(false);
302
                        }
303
                }
304

    
305
                setModel(original);
306
                original = null;
307
                createAlias();
308

    
309
                change.firePropertyChange("model", original, esModel);
310
        }
311

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

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

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

    
337
                        Object di = LayerFactory.getDataSourceFactory().getDriverInfo(
338
                                        esModel.getRecordset().getName());
339

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

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

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

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

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

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

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

    
394
                        esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
395
                        associatedTable = (AlphanumericData) layer;
396

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

    
410
                        setSelectableDataSource03(xml);
411
                }
412

    
413
                setName(xml.getStringProperty("name"));
414
        }
415

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

    
436
                        setSelectableDataSource(xml);
437

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

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

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

    
481
        }
482

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

    
498
                if (xml.contains("layerName")) {
499
                        layerName = xml.getStringProperty("layerName");
500
                }
501

    
502
                if (layerName == null) {
503
                        DataSource dataSource;
504

    
505
                        try {
506
                                dataSource = LayerFactory.getDataSourceFactory()
507
                                                .createRandomDataSource(
508
                                                                xml.getStringProperty("gdbmsname"),
509
                                                                DataSourceFactory.AUTOMATIC_OPENING);
510

    
511
                                SelectableDataSource sds = new SelectableDataSource(dataSource);
512

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

    
525
                } else {
526
                        ProjectView vista = project.getViewByName(xml
527
                                        .getStringProperty("viewName"));
528
                        FLayer layer = vista.getMapContext().getLayers()
529
                                        .getLayer(layerName);
530

    
531
                        esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
532
                        associatedTable = (AlphanumericData) layer;
533
                }
534
        }
535

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

    
553
                try {
554
                        EditableAdapter es;
555

    
556
                        if (xml.contains("layerName")) {
557
                                layerName = xml.getStringProperty("layerName");
558

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

    
569
                                es = ea;
570
                        } else {
571
                                es = new EditableAdapter();
572
                                es.setOriginalDataSource(SelectableDataSource
573
                                                .createSelectableDataSource(xml.getChild(0)));
574
                        }
575

    
576
                        setDataSource(es);
577

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

    
585
                                // replaceDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(1)));
586
                        }
587

    
588
                        if (bNeedToReplace) {
589
                                if (layerName != null) {
590
                                        ProjectView vista = project.getViewByName(xml
591
                                                        .getStringProperty("viewName"));
592
                                        FLayer layer = getLayer(vista.getMapContext().getLayers(),
593
                                                        layerName);
594

    
595
                                        // modelo = ((AlphanumericData) layer).getRecordset();
596
                                        associatedTable = (AlphanumericData) layer;
597
                                }
598

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

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

    
632
        /**
633
         * DOCUMENT ME!
634
         *
635
         * @return DOCUMENT ME!
636
         */
637
        public AlphanumericData getAssociatedTable() {
638
                return associatedTable;
639
        }
640

    
641
        /**
642
         * DOCUMENT ME!
643
         *
644
         * @param associatedTable
645
         *            DOCUMENT ME!
646
         */
647
        public void setAssociatedTable(AlphanumericData associatedTable) {
648
                this.associatedTable = associatedTable;
649
        }
650

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

    
662
        /**
663
         * Devuelve el identificador de la tabla que contiene el link.
664
         *
665
         * @return identificador ?nico de la tabla.
666
         */
667
        public String getLinkTable() {
668
                return linkTable;
669
        }
670

    
671
        /**
672
         * Devuelve el nombre del campo de la tabla a enlazar.
673
         *
674
         * @return Nombre del campo de la tabla a enlazar.
675
         */
676
        public String getField1() {
677
                return field1;
678
        }
679

    
680
        /**
681
         * Devuelve el nombre del campo de la tabla enlazada.
682
         *
683
         * @return Nombre del campo de la tabla enlazada.
684
         */
685
        public String getField2() {
686
                return field2;
687
        }
688

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

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

    
720
        public String[] getAliases() {
721
                return alias;
722
        }
723

    
724
        public void setAliases(String[] alias) {
725
                this.alias = alias;
726
        }
727

    
728
        public int[] getMapping() {
729
                return mapping;
730
        }
731

    
732
        public void setMapping(int[] mapping) {
733
                this.mapping = mapping;
734
        }
735

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

    
751
        public Column getColumn(int i) {
752
                if (i==0){
753
                        Column column=new Column();
754
                        column.setWidth(45);
755
                        return column;
756
                }
757
                i--;
758
                return (Column) columns.get(mapping[i]);
759
        }
760

    
761
        public void addColumn(Column column) {
762
                columns.add(column);
763
        }
764

    
765
        public int getColumnCount() {
766
                return mapping.length;
767
        }
768
}