Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extExpressionField / src / com / iver / cit / gvsig / project / documents / table / gui / EvalExpresionDialog.java @ 11110

History | View | Annotate | Download (26.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.event.MouseEvent;
6
import java.awt.event.MouseListener;
7
import java.io.File;
8
import java.io.FileReader;
9
import java.io.IOException;
10
import java.util.ArrayList;
11
import java.util.prefs.Preferences;
12

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

    
29
import org.apache.bsf.BSFException;
30
import org.apache.bsf.BSFManager;
31
import org.gvsig.gui.beans.AcceptCancelPanel;
32
import org.gvsig.gui.beans.swing.JButton;
33

    
34
import bsh.EvalError;
35

    
36
import com.hardcode.gdbms.engine.data.driver.DriverException;
37
import com.iver.andami.PluginServices;
38
import com.iver.andami.ui.mdiManager.IWindow;
39
import com.iver.andami.ui.mdiManager.WindowInfo;
40
import com.iver.cit.gvsig.ExpresionFieldExtension;
41
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
42
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
43
import com.iver.cit.gvsig.fmap.edition.IEditableSource;
44
import com.iver.cit.gvsig.fmap.layers.FBitSet;
45
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
46
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
47
import com.iver.cit.gvsig.project.documents.table.GraphicOperator;
48
import com.iver.cit.gvsig.project.documents.table.IOperator;
49
import com.iver.cit.gvsig.project.documents.table.Index;
50
import com.iver.cit.gvsig.project.documents.table.operators.Field;
51
import com.iver.utiles.GenericFileFilter;
52

    
53

    
54
/**
55
 * DOCUMENT ME!
56
 *
57
 * @author Vicente Caballero Navarro
58
 */
59
public class EvalExpresionDialog extends JPanel implements IWindow {
60
    private JPanel pNorth = null;
61
    private JPanel pCentral = null;
62
    private JScrollPane jScrollPane = null;
63
    private JTextArea txtExp = null;
64
    private AcceptCancelPanel acceptCancel;
65
    private Table table;
66
    private FLyrVect lv;
67
    private JLabel lblColumn = null;
68
    private JPanel pNorthEast = null;
69
    private JPanel pNorthCenter = null;
70
    private JPanel pNorthWest = null;
71
    private JScrollPane jScrollPane1 = null;
72
    private JList listFields = null;
73
    private JRadioButton rbNumber = null;
74
    private JRadioButton rbString = null;
75
    private JRadioButton rbDate = null;
76
    private JScrollPane jScrollPane2 = null;
77
    private JList listCommand = null;
78
    private BSFManager interpreter = null; // Construct an interpreter
79
    private Index indexRow = null;
80
    private SelectableDataSource sds = null;
81
    private EvalExpresion evalExpresion=null;
82
    private IEditableSource ies=null;
83
        private JPanel pMessage;
84
        //private JTextArea txtMessage;
85
    private static ArrayList operators=new ArrayList();
86
    public EvalExpresionDialog(Table table,BSFManager interpreter, ArrayList operators) {
87
        super();
88
        this.operators=operators;
89
        this.interpreter=interpreter;
90
        this.table = table;
91
        initialize();
92

    
93
    }
94
    /**
95
     * This method initializes this
96
     */
97
    private void initialize() {
98
            try {
99
                evalExpresions();
100
        } catch (BSFException e) {
101
                        e.printStackTrace();
102
                }
103
            evalExpresion=new EvalExpresion();
104
            evalExpresion.setTable(table);
105
            lv = (FLyrVect) table.getModel().getAssociatedTable();
106
        ButtonGroup bg = new ButtonGroup();
107
        bg.add(getRbNumber());
108
        bg.add(getRbString());
109
        bg.add(getRbDate());
110
        this.setLayout(new BorderLayout());
111
        this.setSize(549, 480);
112
        this.add(getTabPrincipal(), java.awt.BorderLayout.CENTER);
113
        this.add(getPMessage(), java.awt.BorderLayout.NORTH);
114
        this.add(getAcceptCancel(), java.awt.BorderLayout.SOUTH);
115
    }
116
    /**
117
     * This method initializes pCentral
118
     *
119
     * @return javax.swing.JPanel
120
     */
121
    private JPanel getPNorth() {
122
        if (pNorth == null) {
123
            pNorth = new JPanel();
124
            pNorth.setLayout(new BorderLayout());
125
            pNorth.add(getPNorthEast(), java.awt.BorderLayout.EAST);
126
            pNorth.add(getPNorthCenter(), java.awt.BorderLayout.CENTER);
127
            pNorth.add(getPNorthWest(), java.awt.BorderLayout.WEST);
128
        }
129

    
130
        return pNorth;
131
    }
132

    
133
    /**
134
     * This method initializes pNorth
135
     *
136
     * @return javax.swing.JPanel
137
     */
138
    private JPanel getPCentral() {
139
        if (pCentral == null) {
140
            pCentral = new JPanel();
141
            pCentral.setBorder(javax.swing.BorderFactory.createTitledBorder(
142
                    null, PluginServices.getText(this,"expresion"),
143
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
144
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
145
            lblColumn = new JLabel();
146
            pCentral.add(lblColumn, null);
147

    
148
            pCentral.add(getJScrollPane(), null);
149
            lblColumn.setText(PluginServices.getText(this, "column") + " : " +
150
                evalExpresion.getFieldDescriptorSelected().getFieldAlias());
151
            pCentral.add(getBClear(), null);
152
        }
153

    
154
        return pCentral;
155
    }
156

    
157
    /**
158
     * This method initializes pSouth
159
     *
160
     * @return javax.swing.JPanel
161
     */
162
    private AcceptCancelPanel getAcceptCancel() {
163
                if (this.acceptCancel == null) {
164
                        this.acceptCancel = new AcceptCancelPanel(
165
                                        new java.awt.event.ActionListener() {
166
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
167
                                                        boolean isAccepted=true;
168
                                                        Preferences prefs = Preferences.userRoot().node(
169
                                                                        "fieldExpresionOptions");
170
                                                        int limit;
171
                                                        limit = prefs.getInt("limit_rows_in_memory", -1);
172
                                                        if (limit != -1) {
173
                                                                int option = JOptionPane
174
                                                                                .showConfirmDialog(
175
                                                                                                (Component) PluginServices
176
                                                                                                                .getMainFrame(),
177
                                                                                                PluginServices
178
                                                                                                                .getText(
179
                                                                                                                                this,
180
                                                                                                                                "it_has_established_a_limit_of_rows_will_lose_the_possibility_to_undo_wants_to_continue"));
181
                                                                if (option != JOptionPane.OK_OPTION) {
182
                                                                        return;
183
                                                                }
184
                                                        }
185
                                                        try {
186
                                                                long t1 = System.currentTimeMillis();
187
                                                                isAccepted=evalExpresion();
188
                                                                long t2 = System.currentTimeMillis();
189
                                                                System.out
190
                                                                                .println("Tiempo evaluar expresiones = "
191
                                                                                                + (t2 - t1));
192
                                                        } catch (DriverException e1) {
193
                                                                e1.printStackTrace();
194
                                                        } catch (IOException e1) {
195
                                                                e1.printStackTrace();
196
                                                        } catch (DriverIOException e1) {
197
                                                                e1.printStackTrace();
198
                                                        } catch (BSFException e1) {
199
                                                                e1.printStackTrace();
200
                                                        }
201
                                                        if (isAccepted)
202
                                                                PluginServices.getMDIManager().closeWindow(
203
                                                                        EvalExpresionDialog.this);
204
                                                }
205
                                        }, new java.awt.event.ActionListener() {
206
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
207
                                                        PluginServices.getMDIManager().closeWindow(
208
                                                                        EvalExpresionDialog.this);
209
                                                }
210
                                        });
211
                        acceptCancel.setOkButtonEnabled(false);
212
                }
213

    
214
                return this.acceptCancel;
215
        }
216
    /**
217
         * Evaluate the expresion.
218
         *
219
         * @throws EvalError
220
         * @throws DriverException
221
         * @throws DriverIOException
222
         * @throws IOException
223
         * @throws DriverIOException
224
         * @throws IOException
225
         * @throws BSFException
226
         */
227
    private boolean evalExpresion()
228
        throws DriverException, IOException, DriverIOException, BSFException {
229
        long rowCount = sds.getRowCount();
230
        String expresion=getTxtExp().getText()
231
                .replaceAll("\\[","field(\"")
232
                .replaceAll("\\]","\")");
233
        interpreter.eval(ExpresionFieldExtension.BEANSHELL,null,-1,-1,"java.lang.Object expresion () {" +expresion+ ";};");
234
        if (rowCount > 0) {
235
            try {
236
                interpreter.eval(ExpresionFieldExtension.BEANSHELL,null,-1,-1,"expresion()");
237
            } catch (BSFException ee) {
238
                int option=JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(),
239
                    PluginServices.getText(this,
240
                        "error_expresion")+"\n"+ee.getMessage()+"\n"+PluginServices.getText(this,"continue?"));
241
                if (option!=JOptionPane.OK_OPTION) {
242
                        return false;
243
                }
244
            }
245
        }
246
        ies.startComplexRow();
247
        interpreter.declareBean("ee",evalExpresion,EvalExpresion.class);
248
        ArrayList exceptions=new ArrayList();
249
        interpreter.declareBean("exceptions",exceptions,ArrayList.class);
250
        FBitSet selection=sds.getSelection();
251
        String p= "";
252
        if (selection.cardinality() > 0) {
253
                        interpreter.declareBean("selection", selection, FBitSet.class);
254
                        p = "for (int i = selection.nextSetBit(0);" + "i >= 0;"
255
                                        + "i = selection.nextSetBit(i + 1)){" + "indexRow.set(i);"
256
                                        + "java.lang.Object obj = expresion();"
257
                                        + "ee.setValue(obj,i);" + "ee.saveEdits(i);" + "}" + "";
258
                } else {
259
                        p = "for (int i=0; i < " + rowCount + "; i++){"
260
                                        + "indexRow.set(i);" +
261
                                        "java.lang.Object obj = expresion();" +
262
                                        "ee.setValue(obj,i);" + "ee.saveEdits(i);" + "}" + "";
263
                }
264
        try {
265
                interpreter.eval(ExpresionFieldExtension.BEANSHELL,null,-1,-1,p);
266
        } catch (BSFException ee) {
267

    
268
                 JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(),
269
                     PluginServices.getText(this, "evaluate_expresion_with_errors")+" "+(rowCount-indexRow.get())+"\n"+ee.getMessage());
270
        }
271

    
272
        ies.endComplexRow(PluginServices.getText(this, "expresion"));
273
        table.refresh();
274
        return true;
275
    }
276
    /**
277
         * This method initializes pMessage
278
         *
279
         * @return javax.swing.JPanel
280
         */
281
        private JPanel getPMessage() {
282
                if (pMessage == null) {
283

    
284
                        pMessage = new JPanel();
285
                        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));
286
                        pMessage.setPreferredSize(new java.awt.Dimension(550,120));
287
                        pMessage.add(getJScrollPane3(), null);
288
                }
289
                return pMessage;
290
        }
291
    private void evalExpresions() throws BSFException {
292
        ies = table.getModel().getModelo();
293
        sds = ies.getRecordset();
294
        interpreter.declareBean("sds", sds,SelectableDataSource.class);
295
        indexRow=new Index();
296
        interpreter.declareBean("indexRow", indexRow,Index.class);
297
    }
298
    /**
299
     * Evaluate the fields.
300
     *
301
     * @param interpreter
302
     *
303
     * @throws EvalError
304
     */
305
    int lastType=-1;
306
        private JButton bClear = null;
307
        private JTabbedPane tabPrincipal = null;
308
        private JPanel pPrincipal = null;
309
        private JPanel pAdvanced = null;
310
        private JPanel pAdvancedNorth = null;
311
        private JTextField jTextField = null;
312
        private JButton bFile = null;
313
        private JPanel pAdvancedCenter = null;
314
        private JLabel lblLeng = null;
315
        private JButton bEval = null;
316
        private JScrollPane jScrollPane3 = null;
317
        private JTextArea txtMessage2 = null;
318
        private void refreshOperators(int type) {
319
        if (lastType!=-1 && lastType==type)
320
                return;
321
        lastType=type;
322
            ListOperatorsModel lom=(ListOperatorsModel)getListCommand().getModel();
323
        lom.clear();
324
           for (int i=0;i<operators.size();i++) {
325
            IOperator operator = (IOperator)operators.get(i);
326
            operator.setType(type);
327
            //Comprobar si tiene una capa asociada y pasarsela al GraphicOperator.
328
            if ((lv != null) && operator instanceof GraphicOperator) {
329
                GraphicOperator igo = (GraphicOperator) operator;
330
                igo.setLayer(lv);
331
            }
332
            if (operator.isEnable()) {
333
                   lom.addOperator(operator);
334
                   //System.out.println("Operator = "+operator.toString());
335
            }
336
        }
337
        getListCommand().repaint();
338

    
339
    }
340
    /**
341
     * This method initializes jScrollPane
342
     *
343
     * @return javax.swing.JScrollPane
344
     */
345
    private JScrollPane getJScrollPane() {
346
        if (jScrollPane == null) {
347
            jScrollPane = new JScrollPane();
348
            jScrollPane.setPreferredSize(new java.awt.Dimension(480, 80));
349
            jScrollPane.setViewportView(getTxtExp());
350
        }
351

    
352
        return jScrollPane;
353
    }
354

    
355
    /**
356
     * This method initializes txtExp
357
     *
358
     * @return javax.swing.JTextArea
359
     */
360
    private JTextArea getTxtExp() {
361
        if (txtExp == null) {
362
            txtExp = new JTextArea();
363
            txtExp.addCaretListener(new CaretListener(){
364
                                public void caretUpdate(CaretEvent e) {
365
                                        if (txtExp.getText().length()>0)
366
                                                getAcceptCancel().setOkButtonEnabled(true);
367
                                        else
368
                                                getAcceptCancel().setOkButtonEnabled(false);
369
                                }
370

    
371

    
372

    
373

    
374
                        });
375
        }
376

    
377
        return txtExp;
378
    }
379

    
380
    public WindowInfo getWindowInfo() {
381
         WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG);
382
        wi.setTitle(PluginServices.getText(this, "calculate_expresion"));
383

    
384
        return wi;
385
    }
386

    
387
    /**
388
     * This method initializes pNorthEast
389
     *
390
     * @return javax.swing.JPanel
391
     */
392
    private JPanel getPNorthEast() {
393
        if (pNorthEast == null) {
394
            pNorthEast = new JPanel();
395
            pNorthEast.setBorder(javax.swing.BorderFactory.createTitledBorder(
396
                    null, PluginServices.getText(this,"commands"),
397
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
398
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
399
            pNorthEast.add(getJScrollPane2(), null);
400
        }
401

    
402
        return pNorthEast;
403
    }
404

    
405
    /**
406
     * This method initializes pNorthCenter
407
     *
408
     * @return javax.swing.JPanel
409
     */
410
    private JPanel getPNorthCenter() {
411
        if (pNorthCenter == null) {
412
            pNorthCenter = new JPanel();
413
            pNorthCenter.setLayout(new BoxLayout(getPNorthCenter(),
414
                    BoxLayout.Y_AXIS));
415
            pNorthCenter.setBorder(javax.swing.BorderFactory.createTitledBorder(
416
                    null, PluginServices.getText(this,"type"),
417
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
418
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
419
            pNorthCenter.add(getRbNumber(), null);
420
            pNorthCenter.add(getRbString(), null);
421
            pNorthCenter.add(getRbDate(), null);
422
        }
423

    
424
        return pNorthCenter;
425
    }
426

    
427
    /**
428
     * This method initializes pNorthWest
429
     *
430
     * @return javax.swing.JPanel
431
     */
432
    private JPanel getPNorthWest() {
433
        if (pNorthWest == null) {
434
            pNorthWest = new JPanel();
435
            pNorthWest.setBorder(javax.swing.BorderFactory.createTitledBorder(
436
                    null, PluginServices.getText(this,"field"),
437
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
438
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
439
            pNorthWest.add(getJScrollPane1(), null);
440
        }
441

    
442
        return pNorthWest;
443
    }
444

    
445
    /**
446
     * This method initializes jScrollPane1
447
     *
448
     * @return javax.swing.JScrollPane
449
     */
450
    private JScrollPane getJScrollPane1() {
451
        if (jScrollPane1 == null) {
452
            jScrollPane1 = new JScrollPane();
453
            jScrollPane1.setPreferredSize(new java.awt.Dimension(175, 100));
454
            jScrollPane1.setViewportView(getListFields());
455
        }
456

    
457
        return jScrollPane1;
458
    }
459

    
460
    /**
461
     * This method initializes listFields
462
     *
463
     * @return javax.swing.JList
464
     */
465
    private JList getListFields() {
466
        if (listFields == null) {
467
            listFields = new JList();
468
            listFields.setModel(new ListOperatorsModel());
469

    
470
            ListOperatorsModel lm = (ListOperatorsModel) listFields.getModel();
471
            FieldDescription[] fds=evalExpresion.getFieldDescriptors();
472
            for (int i = 0; i < fds.length; i++) {
473
                Field field=new Field();
474
                field.setFieldDescription(fds[i]);
475
                try {
476
                        field.eval(interpreter);
477
                } catch (BSFException e) {
478
                                        e.printStackTrace();
479
                                }
480
                lm.addOperator(field);
481
            }
482

    
483
            listFields.addMouseListener(new MouseListener() {
484
                    public void mouseClicked(MouseEvent e) {
485
                            IOperator operator=((IOperator) listFields.getSelectedValue());
486
                            getTxtMessage2().setText(operator.getTooltip());
487
                            if (e.getClickCount() == 2) {
488
                            getTxtExp().setText(operator.addText(
489
                                    getTxtExp().getText()));
490
                        }
491
                    }
492

    
493
                    public void mouseEntered(MouseEvent e) {
494
                    }
495

    
496
                    public void mouseExited(MouseEvent e) {
497
                    }
498

    
499
                    public void mousePressed(MouseEvent e) {
500
                    }
501

    
502
                    public void mouseReleased(MouseEvent e) {
503
                    }
504
                });
505
        }
506

    
507
        return listFields;
508
    }
509

    
510
    /**
511
     * This method initializes rbNumber
512
     *
513
     * @return javax.swing.JRadioButton
514
     */
515
    private JRadioButton getRbNumber() {
516
        if (rbNumber == null) {
517
            rbNumber = new JRadioButton();
518
            rbNumber.setText(PluginServices.getText(this,"numeric"));
519
            rbNumber.setSelected(true);
520
            rbNumber.addChangeListener(new javax.swing.event.ChangeListener() {
521
                public void stateChanged(javax.swing.event.ChangeEvent e) {
522
                     if (rbNumber.isSelected())
523
                         refreshCommands();
524
                }
525
            });
526
        }
527

    
528
        return rbNumber;
529
    }
530

    
531
    /**
532
     * This method initializes rbString
533
     *
534
     * @return javax.swing.JRadioButton
535
     */
536
    private JRadioButton getRbString() {
537
        if (rbString == null) {
538
            rbString = new JRadioButton();
539
            rbString.setText(PluginServices.getText(this,"string"));
540
            rbString.addChangeListener(new javax.swing.event.ChangeListener() {
541
                public void stateChanged(javax.swing.event.ChangeEvent e) {
542
                     if (rbString.isSelected())
543
                         refreshCommands();
544
                }
545
            });
546
        }
547

    
548
        return rbString;
549
    }
550

    
551
    /**
552
     * This method initializes rbData
553
     *
554
     * @return javax.swing.JRadioButton
555
     */
556
    private JRadioButton getRbDate() {
557
        if (rbDate == null) {
558
            rbDate = new JRadioButton();
559
            rbDate.setText(PluginServices.getText(this,"date"));
560
            rbDate.addChangeListener(new javax.swing.event.ChangeListener() {
561
                public void stateChanged(javax.swing.event.ChangeEvent e) {
562
                    if (rbDate.isSelected())
563
                         refreshCommands();
564
                }
565
            });
566
        }
567

    
568
        return rbDate;
569
    }
570

    
571
    /**
572
     * This method initializes jScrollPane2
573
     *
574
     * @return javax.swing.JScrollPane
575
     */
576
    private JScrollPane getJScrollPane2() {
577
        if (jScrollPane2 == null) {
578
            jScrollPane2 = new JScrollPane();
579
            jScrollPane2.setPreferredSize(new java.awt.Dimension(175, 100));
580
            jScrollPane2.setViewportView(getListCommand());
581
        }
582

    
583
        return jScrollPane2;
584
    }
585

    
586
    /**
587
     * Refresh the commands.
588
     */
589
    private void refreshCommands() {
590
        int type=IOperator.NUMBER;
591
        if (getRbNumber().isSelected()) {
592
            type=IOperator.NUMBER;
593
        } else if (getRbString().isSelected()) {
594
            type=IOperator.STRING;
595
        } else if (getRbDate().isSelected()) {
596
            type=IOperator.DATE;
597
        }
598
        refreshOperators(type);
599

    
600
    }
601

    
602
    /**
603
     * This method initializes ListCommand
604
     *
605
     * @return javax.swing.JList
606
     */
607
    private JList getListCommand() {
608
        if (listCommand == null) {
609
            listCommand = new JList();
610
            listCommand.setModel(new ListOperatorsModel());
611
            listCommand.addMouseListener(new MouseListener() {
612
                    public void mouseClicked(MouseEvent e) {
613
                            IOperator operator=((IOperator) listCommand.getSelectedValue());
614
                            getTxtMessage2().setText(operator.getTooltip());
615
                            if (e.getClickCount() == 2) {
616
                                if (listCommand.getSelectedValue()==null)
617
                                        return;
618
                            getTxtExp().setText(operator.addText(
619
                                    getTxtExp().getText()));
620
                        }
621
                    }
622

    
623
                    public void mouseEntered(MouseEvent e) {
624
                    }
625

    
626
                    public void mouseExited(MouseEvent e) {
627
                    }
628

    
629
                    public void mousePressed(MouseEvent e) {
630
                    }
631

    
632
                    public void mouseReleased(MouseEvent e) {
633
                    }
634
                });
635
            refreshOperators(IOperator.NUMBER);
636
        }
637

    
638
        return listCommand;
639
    }
640

    
641
    /**
642
         * This method initializes bClear
643
         *
644
         * @return javax.swing.JButton
645
         */
646
        private JButton getBClear() {
647
                if (bClear == null) {
648
                        bClear = new JButton();
649
                        bClear.setText(PluginServices.getText(this,"clear_expresion"));
650
                        bClear.addActionListener(new java.awt.event.ActionListener() {
651
                                public void actionPerformed(java.awt.event.ActionEvent e) {
652
                                        getTxtExp().setText("");
653
                                }
654
                        });
655
                }
656
                return bClear;
657
        }
658
        /**
659
         * This method initializes tabPrincipal
660
         *
661
         * @return javax.swing.JTabbedPane
662
         */
663
        private JTabbedPane getTabPrincipal() {
664
                if (tabPrincipal == null) {
665
                        tabPrincipal = new JTabbedPane();
666
                        tabPrincipal.addTab(PluginServices.getText(this,"general"), null, getPPrincipal(), null);
667
                        tabPrincipal.addTab(PluginServices.getText(this,"advanced"), null, getPAdvanced(), null);
668
                }
669
                return tabPrincipal;
670
        }
671
        /**
672
         * This method initializes pPrincipal
673
         *
674
         * @return javax.swing.JPanel
675
         */
676
        private JPanel getPPrincipal() {
677
                if (pPrincipal == null) {
678
                        pPrincipal = new JPanel();
679
                        pPrincipal.setLayout(new BorderLayout());
680
                        pPrincipal.setPreferredSize(new java.awt.Dimension(540,252));
681
                        pPrincipal.add(getPNorth(), java.awt.BorderLayout.NORTH);
682
                        pPrincipal.add(getPCentral(), java.awt.BorderLayout.CENTER);
683

    
684
                }
685
                return pPrincipal;
686
        }
687
        /**
688
         * This method initializes pAdvanced
689
         *
690
         * @return javax.swing.JPanel
691
         */
692
        private JPanel getPAdvanced() {
693
                if (pAdvanced == null) {
694
                        pAdvanced = new JPanel();
695
                        pAdvanced.setLayout(new BorderLayout());
696
                        pAdvanced.add(getPAdvancedNorth(), java.awt.BorderLayout.NORTH);
697
                        pAdvanced.add(getPAdvancedCenter(), java.awt.BorderLayout.CENTER);
698
                }
699
                return pAdvanced;
700
        }
701
        /**
702
         * This method initializes pAdvancedNorth
703
         *
704
         * @return javax.swing.JPanel
705
         */
706
        private JPanel getPAdvancedNorth() {
707
                if (pAdvancedNorth == null) {
708
                        pAdvancedNorth = new JPanel();
709
                        pAdvancedNorth.setPreferredSize(new java.awt.Dimension(873,100));
710
                        pAdvancedNorth.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"expresions_from_file"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
711
                        pAdvancedNorth.add(getJTextField(), null);
712
                        pAdvancedNorth.add(getBFile(), null);
713
                        pAdvancedNorth.add(getBEval(), null);
714
                }
715
                return pAdvancedNorth;
716
        }
717
        /**
718
         * This method initializes jTextField
719
         *
720
         * @return javax.swing.JTextField
721
         */
722
        private JTextField getJTextField() {
723
                if (jTextField == null) {
724
                        jTextField = new JTextField();
725
                        jTextField.setPreferredSize(new java.awt.Dimension(250,20));
726
                }
727
                return jTextField;
728
        }
729
        /**
730
         * This method initializes bFile
731
         *
732
         * @return javax.swing.JButton
733
         */
734
        private JButton getBFile() {
735
                if (bFile == null) {
736
                        bFile = new JButton();
737
                        bFile.setText(PluginServices.getText(this,"explorer"));
738
                        bFile.addActionListener(new java.awt.event.ActionListener() {
739
                                public void actionPerformed(java.awt.event.ActionEvent e) {
740
                                        JFileChooser jfc = new JFileChooser();
741
                                        jfc.addChoosableFileFilter(new GenericFileFilter("bs",
742
                                                        PluginServices.getText(this, "expresions")));
743

    
744
                                        if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
745
                                                File fileExpresion = jfc.getSelectedFile();
746
                                                getJTextField().setText(fileExpresion.getAbsolutePath());
747

    
748
                                        }
749
                                }
750
                                });
751
                }
752
                return bFile;
753
        }
754
        private String readFile(File aFile) throws IOException {
755
                StringBuffer fileContents = new StringBuffer();
756
                FileReader fileReader = new FileReader(aFile);
757
                int c;
758
                while ((c = fileReader.read()) > -1) {
759
                        fileContents.append((char)c);
760
                }
761
                fileReader.close();
762
                return fileContents.toString();
763
        }
764
        /**
765
         * This method initializes pAdvancedCenter
766
         *
767
         * @return javax.swing.JPanel
768
         */
769
        private JPanel getPAdvancedCenter() {
770
                if (pAdvancedCenter == null) {
771
                        lblLeng = new JLabel();
772
                        lblLeng.setText("");
773
                        pAdvancedCenter = new JPanel();
774
                        pAdvancedCenter.add(lblLeng, null);
775
                }
776
                return pAdvancedCenter;
777
        }
778

    
779
        /**
780
         * This method initializes bEval
781
         *
782
         * @return javax.swing.JButton
783
         */
784
        private JButton getBEval() {
785
                if (bEval == null) {
786
                        bEval = new JButton();
787
                        bEval.setText(PluginServices.getText(this,"evaluate"));
788
                        bEval.addActionListener(new java.awt.event.ActionListener() {
789
                                public void actionPerformed(java.awt.event.ActionEvent e) {
790
                                        File file=new File(getJTextField().getText());
791
                                        if (!file.exists()) {
792
                                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"incorrect_file"));
793
                                                return;
794
                                        }
795
                                        try {
796
                                                interpreter.eval(ExpresionFieldExtension.BEANSHELL,null,-1,-1,readFile(file));
797
                                        } catch (IOException e1) {
798
                                                e1.printStackTrace();
799
                                        } catch (BSFException e1) {
800
                                                e1.printStackTrace();
801
                                        }
802
                                }
803
                        });
804
                }
805
                return bEval;
806
        }
807
        /**
808
         * This method initializes jScrollPane3
809
         *
810
         * @return javax.swing.JScrollPane
811
         */
812
        private JScrollPane getJScrollPane3() {
813
                if (jScrollPane3 == null) {
814
                        jScrollPane3 = new JScrollPane();
815
                        jScrollPane3.setPreferredSize(new java.awt.Dimension(530,80));
816
                        jScrollPane3.setViewportView(getTxtMessage2());
817
                }
818
                return jScrollPane3;
819
        }
820
        /**
821
         * This method initializes txtMessage2
822
         *
823
         * @return javax.swing.JTextArea
824
         */
825
        private JTextArea getTxtMessage2() {
826
                if (txtMessage2 == null) {
827
                        txtMessage2 = new JTextArea();
828
                        txtMessage2.setText(PluginServices.getText(this,"eval_expresion_will_be_carried_out_right_now_with_current_values_in_table"));
829
                        //txtMessage2.setSize(new java.awt.Dimension(550,100));
830
                        txtMessage2.setEditable(false);
831
                        txtMessage2.setBackground(UIManager.getColor(this));
832
                }
833
                return txtMessage2;
834
        }
835
} //  @jve:decl-index=0:visual-constraint="10,10"