Revision 37204 branches/dal_time_support/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/layers/vectorial/impl/DefaultGraphicLayer.java

View differences:

DefaultGraphicLayer.java
26 26
*/
27 27
package org.gvsig.fmap.mapcontext.layers.vectorial.impl;
28 28

  
29
import java.util.Iterator;
30

  
29 31
import org.cresques.cts.IProjection;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

  
30 35
import org.gvsig.fmap.dal.DALLocator;
31 36
import org.gvsig.fmap.dal.DataManager;
32 37
import org.gvsig.fmap.dal.DataTypes;
33 38
import org.gvsig.fmap.dal.exception.DataException;
34 39
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
35
import org.gvsig.tools.dispose.DisposableIterator;
36 40
import org.gvsig.fmap.dal.feature.EditableFeature;
37 41
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
38 42
import org.gvsig.fmap.dal.feature.EditableFeatureType;
......
49 53
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
50 54
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend;
51 55
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
56
import org.gvsig.tools.dispose.DisposableIterator;
52 57
import org.gvsig.tools.exception.BaseException;
53
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
55 58

  
56 59
/**
57 60
 * Default {@link GraphicLayer} implementation. 
......
129 132
			if (!store.isEditing()){
130 133
				store.edit(FeatureStore.MODE_APPEND);
131 134
			}
132
			EditableFeature feature = store.createNewFeature().getEditable();
133
			feature.setString(GraphicLayer.FEATURE_ATTR_GROUPID, groupId);
134
			feature.setGeometry(GraphicLayer.FEATURE_ATTR_GEOMETRY, geom);
135
			feature.setInt(GraphicLayer.FEATURE_ATTR_IDSYMBOL, idsym);	
136
			feature.setString(GraphicLayer.FEATURE_ATTR_LABEL, label);	
137
			feature.setLong(GraphicLayer.FEATURE_ATTR_FEATUREID, ids);
138
			feature.set(GraphicLayer.FEATURE_ATTR_TAG, tag);
139
			feature.setInt(GraphicLayer.FEATURE_ATTR_PRIORITY, priority);
140

  
141
			ids++;
142

  
143
			store.insert(feature);
135
			insertGeometry(groupId, geom, idsym, label, tag, priority);
144 136
			store.finishEditing();
145 137
		} catch (DataException e) {
146 138
			logger.error("Error adding a geometry to the graphic layer", e);
147 139
		}
148
	}	
140
	}
149 141

  
142
    private void insertGeometry(String groupId, Geometry geom, int idsym,
143
        String label, Object tag, int priority) throws DataException {
144
        EditableFeature feature = store.createNewFeature().getEditable();
145
        feature.setString(GraphicLayer.FEATURE_ATTR_GROUPID, groupId);
146
        feature.setGeometry(GraphicLayer.FEATURE_ATTR_GEOMETRY, geom);
147
        feature.setInt(GraphicLayer.FEATURE_ATTR_IDSYMBOL, idsym);	
148
        feature.setString(GraphicLayer.FEATURE_ATTR_LABEL, label);	
149
        feature.setLong(GraphicLayer.FEATURE_ATTR_FEATUREID, ids);
150
        feature.set(GraphicLayer.FEATURE_ATTR_TAG, tag);
151
        feature.setInt(GraphicLayer.FEATURE_ATTR_PRIORITY, priority);
152

  
153
        ids++;
154

  
155
        store.insert(feature);
156
    }	
157

  
158
    public void addGraphics(String groupId, Iterator geoms, int idsym) {
159
        addGraphics(groupId, geoms, idsym, null, null, DEFAULT_PRIORITY);
160
    }
161

  
162
    public void addGraphics(String groupId, Iterator geoms, int idsym,
163
        String label) {
164
        addGraphics(groupId, geoms, idsym, label, null, DEFAULT_PRIORITY);
165
    }
166

  
167
    public void addGraphics(String groupId, Iterator geoms, int idsym,
168
        String label, Object tag, int priority) {
169
        try {
170
            if (!store.isEditing()) {
171
                store.edit(FeatureStore.MODE_APPEND);
172
            }
173
            for (; geoms.hasNext();) {
174
                Geometry geom = (Geometry) geoms.next();
175
                insertGeometry(groupId, geom, idsym, label, tag, priority);
176
            }
177
            store.finishEditing();
178
        } catch (DataException e) {
179
            logger.error("Error adding a geometry to the graphic layer", e);
180
        }
181
    }
182

  
150 183
	public int addSymbol(ISymbol newSymbol) {
151 184
		symbolId++;
152 185
		legend.addSymbol(new Integer(symbolId), newSymbol);

Also available in: Unified diff