Revision 47703
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/evalexpression/EvaluateExpressionPanel.java | ||
---|---|---|
52 | 52 |
public class EvaluateExpressionPanel extends EvaluateExpressionPanelView { |
53 | 53 |
|
54 | 54 |
private static final Logger LOGGER = LoggerFactory.getLogger(EvaluateExpressionPanel.class); |
55 |
|
|
55 |
|
|
56 | 56 |
private ExpressionPickerController pickerExpression; |
57 | 57 |
private final ActionListenerSupport actionListener; |
58 |
|
|
59 |
public EvaluateExpressionPanel(ActionListenerSupport actionListener, FeatureStore store) {
|
|
58 |
|
|
59 |
public EvaluateExpressionPanel(ActionListenerSupport actionListener, FeatureStore store) { |
|
60 | 60 |
this.actionListener = actionListener; |
61 | 61 |
initComponents(store); |
62 | 62 |
} |
63 |
|
|
63 |
|
|
64 | 64 |
private void initComponents(FeatureStore store) { |
65 | 65 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
66 | 66 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
67 |
|
|
67 |
|
|
68 | 68 |
this.pickerExpression = expressionSwingManager.createExpressionPickerController( |
69 |
this.txtExpression,
|
|
70 |
this.btnExpression,
|
|
71 |
this.btnExpressionHistory,
|
|
69 |
this.txtExpression, |
|
70 |
this.btnExpression, |
|
71 |
this.btnExpressionHistory, |
|
72 | 72 |
this.btnExpressionBookmarks |
73 | 73 |
); |
74 |
if(store != null) { |
|
74 |
if (store != null) {
|
|
75 | 75 |
this.pickerExpression.getConfig().addElement(DALSwingLocator.getDataSwingManager().createFeatureStoreElement(store)); |
76 | 76 |
} |
77 | 77 |
|
... | ... | |
79 | 79 |
IWindow window = application.getActiveWindow(); |
80 | 80 |
symbolTable.setVar("window", window); |
81 | 81 |
this.pickerExpression.getConfig().setPreviewSymbolTable(symbolTable); |
82 |
|
|
83 |
|
|
82 |
|
|
84 | 83 |
this.btnExecute.addActionListener((ActionEvent e) -> { |
85 | 84 |
doExecuteExpression(); |
86 | 85 |
}); |
87 | 86 |
this.txtTitle.setText("Expresion"); |
88 | 87 |
} |
89 |
|
|
88 |
|
|
90 | 89 |
private void doExecuteExpression() { |
91 | 90 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
92 | 91 |
WindowManager windowManager = ToolsSwingLocator.getWindowManager(); |
93 | 92 |
|
94 | 93 |
Expression exp = this.pickerExpression.get(); |
95 |
if( exp == null ) {
|
|
96 |
return ; //???
|
|
94 |
if (exp == null) {
|
|
95 |
return; //??? |
|
97 | 96 |
} |
98 | 97 |
MutableSymbolTable symbolTable = ExpressionUtils.createSymbolTable(); |
99 | 98 |
IWindow window = application.getActiveWindow(); |
... | ... | |
102 | 101 |
Object value; |
103 | 102 |
try { |
104 | 103 |
value = exp.execute(symbolTable); |
105 |
} catch(Throwable th) { |
|
106 |
LOGGER.warn("",th); |
|
104 |
} catch (Throwable th) {
|
|
105 |
LOGGER.warn("", th);
|
|
107 | 106 |
return; //??? |
108 | 107 |
} |
109 |
if( value == null ) {
|
|
108 |
if (value == null) {
|
|
110 | 109 |
return; |
111 | 110 |
} |
112 | 111 |
MyPanel panel = new MyPanel(this.actionListener, symbolTable, exp, (String) this.cboContentType.getSelectedItem()); |
113 |
if( this.chkLaunchOnChangeBBox.isSelected() ) {
|
|
114 |
Document doc = application.getActiveDocument();
|
|
112 |
if (this.chkLaunchOnChangeBBox.isSelected()) {
|
|
113 |
Document doc = application.getActiveDocument(); |
|
115 | 114 |
panel.setWindow(doc.getMainWindow()); |
116 | 115 |
} |
117 |
if( this.chkLaunchOnChangeSelection.isSelected() ) {
|
|
116 |
if (this.chkLaunchOnChangeSelection.isSelected()) {
|
|
118 | 117 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
119 |
if( viewdoc!=null ) {
|
|
118 |
if (viewdoc != null) {
|
|
120 | 119 |
FLyrVect layer = viewdoc.getMapContext().getLayers().getFirstActiveVectorLayer(); |
121 | 120 |
panel.setLayer(layer); |
122 | 121 |
} |
... | ... | |
124 | 123 |
panel.setValue(value); |
125 | 124 |
windowManager.showWindow(panel, this.txtTitle.getText(), this.getWindowMode()); |
126 | 125 |
} |
127 |
|
|
126 |
|
|
128 | 127 |
private WindowManager.MODE getWindowMode() { |
129 | 128 |
String s = (String) this.cboWindowType.getSelectedItem(); |
130 |
switch(s.toLowerCase()) { |
|
129 |
switch (s.toLowerCase()) {
|
|
131 | 130 |
case "modal": |
132 | 131 |
case "dialog": |
133 | 132 |
return WindowManager.MODE.DIALOG; |
... | ... | |
140 | 139 |
return WindowManager.MODE.WINDOW; |
141 | 140 |
} |
142 | 141 |
} |
143 |
|
|
142 |
|
|
144 | 143 |
private static class MyPanel extends JPanel { |
145 | 144 |
|
146 | 145 |
private final Expression expression; |
... | ... | |
149 | 148 |
private final ViewPortListener viewPortListener; |
150 | 149 |
private final MutableSymbolTable symbolTable; |
151 | 150 |
private final ActionListenerSupport actionListener; |
152 |
private boolean isProcessing;
|
|
153 |
private Thread lastUpdate = null;
|
|
154 |
private final Observer selectionListener;
|
|
155 |
|
|
151 |
private boolean isProcessing;
|
|
152 |
private Thread lastUpdate = null;
|
|
153 |
private Observer selectionListener; |
|
154 |
|
|
156 | 155 |
public MyPanel(ActionListenerSupport actionListener, MutableSymbolTable symbolTable, Expression expression, String contentType) { |
157 | 156 |
this.actionListener = actionListener; |
158 | 157 |
this.setOpaque(false); |
... | ... | |
160 | 159 |
this.expression = expression; |
161 | 160 |
this.contentType = contentType; |
162 | 161 |
this.isProcessing = false; |
162 |
this.selectionListener = null; |
|
163 | 163 |
this.actionListener.addActionListener((ActionEvent e) -> { |
164 | 164 |
doUpdate(); |
165 | 165 |
}); |
... | ... | |
179 | 179 |
}; |
180 | 180 |
this.selectionListener = (Observable observable, Object notification) -> { |
181 | 181 |
FeatureStoreNotification n = (FeatureStoreNotification) notification; |
182 |
if( StringUtils.equalsIgnoreCase(n.getType(),DataStoreNotification.SELECTION_CHANGE) ) { |
|
182 |
if (window == null ) { |
|
183 |
try { |
|
184 |
FeatureStore store = (FeatureStore) n.getSource(); |
|
185 |
store.deleteObserver(selectionListener); |
|
186 |
} catch (Throwable t) { |
|
187 |
LOGGER.warn("Can't remove observer from store", t); |
|
188 |
} |
|
189 |
} |
|
190 |
if (StringUtils.equalsIgnoreCase(n.getType(), DataStoreNotification.SELECTION_CHANGE)) { |
|
183 | 191 |
doUpdate(); |
184 | 192 |
} |
185 | 193 |
}; |
... | ... | |
198 | 206 |
|
199 | 207 |
@Override |
200 | 208 |
public void componentHidden(ComponentEvent e) { |
201 |
if( window instanceof IView) {
|
|
202 |
ViewPort viewPort = ((IView)window).getMapControl().getMapContext().getViewPort(); |
|
209 |
if (window instanceof IView) {
|
|
210 |
ViewPort viewPort = ((IView) window).getMapControl().getMapContext().getViewPort();
|
|
203 | 211 |
viewPort.removeViewPortListener(viewPortListener); |
212 |
lastUpdate = null; |
|
213 |
window = null; |
|
204 | 214 |
} |
205 | 215 |
} |
206 | 216 |
}); |
207 | 217 |
} |
208 |
|
|
218 |
|
|
209 | 219 |
private synchronized void doUpdate() { |
210 |
Thread th = new Thread(() -> { |
|
211 |
isProcessing = true; |
|
212 |
Object value = null; |
|
213 |
|
|
214 |
try { |
|
215 |
value = this.expression.execute(this.symbolTable); |
|
216 |
this.setValue(value); |
|
217 |
} catch (Throwable tt) { |
|
218 |
LOGGER.warn("", tt); |
|
219 |
} |
|
220 |
if(lastUpdate!=null) { |
|
221 |
lastUpdate.start(); |
|
222 |
lastUpdate = null; |
|
223 |
} else { |
|
224 |
isProcessing = false; |
|
225 |
} |
|
226 |
}); |
|
227 |
if (isProcessing==true) { |
|
228 |
lastUpdate = th; |
|
229 |
return; |
|
230 |
} |
|
231 |
th.start(); |
|
220 |
if (window == null) { |
|
221 |
return; |
|
222 |
} |
|
223 |
Thread th = new Thread(() -> { |
|
224 |
isProcessing = true; |
|
225 |
Object value = null; |
|
232 | 226 |
|
227 |
try { |
|
228 |
value = this.expression.execute(this.symbolTable); |
|
229 |
this.setValue(value); |
|
230 |
} catch (Throwable tt) { |
|
231 |
LOGGER.warn("", tt); |
|
232 |
} |
|
233 |
if (lastUpdate != null) { |
|
234 |
lastUpdate.start(); |
|
235 |
lastUpdate = null; |
|
236 |
} else { |
|
237 |
isProcessing = false; |
|
238 |
} |
|
239 |
}, "EvaluateExpressionPanel_update"); |
|
240 |
if (isProcessing == true) { |
|
241 |
lastUpdate = th; |
|
242 |
return; |
|
243 |
} |
|
244 |
th.start(); |
|
233 | 245 |
} |
234 |
|
|
246 |
|
|
235 | 247 |
public void setValue(Object value) { |
236 |
if (!SwingUtilities.isEventDispatchThread()) {
|
|
237 |
Object v = value;
|
|
238 |
SwingUtilities.invokeLater(() -> {
|
|
239 |
setValue(v);
|
|
240 |
});
|
|
241 |
return;
|
|
242 |
}
|
|
243 |
if( value == null ) {
|
|
248 |
if (!SwingUtilities.isEventDispatchThread()) {
|
|
249 |
Object v = value;
|
|
250 |
SwingUtilities.invokeLater(() -> {
|
|
251 |
setValue(v);
|
|
252 |
});
|
|
253 |
return;
|
|
254 |
}
|
|
255 |
if (value == null) {
|
|
244 | 256 |
this.removeAll(); |
245 | 257 |
this.revalidate(); |
246 | 258 |
return; |
247 | 259 |
} |
248 |
if( value instanceof SimpleImage ) {
|
|
249 |
value = ((SimpleImage)value).getBufferedImage(); |
|
260 |
if (value instanceof SimpleImage) {
|
|
261 |
value = ((SimpleImage) value).getBufferedImage();
|
|
250 | 262 |
} |
251 |
if( value instanceof Image ) {
|
|
263 |
if (value instanceof Image) {
|
|
252 | 264 |
JLabel label = new JLabel(); |
253 |
label.setIcon(new ImageIcon((Image)value)); |
|
265 |
label.setIcon(new ImageIcon((Image) value));
|
|
254 | 266 |
value = label; |
255 | 267 |
} |
256 |
|
|
268 |
|
|
257 | 269 |
JComponent component; |
258 |
if( value instanceof JComponent ) {
|
|
270 |
if (value instanceof JComponent) {
|
|
259 | 271 |
component = (JComponent) value; |
260 | 272 |
} else { |
261 | 273 |
JEditorPane browser = new JEditorPane(); |
... | ... | |
269 | 281 |
this.setLayout(new BorderLayout()); |
270 | 282 |
this.add(component); |
271 | 283 |
this.revalidate(); |
272 |
|
|
284 |
|
|
273 | 285 |
} |
274 |
|
|
286 |
|
|
275 | 287 |
public void setWindow(IWindow window) { |
276 | 288 |
this.window = window; |
277 |
if( window instanceof IView) {
|
|
278 |
ViewPort viewPort = ((IView)this.window).getMapControl().getMapContext().getViewPort(); |
|
289 |
if (window instanceof IView) {
|
|
290 |
ViewPort viewPort = ((IView) this.window).getMapControl().getMapContext().getViewPort();
|
|
279 | 291 |
viewPort.addViewPortListener(this.viewPortListener); |
280 | 292 |
} |
281 | 293 |
} |
282 |
|
|
294 |
|
|
283 | 295 |
public void setLayer(FLyrVect layer) { |
284 | 296 |
FeatureStore store = layer.getFeatureStore(); |
285 |
if( store != null ) {
|
|
297 |
if (store != null) {
|
|
286 | 298 |
store.deleteObserver(this.selectionListener); |
287 | 299 |
store.addObserver(this.selectionListener); |
288 | 300 |
} |
Also available in: Unified diff