Revision 47

View differences:

org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/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.4/src/main/java/org/gvsig/expressionfield/AboutExpressionFieldExtension.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;
27

  
28
import org.gvsig.about.AboutManager;
29
import org.gvsig.about.AboutParticipant;
30
import org.gvsig.andami.plugins.Extension;
31
import org.gvsig.app.ApplicationLocator;
32
import org.gvsig.app.ApplicationManager;
33

  
34

  
35
/**
36
 * About extension.
37
 *
38
 * Add the about coments to the gvSIG About panel
39
 */
40

  
41
public class AboutExpressionFieldExtension extends Extension {
42

  
43
	public void initialize() {
44
		// TODO Auto-generated method stub
45

  
46
	}
47

  
48
	public void postInitialize() {
49
		ApplicationManager application = ApplicationLocator.getManager();
50
		
51
		AboutManager about = application.getAbout();
52

  
53
		about.addDeveloper(
54
				"IVER",
55
				this.getClass().getClassLoader().getResource("iver.html"),
56
				1
57
		);
58
		
59
		AboutParticipant participant = about.getDeveloper("IVER");
60
		participant.addContribution(
61
			"Expression field",
62
			"Extesi?n para el c?lculo de una expresi?n sobre una columna de la tabla.", 
63
			2007,1,1, 
64
			2007,12,31
65
		);
66
	}
67

  
68
	public void execute(String actionCommand) {
69

  
70
	}
71

  
72
	public boolean isEnabled() {
73
		return false;
74
	}
75

  
76
	public boolean isVisible() {
77
		return false;
78
	}
79

  
80
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/src/main/java/org/gvsig/expressionfield/ExpressionFieldExtension.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;
29

  
30
import java.awt.Component;
31
import java.util.ArrayList;
32
import java.util.Iterator;
33

  
34
import javax.swing.JOptionPane;
35

  
36
import org.apache.bsf.BSFManager;
37
import org.gvsig.andami.IconThemeHelper;
38
import org.gvsig.andami.PluginServices;
39
import org.gvsig.andami.messages.NotificationManager;
40
import org.gvsig.andami.plugins.Extension;
41
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
42
import org.gvsig.expressionfield.gui.FieldExpressionPage;
43
import org.gvsig.expressionfield.project.documents.table.IOperator;
44
import org.gvsig.expressionfield.project.documents.table.gui.EvalExpressionDialog;
45
import org.gvsig.expressionfield.project.documents.table.operators.Abs;
46
import org.gvsig.expressionfield.project.documents.table.operators.Acos;
47
import org.gvsig.expressionfield.project.documents.table.operators.After;
48
import org.gvsig.expressionfield.project.documents.table.operators.Area;
49
import org.gvsig.expressionfield.project.documents.table.operators.Asin;
50
import org.gvsig.expressionfield.project.documents.table.operators.Atan;
51
import org.gvsig.expressionfield.project.documents.table.operators.Before;
52
import org.gvsig.expressionfield.project.documents.table.operators.Ceil;
53
import org.gvsig.expressionfield.project.documents.table.operators.Cos;
54
import org.gvsig.expressionfield.project.documents.table.operators.DateToString;
55
import org.gvsig.expressionfield.project.documents.table.operators.Distinct;
56
import org.gvsig.expressionfield.project.documents.table.operators.Division;
57
import org.gvsig.expressionfield.project.documents.table.operators.E;
58
import org.gvsig.expressionfield.project.documents.table.operators.EndsWith;
59
import org.gvsig.expressionfield.project.documents.table.operators.Equal;
60
import org.gvsig.expressionfield.project.documents.table.operators.Equals;
61
import org.gvsig.expressionfield.project.documents.table.operators.Exp;
62
import org.gvsig.expressionfield.project.documents.table.operators.Floor;
63
import org.gvsig.expressionfield.project.documents.table.operators.Geometry;
64
import org.gvsig.expressionfield.project.documents.table.operators.GetTimeDate;
65
import org.gvsig.expressionfield.project.documents.table.operators.IndexOf;
66
import org.gvsig.expressionfield.project.documents.table.operators.IsNumber;
67
import org.gvsig.expressionfield.project.documents.table.operators.LastIndexOf;
68
import org.gvsig.expressionfield.project.documents.table.operators.Length;
69
import org.gvsig.expressionfield.project.documents.table.operators.LessEquals;
70
import org.gvsig.expressionfield.project.documents.table.operators.LessThan;
71
import org.gvsig.expressionfield.project.documents.table.operators.Log;
72
import org.gvsig.expressionfield.project.documents.table.operators.Max;
73
import org.gvsig.expressionfield.project.documents.table.operators.Min;
74
import org.gvsig.expressionfield.project.documents.table.operators.Minus;
75
import org.gvsig.expressionfield.project.documents.table.operators.MoreEquals;
76
import org.gvsig.expressionfield.project.documents.table.operators.MoreThan;
77
import org.gvsig.expressionfield.project.documents.table.operators.Perimeter;
78
import org.gvsig.expressionfield.project.documents.table.operators.Pi;
79
import org.gvsig.expressionfield.project.documents.table.operators.Plus;
80
import org.gvsig.expressionfield.project.documents.table.operators.PointX;
81
import org.gvsig.expressionfield.project.documents.table.operators.PointY;
82
import org.gvsig.expressionfield.project.documents.table.operators.Pow;
83
import org.gvsig.expressionfield.project.documents.table.operators.Random;
84
import org.gvsig.expressionfield.project.documents.table.operators.RecordIndex;
85
import org.gvsig.expressionfield.project.documents.table.operators.Replace;
86
import org.gvsig.expressionfield.project.documents.table.operators.Round;
87
import org.gvsig.expressionfield.project.documents.table.operators.SetTimeDate;
88
import org.gvsig.expressionfield.project.documents.table.operators.Sin;
89
import org.gvsig.expressionfield.project.documents.table.operators.Sqrt;
90
import org.gvsig.expressionfield.project.documents.table.operators.StartsWith;
91
import org.gvsig.expressionfield.project.documents.table.operators.SubString;
92
import org.gvsig.expressionfield.project.documents.table.operators.Tan;
93
import org.gvsig.expressionfield.project.documents.table.operators.Times;
94
import org.gvsig.expressionfield.project.documents.table.operators.ToDate;
95
import org.gvsig.expressionfield.project.documents.table.operators.ToDegrees;
96
import org.gvsig.expressionfield.project.documents.table.operators.ToLowerCase;
97
import org.gvsig.expressionfield.project.documents.table.operators.ToNumber;
98
import org.gvsig.expressionfield.project.documents.table.operators.ToRadians;
99
import org.gvsig.expressionfield.project.documents.table.operators.ToString;
100
import org.gvsig.expressionfield.project.documents.table.operators.ToUpperCase;
101
import org.gvsig.expressionfield.project.documents.table.operators.Trim;
102
import org.gvsig.fmap.dal.exception.DataException;
103
import org.gvsig.tools.ToolsLocator;
104
import org.gvsig.tools.extensionpoint.ExtensionPoint;
105
import org.gvsig.utils.swing.threads.AbstractMonitorableTask;
106
import org.slf4j.Logger;
107
import org.slf4j.LoggerFactory;
108

  
109
/**
110
 * @author Vicente Caballero Navarro
111
 */
112
public class ExpressionFieldExtension extends Extension {
113

  
114
    private static Logger logger = LoggerFactory.getLogger(ExpressionFieldExtension.class);
115

  
116
    public static final String JYTHON = "jython";
117
    private static BSFManager interpreter = new BSFManager();
118
    private FeatureTableDocumentPanel table = null;
119
    private static ArrayList<IOperator> operators = new ArrayList<IOperator>();
120

  
121
    public void initialize() {
122
        registerIcons();
123
        registerOperations();
124
    }
125

  
126
    public void execute(String actionCommand) {
127
        if ( "table-expression-field".equalsIgnoreCase(actionCommand) ) {
128
            org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager().getActiveWindow();
129
            table = (FeatureTableDocumentPanel) window;
130
            if ( !table.getModel().getStore().isEditing() ) {
131
                int option = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), PluginServices.getText(this, "is_not_in_editing_are_you_sure"));
132
                if ( option != JOptionPane.OK_OPTION ) {
133
                    return;
134
                }
135
            }
136
            if ( operators.isEmpty() ) {
137
                PluginServices.cancelableBackgroundExecution(new EvalOperatorsTask());
138
            } else {
139
                EvalExpressionDialog eed = new EvalExpressionDialog(table, interpreter, operators);
140
                PluginServices.getMDIManager().addWindow(eed);
141
            }
142
        }
143
    }
144

  
145
    public void postInitialize() {
146

  
147
    }
148

  
149
    public boolean isEnabled() {
150
        org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager().getActiveWindow();
151
        if ( window instanceof FeatureTableDocumentPanel ) {
152
            FeatureTableDocumentPanel table = (FeatureTableDocumentPanel) window;
153
            int columnSelected = 0;
154
            try {
155
                columnSelected = table.getTablePanel().getTable().getSelectedColumnCount();
156
            } catch (DataException e) {
157
                logger.error("Can't get selected column in table.", e);
158
            }
159
            if ( columnSelected > 0 && table.getModel().getStore().isEditing() ) {
160
                return true;
161
            }
162
        }
163
        return false;
164
    }
165

  
166
    public boolean isVisible() {
167
        org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager().getActiveWindow();
168
        if ( window instanceof FeatureTableDocumentPanel ) {
169
            return true;
170
        }
171
        return false;
172
    }
173

  
174
    private void registerOperations() {
175
        ExtensionPoint extensionPoints = ToolsLocator.getExtensionPointManager().add(
176
                "cad_editing_properties_pages", "");
177
        extensionPoints.append("fieldExpression", "", new FieldExpressionPage());
178

  
179
        extensionPoints = ToolsLocator.getExtensionPointManager().add(
180
                "ColumnOperators", "");
181
        extensionPoints.append(Abs.class.toString(), "", Abs.class);
182
        extensionPoints.append(Acos.class.toString(), "", Acos.class);
183
        extensionPoints.append(After.class.toString(), "", After.class);
184
        extensionPoints.append(Area.class.toString(), "", Area.class);
185
        extensionPoints.append(Asin.class.toString(), "", Asin.class);
186
        extensionPoints.append(Atan.class.toString(), "", Atan.class);
187
        extensionPoints.append(Acos.class.toString(), "", Acos.class);
188
        extensionPoints.append(Before.class.toString(), "", Before.class);
189
        extensionPoints.append(Ceil.class.toString(), "", Ceil.class);
190
        extensionPoints.append(Cos.class.toString(), "", Cos.class);
191
        extensionPoints.append(DateToString.class.toString(), "", DateToString.class);
192
        extensionPoints.append(Distinct.class.toString(), "", Distinct.class);
193
        extensionPoints.append(Division.class.toString(), "", Division.class);
194
        extensionPoints.append(E.class.toString(), "", E.class);
195
        extensionPoints.append(EndsWith.class.toString(), "", EndsWith.class);
196
        extensionPoints.append(Equal.class.toString(), "", Equal.class);
197
        extensionPoints.append(Equals.class.toString(), "", Equals.class);
198
        extensionPoints.append(Exp.class.toString(), "", Exp.class);
199
        extensionPoints.append(Floor.class.toString(), "", Floor.class);
200
        extensionPoints.append(Geometry.class.toString(), "", Geometry.class);
201
        extensionPoints.append(GetTimeDate.class.toString(), "", GetTimeDate.class);
202
        extensionPoints.append(IndexOf.class.toString(), "", IndexOf.class);
203
        extensionPoints.append(IsNumber.class.toString(), "", IsNumber.class);
204
        extensionPoints.append(LastIndexOf.class.toString(), "", LastIndexOf.class);
205
        extensionPoints.append(Length.class.toString(), "", Length.class);
206
        extensionPoints.append(LessEquals.class.toString(), "", LessEquals.class);
207
        extensionPoints.append(LessThan.class.toString(), "", LessThan.class);
208
        extensionPoints.append(Log.class.toString(), "", Log.class);
209
        extensionPoints.append(Max.class.toString(), "", Max.class);
210
        extensionPoints.append(Min.class.toString(), "", Min.class);
211
        extensionPoints.append(Minus.class.toString(), "", Minus.class);
212
        extensionPoints.append(MoreEquals.class.toString(), "", MoreEquals.class);
213
        extensionPoints.append(MoreThan.class.toString(), "", MoreThan.class);
214
        extensionPoints.append(Perimeter.class.toString(), "", Perimeter.class);
215
        extensionPoints.append(Pi.class.toString(), "", Pi.class);
216
        extensionPoints.append(Plus.class.toString(), "", Plus.class);
217
        extensionPoints.append(PointX.class.toString(), "", PointX.class);
218
        extensionPoints.append(PointY.class.toString(), "", PointY.class);
219
        extensionPoints.append(Pow.class.toString(), "", Pow.class);
220
        extensionPoints.append(Random.class.toString(), "", Random.class);
221

  
222
        // Added November 2013
223
        extensionPoints.append(RecordIndex.class.toString(), "", RecordIndex.class);
224

  
225
        extensionPoints.append(Replace.class.toString(), "", Replace.class);
226
        extensionPoints.append(Round.class.toString(), "", Round.class);
227
        extensionPoints.append(SetTimeDate.class.toString(), "", SetTimeDate.class);
228
        extensionPoints.append(Sin.class.toString(), "", Sin.class);
229
        extensionPoints.append(Sqrt.class.toString(), "", Sqrt.class);
230
        extensionPoints.append(StartsWith.class.toString(), "", StartsWith.class);
231
        extensionPoints.append(SubString.class.toString(), "", SubString.class);
232
        extensionPoints.append(Tan.class.toString(), "", Tan.class);
233
        extensionPoints.append(Times.class.toString(), "", Times.class);
234
        extensionPoints.append(ToDate.class.toString(), "", ToDate.class);
235
        extensionPoints.append(ToDegrees.class.toString(), "", ToDegrees.class);
236
        extensionPoints.append(ToLowerCase.class.toString(), "", ToLowerCase.class);
237
        extensionPoints.append(ToNumber.class.toString(), "", ToNumber.class);
238
        extensionPoints.append(ToRadians.class.toString(), "", ToRadians.class);
239
        extensionPoints.append(ToString.class.toString(), "", ToString.class);
240
        extensionPoints.append(ToUpperCase.class.toString(), "", ToUpperCase.class);
241
        extensionPoints.append(Trim.class.toString(), "", Trim.class);
242
    }
243

  
244
    private void registerIcons() {
245
        IconThemeHelper.registerIcon("action", "table-expression-field", this);
246
        IconThemeHelper.registerIcon("preferences", "expression-field-preferences", this);
247
    }
248

  
249
    private class EvalOperatorsTask extends AbstractMonitorableTask {
250

  
251
        private ExtensionPoint extensionPoint;
252

  
253
        public EvalOperatorsTask() {
254
            setInitialStep(0);
255
            setDeterminatedProcess(true);
256
            setStatusMessage(PluginServices.getText(this, "charging_operators") + "...");
257
            this.extensionPoint = ToolsLocator.getExtensionPointManager().get(
258
                    "ColumnOperators");
259
            setFinalStep(extensionPoint.getCount() + 1);
260
        }
261

  
262
        public void run() throws Exception {
263
            NotificationManager.addInfo(PluginServices.getText(this, "charging_operators"));
264
            long t1 = System.currentTimeMillis();
265
            Iterator iterator = extensionPoint.iterator();
266
            while ( iterator.hasNext() ) {
267
                try {
268
                    if ( isCanceled() ) {
269
                        return;
270
                    }
271
                    org.gvsig.tools.extensionpoint.ExtensionPoint.Extension obj = (org.gvsig.tools.extensionpoint.ExtensionPoint.Extension) iterator.next();
272
                    IOperator operator = (IOperator) extensionPoint.create(obj.getName());
273

  
274
                    operator.eval(interpreter);
275
                    operators.add(operator);
276
                    reportStep();
277
                    setNote(operator.getClass().getName());
278
                } catch (InstantiationException e) {
279
                    e.printStackTrace();
280
                } catch (IllegalAccessException e) {
281
                    e.printStackTrace();
282
                } catch (ClassCastException e) {
283
                    e.printStackTrace();
284
                }
285
            }
286
            long t2 = System.currentTimeMillis();
287
            System.out.println("Tiempo en evaluar y crear del extension point = " + (t2 - t1));
288
            long t3 = System.currentTimeMillis();
289
            System.out.println("Tiempo en a?adir los operadores correctos = " + (t3 - t2));
290
            reportStep();
291
        }
292

  
293
        public void finished() {
294
            if ( isCanceled() ) {
295
                return;
296
            }
297
            NotificationManager.addInfo(PluginServices.getText(this, "charged_operators"));
298
            EvalExpressionDialog eed = new EvalExpressionDialog(table, interpreter, operators);
299
            PluginServices.getMDIManager().addWindow(eed);
300
        }
301

  
302
    }
303
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/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.4/src/main/java/org/gvsig/expressionfield/project/documents/table/GraphicOperator.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 java.awt.geom.PathIterator;
29
import java.util.ArrayList;
30

  
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public abstract class GraphicOperator extends AbstractOperator{
40
	private FLyrVect lv=null;
41
	private static GeometryManager geomManager = GeometryLocator.getGeometryManager();
42
	
43
	public void setLayer(FLyrVect lv) {
44
		this.lv=lv;
45
	}
46
	public FLyrVect getLayer() {
47
		return lv;
48
	}
49
	public abstract double process(org.gvsig.fmap.dal.feature.Feature feature);
50
	protected ArrayList getXY(Geometry geometry) {
51
        ArrayList xs = new ArrayList();
52
        ArrayList ys = new ArrayList();
53
        ArrayList parts=new ArrayList();
54
        double[] theData = new double[6];
55

  
56
        //double[] aux = new double[6];
57
        PathIterator theIterator;
58
        int theType;
59
        int numParts = 0;
60
        theIterator = geometry.getPathIterator(null, geomManager.getFlatness()); //, flatness);
61
        boolean isClosed = false;
62
        while (!theIterator.isDone()) {
63
            theType = theIterator.currentSegment(theData);
64

  
65
            switch (theType) {
66
            case PathIterator.SEG_MOVETO:
67
            		if (numParts==0){
68
            			xs.add(new Double(theData[0]));
69
            			ys.add(new Double(theData[1]));
70
            		}else{
71
            			if (!isClosed){
72
            				Double[] x = (Double[]) xs.toArray(new Double[0]);
73
            				Double[] y = (Double[]) ys.toArray(new Double[0]);
74
            				parts.add(new Double[][] { x, y });
75
            				xs.clear();
76
            				ys.clear();
77
            			}
78
            			xs.add(new Double(theData[0]));
79
            			ys.add(new Double(theData[1]));
80
            		}
81
                numParts++;
82
                isClosed = false;
83
                break;
84
            case PathIterator.SEG_LINETO:
85
            	isClosed=false;
86
                xs.add(new Double(theData[0]));
87
                ys.add(new Double(theData[1]));
88
                break;
89
            case PathIterator.SEG_CLOSE:
90
            	isClosed=true;
91
                xs.add(new Double(theData[0]));
92
                ys.add(new Double(theData[1]));
93
                Double[] x = (Double[]) xs.toArray(new Double[0]);
94
                Double[] y = (Double[]) ys.toArray(new Double[0]);
95
                parts.add(new Double[][] { x, y });
96
                xs.clear();
97
                ys.clear();
98
                break;
99
            } //end switch
100

  
101
            theIterator.next();
102
        } //end while loop
103

  
104
        if (!isClosed){
105
        	isClosed=true;
106
        	xs.add(new Double(theData[0]));
107
            ys.add(new Double(theData[1]));
108
            Double[] x = (Double[]) xs.toArray(new Double[0]);
109
            Double[] y = (Double[]) ys.toArray(new Double[0]);
110
            parts.add(new Double[][] { x, y });
111
            xs.clear();
112
            ys.clear();
113
        }
114
        return parts;
115

  
116
    }
117

  
118
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Pow.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.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public class Pow extends AbstractOperator{
40

  
41
	public String addText(String s) {
42
		return toString()+"("+s+", )";
43
	}
44

  
45
	public void eval(BSFManager interpreter) throws BSFException {
46
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double pow(double value1,double value2){return java.lang.Math.pow(value1,value2);};");
47
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def pow(value1, value2):\n" +
48
				"  import java.lang.Math\n" +
49
				"  return java.lang.Math.pow(value1,value2)");
50
	}
51
	public String toString() {
52
		return "pow";
53
	}
54
	public boolean isEnable() {
55
		return (getType()==IOperator.NUMBER);
56
	}
57
	public String getTooltip(){
58
		return PluginServices.getText(this,"operator")+":  "+ toString()+ "(" +PluginServices.getText(this,"parameter")+"1,"+PluginServices.getText(this,"parameter")+"2"+")\n"+getDescription();
59
	}
60
	public String getDescription() {
61
        return PluginServices.getText(this, "parameter") + "1"+": " +
62
        PluginServices.getText(this, "numeric_value") + "\n"+
63
        PluginServices.getText(this, "parameter") + "2"+": " +
64
        PluginServices.getText(this, "numeric_value") + "\n"+
65
        PluginServices.getText(this, "returns") + ": " +
66
        PluginServices.getText(this, "numeric_value") + "\n" +
67
        PluginServices.getText(this, "description") + ": " +
68
        "Returns the value of the first argument raised to the power of the second argument. Special cases:\n" +
69
        "* If the second argument is positive or negative zero, then the result is 1.0.\n" +
70
        "* If the second argument is 1.0, then the result is the same as the first argument.\n" +
71
        "* If the second argument is NaN, then the result is NaN.\n" +
72
        "* If the first argument is NaN and the second argument is nonzero, then the result is NaN.\n" +
73
        "* If\n" +
74
        "   - the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or\n" +
75
        "   - the absolute value of the first argument is less than 1 and the second argument is negative infinity,\n" +
76
        "then the result is positive infinity.\n" +
77
        "* If\n" +
78
        "   - the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or\n" +
79
        "   - the absolute value of the first argument is less than 1 and the second argument is positive infinity,\n" +
80
        "then the result is positive zero.\n" +
81
        "* If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN.\n" +
82
        "* If\n" +
83
        "   - the first argument is positive zero and the second argument is greater than zero, or\n" +
84
        "   - the first argument is positive infinity and the second argument is less than zero,\n" +
85
        "then the result is positive zero.\n" +
86
        "* If\n" +
87
        "   - the first argument is positive zero and the second argument is less than zero, or\n" +
88
        "   - the first argument is positive infinity and the second argument is greater than zero,\n" +
89
        "then the result is positive infinity.\n" +
90
        "* If\n" +
91
        "   - the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or\n" +
92
        "   - the first argument is negative infinity and the second argument is less than zero but not a finite odd integer,\n" +
93
        "then the result is positive zero.\n" +
94
        "* If\n" +
95
        "   - the first argument is negative zero and the second argument is a positive finite odd integer, or\n" +
96
        "   - the first argument is negative infinity and the second argument is a negative finite odd integer,\n" +
97
        "then the result is negative zero.\n" +
98
        "* If\n" +
99
        "   - the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or\n" +
100
        "   - the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer,\n" +
101
        "then the result is positive infinity.\n" +
102
        "* If\n" +
103
        "   - the first argument is negative zero and the second argument is a negative finite odd integer, or\n" +
104
        "   - the first argument is negative infinity and the second argument is a positive finite odd integer,\n" +
105
        "then the result is negative infinity.\n" +
106
        "* If the first argument is finite and less than zero\n" +
107
        "   - if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument\n" +
108
        "   - if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument\n" +
109
        "   - if the second argument is finite and not an integer, then the result is NaN.\n" +
110
        "* If both arguments are integers, then the result is exactly equal to the mathematical result of raising the first argument to the power of the second argument if that result can in fact be represented exactly as a double value.";
111
    }
112
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Abs.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.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35

  
36

  
37
/**
38
 *
39
 * @author Vicente Caballero Navarro
40
 */
41
public class Abs extends AbstractOperator {
42
    public String addText(String s) {
43
        return toString() + "(" + s + ")";
44
    }
45

  
46
    public String toString() {
47
        return "abs";
48
    }
49

  
50
    public void eval(BSFManager interpreter) throws BSFException {
51
        interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1,
52
            "def abs(value):\n" +
53
            "  import java.lang.Math\n"+
54
            "  return java.lang.Math.abs(value)\n");
55
    }
56

  
57
    public boolean isEnable() {
58
        return (getType() == IOperator.NUMBER);
59
    }
60

  
61
    public double abs(double value) {
62
        return java.lang.Math.abs(value);
63
    }
64

  
65
    public String getDescription() {
66
        return PluginServices.getText(this, "parameter") + ": " +
67
        PluginServices.getText(this, "numeric_value") + "\n" +
68
        PluginServices.getText(this, "returns") + ": " +
69
        PluginServices.getText(this, "numeric_value") + "\n" +
70
        PluginServices.getText(this, "description") + ": " +
71
        "Returns the absolute value of a double value. If the argument is not negative, the argument is returned. " +
72
        "If the argument is negative, the negation of the argument is returned.\n " +
73
        "Special cases:\n" +
74
        "* If the argument is positive zero or negative zero, the result is positive zero.\n" +
75
        "* If the argument is infinite, the result is positive infinity.\n" +
76
        "* If the argument is NaN, the result is NaN.";
77
    }
78
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/RecordIndex.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.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.FeatureIndex;
34

  
35
/**
36
 * This operator returns the 0-based feature index
37
 * by using the Jython bean 'featureIndex' previously declared 
38
 * @author jldominguez
39
 *
40
 */
41
public class RecordIndex extends AbstractOperator {
42

  
43
	public String addText(String s) {
44
		return toString()+"()";
45
	}
46

  
47
	public long process(FeatureIndex featIndex) {
48
		
49
		if (featIndex == null) {
50
			return -1;
51
		} else {
52
			return featIndex.get();
53
		}
54
		
55
	}
56
	
57
	public void eval(BSFManager interpreter) throws BSFException {
58
		interpreter.declareBean("jrec",this,RecordIndex.class);
59
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def rec():\n" +
60
				"  return jrec.process(featureIndex)");
61
	}
62

  
63
	public boolean isEnable() {
64
		return true;
65
	}
66

  
67
	public String toString() {
68
		return "rec";
69
	}
70

  
71
	public String getDescription() {
72
        return PluginServices.getText(this, "returns") + ": " +
73
        PluginServices.getText(this, "numeric_value") + "\n" +
74
        PluginServices.getText(this, "description") + ": " +
75
        "The 0-based index of the current record (row or feature).";
76
	}
77

  
78
}
79

  
80

  
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/AbstractField.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.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.expressionfield.ExpressionFieldExtension;
31
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
32
import org.gvsig.fmap.dal.feature.Feature;
33

  
34

  
35
public abstract class AbstractField extends AbstractOperator{
36
	private boolean isEval=false;
37
	public Object getValue(Feature feature, String nameField){
38
		if (feature != null)
39
			return feature.get(nameField);
40
		return null;
41
	}
42
//	public Object getValue(String nameField,Index indexRow,SelectableDataSource sds) {
43
//		try {
44
//			int index=sds.getFieldIndexByName(nameField);
45
//			Value value=sds.getFieldValue(indexRow.get(),index);
46
//			if (value instanceof NumericValue) {
47
//				double dv=((NumericValue)value).doubleValue();
48
//				return new Double(dv);
49
//			}else if (value instanceof DateValue) {
50
//				Date date=((DateValue)value).getValue();
51
//				return date;
52
//			}else if (value instanceof BooleanValue){
53
//				boolean b=((BooleanValue)value).getValue();
54
//				return new Boolean(b);
55
//			}else {
56
//				return value.toString();
57
//			}
58
//		} catch (ReadDriverException e) {
59
//			throw new RuntimeException(e.getMessage());
60
//		}
61
//	}
62
	public void eval(BSFManager interpreter) throws BSFException {
63
		if (!isEval){
64
		interpreter.declareBean("jfield",this,Field.class);
65
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def field(nameField):\n" +
66
				"  return jfield.getValue(featureContainer.getFeature(), nameField)");
67
		isEval=true;
68
		}
69
	}
70
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/SetTimeDate.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.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public class SetTimeDate extends AbstractOperator{
40

  
41
	public String addText(String s) {
42
		return toString()+"("+s+")";
43
	}
44
	public String toString() {
45
		return "setTimeDate";
46
	}
47
	public void eval(BSFManager interpreter) throws BSFException {
48
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"java.util.Date setTimeDate(java.lang.Object value1,double value2){value1.setTime((long)value2);return value1;};");
49
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,
50
				"import java.util.Date as jDate\n"+
51
				"def setTimeDate(value):\n"+
52
				"  aux = jDate()\n"+
53
				"  aux.setTime(long(value))\n"+
54
				"  return aux");
55
	}
56
	public boolean isEnable() {
57
		return (getType()==IOperator.DATE);
58
	}
59

  
60
	public String getDescription() {
61
	       return PluginServices.getText(this, "parameter") + ": " +
62
	        PluginServices.getText(this, "numeric_value") + "\n"+
63
	        PluginServices.getText(this, "returns") + ": " +
64
	        PluginServices.getText(this, "date_value") + "\n" +
65
	        PluginServices.getText(this, "description") + ": " +
66
	        "Returns a date object to represent a point in time that is 'parameter' milliseconds after January 1, 1970 00:00:00 GMT.";
67
    }
68
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Trim.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.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public class Trim extends AbstractOperator{
40

  
41
	public String addText(String s) {
42
		return toString()+"("+s+")";
43
	}
44
	public String toString() {
45
		return "trim";
46
	}
47
	public void eval(BSFManager interpreter) throws BSFException {
48
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"String trim(String value){return value.trim();};");
49
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def trim(value):\n" +
50
				"  return value.strip()");
51
	}
52
	public boolean isEnable() {
53
		return (getType()==IOperator.STRING);
54
	}
55
	public String getDescription() {
56
	    return PluginServices.getText(this, "parameter") + ": " +
57
	    PluginServices.getText(this, "string_value") + "\n" +
58
	    PluginServices.getText(this, "returns") + ": " +
59
	    PluginServices.getText(this, "string_value") + "\n" +
60
	    PluginServices.getText(this, "description") + ": " +
61
	    "Returns a copy of the string, with leading and trailing whitespace omitted.";
62
	}
63
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/FieldCopy.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.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.expressionfield.ExpressionFieldExtension;
31
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
32
import org.gvsig.fmap.dal.feature.Feature;
33
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
34

  
35
/**
36
 * @author Vicente Caballero Navarro
37
 */
38
public class FieldCopy extends AbstractOperator{
39
	private FeatureAttributeDescriptor fd;
40
	public FieldCopy() {
41
	}
42
	public void setFieldDescription(FeatureAttributeDescriptor fd) {
43
		this.fd=fd;
44
	}
45
	public String addText(String s) {
46
		return s.concat(toString());
47
	}
48

  
49
	public void eval(BSFManager interpreter) throws BSFException {
50
		interpreter.declareBean(fd.getName(),this,FieldCopy.class);
51
		interpreter.eval(ExpressionFieldExtension.JYTHON,null,-1,-1,"java.lang.Object "+ fd.getName()+ "(){return "+fd.getName()+".getValue(feature);};");
52
	}
53
	public Object getValue(Feature feature){
54
		return feature.get(fd.getName());
55
	}
56
//	public Object getValue(Index indexRow,FeatureStore sds) {
57
//		try {
58
//			int index=sds.getFieldIndexByName(fd.getName());
59
//			Value value=sds.getFieldValue(indexRow.get(),index);
60
//			if (value instanceof NumericValue) {
61
//				double dv=((NumericValue)value).doubleValue();
62
//				return new Double(dv);
63
//			}else if (value instanceof DateValue) {
64
//				Date date=((DateValue)value).getValue();
65
//				return date;
66
//			}else if (value instanceof BooleanValue){
67
//				boolean b=((BooleanValue)value).getValue();
68
//				return new Boolean(b);
69
//			}else {
70
//				return value.toString();
71
//			}
72
//		} catch (ReadDriverException e) {
73
//			throw new RuntimeException(e.getMessage());
74
//		}
75
//	}
76
	public String toString() {
77
		return "["+fd.getName()+"]";
78
	}
79
	public boolean isEnable() {
80
		return true;
81
	}
82
	public String getDescription() {
83
		// TODO Auto-generated method stub
84
		return null;
85
	}
86
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/PointX.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.operators;
27

  
28
import java.util.ArrayList;
29

  
30
import org.apache.bsf.BSFException;
31
import org.apache.bsf.BSFManager;
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.andami.messages.NotificationManager;
34
import org.gvsig.expressionfield.ExpressionFieldExtension;
35
import org.gvsig.expressionfield.project.documents.table.GraphicOperator;
36
import org.gvsig.expressionfield.project.documents.table.IOperator;
37
import org.gvsig.fmap.dal.exception.DataException;
38
import org.gvsig.fmap.dal.feature.Feature;
39
import org.gvsig.fmap.dal.feature.FeatureStore;
40

  
41
/**
42
 * @author Vicente Caballero Navarro
43
 */
44
public class PointX extends GraphicOperator{
45

  
46
	public String addText(String s) {
47
		return s.concat(toString()+"()");
48
	}
49
	public double process(Feature feature){
50
//		ReadableVectorial adapter = getLayer().getSource();
51
		org.gvsig.fmap.geom.Geometry geom=null;
52
//		try {
53
			geom = feature.getDefaultGeometry();//adapter.getShape(index.get());
54
//		} catch (ExpansionFileReadException e) {
55
//			throw new DriverIOException(e);
56
//		} catch (ReadDriverException e) {
57
//			throw new DriverIOException(e);
58
//		}
59
		ArrayList parts=getXY(geom);
60
		Double[][] xsys=(Double[][])parts.get(0);//getXY(geom);
61
		return xsys[0][0].doubleValue();
62
	}
63
	public void eval(BSFManager interpreter) throws BSFException {
64
		interpreter.declareBean("pointX",this,PointX.class);
65
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double x(){return pointX.process(indexRow);};");
66
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def x():\n" +
67
				"  return pointX.process(featureContainer.getFeature())");
68
	}
69
	public String toString() {
70
		return "x";
71
	}
72
	public boolean isEnable() {
73
		if (getLayer()==null)
74
			return false;
75
		int geomType=org.gvsig.fmap.geom.Geometry.TYPES.POINT;
76
		try {
77
			FeatureStore store = getLayer().getFeatureStore();
78
			geomType = store.getDefaultFeatureType().getAttributeDescriptor(store.getDefaultFeatureType().getDefaultGeometryAttributeIndex()).getGeometryType();
79
		} catch (DataException e) {
80
			NotificationManager.addError(e);
81
		}
82
		return (getType()==IOperator.NUMBER && geomType==org.gvsig.fmap.geom.Geometry.TYPES.POINT);
83
	}
84
	public String getTooltip(){
85
		return PluginServices.getText(this,"operator")+":  "+addText("")+"\n"+getDescription();
86
	}
87
	public String getDescription() {
88
        return PluginServices.getText(this, "returns") + ": " +
89
        PluginServices.getText(this, "numeric_value") + "\n" +
90
        PluginServices.getText(this, "description") + ": " +
91
        "Returns the X coordenate of point geometry of this row.";
92
    }
93
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Floor.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.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public class Floor extends AbstractOperator{
40

  
41
	public String addText(String s) {
42
		return toString()+"("+s+")";
43
	}
44
	public String toString() {
45
		return "floor";
46
	}
47
	public void eval(BSFManager interpreter) throws BSFException {
48
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def floor(value):\n" +
49
				"  import java.lang.Math\n" +
50
				"  return java.lang.Math.floor(value)");
51
	}
52
	public boolean isEnable() {
53
		return (getType()==IOperator.NUMBER);
54
	}
55
	public String getDescription() {
56
        return PluginServices.getText(this, "parameter") + ": " +
57
        PluginServices.getText(this, "numeric_value") + "\n" +
58
        PluginServices.getText(this, "returns") + ": " +
59
        PluginServices.getText(this, "numeric_value") + "\n" +
60
        PluginServices.getText(this, "description") + ": " +
61
        "Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer. Special cases:\n" +
62
        "* If the argument value is already equal to a mathematical integer, then the result is the same as the argument.\n" +
63
        "* If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.\n";
64
    }
65

  
66
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.4/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/ToDegrees.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
 *******************************************************************************/
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff