Statistics
| Revision:

root / trunk / extensions / extExpressionField / src / com / iver / cit / gvsig / project / documents / table / gui / EvalExpressionDialog.java @ 36459

History | View | Annotate | Download (23.3 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.prefs.Preferences;
15

    
16
import javax.swing.BoxLayout;
17
import javax.swing.ButtonGroup;
18
import javax.swing.JFileChooser;
19
import javax.swing.JLabel;
20
import javax.swing.JList;
21
import javax.swing.JOptionPane;
22
import javax.swing.JPanel;
23
import javax.swing.JRadioButton;
24
import javax.swing.JScrollPane;
25
import javax.swing.JTabbedPane;
26
import javax.swing.JTextArea;
27
import javax.swing.JTextField;
28
import javax.swing.UIManager;
29
import javax.swing.event.CaretEvent;
30
import javax.swing.event.CaretListener;
31

    
32
import org.apache.bsf.BSFException;
33
import org.gvsig.gui.beans.AcceptCancelPanel;
34
import org.gvsig.gui.beans.swing.JButton;
35

    
36
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
37
import com.iver.andami.PluginServices;
38
import com.iver.andami.messages.NotificationManager;
39
import com.iver.andami.ui.mdiManager.IWindow;
40
import com.iver.andami.ui.mdiManager.WindowInfo;
41
import com.iver.cit.gvsig.ExpressionFieldExtension;
42
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
43
import com.iver.cit.gvsig.project.documents.table.GraphicOperator;
44
import com.iver.cit.gvsig.project.documents.table.IOperator;
45
import com.iver.cit.gvsig.project.documents.table.operators.Field;
46
import com.iver.utiles.GenericFileFilter;
47

    
48

    
49
/**
50
 * This dialog allows the user create expressions to fill a field of the table
51
 *
52
 * @author Vicente Caballero Navarro
53
 */
54
public class EvalExpressionDialog extends JPanel implements IWindow {
55
    private JPanel pNorth = null;
56
    private JPanel pCentral = null;
57
    private JScrollPane jScrollPane = null;
58
    private JTextArea txtExp = null;
59
    private AcceptCancelPanel acceptCancel;
60
    private JPanel pNorthEast = null;
61
    private JPanel pNorthCenter = null;
62
    private JPanel pNorthWest = null;
63
    private JScrollPane jScrollPane1 = null;
64
    private JList listFields = null;
65
    private JRadioButton rbNumber = null;
66
    private JRadioButton rbString = null;
67
    private JRadioButton rbDate = null;
68
    private JScrollPane jScrollPane2 = null;
69
    private JList listCommand = null;
70
    private JPanel pMessage;
71
    private EvalExpression evalExpression;
72
    int lastType = -1;
73
    private JButton bClear = null;
74
    private JTabbedPane tabPrincipal = null;
75
    private JPanel pPrincipal = null;
76
    private JPanel pAdvanced = null;
77
    private JPanel pAdvancedNorth = null;
78
    private JTextField jTextField = null;
79
    private JButton bFile = null;
80
    private JPanel pAdvancedCenter = null;
81
    private JLabel lblLeng = null;
82
    private JButton bEval = null;
83
    private JScrollPane jScrollPane3 = null;
84
    private JTextArea txtMessage2 = null;
85
        
86

    
87
    public EvalExpressionDialog(EvalExpression ee) {
88
        this.evalExpression = ee;
89
        initialize();
90
    }
91

    
92
    private void initialize() {
93
        ButtonGroup bg = new ButtonGroup();
94
        bg.add(getRbNumber());
95
        bg.add(getRbString());
96
        bg.add(getRbDate());
97
        this.setLayout(new GridBagLayout());
98
        this.setSize(549, 480);
99
        GridBagConstraints constr = new GridBagConstraints();
100
        constr.gridwidth = GridBagConstraints.REMAINDER;
101
        constr.gridheight = 1;
102
        constr.fill = GridBagConstraints.BOTH;
103
        constr.ipadx=5;
104
        constr.ipady=5;
105
        constr.weightx=1;
106
        constr.weighty=0.3;
107

    
108
        this.add(getPMessage(), constr);
109
        constr.gridheight = 5;
110
        constr.weighty=1;
111
        this.add(getTabPrincipal(), constr);
112
        GridBagConstraints constr2 = new GridBagConstraints();
113
        constr2.gridwidth = GridBagConstraints.REMAINDER;
114
        constr2.gridheight = 1;
115
        constr2.fill = GridBagConstraints.HORIZONTAL;
116
        constr2.anchor = GridBagConstraints.LAST_LINE_END;
117
        constr2.weightx=1;
118
        constr2.weighty=0;
119

    
120
        this.add(getAcceptCancel(), constr2);
121

    
122
    }
123

    
124
    private JPanel getPNorth() {
125
        if (pNorth == null) {
126
            pNorth = new JPanel();
127
            pNorth.setLayout(new GridBagLayout());
128
            GridBagConstraints contr = new GridBagConstraints();
129
            contr.ipadx = 5;
130
            contr.ipady = 5;
131
            contr.fill = GridBagConstraints.BOTH;
132
            contr.weightx =1;
133
            contr.weighty =1;
134
            pNorth.add(getPNorthWest(), contr);
135

    
136
            contr.fill = GridBagConstraints.VERTICAL;
137
            contr.weightx =0;
138
            contr.weighty =1;
139

    
140
            pNorth.add(getPNorthCenter(), contr);
141

    
142
            contr.fill = GridBagConstraints.BOTH;
143
            contr.weightx =0.5;
144
            contr.weighty =1;
145

    
146
            pNorth.add(getPNorthEast(), contr);
147

    
148
        }
149

    
150
        return pNorth;
151
    }
152

    
153
    private JPanel getPCentral() {
154
        if (pCentral == null) {
155
                StringBuilder tit = new StringBuilder();
156
                tit.append(PluginServices.getText(this,"expression"));
157
                tit.append(" ");
158
                tit.append(PluginServices.getText(this, "column"));
159
                tit.append(" : ");
160
                tit.append(evalExpression.getFieldDescriptorSelected().getFieldAlias());
161
            pCentral = new JPanel();
162
            pCentral.setLayout(new GridBagLayout());
163
            pCentral.setBorder(javax.swing.BorderFactory.createTitledBorder(
164
                    null, tit.toString(),
165
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
166
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
167

    
168
            GridBagConstraints contr = new GridBagConstraints();
169
            contr.gridwidth = GridBagConstraints.REMAINDER;
170
            contr.gridheight = 1;
171
            contr.fill = GridBagConstraints.BOTH;
172
            contr.ipadx = 5;
173
            contr.ipady = 5;
174
            contr.weightx=1;
175
            contr.weighty=1;
176
            pCentral.add(getJScrollPane(), contr);
177

    
178
            GridBagConstraints contr1 = new GridBagConstraints();
179
            contr1.gridwidth = 1;
180
            contr1.gridheight = 1;
181
            contr1.fill = GridBagConstraints.NONE;
182
            contr1.ipadx = 5;
183
            contr1.ipady = 5;
184
            contr1.anchor = GridBagConstraints.CENTER;
185
            pCentral.add(getBClear(), contr1);
186
        }
187

    
188
        return pCentral;
189
    }
190

    
191
    private AcceptCancelPanel getAcceptCancel() {
192
                if (this.acceptCancel == null) {
193
                        this.acceptCancel = new AcceptCancelPanel(
194
                                        new java.awt.event.ActionListener() {
195
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
196
                                                        boolean isAccepted=true;
197
                                                        Preferences prefs = Preferences.userRoot().node(
198
                                                                        "fieldExpressionOptions");
199
                                                        int limit;
200
                                                        limit = prefs.getInt("limit_rows_in_memory", -1);
201
                                                        if (limit != -1) {
202
                                                                int option = JOptionPane.showConfirmDialog(
203
                                                                                                (Component) PluginServices.getMainFrame(),
204
                                                                                                PluginServices.getText(
205
                                                                                                                this,
206
                                                                                                                "it_has_established_a_limit_of_rows_will_lose_the_possibility_to_undo_wants_to_continue"));
207
                                                                if (option != JOptionPane.OK_OPTION) {
208
                                                                        return;
209
                                                                }
210
                                                        }
211
                                                        try {
212
                                                                isAccepted=evalExpression.evalExpression(getTxtExp().getText());
213
                                if (evalExpression.getTable() != null) {
214
                                    evalExpression.getTable().refresh();
215
                                }
216
                                                        } catch (BSFException e1) {
217
                                                                NotificationManager.addError(e1);
218
                                                        } catch (ReadDriverException e1) {
219
                                                                NotificationManager.addError(e1);
220
                                                        }
221
                                                        if (isAccepted)
222
                                                                PluginServices.getMDIManager().closeWindow(
223
                                                                        EvalExpressionDialog.this);
224
                                                }
225
                                        }, new java.awt.event.ActionListener() {
226
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
227
                                                        PluginServices.getMDIManager().closeWindow(
228
                                                                        EvalExpressionDialog.this);
229
                                                }
230
                                        });
231
                        acceptCancel.setOkButtonEnabled(false);
232
                }
233

    
234
                return this.acceptCancel;
235
        }
236
   
237
        private JPanel getPMessage() {
238
                if (pMessage == null) {
239

    
240
                        pMessage = new JPanel();
241
                        pMessage.setLayout(new GridLayout());
242
                        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));
243
                        pMessage.add(getJScrollPane3(), null);
244
                }
245
                return pMessage;
246
        }
247
    
248

    
249
        
250
        private void refreshOperators(int type) {
251
        if (lastType!=-1 && lastType==type)
252
                return;
253
        lastType=type;
254
            ListOperatorsModel lom=(ListOperatorsModel)getListCommand().getModel();
255
        lom.clear();
256

    
257
        for (IOperator operator : evalExpression.getOperators()) {
258
            operator.setType(type);
259
            if ((evalExpression.getLayer() != null) && operator instanceof GraphicOperator) {
260
                GraphicOperator igo = (GraphicOperator) operator;
261
                igo.setLayer(evalExpression.getLayer());
262
            }
263
            if (operator.isEnable()) {
264
                lom.addOperator(operator);
265
            }
266

    
267
        }
268

    
269
        getListCommand().repaint();
270
        getJScrollPane2().repaint();
271
        getJScrollPane2().doLayout();
272
        this.doLayout();
273

    
274
    }
275
    
276
    private JScrollPane getJScrollPane() {
277
        if (jScrollPane == null) {
278
            jScrollPane = new JScrollPane();
279
            jScrollPane.setPreferredSize(new java.awt.Dimension(480, 80));
280
            jScrollPane.setViewportView(getTxtExp());
281
        }
282

    
283
        return jScrollPane;
284
    }
285

    
286
    
287
    private JTextArea getTxtExp() {
288
        if (txtExp == null) {
289
            txtExp = new JTextArea();
290
            txtExp.addCaretListener(new CaretListener(){
291
                                public void caretUpdate(CaretEvent e) {
292
                                        if (txtExp.getText().length()>0)
293
                                                getAcceptCancel().setOkButtonEnabled(true);
294
                                        else
295
                                                getAcceptCancel().setOkButtonEnabled(false);
296
                                }
297
                        });
298
        }
299

    
300
        return txtExp;
301
    }
302

    
303
    public WindowInfo getWindowInfo() {
304
         WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG+WindowInfo.RESIZABLE);
305
        wi.setTitle(PluginServices.getText(this, "calculate_expression"));
306

    
307

    
308
        return wi;
309
    }
310

    
311
    private JPanel getPNorthEast() {
312
        if (pNorthEast == null) {
313
            pNorthEast = new JPanel(new GridLayout());
314
            pNorthEast.setBorder(javax.swing.BorderFactory.createTitledBorder(
315
                    null, PluginServices.getText(this,"commands"),
316
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
317
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
318
            pNorthEast.add(getJScrollPane2(), null);
319
        }
320

    
321
        return pNorthEast;
322
    }
323

    
324
    private JPanel getPNorthCenter() {
325
        if (pNorthCenter == null) {
326
            pNorthCenter = new JPanel();
327
            pNorthCenter.setLayout(new BoxLayout(getPNorthCenter(),
328
                    BoxLayout.Y_AXIS));
329
            pNorthCenter.setBorder(javax.swing.BorderFactory.createTitledBorder(
330
                    null, PluginServices.getText(this,"type"),
331
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
332
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
333
            pNorthCenter.add(getRbNumber(), null);
334
            pNorthCenter.add(getRbString(), null);
335
            pNorthCenter.add(getRbDate(), null);
336
        }
337

    
338
        return pNorthCenter;
339
    }
340

    
341
    private JPanel getPNorthWest() {
342
        if (pNorthWest == null) {
343
            pNorthWest = new JPanel(new GridLayout());
344
            pNorthWest.setBorder(javax.swing.BorderFactory.createTitledBorder(
345
                    null, PluginServices.getText(this,"field"),
346
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
347
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
348
            pNorthWest.add(getJScrollPane1(), null);
349
        }
350

    
351
        return pNorthWest;
352
    }
353

    
354
    private JScrollPane getJScrollPane1() {
355
        if (jScrollPane1 == null) {
356
            jScrollPane1 = new JScrollPane();
357
            jScrollPane1.setPreferredSize(new java.awt.Dimension(175, 100));
358
            jScrollPane1.setViewportView(getListFields());
359
        }
360

    
361
        return jScrollPane1;
362
    }
363

    
364
    private JList getListFields() {
365
        if (listFields == null) {
366
            listFields = new JList();
367
            listFields.setModel(new ListOperatorsModel());
368

    
369
            ListOperatorsModel lm = (ListOperatorsModel) listFields.getModel();
370
            FieldDescription[] fds=evalExpression.getFieldDescriptors();
371
            for (int i = 0; i < fds.length; i++) {
372
                Field field=new Field();
373
                field.setFieldDescription(fds[i]);
374
                try {
375
                    field.eval(evalExpression.getInterpreter());
376
                } catch (BSFException e) {
377
                                        e.printStackTrace();
378
                                }
379
                lm.addOperator(field);
380
            }
381

    
382
            listFields.addMouseListener(new MouseListener() {
383
                    public void mouseClicked(MouseEvent e) {
384
                            IOperator operator=((IOperator) listFields.getSelectedValue());
385
                            if (operator!=null){
386
                                    getTxtMessage2().setText(operator.getTooltip());
387
                                    if (e.getClickCount() == 2) {
388
                                        String text = getTxtExp().getText();
389
                                        int selStart = getTxtExp().getSelectionStart();
390
                                        int selEnd = getTxtExp().getSelectionEnd();
391
                                        
392
                            // int caretPos = getTxtExp().getCaretPosition();
393
//                                        if (caretPos == text.length()){
394
//                                                getTxtExp().setText(operator.addText(text));
395
//                                        } else {
396
//                                                getTxtExp().setText(operator.addText(text.substring(0, caretPos))+
397
//                                                                text.substring(caretPos));
398
//                                        }
399
                                        getTxtExp().setText(
400
                                                        operator.addText(text.substring(0, selStart))+
401
                                                        text.substring(selEnd)
402
                                        );
403

    
404
                                    }
405
                            }
406
                    }
407

    
408
                    public void mouseEntered(MouseEvent e) {
409
                    }
410

    
411
                    public void mouseExited(MouseEvent e) {
412
                    }
413

    
414
                    public void mousePressed(MouseEvent e) {
415
                    }
416

    
417
                    public void mouseReleased(MouseEvent e) {
418
                    }
419
                });
420
        }
421

    
422
        return listFields;
423
    }
424

    
425
    private JRadioButton getRbNumber() {
426
        if (rbNumber == null) {
427
            rbNumber = new JRadioButton();
428
            rbNumber.setText(PluginServices.getText(this,"numeric"));
429
            rbNumber.setSelected(true);
430
            rbNumber.addChangeListener(new javax.swing.event.ChangeListener() {
431
                public void stateChanged(javax.swing.event.ChangeEvent e) {
432
                     if (rbNumber.isSelected())
433
                         refreshCommands();
434
                }
435
            });
436
        }
437

    
438
        return rbNumber;
439
    }
440

    
441
    private JRadioButton getRbString() {
442
        if (rbString == null) {
443
            rbString = new JRadioButton();
444
            rbString.setText(PluginServices.getText(this,"string"));
445
            rbString.addChangeListener(new javax.swing.event.ChangeListener() {
446
                public void stateChanged(javax.swing.event.ChangeEvent e) {
447
                     if (rbString.isSelected())
448
                         refreshCommands();
449
                }
450
            });
451
        }
452

    
453
        return rbString;
454
    }
455

    
456
    private JRadioButton getRbDate() {
457
        if (rbDate == null) {
458
            rbDate = new JRadioButton();
459
            rbDate.setText(PluginServices.getText(this,"date"));
460
            rbDate.addChangeListener(new javax.swing.event.ChangeListener() {
461
                public void stateChanged(javax.swing.event.ChangeEvent e) {
462
                    if (rbDate.isSelected())
463
                         refreshCommands();
464
                }
465
            });
466
        }
467

    
468
        return rbDate;
469
    }
470

    
471
    private JScrollPane getJScrollPane2() {
472
        if (jScrollPane2 == null) {
473
            jScrollPane2 = new JScrollPane();
474
            jScrollPane2.setPreferredSize(new java.awt.Dimension(175, 100));
475
            jScrollPane2.setViewportView(getListCommand());
476
        }
477

    
478
        return jScrollPane2;
479
    }
480

    
481
    private void refreshCommands() {
482
        int type=IOperator.NUMBER;
483
        if (getRbNumber().isSelected()) {
484
            type=IOperator.NUMBER;
485
        } else if (getRbString().isSelected()) {
486
            type=IOperator.STRING;
487
        } else if (getRbDate().isSelected()) {
488
            type=IOperator.DATE;
489
        }
490
        refreshOperators(type);
491

    
492
    }
493

    
494
    private JList getListCommand() {
495
        if (listCommand == null) {
496
            listCommand = new JList();
497
            listCommand.setModel(new ListOperatorsModel());
498
            listCommand.addMouseListener(new MouseListener() {
499
                    public void mouseClicked(MouseEvent e) {
500
                            IOperator operator=((IOperator) listCommand.getSelectedValue());
501
                            if (operator!=null){
502
                                    getTxtMessage2().setText(operator.getTooltip());
503
                                    if (e.getClickCount() == 2) {
504
                                            if (listCommand.getSelectedValue()==null)
505
                                                    return;
506
                                    
507
                                    String text = getTxtExp().getText();
508
                                    int caretPos = getTxtExp().getCaretPosition();
509
                                    int selStart = getTxtExp().getSelectionStart();
510
                                    int selEnd = getTxtExp().getSelectionEnd();
511
                                    if (caretPos == text.length()){
512
                                            getTxtExp().setText(operator.addText(text));
513
                                    } else {
514
                                            getTxtExp().setText(
515
                                                            text.substring(0, selStart)+
516
                                                            operator.addText(text.substring(selStart, selEnd))+
517
                                                            text.substring(selEnd)
518
                                            );
519
                                    }
520

    
521
                                    
522
                                    }
523
                                    
524
                            }
525
                    }
526

    
527
                    public void mouseEntered(MouseEvent e) {
528
                    }
529

    
530
                    public void mouseExited(MouseEvent e) {
531
                    }
532

    
533
                    public void mousePressed(MouseEvent e) {
534
                    }
535

    
536
                    public void mouseReleased(MouseEvent e) {
537
                    }
538
                });
539
            refreshOperators(IOperator.NUMBER);
540
        }
541

    
542
        return listCommand;
543
    }
544

    
545
    private JButton getBClear() {
546
                if (bClear == null) {
547
                        bClear = new JButton();
548
                        bClear.setText(PluginServices.getText(this,"clear_expression"));
549
                        bClear.addActionListener(new java.awt.event.ActionListener() {
550
                                public void actionPerformed(java.awt.event.ActionEvent e) {
551
                                        getTxtExp().setText("");
552
                                }
553
                        });
554
                }
555
                return bClear;
556
        }
557
        
558
        private JTabbedPane getTabPrincipal() {
559
                if (tabPrincipal == null) {
560
                        tabPrincipal = new JTabbedPane();
561
                        tabPrincipal.addTab(PluginServices.getText(this,"general"), null, getPPrincipal(), null);
562
                        tabPrincipal.addTab(PluginServices.getText(this,"advanced"), null, getPAdvanced(), null);
563
                }
564
                return tabPrincipal;
565
        }
566
        
567
        private JPanel getPPrincipal() {
568
                if (pPrincipal == null) {
569
                        pPrincipal = new JPanel();
570
                        pPrincipal.setLayout(new BorderLayout());
571
                        pPrincipal.add(getPNorth(), java.awt.BorderLayout.NORTH);
572
                        pPrincipal.add(getPCentral(), java.awt.BorderLayout.CENTER);
573

    
574
                }
575
                return pPrincipal;
576
        }
577

    
578
        private JPanel getPAdvanced() {
579
                if (pAdvanced == null) {
580
                        pAdvanced = new JPanel();
581
                        pAdvanced.setLayout(new BorderLayout());
582
                        pAdvanced.add(getPAdvancedNorth(), java.awt.BorderLayout.NORTH);
583
                        pAdvanced.add(getPAdvancedCenter(), java.awt.BorderLayout.CENTER);
584
                }
585
                return pAdvanced;
586
        }
587

    
588
        private JPanel getPAdvancedNorth() {
589
                if (pAdvancedNorth == null) {
590
                        pAdvancedNorth = new JPanel(new GridBagLayout());
591
                        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));
592
                        GridBagConstraints contr = new GridBagConstraints();
593
                        contr.anchor = GridBagConstraints.FIRST_LINE_START;
594
                        contr.fill = GridBagConstraints.HORIZONTAL;
595
                        contr.weighty =0;
596
                        contr.weightx =1;
597
                        contr.insets = new Insets(3,3,3,3);
598
                        contr.ipadx=5;
599
                        contr.ipady=5;
600

    
601
                        pAdvancedNorth.add(getJTextField(), contr);
602
                        contr.fill = GridBagConstraints.NONE;
603
                        contr.weighty =0;
604
                        contr.weightx =0;
605
                        pAdvancedNorth.add(getBFile(), null);
606
                        pAdvancedNorth.add(getBEval(), null);
607
                }
608
                return pAdvancedNorth;
609
        }
610

    
611
        private JTextField getJTextField() {
612
                if (jTextField == null) {
613
                        jTextField = new JTextField();
614
                        jTextField.setPreferredSize(new java.awt.Dimension(250,20));
615
                }
616
                return jTextField;
617
        }
618

    
619
        private JButton getBFile() {
620
                if (bFile == null) {
621
                        bFile = new JButton();
622
                        bFile.setText(PluginServices.getText(this,"explorer"));
623
                        bFile.addActionListener(new java.awt.event.ActionListener() {
624
                                public void actionPerformed(java.awt.event.ActionEvent e) {
625
                                        JFileChooser jfc = new JFileChooser();
626
                                        jfc.addChoosableFileFilter(new GenericFileFilter("py",
627
                                                        PluginServices.getText(this, "python")));
628

    
629
                                        if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
630
                                                File fileExpression = jfc.getSelectedFile();
631
                                                getJTextField().setText(fileExpression.getAbsolutePath());
632

    
633
                                        }
634
                                }
635
                                });
636
                }
637
                return bFile;
638
        }
639
        private String readFile(File aFile) throws IOException {
640
                StringBuffer fileContents = new StringBuffer();
641
                FileReader fileReader = new FileReader(aFile);
642
                int c;
643
                while ((c = fileReader.read()) > -1) {
644
                        fileContents.append((char)c);
645
                }
646
                fileReader.close();
647
                return fileContents.toString();
648
        }
649

    
650
        private JPanel getPAdvancedCenter() {
651
                if (pAdvancedCenter == null) {
652
                        lblLeng = new JLabel();
653
                        lblLeng.setText("");
654
                        pAdvancedCenter = new JPanel();
655
                        pAdvancedCenter.add(lblLeng, null);
656
                }
657
                return pAdvancedCenter;
658
        }
659

    
660
        private JButton getBEval() {
661
                if (bEval == null) {
662
                        bEval = new JButton();
663
                        bEval.setText(PluginServices.getText(this,"evaluate"));
664
                        bEval.addActionListener(new java.awt.event.ActionListener() {
665
                                public void actionPerformed(java.awt.event.ActionEvent e) {
666
                                        File file=new File(getJTextField().getText());
667
                                        if (!file.exists()) {
668
                                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"incorrect_file"));
669
                                                return;
670
                                        }
671
                                        try {
672
                        evalExpression.getInterpreter().exec(
673
                                ExpressionFieldExtension.JYTHON,
674
                                null, -1, -1, readFile(file));
675
                                        } catch (IOException e1) {
676
                                                e1.printStackTrace();
677
                                        } catch (BSFException e1) {
678
                                                e1.printStackTrace();
679
                                        }
680
                                }
681
                        });
682
                }
683
                return bEval;
684
        }
685

    
686
        private JScrollPane getJScrollPane3() {
687
                if (jScrollPane3 == null) {
688
                        jScrollPane3 = new JScrollPane();
689
                        jScrollPane3.setPreferredSize(new java.awt.Dimension(530,80));
690
                        jScrollPane3.setViewportView(getTxtMessage2());
691
                }
692
                return jScrollPane3;
693
        }
694

    
695
        private JTextArea getTxtMessage2() {
696
                if (txtMessage2 == null) {
697
                        txtMessage2 = new JTextArea();
698
                        txtMessage2.setText(PluginServices.getText(this,"eval_expression_will_be_carried_out_right_now_with_current_values_in_table"));
699
                        txtMessage2.setEditable(false);
700
                        txtMessage2.setBackground(UIManager.getColor(this));
701
                }
702
                return txtMessage2;
703
        }
704
        public Object getWindowProfile() {
705
                return WindowInfo.DIALOG_PROFILE;
706
        }
707
}