Statistics
| Revision:

root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.gui / src / main / java / es / unex / sextante / gui / algorithm / TableFilterPanel.java @ 338

History | View | Annotate | Download (4.7 KB)

1
package es.unex.sextante.gui.algorithm;
2

    
3
import info.clearthought.layout.TableLayout;
4
import info.clearthought.layout.TableLayoutConstants;
5

    
6
import javax.swing.JButton;
7
import javax.swing.JPanel;
8
import javax.swing.JTextField;
9
import org.gvsig.expressionevaluator.Expression;
10
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator;
11
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager;
12
import org.gvsig.expressionevaluator.swing.ExpressionPickerController;
13
import org.gvsig.expressionevaluator.swing.JExpressionBuilder;
14
import org.gvsig.fmap.dal.DALLocator;
15
import org.gvsig.fmap.dal.exception.DataException;
16
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
17
import org.gvsig.fmap.dal.feature.Feature;
18
import org.gvsig.fmap.dal.feature.FeatureStore;
19
import org.gvsig.fmap.dal.swing.DataSwingManager;
20
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement;
21

    
22
/**
23
 * A panel with a text field and a button, which pops-up a filter dialog
24
 *
25
 * @author omartinez
26
 *
27
 */
28
public class TableFilterPanel
29
        extends
30
        JPanel {
31

    
32
    private JTextField textField;
33
    private JButton button;
34
    private FeatureStore m_Store = null;
35
    private ExpressionPickerController expressionControler;
36
    private FeatureStoreElement element;
37

    
38
    /**
39
     * Creates a new file selection panel.
40
     *
41
     * @param bFolder true if the selection must be a folder instead of a file
42
     * @param bOpen true to show a open file dialog. False to show a save file
43
     * one
44
     * @param sExts a list of permitted file extensions
45
     * @param sDescription a description of the panel to show in the file dialog
46
     */
47
    public TableFilterPanel(FeatureStore m_Store) {
48

    
49
        super();
50

    
51
        initGUI();
52

    
53
        this.setStore(m_Store);
54

    
55
    }
56

    
57
    public TableFilterPanel() {
58

    
59
        super();
60

    
61
        initGUI();
62

    
63
    }
64

    
65
    private void initGUI() {
66

    
67
        button = new JButton("");
68
        textField = new JTextField("");
69
        textField.setMaximumSize(new java.awt.Dimension(340, 18));
70

    
71
        final TableLayout thisLayout = new TableLayout(new double[][]{{TableLayoutConstants.FILL, 25.0},
72
        {TableLayoutConstants.FILL}});
73
        this.setLayout(thisLayout);
74
        this.add(textField, "0,  0");
75
        this.add(button, "1,  0");
76
        ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager();
77
        this.expressionControler = swingManager.createExpressionPickerController(textField, button);
78
        this.element = (FeatureStoreElement) swingManager.createElement(
79
                DataSwingManager.FEATURE_STORE_EXPRESSION_ELEMENT,
80
                this.expressionControler,
81
                null);
82
        if (element != null) {
83
            this.expressionControler.addElement(element);
84
        }
85
    }
86

    
87
    /**
88
     * Returns the filepath currently shown in the text field
89
     *
90
     * @return the filepath currently shown in the text field
91
     */
92
    public Expression getExpression() {
93

    
94
//        return textField.getText();
95
        return this.expressionControler.get();
96

    
97
    }
98

    
99
    /**
100
     * Returns this panel's JTextField widget.
101
     *
102
     * @return the text field widget used to input/store the selected file's
103
     * path and name
104
     */
105
    public JTextField getTextField() {
106

    
107
        return (this.textField);
108

    
109
    }
110

    
111
    /**
112
     * Returns this panel's JButton widget.
113
     *
114
     * @return the button widget used to pop up the file selector widget
115
     */
116
    public JButton getButton() {
117

    
118
        return (this.button);
119

    
120
    }
121

    
122
    public void setStore(FeatureStore store) {
123
        this.m_Store = store;
124
        this.element.setFeatureStore(store);
125

    
126
        if (store != null) {
127
            Feature sampleFeature = null;
128
            try {
129
                sampleFeature = store.getFeatureSelection().first();
130
                if (sampleFeature == null) {
131
                    sampleFeature = store.first();
132
                }
133
            } catch (DataException ex) {
134
            }
135
            if (sampleFeature != null) {
136
                FeatureSymbolTable featureSymbolTable = DALLocator.getDataManager().createFeatureSymbolTable();
137
                featureSymbolTable.setFeature(sampleFeature);
138
                this.expressionControler.setPreviewSymbolTable(featureSymbolTable.createParent());
139
            }
140
        }
141

    
142
    }
143

    
144
    public void setPhrase(final String sText) {
145

    
146
        textField.setText(sText);
147

    
148
    }
149

    
150
    public String getPhrase() {
151

    
152
        return textField.getText();
153

    
154
    }
155

    
156
    @Override
157
    public void setToolTipText(final String sText) {
158

    
159
        textField.setToolTipText(sText);
160

    
161
    }
162
}