root / branches / v2_0_0_prep / extensions / extExpressionField / src / com / iver / cit / gvsig / project / documents / table / gui / EvalExpressionDialog.java @ 27752
History | View | Annotate | Download (32.4 KB)
1 |
package com.iver.cit.gvsig.project.documents.table.gui; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Component; |
5 |
import java.awt.GridBagConstraints; |
6 |
import java.awt.GridBagLayout; |
7 |
import java.awt.GridLayout; |
8 |
import java.awt.Insets; |
9 |
import java.awt.event.MouseEvent; |
10 |
import java.awt.event.MouseListener; |
11 |
import java.io.File; |
12 |
import java.io.FileReader; |
13 |
import java.io.IOException; |
14 |
import java.util.ArrayList; |
15 |
import java.util.Iterator; |
16 |
import java.util.prefs.Preferences; |
17 |
|
18 |
import javax.swing.BoxLayout; |
19 |
import javax.swing.ButtonGroup; |
20 |
import javax.swing.JFileChooser; |
21 |
import javax.swing.JLabel; |
22 |
import javax.swing.JList; |
23 |
import javax.swing.JOptionPane; |
24 |
import javax.swing.JPanel; |
25 |
import javax.swing.JRadioButton; |
26 |
import javax.swing.JScrollPane; |
27 |
import javax.swing.JTabbedPane; |
28 |
import javax.swing.JTextArea; |
29 |
import javax.swing.JTextField; |
30 |
import javax.swing.UIManager; |
31 |
import javax.swing.event.CaretEvent; |
32 |
import javax.swing.event.CaretListener; |
33 |
|
34 |
import org.apache.bsf.BSFException; |
35 |
import org.apache.bsf.BSFManager; |
36 |
import org.gvsig.fmap.dal.exception.DataException; |
37 |
import org.gvsig.fmap.dal.exception.ReadException; |
38 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
39 |
import org.gvsig.fmap.dal.feature.Feature; |
40 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
41 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
43 |
import org.gvsig.fmap.dal.feature.FeatureType; |
44 |
import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException; |
45 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
46 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
47 |
import org.gvsig.gui.beans.swing.JButton; |
48 |
import org.gvsig.project.document.table.gui.FeatureTableDocumentPanel; |
49 |
|
50 |
import bsh.EvalError; |
51 |
|
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.andami.messages.NotificationManager; |
54 |
import com.iver.andami.ui.mdiManager.IWindow; |
55 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
56 |
import com.iver.cit.gvsig.ExpressionFieldExtension; |
57 |
import com.iver.cit.gvsig.project.documents.table.GraphicOperator; |
58 |
import com.iver.cit.gvsig.project.documents.table.IOperator; |
59 |
import com.iver.cit.gvsig.project.documents.table.Index; |
60 |
import com.iver.cit.gvsig.project.documents.table.operators.Field; |
61 |
import com.iver.utiles.GenericFileFilter; |
62 |
|
63 |
|
64 |
/**
|
65 |
* DOCUMENT ME!
|
66 |
*
|
67 |
* @author Vicente Caballero Navarro
|
68 |
*/
|
69 |
public class EvalExpressionDialog extends JPanel implements IWindow { |
70 |
private JPanel pNorth = null; |
71 |
private JPanel pCentral = null; |
72 |
private JScrollPane jScrollPane = null; |
73 |
private JTextArea txtExp = null; |
74 |
private AcceptCancelPanel acceptCancel;
|
75 |
private FeatureTableDocumentPanel table;
|
76 |
private FLyrVect lv;
|
77 |
private JLabel lblColumn = null; |
78 |
private JPanel pNorthEast = null; |
79 |
private JPanel pNorthCenter = null; |
80 |
private JPanel pNorthWest = null; |
81 |
private JScrollPane jScrollPane1 = null; |
82 |
private JList listFields = null; |
83 |
private JRadioButton rbNumber = null; |
84 |
private JRadioButton rbString = null; |
85 |
private JRadioButton rbDate = null; |
86 |
private JScrollPane jScrollPane2 = null; |
87 |
private JList listCommand = null; |
88 |
private BSFManager interpreter = null; // Construct an interpreter |
89 |
// private Index indexRow = null;
|
90 |
private Feature feature;
|
91 |
private FeatureStore featureStore = null; |
92 |
private EvalExpression evalExpression=null; |
93 |
// private IEditableSource ies=null;
|
94 |
private JPanel pMessage; |
95 |
private Object featureContainer; |
96 |
//private JTextArea txtMessage;
|
97 |
private static ArrayList operators=new ArrayList(); |
98 |
public EvalExpressionDialog(FeatureTableDocumentPanel table, BSFManager interpreter, ArrayList operators) { |
99 |
super();
|
100 |
this.operators=operators;
|
101 |
this.interpreter=interpreter;
|
102 |
this.table = table;
|
103 |
initialize(); |
104 |
|
105 |
} |
106 |
/**
|
107 |
* This method initializes this
|
108 |
*/
|
109 |
private void initialize() { |
110 |
try {
|
111 |
evalExpressions(); |
112 |
} catch (BSFException e) {
|
113 |
NotificationManager.addError(e); |
114 |
} |
115 |
evalExpression=new EvalExpression();
|
116 |
evalExpression.setTable(table); |
117 |
lv = (FLyrVect) table.getModel().getAssociatedLayer(); |
118 |
ButtonGroup bg = new ButtonGroup(); |
119 |
bg.add(getRbNumber()); |
120 |
bg.add(getRbString()); |
121 |
bg.add(getRbDate()); |
122 |
this.setLayout(new GridBagLayout()); |
123 |
this.setSize(549, 480); |
124 |
GridBagConstraints constr = new GridBagConstraints(); |
125 |
constr.gridwidth = GridBagConstraints.REMAINDER;
|
126 |
constr.gridheight = 1;
|
127 |
constr.fill = GridBagConstraints.BOTH;
|
128 |
constr.ipadx=5;
|
129 |
constr.ipady=5;
|
130 |
constr.weightx=1;
|
131 |
constr.weighty=0.3;
|
132 |
// this.add(getTabPrincipal(), java.awt.BorderLayout.CENTER);
|
133 |
// this.add(getPMessage(), java.awt.BorderLayout.NORTH);
|
134 |
// this.add(getAcceptCancel(), java.awt.BorderLayout.SOUTH);
|
135 |
this.add(getPMessage(), constr);
|
136 |
constr.gridheight = 5;
|
137 |
constr.weighty=1;
|
138 |
this.add(getTabPrincipal(), constr);
|
139 |
GridBagConstraints constr2 = new GridBagConstraints(); |
140 |
constr2.gridwidth = GridBagConstraints.REMAINDER;
|
141 |
constr2.gridheight = 1;
|
142 |
constr2.fill = GridBagConstraints.HORIZONTAL;
|
143 |
constr2.anchor = GridBagConstraints.LAST_LINE_END;
|
144 |
constr2.weightx=1;
|
145 |
constr2.weighty=0;
|
146 |
|
147 |
this.add(getAcceptCancel(), constr2);
|
148 |
|
149 |
} |
150 |
/**
|
151 |
* This method initializes pCentral
|
152 |
*
|
153 |
* @return javax.swing.JPanel
|
154 |
*/
|
155 |
private JPanel getPNorth() { |
156 |
if (pNorth == null) { |
157 |
pNorth = new JPanel(); |
158 |
pNorth.setLayout(new GridBagLayout()); |
159 |
GridBagConstraints contr = new GridBagConstraints(); |
160 |
contr.ipadx = 5;
|
161 |
contr.ipady = 5;
|
162 |
contr.fill = GridBagConstraints.BOTH;
|
163 |
contr.weightx =1;
|
164 |
contr.weighty =1;
|
165 |
pNorth.add(getPNorthWest(), contr); |
166 |
|
167 |
contr.fill = GridBagConstraints.VERTICAL;
|
168 |
contr.weightx =0;
|
169 |
contr.weighty =1;
|
170 |
|
171 |
pNorth.add(getPNorthCenter(), contr); |
172 |
|
173 |
contr.fill = GridBagConstraints.BOTH;
|
174 |
contr.weightx =0.5;
|
175 |
contr.weighty =1;
|
176 |
|
177 |
pNorth.add(getPNorthEast(), contr); |
178 |
|
179 |
|
180 |
|
181 |
// pNorth.add(getPNorthEast(), java.awt.BorderLayout.EAST);
|
182 |
// pNorth.add(getPNorthCenter(), java.awt.BorderLayout.CENTER);
|
183 |
// pNorth.add(getPNorthWest(), java.awt.BorderLayout.WEST);
|
184 |
} |
185 |
|
186 |
return pNorth;
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* This method initializes pNorth
|
191 |
*
|
192 |
* @return javax.swing.JPanel
|
193 |
*/
|
194 |
private JPanel getPCentral() { |
195 |
if (pCentral == null) { |
196 |
StringBuilder tit = new StringBuilder(); |
197 |
tit.append(PluginServices.getText(this,"expression")); |
198 |
tit.append(" ");
|
199 |
tit.append(PluginServices.getText(this, "column")); |
200 |
tit.append(" : ");
|
201 |
tit.append(evalExpression.getFieldDescriptorSelected().getName()); |
202 |
pCentral = new JPanel(); |
203 |
pCentral.setLayout(new GridBagLayout()); |
204 |
pCentral.setBorder(javax.swing.BorderFactory.createTitledBorder( |
205 |
null, tit.toString(),
|
206 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
207 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
208 |
// lblColumn = new JLabel();
|
209 |
// pCentral.add(lblColumn, null);
|
210 |
//
|
211 |
GridBagConstraints contr = new GridBagConstraints(); |
212 |
contr.gridwidth = GridBagConstraints.REMAINDER;
|
213 |
contr.gridheight = 1;
|
214 |
contr.fill = GridBagConstraints.BOTH;
|
215 |
contr.ipadx = 5;
|
216 |
contr.ipady = 5;
|
217 |
contr.weightx=1;
|
218 |
contr.weighty=1;
|
219 |
pCentral.add(getJScrollPane(), contr); |
220 |
// lblColumn.setText(PluginServices.getText(this, "column") + " : " +
|
221 |
// evalExpression.getFieldDescriptorSelected().getFieldAlias());
|
222 |
GridBagConstraints contr1 = new GridBagConstraints(); |
223 |
contr1.gridwidth = 1;
|
224 |
contr1.gridheight = 1;
|
225 |
contr1.fill = GridBagConstraints.NONE;
|
226 |
contr1.ipadx = 5;
|
227 |
contr1.ipady = 5;
|
228 |
contr1.anchor = GridBagConstraints.CENTER;
|
229 |
pCentral.add(getBClear(), contr1); |
230 |
} |
231 |
|
232 |
return pCentral;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* This method initializes pSouth
|
237 |
*
|
238 |
* @return javax.swing.JPanel
|
239 |
*/
|
240 |
private AcceptCancelPanel getAcceptCancel() {
|
241 |
if (this.acceptCancel == null) { |
242 |
this.acceptCancel = new AcceptCancelPanel( |
243 |
new java.awt.event.ActionListener() {
|
244 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
245 |
boolean isAccepted=true; |
246 |
Preferences prefs = Preferences.userRoot().node( |
247 |
"fieldExpressionOptions");
|
248 |
int limit;
|
249 |
limit = prefs.getInt("limit_rows_in_memory", -1); |
250 |
if (limit != -1) { |
251 |
int option = JOptionPane |
252 |
.showConfirmDialog( |
253 |
(Component) PluginServices
|
254 |
.getMainFrame(), |
255 |
PluginServices |
256 |
.getText( |
257 |
this,
|
258 |
"it_has_established_a_limit_of_rows_will_lose_the_possibility_to_undo_wants_to_continue"));
|
259 |
if (option != JOptionPane.OK_OPTION) { |
260 |
return;
|
261 |
} |
262 |
} |
263 |
try {
|
264 |
long t1 = System.currentTimeMillis(); |
265 |
isAccepted=evalExpression(); |
266 |
long t2 = System.currentTimeMillis(); |
267 |
System.out
|
268 |
.println("Tiempo evaluar expresiones = "
|
269 |
+ (t2 - t1)); |
270 |
} catch (BSFException e1) {
|
271 |
NotificationManager.addError(e1); |
272 |
} |
273 |
if (isAccepted)
|
274 |
PluginServices.getMDIManager().closeWindow( |
275 |
EvalExpressionDialog.this); |
276 |
} |
277 |
}, new java.awt.event.ActionListener() {
|
278 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
279 |
PluginServices.getMDIManager().closeWindow( |
280 |
EvalExpressionDialog.this); |
281 |
} |
282 |
}); |
283 |
acceptCancel.setOkButtonEnabled(false);
|
284 |
} |
285 |
|
286 |
return this.acceptCancel; |
287 |
} |
288 |
/**
|
289 |
* Evaluate the expression.
|
290 |
* @throws ReadDriverException
|
291 |
* @throws BSFException
|
292 |
*
|
293 |
* @throws EvalError
|
294 |
* @throws DriverException
|
295 |
* @throws DriverIOException
|
296 |
* @throws IOException
|
297 |
* @throws DriverIOException
|
298 |
* @throws IOException
|
299 |
* @throws BSFException
|
300 |
*/
|
301 |
private boolean evalExpression() throws BSFException{ |
302 |
String expression=getTxtExp().getText()
|
303 |
.replaceAll("\\[","field(\"") |
304 |
.replaceAll("\\]","\")"); |
305 |
interpreter.declareBean("evalExpression",evalExpression,EvalExpression.class);
|
306 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def expression():\n" + |
307 |
" return " +expression+ ""); |
308 |
|
309 |
try {
|
310 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def isCorrect():\n" + |
311 |
" evalExpression.isCorrectValue(expression())\n");
|
312 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"isCorrect()"); |
313 |
} catch (BSFException ee) {
|
314 |
String message=ee.getMessage();
|
315 |
if (message.length()>200){ |
316 |
message=message.substring(0,200); |
317 |
} |
318 |
int option=JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), |
319 |
PluginServices.getText(this,
|
320 |
"error_expression")+"\n"+message+"\n"+PluginServices.getText(this,"continue?")); |
321 |
if (option!=JOptionPane.OK_OPTION) { |
322 |
return false; |
323 |
} |
324 |
} |
325 |
try {
|
326 |
featureStore.beginEditingGroup(PluginServices.getText(this, "expression")); |
327 |
|
328 |
ArrayList exceptions=new ArrayList(); |
329 |
interpreter.declareBean("exceptions",exceptions,ArrayList.class); |
330 |
FeatureSet set= featureStore.getFeatureSet(table.getModel().getQuery()); |
331 |
DisposableIterator iterator=set.iterator(); |
332 |
|
333 |
interpreter.declareBean("featureSet", set, FeatureSet.class);
|
334 |
interpreter.declareBean("iterator",iterator,Iterator.class); |
335 |
boolean emptySelection = ((FeatureSelection)featureStore.getSelection()).isEmpty();
|
336 |
// interpreter.declareBean("emptySelection", emptySelection, boolean.class);
|
337 |
boolean select = true; |
338 |
interpreter.declareBean("select", select, boolean.class); |
339 |
if (!emptySelection){
|
340 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def p():\n" + |
341 |
" \n" +
|
342 |
" while iterator.hasNext():\n" +
|
343 |
" feature=iterator.next()\n" +
|
344 |
" select=featureStore.getSelection().isSelected(feature)\n" +
|
345 |
" if select:\n" +
|
346 |
" featureContainer.setFeature(feature)\n" +
|
347 |
" obj=expression()\n" +
|
348 |
" evalExpression.setValue(featureSet,feature,obj)\n" +
|
349 |
" iterator.dispose()\n" +
|
350 |
" featureSet.dispose\n"
|
351 |
); |
352 |
}else{
|
353 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def p():\n" + |
354 |
" \n" +
|
355 |
" while iterator.hasNext():\n" +
|
356 |
" feature=iterator.next()\n" +
|
357 |
" featureContainer.setFeature(feature)\n" +
|
358 |
" obj=expression()\n" +
|
359 |
" evalExpression.setValue(featureSet,feature,obj)\n" +
|
360 |
" iterator.dispose()\n" +
|
361 |
" featureSet.dispose\n"
|
362 |
); |
363 |
} |
364 |
|
365 |
try {
|
366 |
interpreter.eval(ExpressionFieldExtension.JYTHON,null,-1,-1,"p()"); |
367 |
} catch (BSFException ee) {
|
368 |
|
369 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
370 |
PluginServices.getText(this, "evaluate_expression_with_errors")+" "+exceptions.size() +ee.getMessage()); |
371 |
} |
372 |
featureStore.endEditingGroup(); |
373 |
} catch (NeedEditingModeException e) {
|
374 |
// TODO Auto-generated catch block
|
375 |
e.printStackTrace(); |
376 |
} catch (DataException e) {
|
377 |
// TODO Auto-generated catch block
|
378 |
e.printStackTrace(); |
379 |
} |
380 |
|
381 |
return true; |
382 |
} |
383 |
/**
|
384 |
* This method initializes pMessage
|
385 |
*
|
386 |
* @return javax.swing.JPanel
|
387 |
*/
|
388 |
private JPanel getPMessage() { |
389 |
if (pMessage == null) { |
390 |
|
391 |
pMessage = new JPanel(); |
392 |
pMessage.setLayout(new GridLayout()); |
393 |
pMessage.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"information"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
394 |
// pMessage.setPreferredSize(new java.awt.Dimension(550,120));
|
395 |
pMessage.add(getJScrollPane3(), null);
|
396 |
} |
397 |
return pMessage;
|
398 |
} |
399 |
private void evalExpressions() throws BSFException { |
400 |
featureStore = table.getModel().getStore(); |
401 |
// sds = ies.getRecordset();
|
402 |
interpreter.declareBean("featureStore", featureStore,FeatureStore.class);
|
403 |
featureContainer=new FeatureContainer();
|
404 |
DisposableIterator iterator=null;
|
405 |
FeatureSet set= null;
|
406 |
try {
|
407 |
set=featureStore.getFeatureSet(table.getModel().getQuery()); |
408 |
iterator = set.iterator(); |
409 |
|
410 |
} catch (DataException e) {
|
411 |
// TODO Auto-generated catch block
|
412 |
e.printStackTrace(); |
413 |
} |
414 |
if (iterator.hasNext())
|
415 |
feature=(Feature)iterator.next(); |
416 |
iterator.dispose(); |
417 |
set.dispose(); |
418 |
interpreter.declareBean("featureContainer", featureContainer,FeatureContainer.class);
|
419 |
} |
420 |
/**
|
421 |
* Evaluate the fields.
|
422 |
*
|
423 |
* @param interpreter
|
424 |
*
|
425 |
* @throws EvalError
|
426 |
*/
|
427 |
int lastType=-1; |
428 |
private JButton bClear = null; |
429 |
private JTabbedPane tabPrincipal = null; |
430 |
private JPanel pPrincipal = null; |
431 |
private JPanel pAdvanced = null; |
432 |
private JPanel pAdvancedNorth = null; |
433 |
private JTextField jTextField = null; |
434 |
private JButton bFile = null; |
435 |
private JPanel pAdvancedCenter = null; |
436 |
private JLabel lblLeng = null; |
437 |
private JButton bEval = null; |
438 |
private JScrollPane jScrollPane3 = null; |
439 |
private JTextArea txtMessage2 = null; |
440 |
private void refreshOperators(int type) { |
441 |
if (lastType!=-1 && lastType==type) |
442 |
return;
|
443 |
lastType=type; |
444 |
ListOperatorsModel lom=(ListOperatorsModel)getListCommand().getModel(); |
445 |
lom.clear(); |
446 |
for (int i=0;i<operators.size();i++) { |
447 |
IOperator operator = (IOperator)operators.get(i); |
448 |
operator.setType(type); |
449 |
//Comprobar si tiene una capa asociada y pasarsela al GraphicOperator.
|
450 |
if ((lv != null) && operator instanceof GraphicOperator) { |
451 |
GraphicOperator igo = (GraphicOperator) operator; |
452 |
igo.setLayer(lv); |
453 |
} |
454 |
if (operator.isEnable()) {
|
455 |
lom.addOperator(operator); |
456 |
//System.out.println("Operator = "+operator.toString());
|
457 |
} |
458 |
} |
459 |
getListCommand().repaint(); |
460 |
getJScrollPane2().repaint(); |
461 |
getJScrollPane2().doLayout(); |
462 |
this.doLayout();
|
463 |
|
464 |
} |
465 |
/**
|
466 |
* This method initializes jScrollPane
|
467 |
*
|
468 |
* @return javax.swing.JScrollPane
|
469 |
*/
|
470 |
private JScrollPane getJScrollPane() { |
471 |
if (jScrollPane == null) { |
472 |
jScrollPane = new JScrollPane(); |
473 |
jScrollPane.setPreferredSize(new java.awt.Dimension(480, 80)); |
474 |
jScrollPane.setViewportView(getTxtExp()); |
475 |
} |
476 |
|
477 |
return jScrollPane;
|
478 |
} |
479 |
|
480 |
/**
|
481 |
* This method initializes txtExp
|
482 |
*
|
483 |
* @return javax.swing.JTextArea
|
484 |
*/
|
485 |
private JTextArea getTxtExp() { |
486 |
if (txtExp == null) { |
487 |
txtExp = new JTextArea(); |
488 |
txtExp.addCaretListener(new CaretListener(){ |
489 |
public void caretUpdate(CaretEvent e) { |
490 |
if (txtExp.getText().length()>0) |
491 |
getAcceptCancel().setOkButtonEnabled(true);
|
492 |
else
|
493 |
getAcceptCancel().setOkButtonEnabled(false);
|
494 |
} |
495 |
|
496 |
|
497 |
|
498 |
|
499 |
}); |
500 |
} |
501 |
|
502 |
return txtExp;
|
503 |
} |
504 |
|
505 |
public WindowInfo getWindowInfo() {
|
506 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG+WindowInfo.RESIZABLE);
|
507 |
wi.setTitle(PluginServices.getText(this, "calculate_expression")); |
508 |
|
509 |
|
510 |
return wi;
|
511 |
} |
512 |
|
513 |
/**
|
514 |
* This method initializes pNorthEast
|
515 |
*
|
516 |
* @return javax.swing.JPanel
|
517 |
*/
|
518 |
private JPanel getPNorthEast() { |
519 |
if (pNorthEast == null) { |
520 |
pNorthEast = new JPanel(new GridLayout()); |
521 |
pNorthEast.setBorder(javax.swing.BorderFactory.createTitledBorder( |
522 |
null, PluginServices.getText(this,"commands"), |
523 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
524 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
525 |
pNorthEast.add(getJScrollPane2(), null);
|
526 |
} |
527 |
|
528 |
return pNorthEast;
|
529 |
} |
530 |
|
531 |
/**
|
532 |
* This method initializes pNorthCenter
|
533 |
*
|
534 |
* @return javax.swing.JPanel
|
535 |
*/
|
536 |
private JPanel getPNorthCenter() { |
537 |
if (pNorthCenter == null) { |
538 |
pNorthCenter = new JPanel(); |
539 |
pNorthCenter.setLayout(new BoxLayout(getPNorthCenter(), |
540 |
BoxLayout.Y_AXIS));
|
541 |
pNorthCenter.setBorder(javax.swing.BorderFactory.createTitledBorder( |
542 |
null, PluginServices.getText(this,"type"), |
543 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
544 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
545 |
pNorthCenter.add(getRbNumber(), null);
|
546 |
pNorthCenter.add(getRbString(), null);
|
547 |
pNorthCenter.add(getRbDate(), null);
|
548 |
} |
549 |
|
550 |
return pNorthCenter;
|
551 |
} |
552 |
|
553 |
/**
|
554 |
* This method initializes pNorthWest
|
555 |
*
|
556 |
* @return javax.swing.JPanel
|
557 |
*/
|
558 |
private JPanel getPNorthWest() { |
559 |
if (pNorthWest == null) { |
560 |
pNorthWest = new JPanel(new GridLayout()); |
561 |
pNorthWest.setBorder(javax.swing.BorderFactory.createTitledBorder( |
562 |
null, PluginServices.getText(this,"field"), |
563 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
564 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
565 |
pNorthWest.add(getJScrollPane1(), null);
|
566 |
} |
567 |
|
568 |
return pNorthWest;
|
569 |
} |
570 |
|
571 |
/**
|
572 |
* This method initializes jScrollPane1
|
573 |
*
|
574 |
* @return javax.swing.JScrollPane
|
575 |
*/
|
576 |
private JScrollPane getJScrollPane1() { |
577 |
if (jScrollPane1 == null) { |
578 |
jScrollPane1 = new JScrollPane(); |
579 |
jScrollPane1.setPreferredSize(new java.awt.Dimension(175, 100)); |
580 |
jScrollPane1.setViewportView(getListFields()); |
581 |
} |
582 |
|
583 |
return jScrollPane1;
|
584 |
} |
585 |
|
586 |
/**
|
587 |
* This method initializes listFields
|
588 |
*
|
589 |
* @return javax.swing.JList
|
590 |
*/
|
591 |
private JList getListFields() { |
592 |
if (listFields == null) { |
593 |
listFields = new JList(); |
594 |
listFields.setModel(new ListOperatorsModel());
|
595 |
|
596 |
ListOperatorsModel lm = (ListOperatorsModel) listFields.getModel(); |
597 |
FeatureType fds=evalExpression.getFieldDescriptors(); |
598 |
for (int i = 0; i < fds.size(); i++) { |
599 |
Field field=new Field(); |
600 |
field.setFieldDescription(fds.getAttributeDescriptor(i)); |
601 |
try {
|
602 |
field.eval(interpreter); |
603 |
} catch (BSFException e) {
|
604 |
e.printStackTrace(); |
605 |
} |
606 |
lm.addOperator(field); |
607 |
} |
608 |
|
609 |
listFields.addMouseListener(new MouseListener() { |
610 |
public void mouseClicked(MouseEvent e) { |
611 |
IOperator operator=((IOperator) listFields.getSelectedValue()); |
612 |
getTxtMessage2().setText(operator.getTooltip()); |
613 |
if (e.getClickCount() == 2) { |
614 |
getTxtExp().setText(operator.addText( |
615 |
getTxtExp().getText())); |
616 |
} |
617 |
} |
618 |
|
619 |
public void mouseEntered(MouseEvent e) { |
620 |
} |
621 |
|
622 |
public void mouseExited(MouseEvent e) { |
623 |
} |
624 |
|
625 |
public void mousePressed(MouseEvent e) { |
626 |
} |
627 |
|
628 |
public void mouseReleased(MouseEvent e) { |
629 |
} |
630 |
}); |
631 |
} |
632 |
|
633 |
return listFields;
|
634 |
} |
635 |
|
636 |
/**
|
637 |
* This method initializes rbNumber
|
638 |
*
|
639 |
* @return javax.swing.JRadioButton
|
640 |
*/
|
641 |
private JRadioButton getRbNumber() { |
642 |
if (rbNumber == null) { |
643 |
rbNumber = new JRadioButton(); |
644 |
rbNumber.setText(PluginServices.getText(this,"numeric")); |
645 |
rbNumber.setSelected(true);
|
646 |
rbNumber.addChangeListener(new javax.swing.event.ChangeListener() {
|
647 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
648 |
if (rbNumber.isSelected())
|
649 |
refreshCommands(); |
650 |
} |
651 |
}); |
652 |
} |
653 |
|
654 |
return rbNumber;
|
655 |
} |
656 |
|
657 |
/**
|
658 |
* This method initializes rbString
|
659 |
*
|
660 |
* @return javax.swing.JRadioButton
|
661 |
*/
|
662 |
private JRadioButton getRbString() { |
663 |
if (rbString == null) { |
664 |
rbString = new JRadioButton(); |
665 |
rbString.setText(PluginServices.getText(this,"string")); |
666 |
rbString.addChangeListener(new javax.swing.event.ChangeListener() {
|
667 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
668 |
if (rbString.isSelected())
|
669 |
refreshCommands(); |
670 |
} |
671 |
}); |
672 |
} |
673 |
|
674 |
return rbString;
|
675 |
} |
676 |
|
677 |
/**
|
678 |
* This method initializes rbData
|
679 |
*
|
680 |
* @return javax.swing.JRadioButton
|
681 |
*/
|
682 |
private JRadioButton getRbDate() { |
683 |
if (rbDate == null) { |
684 |
rbDate = new JRadioButton(); |
685 |
rbDate.setText(PluginServices.getText(this,"date")); |
686 |
rbDate.addChangeListener(new javax.swing.event.ChangeListener() {
|
687 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
688 |
if (rbDate.isSelected())
|
689 |
refreshCommands(); |
690 |
} |
691 |
}); |
692 |
} |
693 |
|
694 |
return rbDate;
|
695 |
} |
696 |
|
697 |
/**
|
698 |
* This method initializes jScrollPane2
|
699 |
*
|
700 |
* @return javax.swing.JScrollPane
|
701 |
*/
|
702 |
private JScrollPane getJScrollPane2() { |
703 |
if (jScrollPane2 == null) { |
704 |
jScrollPane2 = new JScrollPane(); |
705 |
jScrollPane2.setPreferredSize(new java.awt.Dimension(175, 100)); |
706 |
jScrollPane2.setViewportView(getListCommand()); |
707 |
} |
708 |
|
709 |
return jScrollPane2;
|
710 |
} |
711 |
|
712 |
/**
|
713 |
* Refresh the commands.
|
714 |
*/
|
715 |
private void refreshCommands() { |
716 |
int type=IOperator.NUMBER;
|
717 |
if (getRbNumber().isSelected()) {
|
718 |
type=IOperator.NUMBER; |
719 |
} else if (getRbString().isSelected()) { |
720 |
type=IOperator.STRING; |
721 |
} else if (getRbDate().isSelected()) { |
722 |
type=IOperator.DATE; |
723 |
} |
724 |
refreshOperators(type); |
725 |
|
726 |
} |
727 |
|
728 |
/**
|
729 |
* This method initializes ListCommand
|
730 |
*
|
731 |
* @return javax.swing.JList
|
732 |
*/
|
733 |
private JList getListCommand() { |
734 |
if (listCommand == null) { |
735 |
listCommand = new JList(); |
736 |
listCommand.setModel(new ListOperatorsModel());
|
737 |
listCommand.addMouseListener(new MouseListener() { |
738 |
public void mouseClicked(MouseEvent e) { |
739 |
IOperator operator=((IOperator) listCommand.getSelectedValue()); |
740 |
getTxtMessage2().setText(operator.getTooltip()); |
741 |
if (e.getClickCount() == 2) { |
742 |
if (listCommand.getSelectedValue()==null) |
743 |
return;
|
744 |
getTxtExp().setText(operator.addText( |
745 |
getTxtExp().getText())); |
746 |
} |
747 |
} |
748 |
|
749 |
public void mouseEntered(MouseEvent e) { |
750 |
} |
751 |
|
752 |
public void mouseExited(MouseEvent e) { |
753 |
} |
754 |
|
755 |
public void mousePressed(MouseEvent e) { |
756 |
} |
757 |
|
758 |
public void mouseReleased(MouseEvent e) { |
759 |
} |
760 |
}); |
761 |
refreshOperators(IOperator.NUMBER); |
762 |
} |
763 |
|
764 |
return listCommand;
|
765 |
} |
766 |
|
767 |
/**
|
768 |
* This method initializes bClear
|
769 |
*
|
770 |
* @return javax.swing.JButton
|
771 |
*/
|
772 |
private JButton getBClear() { |
773 |
if (bClear == null) { |
774 |
bClear = new JButton(); |
775 |
bClear.setText(PluginServices.getText(this,"clear_expression")); |
776 |
bClear.addActionListener(new java.awt.event.ActionListener() {
|
777 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
778 |
getTxtExp().setText("");
|
779 |
} |
780 |
}); |
781 |
} |
782 |
return bClear;
|
783 |
} |
784 |
/**
|
785 |
* This method initializes tabPrincipal
|
786 |
*
|
787 |
* @return javax.swing.JTabbedPane
|
788 |
*/
|
789 |
private JTabbedPane getTabPrincipal() { |
790 |
if (tabPrincipal == null) { |
791 |
tabPrincipal = new JTabbedPane(); |
792 |
tabPrincipal.addTab(PluginServices.getText(this,"general"), null, getPPrincipal(), null); |
793 |
tabPrincipal.addTab(PluginServices.getText(this,"advanced"), null, getPAdvanced(), null); |
794 |
} |
795 |
return tabPrincipal;
|
796 |
} |
797 |
/**
|
798 |
* This method initializes pPrincipal
|
799 |
*
|
800 |
* @return javax.swing.JPanel
|
801 |
*/
|
802 |
private JPanel getPPrincipal() { |
803 |
if (pPrincipal == null) { |
804 |
pPrincipal = new JPanel(); |
805 |
pPrincipal.setLayout(new BorderLayout()); |
806 |
// pPrincipal.setPreferredSize(new java.awt.Dimension(540,252));
|
807 |
pPrincipal.add(getPNorth(), java.awt.BorderLayout.NORTH); |
808 |
pPrincipal.add(getPCentral(), java.awt.BorderLayout.CENTER); |
809 |
|
810 |
} |
811 |
return pPrincipal;
|
812 |
} |
813 |
/**
|
814 |
* This method initializes pAdvanced
|
815 |
*
|
816 |
* @return javax.swing.JPanel
|
817 |
*/
|
818 |
private JPanel getPAdvanced() { |
819 |
if (pAdvanced == null) { |
820 |
pAdvanced = new JPanel(); |
821 |
pAdvanced.setLayout(new BorderLayout()); |
822 |
pAdvanced.add(getPAdvancedNorth(), java.awt.BorderLayout.NORTH); |
823 |
pAdvanced.add(getPAdvancedCenter(), java.awt.BorderLayout.CENTER); |
824 |
} |
825 |
return pAdvanced;
|
826 |
} |
827 |
/**
|
828 |
* This method initializes pAdvancedNorth
|
829 |
*
|
830 |
* @return javax.swing.JPanel
|
831 |
*/
|
832 |
private JPanel getPAdvancedNorth() { |
833 |
if (pAdvancedNorth == null) { |
834 |
pAdvancedNorth = new JPanel(new GridBagLayout()); |
835 |
// pAdvancedNorth.setPreferredSize(new java.awt.Dimension(873,100));
|
836 |
pAdvancedNorth.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"expressions_from_file"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
837 |
GridBagConstraints contr = new GridBagConstraints(); |
838 |
contr.anchor = GridBagConstraints.FIRST_LINE_START;
|
839 |
contr.fill = GridBagConstraints.HORIZONTAL;
|
840 |
contr.weighty =0;
|
841 |
contr.weightx =1;
|
842 |
contr.insets = new Insets(3,3,3,3); |
843 |
contr.ipadx=5;
|
844 |
contr.ipady=5;
|
845 |
|
846 |
pAdvancedNorth.add(getJTextField(), contr); |
847 |
contr.fill = GridBagConstraints.NONE;
|
848 |
contr.weighty =0;
|
849 |
contr.weightx =0;
|
850 |
pAdvancedNorth.add(getBFile(), null);
|
851 |
pAdvancedNorth.add(getBEval(), null);
|
852 |
} |
853 |
return pAdvancedNorth;
|
854 |
} |
855 |
/**
|
856 |
* This method initializes jTextField
|
857 |
*
|
858 |
* @return javax.swing.JTextField
|
859 |
*/
|
860 |
private JTextField getJTextField() { |
861 |
if (jTextField == null) { |
862 |
jTextField = new JTextField(); |
863 |
jTextField.setPreferredSize(new java.awt.Dimension(250,20)); |
864 |
} |
865 |
return jTextField;
|
866 |
} |
867 |
/**
|
868 |
* This method initializes bFile
|
869 |
*
|
870 |
* @return javax.swing.JButton
|
871 |
*/
|
872 |
private JButton getBFile() { |
873 |
if (bFile == null) { |
874 |
bFile = new JButton(); |
875 |
bFile.setText(PluginServices.getText(this,"explorer")); |
876 |
bFile.addActionListener(new java.awt.event.ActionListener() {
|
877 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
878 |
JFileChooser jfc = new JFileChooser(); |
879 |
jfc.addChoosableFileFilter(new GenericFileFilter("py", |
880 |
PluginServices.getText(this, "python"))); |
881 |
|
882 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
883 |
File fileExpression = jfc.getSelectedFile();
|
884 |
getJTextField().setText(fileExpression.getAbsolutePath()); |
885 |
|
886 |
} |
887 |
} |
888 |
}); |
889 |
} |
890 |
return bFile;
|
891 |
} |
892 |
private String readFile(File aFile) throws IOException { |
893 |
StringBuffer fileContents = new StringBuffer(); |
894 |
FileReader fileReader = new FileReader(aFile); |
895 |
int c;
|
896 |
while ((c = fileReader.read()) > -1) { |
897 |
fileContents.append((char)c);
|
898 |
} |
899 |
fileReader.close(); |
900 |
return fileContents.toString();
|
901 |
} |
902 |
/**
|
903 |
* This method initializes pAdvancedCenter
|
904 |
*
|
905 |
* @return javax.swing.JPanel
|
906 |
*/
|
907 |
private JPanel getPAdvancedCenter() { |
908 |
if (pAdvancedCenter == null) { |
909 |
lblLeng = new JLabel(); |
910 |
lblLeng.setText("");
|
911 |
pAdvancedCenter = new JPanel(); |
912 |
pAdvancedCenter.add(lblLeng, null);
|
913 |
} |
914 |
return pAdvancedCenter;
|
915 |
} |
916 |
|
917 |
/**
|
918 |
* This method initializes bEval
|
919 |
*
|
920 |
* @return javax.swing.JButton
|
921 |
*/
|
922 |
private JButton getBEval() { |
923 |
if (bEval == null) { |
924 |
bEval = new JButton(); |
925 |
bEval.setText(PluginServices.getText(this,"evaluate")); |
926 |
bEval.addActionListener(new java.awt.event.ActionListener() {
|
927 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
928 |
File file=new File(getJTextField().getText()); |
929 |
if (!file.exists()) {
|
930 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"incorrect_file")); |
931 |
return;
|
932 |
} |
933 |
try {
|
934 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,readFile(file)); |
935 |
} catch (IOException e1) { |
936 |
e1.printStackTrace(); |
937 |
} catch (BSFException e1) {
|
938 |
e1.printStackTrace(); |
939 |
} |
940 |
} |
941 |
}); |
942 |
} |
943 |
return bEval;
|
944 |
} |
945 |
/**
|
946 |
* This method initializes jScrollPane3
|
947 |
*
|
948 |
* @return javax.swing.JScrollPane
|
949 |
*/
|
950 |
private JScrollPane getJScrollPane3() { |
951 |
if (jScrollPane3 == null) { |
952 |
jScrollPane3 = new JScrollPane(); |
953 |
jScrollPane3.setPreferredSize(new java.awt.Dimension(530,80)); |
954 |
jScrollPane3.setViewportView(getTxtMessage2()); |
955 |
} |
956 |
return jScrollPane3;
|
957 |
} |
958 |
/**
|
959 |
* This method initializes txtMessage2
|
960 |
*
|
961 |
* @return javax.swing.JTextArea
|
962 |
*/
|
963 |
private JTextArea getTxtMessage2() { |
964 |
if (txtMessage2 == null) { |
965 |
txtMessage2 = new JTextArea(); |
966 |
txtMessage2.setText(PluginServices.getText(this,"eval_expression_will_be_carried_out_right_now_with_current_values_in_table")); |
967 |
//txtMessage2.setSize(new java.awt.Dimension(550,100));
|
968 |
txtMessage2.setEditable(false);
|
969 |
txtMessage2.setBackground(UIManager.getColor(this)); |
970 |
} |
971 |
return txtMessage2;
|
972 |
} |
973 |
public Object getWindowProfile() { |
974 |
return WindowInfo.DIALOG_PROFILE;
|
975 |
} |
976 |
} // @jve:decl-index=0:visual-constraint="10,10"
|