Revision 38

View differences:

org.gvsig.expressionfield/trunk/org.gvsig.expressionfield/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Field.java
1
/*******************************************************************************
1
/**
2
 * *****************************************************************************
2 3
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
4
 * gvSIG. Desktop Geographic Information System.
5
 *
6
 * Copyright (C) 2007-2013 gvSIG Association.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 3
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
 * MA 02110-1301, USA.
22
 *
23
 * For any additional information, do not hesitate to contact us
24
 * at info AT gvsig.com, or visit our website www.gvsig.com.
25
 *
26
 ******************************************************************************
27
 */
26 28
package org.gvsig.expressionfield.project.documents.table.operators;
27 29

  
28 30
import org.gvsig.andami.PluginServices;
......
32 34
/**
33 35
 * @author Vicente Caballero Navarro
34 36
 */
35
public class Field extends AbstractField{
36
	private FeatureAttributeDescriptor fd;
37
	private String typeField;
38
	public Field() {
39
	}
40
	public void setFieldDescription(FeatureAttributeDescriptor fd) {
41
		this.fd=fd;
42
		switch (fd.getType()) {
43
		case DataTypes.INT:
44
		case DataTypes.LONG:
45
		case DataTypes.FLOAT:
46
		case DataTypes.DOUBLE:
47
			typeField = PluginServices.getText(this, "numeric_value");
48
			break;
49
		case DataTypes.STRING:
50
			typeField=PluginServices.getText(this,"string_value");
51
			break;
52
		case DataTypes.BOOLEAN:
53
			typeField=PluginServices.getText(this,"boolean_value");
54
			break;
55
		case DataTypes.DATE:
56
			typeField=PluginServices.getText(this,"date_value");
57
			break;
58
		}
37
public class Field extends AbstractField {
59 38

  
60
	}
61
	public String addText(String s) {
62
		return s.concat(toString());
63
	}
64
	public String toString() {
65
		return "["+fd.getName()+"]";
66
	}
67
	public boolean isEnable() {
68
		return true;
69
	}
70
	public String getTooltip(){
71
		return PluginServices.getText(this,"field")+":  "+fd.getName()+"\n"+getDescription();
72
	}
73
	public String getDescription() {
74
        return PluginServices.getText(this, "type") + ": " +
75
        typeField;
39
    private FeatureAttributeDescriptor fd;
40
    private String typeField;
41

  
42
    public Field() {
76 43
    }
44

  
45
    public void setFieldDescription(FeatureAttributeDescriptor fd) {
46
        this.fd = fd;
47
        switch (fd.getType()) {
48
        case DataTypes.INT:
49
        case DataTypes.LONG:
50
        case DataTypes.FLOAT:
51
        case DataTypes.DOUBLE:
52
            typeField = PluginServices.getText(this, "numeric_value");
53
            break;
54
        case DataTypes.STRING:
55
            typeField = PluginServices.getText(this, "string_value");
56
            break;
57
        case DataTypes.BOOLEAN:
58
            typeField = PluginServices.getText(this, "boolean_value");
59
            break;
60
        case DataTypes.DATE:
61
            typeField = PluginServices.getText(this, "date_value");
62
            break;
63
        }
64

  
65
    }
66

  
67
    public String addText(String s) {
68
        return s.concat(toString());
69
    }
70

  
71
    public String toString() {
72
        return "[" + fd.getName() + "]";
73
    }
74

  
75
    public boolean isEnable() {
76
        return true;
77
    }
78

  
79
    public String getTooltip() {
80
        return PluginServices.getText(this, "field") + ":  " + fd.getName() + "\n" + getDescription();
81
    }
82

  
83
    public String getDescription() {
84
        return PluginServices.getText(this, "type") + ": "
85
                + typeField;
86
    }
87

  
88
    public String getName() {
89
        return this.fd.getName();
90
    }
77 91
}
org.gvsig.expressionfield/trunk/org.gvsig.expressionfield/src/main/java/org/gvsig/expressionfield/project/documents/table/gui/EvalExpressionDialog.java
1
/*******************************************************************************
1
/**
2
 * *****************************************************************************
2 3
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
4
 * gvSIG. Desktop Geographic Information System.
5
 *
6
 * Copyright (C) 2007-2013 gvSIG Association.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 3
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
 * MA 02110-1301, USA.
22
 *
23
 * For any additional information, do not hesitate to contact us
24
 * at info AT gvsig.com, or visit our website www.gvsig.com.
25
 *
26
 ******************************************************************************
27
 */
26 28
package org.gvsig.expressionfield.project.documents.table.gui;
27 29

  
28 30
import java.awt.BorderLayout;
......
86 88

  
87 89
import bsh.EvalError;
88 90

  
91
public class EvalExpressionDialog extends JPanel implements IWindow {
89 92

  
90

  
91
/**
92
 * DOCUMENT ME!
93
 *
94
 * @author Vicente Caballero Navarro
95
 */
96
public class EvalExpressionDialog extends JPanel implements IWindow {
97
	
98
	private static Logger logger = LoggerFactory.getLogger(EvalExpressionDialog.class);
99
	private static Preferences prefs = Preferences.userRoot().node( "fieldExpressionOptions" );
100
	private JPanel pNorth = null;
93
    private static Logger logger = LoggerFactory.getLogger(EvalExpressionDialog.class);
94
    private static Preferences prefs = Preferences.userRoot().node("fieldExpressionOptions");
95
    
96
    private JPanel pNorth = null;
101 97
    private JPanel pCentral = null;
102 98
    private JScrollPane jScrollPane = null;
103 99
    private JTextArea txtExp = null;
......
117 113
    private BSFManager interpreter = null; // Construct an interpreter
118 114
    private Feature feature;
119 115
    private FeatureStore featureStore = null;
120
    private EvalExpression evalExpression=null;
116
    private EvalExpression evalExpression = null;
121 117
    /*
122 118
     * Keeps index of row in feature set currently used.
123 119
     */
124 120
    private FeatureIndex fIndex = new FeatureIndex();
125 121

  
126
	private JPanel pMessage;
127
	private FeatureContainer featureContainer;
128
    private static ArrayList<IOperator> operators=new ArrayList<IOperator>();
122
    private JPanel pMessage;
123
    private FeatureContainer featureContainer;
124
    private static ArrayList<IOperator> operators = new ArrayList<IOperator>();
125

  
129 126
    public EvalExpressionDialog(FeatureTableDocumentPanel table, BSFManager interpreter, ArrayList<IOperator> operators) {
130 127
        super();
131
        this.operators=operators;
132
        this.interpreter=interpreter;
128
        this.operators = operators;
129
        this.interpreter = interpreter;
133 130
        this.table = table;
134 131
        initialize();
135 132

  
136 133
    }
134

  
137 135
    /**
138 136
     * This method initializes this
139 137
     */
140 138
    private void initialize() {
141
    	try {
142
	        evalExpressions();
139
        try {
140
            evalExpressions();
143 141
        } catch (BSFException e) {
144
        	NotificationManager.addError(e);
145
		}
146
	    evalExpression=new EvalExpression();
147
	    evalExpression.setTable(table);
148
	    /*
149
	     *  Keeps index of row in feature set currently used
150
	     */
151
	    try {
152
			interpreter.declareBean("featureIndex", fIndex, FeatureIndex.class);
153
		} catch (BSFException e) {
154
			logger.error("While declaring featureIndex (Long).", e);
155
		}
156
	    
157
	    lv = (FLyrVect) table.getModel().getAssociatedLayer();
142
            NotificationManager.addError(e);
143
        }
144
        evalExpression = new EvalExpression();
145
        evalExpression.setTable(table);
146
        /*
147
         *  Keeps index of row in feature set currently used
148
         */
149
        try {
150
            interpreter.declareBean("featureIndex", fIndex, FeatureIndex.class);
151
        } catch (BSFException e) {
152
            logger.error("While declaring featureIndex (Long).", e);
153
        }
154

  
155
        lv = (FLyrVect) table.getModel().getAssociatedLayer();
158 156
        ButtonGroup bg = new ButtonGroup();
159 157
        bg.add(getRbNumber());
160 158
        bg.add(getRbString());
......
165 163
        constr.gridwidth = GridBagConstraints.REMAINDER;
166 164
        constr.gridheight = 1;
167 165
        constr.fill = GridBagConstraints.BOTH;
168
        constr.ipadx=5;
169
        constr.ipady=5;
170
        constr.weightx=1;
171
        constr.weighty=0.3;
166
        constr.ipadx = 5;
167
        constr.ipady = 5;
168
        constr.weightx = 1;
169
        constr.weighty = 0.3;
172 170
        this.add(getPMessage(), constr);
173 171
        constr.gridheight = 5;
174
        constr.weighty=1;
172
        constr.weighty = 1;
175 173
        this.add(getTabPrincipal(), constr);
176 174
        GridBagConstraints constr2 = new GridBagConstraints();
177 175
        constr2.gridwidth = GridBagConstraints.REMAINDER;
178 176
        constr2.gridheight = 1;
179 177
        constr2.fill = GridBagConstraints.HORIZONTAL;
180 178
        constr2.anchor = GridBagConstraints.LAST_LINE_END;
181
        constr2.weightx=1;
182
        constr2.weighty=0;
179
        constr2.weightx = 1;
180
        constr2.weighty = 0;
183 181

  
184 182
        this.add(getAcceptCancel(), constr2);
185 183

  
186 184
    }
185

  
187 186
    /**
188 187
     * This method initializes pCentral
189 188
     *
190 189
     * @return javax.swing.JPanel
191 190
     */
192 191
    private JPanel getPNorth() {
193
        if (pNorth == null) {
192
        if ( pNorth == null ) {
194 193
            pNorth = new JPanel();
195 194
            pNorth.setLayout(new GridBagLayout());
196 195
            GridBagConstraints contr = new GridBagConstraints();
197 196
            contr.ipadx = 5;
198 197
            contr.ipady = 5;
199 198
            contr.fill = GridBagConstraints.BOTH;
200
            contr.weightx =1;
201
            contr.weighty =1;
199
            contr.weightx = 1;
200
            contr.weighty = 1;
202 201
            pNorth.add(getPNorthWest(), contr);
203 202

  
204 203
            contr.fill = GridBagConstraints.VERTICAL;
205
            contr.weightx =0;
206
            contr.weighty =1;
204
            contr.weightx = 0;
205
            contr.weighty = 1;
207 206

  
208 207
            pNorth.add(getPNorthCenter(), contr);
209 208

  
210 209
            contr.fill = GridBagConstraints.BOTH;
211
            contr.weightx =0.5;
212
            contr.weighty =1;
210
            contr.weightx = 0.5;
211
            contr.weighty = 1;
213 212

  
214 213
            pNorth.add(getPNorthEast(), contr);
215 214
        }
......
223 222
     * @return javax.swing.JPanel
224 223
     */
225 224
    private JPanel getPCentral() {
226
        if (pCentral == null) {
227
        	StringBuilder tit = new StringBuilder();
228
        	tit.append(PluginServices.getText(this,"expression"));
229
        	tit.append(" ");
230
        	tit.append(PluginServices.getText(this, "column"));
231
        	tit.append(" : ");
232
        	tit.append(evalExpression.getFieldDescriptorSelected().getName());
225
        if ( pCentral == null ) {
226
            StringBuilder tit = new StringBuilder();
227
            tit.append(PluginServices.getText(this, "expression"));
228
            tit.append(" ");
229
            tit.append(PluginServices.getText(this, "column"));
230
            tit.append(" : ");
231
            tit.append(evalExpression.getFieldDescriptorSelected().getName());
233 232
            pCentral = new JPanel();
234 233
            pCentral.setLayout(new GridBagLayout());
235 234
            pCentral.setBorder(javax.swing.BorderFactory.createTitledBorder(
......
242 241
            contr.fill = GridBagConstraints.BOTH;
243 242
            contr.ipadx = 5;
244 243
            contr.ipady = 5;
245
            contr.weightx=1;
246
            contr.weighty=1;
244
            contr.weightx = 1;
245
            contr.weighty = 1;
247 246
            pCentral.add(getJScrollPane(), contr);
248 247
            GridBagConstraints contr1 = new GridBagConstraints();
249 248
            contr1.gridwidth = 1;
......
264 263
     * @return javax.swing.JPanel
265 264
     */
266 265
    private AcceptCancelPanel getAcceptCancel() {
267
		if (this.acceptCancel == null) {
268
			this.acceptCancel = new AcceptCancelPanel(
269
					new java.awt.event.ActionListener() {
270
						public void actionPerformed(java.awt.event.ActionEvent e) {
271
							boolean isAccepted=true;
272
							Preferences prefs = Preferences.userRoot().node(
273
									"fieldExpressionOptions");
274
							int limit;
275
							limit = prefs.getInt("limit_rows_in_memory", -1);
276
							if (limit != -1) {
277
								int option = JOptionPane
278
										.showConfirmDialog(
279
												(Component) PluginServices
280
														.getMainFrame(),
281
												PluginServices
282
														.getText(
283
																this,
284
																"it_has_established_a_limit_of_rows_will_lose_the_possibility_to_undo_wants_to_continue"));
285
								if (option != JOptionPane.OK_OPTION) {
286
									return;
287
								}
288
							}
289
							try {
290
								long t1 = System.currentTimeMillis();
291
								isAccepted=evalExpression();
292
								long t2 = System.currentTimeMillis();
293
								System.out
294
										.println("Tiempo evaluar expresiones = "
295
												+ (t2 - t1));
296
							} catch (BSFException e1) {
297
								NotificationManager.addError(e1);
298
							}
299
							if (isAccepted)
300
								PluginServices.getMDIManager().closeWindow(
301
									EvalExpressionDialog.this);
302
						}
303
					}, new java.awt.event.ActionListener() {
304
						public void actionPerformed(java.awt.event.ActionEvent e) {
305
							PluginServices.getMDIManager().closeWindow(
306
									EvalExpressionDialog.this);
307
						}
308
					});
309
			acceptCancel.setOkButtonEnabled(false);
310
		}
266
        if ( this.acceptCancel == null ) {
267
            this.acceptCancel = new AcceptCancelPanel(
268
                    new java.awt.event.ActionListener() {
269
                        public void actionPerformed(java.awt.event.ActionEvent e) {
270
                            boolean isAccepted = true;
271
                            Preferences prefs = Preferences.userRoot().node(
272
                                    "fieldExpressionOptions");
273
                            int limit;
274
                            limit = prefs.getInt("limit_rows_in_memory", -1);
275
                            if ( limit != -1 ) {
276
                                int option = JOptionPane
277
                                .showConfirmDialog(
278
                                        (Component) PluginServices
279
                                        .getMainFrame(),
280
                                        PluginServices
281
                                        .getText(
282
                                                this,
283
                                                "it_has_established_a_limit_of_rows_will_lose_the_possibility_to_undo_wants_to_continue"));
284
                                if ( option != JOptionPane.OK_OPTION ) {
285
                                    return;
286
                                }
287
                            }
288
                            try {
289
                                long t1 = System.currentTimeMillis();
290
                                isAccepted = evalExpression();
291
                                long t2 = System.currentTimeMillis();
292
                                System.out
293
                                .println("Tiempo evaluar expresiones = "
294
                                        + (t2 - t1));
295
                            } catch (BSFException e1) {
296
                                NotificationManager.addError(e1);
297
                            }
298
                            if ( isAccepted ) {
299
                                PluginServices.getMDIManager().closeWindow(
300
                                        EvalExpressionDialog.this);
301
                            }
302
                        }
303
                    }, new java.awt.event.ActionListener() {
304
                        public void actionPerformed(java.awt.event.ActionEvent e) {
305
                            PluginServices.getMDIManager().closeWindow(
306
                                    EvalExpressionDialog.this);
307
                        }
308
                    });
309
            acceptCancel.setOkButtonEnabled(false);
310
        }
311 311

  
312
		return this.acceptCancel;
313
	}
312
        return this.acceptCancel;
313
    }
314

  
315
    private String replaceFields(String expression) {
316
        // String s = expression.replaceAll("\\[","field(\"").replaceAll("\\]","\")");
317
        String s = expression;
318

  
319
        JList list = getListFields();
320
        ListOperatorsModel model = (ListOperatorsModel) list.getModel();
321
        for ( int i = 0; i < model.getSize(); i++ ) {
322
            Field f = (Field) model.getElementAt(i);
323
            s = s.replaceAll(f.toString(), "field(\"" + f.getName() + "\")");
324
        }
325
        return s;
326
    }
327

  
314 328
    /**
315
	 * Evaluate the expression.
316
	 * @throws BSFException
317
	 */
318
    private boolean evalExpression() throws BSFException{
329
     * Evaluate the expression.
330
     *
331
     * @throws BSFException
332
     */
333
    private boolean evalExpression() throws BSFException {
319 334

  
320

  
321
        String expression=getTxtExp().getText();
335
        String expression = getTxtExp().getText();
322 336
        byte[] expressionBytes;
323 337
        String encoding = System.getProperty("file.encoding");
324
		try {
325
			expressionBytes = expression.getBytes(encoding);
326
			expression = new String(expressionBytes, "ISO-8859-1");
327
		} catch (UnsupportedEncodingException e) {
328
			// TODO Auto-generated catch block
329
			e.printStackTrace();
330
		}
331
        expression=expression.replaceAll("\\[","field(\"").replaceAll("\\]","\")");
338
        try {
339
            expressionBytes = expression.getBytes(encoding);
340
            expression = new String(expressionBytes, "ISO-8859-1");
341
        } catch (UnsupportedEncodingException e) {
342
            logger.warn("Can't apply enconding ("+encoding+").",e);
343
        }
344
        
345
//        expression = expression.replaceAll("\\[", "field(\"").replaceAll("\\]", "\")");
346
        expression = replaceFields(expression);
347
        
348
        interpreter.declareBean("evalExpression", evalExpression, EvalExpression.class);
349
        interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def expression():\n"
350
                + "  return " + expression + "");
332 351

  
333
    	interpreter.declareBean("evalExpression",evalExpression,EvalExpression.class);
334
    	interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def expression():\n" +
335
    			"  return " +expression+ "");
352
        try {
353
            interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def isCorrect():\n"
354
                    + "    evalExpression.isCorrectValue(expression())\n");
355
            interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "isCorrect()");
356
        } catch (BSFException ee) {
357
            String message = ee.getMessage();
358
            if ( message.length() > 200 ) {
359
                message = message.substring(0, 200);
360
            }
361
            int option = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(),
362
                    PluginServices.getText(this,
363
                            "error_expression") + "\n" + message + "\n" + PluginServices.getText(this, "continue?"));
364
            if ( option != JOptionPane.OK_OPTION ) {
365
                return false;
366
            }
367
        }
368
        try {
369
            boolean select = true;
370
            interpreter.declareBean("select", select, boolean.class);
371
            if ( featureStore.isEditing() ) {
372
                evalInEditing();
373
            } else {
374
                evalOutEditing();
375
            }
376
        } catch (DataException e) {
377
            logger.warn("Can't evaluate expresion ("+expression+").",e);
378
        }
336 379

  
337
    	try {
338
    		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def isCorrect():\n" +
339
    		"    evalExpression.isCorrectValue(expression())\n");
340
    		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"isCorrect()");
341
    	} catch (BSFException ee) {
342
    		String message=ee.getMessage();
343
    		if (message.length()>200){
344
    			message=message.substring(0,200);
345
    		}
346
    		int option=JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(),
347
    				PluginServices.getText(this,
348
    						"error_expression")+"\n"+message+"\n"+PluginServices.getText(this,"continue?"));
349
    		if (option!=JOptionPane.OK_OPTION) {
350
    			return false;
351
    		}
352
    	}
353
    	try {
354
    		boolean select = true;
355
    		interpreter.declareBean("select", select, boolean.class);
356
    		if (featureStore.isEditing()){
357
    			evalInEditing();
358
    		}else{
359
    			evalOutEditing();
360
    		}
361
    	} catch (DataException e) {
362
    		NotificationManager.addError(e);
363
		}
364

  
365 380
        return true;
366 381
    }
382

  
367 383
    private void evalInEditing() throws BSFException, DataException {
368
    	int limit=prefs.getInt("limit_rows_in_memory",-1);
369
    	ArrayList exceptions=new ArrayList();
370
    	interpreter.declareBean("exceptions",exceptions,ArrayList.class);
371
    	boolean emptySelection = ((FeatureSelection)featureStore.getSelection()).isEmpty();
384
        int limit = prefs.getInt("limit_rows_in_memory", -1);
385
        ArrayList exceptions = new ArrayList();
386
        interpreter.declareBean("exceptions", exceptions, ArrayList.class);
387
        boolean emptySelection = ((FeatureSelection) featureStore.getSelection()).isEmpty();
372 388

  
373
		FeatureSet set = null;
374
		DisposableIterator iterator = null;
375
			
376
		try {
377
			set = featureStore.getFeatureSet(table.getModel().getQuery());
378
			iterator = set.iterator();
379
	
380
			interpreter.declareBean("featureSet", set, FeatureSet.class);
381
			interpreter.declareBean("iterator",iterator,Iterator.class);
382
			interpreter.declareBean("limit",limit,int.class);
383
	
384
	
385
	    	if (limit==-1){
386
	    		featureStore.beginEditingGroup(PluginServices.getText(this, "expression"));
387
	    		if (!emptySelection){
388
	    			interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def p():\n" +
389
	    					"  \n" +
390
	    					"  featureIndex.set(0)\n" +
391
	    					"  while iterator.hasNext():\n" +
392
	    					"    feature=iterator.next()\n" +
393
	    					"    select=featureStore.getSelection().isSelected(feature)\n" +
394
	    					"    if select:\n" +
395
	    					"      featureContainer.setFeature(feature)\n" +
396
	    					"      obj=expression()\n" +
397
	    					"      evalExpression.setValue(featureSet,feature,obj)\n" +
398
	    					"      featureIndex.next()\n" +
399
	    					"  iterator.dispose()\n" +
400
	    					"  featureSet.dispose\n"
401
	    			);
402
	    		}else{
403
	    			interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def p():\n" +
404
	    					"  \n" +
405
	    					"  featureIndex.set(0)\n" +
406
	    					"  while iterator.hasNext():\n" +
407
	    					"    feature=iterator.next()\n" +
408
	    					"    featureContainer.setFeature(feature)\n" +
409
	    					"    obj=expression()\n" +
410
	    					"    evalExpression.setValue(featureSet,feature,obj)\n" +
411
	    					"    featureIndex.next()\n" +
412
	    					"  iterator.dispose()\n" +
413
	    					"  featureSet.dispose\n"
414
	    			);
415
	    		}
416
	    		try {
417
					interpreter.eval(ExpressionFieldExtension.JYTHON,null,-1,-1,"p()");
418
				} catch (BSFException ee) {
419
	
420
					JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(),
421
							PluginServices.getText(this, "evaluate_expression_with_errors")+" "+exceptions.size() +ee.getMessage());
422
				}
423
	    		featureStore.endEditingGroup();
424
	    	} else {
425
	    		long size=set.getSize();
426
	    		for(int i=0;i<size;i=i+limit){
389
        FeatureSet set = null;
390
        DisposableIterator iterator = null;
391

  
392
        try {
393
            set = featureStore.getFeatureSet(table.getModel().getQuery());
394
            iterator = set.fastIterator();
395

  
396
            interpreter.declareBean("featureSet", set, FeatureSet.class);
397
            interpreter.declareBean("iterator", iterator, Iterator.class);
398
            interpreter.declareBean("limit", limit, int.class);
399

  
400
            if ( limit == -1 ) {
401
                featureStore.beginEditingGroup(PluginServices.getText(this, "expression"));
402
                if ( !emptySelection ) {
403
                    interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n"
404
                            + "  \n"
405
                            + "  featureIndex.set(0)\n"
406
                            + "  while iterator.hasNext():\n"
407
                            + "    feature=iterator.next()\n"
408
                            + "    select=featureStore.getSelection().isSelected(feature)\n"
409
                            + "    if select:\n"
410
                            + "      featureContainer.setFeature(feature)\n"
411
                            + "      obj=expression()\n"
412
                            + "      evalExpression.setValue(featureSet,feature,obj)\n"
413
                            + "      featureIndex.next()\n"
414
                            + "  iterator.dispose()\n"
415
                            + "  featureSet.dispose\n"
416
                    );
417
                } else {
418
                    interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n"
419
                            + "  \n"
420
                            + "  featureIndex.set(0)\n"
421
                            + "  while iterator.hasNext():\n"
422
                            + "    feature=iterator.next()\n"
423
                            + "    featureContainer.setFeature(feature)\n"
424
                            + "    obj=expression()\n"
425
                            + "    evalExpression.setValue(featureSet,feature,obj)\n"
426
                            + "    featureIndex.next()\n"
427
                            + "  iterator.dispose()\n"
428
                            + "  featureSet.dispose\n"
429
                    );
430
                }
431
                try {
432
                    interpreter.eval(ExpressionFieldExtension.JYTHON, null, -1, -1, "p()");
433
                } catch (BSFException ee) {
434

  
435
                    JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(),
436
                            PluginServices.getText(this, "evaluate_expression_with_errors") + " " + exceptions.size() + ee.getMessage());
437
                }
438
                featureStore.endEditingGroup();
439
            } else {
440
                long size = set.getSize();
441
                for ( int i = 0; i < size; i = i + limit ) {
427 442
	//    			featureStore.finishEditing();
428
	//    			featureStore.edit();
429
	    			featureStore.beginEditingGroup(PluginServices.getText(this, "expression"));
430
	    			set= featureStore.getFeatureSet(table.getModel().getQuery());
431
	    			interpreter.declareBean("featureSet",set,FeatureSet.class);
432
	    	    	iterator=set.iterator(i);
433
	    	    	interpreter.declareBean("iterator",iterator,Iterator.class);
434
	    			if (!emptySelection){
435
	    				interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def p():\n" +
436
	    						"  \n" +
437
	    						"  pos=0\n" +
438
	    						"  featureIndex.set(0)\n" +
439
	    						"  while iterator.hasNext() and pos<limit:\n" +
440
	    						"    feature=iterator.next()\n" +
441
	    						"    select=featureStore.getSelection().isSelected(feature)\n" +
442
	    						"    if select:\n" +
443
	    						"      featureContainer.setFeature(feature)\n" +
444
	    						"      obj=expression()\n" +
445
	    						"      evalExpression.setValue(featureSet,feature,obj)\n" +
446
	    						"      featureIndex.next()\n" +
447
	    						"    pos=pos+1\n" +
448
	    						"  iterator.dispose()\n" +
449
	    						"  featureSet.dispose\n"
450
	    				);
451
	    			}else{
452
	    				interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def p():\n" +
453
	    						"  \n" +
454
	    						"  pos=0\n" +
455
	    						"  featureIndex.set(0)\n" +
456
	    						"  while iterator.hasNext() and pos<limit:\n" +
457
	    						"    feature=iterator.next()\n" +
458
	    						"    featureContainer.setFeature(feature)\n" +
459
	    						"    obj=expression()\n" +
460
	    						"    evalExpression.setValue(featureSet,feature,obj)\n" +
461
	    						"    pos=pos+1\n" +
462
	    						"    featureIndex.next()\n" +
463
	    						"  iterator.dispose()\n" +
464
	    						"  featureSet.dispose\n"
465
	    				);
466
	    			}
467
	    			try {
468
	    				interpreter.eval(ExpressionFieldExtension.JYTHON,null,-1,-1,"p()");
469
	    			} catch (BSFException ee) {
470
	
471
	    				JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(),
472
	    						PluginServices.getText(this, "evaluate_expression_with_errors")+" "+exceptions.size() +ee.getMessage());
473
	    			}
474
	
475
	    			featureStore.endEditingGroup();
476
	    			featureStore.finishEditing();
477
	    			featureStore.edit();
478
	    		}
479
	    	}
480
		} finally {
481
			DisposeUtils.dispose(set);
482
			DisposeUtils.dispose(iterator);
483
		}
443
                    //    			featureStore.edit();
444
                    featureStore.beginEditingGroup(PluginServices.getText(this, "expression"));
445
                    set = featureStore.getFeatureSet(table.getModel().getQuery());
446
                    interpreter.declareBean("featureSet", set, FeatureSet.class);
447
                    iterator = set.fastIterator(i);
448
                    interpreter.declareBean("iterator", iterator, Iterator.class);
449
                    if ( !emptySelection ) {
450
                        interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n"
451
                                + "  \n"
452
                                + "  pos=0\n"
453
                                + "  featureIndex.set(0)\n"
454
                                + "  while iterator.hasNext() and pos<limit:\n"
455
                                + "    feature=iterator.next()\n"
456
                                + "    select=featureStore.getSelection().isSelected(feature)\n"
457
                                + "    if select:\n"
458
                                + "      featureContainer.setFeature(feature)\n"
459
                                + "      obj=expression()\n"
460
                                + "      evalExpression.setValue(featureSet,feature,obj)\n"
461
                                + "      featureIndex.next()\n"
462
                                + "    pos=pos+1\n"
463
                                + "  iterator.dispose()\n"
464
                                + "  featureSet.dispose\n"
465
                        );
466
                    } else {
467
                        interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n"
468
                                + "  \n"
469
                                + "  pos=0\n"
470
                                + "  featureIndex.set(0)\n"
471
                                + "  while iterator.hasNext() and pos<limit:\n"
472
                                + "    feature=iterator.next()\n"
473
                                + "    featureContainer.setFeature(feature)\n"
474
                                + "    obj=expression()\n"
475
                                + "    evalExpression.setValue(featureSet,feature,obj)\n"
476
                                + "    pos=pos+1\n"
477
                                + "    featureIndex.next()\n"
478
                                + "  iterator.dispose()\n"
479
                                + "  featureSet.dispose\n"
480
                        );
481
                    }
482
                    try {
483
                        interpreter.eval(ExpressionFieldExtension.JYTHON, null, -1, -1, "p()");
484
                    } catch (BSFException ee) {
484 485

  
485
	}
486
                        JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(),
487
                                PluginServices.getText(this, "evaluate_expression_with_errors") + " " + exceptions.size() + ee.getMessage());
488
                    }
489

  
490
                    featureStore.endEditingGroup();
491
                    featureStore.finishEditing();
492
                    featureStore.edit();
493
                }
494
            }
495
        } finally {
496
            DisposeUtils.dispose(set);
497
            DisposeUtils.dispose(iterator);
498
        }
499

  
500
    }
501

  
486 502
    private void evalOutEditing() throws BSFException, DataException {
487 503

  
488
	}
504
    }
489 505

  
490 506
    /**
491
	 * This method initializes pMessage
492
	 *
493
	 * @return javax.swing.JPanel
494
	 */
495
	private JPanel getPMessage() {
496
		if (pMessage == null) {
507
     * This method initializes pMessage
508
     *
509
     * @return javax.swing.JPanel
510
     */
511
    private JPanel getPMessage() {
512
        if ( pMessage == null ) {
497 513

  
498
			pMessage = new JPanel();
499
			pMessage.setLayout(new GridLayout());
500
			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));
501
			pMessage.add(getJScrollPane3(), null);
502
		}
503
		return pMessage;
504
	}
514
            pMessage = new JPanel();
515
            pMessage.setLayout(new GridLayout());
516
            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));
517
            pMessage.add(getJScrollPane3(), null);
518
        }
519
        return pMessage;
520
    }
521

  
505 522
    private void evalExpressions() throws BSFException {
506 523
        featureStore = table.getModel().getStore();
507
        interpreter.declareBean("featureStore", featureStore,FeatureStore.class);
508
        featureContainer=new FeatureContainer();
509
        DisposableIterator iterator=null;
510
        FeatureSet set= null;
524
        interpreter.declareBean("featureStore", featureStore, FeatureStore.class);
525
        featureContainer = new FeatureContainer();
526
        DisposableIterator iterator = null;
527
        FeatureSet set = null;
511 528
        try {
512
			set=featureStore.getFeatureSet(table.getModel().getQuery());
513
			iterator = set.iterator();
529
            set = featureStore.getFeatureSet(table.getModel().getQuery());
530
            iterator = set.iterator();
514 531

  
515
        if (iterator.hasNext())
516
        	feature=(Feature)iterator.next();
517
        featureContainer.setFeature(feature);
518
        interpreter.declareBean("featureContainer", featureContainer,Feature.class);
519
		} catch (DataException e) {
520
			e.printStackTrace();
521
		} finally {
522
			if (iterator != null) {
523
				iterator.dispose();
524
			}
525
			if (set != null) {
526
				set.dispose();
527
			}
528
		}
532
            if ( iterator.hasNext() ) {
533
                feature = (Feature) iterator.next();
534
            }
535
            featureContainer.setFeature(feature);
536
            interpreter.declareBean("featureContainer", featureContainer, Feature.class);
537
        } catch (DataException e) {
538
            e.printStackTrace();
539
        } finally {
540
            if ( iterator != null ) {
541
                iterator.dispose();
542
            }
543
            if ( set != null ) {
544
                set.dispose();
545
            }
546
        }
529 547
    }
530 548
    /**
531 549
     * Evaluate the fields.
......
534 552
     *
535 553
     * @throws EvalError
536 554
     */
537
    int lastType=-1;
538
	private JButton bClear = null;
539
	private JTabbedPane tabPrincipal = null;
540
	private JPanel pPrincipal = null;
541
	private JPanel pAdvanced = null;
542
	private JPanel pAdvancedNorth = null;
543
	private JTextField jTextField = null;
544
	private JButton bFile = null;
545
	private JPanel pAdvancedCenter = null;
546
	private JLabel lblLeng = null;
547
	private JButton bEval = null;
548
	private JScrollPane jScrollPane3 = null;
549
	private JTextArea txtMessage2 = null;
550
	private void refreshOperators(int type) {
551
        if (lastType!=-1 && lastType==type)
552
        	return;
553
        lastType=type;
554
    	ListOperatorsModel lom=(ListOperatorsModel)getListCommand().getModel();
555
    int lastType = -1;
556
    private JButton bClear = null;
557
    private JTabbedPane tabPrincipal = null;
558
    private JPanel pPrincipal = null;
559
    private JPanel pAdvanced = null;
560
    private JPanel pAdvancedNorth = null;
561
    private JTextField jTextField = null;
562
    private JButton bFile = null;
563
    private JPanel pAdvancedCenter = null;
564
    private JLabel lblLeng = null;
565
    private JButton bEval = null;
566
    private JScrollPane jScrollPane3 = null;
567
    private JTextArea txtMessage2 = null;
568

  
569
    private void refreshOperators(int type) {
570
        if ( lastType != -1 && lastType == type ) {
571
            return;
572
        }
573
        lastType = type;
574
        ListOperatorsModel lom = (ListOperatorsModel) getListCommand().getModel();
555 575
        lom.clear();
556
           for (int i=0;i<operators.size();i++) {
557
            IOperator operator = (IOperator)operators.get(i);
576
        for ( int i = 0; i < operators.size(); i++ ) {
577
            IOperator operator = (IOperator) operators.get(i);
558 578
            operator.setType(type);
559 579
            //Comprobar si tiene una capa asociada y pasarsela al GraphicOperator.
560
            if ((lv != null) && operator instanceof GraphicOperator) {
580
            if ( (lv != null) && operator instanceof GraphicOperator ) {
561 581
                GraphicOperator igo = (GraphicOperator) operator;
562 582
                igo.setLayer(lv);
563 583
            }
564
            if (operator.isEnable()) {
565
                   lom.addOperator(operator);
566
                   //System.out.println("Operator = "+operator.toString());
584
            if ( operator.isEnable() ) {
585
                lom.addOperator(operator);
586
                //System.out.println("Operator = "+operator.toString());
567 587
            }
568 588
        }
569 589
        getListCommand().repaint();
......
572 592
        this.doLayout();
573 593

  
574 594
    }
595

  
575 596
    /**
576 597
     * This method initializes jScrollPane
577 598
     *
578 599
     * @return javax.swing.JScrollPane
579 600
     */
580 601
    private JScrollPane getJScrollPane() {
581
        if (jScrollPane == null) {
602
        if ( jScrollPane == null ) {
582 603
            jScrollPane = new JScrollPane();
583 604
            jScrollPane.setPreferredSize(new java.awt.Dimension(480, 80));
584 605
            jScrollPane.setViewportView(getTxtExp());
......
593 614
     * @return javax.swing.JTextArea
594 615
     */
595 616
    private JTextArea getTxtExp() {
596
        if (txtExp == null) {
617
        if ( txtExp == null ) {
597 618
            txtExp = new JTextArea();
598
            txtExp.addCaretListener(new CaretListener(){
599
				public void caretUpdate(CaretEvent e) {
600
					if (txtExp.getText().length()>0)
601
						getAcceptCancel().setOkButtonEnabled(true);
602
					else
603
						getAcceptCancel().setOkButtonEnabled(false);
604
				}
619
            txtExp.addCaretListener(new CaretListener() {
620
                public void caretUpdate(CaretEvent e) {
621
                    if ( txtExp.getText().length() > 0 ) {
622
                        getAcceptCancel().setOkButtonEnabled(true);
623
                    } else {
624
                        getAcceptCancel().setOkButtonEnabled(false);
625
                    }
626
                }
605 627

  
606

  
607

  
608

  
609
			});
628
            });
610 629
        }
611 630

  
612 631
        return txtExp;
613 632
    }
614 633

  
615 634
    public WindowInfo getWindowInfo() {
616
         WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG+WindowInfo.RESIZABLE);
635
        WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG + WindowInfo.RESIZABLE);
617 636
        wi.setTitle(PluginServices.getText(this, "calculate_expression"));
618 637

  
619

  
620 638
        return wi;
621 639
    }
622 640

  
......
626 644
     * @return javax.swing.JPanel
627 645
     */
628 646
    private JPanel getPNorthEast() {
629
        if (pNorthEast == null) {
647
        if ( pNorthEast == null ) {
630 648
            pNorthEast = new JPanel(new GridLayout());
631 649
            pNorthEast.setBorder(javax.swing.BorderFactory.createTitledBorder(
632
                    null, PluginServices.getText(this,"commands"),
650
                    null, PluginServices.getText(this, "commands"),
633 651
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
634 652
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
635 653
            pNorthEast.add(getJScrollPane2(), null);
......
644 662
     * @return javax.swing.JPanel
645 663
     */
646 664
    private JPanel getPNorthCenter() {
647
        if (pNorthCenter == null) {
665
        if ( pNorthCenter == null ) {
648 666
            pNorthCenter = new JPanel();
649 667
            pNorthCenter.setLayout(new BoxLayout(getPNorthCenter(),
650 668
                    BoxLayout.Y_AXIS));
651 669
            pNorthCenter.setBorder(javax.swing.BorderFactory.createTitledBorder(
652
                    null, PluginServices.getText(this,"type"),
670
                    null, PluginServices.getText(this, "type"),
653 671
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
654 672
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
655 673
            pNorthCenter.add(getRbNumber(), null);
......
666 684
     * @return javax.swing.JPanel
667 685
     */
668 686
    private JPanel getPNorthWest() {
669
        if (pNorthWest == null) {
687
        if ( pNorthWest == null ) {
670 688
            pNorthWest = new JPanel(new GridLayout());
671 689
            pNorthWest.setBorder(javax.swing.BorderFactory.createTitledBorder(
672
                    null, PluginServices.getText(this,"field"),
690
                    null, PluginServices.getText(this, "field"),
673 691
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
674 692
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
675 693
            pNorthWest.add(getJScrollPane1(), null);
......
684 702
     * @return javax.swing.JScrollPane
685 703
     */
686 704
    private JScrollPane getJScrollPane1() {
687
        if (jScrollPane1 == null) {
705
        if ( jScrollPane1 == null ) {
688 706
            jScrollPane1 = new JScrollPane();
689 707
            jScrollPane1.setPreferredSize(new java.awt.Dimension(175, 100));
690 708
            jScrollPane1.setViewportView(getListFields());
......
699 717
     * @return javax.swing.JList
700 718
     */
701 719
    private JList getListFields() {
702
        if (listFields == null) {
720
        if ( listFields == null ) {
703 721
            listFields = new JList();
704 722
            listFields.setModel(new ListOperatorsModel());
705 723

  
706 724
            ListOperatorsModel lm = (ListOperatorsModel) listFields.getModel();
707
            FeatureType fds=evalExpression.getFieldDescriptors();
708
            for (int i = 0; i < fds.size(); i++) {
709
                Field field=new Field();
725
            FeatureType fds = evalExpression.getFieldDescriptors();
726
            for ( int i = 0; i < fds.size(); i++ ) {
727
                Field field = new Field();
710 728
                field.setFieldDescription(fds.getAttributeDescriptor(i));
711 729
                try {
712
                	field.eval(interpreter);
730
                    field.eval(interpreter);
713 731
                } catch (BSFException e) {
714
					e.printStackTrace();
715
				}
732
                    e.printStackTrace();
733
                }
716 734
                lm.addOperator(field);
717 735
            }
718 736

  
719 737
            listFields.addMouseListener(new MouseListener() {
720
                    public void mouseClicked(MouseEvent e) {
721
                    	IOperator operator=((IOperator) listFields.getSelectedValue());
722
                    	if (operator!=null){
723
                    		getTxtMessage2().setText(operator.getTooltip());
724
                    		if (e.getClickCount() == 2) {
725
                    			getTxtExp().setText(operator.addText(
726
                    					getTxtExp().getText()));
727
                    		}
728
                    	}
738
                public void mouseClicked(MouseEvent e) {
739
                    IOperator operator = ((IOperator) listFields.getSelectedValue());
740
                    if ( operator != null ) {
741
                        getTxtMessage2().setText(operator.getTooltip());
742
                        if ( e.getClickCount() == 2 ) {
743
                            getTxtExp().setText(operator.addText(
744
                                    getTxtExp().getText()));
745
                        }
729 746
                    }
747
                }
730 748

  
731
                    public void mouseEntered(MouseEvent e) {
732
                    }
749
                public void mouseEntered(MouseEvent e) {
750
                }
733 751

  
734
                    public void mouseExited(MouseEvent e) {
735
                    }
752
                public void mouseExited(MouseEvent e) {
753
                }
736 754

  
737
                    public void mousePressed(MouseEvent e) {
738
                    }
755
                public void mousePressed(MouseEvent e) {
756
                }
739 757

  
740
                    public void mouseReleased(MouseEvent e) {
741
                    }
742
                });
758
                public void mouseReleased(MouseEvent e) {
759
                }
760
            });
743 761
        }
744 762

  
745 763
        return listFields;
......
751 769
     * @return javax.swing.JRadioButton
752 770
     */
753 771
    private JRadioButton getRbNumber() {
754
        if (rbNumber == null) {
772
        if ( rbNumber == null ) {
755 773
            rbNumber = new JRadioButton();
756
            rbNumber.setText(PluginServices.getText(this,"numeric"));
774
            rbNumber.setText(PluginServices.getText(this, "numeric"));
757 775
            rbNumber.setSelected(true);
758 776
            rbNumber.addChangeListener(new javax.swing.event.ChangeListener() {
759 777
                public void stateChanged(javax.swing.event.ChangeEvent e) {
760
                     if (rbNumber.isSelected())
761
                         refreshCommands();
778
                    if ( rbNumber.isSelected() ) {
779
                        refreshCommands();
780
                    }
762 781
                }
763 782
            });
764 783
        }
......
772 791
     * @return javax.swing.JRadioButton
773 792
     */
774 793
    private JRadioButton getRbString() {
775
        if (rbString == null) {
794
        if ( rbString == null ) {
776 795
            rbString = new JRadioButton();
777
            rbString.setText(PluginServices.getText(this,"string"));
796
            rbString.setText(PluginServices.getText(this, "string"));
778 797
            rbString.addChangeListener(new javax.swing.event.ChangeListener() {
779 798
                public void stateChanged(javax.swing.event.ChangeEvent e) {
780
                     if (rbString.isSelected())
781
                         refreshCommands();
799
                    if ( rbString.isSelected() ) {
800
                        refreshCommands();
801
                    }
782 802
                }
783 803
            });
784 804
        }
......
792 812
     * @return javax.swing.JRadioButton
793 813
     */
794 814
    private JRadioButton getRbDate() {
795
        if (rbDate == null) {
815
        if ( rbDate == null ) {
796 816
            rbDate = new JRadioButton();
797
            rbDate.setText(PluginServices.getText(this,"date"));
817
            rbDate.setText(PluginServices.getText(this, "date"));
798 818
            rbDate.addChangeListener(new javax.swing.event.ChangeListener() {
799 819
                public void stateChanged(javax.swing.event.ChangeEvent e) {
800
                    if (rbDate.isSelected())
801
                         refreshCommands();
820
                    if ( rbDate.isSelected() ) {
821
                        refreshCommands();
822
                    }
802 823
                }
803 824
            });
804 825
        }
......
812 833
     * @return javax.swing.JScrollPane
813 834
     */
814 835
    private JScrollPane getJScrollPane2() {
815
        if (jScrollPane2 == null) {
836
        if ( jScrollPane2 == null ) {
816 837
            jScrollPane2 = new JScrollPane();
817 838
            jScrollPane2.setPreferredSize(new java.awt.Dimension(175, 100));
818 839
            jScrollPane2.setViewportView(getListCommand());
......
825 846
     * Refresh the commands.
826 847
     */
827 848
    private void refreshCommands() {
828
        int type=IOperator.NUMBER;
829
        if (getRbNumber().isSelected()) {
830
            type=IOperator.NUMBER;
831
        } else if (getRbString().isSelected()) {
832
            type=IOperator.STRING;
833
        } else if (getRbDate().isSelected()) {
834
            type=IOperator.DATE;
849
        int type = IOperator.NUMBER;
850
        if ( getRbNumber().isSelected() ) {
851
            type = IOperator.NUMBER;
852
        } else if ( getRbString().isSelected() ) {
853
            type = IOperator.STRING;
854
        } else if ( getRbDate().isSelected() ) {
855
            type = IOperator.DATE;
835 856
        }
836 857
        refreshOperators(type);
837 858

  
......
843 864
     * @return javax.swing.JList
844 865
     */
845 866
    private JList getListCommand() {
846
        if (listCommand == null) {
867
        if ( listCommand == null ) {
847 868
            listCommand = new JList();
848 869
            listCommand.setModel(new ListOperatorsModel());
849 870
            listCommand.addMouseListener(new MouseListener() {
850
                    public void mouseClicked(MouseEvent e) {
851
                    	IOperator operator=((IOperator) listCommand.getSelectedValue());
852
                    	if (operator!=null){
853
                    		getTxtMessage2().setText(operator.getTooltip());
854
                    		if (e.getClickCount() == 2) {
855
                    			if (listCommand.getSelectedValue()==null)
856
                    				return;
857
                    			getTxtExp().setText(operator.addText(
858
                    					getTxtExp().getText()));
859
                    		}
860
                    	}
871
                public void mouseClicked(MouseEvent e) {
872
                    IOperator operator = ((IOperator) listCommand.getSelectedValue());
873
                    if ( operator != null ) {
874
                        getTxtMessage2().setText(operator.getTooltip());
875
                        if ( e.getClickCount() == 2 ) {
876
                            if ( listCommand.getSelectedValue() == null ) {
877
                                return;
878
                            }
879
                            getTxtExp().setText(operator.addText(
880
                                    getTxtExp().getText()));
881
                        }
861 882
                    }
883
                }
862 884

  
863
                    public void mouseEntered(MouseEvent e) {
864
                    }
885
                public void mouseEntered(MouseEvent e) {
886
                }
865 887

  
866
                    public void mouseExited(MouseEvent e) {
867
                    }
888
                public void mouseExited(MouseEvent e) {
889
                }
868 890

  
869
                    public void mousePressed(MouseEvent e) {
870
                    }
891
                public void mousePressed(MouseEvent e) {
892
                }
871 893

  
872
                    public void mouseReleased(MouseEvent e) {
873
                    }
874
                });
894
                public void mouseReleased(MouseEvent e) {
895
                }
896
            });
875 897
            refreshOperators(IOperator.NUMBER);
876 898
        }
877 899

  
......
879 901
    }
880 902

  
881 903
    /**
882
	 * This method initializes bClear
883
	 *
884
	 * @return javax.swing.JButton
885
	 */
886
	private JButton getBClear() {
887
		if (bClear == null) {
888
			bClear = new JButton();
889
			bClear.setText(PluginServices.getText(this,"clear_expression"));
890
			bClear.addActionListener(new java.awt.event.ActionListener() {
891
				public void actionPerformed(java.awt.event.ActionEvent e) {
892
					getTxtExp().setText("");
893
				}
894
			});
895
		}
896
		return bClear;
897
	}
898
	/**
899
	 * This method initializes tabPrincipal
900
	 *
901
	 * @return javax.swing.JTabbedPane
902
	 */
903
	private JTabbedPane getTabPrincipal() {
904
		if (tabPrincipal == null) {
905
			tabPrincipal = new JTabbedPane();
906
			tabPrincipal.addTab(PluginServices.getText(this,"general"), null, getPPrincipal(), null);
907
			tabPrincipal.addTab(PluginServices.getText(this,"advanced"), null, getPAdvanced(), null);
908
		}
909
		return tabPrincipal;
910
	}
911
	/**
912
	 * This method initializes pPrincipal
913
	 *
914
	 * @return javax.swing.JPanel
915
	 */
916
	private JPanel getPPrincipal() {
917
		if (pPrincipal == null) {
918
			pPrincipal = new JPanel();
919
			pPrincipal.setLayout(new BorderLayout());
904
     * This method initializes bClear
905
     *
906
     * @return javax.swing.JButton
907
     */
908
    private JButton getBClear() {
909
        if ( bClear == null ) {
910
            bClear = new JButton();
911
            bClear.setText(PluginServices.getText(this, "clear_expression"));
912
            bClear.addActionListener(new java.awt.event.ActionListener() {
913
                public void actionPerformed(java.awt.event.ActionEvent e) {
914
                    getTxtExp().setText("");
915
                }
916
            });
917
        }
918
        return bClear;
919
    }
920

  
921
    /**
922
     * This method initializes tabPrincipal
923
     *
924
     * @return javax.swing.JTabbedPane
925
     */
926
    private JTabbedPane getTabPrincipal() {
927
        if ( tabPrincipal == null ) {
928
            tabPrincipal = new JTabbedPane();
929
            tabPrincipal.addTab(PluginServices.getText(this, "general"), null, getPPrincipal(), null);
930
            tabPrincipal.addTab(PluginServices.getText(this, "advanced"), null, getPAdvanced(), null);
931
        }
932
        return tabPrincipal;
933
    }
934

  
935
    /**
936
     * This method initializes pPrincipal
937
     *
938
     * @return javax.swing.JPanel
939
     */
940
    private JPanel getPPrincipal() {
941
        if ( pPrincipal == null ) {
942
            pPrincipal = new JPanel();
943
            pPrincipal.setLayout(new BorderLayout());
920 944
//			pPrincipal.setPreferredSize(new java.awt.Dimension(540,252));
921
			pPrincipal.add(getPNorth(), java.awt.BorderLayout.NORTH);
922
			pPrincipal.add(getPCentral(), java.awt.BorderLayout.CENTER);
945
            pPrincipal.add(getPNorth(), java.awt.BorderLayout.NORTH);
946
            pPrincipal.add(getPCentral(), java.awt.BorderLayout.CENTER);
923 947

  
924
		}
925
		return pPrincipal;
926
	}
927
	/**
928
	 * This method initializes pAdvanced
929
	 *
930
	 * @return javax.swing.JPanel
931
	 */
932
	private JPanel getPAdvanced() {
933
		if (pAdvanced == null) {
934
			pAdvanced = new JPanel();
935
			pAdvanced.setLayout(new BorderLayout());
936
			pAdvanced.add(getPAdvancedNorth(), java.awt.BorderLayout.NORTH);
937
			pAdvanced.add(getPAdvancedCenter(), java.awt.BorderLayout.CENTER);
938
		}
939
		return pAdvanced;
940
	}
941
	/**
942
	 * This method initializes pAdvancedNorth
943
	 *
944
	 * @return javax.swing.JPanel
945
	 */
946
	private JPanel getPAdvancedNorth() {
947
		if (pAdvancedNorth == null) {
948
			pAdvancedNorth = new JPanel(new GridBagLayout());
948
        }
949
        return pPrincipal;
950
    }
951

  
952
    /**
953
     * This method initializes pAdvanced
954
     *
955
     * @return javax.swing.JPanel
956
     */
957
    private JPanel getPAdvanced() {
958
        if ( pAdvanced == null ) {
959
            pAdvanced = new JPanel();
960
            pAdvanced.setLayout(new BorderLayout());
961
            pAdvanced.add(getPAdvancedNorth(), java.awt.BorderLayout.NORTH);
962
            pAdvanced.add(getPAdvancedCenter(), java.awt.BorderLayout.CENTER);
963
        }
964
        return pAdvanced;
965
    }
966

  
967
    /**
968
     * This method initializes pAdvancedNorth
969
     *
970
     * @return javax.swing.JPanel
971
     */
972
    private JPanel getPAdvancedNorth() {
973
        if ( pAdvancedNorth == null ) {
974
            pAdvancedNorth = new JPanel(new GridBagLayout());
949 975
//			pAdvancedNorth.setPreferredSize(new java.awt.Dimension(873,100));
950
			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));
951
			GridBagConstraints contr = new GridBagConstraints();
952
			contr.anchor = GridBagConstraints.FIRST_LINE_START;
953
			contr.fill = GridBagConstraints.HORIZONTAL;
954
			contr.weighty =0;
955
			contr.weightx =1;
956
			contr.insets = new Insets(3,3,3,3);
957
			contr.ipadx=5;
958
			contr.ipady=5;
976
            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));
977
            GridBagConstraints contr = new GridBagConstraints();
978
            contr.anchor = GridBagConstraints.FIRST_LINE_START;
979
            contr.fill = GridBagConstraints.HORIZONTAL;
980
            contr.weighty = 0;
981
            contr.weightx = 1;
982
            contr.insets = new Insets(3, 3, 3, 3);
983
            contr.ipadx = 5;
984
            contr.ipady = 5;
959 985

  
960
			pAdvancedNorth.add(getJTextField(), contr);
961
			contr.fill = GridBagConstraints.NONE;
962
			contr.weighty =0;
963
			contr.weightx =0;
964
			pAdvancedNorth.add(getBFile(), null);
965
			pAdvancedNorth.add(getBEval(), null);
966
		}
967
		return pAdvancedNorth;
968
	}
969
	/**
970
	 * This method initializes jTextField
971
	 *
972
	 * @return javax.swing.JTextField
973
	 */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff