Revision 46277 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/clipboard/PasteFeaturesFromClipboardExtension.java
PasteFeaturesFromClipboardExtension.java | ||
---|---|---|
57 | 57 |
import javax.json.Json; |
58 | 58 |
import javax.json.JsonArray; |
59 | 59 |
import javax.json.JsonReader; |
60 |
import org.gvsig.fmap.dal.exception.DataException; |
|
61 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
62 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
60 | 63 |
|
61 | 64 |
|
62 | 65 |
public class PasteFeaturesFromClipboardExtension extends Extension { |
... | ... | |
136 | 139 |
} |
137 | 140 |
FLyrVect layer = (FLyrVect) layers.get(0); |
138 | 141 |
FeatureStore store = layer.getFeatureStore(); |
142 |
FeatureType ft = store.getDefaultFeatureTypeQuietly(); |
|
143 |
boolean hasPk = false; |
|
144 |
|
|
145 |
if( !jsonArray.isEmpty() ) { |
|
146 |
JsonObject fjson0 = (JsonObject) jsonArray.get(0); |
|
147 |
for (String name : fjson0.keySet()) { |
|
148 |
FeatureAttributeDescriptor attr = ft.getAttributeDescriptor(name); |
|
149 |
if( attr!=null ) { |
|
150 |
if( attr.isPrimaryKey() ) { |
|
151 |
hasPk = true; |
|
152 |
break; |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
} |
|
157 |
final boolean copyPk; |
|
158 |
if( hasPk ) { |
|
159 |
int n = application.confirmDialog( |
|
160 |
i18n.getTranslation("_Copy_primary_key_values_XQuestionX"), |
|
161 |
i18n.getTranslation("_Pasting_features_from_clipboard"), |
|
162 |
JOptionPane.YES_NO_OPTION, |
|
163 |
JOptionPane.QUESTION_MESSAGE, |
|
164 |
"_CopyPrimaryKeyWhenPasteFeaturesFromClipboard" |
|
165 |
); |
|
166 |
copyPk = ( n == JOptionPane.YES_OPTION ); |
|
167 |
} else { |
|
168 |
copyPk = false; |
|
169 |
} |
|
170 |
|
|
171 |
|
|
139 | 172 |
List<EditableFeature> features = new ArrayList<>(); |
140 | 173 |
FilteredLogger theLogger = new FilteredLogger(LOGGER, "PasteFeatures", 10); |
141 | 174 |
for (Object obj : jsonArray) { |
... | ... | |
144 | 177 |
} |
145 | 178 |
JsonObject fjson = (JsonObject) obj; |
146 | 179 |
try { |
147 |
EditableFeature f = store.createNewFeature(fjson); |
|
180 |
EditableFeature f = store.createNewFeature(false); |
|
181 |
f.copyFrom(fjson, new Predicate<FeatureAttributeDescriptor>() { |
|
182 |
@Override |
|
183 |
public boolean test(FeatureAttributeDescriptor attr) { |
|
184 |
if( !copyPk && attr.isPrimaryKey() ) { |
|
185 |
return false; |
|
186 |
} |
|
187 |
return true; |
|
188 |
} |
|
189 |
}); |
|
148 | 190 |
features.add(f); |
149 | 191 |
} catch (Exception ex) { |
150 | 192 |
theLogger.warn("Can't create feature from JSON.", ex); |
Also available in: Unified diff