Index: DefaultJExpressionBuilder.java
===================================================================
--- DefaultJExpressionBuilder.java	(revision 44258)
+++ DefaultJExpressionBuilder.java	(revision 44259)
@@ -18,7 +18,6 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
-import java.util.Map;
 import java.util.Objects;
 import javax.swing.DefaultListCellRenderer;
 import javax.swing.ImageIcon;
@@ -50,12 +49,8 @@
 import org.apache.commons.lang3.StringUtils;
 import org.gvsig.expressionevaluator.Expression;
 import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
-import org.gvsig.expressionevaluator.Function;
 import org.gvsig.expressionevaluator.SymbolTable;
 import org.gvsig.expressionevaluator.swing.Element;
-import org.gvsig.expressionevaluator.swing.Element.CalculatedElement;
-import org.gvsig.expressionevaluator.swing.Element.ConstantElement;
-import org.gvsig.expressionevaluator.swing.Element.FunctionElement;
 import org.gvsig.expressionevaluator.swing.Element.GroupElement;
 import org.gvsig.expressionevaluator.swing.Element.SimpleElement;
 import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig;
@@ -65,7 +60,6 @@
 import org.gvsig.tools.i18n.I18nManager;
 import org.gvsig.tools.script.Script;
 import org.gvsig.tools.swing.api.Component;
-import org.gvsig.tools.swing.api.ListElement;
 import org.gvsig.tools.swing.api.ToolsSwingLocator;
 import org.gvsig.tools.swing.api.ToolsSwingManager;
 import org.gvsig.tools.swing.api.pickercontroller.PickerController;
@@ -79,7 +73,7 @@
  */
 @SuppressWarnings("UseSpecificCatch")
 public class DefaultJExpressionBuilder
-        extends DefaultJExpressionBuilderView
+        extends DefaultJExpressionBuilderView2
         implements JExpressionBuilder {
 
     private final ExpressionEvaluatorSwingManager manager;
@@ -87,7 +81,7 @@
     private PickerController<List<Script>> scriptPicker;
     private ScriptSwingManager.ScriptEditor scriptEditor;
     
-    private final ExpressionBuilderConfig config;
+    private final ExpressionBuilderConfig bulderConfig;
     private ElementsTreeModel treeModel;
     private ImageIcon defaultIconGroup;
     private ImageIcon defaultIconElement;
@@ -277,9 +271,9 @@
     public DefaultJExpressionBuilder(ExpressionEvaluatorSwingManager manager, ExpressionBuilderConfig config) {
         this.manager = manager;
         if( config == null ) {
-            this.config = new DefaultExpressionBuilderConfig(manager);
+            this.bulderConfig = new DefaultExpressionBuilderConfig(manager);
         } else {
-            this.config = config;
+            this.bulderConfig = config;
         }
         this.initComponents();
     }
@@ -304,7 +298,7 @@
         final I18nManager i18n = ToolsLocator.getI18nManager();
         
         this.automaticExpressionChecker = new AbstractAutomaticExpressionChecker(
-                config, txtExpression
+                bulderConfig, txtExpression
             ) {
             @Override
             protected Expression getExpression() {
@@ -390,29 +384,47 @@
                 lblColumn.setText(Integer.toString(e.getDot()));
             }
         });
+        this.treeElements.setRowHeight(0);
         this.treeElements.setCellRenderer(new DefaultTreeCellRenderer() {
             @Override
             public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
-                JLabel label = (JLabel) super.getTreeCellRendererComponent(tree,value, selected, expanded, leaf, row, hasFocus);
+                JLabel component = (JLabel) super.getTreeCellRendererComponent(tree,value, selected, expanded, leaf, row, hasFocus);
+                JLabel text = component;
+                JLabel icon = component;
+
+//                JPanel component = new JPanel();
+//                JLabel text = new JLabel();
+//                JLabel icon = new JLabel();
+//                component.setLayout(new FlowLayout());
+//                component.add(icon);
+//                component.add(text);
+//                component.setLayout(new GridBagLayout());
+//                component.add(icon, new GridBagConstraints(0,0,0,0,0,0,GridBagConstraints.NORTH,GridBagConstraints.BOTH,new Insets(1,1,1,1),1,1));
+//                component.add(text, new GridBagConstraints(1,0,0,0,0,0,GridBagConstraints.NORTH,GridBagConstraints.BOTH,new Insets(1,1,1,1),1,1));
+                
                 if( value instanceof Element ) {
                     Element element = (Element) value;
                     if( element.getIconName()==null ) {
                         if( element instanceof GroupElement ) {
-                            label.setIcon(defaultIconGroup);
+                            icon.setIcon(defaultIconGroup);
                         } else {
-                            label.setIcon(defaultIconElement);
+                            icon.setIcon(defaultIconElement);
                         }
                     } else {
-                        label.setIcon(element.getIcon());
+                        icon.setIcon(element.getIcon());
                     }
-                    label.setText(element.getName());
-                    label.setEnabled(element.isEnabled());
+                    text.setText(element.getLabel());
+                    text.setEnabled(element.isEnabled());
                 } else {
-                    label.setIcon(null);
-                    label.setText(Objects.toString(value, ""));
+                    icon.setIcon(null);
+                    text.setText(Objects.toString(value, ""));
                 }
-                return label;
+                return component;
             }
+
+            private JLabel JPanel() {
+                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+            }
         });
         
         this.treeElements.addTreeSelectionListener(new TreeSelectionListener() {
@@ -448,9 +460,9 @@
         this.btnSimpleElementInsert.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
-                ListElement<SimpleElement> element = (ListElement<SimpleElement>) lstSimpleElement.getSelectedValue();
+                Element element = (Element) lstSimpleElement.getSelectedValue();
                 if (element != null) {
-                    doInsert(element.getValue());
+                    doInsert(element);
                 }
             }
         });
@@ -466,13 +478,8 @@
             @Override
             public java.awt.Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                 JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
-                Element element = null;
-                if( value instanceof ListElement ) {
-                    if( ((ListElement) value).getValue() instanceof Element ) {
-                        element = (Element) ((ListElement) value).getValue();
-                    }
-                }
-                if( element !=null ) {
+                if( value instanceof Element ) {
+                    Element element = (Element) value;
                     if( element.getIconName()==null ) {
                         if( element instanceof GroupElement ) {
                             label.setIcon(defaultIconGroup);
@@ -482,7 +489,7 @@
                     } else {
                         label.setIcon(element.getIcon());
                     }
-                    label.setText(element.getName());
+                    label.setText(element.getLabel());
                     label.setEnabled(element.isEnabled());
                 } else {
                     label.setIcon(null);
@@ -494,9 +501,9 @@
         this.lstSimpleElement.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
             @Override
             public void valueChanged(ListSelectionEvent e) {
-                ListElement<SimpleElement> element = (ListElement<SimpleElement>) lstSimpleElement.getSelectedValue();
+                Element element = (Element) lstSimpleElement.getSelectedValue();
                 if (element != null) {
-                    doSelectElement(element.getValue());
+                    doSelectElement(element);
                 }
             }
         });
@@ -504,10 +511,10 @@
             @Override
             public void mouseClicked(MouseEvent e) {
                 if( e.getButton()==MouseEvent.BUTTON1 && e.getClickCount()==2 ) {
-                    ListElement<SimpleElement> element = (ListElement<SimpleElement>) lstSimpleElement.getSelectedValue();
+                    Element element = (Element) lstSimpleElement.getSelectedValue();
                     if (element != null) {
-                        doSelectElement(element.getValue());
-                        doInsert(element.getValue());
+                        doSelectElement(element);
+                        doInsert(element);
                     }
                 }
             }
@@ -516,10 +523,10 @@
             @Override
             public void keyReleased(KeyEvent e) {
                 if( e.getKeyCode()==KeyEvent.VK_ENTER ) {
-                    ListElement<SimpleElement> element = (ListElement<SimpleElement>) lstSimpleElement.getSelectedValue();
+                    Element element = (Element) lstSimpleElement.getSelectedValue();
                     if (element != null) {
-                        doSelectElement(element.getValue());
-                        doInsert(element.getValue());
+                        doSelectElement(element);
+                        doInsert(element);
                     }
                 }
             }
@@ -611,11 +618,17 @@
         this.pnlScriptEditorContainer.setLayout(new BorderLayout());
         this.pnlScriptEditorContainer.add(this.scriptEditor.asJComponent(), BorderLayout.CENTER);
     
-        this.tabExpressionBuilder.setEnabledAt(0, this.config.getScriptsEnabled());
+        this.tabExpressionBuilder.setEnabledAt(0, this.bulderConfig.getPreferences().getScriptsEnabled());
         
         this.infoPanel.repaint();
         
         this.setPreferredSize(new Dimension(650, 350));
+        
+
+        Dimension dim = this.getPreferredSize();
+        this.spnlExpression.setDividerLocation(dim.height/5);
+        this.spnlBottom.setDividerLocation(dim.width/3);
+        this.spnlItem.setDividerLocation(dim.width/3);
     }
 
     private String removeCursorMark(String s) {
@@ -655,25 +668,9 @@
         this.txtExpression.requestFocusInWindow();
     }
 
-    private void doInsert(SimpleElement element) {
-        if( element instanceof FunctionElement ) {
-            Function function = ((FunctionElement)element).getFunction();
-            if (function == null) {
-                doInsert(element.getName());
-            } else {
-                doInsert(function.template() == null ? function.name() + "({{}})" : function.template());
-            }
-        } else if( element instanceof CalculatedElement) {
-            Object value = ((CalculatedElement) element).getValue();
-            if( value != null ) {
-                doInsert(" "+value.toString()+" ");
-            }
-        } else if( element instanceof ConstantElement) {
-            Object value = ((ConstantElement) element).getValue();
-            doInsert(" "+Utils.repr(value)+" ");
-        } else {
-            doInsert(" "+element.getName()+" ");
-        }
+    private void doInsert(Element element) {
+        doInsert(element.getRenderedValue());
+        element.used();
     }
 
     private void doFilter() {
@@ -681,7 +678,7 @@
         model.setFilter(this.txtSimpleElementFilter.getText());
     }
 
-    private void doSelectElement(SimpleElement element) {
+    private void doSelectElement(Element element) {
 //        if( !element.isEnabled() ) {
 //            this.infoPanel.clean();
 //        } else {
@@ -724,13 +721,7 @@
                 return;
             }
             if (child instanceof SimpleElement) {
-                String label = child.getName();
-                Function function = child instanceof FunctionElement?  ((FunctionElement)child).getFunction(): null;
-                if (function != null && !StringUtils.isEmpty(function.returnType())) {
-                    label = "<html><b>" + label + "</b> return " + function.returnType() + "</html>";
-//                    label = label + " return " + function.returnType();
-                }
-                model.addElement(new ListElement<>(label, child));
+                model.addElement(child);
             }
         }
         model.sort(true);
@@ -784,97 +775,56 @@
             }
         }
     }
-    
-    @Override
-    public int getSimpleElementsLimit() {
-        return this.config.getSimpleElementsLimit();
-    }
 
     @Override
-    public void setSimpleElementsLimit(int limit) {
-        this.config.setSimpleElementsLimit(limit);
+    public Preferences getPreferences() {
+        return this.bulderConfig.getPreferences();
     }
     
     @Override
     public List<Element> getElements() {
-        return this.config.getElements();
+        return this.bulderConfig.getElements();
     }
     
     @Override
     public void addElement(Element element) {
-        this.config.addElement(element);
+        this.bulderConfig.addElement(element);
     }
     
     @Override
     public Collection<SymbolTable> getSymbolTables() {
-        return this.config.getSymbolTables();
+        return this.bulderConfig.getSymbolTables();
     }
     
     @Override
     public void addSymbolTable(String name) {
-        this.config.addSymbolTable(name);
+        this.bulderConfig.addSymbolTable(name);
     }
     
     @Override
     public void addSymbolTable(SymbolTable symbolTable) {
-        this.config.addSymbolTable(symbolTable);
+        this.bulderConfig.addSymbolTable(symbolTable);
     }
 
     @Override
     public void removeAllSymbolTables() {
-        this.config.removeAllSymbolTables();
+        this.bulderConfig.removeAllSymbolTables();
     }
 
     @Override
     public void removeSymbolTable(String name) {
-        this.config.removeSymbolTable(name);
+        this.bulderConfig.removeSymbolTable(name);
     }
 
     @Override
     public SymbolTable getPreviewSymbolTable() {
-        return this.config.getPreviewSymbolTable();
+        return this.bulderConfig.getPreviewSymbolTable();
     }
 
     @Override
     public void setPreviewSymbolTable(SymbolTable symbolTable) {
-        this.config.setPreviewSymbolTable(symbolTable);
+        this.bulderConfig.setPreviewSymbolTable(symbolTable);
     }
-
-    @Override
-    public void setScriptsEnabled(boolean enabled) {
-        this.config.setScriptsEnabled(enabled);
-        this.tabExpressionBuilder.setEnabledAt(0, this.config.getScriptsEnabled());
-    }
-
-    @Override
-    public boolean getScriptsEnabled() {
-        return this.config.getScriptsEnabled();
-    }
-
-    @Override
-    public void setSQLCompatible(boolean sqlCompatible) {
-        this.config.setSQLCompatible(sqlCompatible);
-    }
-
-    @Override
-    public boolean isSQLCompatible() {
-        return this.config.isSQLCompatible();
-    }
-
-    @Override
-    public Object getProperty(String string) {
-        return this.config.getProperty(string);
-    }
-
-    @Override
-    public void setProperty(String string, Object o) {
-        this.config.setProperty(string, o);
-    }
-
-    @Override
-    public Map<String, Object> getProperties() {
-        return this.config.getProperties();
-    }
     
     @Override
     public JComponent asJComponent() {
@@ -885,13 +835,11 @@
     private void initializeTree() {
         if( this.treeModel == null ) {
             I18nManager i18n = ToolsLocator.getI18nManager();
-            this.treeModel = new ElementsTreeModel(
+            this.treeModel = new ElementsTreeModel( (GroupElement)
                     this.manager.createGroupElement(
-                            this.config,
                             i18n.getTranslation("_Elements"),
                             this.getElements()
-                    )
-            );
+                    ).setConfig(this));
             this.treeElements.setModel(this.treeModel);
         }
     }
@@ -902,14 +850,14 @@
                 "Indicate the time limit in seconds for calculating the elements", 
                 "Time limit", 
                 JOptionPane.QUESTION_MESSAGE, 
-                String.valueOf(this.config.getSimpleElementsLimit())
+                String.valueOf(this.bulderConfig.getPreferences().getSimpleElementsLimit())
         );
         if( StringUtils.isBlank(s) ) {
             return;
         }
         try {
             int n = Integer.parseInt(s);
-            this.config.setSimpleElementsLimit(n);
+            this.bulderConfig.getPreferences().setSimpleElementsLimit(n);
             this.treeModel.reload();
         } catch(Exception ex) {
             dialogs.messageDialog(
