Statistics
| Revision:

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

History | View | Annotate | Download (3.84 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.feature.FeatureStore;
15
import org.gvsig.fmap.dal.swing.DataSwingManager;
16
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement;
17

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

    
28
    private JTextField textField;
29
    private JButton button;
30
    private FeatureStore m_Store = null;
31
    private ExpressionPickerController expressionControler;
32
    private FeatureStoreElement element;
33

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

    
45
        super();
46

    
47
        initGUI();
48

    
49
        this.setStore(m_Store);
50

    
51
    }
52

    
53
    public TableFilterPanel() {
54

    
55
        super();
56

    
57
        initGUI();
58

    
59
    }
60

    
61
    private void initGUI() {
62

    
63
        button = new JButton("");
64
        textField = new JTextField("");
65
        textField.setMaximumSize(new java.awt.Dimension(340, 18));
66

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

    
83
    /**
84
     * Returns the filepath currently shown in the text field
85
     *
86
     * @return the filepath currently shown in the text field
87
     */
88
    public Expression getExpression() {
89

    
90
//        return textField.getText();
91
        return this.expressionControler.get();
92

    
93
    }
94

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

    
103
        return (this.textField);
104

    
105
    }
106

    
107
    /**
108
     * Returns this panel's JButton widget.
109
     *
110
     * @return the button widget used to pop up the file selector widget
111
     */
112
    public JButton getButton() {
113

    
114
        return (this.button);
115

    
116
    }
117

    
118
    public void setStore(FeatureStore store) {
119
        this.m_Store = store;
120
        this.element.setFeatureStore(store);
121

    
122
    }
123

    
124
    public void setPhrase(final String sText) {
125

    
126
        textField.setText(sText);
127

    
128
    }
129

    
130
    public String getPhrase() {
131

    
132
        return textField.getText();
133

    
134
    }
135

    
136
    @Override
137
    public void setToolTipText(final String sText) {
138

    
139
        textField.setToolTipText(sText);
140

    
141
    }
142
}