Source Code Cross Referenced for EnvEntryDelegate.java in  » Workflow-Engines » osbl-1_0 » core » 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 » Workflow Engines » osbl 1_0 » core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * 
003:         */package core;
004:
005:        import gui.section.IEnvEntryViewer;
006:
007:        import java.util.Iterator;
008:        import java.util.Set;
009:
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:        import org.eclipse.core.runtime.CoreException;
013:        import org.eclipse.core.runtime.IProgressMonitor;
014:        import org.eclipse.core.runtime.OperationCanceledException;
015:        import org.eclipse.jdt.core.JavaModelException;
016:        import org.eclipse.jdt.core.dom.FieldDeclaration;
017:        import org.eclipse.ltk.core.refactoring.Change;
018:        import org.eclipse.ltk.core.refactoring.CompositeChange;
019:        import org.eclipse.ltk.core.refactoring.RefactoringStatus;
020:        import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
021:
022:        import diagram.section.EnvEntry;
023:
024:        /**
025:         * The Delegate Class which does the refactoring modifications 
026:         * in the source and onto the model. It also contains the undo
027:         * modifications.
028:         * 
029:         * @author sh
030:         *
031:         */
032:        public class EnvEntryDelegate {
033:
034:            // the Info Object containing all nesessary refactor info
035:            private final RefactorInfo info;
036:
037:            // FIXME
038:            // the viewer set and the EnvEntry is needed to execute the table model update
039:            // after an environment entry has changed. It will be
040:            // transmitted from the EnvEntryList, to RefactorEnvEntryAction,
041:            // to EnvEntryProcessor and finally to EnvEntryDelegate where the
042:            // update will be performed.
043:            private Set<IEnvEntryViewer> changeListeners = null;
044:            private EnvEntry envEntry = null;
045:
046:            private Log log = LogFactory.getLog(getClass());
047:
048:            /**
049:             * Constructor
050:             * 
051:             * @param info the refactoring info object
052:             * @param envEntry the selected environment entry to change
053:             * @param changeListeners the Listeners which listen to envEntry changes
054:             */
055:            public EnvEntryDelegate(RefactorInfo info, EnvEntry envEntry,
056:                    Set<IEnvEntryViewer> changeListeners) {
057:                super ();
058:                this .info = info;
059:                this .envEntry = envEntry;
060:                this .changeListeners = changeListeners;
061:            }
062:
063:            /**
064:             * Check if the info object contains valid information.
065:             * 
066:             * @return result a Refactoring Status object
067:             */
068:            public RefactoringStatus checkInitialConditions() {
069:                RefactoringStatus result = new RefactoringStatus();
070:
071:                if (info.getNewName() == null || info.getNewName().equals("")) {
072:                    result
073:                            .addFatalError("No new type name could be determined");
074:                } else if (info.getOldName() == null
075:                        || info.getOldName().equals("")) {
076:                    result.addFatalError("The old name could't be determined.");
077:                }
078:
079:                if (info.getElement() instanceof  FieldDeclaration == false) {
080:                    result
081:                            .addWarning("Environment Entry not yet available, will be created");
082:                }
083:
084:                boolean isConsitent = false;
085:                try {
086:                    isConsitent = info.getUnit().isConsistent();
087:                } catch (JavaModelException e) {
088:                    result.addFatalError("No source file could be determined");
089:                }
090:
091:                if (!isConsitent)
092:                    result.addFatalError("No source file could be determined.");
093:                else if (info.getUnit() == null || info.getUnit().isReadOnly()) {
094:                    result.addFatalError("No source file could be determined.");
095:                }
096:                return result;
097:            }
098:
099:            /**
100:             * Checks the final conditions before the refactoring will be executed.
101:             * If an error will be returned no refactoring operation will be invoked.
102:             * 
103:             * @param pm a progress monitor
104:             * @param ctxt
105:             * @return result a Refactoring Status object
106:             */
107:            public RefactoringStatus checkFinalConditions(
108:                    final IProgressMonitor pm, final CheckConditionsContext ctxt) {
109:                RefactoringStatus result = new RefactoringStatus();
110:
111:                // TODO use the CheckConditionContext and check the model
112:
113:                return result;
114:            }
115:
116:            /**
117:             * The code refactoring, environment entry creation and the model 
118:             * refactoring are added as one task to the Composite Changed object 
119:             * used by the processor. Each refactoring change object contains 
120:             * its undo handling. If an undo operation was executed, all tasks 
121:             * of the Composite Change object are considered.
122:             * 
123:             * @param pm a progress monitor
124:             * @param rootChange the Composite Change object
125:             */
126:            void createChange(final IProgressMonitor pm,
127:                    final CompositeChange rootChange) {
128:                // if no environment entry in the source is available,
129:                // generate it.
130:                if (info.getElement() instanceof  FieldDeclaration == false) {
131:                    try {
132:                        pm.beginTask("Collecting changes", 100);
133:                        rootChange.add(new EnvEntryCreation());
134:                        pm.worked(30);
135:                        rootChange.add(new ModelChange());
136:                    } finally {
137:                        pm.done();
138:                    }
139:                }
140:
141:                // refactor the source and the model
142:                else {
143:                    try {
144:                        pm.beginTask("Collecting changes", 100);
145:                        rootChange.add(new TypeChange());
146:                        pm.worked(30);
147:                        rootChange.add(new ModelChange());
148:                    } finally {
149:                        pm.done();
150:                    }
151:                }
152:            }
153:
154:            /**
155:             * The change class responsible for environment entry ereation
156:             * and undo handling.
157:             * 
158:             * @author sh
159:             *
160:             */
161:            private class EnvEntryCreation extends Change {
162:                public Object getModifiedElement() {
163:                    return null;
164:                }
165:
166:                public String getName() {
167:                    return "Environment Entry source code creation";
168:                }
169:
170:                public void initializeValidationData(IProgressMonitor pm) {
171:                }
172:
173:                public RefactoringStatus isValid(IProgressMonitor pm)
174:                        throws CoreException, OperationCanceledException {
175:                    return new RefactoringStatus();
176:                }
177:
178:                /**
179:                 * performs the type refactoring 
180:                 */
181:                @Override
182:                public Change perform(IProgressMonitor pm) throws CoreException {
183:                    CreateFieldDeclaration createField = new CreateFieldDeclaration();
184:                    createField.createFieldDeclarations(info);
185:                    log
186:                            .info("Source Code: Environment Entry creation perfomed");
187:
188:                    // returns the undo change object
189:                    return new Change() {
190:                        public Object getModifiedElement() {
191:                            return null;
192:                        }
193:
194:                        public String getName() {
195:                            return "Undo Environment Entry source code creation";
196:                        }
197:
198:                        public void initializeValidationData(IProgressMonitor pm) {
199:                        }
200:
201:                        public RefactoringStatus isValid(IProgressMonitor pm)
202:                                throws CoreException,
203:                                OperationCanceledException {
204:                            return new RefactoringStatus();
205:                        }
206:
207:                        /**
208:                         * performs the undo operation
209:                         */
210:                        @Override
211:                        public Change perform(IProgressMonitor pm)
212:                                throws CoreException {
213:                            new RemoveFieldDeclaration()
214:                                    .removeFieldDeclarations(info);
215:                            log
216:                                    .info("Source Code: Environment Entry creation undone");
217:                            return null;
218:                        }
219:                    };
220:                }
221:            }
222:
223:            /**
224:             * The change class responsible for source type refacturing
225:             * and undo handling.
226:             * 
227:             * @author sh
228:             *
229:             */
230:            private class TypeChange extends Change {
231:                public Object getModifiedElement() {
232:                    return null;
233:                }
234:
235:                public String getName() {
236:                    return "Environment Entry source code change";
237:                }
238:
239:                public void initializeValidationData(IProgressMonitor pm) {
240:                }
241:
242:                public RefactoringStatus isValid(IProgressMonitor pm)
243:                        throws CoreException, OperationCanceledException {
244:                    return new RefactoringStatus();
245:                }
246:
247:                /**
248:                 * performs the type refactoring 
249:                 */
250:                @Override
251:                public Change perform(IProgressMonitor pm) throws CoreException {
252:                    RenameFieldDeclaration renField = new RenameFieldDeclaration();
253:                    renField.process(info);
254:                    log.info("Source Code: Environment Entry change perfomed");
255:
256:                    // returns the undo change object
257:                    return new Change() {
258:                        public Object getModifiedElement() {
259:                            return null;
260:                        }
261:
262:                        public String getName() {
263:                            return "Undo Environment Entry source code change";
264:                        }
265:
266:                        public void initializeValidationData(IProgressMonitor pm) {
267:                        }
268:
269:                        public RefactoringStatus isValid(IProgressMonitor pm)
270:                                throws CoreException,
271:                                OperationCanceledException {
272:                            return new RefactoringStatus();
273:                        }
274:
275:                        /**
276:                         * performs the undo operation
277:                         */
278:                        @Override
279:                        public Change perform(IProgressMonitor pm)
280:                                throws CoreException {
281:                            RenameFieldDeclaration renField = new RenameFieldDeclaration();
282:                            RefactorInfo undoInfo = new RefactorInfo();
283:
284:                            // invert values
285:                            undoInfo.setElement(info.getElement());
286:                            undoInfo.setUnit(info.getUnit());
287:                            undoInfo.setNewName(info.getOldName());
288:                            undoInfo.setOldName(info.getNewName());
289:                            undoInfo.setNewVarName(info.getOldVarName());
290:                            undoInfo.setOldVarName(info.getNewVarName());
291:
292:                            // start the undo operation
293:                            renField.process(undoInfo);
294:                            log
295:                                    .info("Source Code: Environment Entry change undone");
296:                            return null;
297:                        }
298:                    };
299:                }
300:            }
301:
302:            /**
303:             * The change class responsible for model type refacturing
304:             * and undo handling.
305:             * 
306:             * @author sh
307:             *
308:             */
309:            private class ModelChange extends Change {
310:                public Object getModifiedElement() {
311:                    return null;
312:                }
313:
314:                public String getName() {
315:                    return "Environment Entry model change";
316:                }
317:
318:                public void initializeValidationData(IProgressMonitor pm) {
319:                }
320:
321:                public RefactoringStatus isValid(IProgressMonitor pm)
322:                        throws CoreException, OperationCanceledException {
323:                    return new RefactoringStatus();
324:                }
325:
326:                /**
327:                 * performs the type refactoring 
328:                 */
329:                @Override
330:                public Change perform(IProgressMonitor pm) throws CoreException {
331:                    // perform the model modification
332:                    RenameModelField renField = new RenameModelField();
333:                    renField.process(info);
334:                    log.info("Model: Environment Entry change performed");
335:
336:                    // update the model
337:                    envEntry.setName(info.getNewVarName());
338:                    envEntry.setType(info.getNewName());
339:
340:                    // perform the table refresh
341:                    Iterator<IEnvEntryViewer> iterator = changeListeners
342:                            .iterator();
343:                    while (iterator.hasNext())
344:                        ((IEnvEntryViewer) iterator.next())
345:                                .updateEnvEntry(envEntry);
346:
347:                    // returns the undo change object
348:                    return new Change() {
349:                        public Object getModifiedElement() {
350:                            return null;
351:                        }
352:
353:                        public String getName() {
354:                            return "Undo Environment Entry model change";
355:                        }
356:
357:                        public void initializeValidationData(IProgressMonitor pm) {
358:                        }
359:
360:                        public RefactoringStatus isValid(IProgressMonitor pm)
361:                                throws CoreException,
362:                                OperationCanceledException {
363:                            return new RefactoringStatus();
364:                        }
365:
366:                        /**
367:                         * performs the undo operation
368:                         */
369:                        @Override
370:                        public Change perform(IProgressMonitor pm)
371:                                throws CoreException {
372:                            RenameModelField renField = new RenameModelField();
373:                            RefactorInfo undoInfo = new RefactorInfo();
374:
375:                            // invert values
376:                            undoInfo.setElement(info.getElement());
377:                            undoInfo.setUnit(info.getUnit());
378:                            undoInfo.setNewName(info.getOldName());
379:                            undoInfo.setOldName(info.getNewName());
380:                            undoInfo.setNewVarName(info.getOldVarName());
381:                            undoInfo.setOldVarName(info.getNewVarName());
382:
383:                            // start the undo operation
384:                            renField.process(undoInfo);
385:                            log.info("Model: Environment Entry change undone");
386:
387:                            // update the model
388:                            envEntry.setName(undoInfo.getNewVarName());
389:                            envEntry.setType(undoInfo.getNewName());
390:
391:                            // perform the table refresh
392:                            Iterator<IEnvEntryViewer> iterator = changeListeners
393:                                    .iterator();
394:                            while (iterator.hasNext())
395:                                ((IEnvEntryViewer) iterator.next())
396:                                        .updateEnvEntry(envEntry);
397:
398:                            return null;
399:                        }
400:                    };
401:                }
402:            }
403:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.