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


001:        /**
002:         * 
003:         */package gui.participants;
004:
005:        import logging.LoggingPlugin;
006:        import model.ModelModifier;
007:
008:        import org.apache.commons.logging.Log;
009:        import org.apache.commons.logging.LogFactory;
010:        import org.eclipse.core.runtime.CoreException;
011:        import org.eclipse.core.runtime.ILog;
012:        import org.eclipse.core.runtime.IProgressMonitor;
013:        import org.eclipse.core.runtime.IStatus;
014:        import org.eclipse.core.runtime.OperationCanceledException;
015:        import org.eclipse.core.runtime.Status;
016:        import org.eclipse.jdt.internal.core.SourceField;
017:        import org.eclipse.jdt.internal.core.SourceType;
018:        import org.eclipse.ltk.core.refactoring.Change;
019:        import org.eclipse.ltk.core.refactoring.RefactoringStatus;
020:        import org.eclipse.ltk.core.refactoring.participants.RenameArguments;
021:
022:        /**
023:         * This change class is responsible for updating the environment
024:         * entries in the model. It checks if the type containing
025:         * this field is an element in the model. If so it checks
026:         * if the element contains this field as environment entry.
027:         * It also returns the undo operations for this modification.
028:         * 
029:         * @author sh
030:         *
031:         */
032:        public class FieldModelChange extends Change {
033:            // the selected element to refacter
034:            private Object selection = null;
035:
036:            // the input of the refactoring dialog
037:            private RenameArguments arguments = null;
038:
039:            private Log log = LogFactory.getLog(getClass());
040:
041:            /**
042:             * Constructor
043:             * 
044:             * @param selection the element to refacter
045:             * @param arguments the input data of the refactoring dialog
046:             */
047:            public FieldModelChange(Object selection, RenameArguments arguments) {
048:                super ();
049:                this .selection = selection;
050:                this .arguments = arguments;
051:            }
052:
053:            /**
054:             * Returns the element modified by this <code>Change</code>. The method may return 
055:             * <code>null</code> if the change isn't related to an element.
056:             * 
057:             * @return the element modified by this change
058:             */
059:            @Override
060:            public Object getModifiedElement() {
061:                return null;
062:            }
063:
064:            /* (non-Javadoc)
065:             * @see org.eclipse.ltk.core.refactoring.Change#getName()
066:             */
067:            @Override
068:            public String getName() {
069:                return new String("Environment Entry change");
070:            }
071:
072:            /* (non-Javadoc)
073:             * @see org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.eclipse.core.runtime.IProgressMonitor)
074:             */
075:            @Override
076:            public void initializeValidationData(IProgressMonitor pm) {
077:            }
078:
079:            /* (non-Javadoc)
080:             * @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor)
081:             */
082:            @Override
083:            public RefactoringStatus isValid(IProgressMonitor pm)
084:                    throws CoreException, OperationCanceledException {
085:
086:                // if an fatal error will return, the refactoring will stoped
087:                RefactoringStatus result = new RefactoringStatus();
088:
089:                // TODO: check if some model could be read
090:
091:                return result;
092:            }
093:
094:            /**
095:             * Performs this change after the method isValid has been called. If isValid
096:             * returns an fatal error or the change is disabled this change will not be performed. 
097:             * Changes should in general not respond to {@link IProgressMonitor#isCanceled()} 
098:             * since canceling a change tree in the middle of its execution leaves the workspace 
099:             * in a half changed state.   
100:             * 
101:             * @param pm a progress monitor
102:             * @return the undo change for this change object or <code>null</code> if no
103:             *  undo is provided
104:             * @throws CoreException if an error occurred during change execution
105:             */
106:            @Override
107:            public Change perform(IProgressMonitor pm) throws CoreException {
108:                Object sel = this .selection;
109:                RenameArguments args = this .arguments;
110:
111:                // get the fqn of the type
112:                SourceField field = (SourceField) this .selection;
113:                SourceType jElement = (SourceType) field.getParent();
114:                String implementation = jElement.getFullyQualifiedName();
115:
116:                // if field is in subclass e.g. testpackage.p8.Anybody$foo
117:                // replace the '$'
118:                implementation = implementation.replace('$', '.');
119:
120:                // get the old field name
121:                String oldEntryName = field.getElementName();
122:
123:                // get the new field name
124:                String newEntryName = ((RenameArguments) this .arguments)
125:                        .getNewName();
126:
127:                // check if values are valid
128:                if (!valuesValid(implementation, oldEntryName, newEntryName)) {
129:                    String message = "Model Update could't be done !";
130:                    ILog logger = LoggingPlugin.getDefault().getLog();
131:                    String symName = LoggingPlugin.getDefault().getBundle()
132:                            .getSymbolicName();
133:                    logger.log(new Status(IStatus.ERROR, symName, 0, message,
134:                            null));
135:                    throw new RuntimeException(message);
136:                }
137:
138:                // start the model update
139:                new ModelModifier().doEnvEntryNameModification(implementation,
140:                        oldEntryName, newEntryName);
141:                log.info("Model: Environment Entry name change performed");
142:
143:                // for the transaction handling the undo change element is returned
144:                // which reverts the environment entry name property change to the original state
145:                String undoOldImpl = newEntryName;
146:                String undoNewImpl = oldEntryName;
147:                return new FieldUndoModelChange(implementation, undoOldImpl,
148:                        undoNewImpl);
149:            }
150:
151:            /**
152:             * check if the given values are valid, means they are initialized and
153:             * the string is not empty.
154:             * 
155:             * @param implementation the full qualified name of a compilation unit
156:             * @param oldEntryName an environment entry name
157:             * @param newEntryName an environment entry name
158:             * 
159:             * @return true if all values pass the check
160:             */
161:            private boolean valuesValid(String implementation,
162:                    String oldEntryName, String newEntryName) {
163:                boolean valid = false;
164:
165:                if (implementation != null)
166:                    if (!implementation.equals(""))
167:                        valid = true;
168:
169:                if (oldEntryName != null) {
170:                    if (!oldEntryName.equals(""))
171:                        valid = true;
172:                }
173:
174:                if (newEntryName != null) {
175:                    if (!newEntryName.equals(""))
176:                        valid = true;
177:                }
178:
179:                return valid;
180:            }
181:
182:            /**
183:             * The undo change class which is used by the FieldModelChange participant.
184:             * If a model modification will be undone, an instance of that class
185:             * will be returned to set the original state.
186:             * 
187:             * @author sh
188:             *
189:             */
190:            private class FieldUndoModelChange extends Change {
191:                // the implementation of the model element containing the environment entry
192:                private String implementation = null;
193:                // the old environment entry name
194:                private String oldEntryName = null;
195:                // the new environment entry name
196:                private String newEntryName = null;
197:
198:                public Object getModifiedElement() {
199:                    return null;
200:                }
201:
202:                public String getName() {
203:                    return "Undo Environment Entry change";
204:                }
205:
206:                public void initializeValidationData(IProgressMonitor pm) {
207:                }
208:
209:                public FieldUndoModelChange(String implementation,
210:                        String oldEntryName, String newEntryName) {
211:                    super ();
212:                    this .implementation = implementation;
213:                    this .oldEntryName = oldEntryName;
214:                    this .newEntryName = newEntryName;
215:                }
216:
217:                /**
218:                 * check if properties are set.
219:                 */
220:                @Override
221:                public RefactoringStatus isValid(IProgressMonitor pm)
222:                        throws CoreException, OperationCanceledException {
223:
224:                    if (this .implementation == null
225:                            || this .oldEntryName == null
226:                            || this .newEntryName == null) {
227:                        String message = "unable to undo the model environment entry name modification";
228:                        ILog logger = LoggingPlugin.getDefault().getLog();
229:                        String symName = LoggingPlugin.getDefault().getBundle()
230:                                .getSymbolicName();
231:                        logger.log(new Status(IStatus.ERROR, symName, 0,
232:                                message, null));
233:                        throw new RuntimeException(message);
234:                    }
235:                    return new RefactoringStatus();
236:                }
237:
238:                /**
239:                 * perform the undo operation
240:                 */
241:                @Override
242:                public Change perform(IProgressMonitor pm) throws CoreException {
243:                    new ModelModifier().doEnvEntryNameModification(
244:                            implementation, oldEntryName, newEntryName);
245:                    log.info("Model: Environment Entry name change undone");
246:                    return null;
247:                }
248:            }
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.