Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / table / ProjectTable.java @ 22477

History | View | Annotate | Download (21.6 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.documents.table;
42

    
43
import java.text.DateFormat;
44
import java.util.ArrayList;
45
import java.util.Date;
46

    
47
import org.gvsig.fmap.data.ReadException;
48
import org.gvsig.fmap.data.feature.FeatureStore;
49
import org.gvsig.fmap.data.feature.FeatureType;
50
import org.gvsig.fmap.mapcontext.layers.FLayer;
51
import org.gvsig.fmap.mapcontext.layers.FLayers;
52
import org.gvsig.fmap.mapcontext.layers.XMLException;
53
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
54
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
55
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
56

    
57
import com.iver.andami.messages.NotificationManager;
58
import com.iver.andami.ui.mdiManager.IWindow;
59
import com.iver.cit.gvsig.project.Project;
60
import com.iver.cit.gvsig.project.documents.ProjectDocument;
61
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
62
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
63
import com.iver.cit.gvsig.project.documents.table.gui.TableProperties;
64
import com.iver.cit.gvsig.project.documents.table.gui.tablemodel.Column;
65
import com.iver.cit.gvsig.project.documents.table.gui.tablemodel.Columns;
66
import com.iver.cit.gvsig.project.documents.view.ProjectView;
67
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory;
68
import com.iver.utiles.XMLEntity;
69

    
70
/**
71
 * Tabla del proyecto
72
 *
73
 * @author Fernando Gonz?lez Cort?s
74
 */
75
public class ProjectTable extends ProjectDocument {
76
        //public static int numTables = 0;
77

    
78
        private FeatureStore esModel;
79

    
80
        private FeatureStore original;
81

    
82
        private String linkTable;
83

    
84
        private String field1;
85

    
86
        private String field2;
87

    
88
        /* No es necesaria para operar, s?lo para guardar el proyecto */
89
        private FLyrVect associatedTable;
90

    
91
        private int[] mapping;
92

    
93
        private String[] alias;
94

    
95
        private Columns columns = new Columns();
96
        private long[] orderIndexes = null;
97

    
98
        private XMLEntity backupXMLEntity= null;
99

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

    
111
                change.firePropertyChange("visibles", true, true);
112
        }
113

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

    
129
        /**
130
         * Obtiene el modelo de la Tabla. Es decir, una clase con capacidad para
131
         * leer la informaci?n de la tabla
132
         *
133
         * @return
134
         */
135
        public FeatureStore getModelo() {
136
                return esModel;
137
        }
138

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

    
153

    
154

    
155
        public void createAlias() throws ReadException {
156
                FeatureType sds = esModel.getDefaultFeatureType();
157
//                mapping = new int[sds.getFieldCount()+1];
158
//                alias = new String[sds.getFieldCount()+1];
159
//                for (int i = 0; i < sds.getFieldCount()+1; i++) {
160
                if (mapping == null){
161
                        int size=sds.size();
162
                        mapping = new int[size];
163
                        alias = new String[size];
164
                for (int i = 0; i < size; i++) {
165
                        mapping[i]=i;
166
                        alias[i]=sds.getByOrder(i).getName();
167

    
168
//                        if (i==0){
169
//                                mapping[i]=i;
170
//                                alias[i]=" ";
171
//                        }else{
172
//
173
//                                mapping[i] = i;
174
//                                alias[i] = sds.getFieldName(i-1);
175
//                        }
176
                }
177
                }
178

    
179
                recalculateColumnsFromAliases();
180

    
181
        }
182

    
183
        public void recalculateColumnsFromAliases()
184
        {
185
                ArrayList columnsAux=new ArrayList();
186
                columnsAux.addAll(columns);
187
                columns.clear();
188
                for (int i = 0; i < alias.length; i++) {
189
                        if (columnsAux.size()>i) {
190
                                columns.add(columnsAux.get(i));
191
                        }else {
192
                                addColumn(new Column());
193
                        }
194
                }
195

    
196
        }
197

    
198
        /**
199
         * DOCUMENT ME!
200
         *
201
         * @param sds
202
         *            DOCUMENT ME!
203
         * @throws DriverLoadException
204
         * @throws ReadDriverException
205
         */
206
//        public void setDataSource(IEditableSource es) throws DriverLoadException, ReadDriverException {
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 ReadDriverException
220
         * @throws com.hardcode.gdbms.engine.data.driver.DriverException
221
         */
222
//        public void replaceDataSource(IEditableSource es) throws ReadException {
223
//                if (original == null) {
224
//                        original = esModel;
225
//                }
226
//                setModel(es);
227
//                 es.getRecordset().setSelectionSupport((original
228
//                                                        .getRecordset()).getSelectionSupport());
229
//
230
//                        createAlias();
231
//                // FJP:
232
//                // Si la tabla proviene de un layer, cambiamos su recordset
233
//                if (associatedTable != null) {
234
//                        if (associatedTable instanceof FLyrVect) {
235
//                                // ((EditableAdapter)((FLyrVect)
236
//                                // associatedTable).getSource()).setRecordSet((SelectableDataSource)es.getRecordset());
237
//                                FLyrVect lyrVect = (FLyrVect) associatedTable;
238
//                                lyrVect.setRecordset(es.getRecordset());
239
//                                ((FLyrVect) associatedTable).setIsJoined(true);
240
//                        }
241
//                }
242
//
243
//                change.firePropertyChange("model", original, esModel);
244
//        }
245

    
246
        /**
247
         * DOCUMENT ME!
248
         *
249
         * @throws com.hardcode.gdbms.engine.data.driver.DriverException
250
         * @throws DriverLoadException
251
         */
252
//        public void restoreDataSource()
253
//                        throws ReadException,
254
//                        DriverLoadException {
255
//                // FJP:
256
//                // Si la tabla proviene de un layer, cambiamos su recordset
257
//                if (associatedTable != null) {
258
//                        if (associatedTable instanceof FLyrVect) {
259
//                                // Miramos si la leyenda que est? usando es una
260
//                                // leyenda basada en un campo de los de la uni?n.
261
//                                // Si lo es, no dejamos pegarle el cambiazo al recordset
262
//                                FLyrVect lyr = ((FLyrVect) associatedTable);
263
//                                if (lyr.getLegend() instanceof IClassifiedVectorLegend) {
264
//                                        IClassifiedVectorLegend legend = (IClassifiedVectorLegend) lyr
265
//                                                        .getLegend();
266
//                                        IVectorLegend aux = (IVectorLegend) legend;
267
//                                        int idField = original.getRecordset().getFieldIndexByName(
268
//                                                        legend.getClassifyingFieldNames()[0]);
269
//                                        int idLabelField = -2;
270
//
271
//                                        // TODO
272
//                                        NotificationManager.addWarning("Piece of code remains unrefactored in methdo com.iver.cit.gvsig.project.documents.table.ProjectTable.restoreDataSource()", null);
273
//                                        // TODO
274
////                                        if (aux.getLabelField() != null) {
275
////                                                idLabelField = original.getRecordset()
276
////                                                                .getFieldIndexByName(aux.getLabelField());
277
////                                        }
278
////                                        if ((idField == -1) || (idLabelField == -1)) {
279
////                                                // No se ha encontrado ese campo, o se est? etiquetando
280
////                                                // por ese campo
281
////                                                JOptionPane.showMessageDialog(null, PluginServices
282
////                                                                .getText(this, "leyenda_campo_unido"));
283
////
284
////                                                return;
285
////                                        }
286
//                                }
287
//
288
//                                lyr.setRecordset(original.getRecordset());
289
//
290
//                                lyr.setIsJoined(false);
291
//                        }
292
//                }
293
//
294
//                setModel(original);
295
//                original = null;
296
//                createAlias();
297
//
298
//                change.firePropertyChange("model", original, esModel);
299
//        }
300

    
301
        /**
302
         * DOCUMENT ME!
303
         *
304
         * @return DOCUMENT ME!
305
         * @throws SaveException
306
         *
307
         * @throws XMLException
308
         */
309
        public XMLEntity getXMLEntity() throws SaveException {
310
                XMLEntity xml = super.getXMLEntity();
311
//                try {
312
//                        // xml.putProperty("nameClass", this.getClass().getName());
313
//                        int numTables=((Integer)ProjectDocument.NUMS.get(ProjectTableFactory.registerName)).intValue();
314
//
315
//                        xml.putProperty("numTables", numTables);
316
//
317
//                        if (this.getModelo() == null){
318
//                                if (this.backupXMLEntity == null){
319
//                                        return xml;
320
//                                } else{
321
//                                        return this.backupXMLEntity;
322
//                                }
323
//                        }
324
//
325
//                        if (getLinkTable() != null) {
326
//                                xml.putProperty("linkTable", linkTable);
327
//                                xml.putProperty("field1", field1);
328
//                                xml.putProperty("field2", field2);
329
//                        }
330
//
331
//                        if (getOriginal() != null) {
332
//                                xml.addChild(getOriginal().getRecordset().getXMLEntity());
333
//                        }
334
//                        xml.addChild(esModel.getRecordset().getXMLEntity());
335
//
336
////                        Object di = LayerFactory.getDataSourceFactory().getDriverInfo(
337
////                                        esModel.getRecordset().getName());
338
//
339
//                        if (associatedTable != null) {
340
//                                xml.putProperty("layerName", ((FLayer) associatedTable)
341
//                                                .getName());
342
//                                xml.putProperty("viewName", project
343
//                                                .getView((FLayer) associatedTable));
344
//                        }
345
//
346
//                        xml.putProperty("mapping", mapping);
347
//                        xml.putProperty("aliases", alias);
348
//                } catch (Exception e) {
349
//                        throw new SaveException(e, this.getClass().getName());
350
//                }
351
//
352
//                // for (int i=0;i<columns.size();i++){
353
//                // Column column=(Column)columns.get(i);
354
//                // xml.addChild(column.getXMLEntity());
355
//                // }
356
//                xml.addChild(columns.getXMLEntity());
357
//                xml.putProperty("columns", true);
358
                return xml;
359
        }
360

    
361
        private void fillAsEmpty(){
362
                this.esModel = null;
363
                mapping = new int[0];
364
                alias = new String[0];
365
                recalculateColumnsFromAliases();
366
        }
367

    
368
        /**
369
         * DOCUMENT ME!
370
         *
371
         * @param xml
372
         *            DOCUMENT ME!
373
         * @param p
374
         *            DOCUMENT ME!
375
         *
376
         * @throws XMLException
377
         * @throws DriverException
378
         * @throws OpenException
379
         *
380
         * @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
381
         */
382
        public void setXMLEntity(XMLEntity xml) throws XMLException,
383
                        ReadException, OpenException {
384
//                try {
385
//                        super.setXMLEntity(xml);
386
//                        backupXMLEntity = xml;
387
//
388
//                        setName(xml.getStringProperty("name"));
389
//                        int numTables = xml.getIntProperty("numTables");
390
//                        ProjectDocument.NUMS.put(ProjectTableFactory.registerName,new Integer(numTables));
391
//
392
//                        if (xml.getChildrenCount() == 0){
393
//                                fillAsEmpty();
394
//                                return;
395
//
396
//                        }
397
//                        try{
398
//                                setSelectableDataSource(xml);
399
//                        } catch (ReadException e){
400
//                                fillAsEmpty();
401
//                                throw e;
402
//                        }
403
//
404
//                        /*
405
//                         * if (xml.getStringProperty("type").equals("otherDriverFile")) { }
406
//                         * else if (xml.getStringProperty("type").equals("sameDriverFile")) {
407
//                         * String layerName = xml.getStringProperty("layerName");
408
//                         * ProjectView vista = project.getViewByName(xml.getStringProperty(
409
//                         * "viewName")); FLayer layer =
410
//                         * vista.getMapContext().getLayers().getLayer(layerName);
411
//                         *
412
//                         * modelo = ((AlphanumericData) layer).getRecordset();
413
//                         * associatedTable = (AlphanumericData) layer; } else if
414
//                         * (xml.getStringProperty("type").equals("db")) {
415
//                         * setSelectableDataSource(xml); }
416
//                         */
417
//                        setName(xml.getStringProperty("name"));
418
//
419
//                        if (xml.contains("linkTable")) {
420
//                                setLinkTable(xml.getStringProperty("linkTable"), xml
421
//                                                .getStringProperty("field1"), xml
422
//                                                .getStringProperty("field2"));
423
//                        }
424
//
425
//                        if (xml.contains("mapping")) {
426
//                                mapping = xml.getIntArrayProperty("mapping");
427
//                                alias = xml.getStringArrayProperty("aliases");
428
//                                // we check if all fields are real there (may be some external program has changed them.
429
//                                // If we detect any change, we discard all mapping and aliases.
430
//                                if (mapping.length != getModelo().getRecordset().getFieldCount())
431
//                                {
432
//                                        createAlias();
433
////                                        columns.clear();
434
////                                        for (int i = 0; i < esModel.getRecordset().getFieldCount(); i++) {
435
////                                                addColumn(new Column());
436
////                                        }
437
//                                        return;
438
//
439
//                                }
440
//
441
//                        } else {
442
//                                try {
443
//                                        createAlias();
444
//                                } catch (ReadException e) {
445
//                                        throw new XMLException(e);
446
//                                }
447
//                        }
448
//                } catch (Exception e) {
449
//                        throw new OpenException(e, this.getClass().getName());
450
//                }
451
//
452
//                // for (int i=1;i<xml.getNumChild();i++){
453
//                // columns.add(Column.createColumn(xml.getChild(i)));
454
//                // }
455
//                if (xml.contains("columns")) {
456
//                        columns.clear();
457
//                        columns = Columns
458
//                                        .createColumns(xml.getChild(xml.getChildrenCount() - 1));
459
//                }
460

    
461

    
462
        }
463

    
464
        /**
465
         * DOCUMENT ME!
466
         *
467
         * @param xml
468
         *            DOCUMENT ME!
469
         *
470
         * @throws XMLException
471
         *             DOCUMENT ME!
472
         * @throws DriverException
473
         *             DOCUMENT ME!
474
         */
475
        private void setSelectableDataSource(XMLEntity xml) throws ReadException {
476
//                String layerName = null;
477
//                boolean bNeedToReplace = false;
478
//                XMLEntity xmlAux = null;
479
//
480
//                try {
481
//                        EditableAdapter es;
482
//
483
//                        if (xml.contains("layerName")) {
484
//                                layerName = xml.getStringProperty("layerName");
485
//
486
//                                ProjectView vista = (ProjectView) project.getProjectDocumentByName(xml
487
//                                                .getStringProperty("viewName"), ProjectViewFactory.registerName);
488
//                                FLayer layer = getLayer(vista.getMapContext().getLayers(),
489
//                                                layerName);
490
//                                EditableAdapter ea = new EditableAdapter();
491
//                                SelectableDataSource sds = ((FLyrVect) layer).getRecordset();
492
//                                // sds.setSelectionSupport(((FLyrVect)
493
//                                // layer).getSelectionSupport());
494
//                                ea.setOriginalDataSource(sds);
495
//                                associatedTable = (FLyrVect) layer;
496
//
497
//                                es = ea;
498
//                        } else {
499
//                                es = new EditableAdapter();
500
//                                es.setOriginalDataSource(SelectableDataSource
501
//                                                .createSelectableDataSource(xml.getChild(0)));
502
//                        }
503
//
504
//                        setDataSource(es);
505
//
506
//                        if (xml.getChildrenCount() == 2 && !(xml.contains("columns"))
507
//                                        || (xml.contains("columns") && (xml.getChildrenCount() == 3))) {
508
//                                bNeedToReplace = true;
509
//                                xmlAux = xml.getChild(1);
510
//                                es = new EditableAdapter();
511
//                                // es.setRecordSet(SelectableDataSource.createSelectableDataSource(xmlAux));
512
//
513
//                                // replaceDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(1)));
514
//                        }
515
//
516
//                        if (bNeedToReplace) {
517
//                                if (layerName != null) {
518
//                                        ProjectView vista = (ProjectView) project.getProjectDocumentByName(xml
519
//                                                        .getStringProperty("viewName"), ProjectViewFactory.registerName);
520
//                                        FLayer layer = getLayer(vista.getMapContext().getLayers(),
521
//                                                        layerName);
522
//
523
//                                        // modelo = ((AlphanumericData) layer).getRecordset();
524
//                                        associatedTable = (FLyrVect) layer;
525
//                                }
526
//
527
//                                EditableAdapter auxea = new EditableAdapter();
528
//                                auxea.setOriginalDataSource(SelectableDataSource
529
//                                                .createSelectableDataSource(xmlAux));
530
//                                replaceDataSource(auxea);
531
//                        }
532
//                } catch (DriverLoadException e) {
533
//                        throw new ReadException(getName(),e);
534
//                } catch (XMLException e) {
535
//                        throw new ReadException(getName(),e);
536
//                }
537
        }
538

    
539
        private FLayer getLayer(FLayers layers, String name) {
540
                FLayer aux;
541
                for (int i = 0; i < layers.getLayersCount(); i++) {
542
                        if (layers.getLayer(i) instanceof FLayers) {
543
                                aux = getLayer((FLayers) layers.getLayer(i), name);
544
                                if (aux != null){
545
                                        return aux;
546
                                }
547
                        } else if (layers.getLayer(i).getName().equals(name)) {
548
                                return layers.getLayer(i);
549
                        }
550
                }
551
                return null;
552
        }
553

    
554
        /**
555
         * DOCUMENT ME!
556
         *
557
         * @return DOCUMENT ME!
558
         */
559
        public FLyrVect getAssociatedTable() {
560
                return associatedTable;
561
        }
562

    
563
        /**
564
         * DOCUMENT ME!
565
         *
566
         * @param associatedTable
567
         *            DOCUMENT ME!
568
         */
569
        public void setAssociatedTable(FLyrVect associatedTable) {
570
                this.associatedTable = associatedTable;
571
        }
572

    
573
        /**
574
         * Obtiene la fuente de datos original de la tabla si se ha invocado
575
         * replaceDataSource. Si no se invoc? este m?todo o se invoc? posteriormente
576
         * restoreDataSource se devuelve null
577
         *
578
         * @return Returns the original.
579
         */
580
        public FeatureStore getOriginal() {
581
                return original;
582
        }
583

    
584
        /**
585
         * Devuelve el identificador de la tabla que contiene el link.
586
         *
587
         * @return identificador ?nico de la tabla.
588
         */
589
        public String getLinkTable() {
590
                return linkTable;
591
        }
592

    
593
        /**
594
         * Devuelve el nombre del campo de la tabla a enlazar.
595
         *
596
         * @return Nombre del campo de la tabla a enlazar.
597
         */
598
        public String getField1() {
599
                return field1;
600
        }
601

    
602
        /**
603
         * Devuelve el nombre del campo de la tabla enlazada.
604
         *
605
         * @return Nombre del campo de la tabla enlazada.
606
         */
607
        public String getField2() {
608
                return field2;
609
        }
610

    
611
        /**
612
         * Inserta el identificador de la tabla, el campo de la primera tabla y el
613
         * campo de la segunda tabla.
614
         *
615
         * @param lt
616
         *            identificado de la tabla.
617
         * @param f1
618
         *            nombre del campo de la primera tabla.
619
         * @param f2
620
         *            nombre del campo de la segunda tabla.
621
         */
622
        public void setLinkTable(String lt, String f1, String f2) {
623
                linkTable = lt;
624
                field1 = f1;
625
                field2 = f2;
626
        }
627

    
628
        /**
629
         * Borra el identificador de la tabla y elimina del array de listener los
630
         * listener que sean del tipo: LinkSelectionListenr
631
         */
632
        public void removeLinkTable() {
633
                //TODO
634
//                linkTable = null;
635
//                try {
636
//                        getModelo().getRecordset()
637
//                                        .removeLinksSelectionListener();
638
//                } catch (ReadDriverException e) {
639
//                        e.printStackTrace();
640
//                }
641
        }
642

    
643
        public String[] getAliases() {
644
                return alias;
645
        }
646

    
647
        public void setAliases(String[] alias) {
648
                this.alias = alias;
649
        }
650

    
651
        public int[] getMapping() {
652
                if (mapping == null) {
653
                        mapping = new int[alias.length];
654
                        for (int i = 0; i < mapping.length; i++) {
655
                                mapping[i] = i;
656
                        }
657
                }
658
                return mapping;
659
        }
660

    
661
        public void setMapping(int[] mapping) {
662
                this.mapping = mapping;
663
        }
664

    
665
        public void setModel(FeatureStore fstore) {
666
                setTheModel(fstore);
667
                try {
668
                        if (mapping==null) {
669
                                createAlias();
670
                        }
671
                } catch (ReadException e) {
672
                        e.printStackTrace();
673
                        NotificationManager.addError(e);
674
                }
675
        }
676

    
677
        public Column getColumn(int i) {
678
//                if (i==0){
679
//                        Column column=new Column();
680
//                        column.setWidth(45);
681
//                        return column;
682
//                }
683
//                i--;
684
                        return (Column) columns.get(getMapping()[i]);
685
        }
686

    
687
        public void addColumn(Column column) {
688
                columns.add(column);
689
        }
690

    
691
        public int getColumnCount() {
692
                return columns.size();
693
        }
694

    
695
        public IWindow createWindow() {
696
                if (this.getModelo() == null)
697
                        return null;
698
                com.iver.cit.gvsig.project.documents.table.gui.Table table = new com.iver.cit.gvsig.project.documents.table.gui.Table();
699
                table.setModel(this);
700
                return table;
701
        }
702
        public IWindow getProperties() {
703
                return new TableProperties(this);
704
        }
705

    
706
        public void afterRemove() {
707
                // TODO Auto-generated method stub
708

    
709
        }
710

    
711
        public void afterAdd() {
712
                // TODO Auto-generated method stub
713

    
714
        }
715

    
716
        private void setTheModel(FeatureStore fs) {
717
                this.esModel = fs;
718

    
719
        }
720

    
721
        public void exportToXML(XMLEntity root, Project project)  throws SaveException {
722
                //TODO
723
//                XMLEntity tableRoot = project.getExportXMLTypeRootNode(root,ProjectTableFactory.registerName);
724
//                try {
725
//                        project.exportToXMLDataSource(root,this.getModelo().getRecordset().getName());
726
//                } catch (ReadDriverException e) {
727
//                        throw new SaveException();
728
//                }
729
//                tableRoot.addChild(this.getXMLEntity());
730
        }
731

    
732
        public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, ReadException, OpenException {
733
                //TODO
734
//                XMLEntity element = typeRoot.getChild(elementIndex);
735
//                this.setXMLEntity(element);
736
//                if (removeDocumentsFromRoot) {
737
//                        typeRoot.removeChild(elementIndex);
738
//                }
739
//                project.addDocument(this);
740

    
741
        }
742

    
743
        public long[] getOrderIndexes() {
744
                return orderIndexes;
745
        }
746

    
747
        public void setOrderIndexes(long[] orderIndexes) {
748
                this.orderIndexes = orderIndexes;
749
        }
750

    
751
//        public int computeSignature() {
752
//                int result = 17;
753
//
754
//                Class clazz = getClass();
755
//                Field[] fields = clazz.getDeclaredFields();
756
//                for (int i = 0; i < fields.length; i++) {
757
//                        try {
758
//                                String type = fields[i].getType().getName();
759
//                                if (type.equals("boolean")) {
760
//                                        result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
761
//                                } else if (type.equals("java.lang.String")) {
762
//                                        Object v = fields[i].get(this);
763
//                                        if (v == null) {
764
//                                                result += 37;
765
//                                                continue;
766
//                                        }
767
//                                        char[] chars = ((String) v).toCharArray();
768
//                                        for (int j = 0; j < chars.length; j++) {
769
//                                                result += 37 + (int) chars[i];
770
//                                        }
771
//                                } else if (type.equals("byte")) {
772
//                                        result += 37 + (int) fields[i].getByte(this);
773
//                                } else if (type.equals("char")) {
774
//                                        result += 37 + (int) fields[i].getChar(this);
775
//                                } else if (type.equals("short")) {
776
//                                        result += 37 + (int) fields[i].getShort(this);
777
//                                } else if (type.equals("int")) {
778
//                                        result += 37 + fields[i].getInt(this);
779
//                                } else if (type.equals("long")) {
780
//                                        long f = fields[i].getLong(this) ;
781
//                                        result += 37 + (f ^ (f >>> 32));
782
//                                } else if (type.equals("float")) {
783
//                                        result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
784
//                                } else if (type.equals("double")) {
785
//                                        long f = Double.doubleToLongBits(fields[i].getDouble(this));
786
//                                        result += 37 + (f ^ (f >>> 32));
787
//                                } else {
788
//                                        Object obj = fields[i].get(this);
789
//                                        result += 37 + ((obj != null)? obj.hashCode() : 0);
790
//                                }
791
//                        } catch (Exception e) { e.printStackTrace(); }
792
//
793
//                }
794
//                return result;
795
//        }
796
}