Revision 516

View differences:

org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.97/src/test/java/org/gvsig/expressionfield/AllTests.java
1
package org.gvsig.expressionfield;
2

  
3
import junit.framework.Test;
4
import junit.framework.TestSuite;
5

  
6
public class AllTests {
7

  
8
	public static Test suite() {
9
		TestSuite suite = new TestSuite(
10
				"Test for com.iver.cit.gvsig.expressionField");
11
		//$JUnit-BEGIN$
12

  
13
		//$JUnit-END$
14
		return suite;
15
	}
16

  
17
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.97/src/main/assembly/gvsig-plugin-package.xml
1
<!--
2

  
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
-->
26
<assembly>
27
  <id>gvsig-plugin-package</id>
28
  <formats>
29
    <format>zip</format>
30
  </formats>
31
  <baseDirectory>${project.artifactId}</baseDirectory>
32
  <includeBaseDirectory>true</includeBaseDirectory>
33
  <files>
34
    <file>
35
      <source>target/${project.artifactId}-${project.version}.jar</source>
36
      <outputDirectory>lib</outputDirectory>
37
    </file>
38
    <file>
39
      <source>target/package.info</source>
40
    </file>
41
  </files>
42

  
43
  <fileSets>
44
    <fileSet>
45
      <directory>src/main/resources-plugin</directory>
46
      <outputDirectory>.</outputDirectory>
47
    </fileSet>
48
  </fileSets>
49

  
50
  <dependencySets>
51
    <dependencySet>
52
      <useProjectArtifact>false</useProjectArtifact>
53
      <useTransitiveDependencies>false</useTransitiveDependencies>
54
      <outputDirectory>lib</outputDirectory>
55
      <includes>
56
        <include>bsf:bsf</include>
57
        <include>org.python:jython</include>
58
        <include>com.fifesoft:rsyntaxtextarea</include>
59
      </includes>
60
    </dependencySet>
61
  </dependencySets>
62

  
63
</assembly>
64

  
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.97/src/main/java/org/gvsig/expressionfield/gui/FieldExpressionPage.java
1
/*******************************************************************************
2
 *
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
 *******************************************************************************/
26
package org.gvsig.expressionfield.gui;
27

  
28
import java.awt.event.MouseEvent;
29
import java.awt.event.MouseListener;
30
import java.util.prefs.Preferences;
31

  
32
import javax.swing.ImageIcon;
33
import javax.swing.JCheckBox;
34
import javax.swing.JPanel;
35
import javax.swing.JTextArea;
36
import javax.swing.JTextField;
37

  
38
import org.gvsig.andami.IconThemeHelper;
39
import org.gvsig.andami.PluginServices;
40
import org.gvsig.andami.preferences.AbstractPreferencePage;
41
import org.gvsig.andami.preferences.StoreException;
42

  
43

  
44
/**
45
 * @author Vicente Caballero Navarro
46
 */
47
public class FieldExpressionPage extends AbstractPreferencePage {
48
	private static Preferences prefs = Preferences.userRoot().node( "fieldExpressionOptions" );
49
	private JTextArea jTextArea = null;
50
	private JTextField txtLimit;
51
	private JCheckBox ckLimit=null;
52
	private ImageIcon icon;
53

  
54
	public FieldExpressionPage() {
55
		super();
56
		
57
		icon = IconThemeHelper.getImageIcon("expression-field-preferences");
58
		
59
		addComponent(getJTextArea());
60

  
61
		addComponent(PluginServices.getText(this, "limit_rows_in_memory") + ":",
62
			txtLimit = new JTextField("", 15));
63
		addComponent(ckLimit = new JCheckBox(PluginServices.getText(this, "without_limit")));
64
		ckLimit.addMouseListener(new MouseListener() {
65
			public void mouseClicked(MouseEvent e) {
66
				if (ckLimit.isSelected()) {
67
					txtLimit.setText(PluginServices.getText(this, "without_limit"));
68
				}else {
69
					if (txtLimit.getText().equals(PluginServices.getText(this, "without_limit")))
70
					txtLimit.setText("500000");
71
				}
72

  
73
			}
74
			public void mouseEntered(MouseEvent e) {
75
			}
76
			public void mouseExited(MouseEvent e) {
77
			}
78
			public void mousePressed(MouseEvent e) {
79
			}
80
			public void mouseReleased(MouseEvent e) {
81
			}
82

  
83
		});
84
	}
85

  
86
	public void initializeValues() {
87
		int limit = prefs.getInt("limit_rows_in_memory",-1);
88
		if (limit==-1) {
89
			ckLimit.setSelected(true);
90
			txtLimit.setText(PluginServices.getText(this,"without_limit"));
91
		}else {
92
			ckLimit.setSelected(false);
93
			txtLimit.setText(String.valueOf(limit));
94
		}
95
	}
96

  
97
	public String getID() {
98
		return this.getClass().getName();
99
	}
100

  
101
	public String getTitle() {
102
		return PluginServices.getText(this, "limit_rows_in_memory");
103
	}
104

  
105
	public JPanel getPanel() {
106
		return this;
107
	}
108

  
109
	public void storeValues() throws StoreException {
110
		int limit;
111
		try{
112
			if (ckLimit.isSelected()) {
113
				limit=-1;
114
			}else {
115
//			if (txtLimit.getText().equals(PluginServices.getText(this,"without_limit"))) {
116
//				limit=-1;
117
//			}else {
118
				limit=Integer.parseInt(txtLimit.getText());
119
			}
120
		}catch (Exception e) {
121
			throw new StoreException(PluginServices.getText(this,"limit_rows_in_memory")+PluginServices.getText(this,"error"));
122
		}
123
		prefs.putInt("limit_rows_in_memory", limit);
124
	}
125

  
126
	public void initializeDefaults() {
127
		int limit=prefs.getInt("limit_rows_in_memory",-1);
128
		if (limit==-1) {
129
			ckLimit.setSelected(true);
130
			txtLimit.setText(PluginServices.getText(this,"without_limit"));
131
		}else {
132
			ckLimit.setSelected(false);
133
			txtLimit.setText(String.valueOf(limit));
134
		}
135
	}
136

  
137
	public ImageIcon getIcon() {
138
		return icon;
139
	}
140
	/**
141
	 * This method initializes jTextArea
142
	 *
143
	 * @return javax.swing.JTextArea
144
	 */
145
	private JTextArea getJTextArea() {
146
		if (jTextArea == null) {
147
			jTextArea = new JTextArea();
148
			jTextArea.setBounds(new java.awt.Rectangle(13,7,285,57));
149
			jTextArea.setForeground(java.awt.Color.black);
150
			jTextArea.setBackground(java.awt.SystemColor.control);
151
			jTextArea.setRows(3);
152
			jTextArea.setWrapStyleWord(true);
153
			jTextArea.setLineWrap(true);
154
			jTextArea.setEditable(false);
155
			jTextArea.setText(PluginServices.getText(this,"specifies_the_limit_rows_in_memory_when_the_program_eval_the_expression"));
156
		}
157
		return jTextArea;
158
	}
159

  
160
	public boolean isValueChanged() {
161
		return super.hasChanged();
162
	}
163

  
164
	public void setChangesApplied() {
165
		setChanged(false);
166
	}
167
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.97/src/main/java/org/gvsig/expressionfield/project/documents/table/FeatureIndex.java
1
/*******************************************************************************
2
 *
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
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table;
27

  
28
/**
29
 * Utility class to use in Jython bean
30
 * 
31
 * @author jldominguez
32
 * 
33
 */
34
public class FeatureIndex {
35

  
36
	private long index = -1;
37

  
38
	public void next() {
39
		index++;
40
	}
41

  
42
	public void previous() {
43
		index--;
44
	}
45

  
46
	public long get() {
47
		return index;
48
	}
49

  
50
	public void set(long i) {
51
		index = i;
52
	}
53
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.97/src/main/java/org/gvsig/expressionfield/project/documents/table/IOperator.java
1
/*******************************************************************************
2
 *
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
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30

  
31
/**
32
 * @author Vicente Caballero Navarro
33
 */
34
public interface IOperator {
35
	int NUMBER = 0;
36
	int STRING = 1;
37
	int DATE = 2;
38
	public String addText(String s);
39
	public String toString();
40
	public void eval(BSFManager interpreter) throws BSFException ;
41
	public boolean isEnable();
42
	public void setType(int fieldType);
43
	public String getTooltip();
44
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.97/src/main/java/org/gvsig/expressionfield/project/documents/table/gui/EvalExpression.java
1
/*******************************************************************************
2
 *
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
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.gui;
27

  
28
import java.util.Date;
29

  
30
import org.apache.bsf.BSFException;
31
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
32
import org.gvsig.fmap.dal.DataTypes;
33
import org.gvsig.fmap.dal.exception.DataException;
34
import org.gvsig.fmap.dal.feature.EditableFeature;
35
import org.gvsig.fmap.dal.feature.Feature;
36
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
37
import org.gvsig.fmap.dal.feature.FeatureSet;
38
import org.gvsig.fmap.dal.feature.FeatureType;
39

  
40
/**
41
 * @author Vicente Caballero Navarro
42
 */
43
public class EvalExpression {
44
	private FeatureType featureType;
45
	private FeatureAttributeDescriptor selectedDescriptor;
46
	public EvalExpression() {
47
	}
48
	public void setTable(FeatureTableDocumentPanel table) {
49
		try {
50
			selectedDescriptor = table.getTablePanel().getTable().getSelectedColumnsAttributeDescriptor()[0];
51
		    featureType = table.getModel().getStore().getDefaultFeatureType();
52
		} catch (DataException e) {
53
			e.printStackTrace();
54
		}
55
	}
56

  
57
	public void setValue(FeatureSet featureSet,Feature feature,Object obj) {
58
		Object objBoolean=obj;
59
		EditableFeature eFeature=feature.getEditable();
60
		int type=((FeatureAttributeDescriptor)featureSet.getDefaultFeatureType().get(selectedDescriptor.getName())).getType();
61
		if (type==DataTypes.BOOLEAN){
62
			Integer integer=((Integer)obj).intValue();
63
			if (integer==0){
64
				objBoolean=new Boolean(false);
65
			}else{
66
				objBoolean=new Boolean(true);
67
			}
68
		}
69
		eFeature.set(selectedDescriptor.getName(), objBoolean);
70
		try {
71
			featureSet.update(eFeature);
72
		} catch (DataException e) {
73
			e.printStackTrace();
74
		}
75
	}
76
	 public void isCorrectValue(Object obj) throws BSFException {
77
	        if (obj instanceof Number || obj instanceof Date || obj instanceof Boolean || obj instanceof String || obj == null ) {
78

  
79
	        }else{
80
	        	throw new BSFException("incorrect");
81
	        }
82
	 }
83

  
84
	public FeatureAttributeDescriptor getFieldDescriptorSelected() {
85
		return selectedDescriptor;
86
	}
87
	public FeatureType getFieldDescriptors() {
88
		return featureType;
89
	}
90
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.97/src/main/java/org/gvsig/expressionfield/project/documents/table/gui/EvalExpressionDialog.java
1
/**
2
 * *****************************************************************************
3
 *
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
 */
28
package org.gvsig.expressionfield.project.documents.table.gui;
29

  
30
import java.awt.BorderLayout;
31
import java.awt.Component;
32
import java.awt.GridBagConstraints;
33
import java.awt.GridBagLayout;
34
import java.awt.GridLayout;
35
import java.awt.Insets;
36
import java.awt.event.MouseEvent;
37
import java.awt.event.MouseListener;
38
import java.io.File;
39
import java.io.FileReader;
40
import java.io.IOException;
41
import java.io.UnsupportedEncodingException;
42
import java.util.ArrayList;
43
import java.util.Iterator;
44
import java.util.prefs.Preferences;
45

  
46
import javax.swing.BoxLayout;
47
import javax.swing.ButtonGroup;
48
import javax.swing.JFileChooser;
49
import javax.swing.JLabel;
50
import javax.swing.JList;
51
import javax.swing.JOptionPane;
52
import javax.swing.JPanel;
53
import javax.swing.JRadioButton;
54
import javax.swing.JScrollPane;
55
import javax.swing.JTabbedPane;
56
import javax.swing.JTextArea;
57
import javax.swing.JTextField;
58
import javax.swing.UIManager;
59
import javax.swing.event.CaretEvent;
60
import javax.swing.event.CaretListener;
61

  
62
import org.apache.bsf.BSFException;
63
import org.apache.bsf.BSFManager;
64
import org.gvsig.andami.PluginServices;
65
import org.gvsig.andami.messages.NotificationManager;
66
import org.gvsig.andami.ui.mdiManager.IWindow;
67
import org.gvsig.andami.ui.mdiManager.WindowInfo;
68
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
69
import org.gvsig.expressionfield.ExpressionFieldExtension;
70
import org.gvsig.expressionfield.project.documents.table.FeatureIndex;
71
import org.gvsig.expressionfield.project.documents.table.GraphicOperator;
72
import org.gvsig.expressionfield.project.documents.table.IOperator;
73
import org.gvsig.expressionfield.project.documents.table.operators.Field;
74
import org.gvsig.fmap.dal.exception.DataException;
75
import org.gvsig.fmap.dal.feature.Feature;
76
import org.gvsig.fmap.dal.feature.FeatureSelection;
77
import org.gvsig.fmap.dal.feature.FeatureSet;
78
import org.gvsig.fmap.dal.feature.FeatureStore;
79
import org.gvsig.fmap.dal.feature.FeatureType;
80
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
81
import org.gvsig.gui.beans.AcceptCancelPanel;
82
import org.gvsig.gui.beans.swing.JButton;
83
import org.gvsig.tools.dispose.DisposableIterator;
84
import org.gvsig.tools.dispose.DisposeUtils;
85
import org.gvsig.utils.GenericFileFilter;
86
import org.slf4j.Logger;
87
import org.slf4j.LoggerFactory;
88

  
89
import bsh.EvalError;
90
import org.apache.commons.lang3.StringUtils;
91
import org.gvsig.app.ApplicationLocator;
92
import org.gvsig.app.ApplicationManager;
93
import org.gvsig.tools.ToolsLocator;
94
import org.gvsig.tools.i18n.I18nManager;
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
    
101
    private JPanel pNorth = null;
102
    private JPanel pCentral = null;
103
    private JScrollPane jScrollPane = null;
104
    private JTextArea txtExp = null;
105
    private AcceptCancelPanel acceptCancel;
106
    private FeatureTableDocumentPanel table;
107
    private FLyrVect lv;
108
    private JPanel pNorthEast = null;
109
    private JPanel pNorthCenter = null;
110
    private JPanel pNorthWest = null;
111
    private JScrollPane jScrollPane1 = null;
112
    private JList listFields = null;
113
    private JRadioButton rbNumber = null;
114
    private JRadioButton rbString = null;
115
    private JRadioButton rbDate = null;
116
    private JScrollPane jScrollPane2 = null;
117
    private JList listCommand = null;
118
    private BSFManager interpreter = null; // Construct an interpreter
119
    private Feature feature;
120
    private FeatureStore featureStore = null;
121
    private EvalExpression evalExpression = null;
122
    /*
123
     * Keeps index of row in feature set currently used.
124
     */
125
    private FeatureIndex fIndex = new FeatureIndex();
126

  
127
    private JPanel pMessage;
128
    private FeatureContainer featureContainer;
129
    private static ArrayList<IOperator> operators = new ArrayList<IOperator>();
130

  
131
    public EvalExpressionDialog(FeatureTableDocumentPanel table, BSFManager interpreter, ArrayList<IOperator> operators) {
132
        super();
133
        this.operators = operators;
134
        this.interpreter = interpreter;
135
        this.table = table;
136
        initialize();
137

  
138
    }
139

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

  
160
        lv = (FLyrVect) table.getModel().getAssociatedLayer();
161
        ButtonGroup bg = new ButtonGroup();
162
        bg.add(getRbNumber());
163
        bg.add(getRbString());
164
        bg.add(getRbDate());
165
        this.setLayout(new GridBagLayout());
166
        this.setSize(549, 480);
167
        GridBagConstraints constr = new GridBagConstraints();
168
        constr.gridwidth = GridBagConstraints.REMAINDER;
169
        constr.gridheight = 1;
170
        constr.fill = GridBagConstraints.BOTH;
171
        constr.ipadx = 5;
172
        constr.ipady = 5;
173
        constr.weightx = 1;
174
        constr.weighty = 0.3;
175
        this.add(getPMessage(), constr);
176
        constr.gridheight = 5;
177
        constr.weighty = 1;
178
        this.add(getTabPrincipal(), constr);
179
        GridBagConstraints constr2 = new GridBagConstraints();
180
        constr2.gridwidth = GridBagConstraints.REMAINDER;
181
        constr2.gridheight = 1;
182
        constr2.fill = GridBagConstraints.HORIZONTAL;
183
        constr2.anchor = GridBagConstraints.LAST_LINE_END;
184
        constr2.weightx = 1;
185
        constr2.weighty = 0;
186

  
187
        this.add(getAcceptCancel(), constr2);
188

  
189
    }
190

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

  
208
            contr.fill = GridBagConstraints.VERTICAL;
209
            contr.weightx = 0;
210
            contr.weighty = 1;
211

  
212
            pNorth.add(getPNorthCenter(), contr);
213

  
214
            contr.fill = GridBagConstraints.BOTH;
215
            contr.weightx = 0.5;
216
            contr.weighty = 1;
217

  
218
            pNorth.add(getPNorthEast(), contr);
219
        }
220

  
221
        return pNorth;
222
    }
223

  
224
    /**
225
     * This method initializes pNorth
226
     *
227
     * @return javax.swing.JPanel
228
     */
229
    private JPanel getPCentral() {
230
        if ( pCentral == null ) {
231
            StringBuilder tit = new StringBuilder();
232
            tit.append(PluginServices.getText(this, "expression"));
233
            tit.append(" ");
234
            tit.append(PluginServices.getText(this, "column"));
235
            tit.append(" : ");
236
            tit.append(evalExpression.getFieldDescriptorSelected().getName());
237
            pCentral = new JPanel();
238
            pCentral.setLayout(new GridBagLayout());
239
            pCentral.setBorder(javax.swing.BorderFactory.createTitledBorder(
240
                    null, tit.toString(),
241
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
242
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
243
            GridBagConstraints contr = new GridBagConstraints();
244
            contr.gridwidth = GridBagConstraints.REMAINDER;
245
            contr.gridheight = 1;
246
            contr.fill = GridBagConstraints.BOTH;
247
            contr.ipadx = 5;
248
            contr.ipady = 5;
249
            contr.weightx = 1;
250
            contr.weighty = 1;
251
            pCentral.add(getJScrollPane(), contr);
252
            GridBagConstraints contr1 = new GridBagConstraints();
253
            contr1.gridwidth = 1;
254
            contr1.gridheight = 1;
255
            contr1.fill = GridBagConstraints.NONE;
256
            contr1.ipadx = 5;
257
            contr1.ipady = 5;
258
            contr1.anchor = GridBagConstraints.CENTER;
259
            pCentral.add(getBClear(), contr1);
260
        }
261

  
262
        return pCentral;
263
    }
264

  
265
    /**
266
     * This method initializes pSouth
267
     *
268
     * @return javax.swing.JPanel
269
     */
270
    private AcceptCancelPanel getAcceptCancel() {
271
        if ( this.acceptCancel == null ) {
272
            this.acceptCancel = new AcceptCancelPanel(
273
                    new java.awt.event.ActionListener() {
274
                        public void actionPerformed(java.awt.event.ActionEvent e) {
275
                            boolean isAccepted = true;
276
                            Preferences prefs = Preferences.userRoot().node(
277
                                    "fieldExpressionOptions");
278
                            int limit;
279
                            limit = prefs.getInt("limit_rows_in_memory", -1);
280
                            if ( limit != -1 ) {
281
                                int option = JOptionPane
282
                                .showConfirmDialog(
283
                                        (Component) PluginServices
284
                                        .getMainFrame(),
285
                                        PluginServices
286
                                        .getText(
287
                                                this,
288
                                                "it_has_established_a_limit_of_rows_will_lose_the_possibility_to_undo_wants_to_continue"));
289
                                if ( option != JOptionPane.OK_OPTION ) {
290
                                    return;
291
                                }
292
                            }
293
                            try {
294
                                long t1 = System.currentTimeMillis();
295
                                isAccepted = evalExpression();
296
                                long t2 = System.currentTimeMillis();
297
                                logger.info("Tiempo evaluar expresiones = " + (t2 - t1));
298
                            } catch (BSFException e1) {
299
                                NotificationManager.addError(e1);
300
                            }
301
                            if ( isAccepted ) {
302
                                PluginServices.getMDIManager().closeWindow(
303
                                        EvalExpressionDialog.this);
304
                            }
305
                        }
306
                    }, new java.awt.event.ActionListener() {
307
                        public void actionPerformed(java.awt.event.ActionEvent e) {
308
                            PluginServices.getMDIManager().closeWindow(
309
                                    EvalExpressionDialog.this);
310
                        }
311
                    });
312
            acceptCancel.setOkButtonEnabled(false);
313
        }
314

  
315
        return this.acceptCancel;
316
    }
317

  
318
    private String replaceFields(String expression) {
319
        String s = expression;
320

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

  
330
    /**
331
     * Evaluate the expression.
332
     *
333
     * @throws BSFException
334
     */
335
    private boolean evalExpression() throws BSFException {
336
        final I18nManager i18nManager = ToolsLocator.getI18nManager();
337
        final ApplicationManager application = ApplicationLocator.getManager();
338
        String expression = getTxtExp().getText();
339
        byte[] expressionBytes;
340
        String encoding = System.getProperty("file.encoding");
341
        try {
342
            expressionBytes = expression.getBytes(encoding);
343
            expression = new String(expressionBytes, "ISO-8859-1");
344
        } catch (UnsupportedEncodingException e) {
345
            logger.warn("Can't apply enconding ("+encoding+").",e);
346
        }
347
        String advancedCode = advancedPanel.getCode();
348
        if( advancedCode != null ) {
349
            try {
350
                interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, advancedCode);
351
            } catch (BSFException ex) {
352
                logger.warn("Can't execute script from advanced tab:\n" + advancedCode + "\n", ex);
353
                application.messageDialog(
354
                    i18nManager.getTranslation("_Se_han_producido_errores_ejecutando_el_codigo_de_la_pesta?a_avanzado") + "\n\n" + ex.getMessage(),
355
                    i18nManager.getTranslation("_Atencion"),
356
                    JOptionPane.WARNING_MESSAGE);
357
            }
358
        }
359
        expression = replaceFields(expression);
360
        
361
        interpreter.declareBean("evalExpression", evalExpression, EvalExpression.class);
362
        interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def expression():\n"
363
                + "  return " + expression + "");
364

  
365
        try {
366
            interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def isCorrect():\n"
367
                    + "    evalExpression.isCorrectValue(expression())\n");
368
            interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "isCorrect()");
369
        } catch (BSFException ee) {
370
            String message = ee.getMessage();
371
            if ( message.length() > 200 ) {
372
                message = message.substring(0, 200);
373
            }
374
            int option = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(),
375
                    PluginServices.getText(this,
376
                            "error_expression") + "\n" + message + "\n" + PluginServices.getText(this, "continue?"));
377
            if ( option != JOptionPane.OK_OPTION ) {
378
                return false;
379
            }
380
        }
381
        try {
382
            boolean select = true;
383
            interpreter.declareBean("select", select, boolean.class);
384
            if ( featureStore.isEditing() ) {
385
                evalInEditing();
386
            } else {
387
                evalOutEditing();
388
            }
389
        } catch (DataException e) {
390
            logger.warn("Can't evaluate expresion ("+expression+").",e);
391
        }
392

  
393
        return true;
394
    }
395

  
396
    private void evalInEditing() throws BSFException, DataException {
397
        int limit = prefs.getInt("limit_rows_in_memory", -1);
398
        ArrayList exceptions = new ArrayList();
399
        interpreter.declareBean("exceptions", exceptions, ArrayList.class);
400
        boolean emptySelection = ((FeatureSelection) featureStore.getSelection()).isEmpty();
401

  
402
        FeatureSet set = null;
403
        DisposableIterator iterator = null;
404

  
405
        try {
406
            set = featureStore.getFeatureSet(table.getModel().getQuery());
407
            iterator = set.fastIterator();
408

  
409
            interpreter.declareBean("featureSet", set, FeatureSet.class);
410
            interpreter.declareBean("iterator", iterator, Iterator.class);
411
            interpreter.declareBean("limit", limit, int.class);
412

  
413
            if ( limit == -1 ) {
414
                featureStore.beginEditingGroup(PluginServices.getText(this, "expression"));
415
                if ( !emptySelection ) {
416
                    interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n"
417
                            + "  \n"
418
                            + "  featureIndex.set(0)\n"
419
                            + "  while iterator.hasNext():\n"
420
                            + "    feature=iterator.next()\n"
421
                            + "    select=featureStore.getSelection().isSelected(feature)\n"
422
                            + "    if select:\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
                } else {
431
                    interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n"
432
                            + "  \n"
433
                            + "  featureIndex.set(0)\n"
434
                            + "  while iterator.hasNext():\n"
435
                            + "    feature=iterator.next()\n"
436
                            + "    featureContainer.setFeature(feature)\n"
437
                            + "    obj=expression()\n"
438
                            + "    evalExpression.setValue(featureSet,feature,obj)\n"
439
                            + "    featureIndex.next()\n"
440
                            + "  iterator.dispose()\n"
441
                            + "  featureSet.dispose\n"
442
                    );
443
                }
444
                try {
445
                    interpreter.eval(ExpressionFieldExtension.JYTHON, null, -1, -1, "p()");
446
                } catch (BSFException ee) {
447

  
448
                    JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(),
449
                            PluginServices.getText(this, "evaluate_expression_with_errors") + " " + exceptions.size() + ee.getMessage());
450
                }
451
                featureStore.endEditingGroup();
452
            } else {
453
                long size = set.getSize();
454
                for ( int i = 0; i < size; i = i + limit ) {
455
	//    			featureStore.finishEditing();
456
                    //    			featureStore.edit();
457
                    featureStore.beginEditingGroup(PluginServices.getText(this, "expression"));
458
                    set = featureStore.getFeatureSet(table.getModel().getQuery());
459
                    interpreter.declareBean("featureSet", set, FeatureSet.class);
460
                    iterator = set.fastIterator(i);
461
                    interpreter.declareBean("iterator", iterator, Iterator.class);
462
                    if ( !emptySelection ) {
463
                        interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n"
464
                                + "  \n"
465
                                + "  pos=0\n"
466
                                + "  featureIndex.set(0)\n"
467
                                + "  while iterator.hasNext() and pos<limit:\n"
468
                                + "    feature=iterator.next()\n"
469
                                + "    select=featureStore.getSelection().isSelected(feature)\n"
470
                                + "    if select:\n"
471
                                + "      featureContainer.setFeature(feature)\n"
472
                                + "      obj=expression()\n"
473
                                + "      evalExpression.setValue(featureSet,feature,obj)\n"
474
                                + "      featureIndex.next()\n"
475
                                + "    pos=pos+1\n"
476
                                + "  iterator.dispose()\n"
477
                                + "  featureSet.dispose\n"
478
                        );
479
                    } else {
480
                        interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n"
481
                                + "  \n"
482
                                + "  pos=0\n"
483
                                + "  featureIndex.set(0)\n"
484
                                + "  while iterator.hasNext() and pos<limit:\n"
485
                                + "    feature=iterator.next()\n"
486
                                + "    featureContainer.setFeature(feature)\n"
487
                                + "    obj=expression()\n"
488
                                + "    evalExpression.setValue(featureSet,feature,obj)\n"
489
                                + "    pos=pos+1\n"
490
                                + "    featureIndex.next()\n"
491
                                + "  iterator.dispose()\n"
492
                                + "  featureSet.dispose\n"
493
                        );
494
                    }
495
                    try {
496
                        interpreter.eval(ExpressionFieldExtension.JYTHON, null, -1, -1, "p()");
497
                    } catch (BSFException ee) {
498

  
499
                        JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(),
500
                                PluginServices.getText(this, "evaluate_expression_with_errors") + " " + exceptions.size() + ee.getMessage());
501
                    }
502

  
503
                    featureStore.endEditingGroup();
504
                    featureStore.finishEditing();
505
                    featureStore.edit();
506
                }
507
            }
508
        } finally {
509
            DisposeUtils.dispose(set);
510
            DisposeUtils.dispose(iterator);
511
        }
512

  
513
    }
514

  
515
    private void evalOutEditing() throws BSFException, DataException {
516

  
517
    }
518

  
519
    /**
520
     * This method initializes pMessage
521
     *
522
     * @return javax.swing.JPanel
523
     */
524
    private JPanel getPMessage() {
525
        if ( pMessage == null ) {
526

  
527
            pMessage = new JPanel();
528
            pMessage.setLayout(new GridLayout());
529
            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));
530
            pMessage.add(getJScrollPane3(), null);
531
        }
532
        return pMessage;
533
    }
534

  
535
    private void evalExpressions() throws BSFException {
536
        featureStore = table.getModel().getStore();
537
        interpreter.declareBean("featureStore", featureStore, FeatureStore.class);
538
        featureContainer = new FeatureContainer();
539
        DisposableIterator iterator = null;
540
        FeatureSet set = null;
541
        try {
542
            set = featureStore.getFeatureSet(table.getModel().getQuery());
543
            iterator = set.iterator();
544

  
545
            if ( iterator.hasNext() ) {
546
                feature = (Feature) iterator.next();
547
            }
548
            featureContainer.setFeature(feature);
549
            interpreter.declareBean("featureContainer", featureContainer, Feature.class);
550
        } catch (DataException e) {
551
            e.printStackTrace();
552
        } finally {
553
            if ( iterator != null ) {
554
                iterator.dispose();
555
            }
556
            if ( set != null ) {
557
                set.dispose();
558
            }
559
        }
560
    }
561
    /**
562
     * Evaluate the fields.
563
     *
564
     * @param interpreter
565
     *
566
     * @throws EvalError
567
     */
568
    int lastType = -1;
569
    private JButton bClear = null;
570
    private JTabbedPane tabPrincipal = null;
571
    private JPanel pPrincipal = null;
572
    private JPanel pAdvanced = null;
573
    private AdvancedPanel advancedPanel = null; 
574
//    private JPanel pAdvancedNorth = null;
575
//    private JTextField jTextField = null;
576
//    private JButton bFile = null;
577
//    private JPanel pAdvancedCenter = null;
578
//    private JLabel lblLeng = null;
579
//    private JButton bEval = null;
580
    private JScrollPane jScrollPane3 = null;
581
    private JTextArea txtMessage2 = null;
582

  
583
    private void refreshOperators(int type) {
584
        if ( lastType != -1 && lastType == type ) {
585
            return;
586
        }
587
        lastType = type;
588
        ListOperatorsModel lom = (ListOperatorsModel) getListCommand().getModel();
589
        lom.clear();
590
        for ( int i = 0; i < operators.size(); i++ ) {
591
            IOperator operator = (IOperator) operators.get(i);
592
            operator.setType(type);
593
            //Comprobar si tiene una capa asociada y pasarsela al GraphicOperator.
594
            if ( (lv != null) && operator instanceof GraphicOperator ) {
595
                GraphicOperator igo = (GraphicOperator) operator;
596
                igo.setLayer(lv);
597
            }
598
            if ( operator.isEnable() ) {
599
                lom.addOperator(operator);
600
                //System.out.println("Operator = "+operator.toString());
601
            }
602
        }
603
        getListCommand().repaint();
604
        getJScrollPane2().repaint();
605
        getJScrollPane2().doLayout();
606
        this.doLayout();
607

  
608
    }
609

  
610
    /**
611
     * This method initializes jScrollPane
612
     *
613
     * @return javax.swing.JScrollPane
614
     */
615
    private JScrollPane getJScrollPane() {
616
        if ( jScrollPane == null ) {
617
            jScrollPane = new JScrollPane();
618
            jScrollPane.setPreferredSize(new java.awt.Dimension(480, 80));
619
            jScrollPane.setViewportView(getTxtExp());
620
        }
621

  
622
        return jScrollPane;
623
    }
624

  
625
    /**
626
     * This method initializes txtExp
627
     *
628
     * @return javax.swing.JTextArea
629
     */
630
    private JTextArea getTxtExp() {
631
        if ( txtExp == null ) {
632
            txtExp = new JTextArea();
633
            txtExp.addCaretListener(new CaretListener() {
634
                public void caretUpdate(CaretEvent e) {
635
                    if ( txtExp.getText().length() > 0 ) {
636
                        getAcceptCancel().setOkButtonEnabled(true);
637
                    } else {
638
                        getAcceptCancel().setOkButtonEnabled(false);
639
                    }
640
                }
641

  
642
            });
643
        }
644

  
645
        return txtExp;
646
    }
647

  
648
    public WindowInfo getWindowInfo() {
649
        WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG + WindowInfo.RESIZABLE);
650
        wi.setTitle(PluginServices.getText(this, "calculate_expression"));
651

  
652
        return wi;
653
    }
654

  
655
    /**
656
     * This method initializes pNorthEast
657
     *
658
     * @return javax.swing.JPanel
659
     */
660
    private JPanel getPNorthEast() {
661
        if ( pNorthEast == null ) {
662
            pNorthEast = new JPanel(new GridLayout());
663
            pNorthEast.setBorder(javax.swing.BorderFactory.createTitledBorder(
664
                    null, PluginServices.getText(this, "commands"),
665
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
666
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
667
            pNorthEast.add(getJScrollPane2(), null);
668
        }
669

  
670
        return pNorthEast;
671
    }
672

  
673
    /**
674
     * This method initializes pNorthCenter
675
     *
676
     * @return javax.swing.JPanel
677
     */
678
    private JPanel getPNorthCenter() {
679
        if ( pNorthCenter == null ) {
680
            pNorthCenter = new JPanel();
681
            pNorthCenter.setLayout(new BoxLayout(getPNorthCenter(),
682
                    BoxLayout.Y_AXIS));
683
            pNorthCenter.setBorder(javax.swing.BorderFactory.createTitledBorder(
684
                    null, PluginServices.getText(this, "type"),
685
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
686
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
687
            pNorthCenter.add(getRbNumber(), null);
688
            pNorthCenter.add(getRbString(), null);
689
            pNorthCenter.add(getRbDate(), null);
690
        }
691

  
692
        return pNorthCenter;
693
    }
694

  
695
    /**
696
     * This method initializes pNorthWest
697
     *
698
     * @return javax.swing.JPanel
699
     */
700
    private JPanel getPNorthWest() {
701
        if ( pNorthWest == null ) {
702
            pNorthWest = new JPanel(new GridLayout());
703
            pNorthWest.setBorder(javax.swing.BorderFactory.createTitledBorder(
704
                    null, PluginServices.getText(this, "field"),
705
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
706
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
707
            pNorthWest.add(getJScrollPane1(), null);
708
        }
709

  
710
        return pNorthWest;
711
    }
712

  
713
    /**
714
     * This method initializes jScrollPane1
715
     *
716
     * @return javax.swing.JScrollPane
717
     */
718
    private JScrollPane getJScrollPane1() {
719
        if ( jScrollPane1 == null ) {
720
            jScrollPane1 = new JScrollPane();
721
            jScrollPane1.setPreferredSize(new java.awt.Dimension(175, 100));
722
            jScrollPane1.setViewportView(getListFields());
723
        }
724

  
725
        return jScrollPane1;
726
    }
727

  
728
    /**
729
     * This method initializes listFields
730
     *
731
     * @return javax.swing.JList
732
     */
733
    private JList getListFields() {
734
        if ( listFields == null ) {
735
            listFields = new JList();
736
            listFields.setModel(new ListOperatorsModel());
737

  
738
            ListOperatorsModel lm = (ListOperatorsModel) listFields.getModel();
739
            FeatureType fds = evalExpression.getFieldDescriptors();
740
            for ( int i = 0; i < fds.size(); i++ ) {
741
                Field field = new Field();
742
                field.setFieldDescription(fds.getAttributeDescriptor(i));
743
                try {
744
                    field.eval(interpreter);
745
                } catch (BSFException e) {
746
                    e.printStackTrace();
747
                }
748
                lm.addOperator(field);
749
            }
750

  
751
            listFields.addMouseListener(new MouseListener() {
752
                public void mouseClicked(MouseEvent e) {
753
                    IOperator operator = ((IOperator) listFields.getSelectedValue());
754
                    if ( operator != null ) {
755
                        getTxtMessage2().setText(operator.getTooltip());
756
                        if ( e.getClickCount() == 2 ) {
757
                            getTxtExp().setText(operator.addText(
758
                                    getTxtExp().getText()));
759
                        }
760
                    }
761
                }
762

  
763
                public void mouseEntered(MouseEvent e) {
764
                }
765

  
766
                public void mouseExited(MouseEvent e) {
767
                }
768

  
769
                public void mousePressed(MouseEvent e) {
770
                }
771

  
772
                public void mouseReleased(MouseEvent e) {
773
                }
774
            });
775
        }
776

  
777
        return listFields;
778
    }
779

  
780
    /**
781
     * This method initializes rbNumber
782
     *
783
     * @return javax.swing.JRadioButton
784
     */
785
    private JRadioButton getRbNumber() {
786
        if ( rbNumber == null ) {
787
            rbNumber = new JRadioButton();
788
            rbNumber.setText(PluginServices.getText(this, "numeric"));
789
            rbNumber.setSelected(true);
790
            rbNumber.addChangeListener(new javax.swing.event.ChangeListener() {
791
                public void stateChanged(javax.swing.event.ChangeEvent e) {
792
                    if ( rbNumber.isSelected() ) {
793
                        refreshCommands();
794
                    }
795
                }
796
            });
797
        }
798

  
799
        return rbNumber;
800
    }
801

  
802
    /**
803
     * This method initializes rbString
804
     *
805
     * @return javax.swing.JRadioButton
806
     */
807
    private JRadioButton getRbString() {
808
        if ( rbString == null ) {
809
            rbString = new JRadioButton();
810
            rbString.setText(PluginServices.getText(this, "string"));
811
            rbString.addChangeListener(new javax.swing.event.ChangeListener() {
812
                public void stateChanged(javax.swing.event.ChangeEvent e) {
813
                    if ( rbString.isSelected() ) {
814
                        refreshCommands();
815
                    }
816
                }
817
            });
818
        }
819

  
820
        return rbString;
821
    }
822

  
823
    /**
824
     * This method initializes rbData
825
     *
826
     * @return javax.swing.JRadioButton
827
     */
828
    private JRadioButton getRbDate() {
829
        if ( rbDate == null ) {
830
            rbDate = new JRadioButton();
831
            rbDate.setText(PluginServices.getText(this, "date"));
832
            rbDate.addChangeListener(new javax.swing.event.ChangeListener() {
833
                public void stateChanged(javax.swing.event.ChangeEvent e) {
834
                    if ( rbDate.isSelected() ) {
835
                        refreshCommands();
836
                    }
837
                }
838
            });
839
        }
840

  
841
        return rbDate;
842
    }
843

  
844
    /**
845
     * This method initializes jScrollPane2
846
     *
847
     * @return javax.swing.JScrollPane
848
     */
849
    private JScrollPane getJScrollPane2() {
850
        if ( jScrollPane2 == null ) {
851
            jScrollPane2 = new JScrollPane();
852
            jScrollPane2.setPreferredSize(new java.awt.Dimension(175, 100));
853
            jScrollPane2.setViewportView(getListCommand());
854
        }
855

  
856
        return jScrollPane2;
857
    }
858

  
859
    /**
860
     * Refresh the commands.
861
     */
862
    private void refreshCommands() {
863
        int type = IOperator.NUMBER;
864
        if ( getRbNumber().isSelected() ) {
865
            type = IOperator.NUMBER;
866
        } else if ( getRbString().isSelected() ) {
867
            type = IOperator.STRING;
868
        } else if ( getRbDate().isSelected() ) {
869
            type = IOperator.DATE;
870
        }
871
        refreshOperators(type);
872

  
873
    }
874

  
875
    /**
876
     * This method initializes ListCommand
877
     *
878
     * @return javax.swing.JList
879
     */
880
    private JList getListCommand() {
881
        if ( listCommand == null ) {
882
            listCommand = new JList();
883
            listCommand.setModel(new ListOperatorsModel());
884
            listCommand.addMouseListener(new MouseListener() {
885
                public void mouseClicked(MouseEvent e) {
886
                    IOperator operator = ((IOperator) listCommand.getSelectedValue());
887
                    if ( operator != null ) {
888
                        getTxtMessage2().setText(operator.getTooltip());
889
                        if ( e.getClickCount() == 2 ) {
890
                            if ( listCommand.getSelectedValue() == null ) {
891
                                return;
892
                            }
893
                            getTxtExp().setText(operator.addText(
894
                                    getTxtExp().getText()));
895
                        }
896
                    }
897
                }
898

  
899
                public void mouseEntered(MouseEvent e) {
900
                }
901

  
902
                public void mouseExited(MouseEvent e) {
903
                }
904

  
905
                public void mousePressed(MouseEvent e) {
906
                }
907

  
908
                public void mouseReleased(MouseEvent e) {
909
                }
910
            });
911
            refreshOperators(IOperator.NUMBER);
912
        }
913

  
914
        return listCommand;
915
    }
916

  
917
    /**
918
     * This method initializes bClear
919
     *
920
     * @return javax.swing.JButton
921
     */
922
    private JButton getBClear() {
923
        if ( bClear == null ) {
924
            bClear = new JButton();
925
            bClear.setText(PluginServices.getText(this, "clear_expression"));
926
            bClear.addActionListener(new java.awt.event.ActionListener() {
927
                public void actionPerformed(java.awt.event.ActionEvent e) {
928
                    getTxtExp().setText("");
929
                }
930
            });
931
        }
932
        return bClear;
933
    }
934

  
935
    /**
936
     * This method initializes tabPrincipal
937
     *
938
     * @return javax.swing.JTabbedPane
939
     */
940
    private JTabbedPane getTabPrincipal() {
941
        if ( tabPrincipal == null ) {
942
            tabPrincipal = new JTabbedPane();
943
            tabPrincipal.addTab(PluginServices.getText(this, "general"), null, getPPrincipal(), null);
944
            tabPrincipal.addTab(PluginServices.getText(this, "advanced"), null, getPAdvanced(), null);
945
        }
946
        return tabPrincipal;
947
    }
948

  
949
    /**
950
     * This method initializes pPrincipal
951
     *
952
     * @return javax.swing.JPanel
953
     */
954
    private JPanel getPPrincipal() {
955
        if ( pPrincipal == null ) {
956
            pPrincipal = new JPanel();
957
            pPrincipal.setLayout(new BorderLayout());
958
//			pPrincipal.setPreferredSize(new java.awt.Dimension(540,252));
959
            pPrincipal.add(getPNorth(), java.awt.BorderLayout.NORTH);
960
            pPrincipal.add(getPCentral(), java.awt.BorderLayout.CENTER);
961

  
962
        }
963
        return pPrincipal;
964
    }
965

  
966
    /**
967
     * This method initializes pAdvanced
968
     *
969
     * @return javax.swing.JPanel
970
     */
971
    private JPanel getPAdvanced() {
972
        if ( pAdvanced == null ) {
973
            pAdvanced = new JPanel();
974
            pAdvanced.setLayout(new BorderLayout());
975
//            pAdvanced.add(getPAdvancedNorth(), java.awt.BorderLayout.NORTH);
976
//            pAdvanced.add(getPAdvancedCenter(), java.awt.BorderLayout.CENTER);
977
            advancedPanel = new AdvancedPanel(interpreter);
978
            pAdvanced.add(advancedPanel, java.awt.BorderLayout.CENTER);
979
        }
980
        return pAdvanced;
981
    }
982

  
983
    /**
984
     * This method initializes jScrollPane3
985
     *
986
     * @return javax.swing.JScrollPane
987
     */
988
    private JScrollPane getJScrollPane3() {
989
        if ( jScrollPane3 == null ) {
990
            jScrollPane3 = new JScrollPane();
991
            jScrollPane3.setPreferredSize(new java.awt.Dimension(530, 80));
992
            jScrollPane3.setViewportView(getTxtMessage2());
993
        }
994
        return jScrollPane3;
995
    }
996

  
997
    /**
998
     * This method initializes txtMessage2
999
     *
1000
     * @return javax.swing.JTextArea
1001
     */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff