Revision 44094

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.api/src/main/java/org/gvsig/expressionevaluator/swing/ExpressionPickerController.java
9 9
 */
10 10
public interface ExpressionPickerController 
11 11
        extends PickerController<Expression>, ExpressionBuilderConfig {
12
    
12

  
13
    public void unbind();
13 14
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/java/org/gvsig/expressionevaluator/swing/impl/DefaultExpressionPickerController.java
1 1
package org.gvsig.expressionevaluator.swing.impl;
2 2

  
3
import java.awt.MenuItem;
3 4
import java.awt.event.ActionEvent;
4 5
import java.awt.event.ActionListener;
5 6
import java.net.URL;
......
9 10
import javax.swing.Action;
10 11
import javax.swing.ImageIcon;
11 12
import javax.swing.JButton;
13
import javax.swing.JMenuItem;
12 14
import javax.swing.JPopupMenu;
13 15
import javax.swing.text.JTextComponent;
14 16
import org.apache.commons.lang3.StringUtils;
......
57 59
    private Expression value;
58 60
    private ExpressionBuilderConfig config;
59 61
    private final ExpressionEvaluatorSwingManager manager;
62
    private final ActionListener buttonAction;
63
    private final JMenuItem menuItem;
60 64
    
61 65
    public DefaultExpressionPickerController(ExpressionEvaluatorSwingManager manager, JTextComponent text, JButton button) {
62 66
        ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager();
......
68 72
        this.button = button;
69 73
        this.value = ExpressionEvaluatorLocator.getManager().createExpression();
70 74
        this.button.setIcon(this.getIcon("picker-expression"));
71
        this.button.addActionListener(new ActionListener() {
75
        this.buttonAction = new ActionListener() {
72 76
            @Override
73 77
            public void actionPerformed(ActionEvent e) {
74 78
                doSelectExpression();
75 79
            }
76
        });
80
        };
81
        this.button.addActionListener(this.buttonAction);
77 82

  
78 83
        swingManager.addClearButton(this.text);
79 84
        swingManager.setDefaultPopupMenu(this.text);
80 85
        JPopupMenu popupMenu = this.text.getComponentPopupMenu();
81
        Action showExpressionBuilderAction = new AbstractAction(i18n.getTranslation("_Show_expression_builder")) {
82
            @Override
83
            public void actionPerformed(ActionEvent e) {
84
                doSelectExpression();
85
            }
86
        };  
87
        popupMenu.addSeparator();
88
        popupMenu.add(showExpressionBuilderAction);
86
        this.menuItem = new JMenuItem(i18n.getTranslation("_Show_expression_builder"));
87
        this.menuItem.addActionListener(buttonAction);
88
        popupMenu.add(this.menuItem);
89 89
    }
90 90
    
91
    @Override
92
    public void unbind() {
93
        this.button.removeActionListener(this.buttonAction);
94
        JPopupMenu popupMenu = this.text.getComponentPopupMenu();
95
        popupMenu.remove(this.menuItem);
96
    }
97
    
91 98
    private void doSelectExpression() {
92 99
        this.value.setPhrase(this.text.getText());
93 100

  
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/FeatureProvider.java
74 74

  
75 75
	public void setDefaultGeometry(Geometry geom);
76 76

  
77
        public void setDefautltTime(Time time);
77
        public void setDefaultTime(Time time);
78 78
        
79 79
	public boolean isNull(int i);
80 80

  
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/memory/MemoryFeatureProviderAttributeMapper.java
32 32
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
33 33
import org.gvsig.fmap.geom.Geometry;
34 34
import org.gvsig.fmap.geom.primitive.Envelope;
35
import org.gvsig.timesupport.Time;
35 36

  
36 37
/**
37 38
 * Envuelve un FeatureProvider en memoria para que muestre un FeautureType
......
45 46
 *
46 47
 */
47 48
public class MemoryFeatureProviderAttributeMapper implements FeatureProvider {
48
	private DefaultFeatureProvider original;
49
	private FeatureType myFeatureType;
49
	private final DefaultFeatureProvider original;
50
	private final FeatureType myFeatureType;
50 51

  
51 52
	/**
52 53
	 * Default constructor.
......
213 214
		original.setOID(oid);
214 215
	}
215 216

  
217
    @Override
218
    public Time getDefaultTime() {
219
        return original.getDefaultTime();
220
    }
221

  
222
    @Override
223
    public void setDefaultTime(Time time) {
224
        original.setDefaultTime(time);
225
    }
226

  
216 227
}
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
16 16
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
17 17
import org.gvsig.fmap.dal.feature.FeatureStore;
18 18
import org.gvsig.fmap.dal.feature.FeatureType;
19
import org.gvsig.timesupport.RelativeInterval;
20
import org.gvsig.timesupport.TimeSupportLocator;
19 21
import org.gvsig.tools.ToolsLocator;
20 22
import org.gvsig.tools.dynobject.DynStruct;
21 23
import org.gvsig.tools.persistence.PersistenceManager;
......
24 26
import org.gvsig.tools.persistence.exception.PersistenceException;
25 27

  
26 28

  
29
@SuppressWarnings("UseSpecificCatch")
27 30
public class DALFile implements Persistent {
28 31

  
29 32
    private static final String DALFILE_PERSISTENCE_DEFINITION_NAME = "DALFile";
30
    private static final String CALCULATEDATTRIBUTE_PERSISTENCE_DEFINITION_NAME = "DALFileCalculatedAttribute";
33
    private static final String ATTRIBUTE_PERSISTENCE_DEFINITION_NAME = "DALFileAttribute";
31 34
    
32 35
    public static DALFile getDALFile() {
33 36
        DALFile f = new DALFile();
......
50 53
                null, 
51 54
                null
52 55
            );
53
            definition.addDynFieldList("calculatedAttributes")
54
                .setClassOfItems(CalculatedAttribute.class)
56
            definition.addDynFieldList("attributes")
57
                .setClassOfItems(Attribute.class)
55 58
                .setMandatory(true)
56 59
                .setPersistent(true);
57 60
        }
58
        if (manager.getDefinition(CALCULATEDATTRIBUTE_PERSISTENCE_DEFINITION_NAME) == null) {
61
        if (manager.getDefinition(ATTRIBUTE_PERSISTENCE_DEFINITION_NAME) == null) {
59 62
            DynStruct definition = manager.addDefinition(
60
                CalculatedAttribute.class,
61
                CALCULATEDATTRIBUTE_PERSISTENCE_DEFINITION_NAME, 
62
                CALCULATEDATTRIBUTE_PERSISTENCE_DEFINITION_NAME + " Persistent definition", 
63
                Attribute.class,
64
                ATTRIBUTE_PERSISTENCE_DEFINITION_NAME, 
65
                ATTRIBUTE_PERSISTENCE_DEFINITION_NAME + " Persistent definition", 
63 66
                null, 
64 67
                null
65 68
            );
......
80 83
    }
81 84

  
82 85
    
83
    public static class CalculatedAttribute implements Persistent {
86
    public static class Attribute implements Persistent {
84 87

  
85 88
        private String name;
86 89
        private int type;
87 90
        private FeatureAttributeEmulator emulator;
88 91
        private int featureTypeIndex;
92
        private RelativeInterval interval;
89 93
        
90
        public CalculatedAttribute() {
94
        public Attribute() {
91 95
            
92 96
        }
93 97

  
94
        private CalculatedAttribute(int featureTypeIndex, FeatureAttributeDescriptor attrdesc) {
98
        private Attribute(int featureTypeIndex, FeatureAttributeDescriptor attrdesc) {
95 99
            this.featureTypeIndex = featureTypeIndex;
96 100
            this.name = attrdesc.getName();
97 101
            this.type = attrdesc.getType();
98 102
            this.emulator = attrdesc.getFeatureAttributeEmulator();
103
            if( attrdesc.getInterval().isRelative() ) {
104
                this.interval = (RelativeInterval) attrdesc.getInterval();
105
            } else {
106
                this.interval = null;
107
            }
99 108
        }
100 109

  
110
        public boolean needPersist() {
111
            if( emulator!= null && emulator instanceof Persistent ) {
112
                return true;
113
            }
114
            if( this.interval!=null ) {
115
                return true;
116
            }
117
            return false;
118
        }
119
        
101 120
        @Override
102 121
        public void saveToState(PersistentState state) throws PersistenceException {
103 122
            state.set("name", name);
104 123
            state.set("type", type);
105 124
            state.set("featureTypeIndex", featureTypeIndex);
106 125
            state.set("emulator", emulator);
126
            if( this.interval!=null ) {
127
                state.set("intervalStart", interval.getStart().toMillis());
128
                state.set("intervalEnd", interval.getEnd().toMillis());
129
            } else {
130
                state.setNull("intervalStart");
131
                state.setNull("intervalEnd");
132
            }
107 133
        }
108 134

  
109 135
        @Override
......
112 138
            this.type = state.getInt("type");
113 139
            this.featureTypeIndex = state.getInt("featureTypeIndex");
114 140
            this.emulator = (FeatureAttributeEmulator) state.get("emulator");
141
            if( state.get("intervalStart")!=null ) {
142
                this.interval = TimeSupportLocator.getManager().createRelativeInterval(
143
                        state.getLong("intervalStart"), 
144
                        state.getLong("intervalEnd")
145
                );
146
            }
115 147
        }
148

  
149
        private void fetch(DefaultFeatureAttributeDescriptor attrdesc) {
150
            attrdesc.setDataType(this.type);
151
            attrdesc.setName(this.name);
152
            attrdesc.setFeatureAttributeEmulator(this.emulator);
153
            attrdesc.setInterval(this.interval);
154
        }
116 155
        
117 156
        
118 157
    }
119 158
    
120
    private final List<CalculatedAttribute> calculatedAttributes;
159
    private final List<Attribute> attributes;
121 160
    
122 161
    public DALFile() {
123
        this.calculatedAttributes = new ArrayList<>();
162
        this.attributes = new ArrayList<>();
124 163
    }
125 164

  
126 165
    public boolean isEmpty() {
127
        if( CollectionUtils.isEmpty(this.calculatedAttributes) ) {
166
        if( CollectionUtils.isEmpty(this.attributes) ) {
128 167
            return true;
129 168
        }
130 169
        return false;
......
144 183
        }
145 184
    }
146 185

  
147
    @SuppressWarnings("UseSpecificCatch")
148 186
    public void read(File f) {
149 187
        FileInputStream in = null;
150 188
        try {
151 189
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
152 190
            in = new FileInputStream(f);
153 191
            DALFile x = (DALFile) manager.getObject(in);
154
            this.calculatedAttributes.clear();
155
            this.calculatedAttributes.addAll(x.calculatedAttributes);
192
            this.attributes.clear();
193
            this.attributes.addAll(x.attributes);
156 194
        } catch(Exception ex) {
157 195
            throw new RuntimeException("Can't read DAL file.",ex);
158 196
        } finally {
......
161 199
    }
162 200

  
163 201
    public void setStore(FeatureStore store) throws DataException {
164
        this.calculatedAttributes.clear();
202
        this.attributes.clear();
165 203
        
166 204
        List<FeatureType> types = store.getFeatureTypes();
167 205
        for( int n=0; n<types.size(); n++ ) {
168 206
            FeatureType type = types.get(n);
169 207
                for (FeatureAttributeDescriptor attrdesc : type) {
170
                    FeatureAttributeEmulator emulator = attrdesc.getFeatureAttributeEmulator();
171
                    if( emulator!= null && emulator instanceof Persistent ) {
172
                        CalculatedAttribute calculatedAttribute = new CalculatedAttribute(n,attrdesc);
173
                        this.calculatedAttributes.add(calculatedAttribute);
208
                    Attribute attribute = new Attribute(n,attrdesc);
209
                    if( attribute.needPersist() ) {
210
                        this.attributes.add(attribute);
174 211
                    }
175 212
            }
176 213
        }
......
180 217
        List<FeatureType> types = store.getFeatureTypes();
181 218
        Set<DefaultFeatureType> needFixTypes = new HashSet<>();
182 219
        
183
        for (CalculatedAttribute calculatedAttribute : calculatedAttributes) {
184
            DefaultFeatureType ft = (DefaultFeatureType) types.get(calculatedAttribute.featureTypeIndex);
185
            DefaultFeatureAttributeDescriptor attrdesc = new DefaultFeatureAttributeDescriptor(ft);
186
            attrdesc.setDataType(calculatedAttribute.type);
187
            attrdesc.setName(calculatedAttribute.name);
188
            attrdesc.setFeatureAttributeEmulator(calculatedAttribute.emulator);
189
            ft.add(attrdesc);
220
        for (Attribute attribute : this.attributes) {
221
            DefaultFeatureType ft = (DefaultFeatureType) types.get(attribute.featureTypeIndex);
222
            DefaultFeatureAttributeDescriptor attrdesc = (DefaultFeatureAttributeDescriptor) ft.get(attribute.name);
223
            if( ft.get(attribute.name)==null ) {
224
                attrdesc = new DefaultFeatureAttributeDescriptor(ft);
225
                attribute.fetch(attrdesc);
226
                ft.add(attrdesc);
227
            } else {
228
                attribute.fetch(attrdesc);
229
            }
190 230
            needFixTypes.add(ft);
191 231
        }
192 232
        for (DefaultFeatureType type : needFixTypes) {
......
196 236

  
197 237
    @Override
198 238
    public void saveToState(PersistentState state) throws PersistenceException {
199
        state.set("calculatedAttributes", calculatedAttributes);
239
        state.set("attributes", attributes);
200 240
    }
201 241

  
202 242
    @Override
203 243
    public void loadFromState(PersistentState state) throws PersistenceException {
204
        this.calculatedAttributes.clear();
205
        Iterator<CalculatedAttribute> it = state.getIterator("calculatedAttributes");
244
        this.attributes.clear();
245
        Iterator<Attribute> it = state.getIterator("attributes");
206 246
        while( it.hasNext() ) {
207
            CalculatedAttribute calculatedAttribute = it.next();
208
            this.calculatedAttributes.add(calculatedAttribute);
247
            Attribute attribute = it.next();
248
            this.attributes.add(attribute);
209 249
        }
210 250
    }
211 251

  
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/DefaultFeatureType.java
822 822
        while (iter.hasNext()) {
823 823
            attr = (DefaultFeatureAttributeDescriptor) iter.next();
824 824
            attr.setIndex(i++);
825
            if (attr instanceof DefaultEditableFeatureAttributeDescriptor) {
826
                ((DefaultEditableFeatureAttributeDescriptor) attr).fixAll();
827
            }
825
            attr.fixAll();
828 826
            if (attr.getEvaluator() != null) {
829 827
                this.hasEvaluators = true;
830 828
            }
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
28 28
import org.apache.commons.lang3.StringUtils;
29 29

  
30 30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.dal.DataTypes;
32 31
import org.slf4j.Logger;
33 32
import org.slf4j.LoggerFactory;
34 33

  
......
50 49
    private static Logger logger = LoggerFactory.getLogger(
51 50
        DefaultEditableFeatureAttributeDescriptor.class);
52 51

  
53
    private DefaultFeatureAttributeDescriptor source;
52
    private final DefaultFeatureAttributeDescriptor source;
54 53
    private boolean hasStrongChanges;
55 54
    private String originalName = null;
56 55

  
......
77 76
    public DefaultFeatureAttributeDescriptor getSource() {
78 77
        return this.source;
79 78
    }
80

  
79
    
81 80
    public void fixAll() {
82
        switch(this.getType()) {
83
            case DataTypes.INSTANT:
84
            case DataTypes.INTERVAL:
85
            case DataTypes.DATE:
86
                if( this.getInterval()!=null ) {
87
                    this.isTime = true;
88
                }
89
                break;
90
        }
81
        super.fixAll();
91 82
    }
92

  
83
    
93 84
    public void checkIntegrity() throws AttributeFeatureTypeIntegrityException {
94 85
        AttributeFeatureTypeIntegrityException ex =
95 86
            new AttributeFeatureTypeIntegrityException(getName());
......
263 254
    }
264 255

  
265 256
    public EditableFeatureAttributeDescriptor setInterval(Interval interval) {
266
        this.interval = interval;
257
        super.setInterval(interval);
267 258
        if (!isComputed()) {
268 259
            hasStrongChanges = true;
269 260
        }
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/DefaultFeatureAttributeDescriptor.java
34 34
import org.gvsig.fmap.crs.CRSFactory;
35 35
import org.gvsig.fmap.dal.DataStore;
36 36
import org.gvsig.fmap.dal.DataTypes;
37
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
37 38
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
38 39
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
39 40
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter;
......
1045 1046
        }
1046 1047
        return (FeatureType) this.typeRef.get();
1047 1048
    }
1049

  
1050
    public FeatureAttributeDescriptor setInterval(Interval interval) {
1051
        this.interval = interval;
1052
        return this;
1053
    }
1054

  
1055
    public void fixAll() {
1056
        switch(this.getType()) {
1057
            case DataTypes.INSTANT:
1058
            case DataTypes.INTERVAL:
1059
            case DataTypes.DATE:
1060
                if( this.getInterval()!=null ) {
1061
                    this.isTime = true;
1062
                }
1063
                break;
1064
        }
1065
    }
1066

  
1048 1067
}
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/fmap/dal/swing/impl/featuretype/DefaultFeatureTypeAttributePanel.java
299 299
            this.clean();
300 300
            return;
301 301
        }
302
        if (!(descriptor instanceof EditableFeatureAttributeDescriptor)) {
303
            this.setEditable(false);
302
        ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager();
303
        if( this.pickerVirtualField!=null ) {
304
            this.pickerVirtualField.unbind();
304 305
        }
305
        ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager();
306 306
        this.pickerVirtualField = ExpressionEvaluatorSwingLocator.getManager()
307 307
                .createExpressionPickerController(txtVirtualField, btnVirtualField);
308 308
        if( descriptor.getFeatureType()!=null && descriptor.getFeatureType().getStore()!=null ) {
......
314 314
                )
315 315
            );
316 316
        }
317
        if (!(descriptor instanceof EditableFeatureAttributeDescriptor)) {
318
            this.setEditable(false);
319
        }
317 320
                
318 321
        this.pickerDefaultValue.set(descriptor.getDefaultValue());
319 322
        this.pickerFieldName.set(descriptor.getName());

Also available in: Unified diff