Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / table / ProjectTable.java @ 22932

History | View | Annotate | Download (22.4 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
import java.util.List;
47

    
48
import org.gvsig.fmap.data.ReadException;
49
import org.gvsig.fmap.data.feature.AbstractFeatureStore;
50
import org.gvsig.fmap.data.feature.FeatureStore;
51
import org.gvsig.fmap.data.feature.FeatureType;
52
import org.gvsig.fmap.mapcontext.layers.FLayer;
53
import org.gvsig.fmap.mapcontext.layers.FLayers;
54
import org.gvsig.fmap.mapcontext.layers.XMLException;
55
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
56
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
57
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
58
import org.gvsig.util.observer.Observable;
59
import org.gvsig.util.observer.Observer;
60

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

    
74
/**
75
 * Tabla del proyecto
76
 *
77
 * @author Fernando Gonz?lez Cort?s
78
 */
79
public class ProjectTable extends ProjectDocument{
80
        //public static int numTables = 0;
81

    
82
        private FeatureStore esModel;
83

    
84
        private FeatureStore original;
85

    
86
        private String linkTable;
87

    
88
        private String field1;
89

    
90
        private String field2;
91

    
92
        /* No es necesaria para operar, s?lo para guardar el proyecto */
93
        private FLyrVect associatedTable;
94

    
95
        private int[] mapping;
96

    
97
        private String[] alias;
98

    
99
        private Columns columns = new Columns();
100
        private long[] orderIndexes = null;
101

    
102
        private XMLEntity backupXMLEntity= null;
103

    
104
        private LinkSelectionObserver linkSelectionObserver;
105

    
106
//        private ArrayList observers=new ArrayList();
107

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

    
119
                change.firePropertyChange("visibles", true, true);
120
        }
121

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

    
137
        /**
138
         * Obtiene el modelo de la Tabla. Es decir, una clase con capacidad para
139
         * leer la informaci?n de la tabla
140
         *
141
         * @return
142
         */
143
        public FeatureStore getModel() {
144
                return esModel;
145
        }
146

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

    
161

    
162

    
163
        public void createAlias() throws ReadException {
164
                FeatureType sds = esModel.getDefaultFeatureType();
165
//                mapping = new int[sds.getFieldCount()+1];
166
//                alias = new String[sds.getFieldCount()+1];
167
//                for (int i = 0; i < sds.getFieldCount()+1; i++) {
168
//                if (mapping == null){
169
                        int size=sds.size();
170
                        mapping = new int[size];
171
                        alias = new String[size];
172
                for (int i = 0; i < size; i++) {
173
                        mapping[i]=i;
174
                        alias[i]=sds.getByOrder(i).getName();
175

    
176
//                        if (i==0){
177
//                                mapping[i]=i;
178
//                                alias[i]=" ";
179
//                        }else{
180
//
181
//                                mapping[i] = i;
182
//                                alias[i] = sds.getFieldName(i-1);
183
//                        }
184
//                }
185
                }
186

    
187
                recalculateColumnsFromAliases();
188

    
189
        }
190

    
191
        public void recalculateColumnsFromAliases()
192
        {
193
                ArrayList columnsAux=new ArrayList();
194
                columnsAux.addAll(columns);
195
                columns.clear();
196
                for (int i = 0; i < alias.length; i++) {
197
                        if (columnsAux.size()>i) {
198
                                columns.add(columnsAux.get(i));
199
                        }else {
200
                                addColumn(new Column());
201
                        }
202
                }
203

    
204
        }
205

    
206
        /**
207
         * DOCUMENT ME!
208
         *
209
         * @param sds
210
         *            DOCUMENT ME!
211
         * @throws DriverLoadException
212
         * @throws ReadDriverException
213
         */
214
//        public void setDataSource(IEditableSource es) throws DriverLoadException, ReadDriverException {
215
//                setModel(es);
216
//
217
//                setName(esModel.getRecordset().getName());
218
//                setCreationDate(DateFormat.getInstance().format(new Date()));
219
//                change.firePropertyChange("model", esModel, esModel);
220
//        }
221

    
222
        /**
223
         * DOCUMENT ME!
224
         *
225
         * @param ds
226
         *            DOCUMENT ME!
227
         * @throws ReadDriverException
228
         * @throws com.hardcode.gdbms.engine.data.driver.DriverException
229
         */
230
//        public void replaceDataSource(IEditableSource es) throws ReadException {
231
//                if (original == null) {
232
//                        original = esModel;
233
//                }
234
//                setModel(es);
235
//                 es.getRecordset().setSelectionSupport((original
236
//                                                        .getRecordset()).getSelectionSupport());
237
//
238
//                        createAlias();
239
//                // FJP:
240
//                // Si la tabla proviene de un layer, cambiamos su recordset
241
//                if (associatedTable != null) {
242
//                        if (associatedTable instanceof FLyrVect) {
243
//                                // ((EditableAdapter)((FLyrVect)
244
//                                // associatedTable).getSource()).setRecordSet((SelectableDataSource)es.getRecordset());
245
//                                FLyrVect lyrVect = (FLyrVect) associatedTable;
246
//                                lyrVect.setRecordset(es.getRecordset());
247
//                                ((FLyrVect) associatedTable).setIsJoined(true);
248
//                        }
249
//                }
250
//
251
//                change.firePropertyChange("model", original, esModel);
252
//        }
253

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

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

    
369
        private void fillAsEmpty(){
370
                this.esModel = null;
371
                mapping = new int[0];
372
                alias = new String[0];
373
                recalculateColumnsFromAliases();
374
        }
375

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

    
469

    
470
        }
471

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

    
547
        private FLayer getLayer(FLayers layers, String name) {
548
                FLayer aux;
549
                for (int i = 0; i < layers.getLayersCount(); i++) {
550
                        if (layers.getLayer(i) instanceof FLayers) {
551
                                aux = getLayer((FLayers) layers.getLayer(i), name);
552
                                if (aux != null){
553
                                        return aux;
554
                                }
555
                        } else if (layers.getLayer(i).getName().equals(name)) {
556
                                return layers.getLayer(i);
557
                        }
558
                }
559
                return null;
560
        }
561

    
562
        /**
563
         * DOCUMENT ME!
564
         *
565
         * @return DOCUMENT ME!
566
         */
567
        public FLyrVect getAssociatedTable() {
568
                return associatedTable;
569
        }
570

    
571
        /**
572
         * DOCUMENT ME!
573
         *
574
         * @param associatedTable
575
         *            DOCUMENT ME!
576
         */
577
        public void setAssociatedTable(FLyrVect associatedTable) {
578
                this.associatedTable = associatedTable;
579
        }
580

    
581
        /**
582
         * Obtiene la fuente de datos original de la tabla si se ha invocado
583
         * replaceDataSource. Si no se invoc? este m?todo o se invoc? posteriormente
584
         * restoreDataSource se devuelve null
585
         *
586
         * @return Returns the original.
587
         */
588
        public FeatureStore getOriginal() {
589
                return original;
590
        }
591

    
592
        /**
593
         * Devuelve el identificador de la tabla que contiene el link.
594
         *
595
         * @return identificador ?nico de la tabla.
596
         */
597
        public String getLinkTable() {
598
                return linkTable;
599
        }
600

    
601
        /**
602
         * Devuelve el nombre del campo de la tabla a enlazar.
603
         *
604
         * @return Nombre del campo de la tabla a enlazar.
605
         */
606
        public String getField1() {
607
                return field1;
608
        }
609

    
610
        /**
611
         * Devuelve el nombre del campo de la tabla enlazada.
612
         *
613
         * @return Nombre del campo de la tabla enlazada.
614
         */
615
        public String getField2() {
616
                return field2;
617
        }
618

    
619
        /**
620
         * Inserta el identificador de la tabla, el campo de la primera tabla y el
621
         * campo de la segunda tabla.
622
         *
623
         * @param lt
624
         *            identificado de la tabla.
625
         * @param f1
626
         *            nombre del campo de la primera tabla.
627
         * @param f2
628
         *            nombre del campo de la segunda tabla.
629
         */
630
        public void setLinkTable(String lt, String f1, String f2) {
631
                linkTable = lt;
632
                field1 = f1;
633
                field2 = f2;
634
        }
635

    
636
        /**
637
         * Borra el identificador de la tabla y elimina del array de listener los
638
         * listener que sean del tipo: LinkSelectionObserver
639
         */
640
        public void removeLinkTable() {
641
                linkTable = null;
642
//                try {
643
                        getModel().deleteObserver(linkSelectionObserver);//removeLinksSelectionListener();
644
//                } catch (ReadException e) {
645
//                        e.printStackTrace();
646
//                }
647
        }
648

    
649
        public String[] getAliases() {
650
                return alias;
651
        }
652

    
653
        public void setAliases(String[] alias) {
654
                this.alias = alias;
655
        }
656

    
657
        public int[] getMapping() {
658
                if (mapping == null) {
659
                        mapping = new int[alias.length];
660
                        for (int i = 0; i < mapping.length; i++) {
661
                                mapping[i] = i;
662
                        }
663
                }
664
                return mapping;
665
        }
666

    
667
        public void setMapping(int[] mapping) {
668
                this.mapping = mapping;
669
        }
670

    
671
        public void setModel(FeatureStore fstore) {
672
                setTheModel(fstore);
673
                ((AbstractFeatureStore)fstore).notifyResourceChange();
674
                try {
675
//                        if (mapping==null) {
676
                                createAlias();
677
//                        }
678
                } catch (ReadException e) {
679
                        e.printStackTrace();
680
                        NotificationManager.addError(e);
681
                }
682
//                refresh();
683
        }
684

    
685
        public Column getColumn(int i) {
686
//                if (i==0){
687
//                        Column column=new Column();
688
//                        column.setWidth(45);
689
//                        return column;
690
//                }
691
//                i--;
692
                        return (Column) columns.get(getMapping()[i]);
693
        }
694

    
695
        public void addColumn(Column column) {
696
                columns.add(column);
697
        }
698

    
699
        public int getColumnCount() {
700
                return columns.size();
701
        }
702

    
703
        public IWindow createWindow() {
704
                if (this.getModel() == null)
705
                        return null;
706
                com.iver.cit.gvsig.project.documents.table.gui.Table table = new com.iver.cit.gvsig.project.documents.table.gui.Table();
707
                table.setModel(this);
708
                return table;
709
        }
710
        public IWindow getProperties() {
711
                return new TableProperties(this);
712
        }
713

    
714
        public void afterRemove() {
715
                // TODO Auto-generated method stub
716

    
717
        }
718

    
719
        public void afterAdd() {
720
                // TODO Auto-generated method stub
721

    
722
        }
723

    
724
        private void setTheModel(FeatureStore fs) {
725
                this.esModel = fs;
726

    
727
        }
728

    
729
        public void exportToXML(XMLEntity root, Project project)  throws SaveException {
730
                //TODO
731
//                XMLEntity tableRoot = project.getExportXMLTypeRootNode(root,ProjectTableFactory.registerName);
732
//                try {
733
//                        project.exportToXMLDataSource(root,this.getModelo().getRecordset().getName());
734
//                } catch (ReadDriverException e) {
735
//                        throw new SaveException();
736
//                }
737
//                tableRoot.addChild(this.getXMLEntity());
738
        }
739

    
740
        public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, ReadException, OpenException {
741
                //TODO
742
//                XMLEntity element = typeRoot.getChild(elementIndex);
743
//                this.setXMLEntity(element);
744
//                if (removeDocumentsFromRoot) {
745
//                        typeRoot.removeChild(elementIndex);
746
//                }
747
//                project.addDocument(this);
748

    
749
        }
750

    
751
        public long[] getOrderIndexes() {
752
                return orderIndexes;
753
        }
754

    
755
        public void setOrderIndexes(long[] orderIndexes) {
756
                this.orderIndexes = orderIndexes;
757
        }
758

    
759
        public void addLinkSelectionObserver(LinkSelectionObserver lso) {
760
                linkSelectionObserver=lso;
761

    
762
        }
763

    
764
//        public void addObserver(Observer arg0) {
765
//                observers.add(arg0);
766
//        }
767
//
768
//        public void deleteObserver(Observer arg0) {
769
//                observers.remove(arg0);
770
//
771
//        }
772
//
773
//        public void deleteObservers() {
774
//                observers.clear();
775
//
776
//        }
777
//        private void refresh(){
778
//                for (int i = 0; i < observers.size(); i++) {
779
//                        ((Observer)observers.get(i)).update(this,null);
780
//                }
781
//        }
782

    
783
//        public int computeSignature() {
784
//                int result = 17;
785
//
786
//                Class clazz = getClass();
787
//                Field[] fields = clazz.getDeclaredFields();
788
//                for (int i = 0; i < fields.length; i++) {
789
//                        try {
790
//                                String type = fields[i].getType().getName();
791
//                                if (type.equals("boolean")) {
792
//                                        result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
793
//                                } else if (type.equals("java.lang.String")) {
794
//                                        Object v = fields[i].get(this);
795
//                                        if (v == null) {
796
//                                                result += 37;
797
//                                                continue;
798
//                                        }
799
//                                        char[] chars = ((String) v).toCharArray();
800
//                                        for (int j = 0; j < chars.length; j++) {
801
//                                                result += 37 + (int) chars[i];
802
//                                        }
803
//                                } else if (type.equals("byte")) {
804
//                                        result += 37 + (int) fields[i].getByte(this);
805
//                                } else if (type.equals("char")) {
806
//                                        result += 37 + (int) fields[i].getChar(this);
807
//                                } else if (type.equals("short")) {
808
//                                        result += 37 + (int) fields[i].getShort(this);
809
//                                } else if (type.equals("int")) {
810
//                                        result += 37 + fields[i].getInt(this);
811
//                                } else if (type.equals("long")) {
812
//                                        long f = fields[i].getLong(this) ;
813
//                                        result += 37 + (f ^ (f >>> 32));
814
//                                } else if (type.equals("float")) {
815
//                                        result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
816
//                                } else if (type.equals("double")) {
817
//                                        long f = Double.doubleToLongBits(fields[i].getDouble(this));
818
//                                        result += 37 + (f ^ (f >>> 32));
819
//                                } else {
820
//                                        Object obj = fields[i].get(this);
821
//                                        result += 37 + ((obj != null)? obj.hashCode() : 0);
822
//                                }
823
//                        } catch (Exception e) { e.printStackTrace(); }
824
//
825
//                }
826
//                return result;
827
//        }
828
}