root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.gui / src / main / java / es / unex / sextante / gui / algorithm / TableFilterPanel.java @ 348
History | View | Annotate | Download (4.88 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.DALSwingLocator; |
20 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
21 |
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement; |
22 |
|
23 |
/**
|
24 |
* A panel with a text field and a button, which pops-up a filter dialog
|
25 |
*
|
26 |
* @author omartinez
|
27 |
*
|
28 |
*/
|
29 |
public class TableFilterPanel |
30 |
extends
|
31 |
JPanel {
|
32 |
|
33 |
private JTextField textField; |
34 |
private JButton button; |
35 |
private FeatureStore m_Store = null; |
36 |
private ExpressionPickerController expressionControler;
|
37 |
private FeatureStoreElement element;
|
38 |
|
39 |
/**
|
40 |
* Creates a new file selection panel.
|
41 |
*
|
42 |
* @param bFolder true if the selection must be a folder instead of a file
|
43 |
* @param bOpen true to show a open file dialog. False to show a save file
|
44 |
* one
|
45 |
* @param sExts a list of permitted file extensions
|
46 |
* @param sDescription a description of the panel to show in the file dialog
|
47 |
*/
|
48 |
public TableFilterPanel(FeatureStore m_Store) {
|
49 |
|
50 |
super();
|
51 |
|
52 |
initGUI(); |
53 |
|
54 |
this.setStore(m_Store);
|
55 |
|
56 |
} |
57 |
|
58 |
public TableFilterPanel() {
|
59 |
|
60 |
super();
|
61 |
|
62 |
initGUI(); |
63 |
|
64 |
} |
65 |
|
66 |
private void initGUI() { |
67 |
|
68 |
button = new JButton(""); |
69 |
textField = new JTextField(""); |
70 |
textField.setMaximumSize(new java.awt.Dimension(340, 18)); |
71 |
|
72 |
final TableLayout thisLayout = new TableLayout(new double[][]{{TableLayoutConstants.FILL, 25.0}, |
73 |
{TableLayoutConstants.FILL}}); |
74 |
this.setLayout(thisLayout);
|
75 |
this.add(textField, "0, 0"); |
76 |
this.add(button, "1, 0"); |
77 |
ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager(); |
78 |
this.expressionControler = swingManager.createExpressionPickerController(textField, button);
|
79 |
// this.element = (FeatureStoreElement) swingManager.createElement(
|
80 |
// DataSwingManager.FEATURE_STORE_EXPRESSION_ELEMENT,
|
81 |
// this.expressionControler,
|
82 |
// null);
|
83 |
this.element = DALSwingLocator.getSwingManager().createFeatureStoreElement(this.expressionControler); |
84 |
|
85 |
if (element != null) { |
86 |
this.expressionControler.addElement(element);
|
87 |
} |
88 |
} |
89 |
|
90 |
/**
|
91 |
* Returns the filepath currently shown in the text field
|
92 |
*
|
93 |
* @return the filepath currently shown in the text field
|
94 |
*/
|
95 |
public Expression getExpression() { |
96 |
|
97 |
// return textField.getText();
|
98 |
return this.expressionControler.get(); |
99 |
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* Returns this panel's JTextField widget.
|
104 |
*
|
105 |
* @return the text field widget used to input/store the selected file's
|
106 |
* path and name
|
107 |
*/
|
108 |
public JTextField getTextField() { |
109 |
|
110 |
return (this.textField); |
111 |
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* Returns this panel's JButton widget.
|
116 |
*
|
117 |
* @return the button widget used to pop up the file selector widget
|
118 |
*/
|
119 |
public JButton getButton() { |
120 |
|
121 |
return (this.button); |
122 |
|
123 |
} |
124 |
|
125 |
public void setStore(FeatureStore store) { |
126 |
this.m_Store = store;
|
127 |
this.element.setFeatureStore(store);
|
128 |
|
129 |
if (store != null) { |
130 |
Feature sampleFeature = null;
|
131 |
try {
|
132 |
sampleFeature = store.getFeatureSelection().first(); |
133 |
if (sampleFeature == null) { |
134 |
sampleFeature = store.first(); |
135 |
} |
136 |
} catch (DataException ex) {
|
137 |
} |
138 |
if (sampleFeature != null) { |
139 |
FeatureSymbolTable featureSymbolTable = DALLocator.getDataManager().createFeatureSymbolTable(); |
140 |
featureSymbolTable.setFeature(sampleFeature); |
141 |
this.expressionControler.setPreviewSymbolTable(featureSymbolTable.createParent());
|
142 |
} |
143 |
} |
144 |
|
145 |
} |
146 |
|
147 |
public void setPhrase(final String sText) { |
148 |
|
149 |
textField.setText(sText); |
150 |
|
151 |
} |
152 |
|
153 |
public String getPhrase() { |
154 |
|
155 |
return textField.getText();
|
156 |
|
157 |
} |
158 |
|
159 |
@Override
|
160 |
public void setToolTipText(final String sText) { |
161 |
|
162 |
textField.setToolTipText(sText); |
163 |
|
164 |
} |
165 |
} |