svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / dal / expresionPanel / ExpresionPanel.java @ 41657
History | View | Annotate | Download (4.84 KB)
1 |
|
---|---|
2 |
package org.gvsig.fmap.mapcontrol.dal.expresionPanel; |
3 |
|
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ActionListener; |
6 |
import java.util.Map; |
7 |
import javax.swing.ListModel; |
8 |
import javax.swing.event.ListDataListener; |
9 |
import javax.swing.event.ListSelectionEvent; |
10 |
import javax.swing.event.ListSelectionListener; |
11 |
import org.apache.commons.lang3.StringUtils; |
12 |
import org.gvsig.fmap.dal.exception.DataException; |
13 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
15 |
import org.gvsig.fmap.dal.feature.FeatureType; |
16 |
import org.slf4j.Logger; |
17 |
import org.slf4j.LoggerFactory; |
18 |
|
19 |
|
20 |
public class ExpresionPanel extends ExpresionPanelLayout { |
21 |
|
22 |
private static final Logger logger = LoggerFactory.getLogger(ExpresionPanel.class); |
23 |
|
24 |
private FeatureStore store;
|
25 |
private Map values; |
26 |
private boolean okCancelVisible = true; |
27 |
private boolean isCanceled; |
28 |
|
29 |
private static class FeatureTypeListModel implements ListModel { |
30 |
private final FeatureType featureType; |
31 |
|
32 |
public FeatureTypeListModel(FeatureType featureType) {
|
33 |
this.featureType = featureType;
|
34 |
} |
35 |
public int getSize() { |
36 |
return this.featureType.size(); |
37 |
} |
38 |
|
39 |
public Object getElementAt(int index) { |
40 |
return this.featureType.get(index); |
41 |
} |
42 |
|
43 |
public void addListDataListener(ListDataListener l) { |
44 |
|
45 |
} |
46 |
|
47 |
public void removeListDataListener(ListDataListener l) { |
48 |
|
49 |
} |
50 |
|
51 |
} |
52 |
|
53 |
public ExpresionPanel(FeatureStore store) {
|
54 |
this.isCanceled = false; |
55 |
this.initComponents();
|
56 |
} |
57 |
|
58 |
public void setFeatureStore(FeatureStore store) { |
59 |
this.store = store;
|
60 |
try {
|
61 |
this.lstFields.setModel(new FeatureTypeListModel(this.store.getDefaultFeatureType())); |
62 |
} catch (DataException ex) {
|
63 |
logger.warn("Can't create model for field list.",ex);
|
64 |
} |
65 |
} |
66 |
|
67 |
public void setOkCancelVisible(boolean acceptVisible) { |
68 |
this.okCancelVisible = acceptVisible;
|
69 |
} |
70 |
|
71 |
public boolean getOkCancelVisible() { |
72 |
return this.okCancelVisible; |
73 |
} |
74 |
|
75 |
private void initComponents() { |
76 |
this.butAccept.setVisible(this.okCancelVisible); |
77 |
|
78 |
this.lstFields.addListSelectionListener(new ListSelectionListener() { |
79 |
public void valueChanged(ListSelectionEvent e) { |
80 |
doSelectField(); |
81 |
} |
82 |
}); |
83 |
this.lstValues.addListSelectionListener(new ListSelectionListener() { |
84 |
public void valueChanged(ListSelectionEvent e) { |
85 |
doSelectValue(); |
86 |
} |
87 |
}); |
88 |
ActionListener action = new ActionListener() { |
89 |
public void actionPerformed(ActionEvent e) { |
90 |
doInsert(e.getActionCommand()+" ");
|
91 |
} |
92 |
}; |
93 |
this.butAnd.addActionListener(action);
|
94 |
this.butOr.addActionListener(action);
|
95 |
this.butNot.addActionListener(action);
|
96 |
this.butEq.addActionListener(action);
|
97 |
this.butNe.addActionListener(action);
|
98 |
this.butGt.addActionListener(action);
|
99 |
this.butLt.addActionListener(action);
|
100 |
this.butGe.addActionListener(action);
|
101 |
this.butLe.addActionListener(action);
|
102 |
|
103 |
this.butClear.addActionListener(new ActionListener() { |
104 |
public void actionPerformed(ActionEvent e) { |
105 |
doClear(); |
106 |
} |
107 |
}); |
108 |
|
109 |
this.butAccept.addActionListener(new ActionListener() { |
110 |
public void actionPerformed(ActionEvent e) { |
111 |
doAcept(); |
112 |
} |
113 |
}); |
114 |
|
115 |
this.butCancel.addActionListener(new ActionListener() { |
116 |
public void actionPerformed(ActionEvent e) { |
117 |
doCancel(); |
118 |
} |
119 |
}); |
120 |
|
121 |
} |
122 |
|
123 |
public boolean isCanceled() { |
124 |
return this.isCanceled; |
125 |
} |
126 |
|
127 |
public String getExpresion() { |
128 |
return StringUtils.defaultIfBlank(this.txtExpresion.getText(), null); |
129 |
} |
130 |
|
131 |
private void doAcept() { |
132 |
this.isCanceled=false; |
133 |
this.setVisible(false); |
134 |
} |
135 |
|
136 |
private void doCancel() { |
137 |
this.isCanceled=true; |
138 |
this.setVisible(false); |
139 |
} |
140 |
|
141 |
private void doSelectField() { |
142 |
FeatureAttributeDescriptor x = (FeatureAttributeDescriptor) this.lstFields.getSelectedValue();
|
143 |
if( x == null ) { |
144 |
return;
|
145 |
} |
146 |
this.doInsert(x.getName());
|
147 |
this.doInsert(" "); |
148 |
this.fillValuesList(x.getName());
|
149 |
} |
150 |
|
151 |
private void doClear() { |
152 |
this.txtExpresion.setText(""); |
153 |
} |
154 |
|
155 |
private void doSelectValue() { |
156 |
// TODO: falta por implemetar doSelectValue
|
157 |
} |
158 |
|
159 |
private void doInsert(String s) { |
160 |
this.txtExpresion.insert(s, this.txtExpresion.getCaretPosition()); |
161 |
} |
162 |
|
163 |
private void fillValuesList(String name) { |
164 |
// TODO: falta por implemetar fillValuesList
|
165 |
} |
166 |
|
167 |
|
168 |
} |