Revision 41537 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.impl/src/main/java/org/gvsig/exportto/swing/impl/panel/ExportFilterPanel.java
ExportFilterPanel.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.exportto.swing.impl.panel; |
25 | 25 |
|
26 |
import java.awt.GridBagConstraints; |
|
27 |
import java.awt.GridBagLayout; |
|
28 |
import java.awt.Insets; |
|
29 |
import java.awt.event.ItemEvent; |
|
30 |
import java.awt.event.ItemListener; |
|
31 |
|
|
32 |
import javax.swing.ButtonGroup; |
|
33 |
import javax.swing.JList; |
|
34 |
import javax.swing.JPanel; |
|
35 |
import javax.swing.JRadioButton; |
|
36 |
import javax.swing.JScrollPane; |
|
37 |
import javax.swing.JTextArea; |
|
38 |
import javax.swing.border.TitledBorder; |
|
39 |
import javax.swing.event.ChangeEvent; |
|
40 |
import javax.swing.event.ListSelectionEvent; |
|
41 |
import javax.swing.event.ListSelectionListener; |
|
42 |
|
|
26 |
import java.awt.event.ActionEvent; |
|
27 |
import java.awt.event.ActionListener; |
|
28 |
import java.util.Iterator; |
|
29 |
import javax.swing.DefaultListModel; |
|
43 | 30 |
import org.gvsig.exportto.ExporttoLocator; |
44 | 31 |
import org.gvsig.exportto.ExporttoManager; |
45 | 32 |
import org.gvsig.exportto.swing.impl.DefaultJExporttoServicePanel; |
46 |
import org.gvsig.exportto.swing.impl.panel.ExportFiltersListModel.Filter; |
|
33 |
import org.gvsig.fmap.dal.DALLocator; |
|
34 |
import org.gvsig.fmap.dal.DataManager; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
import org.gvsig.tools.ToolsLocator; |
|
37 |
import org.gvsig.tools.dynobject.DynObject; |
|
38 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
39 |
import org.gvsig.tools.evaluator.Evaluator; |
|
40 |
import org.gvsig.tools.evaluator.EvaluatorData; |
|
47 | 41 |
|
48 | 42 |
/** |
49 | 43 |
* @author gvSIG Team |
50 | 44 |
* @version $Id$ |
51 | 45 |
* |
52 | 46 |
*/ |
53 |
public class ExportFilterPanel extends AbstractExporttoPanel implements |
|
54 |
ListSelectionListener, ItemListener { |
|
47 |
public class ExportFilterPanel extends ExportFilterPanelLayout { |
|
55 | 48 |
|
56 |
private static final long serialVersionUID = -7108159123965667106L; |
|
57 |
|
|
58 |
private static final ExporttoManager EXPORTTO_MANAGER = ExporttoLocator |
|
59 |
.getManager(); |
|
60 |
|
|
61 |
private ButtonGroup selectionButtonGroup; |
|
62 |
private JRadioButton allLayerRadioButton; |
|
63 |
private JRadioButton selectedFeaturesRabioButton; |
|
64 |
private JRadioButton personalizedFilterRabioButton; |
|
65 |
|
|
66 |
private JPanel filterPanel; |
|
67 |
|
|
68 |
private JPanel predefinedFilterPanel; |
|
69 |
private JScrollPane predefinedFilterScrollPane; |
|
70 |
private JList predefinedFilterList; |
|
71 |
|
|
72 |
private JPanel freeFilterPanel; |
|
73 |
private JScrollPane freeFilterScrollPane; |
|
74 |
private JTextArea freeFilterTextArea; |
|
75 |
|
|
49 |
private FeatureStore store; |
|
50 |
|
|
76 | 51 |
public ExportFilterPanel(DefaultJExporttoServicePanel exporttoServicePanel) { |
77 |
super(exporttoServicePanel); |
|
78 |
initializeComponents(); |
|
79 |
itemStateChanged(null); |
|
52 |
this.store = null; |
|
53 |
this.initComponents(); |
|
80 | 54 |
} |
81 | 55 |
|
82 |
private void initializeComponents() { |
|
83 |
GridBagConstraints gridBagConstraints; |
|
84 |
setLayout(new GridBagLayout()); |
|
56 |
private static class FilterItem { |
|
57 |
private final String label; |
|
58 |
private final String value; |
|
59 |
public FilterItem(String label, String value) { |
|
60 |
this.label=label; |
|
61 |
this.value=value; |
|
62 |
} |
|
63 |
@Override |
|
64 |
public String toString() { |
|
65 |
return this.label; |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
private void initComponents() { |
|
70 |
ExporttoManager manager = ExporttoLocator.getManager(); |
|
71 |
|
|
72 |
DefaultListModel model = new DefaultListModel(); |
|
73 |
Iterator filterNames = manager.getPredefinedFilters(); |
|
74 |
while( filterNames.hasNext() ) { |
|
75 |
String name = (String) filterNames.next(); |
|
76 |
String expresion = manager.getFilter(name); |
|
77 |
model.addElement(new FilterItem(name, expresion)); |
|
78 |
} |
|
79 |
this.lstFilters.setModel(model); |
|
80 |
if( model.size()<1 ) { |
|
81 |
this.rdbFilteredRows.setEnabled(false); |
|
82 |
} |
|
83 |
this.rdbAllRows.addActionListener(new ActionListener() { |
|
84 |
public void actionPerformed(ActionEvent e) { |
|
85 |
doChangeOption(); |
|
86 |
} |
|
87 |
}); |
|
88 |
this.rdbFilteredRows.addActionListener(new ActionListener() { |
|
89 |
public void actionPerformed(ActionEvent e) { |
|
90 |
doChangeOption(); |
|
91 |
} |
|
92 |
}); |
|
93 |
this.rdbSelectedRows.addActionListener(new ActionListener() { |
|
94 |
public void actionPerformed(ActionEvent e) { |
|
95 |
doChangeOption(); |
|
96 |
} |
|
97 |
}); |
|
98 |
this.rdbAllRows.setSelected(true); |
|
99 |
this.butTest.addActionListener(new ActionListener() { |
|
100 |
public void actionPerformed(ActionEvent e) { |
|
101 |
doTest(); |
|
102 |
} |
|
103 |
}); |
|
104 |
} |
|
105 |
|
|
106 |
private static class Data implements EvaluatorData { |
|
107 |
private final DynObject data; |
|
108 |
|
|
109 |
public Data(DynObject data) { |
|
110 |
this.data = data; |
|
111 |
} |
|
112 |
public Object getDataValue(String name) { |
|
113 |
return this.data.getDynValue(name); |
|
114 |
} |
|
85 | 115 |
|
86 |
// Adding the radio buttons to the button group |
|
87 |
allLayerRadioButton = new JRadioButton(); |
|
88 |
allLayerRadioButton.setSelected(true); |
|
89 |
selectedFeaturesRabioButton = new JRadioButton(); |
|
90 |
personalizedFilterRabioButton = new JRadioButton(); |
|
116 |
public Object getContextValue(String name) { |
|
117 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
118 |
} |
|
91 | 119 |
|
92 |
allLayerRadioButton.addItemListener(this);
|
|
93 |
selectedFeaturesRabioButton.addItemListener(this);
|
|
94 |
personalizedFilterRabioButton.addItemListener(this);
|
|
120 |
public Iterator getDataValues() {
|
|
121 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
122 |
}
|
|
95 | 123 |
|
96 |
selectionButtonGroup = new ButtonGroup(); |
|
97 |
selectionButtonGroup.add(allLayerRadioButton); |
|
98 |
selectionButtonGroup.add(selectedFeaturesRabioButton); |
|
99 |
selectionButtonGroup.add(personalizedFilterRabioButton); |
|
124 |
public Iterator getDataNames() { |
|
125 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
126 |
} |
|
100 | 127 |
|
101 |
allLayerRadioButton.setText(exporttoServicePanel |
|
102 |
.getExporttoSwingManager().getTranslation("all_layer")); |
|
103 |
gridBagConstraints = new GridBagConstraints(); |
|
104 |
gridBagConstraints.gridx = 0; |
|
105 |
gridBagConstraints.gridy = 0; |
|
106 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; |
|
107 |
gridBagConstraints.anchor = GridBagConstraints.WEST; |
|
108 |
gridBagConstraints.weightx = 1.0; |
|
109 |
add(allLayerRadioButton, gridBagConstraints); |
|
128 |
public boolean hasDataValue(String name) { |
|
129 |
return this.data.hasDynValue(name); |
|
130 |
} |
|
110 | 131 |
|
111 |
selectedFeaturesRabioButton.setText(exporttoServicePanel |
|
112 |
.getExporttoSwingManager().getTranslation("selected_features")); |
|
113 |
gridBagConstraints = new GridBagConstraints(); |
|
114 |
gridBagConstraints.gridx = 0; |
|
115 |
gridBagConstraints.gridy = 1; |
|
116 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; |
|
117 |
gridBagConstraints.anchor = GridBagConstraints.WEST; |
|
118 |
gridBagConstraints.weightx = 1.0; |
|
119 |
add(selectedFeaturesRabioButton, gridBagConstraints); |
|
120 |
|
|
121 |
personalizedFilterRabioButton.setText(exporttoServicePanel |
|
122 |
.getExporttoSwingManager().getTranslation("filter")); |
|
123 |
gridBagConstraints = new GridBagConstraints(); |
|
124 |
gridBagConstraints.gridx = 0; |
|
125 |
gridBagConstraints.gridy = 2; |
|
126 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; |
|
127 |
gridBagConstraints.anchor = GridBagConstraints.WEST; |
|
128 |
gridBagConstraints.weightx = 1.0; |
|
129 |
add(personalizedFilterRabioButton, gridBagConstraints); |
|
130 |
|
|
131 |
// Create the filter panel |
|
132 |
filterPanel = new JPanel(); |
|
133 |
filterPanel.setLayout(new GridBagLayout()); |
|
134 |
|
|
135 |
// Create the predefined filter panel |
|
136 |
predefinedFilterPanel = new JPanel(); |
|
137 |
predefinedFilterScrollPane = new JScrollPane(); |
|
138 |
predefinedFilterPanel.setBorder(new TitledBorder(exporttoServicePanel |
|
139 |
.getExporttoSwingManager().getTranslation("predefined_filters"))); |
|
140 |
predefinedFilterList = new JList(); |
|
141 |
predefinedFilterList.setModel(new ExportFiltersListModel( |
|
142 |
exporttoServicePanel)); |
|
143 |
predefinedFilterList.addListSelectionListener(this); |
|
144 |
|
|
145 |
predefinedFilterPanel.setLayout(new GridBagLayout()); |
|
146 |
predefinedFilterScrollPane.setViewportView(predefinedFilterList); |
|
147 |
|
|
148 |
gridBagConstraints = new GridBagConstraints(); |
|
149 |
gridBagConstraints.gridx = 0; |
|
150 |
gridBagConstraints.gridy = 0; |
|
151 |
gridBagConstraints.fill = GridBagConstraints.BOTH; |
|
152 |
gridBagConstraints.weightx = 1.0; |
|
153 |
gridBagConstraints.weighty = 1.0; |
|
154 |
predefinedFilterPanel.add(predefinedFilterScrollPane, |
|
155 |
gridBagConstraints); |
|
156 |
|
|
157 |
gridBagConstraints = new GridBagConstraints(); |
|
158 |
gridBagConstraints.gridx = 0; |
|
159 |
gridBagConstraints.gridy = 0; |
|
160 |
gridBagConstraints.fill = GridBagConstraints.BOTH; |
|
161 |
gridBagConstraints.weightx = 1.0; |
|
162 |
gridBagConstraints.weighty = 1.0; |
|
163 |
filterPanel.add(predefinedFilterPanel, gridBagConstraints); |
|
164 |
|
|
165 |
// Create the free filter panel |
|
166 |
freeFilterPanel = new JPanel(); |
|
167 |
freeFilterScrollPane = new JScrollPane(); |
|
168 |
freeFilterPanel.setBorder(new TitledBorder(exporttoServicePanel |
|
169 |
.getExporttoSwingManager().getTranslation("free_filter"))); |
|
170 |
freeFilterTextArea = new JTextArea(); |
|
171 |
|
|
172 |
freeFilterPanel.setLayout(new GridBagLayout()); |
|
173 |
freeFilterScrollPane.setViewportView(freeFilterTextArea); |
|
174 |
|
|
175 |
gridBagConstraints = new GridBagConstraints(); |
|
176 |
gridBagConstraints.gridx = 0; |
|
177 |
gridBagConstraints.gridy = 0; |
|
178 |
gridBagConstraints.fill = GridBagConstraints.BOTH; |
|
179 |
gridBagConstraints.weightx = 1.0; |
|
180 |
gridBagConstraints.weighty = 1.0; |
|
181 |
freeFilterPanel.add(freeFilterScrollPane, gridBagConstraints); |
|
182 |
|
|
183 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
|
184 |
gridBagConstraints.gridx = 0; |
|
185 |
gridBagConstraints.gridy = 1; |
|
186 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
|
187 |
gridBagConstraints.weightx = 1.0; |
|
188 |
gridBagConstraints.weighty = 1.0; |
|
189 |
filterPanel.add(freeFilterPanel, gridBagConstraints); |
|
190 |
|
|
191 |
// Add the filter panel |
|
192 |
gridBagConstraints = new GridBagConstraints(); |
|
193 |
gridBagConstraints.gridx = 0; |
|
194 |
gridBagConstraints.gridy = 3; |
|
195 |
gridBagConstraints.fill = GridBagConstraints.BOTH; |
|
196 |
gridBagConstraints.insets = new Insets(0, 20, 0, 0); |
|
197 |
gridBagConstraints.weightx = 1.0; |
|
198 |
gridBagConstraints.weighty = 1.0; |
|
199 |
add(filterPanel, gridBagConstraints); |
|
200 |
|
|
132 |
public boolean hasContextValue(String name) { |
|
133 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
134 |
} |
|
201 | 135 |
} |
202 |
|
|
136 |
|
|
137 |
protected void doTest() { |
|
138 |
String filter = this.getFilter(); |
|
139 |
if( filter == null ) { |
|
140 |
return; |
|
141 |
} |
|
142 |
DynObjectManager dynobjmanager = ToolsLocator.getDynObjectManager(); |
|
143 |
DynObject values = dynobjmanager.createDynObject(this.store.getDefaultFeatureType()); |
|
144 |
DataManager datamanager = DALLocator.getDataManager(); |
|
145 |
Evaluator evaluator = datamanager.createExpresion(filter); |
|
146 |
evaluator.e |
|
147 |
|
|
148 |
} |
|
149 |
|
|
150 |
protected void doChangeOption(){ |
|
151 |
if( this.rdbAllRows.isSelected() ) { |
|
152 |
this.lstFilters.setEnabled(false); |
|
153 |
this.txtName.setEnabled(false); |
|
154 |
this.txtExpresion.setEnabled(false); |
|
155 |
} else if( this.rdbFilteredRows.isSelected() ) { |
|
156 |
this.lstFilters.setEnabled(true); |
|
157 |
this.txtName.setEnabled(true); |
|
158 |
this.txtExpresion.setEnabled(true); |
|
159 |
} else if( this.rdbSelectedRows.isSelected() ) { |
|
160 |
this.lstFilters.setEnabled(false); |
|
161 |
this.txtName.setEnabled(false); |
|
162 |
this.txtExpresion.setEnabled(false); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
203 | 166 |
public boolean isFullLayerSelected() { |
204 |
return allLayerRadioButton.isSelected();
|
|
167 |
return this.rdbAllRows.isSelected();
|
|
205 | 168 |
} |
206 | 169 |
|
207 | 170 |
public boolean isSelectedFeaturesSelected() { |
208 |
return selectedFeaturesRabioButton.isSelected();
|
|
171 |
return this.rdbSelectedRows.isSelected();
|
|
209 | 172 |
} |
210 | 173 |
|
211 | 174 |
public boolean isPersonalizedFilterSelected() { |
212 |
return personalizedFilterRabioButton.isSelected();
|
|
175 |
return this.rdbFilteredRows.isSelected();
|
|
213 | 176 |
} |
214 | 177 |
|
215 |
public String getFreeFilter() { |
|
216 |
if ((freeFilterTextArea.getText() != null) |
|
217 |
&& (!freeFilterTextArea.getText().equals(""))) { |
|
218 |
return freeFilterTextArea.getText(); |
|
219 |
} |
|
220 |
return null; |
|
178 |
public String getFilter() { |
|
221 | 179 |
} |
222 | 180 |
|
223 |
public void valueChanged(ListSelectionEvent e) { |
|
224 |
Object obj = predefinedFilterList.getSelectedValue(); |
|
225 |
if (obj != null) { |
|
226 |
Filter filter = (Filter) obj; |
|
227 |
this.freeFilterTextArea.setText(EXPORTTO_MANAGER.getFilter(filter |
|
228 |
.getFilterKey())); |
|
229 |
} |
|
230 |
} |
|
231 |
|
|
232 |
public void stateChanged(ChangeEvent e) { |
|
233 |
// TODO Auto-generated method stub |
|
234 |
|
|
235 |
} |
|
236 |
|
|
237 |
public void itemStateChanged(ItemEvent e) { |
|
238 |
predefinedFilterList.setEnabled(isPersonalizedFilterSelected()); |
|
239 |
freeFilterTextArea.setEnabled(isPersonalizedFilterSelected()); |
|
240 |
} |
|
241 | 181 |
} |
Also available in: Unified diff