Source Code Cross Referenced for EditAttributeByFormulaPlugIn.java in  » GIS » openjump » de » fho » jump » pirol » plugins » EditAttributeByFormula » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » openjump » de.fho.jump.pirol.plugins.EditAttributeByFormula 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 20.06.2005
003:         *
004:         * CVS information:
005:         *  $Author: javamap $
006:         *  $Date: 2007-06-18 21:15:27 -0700 (Mon, 18 Jun 2007) $
007:         *  $ID$
008:         *  $Rev: 856 $
009:         *  $Id: EditAttributeByFormulaPlugIn.java 856 2007-06-19 04:15:27Z javamap $
010:         *  $Log$
011:         *  Revision 1.4  2007/03/24 19:33:19  mentaer
012:         *  changed ui, so that pirol formula propeties file is not assumed (used formulas are not stored)
013:         *
014:         *  Revision 1.3  2007/03/24 18:13:11  mentaer
015:         *  changed to inherit AbstractPlugIn instead of StandardPirolPlugIn, subsequently changed also to normal logger
016:         *
017:         *  Revision 1.2  2007/02/03 14:19:47  mentaer
018:         *  modified debug output for pirol stuff
019:         *
020:         *  Revision 1.1  2006/11/23 18:53:15  mentaer
021:         *  added EditAttributeByFormula Plugin by Pirol including some parts of the baseclasses - note: plugin needs java 1.5
022:         *
023:         *  Revision 1.6  2006/11/05 14:28:05  mentaer
024:         *  translated pirol attribute calculator plugin
025:         *
026:         *  Revision 1.5  2006/11/05 13:47:35  mentaer
027:         *  refactoring of menu positions and set OJ version to 1.1 B
028:         *
029:         *  Revision 1.4  2006/11/04 19:22:42  mentaer
030:         *  changed menu position
031:         *
032:         *  Revision 1.3  2006/11/04 19:16:09  mentaer
033:         *  changed enable check
034:         *
035:         *  Revision 1.2  2006/11/04 19:11:58  mentaer
036:         *  *** empty log message ***
037:         *
038:         *  Revision 1.1  2006/11/04 19:09:34  mentaer
039:         *  added Pirol Plugin for Attribute Calculations for testing, which needs the baseclasses.jar
040:         *
041:         *  Revision 1.12  2006/05/09 14:31:39  orahn
042:         *  kleiner GUI verschönerung
043:         *
044:         *  Revision 1.11  2006/02/01 17:35:56  orahn
045:         *  + Unterstützung f. Attributnamen mit Leerzeichen
046:         *  + kleines, generelles Update für das PlugIn
047:         *
048:         *  Revision 1.10  2005/08/03 13:50:44  orahn
049:         *  +i18n
050:         *  -warnings
051:         *
052:         *  Revision 1.9  2005/07/13 10:12:55  orahn
053:         *  Einsatz: MetaInformationHandler
054:         *
055:         *  Revision 1.8  2005/07/12 16:33:56  orahn
056:         *  +Nutzung des PropertiesHandler
057:         *
058:         *  Revision 1.7  2005/06/30 10:42:12  orahn
059:         *  besseres Fehler-Feedback bei der Formeleingabe
060:         *
061:         *  Revision 1.6  2005/06/30 08:37:40  orahn
062:         *  misslungene Formel beschädigt nicht mehr das Layer
063:         *
064:         *  Revision 1.5  2005/06/29 16:03:57  orahn
065:         *  aufgemotzt
066:         *
067:         *  Revision 1.4  2005/06/28 15:35:18  orahn
068:         *  fast soweit: es fehlt noch eine "taste" wie backspace für ganze operatoren bzw. operanden
069:         *  und das Formel-Text-Feld muß gegen direkte User-Eingaben geschützt werden
070:         *
071:         *  Revision 1.3  2005/06/23 13:57:20  orahn
072:         *  nutzt jetzt uniqueAttributeName
073:         *
074:         *  Revision 1.2  2005/06/23 13:41:17  orahn
075:         *  erste BETA des Formel-Parser-PlugIns
076:         *
077:         *  Revision 1.1  2005/06/20 18:17:34  orahn
078:         *  erster Ansatz
079:         *
080:         */
081:        package de.fho.jump.pirol.plugins.EditAttributeByFormula;
082:
083:        import java.io.FileNotFoundException;
084:        import java.io.IOException;
085:
086:        import org.apache.log4j.Logger;
087:
088:        import com.vividsolutions.jump.I18N;
089:        import com.vividsolutions.jump.feature.FeatureCollection;
090:        import com.vividsolutions.jump.workbench.WorkbenchContext;
091:        import com.vividsolutions.jump.workbench.model.Layer;
092:        import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
093:        import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
094:        import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
095:        import com.vividsolutions.jump.workbench.plugin.PlugInContext;
096:        import com.vividsolutions.jump.workbench.ui.MenuNames;
097:
098:        import de.fho.jump.pirol.utilities.FormulaParsing.FormulaValue;
099:        import de.fho.jump.pirol.utilities.Properties.PropertiesHandler;
100:        import de.fho.jump.pirol.utilities.apiTools.FeatureCollectionTools;
101:        import de.fho.jump.pirol.utilities.attributes.AttributeInfo;
102:        import de.fho.jump.pirol.utilities.metaData.MetaInformationHandler;
103:        import de.fho.jump.pirol.utilities.plugIns.StandardPirolPlugIn;
104:        import de.fho.jump.pirol.utilities.settings.PirolPlugInSettings;
105:
106:        /**
107:         * 
108:         * PlugIn that creates a new attribute and assigns values to it, that are 
109:         * calculated by processing a formula that was created by the user.
110:         *
111:         * @author Ole Rahn
112:         * <br>
113:         * <br>FH Osnabr&uuml;ck - University of Applied Sciences Osnabr&uuml;ck,
114:         * <br>Project: PIROL (2005),
115:         * <br>Subproject: Daten- und Wissensmanagement
116:         * 
117:         * @version $Rev: 856 $
118:         */
119:        //--[sstein 24.March.2007] changed to normal plugin - thus we do not need 
120:        //  to load and create the properties file
121:        //public class EditAttributeByFormulaPlugIn extends StandardPirolPlugIn {
122:        public class EditAttributeByFormulaPlugIn extends AbstractPlugIn {
123:
124:            protected static PropertiesHandler storedFormulas = null;
125:            protected static final String storedFormulasFileName = "Formula.properties"; //$NON-NLS-1$
126:            //[sstein 24.March.2007] added this logger instead using Personal logger
127:            private static final Logger LOG = Logger
128:                    .getLogger(EditAttributeByFormulaPlugIn.class);
129:
130:            public void initialize(PlugInContext context) throws Exception {
131:                context.getFeatureInstaller().addMainMenuItemWithJava14Fix(
132:                        this ,
133:                        new String[] { MenuNames.TOOLS,
134:                                MenuNames.TOOLS_EDIT_ATTRIBUTES },
135:                        this .getName(), false, null,
136:                        createEnableCheck(context.getWorkbenchContext()));
137:            }
138:
139:            public String getName() {
140:                return I18N
141:                        .get("pirol.plugIns.EditAttributeByFormulaPlugIn.Attribute-Calculator");
142:            }
143:
144:            public static MultiEnableCheck createEnableCheck(
145:                    WorkbenchContext workbenchContext) {
146:                EnableCheckFactory checkFactory = new EnableCheckFactory(
147:                        workbenchContext);
148:
149:                return new MultiEnableCheck()
150:                        .add(
151:                                checkFactory
152:                                        .createAtLeastNLayersMustBeSelectedCheck(1))
153:                        .add(
154:                                checkFactory
155:                                        .createSelectedLayersMustBeEditableCheck());
156:            }
157:
158:            /* //-- [sstein 24.March 2007] disabled since we make it to a 
159:               //    normal plugin, not a StandardPirolPlugin
160:            public EditAttributeByFormulaPlugIn(){
161:                super(new PersonalLogger(DebugUserIds.ALL)); 
162:            }
163:             */
164:
165:            /**
166:             * @inheritDoc
167:             */
168:            public String getIconString() {
169:                return null;
170:            }
171:
172:            /**
173:             *@inheritDoc
174:             */
175:            public String getCategoryName() {
176:                return PirolPlugInSettings.getName_AttributeMenu();
177:            }
178:
179:            /**
180:             * @inheritDoc
181:             */
182:            public boolean execute(PlugInContext context) throws Exception {
183:                Layer layer = StandardPirolPlugIn.getSelectedLayer(context);
184:
185:                if (layer == null) {
186:                    StandardPirolPlugIn
187:                            .warnUser(
188:                                    context,
189:                                    I18N
190:                                            .get("pirol.plugIns.EditAttributeByFormulaPlugIn.no-layer-selected")); //$NON-NLS-1$
191:                    //--[sstein 24.March 2007]: disabled since I changed from StandardPirolPlugIn to AbstractPlugIn
192:                    return false;
193:                    //return this.finishExecution(context, false);
194:                } else if (!layer.isEditable()) {
195:                    StandardPirolPlugIn
196:                            .warnUser(
197:                                    context,
198:                                    I18N
199:                                            .get("pirol.plugIns.EditAttributeByFormulaPlugIn.layer-not-editable")); //$NON-NLS-1$
200:                    //--[sstein 24.March 2007] disabled since I changed from StandardPirolPlugIn to AbstractPlugIn
201:                    //return this.finishExecution(context, false);
202:                    return false;
203:                }
204:
205:                try {
206:                    //--[sstein 24.March 2007] currently the following line is useless
207:                    EditAttributeByFormulaPlugIn.storedFormulas = new PropertiesHandler(
208:                            EditAttributeByFormulaPlugIn.storedFormulasFileName);
209:                    //--[sstein 24.March 2007] disabled - we dont assume an existing file
210:                    //EditAttributeByFormulaPlugIn.storedFormulas.load();
211:                }
212:                /* catch (FileNotFoundException e1) {
213:                    //this.logger.printWarning(e1.getMessage());
214:                	this.LOG.warn(e1.getMessage());
215:                } 
216:                catch (IOException e1) {
217:                    //this.logger.printWarning(e1.getMessage());
218:                	this.LOG.warn(e1.getMessage());
219:                } 
220:                 **/
221:                catch (Exception e1) {
222:                    //this.logger.printWarning(e1.getMessage());
223:                    this .LOG.warn(e1.getMessage());
224:                }
225:
226:                /* [sstein 24.March 2007] replaced - since we dont have stored formulas
227:                EditAttributeByFormulaDialog dialog = new EditAttributeByFormulaDialog(context.getWorkbenchFrame(), 
228:                		I18N.get("pirol.plugIns.EditAttributeByFormulaPlugIn.specify-attribute-and-formula"), 
229:                		true, 
230:                		I18N.get("pirol.plugIns.EditAttributeByFormulaPlugIn.editByFormula-explaining-text"), 
231:                		layer.getFeatureCollectionWrapper().getFeatureSchema(), 
232:                		EditAttributeByFormulaPlugIn.storedFormulas); //$NON-NLS-1$ //$NON-NLS-2$
233:                 */
234:                EditAttributeByFormulaDialog dialog = new EditAttributeByFormulaDialog(
235:                        context.getWorkbenchFrame(),
236:                        I18N
237:                                .get("pirol.plugIns.EditAttributeByFormulaPlugIn.specify-attribute-and-formula"),
238:                        true,
239:                        I18N
240:                                .get("pirol.plugIns.EditAttributeByFormulaPlugIn.editByFormula-explaining-text"),
241:                        layer.getFeatureCollectionWrapper().getFeatureSchema());
242:
243:                dialog.setVisible(true);
244:
245:                String formula = dialog.getFormula();
246:
247:                if (!dialog.wasOkClicked() || formula == null
248:                        || formula.length() == 0) {
249:                    //--[sstein 24.March 2007]: disabled since I changed from StandardPirolPlugIn to AbstractPlugIn
250:                    //return this.finishExecution(context, false);
251:                    return false;
252:                }
253:
254:                AttributeInfo attrInfo = dialog.getAttributeInfo();
255:
256:                FeatureCollection oldFc = layer.getFeatureCollectionWrapper()
257:                        .getUltimateWrappee();
258:
259:                attrInfo.setUniqueAttributeName(FeatureCollectionTools
260:                        .getUniqueAttributeName(oldFc, attrInfo
261:                                .getAttributeName()));
262:
263:                try {
264:                    FormulaValue parsedFormula = dialog.getParsedFormula();
265:
266:                    FeatureCollection newFc = FeatureCollectionTools
267:                            .applyFormulaToFeatureCollection(oldFc, attrInfo,
268:                                    parsedFormula, true);
269:                    layer.setFeatureCollection(newFc);
270:
271:                    MetaInformationHandler metaInfHandler = new MetaInformationHandler(
272:                            layer);
273:                    metaInfHandler
274:                            .addMetaInformation(
275:                                    I18N
276:                                            .get("pirol.plugIns.EditAttributeByFormulaPlugIn.formula-for")
277:                                            + attrInfo.getUniqueAttributeName(),
278:                                    formula); //$NON-NLS-1$
279:
280:                    if (storedFormulas != null) {
281:                        storedFormulas
282:                                .setProperty(attrInfo.toString(), formula);
283:                        storedFormulas
284:                                .store(I18N
285:                                        .get("pirol.plugIns.EditAttributeByFormulaPlugIn.editByFormula-properties-comment")); //$NON-NLS-1$
286:                    }
287:
288:                } catch (Exception e) {
289:                    //--[sstein 24.March 2007]: disabled since I changed from StandardPirolPlugIn to AbstractPlugIn
290:                    //this.handleThrowable(e);
291:                    LOG.debug(e.getMessage());
292:                    e.printStackTrace();
293:                    //return this.finishExecution(context, false);
294:                    return false;
295:                }
296:                //--[sstein 24.March 2007]: disabled since I changed from StandardPirolPlugIn to AbstractPlugIn
297:                //return this.finishExecution(context, true);
298:                return false;
299:            }
300:
301:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.