Revision 41
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.3/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.3/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 |
</includes> |
|
59 |
</dependencySet> |
|
60 |
</dependencySets> |
|
61 |
|
|
62 |
</assembly> |
|
63 |
|
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.3/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.3/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.3/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.3/src/main/java/org/gvsig/expressionfield/project/documents/table/AbstractOperator.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.gvsig.andami.PluginServices; |
|
29 |
|
|
30 |
/** |
|
31 |
* @author Vicente Caballero Navarro |
|
32 |
*/ |
|
33 |
public abstract class AbstractOperator implements IOperator{ |
|
34 |
private int type; |
|
35 |
|
|
36 |
public void setType(int type) { |
|
37 |
this.type=type; |
|
38 |
} |
|
39 |
public int getType() { |
|
40 |
return type; |
|
41 |
} |
|
42 |
public abstract String toString(); |
|
43 |
|
|
44 |
public String getTooltip(){ |
|
45 |
return PluginServices.getText(this,"operator")+": "+addText(PluginServices.getText(this,"parameter"))+"\n"+getDescription(); |
|
46 |
} |
|
47 |
public abstract String getDescription(); |
|
48 |
} |
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.3/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.3/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.3/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.3/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 |
|
|
91 |
public class EvalExpressionDialog extends JPanel implements IWindow { |
|
92 |
|
|
93 |
private static Logger logger = LoggerFactory.getLogger(EvalExpressionDialog.class); |
|
94 |
private static Preferences prefs = Preferences.userRoot().node("fieldExpressionOptions"); |
|
95 |
|
|
96 |
private JPanel pNorth = null; |
|
97 |
private JPanel pCentral = null; |
|
98 |
private JScrollPane jScrollPane = null; |
|
99 |
private JTextArea txtExp = null; |
|
100 |
private AcceptCancelPanel acceptCancel; |
|
101 |
private FeatureTableDocumentPanel table; |
|
102 |
private FLyrVect lv; |
|
103 |
private JPanel pNorthEast = null; |
|
104 |
private JPanel pNorthCenter = null; |
|
105 |
private JPanel pNorthWest = null; |
|
106 |
private JScrollPane jScrollPane1 = null; |
|
107 |
private JList listFields = null; |
|
108 |
private JRadioButton rbNumber = null; |
|
109 |
private JRadioButton rbString = null; |
|
110 |
private JRadioButton rbDate = null; |
|
111 |
private JScrollPane jScrollPane2 = null; |
|
112 |
private JList listCommand = null; |
|
113 |
private BSFManager interpreter = null; // Construct an interpreter |
|
114 |
private Feature feature; |
|
115 |
private FeatureStore featureStore = null; |
|
116 |
private EvalExpression evalExpression = null; |
|
117 |
/* |
|
118 |
* Keeps index of row in feature set currently used. |
|
119 |
*/ |
|
120 |
private FeatureIndex fIndex = new FeatureIndex(); |
|
121 |
|
|
122 |
private JPanel pMessage; |
|
123 |
private FeatureContainer featureContainer; |
|
124 |
private static ArrayList<IOperator> operators = new ArrayList<IOperator>(); |
|
125 |
|
|
126 |
public EvalExpressionDialog(FeatureTableDocumentPanel table, BSFManager interpreter, ArrayList<IOperator> operators) { |
|
127 |
super(); |
|
128 |
this.operators = operators; |
|
129 |
this.interpreter = interpreter; |
|
130 |
this.table = table; |
|
131 |
initialize(); |
|
132 |
|
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* This method initializes this |
|
137 |
*/ |
|
138 |
private void initialize() { |
|
139 |
try { |
|
140 |
evalExpressions(); |
|
141 |
} catch (BSFException e) { |
|
142 |
NotificationManager.addError(e); |
|
143 |
} |
|
144 |
evalExpression = new EvalExpression(); |
|
145 |
evalExpression.setTable(table); |
|
146 |
/* |
|
147 |
* Keeps index of row in feature set currently used |
|
148 |
*/ |
|
149 |
try { |
|
150 |
interpreter.declareBean("featureIndex", fIndex, FeatureIndex.class); |
|
151 |
} catch (BSFException e) { |
|
152 |
logger.error("While declaring featureIndex (Long).", e); |
|
153 |
} |
|
154 |
|
|
155 |
lv = (FLyrVect) table.getModel().getAssociatedLayer(); |
|
156 |
ButtonGroup bg = new ButtonGroup(); |
|
157 |
bg.add(getRbNumber()); |
|
158 |
bg.add(getRbString()); |
|
159 |
bg.add(getRbDate()); |
|
160 |
this.setLayout(new GridBagLayout()); |
|
161 |
this.setSize(549, 480); |
|
162 |
GridBagConstraints constr = new GridBagConstraints(); |
|
163 |
constr.gridwidth = GridBagConstraints.REMAINDER; |
|
164 |
constr.gridheight = 1; |
|
165 |
constr.fill = GridBagConstraints.BOTH; |
|
166 |
constr.ipadx = 5; |
|
167 |
constr.ipady = 5; |
|
168 |
constr.weightx = 1; |
|
169 |
constr.weighty = 0.3; |
|
170 |
this.add(getPMessage(), constr); |
|
171 |
constr.gridheight = 5; |
|
172 |
constr.weighty = 1; |
|
173 |
this.add(getTabPrincipal(), constr); |
|
174 |
GridBagConstraints constr2 = new GridBagConstraints(); |
|
175 |
constr2.gridwidth = GridBagConstraints.REMAINDER; |
|
176 |
constr2.gridheight = 1; |
|
177 |
constr2.fill = GridBagConstraints.HORIZONTAL; |
|
178 |
constr2.anchor = GridBagConstraints.LAST_LINE_END; |
|
179 |
constr2.weightx = 1; |
|
180 |
constr2.weighty = 0; |
|
181 |
|
|
182 |
this.add(getAcceptCancel(), constr2); |
|
183 |
|
|
184 |
} |
|
185 |
|
|
186 |
/** |
|
187 |
* This method initializes pCentral |
|
188 |
* |
|
189 |
* @return javax.swing.JPanel |
|
190 |
*/ |
|
191 |
private JPanel getPNorth() { |
|
192 |
if ( pNorth == null ) { |
|
193 |
pNorth = new JPanel(); |
|
194 |
pNorth.setLayout(new GridBagLayout()); |
|
195 |
GridBagConstraints contr = new GridBagConstraints(); |
|
196 |
contr.ipadx = 5; |
|
197 |
contr.ipady = 5; |
|
198 |
contr.fill = GridBagConstraints.BOTH; |
|
199 |
contr.weightx = 1; |
|
200 |
contr.weighty = 1; |
|
201 |
pNorth.add(getPNorthWest(), contr); |
|
202 |
|
|
203 |
contr.fill = GridBagConstraints.VERTICAL; |
|
204 |
contr.weightx = 0; |
|
205 |
contr.weighty = 1; |
|
206 |
|
|
207 |
pNorth.add(getPNorthCenter(), contr); |
|
208 |
|
|
209 |
contr.fill = GridBagConstraints.BOTH; |
|
210 |
contr.weightx = 0.5; |
|
211 |
contr.weighty = 1; |
|
212 |
|
|
213 |
pNorth.add(getPNorthEast(), contr); |
|
214 |
} |
|
215 |
|
|
216 |
return pNorth; |
|
217 |
} |
|
218 |
|
|
219 |
/** |
|
220 |
* This method initializes pNorth |
|
221 |
* |
|
222 |
* @return javax.swing.JPanel |
|
223 |
*/ |
|
224 |
private JPanel getPCentral() { |
|
225 |
if ( pCentral == null ) { |
|
226 |
StringBuilder tit = new StringBuilder(); |
|
227 |
tit.append(PluginServices.getText(this, "expression")); |
|
228 |
tit.append(" "); |
|
229 |
tit.append(PluginServices.getText(this, "column")); |
|
230 |
tit.append(" : "); |
|
231 |
tit.append(evalExpression.getFieldDescriptorSelected().getName()); |
|
232 |
pCentral = new JPanel(); |
|
233 |
pCentral.setLayout(new GridBagLayout()); |
|
234 |
pCentral.setBorder(javax.swing.BorderFactory.createTitledBorder( |
|
235 |
null, tit.toString(), |
|
236 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
237 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
238 |
GridBagConstraints contr = new GridBagConstraints(); |
|
239 |
contr.gridwidth = GridBagConstraints.REMAINDER; |
|
240 |
contr.gridheight = 1; |
|
241 |
contr.fill = GridBagConstraints.BOTH; |
|
242 |
contr.ipadx = 5; |
|
243 |
contr.ipady = 5; |
|
244 |
contr.weightx = 1; |
|
245 |
contr.weighty = 1; |
|
246 |
pCentral.add(getJScrollPane(), contr); |
|
247 |
GridBagConstraints contr1 = new GridBagConstraints(); |
|
248 |
contr1.gridwidth = 1; |
|
249 |
contr1.gridheight = 1; |
|
250 |
contr1.fill = GridBagConstraints.NONE; |
|
251 |
contr1.ipadx = 5; |
|
252 |
contr1.ipady = 5; |
|
253 |
contr1.anchor = GridBagConstraints.CENTER; |
|
254 |
pCentral.add(getBClear(), contr1); |
|
255 |
} |
|
256 |
|
|
257 |
return pCentral; |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* This method initializes pSouth |
|
262 |
* |
|
263 |
* @return javax.swing.JPanel |
|
264 |
*/ |
|
265 |
private AcceptCancelPanel getAcceptCancel() { |
|
266 |
if ( this.acceptCancel == null ) { |
|
267 |
this.acceptCancel = new AcceptCancelPanel( |
|
268 |
new java.awt.event.ActionListener() { |
|
269 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
270 |
boolean isAccepted = true; |
|
271 |
Preferences prefs = Preferences.userRoot().node( |
|
272 |
"fieldExpressionOptions"); |
|
273 |
int limit; |
|
274 |
limit = prefs.getInt("limit_rows_in_memory", -1); |
|
275 |
if ( limit != -1 ) { |
|
276 |
int option = JOptionPane |
|
277 |
.showConfirmDialog( |
|
278 |
(Component) PluginServices |
|
279 |
.getMainFrame(), |
|
280 |
PluginServices |
|
281 |
.getText( |
|
282 |
this, |
|
283 |
"it_has_established_a_limit_of_rows_will_lose_the_possibility_to_undo_wants_to_continue")); |
|
284 |
if ( option != JOptionPane.OK_OPTION ) { |
|
285 |
return; |
|
286 |
} |
|
287 |
} |
|
288 |
try { |
|
289 |
long t1 = System.currentTimeMillis(); |
|
290 |
isAccepted = evalExpression(); |
|
291 |
long t2 = System.currentTimeMillis(); |
|
292 |
System.out |
|
293 |
.println("Tiempo evaluar expresiones = " |
|
294 |
+ (t2 - t1)); |
|
295 |
} catch (BSFException e1) { |
|
296 |
NotificationManager.addError(e1); |
|
297 |
} |
|
298 |
if ( isAccepted ) { |
|
299 |
PluginServices.getMDIManager().closeWindow( |
|
300 |
EvalExpressionDialog.this); |
|
301 |
} |
|
302 |
} |
|
303 |
}, new java.awt.event.ActionListener() { |
|
304 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
305 |
PluginServices.getMDIManager().closeWindow( |
|
306 |
EvalExpressionDialog.this); |
|
307 |
} |
|
308 |
}); |
|
309 |
acceptCancel.setOkButtonEnabled(false); |
|
310 |
} |
|
311 |
|
|
312 |
return this.acceptCancel; |
|
313 |
} |
|
314 |
|
|
315 |
private String replaceFields(String expression) { |
|
316 |
// String s = expression.replaceAll("\\[","field(\"").replaceAll("\\]","\")"); |
|
317 |
String s = expression; |
|
318 |
|
|
319 |
JList list = getListFields(); |
|
320 |
ListOperatorsModel model = (ListOperatorsModel) list.getModel(); |
|
321 |
for ( int i = 0; i < model.getSize(); i++ ) { |
|
322 |
Field f = (Field) model.getElementAt(i); |
|
323 |
s = s.replaceAll(f.toString(), "field(\"" + f.getName() + "\")"); |
|
324 |
} |
|
325 |
return s; |
|
326 |
} |
|
327 |
|
|
328 |
/** |
|
329 |
* Evaluate the expression. |
|
330 |
* |
|
331 |
* @throws BSFException |
|
332 |
*/ |
|
333 |
private boolean evalExpression() throws BSFException { |
|
334 |
|
|
335 |
String expression = getTxtExp().getText(); |
|
336 |
byte[] expressionBytes; |
|
337 |
String encoding = System.getProperty("file.encoding"); |
|
338 |
try { |
|
339 |
expressionBytes = expression.getBytes(encoding); |
|
340 |
expression = new String(expressionBytes, "ISO-8859-1"); |
|
341 |
} catch (UnsupportedEncodingException e) { |
|
342 |
logger.warn("Can't apply enconding ("+encoding+").",e); |
|
343 |
} |
|
344 |
|
|
345 |
// expression = expression.replaceAll("\\[", "field(\"").replaceAll("\\]", "\")"); |
|
346 |
expression = replaceFields(expression); |
|
347 |
|
|
348 |
interpreter.declareBean("evalExpression", evalExpression, EvalExpression.class); |
|
349 |
interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def expression():\n" |
|
350 |
+ " return " + expression + ""); |
|
351 |
|
|
352 |
try { |
|
353 |
interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def isCorrect():\n" |
|
354 |
+ " evalExpression.isCorrectValue(expression())\n"); |
|
355 |
interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "isCorrect()"); |
|
356 |
} catch (BSFException ee) { |
|
357 |
String message = ee.getMessage(); |
|
358 |
if ( message.length() > 200 ) { |
|
359 |
message = message.substring(0, 200); |
|
360 |
} |
|
361 |
int option = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), |
|
362 |
PluginServices.getText(this, |
|
363 |
"error_expression") + "\n" + message + "\n" + PluginServices.getText(this, "continue?")); |
|
364 |
if ( option != JOptionPane.OK_OPTION ) { |
|
365 |
return false; |
|
366 |
} |
|
367 |
} |
|
368 |
try { |
|
369 |
boolean select = true; |
|
370 |
interpreter.declareBean("select", select, boolean.class); |
|
371 |
if ( featureStore.isEditing() ) { |
|
372 |
evalInEditing(); |
|
373 |
} else { |
|
374 |
evalOutEditing(); |
|
375 |
} |
|
376 |
} catch (DataException e) { |
|
377 |
logger.warn("Can't evaluate expresion ("+expression+").",e); |
|
378 |
} |
|
379 |
|
|
380 |
return true; |
|
381 |
} |
|
382 |
|
|
383 |
private void evalInEditing() throws BSFException, DataException { |
|
384 |
int limit = prefs.getInt("limit_rows_in_memory", -1); |
|
385 |
ArrayList exceptions = new ArrayList(); |
|
386 |
interpreter.declareBean("exceptions", exceptions, ArrayList.class); |
|
387 |
boolean emptySelection = ((FeatureSelection) featureStore.getSelection()).isEmpty(); |
|
388 |
|
|
389 |
FeatureSet set = null; |
|
390 |
DisposableIterator iterator = null; |
|
391 |
|
|
392 |
try { |
|
393 |
set = featureStore.getFeatureSet(table.getModel().getQuery()); |
|
394 |
iterator = set.fastIterator(); |
|
395 |
|
|
396 |
interpreter.declareBean("featureSet", set, FeatureSet.class); |
|
397 |
interpreter.declareBean("iterator", iterator, Iterator.class); |
|
398 |
interpreter.declareBean("limit", limit, int.class); |
|
399 |
|
|
400 |
if ( limit == -1 ) { |
|
401 |
featureStore.beginEditingGroup(PluginServices.getText(this, "expression")); |
|
402 |
if ( !emptySelection ) { |
|
403 |
interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n" |
|
404 |
+ " \n" |
|
405 |
+ " featureIndex.set(0)\n" |
|
406 |
+ " while iterator.hasNext():\n" |
|
407 |
+ " feature=iterator.next()\n" |
|
408 |
+ " select=featureStore.getSelection().isSelected(feature)\n" |
|
409 |
+ " if select:\n" |
|
410 |
+ " featureContainer.setFeature(feature)\n" |
|
411 |
+ " obj=expression()\n" |
|
412 |
+ " evalExpression.setValue(featureSet,feature,obj)\n" |
|
413 |
+ " featureIndex.next()\n" |
|
414 |
+ " iterator.dispose()\n" |
|
415 |
+ " featureSet.dispose\n" |
|
416 |
); |
|
417 |
} else { |
|
418 |
interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n" |
|
419 |
+ " \n" |
|
420 |
+ " featureIndex.set(0)\n" |
|
421 |
+ " while iterator.hasNext():\n" |
|
422 |
+ " feature=iterator.next()\n" |
|
423 |
+ " featureContainer.setFeature(feature)\n" |
|
424 |
+ " obj=expression()\n" |
|
425 |
+ " evalExpression.setValue(featureSet,feature,obj)\n" |
|
426 |
+ " featureIndex.next()\n" |
|
427 |
+ " iterator.dispose()\n" |
|
428 |
+ " featureSet.dispose\n" |
|
429 |
); |
|
430 |
} |
|
431 |
try { |
|
432 |
interpreter.eval(ExpressionFieldExtension.JYTHON, null, -1, -1, "p()"); |
|
433 |
} catch (BSFException ee) { |
|
434 |
|
|
435 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
|
436 |
PluginServices.getText(this, "evaluate_expression_with_errors") + " " + exceptions.size() + ee.getMessage()); |
|
437 |
} |
|
438 |
featureStore.endEditingGroup(); |
|
439 |
} else { |
|
440 |
long size = set.getSize(); |
|
441 |
for ( int i = 0; i < size; i = i + limit ) { |
|
442 |
// featureStore.finishEditing(); |
|
443 |
// featureStore.edit(); |
|
444 |
featureStore.beginEditingGroup(PluginServices.getText(this, "expression")); |
|
445 |
set = featureStore.getFeatureSet(table.getModel().getQuery()); |
|
446 |
interpreter.declareBean("featureSet", set, FeatureSet.class); |
|
447 |
iterator = set.fastIterator(i); |
|
448 |
interpreter.declareBean("iterator", iterator, Iterator.class); |
|
449 |
if ( !emptySelection ) { |
|
450 |
interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n" |
|
451 |
+ " \n" |
|
452 |
+ " pos=0\n" |
|
453 |
+ " featureIndex.set(0)\n" |
|
454 |
+ " while iterator.hasNext() and pos<limit:\n" |
|
455 |
+ " feature=iterator.next()\n" |
|
456 |
+ " select=featureStore.getSelection().isSelected(feature)\n" |
|
457 |
+ " if select:\n" |
|
458 |
+ " featureContainer.setFeature(feature)\n" |
|
459 |
+ " obj=expression()\n" |
|
460 |
+ " evalExpression.setValue(featureSet,feature,obj)\n" |
|
461 |
+ " featureIndex.next()\n" |
|
462 |
+ " pos=pos+1\n" |
|
463 |
+ " iterator.dispose()\n" |
|
464 |
+ " featureSet.dispose\n" |
|
465 |
); |
|
466 |
} else { |
|
467 |
interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def p():\n" |
|
468 |
+ " \n" |
|
469 |
+ " pos=0\n" |
|
470 |
+ " featureIndex.set(0)\n" |
|
471 |
+ " while iterator.hasNext() and pos<limit:\n" |
|
472 |
+ " feature=iterator.next()\n" |
|
473 |
+ " featureContainer.setFeature(feature)\n" |
|
474 |
+ " obj=expression()\n" |
|
475 |
+ " evalExpression.setValue(featureSet,feature,obj)\n" |
|
476 |
+ " pos=pos+1\n" |
|
477 |
+ " featureIndex.next()\n" |
|
478 |
+ " iterator.dispose()\n" |
|
479 |
+ " featureSet.dispose\n" |
|
480 |
); |
|
481 |
} |
|
482 |
try { |
|
483 |
interpreter.eval(ExpressionFieldExtension.JYTHON, null, -1, -1, "p()"); |
|
484 |
} catch (BSFException ee) { |
|
485 |
|
|
486 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
|
487 |
PluginServices.getText(this, "evaluate_expression_with_errors") + " " + exceptions.size() + ee.getMessage()); |
|
488 |
} |
|
489 |
|
|
490 |
featureStore.endEditingGroup(); |
|
491 |
featureStore.finishEditing(); |
|
492 |
featureStore.edit(); |
|
493 |
} |
|
494 |
} |
|
495 |
} finally { |
|
496 |
DisposeUtils.dispose(set); |
|
497 |
DisposeUtils.dispose(iterator); |
|
498 |
} |
|
499 |
|
|
500 |
} |
|
501 |
|
|
502 |
private void evalOutEditing() throws BSFException, DataException { |
|
503 |
|
|
504 |
} |
|
505 |
|
|
506 |
/** |
|
507 |
* This method initializes pMessage |
|
508 |
* |
|
509 |
* @return javax.swing.JPanel |
|
510 |
*/ |
|
511 |
private JPanel getPMessage() { |
|
512 |
if ( pMessage == null ) { |
|
513 |
|
|
514 |
pMessage = new JPanel(); |
|
515 |
pMessage.setLayout(new GridLayout()); |
|
516 |
pMessage.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "information"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
517 |
pMessage.add(getJScrollPane3(), null); |
|
518 |
} |
|
519 |
return pMessage; |
|
520 |
} |
|
521 |
|
|
522 |
private void evalExpressions() throws BSFException { |
|
523 |
featureStore = table.getModel().getStore(); |
|
524 |
interpreter.declareBean("featureStore", featureStore, FeatureStore.class); |
|
525 |
featureContainer = new FeatureContainer(); |
|
526 |
DisposableIterator iterator = null; |
|
527 |
FeatureSet set = null; |
|
528 |
try { |
|
529 |
set = featureStore.getFeatureSet(table.getModel().getQuery()); |
|
530 |
iterator = set.iterator(); |
|
531 |
|
|
532 |
if ( iterator.hasNext() ) { |
|
533 |
feature = (Feature) iterator.next(); |
|
534 |
} |
|
535 |
featureContainer.setFeature(feature); |
|
536 |
interpreter.declareBean("featureContainer", featureContainer, Feature.class); |
|
537 |
} catch (DataException e) { |
|
538 |
e.printStackTrace(); |
|
539 |
} finally { |
|
540 |
if ( iterator != null ) { |
|
541 |
iterator.dispose(); |
|
542 |
} |
|
543 |
if ( set != null ) { |
|
544 |
set.dispose(); |
|
545 |
} |
|
546 |
} |
|
547 |
} |
|
548 |
/** |
|
549 |
* Evaluate the fields. |
|
550 |
* |
|
551 |
* @param interpreter |
|
552 |
* |
|
553 |
* @throws EvalError |
|
554 |
*/ |
|
555 |
int lastType = -1; |
|
556 |
private JButton bClear = null; |
|
557 |
private JTabbedPane tabPrincipal = null; |
|
558 |
private JPanel pPrincipal = null; |
|
559 |
private JPanel pAdvanced = null; |
|
560 |
private JPanel pAdvancedNorth = null; |
|
561 |
private JTextField jTextField = null; |
|
562 |
private JButton bFile = null; |
|
563 |
private JPanel pAdvancedCenter = null; |
|
564 |
private JLabel lblLeng = null; |
|
565 |
private JButton bEval = null; |
|
566 |
private JScrollPane jScrollPane3 = null; |
|
567 |
private JTextArea txtMessage2 = null; |
|
568 |
|
|
569 |
private void refreshOperators(int type) { |
|
570 |
if ( lastType != -1 && lastType == type ) { |
|
571 |
return; |
|
572 |
} |
|
573 |
lastType = type; |
|
574 |
ListOperatorsModel lom = (ListOperatorsModel) getListCommand().getModel(); |
|
575 |
lom.clear(); |
|
576 |
for ( int i = 0; i < operators.size(); i++ ) { |
|
577 |
IOperator operator = (IOperator) operators.get(i); |
|
578 |
operator.setType(type); |
|
579 |
//Comprobar si tiene una capa asociada y pasarsela al GraphicOperator. |
|
580 |
if ( (lv != null) && operator instanceof GraphicOperator ) { |
|
581 |
GraphicOperator igo = (GraphicOperator) operator; |
|
582 |
igo.setLayer(lv); |
|
583 |
} |
|
584 |
if ( operator.isEnable() ) { |
|
585 |
lom.addOperator(operator); |
|
586 |
//System.out.println("Operator = "+operator.toString()); |
Also available in: Unified diff