Revision 43981 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java

View differences:

DefaultFeatureStore.java
41 41
import java.util.Map.Entry;
42 42
import java.util.Set;
43 43
import java.util.logging.Level;
44
import org.apache.commons.collections4.ListUtils;
44 45

  
45 46
import org.apache.commons.io.FilenameUtils;
46 47
import org.apache.commons.lang3.StringUtils;
......
70 71
import org.gvsig.fmap.dal.feature.EditableFeatureType;
71 72
import org.gvsig.fmap.dal.feature.Feature;
72 73
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
74
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
73 75
import org.gvsig.fmap.dal.feature.FeatureCache;
74 76
import org.gvsig.fmap.dal.feature.FeatureIndex;
75 77
import org.gvsig.fmap.dal.feature.FeatureIndexes;
......
1186 1188
    synchronized public void update(EditableFeatureType type)
1187 1189
        throws DataException {
1188 1190
        try {
1189
            checkInEditingMode();
1190 1191
            if (type == null) {
1191 1192
                throw new NullFeatureTypeException(getName());
1192 1193
            }
1194
            boolean typehasStrongChanges = ((DefaultEditableFeatureType) type).hasStrongChanges();
1195
            if (typehasStrongChanges) {
1196
                checkInEditingMode();
1197
            }  else if(!this.isAppending()) {
1198
                throw new NeedEditingModeException(this.getName());
1199
            }
1193 1200
            // FIXME: Comprobar que es un featureType aceptable.
1194 1201
            notifyChange(FeatureStoreNotification.BEFORE_UPDATE_TYPE, type);
1195 1202
            newVersionOfUpdate();
1196

  
1197
            FeatureType oldt = type.getSource().getCopy();
1198
            FeatureType newt = type.getCopy();
1199
            commands.update(newt, oldt);
1200

  
1201
            if (((DefaultEditableFeatureType) type).hasStrongChanges()) {
1203
            
1204
            if (typehasStrongChanges) { 
1205
                FeatureType oldt = type.getSource().getCopy();
1206
                FeatureType newt = type.getCopy();
1207
                commands.update(newt, oldt);
1202 1208
                hasStrongChanges = true;
1209
            } else {
1210
                boolean ok = this.featureTypes.remove(this.defaultFeatureType);
1211
                this.defaultFeatureType = type.getCopy();
1212
                if (ok) {
1213
                    this.featureTypes.add(this.defaultFeatureType);
1214
                }
1203 1215
            }
1204 1216
            notifyChange(FeatureStoreNotification.AFTER_UPDATE_TYPE, type);
1205 1217
        } catch (Exception e) {
......
1433 1445
             * editing mode.
1434 1446
             */
1435 1447
//            ((FeatureSelection) this.getSelection()).deselectAll();
1436

  
1448
            Map<String,List<FeatureAttributeDescriptor>> computedFields = this.getComputedFields();
1437 1449
            switch (mode) {
1438 1450
            case MODE_QUERY:
1439 1451
                throw new NeedEditingModeException(this.getName());
......
1445 1457
                notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING);
1446 1458
                provider.endAppend();
1447 1459
                exitEditingMode();
1460
                this.updateComputedFields(computedFields);
1461
                saveDALFile();
1448 1462
                updateIndexes();
1449 1463
                notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING);
1450 1464
                break;
......
1468 1482
                        featureManager.getInserted(),
1469 1483
                        featureManager.getUpdated(),
1470 1484
                        removeCalculatedAttributes(featureTypeManager.getFeatureTypesChanged()).iterator());
1485
                    
1471 1486
                }  
1487
                exitEditingMode();
1488
                this.updateComputedFields(computedFields);
1472 1489
                saveDALFile();
1473
                exitEditingMode();
1474 1490
                updateIndexes();
1475 1491
                notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING);
1476 1492
                break;
......
1481 1497
            throw new FinishEditingException(e);
1482 1498
        }
1483 1499
    }
1484
    
1500
    private Map<String,List<FeatureAttributeDescriptor>> getComputedFields() throws DataException {
1501
        Map<String,List<FeatureAttributeDescriptor>> r = new HashMap<>();
1502
        
1503
        List<FeatureType> theTypes = new ArrayList<>();
1504
        theTypes.addAll(this.getFeatureTypes());
1505
        theTypes.add(this.getDefaultFeatureType());
1506
        for( int n=0; n<theTypes.size(); n++ ) {
1507
            FeatureType type = theTypes.get(n);
1508
                for (FeatureAttributeDescriptor attrdesc : type) {
1509
                    FeatureAttributeEmulator emulator = attrdesc.getFeatureAttributeEmulator();
1510
                    if( emulator!= null) {
1511
                        List<FeatureAttributeDescriptor> l = r.get(type.getId());
1512
                        if (l==null) {
1513
                            l = new ArrayList<>();
1514
                            r.put(type.getId(), l);
1515
                        }
1516
                        l.add(attrdesc);
1517
                    }
1518
            }
1519
        }
1520
        return r;
1521
    }
1522
    private void updateComputedFields(Map<String,List<FeatureAttributeDescriptor>> computedFields) throws DataException {
1523

  
1524
        List<FeatureType> theTypes = new ArrayList<>();
1525
        theTypes.addAll(this.getFeatureTypes());
1526
        theTypes.add(this.getDefaultFeatureType());
1527
        for( int n=0; n<theTypes.size(); n++ ) {
1528
            DefaultFeatureType type = (DefaultFeatureType) theTypes.get(n);
1529
            List<FeatureAttributeDescriptor> x = computedFields.get(type.getId());
1530
            if(x!=null && !x.isEmpty()) {
1531
                for (FeatureAttributeDescriptor attrdesc : x) {
1532
                    if (type.get(attrdesc.getName())==null) {
1533
                        type.add(attrdesc);
1534
                    }
1535
                }
1536
            }
1537
        }
1538
        
1539
    }
1485 1540
    private List<FeatureStoreProvider.FeatureTypeChanged> removeCalculatedAttributes(List<FeatureStoreProvider.FeatureTypeChanged> ftypes) {
1486 1541
        // FIXME: Falta por implementar
1487 1542
//        for (FeatureStoreProvider.FeatureTypeChanged ftype : ftypes) {

Also available in: Unified diff