Index: DefaultFeatureTypeAttributePanel.java
===================================================================
--- DefaultFeatureTypeAttributePanel.java	(revision 44084)
+++ DefaultFeatureTypeAttributePanel.java	(revision 44085)
@@ -1,23 +1,36 @@
 package org.gvsig.fmap.dal.swing.impl.featuretype;
 
+import com.vividsolutions.jts.operation.distance.GeometryLocation;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JComponent;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
 import org.cresques.cts.IProjection;
 import org.gvsig.expressionevaluator.Expression;
 import org.gvsig.expressionevaluator.swing.CalculatorController;
 import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator;
 import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager;
 import org.gvsig.expressionevaluator.swing.ExpressionPickerController;
+import org.gvsig.fmap.dal.DALLocator;
+import org.gvsig.fmap.dal.DataManager;
 import org.gvsig.fmap.dal.DataTypes;
 import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression;
 import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
 import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
 import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
 import org.gvsig.fmap.dal.swing.DALSwingLocator;
+import org.gvsig.fmap.dal.swing.DataSwingManager;
 import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.GeometryLocator;
+import org.gvsig.fmap.geom.GeometryManager;
+import org.gvsig.fmap.geom.type.GeometryType;
 import org.gvsig.timesupport.RelativeInterval;
 import org.gvsig.tools.ToolsLocator;
 import org.gvsig.tools.dataTypes.DataTypesManager;
@@ -26,20 +39,21 @@
 import org.gvsig.tools.swing.api.ToolsSwingManager;
 import org.gvsig.tools.swing.api.pickercontroller.DatePickerController;
 import org.gvsig.tools.swing.api.pickercontroller.PickerController;
+import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
 
 /**
  *
  * @author jjdelcerro
  */
-public class DefaultFeatureTypeAttributePanel 
-        extends FeatureTypeAttributePanelView 
-        implements FeatureTypeAttributePanel 
-    {
+@SuppressWarnings("UseSpecificCatch")
+public class DefaultFeatureTypeAttributePanel
+        extends FeatureTypeAttributePanelView
+        implements FeatureTypeAttributePanel {
 
     private final List<ListElement<Integer>> fieldTypes;
     private final List<ListElement<Integer>> geometryTypes;
     private final List<ListElement<Integer>> geometrySubtypes;
-    
+
     private DatePickerController pickerIntervalEnd;
     private DatePickerController pickerIntervalStart;
     private CalculatorController<Integer> pickerSize;
@@ -49,8 +63,10 @@
     private PickerController<IProjection> pickerCRS;
     private ExpressionPickerController pickerVirtualField;
 
+    private boolean editable;
 
     public DefaultFeatureTypeAttributePanel() {
+        this.editable = true;
         DataTypesManager dataManager = ToolsLocator.getDataTypesManager();
         this.fieldTypes = new ArrayList<>();
         this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.BOOLEAN), DataTypes.BOOLEAN));
@@ -61,8 +77,9 @@
         this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.DOUBLE), DataTypes.DOUBLE));
         this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.LONG), DataTypes.LONG));
         this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.INTERVAL), DataTypes.INTERVAL));
-        this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.DOUBLE), DataTypes.DOUBLE));
+        this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.INSTANT), DataTypes.INSTANT));
         this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.STRING), DataTypes.STRING));
+        this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.GEOMETRY), DataTypes.GEOMETRY));
         this.fieldTypes.sort(new Comparator<ListElement<Integer>>() {
             @Override
             public int compare(ListElement<Integer> o1, ListElement<Integer> o2) {
@@ -83,7 +100,7 @@
                 return o1.toString().compareTo(o2.toString());
             }
         });
-        
+
         this.geometrySubtypes = new ArrayList<>();
         this.geometrySubtypes.add(new ListElement("2D", Geometry.SUBTYPES.GEOM2D));
         this.geometrySubtypes.add(new ListElement("2DM", Geometry.SUBTYPES.GEOM3D));
@@ -95,10 +112,10 @@
                 return o1.toString().compareTo(o2.toString());
             }
         });
-        
+
         this.initComponents();
     }
-    
+
     private void initComponents() {
         ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager();
         ExpressionEvaluatorSwingManager evaluatorManager = ExpressionEvaluatorSwingLocator.getManager();
@@ -119,15 +136,16 @@
         for (ListElement<Integer> element : this.geometrySubtypes) {
             modelGeomSubtypes.addElement(element);
         }
-        this.cboGeometryType.setModel(modelGeomSubtypes);
-        
+
+        this.cboGeometrySubtype.setModel(modelGeomSubtypes);
+
         swingManager.addClearButton(this.txtDefaultValue);
         swingManager.addClearButton(this.txtFieldName);
         swingManager.addClearButton(this.txtIntervalEnd);
         swingManager.addClearButton(this.txtIntervalStart);
         swingManager.addClearButton(this.txtPrecision);
         swingManager.addClearButton(this.txtSize);
-        
+
         swingManager.setDefaultPopupMenu(this.txtDefaultValue);
         swingManager.setDefaultPopupMenu(this.txtFieldName);
         swingManager.setDefaultPopupMenu(this.txtIntervalEnd);
@@ -138,36 +156,60 @@
         swingManager.setDefaultPopupMenu(this.cboFieldType);
         swingManager.setDefaultPopupMenu(this.cboGeometrySubtype);
         swingManager.setDefaultPopupMenu(this.cboGeometryType);
-        
+
         this.pickerIntervalEnd = swingManager.createDatePickerController(
-                this.txtIntervalEnd, 
+                this.txtIntervalEnd,
                 this.btnIntervalEnd
         );
         this.pickerIntervalStart = swingManager.createDatePickerController(
-                this.txtIntervalStart, 
+                this.txtIntervalStart,
                 this.btnIntervalStart
         );
         this.pickerSize = evaluatorManager.createCalculatorController(
-                this.txtSize,DataTypes.INT
+                this.txtSize, DataTypes.INT
         );
         this.pickerPrecision = evaluatorManager.createCalculatorController(
-                this.txtPrecision,DataTypes.INT
+                this.txtPrecision, DataTypes.INT
         );
         this.pickerFieldName = evaluatorManager.createCalculatorController(
-                this.txtFieldName,DataTypes.STRING
+                this.txtFieldName, DataTypes.STRING
         );
         this.pickerDefaultValue = evaluatorManager.createCalculatorController(
-                this.txtDefaultValue,DataTypes.OBJECT
+                this.txtDefaultValue, DataTypes.OBJECT
         );
-        
+
+        this.btnVirtualField.setText("");
         this.pickerVirtualField = ExpressionEvaluatorSwingLocator.getManager()
                 .createExpressionPickerController(txtVirtualField, btnVirtualField);
 
         this.pickerCRS = DALSwingLocator.getSwingManager()
                 .createProjectionPickerController(this.txtCRS, this.btnCRS);
-        
+
+        this.cboFieldType.addItemListener(new ItemListener() {
+            @Override
+            public void itemStateChanged(ItemEvent e) {
+                SwingUtilities.invokeLater(new Runnable() {
+                    @Override
+                    public void run() {
+                        doFieldTypeChanged();
+                    }
+                });
+
+            }
+        });
+
+        this.chkVirtualField.addChangeListener(new ChangeListener() {
+            @Override
+            public void stateChanged(ChangeEvent e) {
+                if (chkVirtualField.isSelected()) {
+                    pickerVirtualField.setEnabled(editable);
+                } else {
+                    pickerVirtualField.setEnabled(false);
+                }
+            }
+        });
     }
-    
+
     @Override
     public JComponent asJComponent() {
         return this;
@@ -175,6 +217,56 @@
 
     @Override
     public EditableFeatureAttributeDescriptor fetch(EditableFeatureAttributeDescriptor descriptor) {
+        try {
+            descriptor.setDataType((int) ListElement.getSelected(this.cboFieldType));
+            descriptor.setName(this.txtFieldName.getText());
+            descriptor.setAllowNull(this.chkAllowNulls.isSelected());
+            descriptor.setIsPrimaryKey(this.chkIsPrimaryKey.isSelected());
+            descriptor.setIsAutomatic(this.chkIsAutomatic.isSelected());
+            descriptor.setSize(this.pickerSize.get());
+            descriptor.setPrecision(this.pickerPrecision.get());
+            descriptor.setDefaultValue(this.pickerDefaultValue.get());
+            switch (descriptor.getType()) {
+                case DataTypes.GEOMETRY:
+                    GeometryManager geomManager = GeometryLocator.getGeometryManager();
+                    GeometryType geomType = geomManager.getGeometryType(
+                            (int) ListElement.getSelected(this.cboGeometryType),
+                            (int) ListElement.getSelected(this.cboGeometrySubtype)
+                    );
+                    descriptor.setGeometryType(geomType);
+                    descriptor.setSRS(this.pickerCRS.get());
+                    break;
+                case DataTypes.INSTANT:
+                case DataTypes.INTERVAL:
+                case DataTypes.DATE:
+                case DataTypes.TIME:
+                case DataTypes.TIMESTAMP:
+                    // FIXME
+                    break;
+                default:
+                    break;
+            }
+            if( this.chkVirtualField.isSelected() && this.pickerVirtualField.isEnabled() ) {
+                Expression expression = this.pickerVirtualField.get();
+                if( expression==null ) {
+                    descriptor.setFeatureAttributeEmulator(null);
+                } else {
+                    DataManager dataManager = DALLocator.getDataManager();
+                    FeatureAttributeEmulatorExpression emulator = dataManager.createFeatureAttributeEmulatorExpression(
+                            descriptor.getFeatureType(),
+                            expression
+                    );
+                    descriptor.setFeatureAttributeEmulator(emulator);
+                }
+            }
+        } catch (Exception ex) {
+            ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
+            dialogs.messageDialog(
+                    "Can't retrieve information from user form.", 
+                    "Warning", 
+                    JOptionPane.WARNING_MESSAGE
+            );
+        }
         return descriptor;
     }
 
@@ -189,75 +281,152 @@
         this.chkAllowNulls.setSelected(false);
         this.chkIsAutomatic.setSelected(false);
         this.chkIsPrimaryKey.setSelected(false);
-        
+
         this.chkVirtualField.setSelected(false);
-        this.chkVirtualField.setEnabled(true);
+        this.chkVirtualField.setEnabled(editable);
         this.pickerVirtualField.setEnabled(false);
         this.pickerVirtualField.set(null);
 
-        ListElement.setSelected(cboFieldType, null);
         ListElement.setSelected(cboGeometryType, null);
         ListElement.setSelected(cboGeometrySubtype, null);
+
+        ListElement.setSelected(cboFieldType, DataTypes.STRING);
     }
-    
+
     @Override
     public void put(FeatureAttributeDescriptor descriptor) {
-        if( descriptor == null ) {
+        if (descriptor == null) {
             this.clean();
             return;
         }
+        if (!(descriptor instanceof EditableFeatureAttributeDescriptor)) {
+            this.setEditable(false);
+        }
+        ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager();
+        this.pickerVirtualField = ExpressionEvaluatorSwingLocator.getManager()
+                .createExpressionPickerController(txtVirtualField, btnVirtualField);
+        if( descriptor.getFeatureType()!=null && descriptor.getFeatureType().getStore()!=null ) {
+            this.pickerVirtualField.addElement(
+                expressionSwingManager.createElement(
+                        DataSwingManager.FEATURE_STORE_EXPRESSION_ELEMENT,
+                        this.pickerVirtualField,
+                        descriptor.getFeatureType().getStore()
+                )
+            );
+        }
+                
         this.pickerDefaultValue.set(descriptor.getDefaultValue());
         this.pickerFieldName.set(descriptor.getName());
         RelativeInterval interval = (RelativeInterval) descriptor.getInterval();
-        if( interval==null ) {
-//            this.pickerIntervalEnd.set(null);
-//            this.pickerIntervalStart.set(null);
+        if (interval == null) {
+            this.pickerIntervalEnd.set(null);
+            this.pickerIntervalStart.set(null);
         } else {
             this.pickerIntervalEnd.set(interval.getEnd().toDate());
             this.pickerIntervalStart.set(interval.getStart().toDate());
         }
         this.pickerPrecision.set(descriptor.getPrecision());
         this.pickerSize.set(descriptor.getSize());
-        
+
         this.chkAllowNulls.setSelected(descriptor.allowNull());
         this.chkIsAutomatic.setSelected(descriptor.isAutomatic());
         this.chkIsPrimaryKey.setSelected(descriptor.isPrimaryKey());
-        
+
         FeatureAttributeEmulator attrEmulator = descriptor.getFeatureAttributeEmulator();
-        if( attrEmulator instanceof FeatureAttributeEmulatorExpression ) {
+        if (attrEmulator instanceof FeatureAttributeEmulatorExpression) {
             Expression expression = ((FeatureAttributeEmulatorExpression) attrEmulator).getExpression();
-            this.chkVirtualField.setEnabled(true);
+            this.chkVirtualField.setEnabled(editable);
             this.chkVirtualField.setSelected(true);
+            this.pickerVirtualField.setEnabled(editable);
             this.pickerVirtualField.set(expression);
-            this.pickerVirtualField.setEnabled(true);
-        } else if( descriptor.isComputed() ) {
+        } else if (descriptor.isComputed()) {
+            this.chkVirtualField.setEnabled(false);
             this.chkVirtualField.setSelected(true);
-            this.chkVirtualField.setEnabled(false);
             this.pickerVirtualField.setEnabled(false);
             this.pickerVirtualField.set(null);
         } else {
+            this.chkVirtualField.setEnabled(editable);
             this.chkVirtualField.setSelected(false);
-            this.chkVirtualField.setEnabled(true);
             this.pickerVirtualField.setEnabled(false);
             this.pickerVirtualField.set(null);
         }
-        
+
         this.pickerCRS.set(descriptor.getSRS());
-        
-        ListElement.setSelected(cboFieldType, descriptor.getType());
-        if( descriptor.getType()==DataTypes.GEOMETRY ) {
+
+        if (descriptor.getGeomType() != null) {
             ListElement.setSelected(cboGeometryType, descriptor.getGeomType().getType());
             ListElement.setSelected(cboGeometrySubtype, descriptor.getGeomType().getSubType());
-            this.cboGeometryType.setEnabled(true);
-            this.cboGeometrySubtype.setEnabled(true);
-        } else {
-            this.cboGeometryType.setEnabled(false);
-            this.cboGeometrySubtype.setEnabled(false);
         }
-        
+        ListElement.setSelected(cboFieldType, descriptor.getType());
+
     }
 
-    public void setReadonly(boolean readonly) {
-        
+    private void doFieldTypeChanged() {
+        try {
+            Integer fieldType = (Integer) ListElement.getSelected(this.cboFieldType);
+            if (fieldType == null) {
+                fieldType = DataTypes.UNKNOWN;
+            }
+            switch (fieldType) {
+                case DataTypes.GEOMETRY:
+                    this.cboGeometryType.setEnabled(editable);
+                    this.cboGeometrySubtype.setEnabled(editable);
+                    this.pickerCRS.setEnabled(editable);
+                    this.cboDateFormat.setEnabled(false);
+                    this.pickerIntervalStart.setEnabled(false);
+                    this.pickerIntervalEnd.setEditable(false);
+                    this.tabAditionalFields.setEnabledAt(1, true);
+                    this.tabAditionalFields.setEnabledAt(2, false);
+                    break;
+                case DataTypes.INSTANT:
+                case DataTypes.INTERVAL:
+                case DataTypes.DATE:
+                case DataTypes.TIME:
+                case DataTypes.TIMESTAMP:
+                    this.cboGeometryType.setEnabled(false);
+                    this.cboGeometrySubtype.setEnabled(false);
+                    this.pickerCRS.setEnabled(false);
+                    this.cboDateFormat.setEnabled(editable);
+                    this.pickerIntervalStart.setEnabled(editable);
+                    this.pickerIntervalEnd.setEditable(editable);
+                    this.tabAditionalFields.setEnabledAt(1, false);
+                    this.tabAditionalFields.setEnabledAt(2, true);
+                    break;
+                default:
+                    this.cboGeometryType.setEnabled(false);
+                    this.cboGeometrySubtype.setEnabled(false);
+                    this.pickerCRS.setEnabled(false);
+                    this.cboDateFormat.setEnabled(false);
+                    this.pickerIntervalStart.setEnabled(false);
+                    this.pickerIntervalEnd.setEditable(false);
+                    this.tabAditionalFields.setEnabledAt(1, false);
+                    this.tabAditionalFields.setEnabledAt(2, false);
+            }
+        } catch (Exception ex) {
+
+        }
     }
+
+    public void setEditable(boolean editable) {
+        this.editable = editable;
+        this.pickerDefaultValue.setEditable(editable);
+        this.pickerFieldName.setEditable(editable);
+        this.pickerIntervalEnd.setEditable(editable);
+        this.pickerIntervalStart.setEditable(editable);
+        this.pickerPrecision.setEditable(editable);
+        this.pickerSize.setEditable(editable);
+
+        this.chkAllowNulls.setEnabled(editable);
+        this.chkIsAutomatic.setEnabled(editable);
+        this.chkIsPrimaryKey.setEnabled(editable);
+
+        this.chkVirtualField.setEnabled(editable);
+        this.pickerVirtualField.setEditable(editable);
+
+        this.cboDateFormat.setEnabled(editable);
+        this.cboFieldType.setEnabled(editable);
+        this.cboGeometryType.setEnabled(editable);
+        this.cboGeometrySubtype.setEnabled(editable);
+
+    }
 }
