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/PasteAlphanumericValuesFromClipboardExtension.java

View differences:

PasteAlphanumericValuesFromClipboardExtension.java
26 26
import java.io.StringReader;
27 27
import java.util.List;
28 28
import java.util.function.Predicate;
29
import java.util.logging.Level;
30 29

  
31 30
import javax.swing.JOptionPane;
32 31
import org.apache.commons.lang.mutable.MutableInt;
......
43 42
import org.gvsig.app.project.documents.view.ViewManager;
44 43
import org.gvsig.fmap.dal.feature.EditableFeature;
45 44
import org.gvsig.fmap.dal.feature.FeatureStore;
46
import org.gvsig.fmap.geom.Geometry;
47 45
import org.gvsig.fmap.mapcontext.MapContext;
48 46
import org.gvsig.fmap.mapcontext.layers.FLayer;
49 47
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
......
60 58
import org.gvsig.fmap.dal.feature.Feature;
61 59
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
62 60
import org.gvsig.fmap.dal.feature.FeatureSelection;
61
import org.gvsig.fmap.dal.feature.FeatureType;
63 62

  
63
@SuppressWarnings({"UseSpecificCatch", "Convert2Lambda", "ConvertToTryWithResources"})
64 64
public class PasteAlphanumericValuesFromClipboardExtension extends Extension {
65 65

  
66 66
    private static final Logger LOGGER = LoggerFactory.getLogger(PasteAlphanumericValuesFromClipboardExtension.class);
......
123 123
        }
124 124

  
125 125
        MapContext mapContext = viewdoc.getMapContext();
126
        List<FLayer> layers = mapContext.getLayers().getLayers(new Predicate<FLayer>() {
127
            @Override
128
            public boolean test(FLayer layer) {
129
                return layer instanceof FLyrVect
130
                        && layer.isActive()
131
                        && layer.isAvailable()
132
                        && layer.isEditing();
133
            }
134
        });
126
        List<FLayer> layers = mapContext.getLayers().getLayers((FLayer layer) -> layer instanceof FLyrVect
127
                && layer.isActive()
128
                && layer.isAvailable()
129
                && layer.isEditing());
135 130
        if (layers.isEmpty()) {
136 131
            return;
137 132
        }
......
157 152
        }
158 153
        JsonObject fjson = (JsonObject) obj;
159 154
        try {
155
            boolean hasPk = false;
156
            FeatureType ft = store.getDefaultFeatureTypeQuietly();
157
            for (String name : fjson.keySet()) {
158
                FeatureAttributeDescriptor attr = ft.getAttributeDescriptor(name);
159
                if( attr!=null ) {
160
                    if( attr.isPrimaryKey() ) {
161
                        hasPk = true;
162
                        break;
163
                    }
164
                }
165
            }
166
            final boolean copyPk = hasPk && (application.confirmDialog(
167
                        i18n.getTranslation("_Copy_primary_key_values_XQuestionX"),
168
                        i18n.getTranslation("_Pasting_features_from_clipboard"),
169
                        JOptionPane.YES_NO_OPTION,
170
                        JOptionPane.QUESTION_MESSAGE, 
171
                        "_CopyPrimaryKeyWhenPasteAlphanumericValuesFromClipboard"
172
                ) == JOptionPane.YES_OPTION);
160 173
            EditableFeature f = store.createNewFeature(fjson);
161 174
            
162
            
163 175
            for (Feature selectionFeature : selectionFeatures) {
164 176
                EditableFeature eds = selectionFeature.getEditable();
165 177
                eds.copyFrom(f, new Predicate<FeatureAttributeDescriptor>() {
178
                    @Override
166 179
                    public boolean test(FeatureAttributeDescriptor attr) {
167 180
                        String nameGeom;
168 181
                        try {
......
173 186
                        if (StringUtils.equals(attr.getName(), nameGeom)) {
174 187
                            return false;
175 188
                        }
189
                        if( !copyPk && attr.isPrimaryKey() ) {
190
                            return false;
191
                        }
176 192
                        return true;
177 193
                    }
178 194
                });
......
184 200
        mapContext.invalidate();
185 201
    }
186 202
    
187
    //metodo static para escribir en el store
188
    // pasteFromClipboard(FeatureStore store)
189
    
190
    // isValidClipboard()
191
    
192

  
193 203
    @Override
194 204
    public boolean isEnabled() {
195 205
        ApplicationManager application = ApplicationLocator.getManager();
......
227 237
                    if (layer.isEditing()) {
228 238
                        numActiveVectorialEditable.increment();
229 239
                    }
230
                    try {
231
                        if (!((FLyrVect) layer).getFeatureStore().getFeatureSelection().isEmpty()) {
232
                            hasSelection.increment();
233
                        }
234
                    } catch (DataException ex) {
235

  
240
                    if (!((FLyrVect) layer).getFeatureStore().isFeatureSelectionEmpty()) {
241
                        hasSelection.increment();
236 242
                    }
237 243
                }
238 244
                // No recuperamos ninguna capa, solo contamos las activa en edicion

Also available in: Unified diff