Revision 44189

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialExplorer.java
1 1
package org.gvsig.fmap.dal.store.h2;
2 2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
5 3
import java.io.File;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.io.OutputStream;
9
import java.net.URI;
10
import java.nio.file.FileSystem;
11
import java.nio.file.FileSystems;
12
import java.nio.file.Files;
13
import java.nio.file.Path;
14
import java.util.HashMap;
15
import java.util.Map;
16 4
import org.apache.commons.io.FilenameUtils;
17
import org.apache.commons.io.IOUtils;
18 5
import org.gvsig.fmap.dal.DataStore;
19 6
import org.gvsig.fmap.dal.exception.DataException;
20 7
import org.gvsig.fmap.dal.exception.InitializeException;
......
29 16
 */
30 17
@SuppressWarnings("UseSpecificCatch")
31 18
public class H2SpatialExplorer extends JDBCServerExplorerBase {
32
    
33
    private class H2Resource implements DataResource {
34

  
35
        private final File zipFile;
36
        private final String tableName;
37
        private InputStream in;
38
        private ByteArrayOutputStream out;
39
        private FileSystem fs;
40 19
        
41
        public H2Resource(File zipFile, String tableName) {
42
            this.zipFile = zipFile;
43
            this.tableName = tableName;
44
        }
45

  
46
        @Override
47
        public boolean exists() {
48
            if( !this.zipFile.exists() ) {
49
                return false;
50
            }
51
            try {
52
                Map<String, String> attributes = new HashMap<>();
53
                attributes.put("create", "false");
54
                URI zipURI = new URI("zip:"+this.zipFile.toURI().toString());
55
                this.fs = FileSystems.newFileSystem(zipURI, attributes);
56
                Path tablePath = fs.getPath(this.tableName);
57
                if( tablePath==null ) {
58
                    IOUtils.closeQuietly(fs);
59
                    this.fs = null;
60
                    return false;
61
                }
62
                return true;
63
                
64
            } catch(Exception ex) {
65
                IOUtils.closeQuietly(fs);
66
                this.fs = null;
67
                return false;
68
            }
69
        }
70

  
71
        @Override
72
        public InputStream asInputStream() throws IOException {
73
            if( !this.zipFile.exists()) {
74
                return null;
75
            }
76
            if( this.in!=null || this.out!=null ) {
77
                throw new IllegalStateException("Resource is already open ("+this.zipFile.toString()+"!"+this.tableName+")");
78
            }
79
            try {
80
                Map<String, String> attributes = new HashMap<>();
81
                attributes.put("create", "false");
82
                URI zipURI = new URI("zip:"+this.zipFile.toURI().toString());
83
                this.fs = FileSystems.newFileSystem(zipURI, attributes);
84
                Path tablePath = fs.getPath(this.tableName);
85
                if( tablePath==null ) {
86
                    IOUtils.closeQuietly(fs);
87
                    this.fs = null;
88
                    return null;
89
                }
90
                this.in = Files.newInputStream(tablePath);
91
                return this.in;
92
                
93
            } catch(Exception ex) {
94
                IOUtils.closeQuietly(fs);
95
                this.fs = null;
96
                return null;
97
            }
98
        }
99

  
100
        @Override
101
        public OutputStream asOutputStream() throws IOException {
102
            if( !this.zipFile.exists() ) {
103
                return null;
104
            }
105
            if( this.in!=null || this.out!=null ) {
106
                throw new IllegalStateException("Resource is already open ("+this.zipFile.toString()+"!"+this.tableName+")");
107
            }
108
            this.out = new ByteArrayOutputStream();
109
            return this.out;
110
        }
111

  
112
        @Override
113
        public void close() {
114
            if( this.in!=null ) {
115
                IOUtils.closeQuietly(this.in);
116
                this.in = null;
117
            }
118
            if(this.out != null ) {
119
                try {
120
                    Map<String, String> attributes = new HashMap<>();
121
                    attributes.put("create", "true");
122
                    URI zipURI = new URI("zip:"+this.zipFile.toURI().toString());
123
                    this.fs = FileSystems.newFileSystem(zipURI, attributes);
124
                    Path tablePath = fs.getPath(this.tableName);
125
                    ByteArrayInputStream lin = new ByteArrayInputStream(this.out.toByteArray());
126
                    Files.copy(lin, tablePath);
127

  
128
                } catch(Exception ex) {
129
                    IOUtils.closeQuietly(this.out);
130
                    this.out = null;
131
                }
132
            }
133
            if( this.fs!=null ) {
134
                IOUtils.closeQuietly(this.fs);
135
                this.fs = null;
136
            }
137
        }
138
    }
139
    
140 20
    public H2SpatialExplorer(JDBCServerExplorerParameters parameters, DataServerExplorerProviderServices services, JDBCHelper helper) throws InitializeException {
141 21
        super(parameters, services, helper);
142 22
    }
......
151 31
        String zipPath = this.getParameters().getFile().getAbsolutePath();
152 32
        zipPath = FilenameUtils.removeExtension(zipPath);
153 33
        zipPath = zipPath + "." + resourceName;
154
        H2Resource resource = new H2Resource(new File(zipPath), dataStore.getName());
34
        H2SpatialResource resource = new H2SpatialResource(new File(zipPath), dataStore.getName());
155 35
        return resource;
156 36
    }
157 37
    
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialResource.java
1
package org.gvsig.fmap.dal.store.h2;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.File;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.io.OutputStream;
9
import java.net.MalformedURLException;
10
import java.net.URI;
11
import java.net.URISyntaxException;
12
import java.net.URL;
13
import java.nio.file.FileSystem;
14
import java.nio.file.FileSystems;
15
import java.nio.file.Files;
16
import java.nio.file.Path;
17
import java.util.Collections;
18
import java.util.Objects;
19
import java.util.logging.Level;
20
import java.util.logging.Logger;
21
import org.apache.commons.io.IOUtils;
22
import org.gvsig.fmap.dal.AbstractDataResource;
23
import org.gvsig.fmap.dal.DataServerExplorer.DataResource;
24

  
25
/**
26
 *
27
 * @author jjdelcerro
28
 */
29
@SuppressWarnings("UseSpecificCatch")
30
class H2SpatialResource 
31
        extends AbstractDataResource
32
        implements DataResource 
33
    {
34
    
35
    private final File zipFile;
36
    private final String tableName;
37
    private InputStream in;
38
    private ByteArrayOutputStream out;
39
    private FileSystem zipfs;
40
    private final URI zipfsuri;
41

  
42
    public H2SpatialResource(File zipFile, String tableName) {
43
        this.zipFile = zipFile;
44
        this.tableName = tableName;
45
        try {
46
            this.zipfsuri = new URI("jar:" + this.zipFile.toURI().toString());
47
        } catch (URISyntaxException ex) {
48
            throw new IllegalArgumentException("The zip file '" + Objects.toString(zipFile) + "' is not a valid file name.", ex);
49
        }
50
    }
51

  
52
    @Override
53
    public URL getURL() {
54
        try {
55
            return new URL(this.zipfsuri.toString()+"!"+this.tableName);
56
        } catch (MalformedURLException ex) {
57
            return null;
58
        }
59
    }
60

  
61
    private void openzipfs(boolean create) throws IOException {
62
        if (this.zipfs == null) {
63
            this.zipfs = FileSystems.newFileSystem(this.zipfsuri, Collections.singletonMap("create", create ? "true" : "false"));
64
        }
65
    }
66

  
67
    @Override
68
    public boolean exists() {
69
        if (!this.zipFile.exists()) {
70
            return false;
71
        }
72
        try {
73
            this.openzipfs(false);
74
            Path tablePath = this.zipfs.getPath(this.tableName);
75
            if (tablePath == null) {
76
                return false;
77
            }
78
            return true;
79
        } catch (Exception ex) {
80
            return false;
81
        }
82
    }
83

  
84
    @Override
85
    public InputStream asInputStream() throws IOException {
86
        if (!this.zipFile.exists()) {
87
            return null;
88
        }
89
        if (this.in != null || this.out != null) {
90
            throw new IllegalStateException("Resource is already open (" + this.zipFile.toString() + "!" + this.tableName + ")");
91
        }
92
        try {
93
            this.openzipfs(false);
94
            Path tablePath = this.zipfs.getPath(this.tableName);
95
            if (tablePath == null) {
96
                return null;
97
            }
98
            this.in = Files.newInputStream(tablePath);
99
            return this.in;
100
        } catch (Exception ex) {
101
            return null;
102
        }
103
    }
104

  
105
    @Override
106
    public OutputStream asOutputStream() throws IOException {
107
        if (this.in != null || this.out != null) {
108
            throw new IllegalStateException("Resource is already open (" + this.zipFile.toString() + "!" + this.tableName + ")");
109
        }
110
        this.out = new ByteArrayOutputStream();
111
        return this.out;
112
    }
113

  
114
    @Override
115
    public void close() {
116
        if (this.in != null) {
117
            IOUtils.closeQuietly(this.in);
118
            this.in = null;
119
        }
120
        if (this.out != null) {
121
            ByteArrayInputStream pipe = null;
122
            try {
123
                this.openzipfs(true);
124
                Path tablePath = this.zipfs.getPath(this.tableName);
125
                pipe = new ByteArrayInputStream(this.out.toByteArray());
126
                Files.copy(pipe, tablePath);
127
            } catch (Exception ex) {
128
            } finally {
129
                IOUtils.closeQuietly(pipe);
130
                IOUtils.closeQuietly(this.out);
131
                this.out = null;
132
            }
133
        }
134
        if (this.zipfs != null) {
135
            IOUtils.closeQuietly(this.zipfs);
136
        }
137
    }
138
    
139
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/featureform/swing/impl/DefaultJFeaturesForm.java
151 151
            return;
152 152
        }
153 153
        DynFormManager formManager = DynFormLocator.getDynFormManager();
154
        if( definition == null ) {
154
        if( definition == null || definition instanceof FeatureType ) {
155 155
            DataServerExplorer explorer=null;
156 156
            try {
157 157
                explorer = store.getExplorer();
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/featureform/swing/impl/dynformfield/ImageFile/AbstractJDynFormFieldImage.java
27 27
import java.awt.event.FocusEvent;
28 28
import java.awt.event.FocusListener;
29 29
import java.util.Objects;
30
import javax.swing.JComponent;
30 31
import javax.swing.JPanel;
31 32
import org.gvsig.imageviewer.ImageViewer;
32 33
import org.gvsig.tools.dynform.JDynFormField;
......
72 73
        this.contents.setLayout(new BorderLayout(2, 0));
73 74

  
74 75
        this.imageViewer = ToolsUtilLocator.getImageViewerManager().createImageViewer();
75
        this.imageViewer.asJComponent().setPreferredSize(new Dimension(300, 200));
76

  
77
        this.contents.add(this.imageViewer.asJComponent(), BorderLayout.CENTER);
76
        JComponent jimageViewer = this.imageViewer.asJComponent();
77
        
78
        jimageViewer.setPreferredSize(new Dimension(300, 200));
79
        jimageViewer.setSize(300,200);
80
        
81
        this.contents.add(jimageViewer, BorderLayout.CENTER);
78 82
        this.contents.setVisible(true);
79 83
    }
80 84

  
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/AbstractDataResource.java
1
package org.gvsig.fmap.dal;
2

  
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.io.OutputStream;
6
import java.net.URL;
7
import org.gvsig.fmap.dal.DataServerExplorer.DataResource;
8

  
9
/**
10
 *
11
 * @author jjdelcerro
12
 */
13
public abstract class AbstractDataResource implements DataResource {
14

  
15
    @Override
16
    public URL getURL() {
17
        return null;
18
    }
19

  
20
    @Override
21
    public boolean exists() {
22
        return false;
23
    }
24

  
25
    @Override
26
    public InputStream asInputStream() throws IOException {
27
        return null;
28
    }
29

  
30
    @Override
31
    public OutputStream asOutputStream() throws IOException {
32
        return null;
33
    }
34

  
35
    @Override
36
    public void close() {
37

  
38
    }
39
    
40
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/AbstractDataProfile.java
1
package org.gvsig.fmap.dal.feature;
2

  
3
/**
4
 *
5
 * @author jjdelcerro
6
 */
7
public abstract class AbstractDataProfile implements DataProfile {
8

  
9
    private final String name;
10
    private final Class dataClass;
11

  
12
    public AbstractDataProfile(String name, Class dataClass) {
13
        this.name = name;
14
        this.dataClass = dataClass;
15
    }
16
    @Override
17
    public String getName() {
18
        return this.name;
19
    }
20

  
21
    @Override
22
    public Class getDataClass() {
23
        return this.dataClass;
24
    }
25

  
26
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/DataProfile.java
8 8

  
9 9
    public String getName();
10 10
    
11
    public Class getDataClass();
12
    
11 13
    public Object createData(Object data);
12 14
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataServerExplorer.java
28 28
import java.io.IOException;
29 29
import java.io.InputStream;
30 30
import java.io.OutputStream;
31
import java.net.URL;
31 32
import java.util.List;
32 33

  
33 34
import org.gvsig.fmap.dal.exception.DataException;
35
import static org.gvsig.tools.dataTypes.DataTypes.URL;
34 36
import org.gvsig.tools.dispose.Disposable;
35 37

  
36 38
/**
......
43 45
public interface DataServerExplorer extends Disposable, DataFactoryUnit {
44 46

  
45 47
    public interface DataResource extends Closeable {
48
        public URL getURL();
49
        
46 50
        public boolean exists();
47 51
        
48 52
        public InputStream asInputStream() throws IOException;
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/HasDataStore.java
1
package org.gvsig.fmap.dal;
2

  
3
/**
4
 *
5
 * @author jjdelcerro
6
 */
7
public interface HasDataStore {
8

  
9
    public DataStore getDataStore();
10
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/impl/DefaultFilesystemServerExplorer.java
27 27
import java.io.FileOutputStream;
28 28
import java.io.InputStream;
29 29
import java.io.OutputStream;
30
import java.net.MalformedURLException;
31
import java.net.URL;
30 32
import java.util.ArrayList;
31 33
import java.util.HashSet;
32 34
import java.util.Iterator;
33 35
import java.util.List;
34 36
import java.util.Set;
37
import java.util.logging.Level;
38
import java.util.logging.Logger;
35 39
import org.apache.commons.io.FilenameUtils;
36 40
import org.apache.commons.io.IOUtils;
41
import org.gvsig.fmap.dal.AbstractDataResource;
37 42

  
38 43
import org.gvsig.fmap.dal.DALFileLocator;
39 44
import org.gvsig.fmap.dal.DALLocator;
......
66 71
        implements FilesystemServerExplorerProviderServices,
67 72
        FilesystemFileFilter {
68 73

  
69
    private class FileResource implements DataResource {
74
    private class FileResource 
75
            extends AbstractDataResource
76
            implements DataResource 
77
        {
70 78

  
71 79
        private final File f;
72 80
        private FileInputStream in;
......
76 84
            this.f = f;
77 85
        }
78 86

  
87
        public URL getURL() {
88
            try {
89
                return this.f.toURI().toURL();
90
            } catch (MalformedURLException ex) {
91
                return null;
92
            }
93
        }
94
        
79 95
        public File getFile() {
80 96
            return this.f;
81 97
        }
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.dbf/src/main/java/org/gvsig/fmap/dal/store/dbf/utils/DbaseFileWriter.java
232 232
        int dbfFieldIndex = this.header.getFieldIndex(attr.getName());
233 233
        final int fieldLen = header.getFieldLength(dbfFieldIndex);
234 234
        String fieldString = "";
235
        //
236
        // https://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm
237
        //
235 238
        if (DataTypes.BOOLEAN == type) {
236 239
            boolean b = feature.getBoolean(attr.getIndex());
237 240
            if (b) {
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/DALFile.java
78 78
                .setPersistent(true);
79 79
            definition.addDynFieldObject("emulator")
80 80
                .setClassOfValue(FeatureAttributeEmulator.class)
81
                .setMandatory(true)
81
                .setMandatory(false)
82 82
                .setPersistent(true);
83 83
            definition.addDynFieldLong("IntervalStart")
84 84
                .setMandatory(false)
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
617 617
        } catch(Throwable th) {
618 618
            state.setBreakingsCause(th);
619 619
        }
620

  
621 620
        try {
622 621
            selection = (FeatureSelection) state.get("selection");
623 622
        } catch(Throwable th) {
......
1203 1202
            notifyChange(FeatureStoreNotification.BEFORE_UPDATE_TYPE, type);
1204 1203
            newVersionOfUpdate();
1205 1204
            
1205
            FeatureType oldt = type.getSource().getCopy();
1206
            FeatureType newt = type.getCopy();
1207
            commands.update(newt, oldt);
1206 1208
            if (typehasStrongChanges) { 
1207
                FeatureType oldt = type.getSource().getCopy();
1208
                FeatureType newt = type.getCopy();
1209
                commands.update(newt, oldt);
1210 1209
                hasStrongChanges = true;
1211
            } else {
1212
                boolean ok = this.featureTypes.remove(this.defaultFeatureType);
1213
                this.defaultFeatureType = type.getNotEditableCopy();
1214
                if (ok) {
1215
                    this.featureTypes.add(this.defaultFeatureType);
1216
                }
1217 1210
            }
1218 1211
            notifyChange(FeatureStoreNotification.AFTER_UPDATE_TYPE, type);
1219 1212
        } catch (Exception e) {
......
1457 1450
                    selection = null;
1458 1451
                }
1459 1452
                notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING);
1453
                saveDALFile();
1460 1454
                provider.endAppend();
1461 1455
                exitEditingMode();
1462 1456
                this.updateComputedFields(computedFields);
1463
                saveDALFile();
1457
                loadDALFile();
1464 1458
                updateIndexes();
1465 1459
                notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING);
1466 1460
                break;
......
1469 1463
                if (hasStrongChanges && !this.allowWrite()) {
1470 1464
                    throw new WriteNotAllowedException(getName());
1471 1465
                }
1466
                saveDALFile();
1472 1467
                if(featureManager.isSelectionCompromised() && selection!=null ) {
1473 1468
                    selection = null;
1474 1469
                }
......
1486 1481
                        removeCalculatedAttributes(featureTypeManager.getFeatureTypesChanged()).iterator());
1487 1482
                    
1488 1483
                }  
1489
                exitEditingMode();
1490 1484
                this.updateComputedFields(computedFields);
1491
                saveDALFile();
1485
                exitEditingMode();
1486
                loadDALFile();
1492 1487
                updateIndexes();
1493 1488
                notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING);
1494 1489
                break;
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/DefaultEditableFeatureAttributeDescriptor.java
25 25

  
26 26
import java.text.DateFormat;
27 27
import java.util.HashMap;
28
import java.util.Objects;
28 29
import org.apache.commons.lang3.StringUtils;
29 30

  
30 31
import org.cresques.cts.IProjection;
......
40 41
import org.gvsig.fmap.geom.type.GeometryType;
41 42
import org.gvsig.timesupport.Interval;
42 43
import org.gvsig.tools.ToolsLocator;
44
import org.gvsig.tools.dataTypes.DataType;
43 45
import org.gvsig.tools.evaluator.Evaluator;
44 46

  
45 47
public class DefaultEditableFeatureAttributeDescriptor extends
......
101 103
    }
102 104

  
103 105
    public EditableFeatureAttributeDescriptor setAllowNull(boolean allowNull) {
106
        updateStrongChanges(this.allowNull, allowNull);
104 107
        this.allowNull = allowNull;
105
        if (!isComputed()) {
106
            hasStrongChanges = true;
107
        }
108 108
        return this;
109 109
    }
110 110

  
111 111
    public EditableFeatureAttributeDescriptor setDataType(int type) {
112
        updateStrongChanges(this.dataType, type);
112 113
        this.dataType = ToolsLocator.getDataTypesManager().get(type);
113
        if (!isComputed()) {
114
            hasStrongChanges = true;
115
        }
116 114
        return this;
117 115
    }
118 116

  
119 117
    public EditableFeatureAttributeDescriptor setDefaultValue(
120 118
        Object defaultValue) {
119
        updateStrongChanges(this.defaultValue, defaultValue);
121 120
        this.defaultValue = defaultValue;
122
        if (!isComputed()) {
123
            hasStrongChanges = true;
124
        }
125 121
        return this;
126 122
    }
127 123

  
128 124
    public EditableFeatureAttributeDescriptor setEvaluator(Evaluator evaluator) {
129
        if (this.evaluator != null && evaluator == null) {
130
            hasStrongChanges = true;
131
        }
125
        updateStrongChanges(this.evaluator, evaluator);
132 126
        this.evaluator = evaluator;
133 127
        return this;
134 128
    }
......
155 149

  
156 150
    public EditableFeatureAttributeDescriptor setGeometryType(
157 151
        GeometryType geometryType) {
152
        updateStrongChanges(this.geomType, geometryType);
158 153
        this.geomType = geometryType;
159 154
        this.geometryType = this.geomType.getType();
160 155
        this.geometrySubType = this.geomType.getSubType();
161
        if (!isComputed()) {
162
            hasStrongChanges = true;
163
        }
164 156
        return this;
165 157
    }
166 158

  
......
174 166

  
175 167
    public EditableFeatureAttributeDescriptor setIsPrimaryKey(
176 168
        boolean isPrimaryKey) {
169
        updateStrongChanges(this.primaryKey, primaryKey);
177 170
        this.primaryKey = isPrimaryKey;
178
        if (!isComputed()) {
179
            hasStrongChanges = true;
180
        }
181 171
        return this;
182 172
    }
183 173

  
184 174
    public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) {
175
        updateStrongChanges(this.readOnly, readOnly);
185 176
        this.readOnly = isReadOnly;
186
        if (!isComputed()) {
187
            hasStrongChanges = true;
188
        }
189 177
        return this;
190 178
    }
191 179

  
192 180
    public EditableFeatureAttributeDescriptor setMaximumOccurrences(
193 181
        int maximumOccurrences) {
182
        updateStrongChanges(this.maximumOccurrences, maximumOccurrences);
194 183
        this.maximumOccurrences = maximumOccurrences;
195
        if (!isComputed()) {
196
            hasStrongChanges = true;
197
        }
198 184
        return this;
199 185
    }
200 186

  
201 187
    public EditableFeatureAttributeDescriptor setMinimumOccurrences(
202 188
        int minimumOccurrences) {
189
        updateStrongChanges(this.minimumOccurrences, minimumOccurrences);
203 190
        this.minimumOccurrences = minimumOccurrences;
204
        if (!isComputed()) {
205
            hasStrongChanges = true;
206
        }
207 191
        return this;
208 192
    }
209 193

  
......
230 214
    }
231 215

  
232 216
    public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) {
217
        updateStrongChanges(this.objectClass, theClass);
233 218
        this.objectClass = theClass;
234
        if (!isComputed()) {
235
            hasStrongChanges = true;
236
        }
237 219
        return this;
238 220
    }
239 221

  
240 222
    public EditableFeatureAttributeDescriptor setPrecision(int precision) {
223
        updateStrongChanges(this.precision, precision);
241 224
        this.precision = precision;
242
        if (!isComputed()) {
243
            hasStrongChanges = true;
244
        }
245 225
        return this;
246 226
    }
247 227

  
248 228
    public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
229
        updateStrongChanges(this.SRS, SRS);
249 230
        this.SRS = SRS;
250
        if (!isComputed()) {
251
            hasStrongChanges = true;
252
        }
253 231
        return this;
254 232
    }
255 233

  
256 234
    public EditableFeatureAttributeDescriptor setInterval(Interval interval) {
235
        updateStrongChanges(this.getInterval(), interval);
257 236
        super.setInterval(interval);
258
        if (!isComputed()) {
259
            hasStrongChanges = true;
260
        }
261 237
        return this;
262 238
    }
263 239

  
264 240
    public EditableFeatureAttributeDescriptor setSize(int size) {
241
        updateStrongChanges(this.size, size);
265 242
        this.size = size;
266
        if (!isComputed()) {
267
            hasStrongChanges = true;
268
        }
269 243
        return this;
270 244
    }
271 245

  
......
291 265
    }
292 266
    
293 267
    public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) {
268
        updateStrongChanges(this.isTime, isTime);
294 269
        this.isTime = isTime;
295
        if (!isComputed()) {
296
            hasStrongChanges = true;
297
        }
298 270
        return this;
299 271
    }
300 272

  
......
304 276
    }
305 277

  
306 278
    public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) {
279
        updateStrongChanges(this.indexed, isIndexed);
307 280
        this.indexed = isIndexed;
308
        if (!isComputed()) {
309
            hasStrongChanges = true;
310
        }
311 281
        return this;
312 282
    }
313 283
    
314 284
    public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) {
285
        updateStrongChanges(this.allowIndexDuplicateds, allowDuplicateds);
315 286
        this.allowIndexDuplicateds = allowDuplicateds;
316
        if (!isComputed()) {
317
            hasStrongChanges = true;
318
        }
319 287
        return this;
320 288
    }
321 289

  
322 290
    public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) {
291
        updateStrongChanges(this.isIndexAscending, ascending);
323 292
        this.isIndexAscending = ascending;
324
        if (!isComputed()) {
325
            hasStrongChanges = true;
326
        }
327 293
        return this;
328 294
    }
329 295

  
......
332 298
        super.setDataProfileName(dataProfile);
333 299
        return this;
334 300
    }
335
    
301

  
302
    private void updateStrongChanges(int previous, int newvalue) {
303
        if( isComputed() ) {
304
            return;
305
        }
306
        if( previous == newvalue ) {
307
            return;
308
        }
309
        this.hasStrongChanges = true;
310
    }
311

  
312
    private void updateStrongChanges(DataType previous, int newvalue) {
313
        if( isComputed() ) {
314
            return;
315
        }
316
        if( previous!=null ) {
317
            if( previous.getType() == newvalue ) {
318
                return;
319
            }
320
        }
321
        this.hasStrongChanges = true;
322
    }
323

  
324
    private void updateStrongChanges(boolean previous, boolean newvalue) {
325
        if( isComputed() ) {
326
            return;
327
        }
328
        if( previous == newvalue ) {
329
            return;
330
        }
331
        this.hasStrongChanges = true;
332
    }
333

  
334
    private void updateStrongChanges(Object previous, Object newvalue) {
335
        if( isComputed() ) {
336
            return;
337
        }
338
        if( Objects.equals(newvalue, previous) ) {
339
            return;
340
        }
341
        this.hasStrongChanges = true;
342
    }
336 343
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/operations/SingleLayer.java
24 24
package org.gvsig.fmap.mapcontext.layers.operations;
25 25

  
26 26
import org.gvsig.fmap.dal.DataStore;
27
import org.gvsig.fmap.dal.HasDataStore;
27 28
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
28 29
import org.gvsig.fmap.mapcontext.layers.FLayer;
29 30

  
30
/**
31
 * DOCUMENT ME!
32
 *
33
 */
34
public interface SingleLayer extends FLayer {
31
public interface SingleLayer extends FLayer, HasDataStore {
35 32
	/**
36 33
	 * M?todo que devuelve el DataStore del que saca los datos la capa.
37 34
	 *
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/TableDocument.java
39 39
import org.gvsig.app.project.ProjectManager;
40 40
import org.gvsig.app.project.documents.AbstractDocument;
41 41
import org.gvsig.app.project.documents.DocumentManager;
42
import org.gvsig.fmap.dal.DataStore;
42 43
import org.gvsig.fmap.dal.DataTypes;
44
import org.gvsig.fmap.dal.HasDataStore;
43 45
import org.gvsig.fmap.dal.exception.DataException;
44 46
import org.gvsig.fmap.dal.feature.Feature;
45 47
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
......
68 70
/**
69 71
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
70 72
 */
71
public class TableDocument extends AbstractDocument implements Observer {
73
public class TableDocument extends AbstractDocument implements HasDataStore, Observer {
72 74

  
73 75
    public static final String TABLE_PROPERTIES_PAGE_GROUP = "TableDocument";
74 76

  
......
244 246
        return store;
245 247
    }
246 248

  
249
    @Override
250
    public FeatureStore getDataStore() {
251
        return store;
252
    }
253
    
254
    
255

  
247 256
    /**
248 257
     * @return the store
249 258
     */
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/symboltables/ProjectSymbolTable.java
1 1
package org.gvsig.app.project.symboltables;
2 2

  
3
import com.sun.corba.se.impl.protocol.FullServantCacheLocalCRDImpl;
4 3
import java.io.File;
5 4
import java.io.FileInputStream;
6 5
import java.util.HashMap;
......
20 19
import org.gvsig.expressionevaluator.Expression;
21 20
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
22 21
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
22
import org.gvsig.expressionevaluator.ExpressionRuntimeException;
23 23
import org.gvsig.expressionevaluator.Interpreter;
24 24
import org.gvsig.expressionevaluator.spi.AbstractFunction;
25 25
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable;
26 26
import org.gvsig.fmap.crs.CRSFactory;
27 27
import org.gvsig.fmap.dal.DALLocator;
28 28
import org.gvsig.fmap.dal.DataManager;
29
import org.gvsig.fmap.dal.HasDataStore;
29 30
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
30 31
import org.gvsig.fmap.dal.feature.Feature;
31 32
import org.gvsig.fmap.dal.feature.FeatureQuery;
32
import org.gvsig.fmap.dal.feature.FeatureSelection;
33 33
import org.gvsig.fmap.dal.feature.FeatureSet;
34 34
import org.gvsig.fmap.dal.feature.FeatureStore;
35 35
import org.gvsig.fmap.geom.Geometry;
36 36
import org.gvsig.fmap.geom.primitive.Point;
37 37
import org.gvsig.fmap.mapcontext.MapContext;
38 38
import org.gvsig.fmap.mapcontext.layers.FLayer;
39
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
40 39
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
41 40
import org.gvsig.fmap.mapcontrol.AreaAndPerimeterCalculator;
42 41
import org.gvsig.temporarystorage.TemporaryStorageGroup;
......
58 57
        
59 58
    static final String NAME = "Project";
60 59
    
60
    private static final String TABLE_DOCUMENT_TYPENAME = "project.document.table";
61
    
61 62
    private abstract class CachedValue<T> {
62 63

  
63 64
        T value = null;
......
143 144

  
144 145
    }
145 146

  
146
    private class FirstSelectedFeatureFunction extends AbstractFunction {
147

  
148
        public FirstSelectedFeatureFunction() {
149
            super(
150
                    "Project",
151
                    "firstSelectedFeature",
152
                    Range.between(3, 4),
153
                    "Access to the first selected feature of the layer, and "
154
                    + "return the value of the attribute.",
155
                    "firstSelectedFeature({{view}}, layer, attribute, defaulValue)",
156
                    new String[]{
157
                        "view - String value with the name of a view",
158
                        "layer - String value with the name of a layer in the indicated view",
159
                        "attribute - String value with the name of the attribute in the indicated layer",
160
                        "defaultValue - Optional. Value to use if the indicated "
161
                        + "attribute can not be accessed. For example, if the "
162
                        + "view or layer does not exist, or it does not have "
163
                        + "selected elements."
164
                    },
165
                    "Object"
166
            );
167
        }
168

  
169
        @Override
170
        public Object call(Interpreter interpreter, Object[] args) throws Exception {
171
            Object defaultValue = null;
172
            String viewName = getStr(args, 0);
173
            String layerName = getStr(args, 1);
174
            String attrName = getStr(args, 2);
175
            if (args.length == 4) {
176
                defaultValue = getObject(args, 3);
177
            }
178
            try {
179
                Project project = currentProject.get();
180
                ViewDocument view = (ViewDocument) project.getDocument(viewName, ViewManager.TYPENAME);
181
                if (view == null) {
182
                    return defaultValue;
183
                }
184
                FLayer layer = view.getLayer(layerName);
185
                if (!(layer instanceof FLyrVect)) {
186
                    return defaultValue;
187
                }
188
                FeatureSelection selection = ((FLyrVect) layer).getFeatureStore().getFeatureSelection();
189
                if (selection == null || selection.isEmpty()) {
190
                    return defaultValue;
191
                }
192
                Feature feature = selection.first();
193
                if (feature == null) {
194
                    return defaultValue;
195
                }
196
                return feature.get(attrName);
197
            } catch (Exception ex) {
198
                return defaultValue;
199
            }
200
        }
201

  
202
    }
203

  
204 147
    private class StoreFunction extends AbstractFunction {
205
        
148

  
206 149
        public StoreFunction() {
207 150
            super(
208 151
                    "Project",
......
228 171
        public Object call(Interpreter interpreter, Object[] args) throws Exception {
229 172
            Project project = currentProject.get();
230 173
            switch (args.length) {
231
//                case 1:
232
//                    String tableName = getStr(args, 0);
233
//                    TableDocument table = (TableDocument) project.getDocument(tableName, TableManager.TYPENAME);
234
//                    if (table == null) {
235
//                        return null;
236
//                    }
237
//                    return table.getFeatureStore();
238
//                    break;
174
                case 1:
175
                    String tableName = getStr(args, 0);
176
                    Document document = project.getDocument(tableName, TABLE_DOCUMENT_TYPENAME);
177
                    if (document == null) {
178
                        return null;
179
                    }
180
                    if( document instanceof HasDataStore ) {
181
                        return ((HasDataStore) document).getDataStore();
182
                    }
183
                    return null;
184

  
239 185
                case 2:
240 186
                    String viewName = getStr(args, 0);
241 187
                    String layerName = getStr(args, 1);
......
244 190
                        return null;
245 191
                    }
246 192
                    FLayer layer = view.getLayer(layerName);
247
                    if( !(layer instanceof SingleLayer ) ) {
248
                        return null;
193
                    if( layer instanceof HasDataStore ) {
194
                        return ((HasDataStore)layer).getDataStore();
249 195
                    }
250
                    return ((SingleLayer)layer).getDataStore();
196
                    return null;
251 197
            }
252 198
            return null;
253 199
        }
......
276 222

  
277 223
        @Override
278 224
        public Object call(Interpreter interpreter, Object[] args) throws Exception {
279
            Object value = null;
225
            Object value;
280 226
            String where = null;
281 227
            String order = null;
282 228
            String expression_s = getStr(args, 0);
283 229
            FeatureStore store = (FeatureStore) getObject(args, 1);
284 230
            switch (args.length) {
285
                case 2:
231
                case 3:
286 232
                    where = getStr(args, 2);
287 233
                    break;
288 234
                case 4:
......
320 266
                
321 267
                return value;
322 268
            } catch (Exception ex) {
323
                return null;
269
                throw new ExpressionRuntimeException("Problems calling '"+FETCH_FIRST_NAME+"' function", ex);
324 270
            }
325 271
        }
326 272
    }
......
362 308
                
363 309
                return value;
364 310
            } catch (Exception ex) {
365
                return null;
311
                throw new ExpressionRuntimeException("Problems calling '"+FETCH_FIRST_SELECTED_NAME+"' function", ex);
366 312
            }
367 313
        }
368 314
    }
......
590 536
    public ProjectSymbolTable() {
591 537
        super(NAME);
592 538
        this.addFunction(new CurrentProjectFunction());
593
        this.addFunction(new FirstSelectedFeatureFunction());
594 539
        this.addFunction(new StoreFunction());
595 540
        this.addFunction(new FetchFirstFunction());
596 541
        this.addFunction(new FetchFirstSelectedFunction());
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/InitializeApplicationExtension.java
53 53
import org.gvsig.fmap.dal.DALLocator;
54 54
import org.gvsig.fmap.dal.DataManager;
55 55
import org.gvsig.fmap.dal.OpenErrorHandler;
56
import org.gvsig.fmap.dal.feature.DataProfile;
56
import org.gvsig.fmap.dal.feature.AbstractDataProfile;
57 57
import org.gvsig.fmap.dal.resource.ResourceManager;
58 58
import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException;
59 59
import org.gvsig.installer.lib.api.InstallerLocator;
......
75 75

  
76 76
    private OpenErrorHandler openErrorHandler = null;
77 77

  
78
    private static class SimpleImageDataProfile extends AbstractDataProfile {
79

  
80
        public SimpleImageDataProfile() {
81
            super("Image", SimpleImage.class);
82
        }
83
        
84
        @Override
85
        public Object createData(Object data) {
86
            final ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
87
            SimpleImage image = toolsSwingManager.createSimpleImage(data);
88
            return image;
89
        }
90
    }
91
    
78 92
    @Override
79 93
    public void initialize() {
80

  
81
        final ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
82 94
        DALLocator.registerFeatureTypeDefinitionsManager(DefaultFeatureTypeDefinitionsManager.class);
83 95
        
84 96
        DataManager dataManager = DALLocator.getDataManager();
85
        dataManager.registerDataProfile(new DataProfile() {
86
            @Override
87
            public String getName() {
88
                return "Image";
89
            }
90

  
91
            @Override
92
            public Object createData(Object data) {
93
                SimpleImage image = toolsSwingManager.createSimpleImage(data);
94
                return data;
95
            }
96
        });
97
        dataManager.registerDataProfile(new SimpleImageDataProfile());
97 98
        
98 99
        InfoListener.initializeExtensionPoint();
99 100

  
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/DefaultFeatureTypeDefinitionsManager.java
18 18
import org.gvsig.andami.PluginsLocator;
19 19
import org.gvsig.andami.PluginsManager;
20 20
import org.gvsig.fmap.dal.DataServerExplorer;
21
import org.gvsig.fmap.dal.DataServerExplorer.DataResource;
21 22
import org.gvsig.fmap.dal.feature.AbstractFeatureTypeDefinitionsManager;
22 23
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
23 24
import org.gvsig.fmap.dal.feature.FeatureStore;
......
94 95
        } catch (IOException ex) {
95 96
            return null;
96 97
        }
97
        File f = new File(folder, key + ".xml");
98
        File f = new File(folder, key + ".ftd");
98 99
        if (f.exists()) {
99 100
            return f;
100 101
        }
......
135 136
            DataServerExplorer explorer = null;
136 137
            try {
137 138
                explorer = store.getExplorer();
138
                definitionFile = explorer.getResourcePath(store, key+".xml");
139
                DataResource resource = explorer.getResource(store, key+".ftd");
140
                if( resource !=null && resource.getURL()!=null ) {
141
                    // FIXME; use resource.asInputStream() instead resource.getURL()
142
                    definitionFile = new File(resource.getURL().toURI());
143
                }
139 144
            } catch(Exception ex) {
140 145
                // Do nothing, leave definitionFile to null
141 146
            } finally {
142 147
                DisposeUtils.disposeQuietly(explorer);
143 148
            }
144 149
            if( definitionFile == null || !definitionFile.exists()) {
145
                return featureType;
150
                return this.getDynClass(featureType);
146 151
            }
147 152
        }
148 153
        DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager();
......
164 169
        if (dynClass != null) {
165 170
            return dynClass;
166 171
        }
167
        return featureType;
172
        return this.getDynClass(featureType);
168 173
    }
169 174

  
170 175
    @Override
......
176 181
    @Override
177 182
    public void add(FeatureStore store, FeatureType featureType, DynClass dynClass) {
178 183
        try {
184
            if( dynClass instanceof FeatureType ) {
185
                dynClass = this.getDynClass((FeatureType) dynClass);
186
            }
179 187
            String key = this.getKey(store, featureType);
180
            File f = new File(getDefinitionsFolder(), key + ".xml");
188
            File f = new File(getDefinitionsFolder(), key + ".ftd");
181 189
            DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager();
182 190
            String xml = dynObjectManager.exportSimpleDynClassDefinitions(dynClass);
183 191
            FileUtils.write(f, xml);
......
234 242
          }
235 243
    }
236 244

  
245
    private DynClass getDynClass(FeatureType featureType) {
246
        return featureType;
247
//        DynObjectManager manager = ToolsLocator.getDynObjectManager();
248
//        DynClass x = manager.createCopy(featureType);
249
//        // FIXME: Aqui falta a?adir el arreglo del subtype
250
//        return x;
251
    }
237 252
}

Also available in: Unified diff