Statistics
| Revision:

root / branches / Mobile_Compatible_Hito_1 / libFMap / src-data / org / gvsig / data / vectorial / expansionadapter / FeatureManager.java @ 21606

History | View | Annotate | Download (5.68 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

    
43
package org.gvsig.data.vectorial.expansionadapter;
44

    
45
import java.util.ArrayList;
46
import java.util.HashMap;
47

    
48
import org.gvsig.data.vectorial.IFeature;
49
import org.gvsig.data.vectorial.IFeatureID;
50

    
51

    
52
/**
53
 * DOCUMENT ME!
54
 *
55
 * @author Vicente Caballero Navarro
56
 */
57
public class FeatureManager {
58
    protected HashMap relations = new HashMap();//<IFeatureID,Integer>
59
    protected IExpansionAdapter expansionAdapter;
60
    protected ArrayList deletedFeatures = new ArrayList();//<IFeatureID>
61
    protected int num=0;
62
    public FeatureManager(IExpansionAdapter expansionAdapter){
63
            this.expansionAdapter=expansionAdapter;
64
    }
65

    
66
    public void deleteFeature(IFeatureID id) {
67
        deletedFeatures.add(id);
68
        num--;
69
    }
70

    
71
    /**
72
     * DOCUMENT ME!
73
     *
74
     * @param feature DOCUMENT ME!
75
     */
76
    public void addFeature(IFeature feature) {
77
        int pos = expansionAdapter.addObject(feature);
78
        relations.put(feature.getID(), new Integer(pos));
79
        num++;
80
    }
81

    
82
    /**
83
     * DOCUMENT ME!
84
     *
85
     * @param id DOCUMENT ME!
86
     */
87
    public void deleteLastFeature(IFeatureID id) {
88
        expansionAdapter.deleteLastObject();
89
        relations.remove(id);
90
        num--;
91
    }
92

    
93
    /**
94
     * DOCUMENT ME!
95
     *
96
     * @param id DOCUMENT ME!
97
     *
98
     * @return DOCUMENT ME!
99
     */
100
    public boolean contains(IFeatureID id) {
101
        return relations.containsKey(id);
102
    }
103

    
104
    /**
105
     * DOCUMENT ME!
106
     *
107
     * @param id DOCUMENT ME!
108
     *
109
     * @return DOCUMENT ME!
110
     */
111
    public IFeature getFeature(IFeatureID id) {
112
        int num = ((Integer) relations.get(id)).intValue();
113

    
114
        return (IFeature)expansionAdapter.getObject(num);
115
    }
116

    
117
    /**
118
     * DOCUMENT ME!
119
     *
120
     * @param feature DOCUMENT ME!
121
     * @param oldFeature DOCUMENT ME!
122
     */
123
    public void updateFeature(IFeature feature, IFeature oldFeature) {
124
        deletedFeatures.add(oldFeature.getID());
125

    
126
        int num = expansionAdapter.updateObject(feature);
127

    
128
        /*
129
         * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
130
         * fichero de expansi?n.
131
         */
132
        relations.put(feature.getID(), new Integer(num));
133
    }
134

    
135
    /**
136
     * DOCUMENT ME!
137
     *
138
     * @param id DOCUMENT ME!
139
     */
140
    public void restoreFeature(IFeatureID id) {
141
        deletedFeatures.remove(id);
142
        num++;
143
    }
144
    public int getNum(){
145
            return num;
146
    }
147

    
148
    public IFeature getFeature(int i){
149
            return (IFeature)expansionAdapter.getObject(i);
150
    }
151
    public boolean isDeleted(IFeature feature){
152
            return deletedFeatures.contains(feature.getID());
153
    }
154

    
155
        public void clear() {
156
                relations.clear();//<IFeatureID,Integer>
157
            expansionAdapter.close();
158
            deletedFeatures.clear();//<IFeatureID>
159
            num=0;
160
        }
161

    
162

    
163
//        public IFeatureCollection getDataCollection(IDataCollection originalCollection, IFeatureType type, String filter, String order) {
164
//                MemoryFeatureCollection memoryCollection=new MemoryFeatureCollection();
165
////                TODO Filtrar y ordenar, quedar? tambi?n pendiente el IFeatureType que se pasa como
166
//                //par?metro ya que aqu? lo ?nico que introducimos al DataCollection son IFeatureID,
167
//                //todav?a no creamos IFeatures
168
//                for (int i=0;i<relations.size();i++){
169
//                        IFeature feature=(IFeature)expansionAdapter.getObject(i);
170
//                        if (!deletedFeatures.contains(feature.getID())){
171
//                                memoryCollection.add(feature);
172
//                        }
173
//                }
174
//                Iterator iter=originalCollection.iterator();
175
//                int i=0;
176
//                featureStore.open();
177
//                while (iter.hasNext()) {
178
//                        IFeature feature = (IFeature) iter.next();
179
//                        if (!deletedFeatures.contains(feature.getID())){
180
//                                memoryCollection.add(feature);
181
//                        }
182
//                        i++;
183
//                }
184
//
185
//                //TODO en el filtro de las features originales hay que a?adir, que no muestre las que est?n el el HashMap deletedFeatures
186
////                IFeatureCollection featureCollection=(IFeatureCollection)featureStore.getDataCollection(type,filter,order);
187
//
188
//
189
//                EditingFeatureCollection collection=new EditingFeatureCollection(originalCollection, memoryCollection,type);
190
////                collection.
191
////                MemoryFeatureCollection collection=new MemoryFeatureCollection();
192
//                //TODO Filtrar y ordenar, quedar? tambi?n pendiente el IFeatureType que se pasa como
193
//                //par?metro ya que aqu? lo ?nico que introducimos al DataCollection son IFeatureID,
194
//                //todav?a no creamos IFeatures
195
////                featureStore.createDefaultFeature()
196
////                for (int i=0;i<driver.getFeatureCount();i++){
197
////                        MemoryFeatureID id=new MemoryFeatureID(driver.getFeatureByPosition(type,i));
198
////                        collection.add(id);
199
////                }
200
//                return collection;
201
//
202
//        }
203

    
204
}