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


001:        /**
002:         * 
003:         */package gui.actions;
004:
005:        import gui.section.IEnvEntryViewer;
006:        import gui.wizards.RenameTypeWizard;
007:
008:        import java.util.Iterator;
009:        import java.util.List;
010:        import java.util.Set;
011:
012:        import logging.LoggingPlugin;
013:        import model.ModelUtil;
014:
015:        import org.apache.commons.logging.Log;
016:        import org.apache.commons.logging.LogFactory;
017:        import org.eclipse.core.runtime.ILog;
018:        import org.eclipse.core.runtime.IStatus;
019:        import org.eclipse.core.runtime.Status;
020:        import org.eclipse.gef.EditPart;
021:        import org.eclipse.jdt.core.ICompilationUnit;
022:        import org.eclipse.jdt.core.dom.FieldDeclaration;
023:        import org.eclipse.jface.action.Action;
024:        import org.eclipse.jface.dialogs.MessageDialog;
025:        import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
026:        import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
027:
028:        import core.EnvEntryProcessor;
029:        import core.FieldDeclarationParser;
030:        import core.RefactorInfo;
031:        import core.RenameProcessorHolder;
032:        import core.Util;
033:        import diagram.section.EnvEntry;
034:
035:        /**
036:         * This action will be called from the Environment Entry
037:         * property sheet page. It startes the refactor type 
038:         * process, which refactors a variable declaration type. 
039:         * It openes a refactoring wizard and adapts the changes 
040:         * to the source and the model. This currently only workes 
041:         * when the file in the workspace is selected.
042:         * 
043:         * @author sh
044:         */
045:        public class RefactorEnvEntryAction extends Action {
046:
047:            // the selected EditPart
048:            private EditPart selectedEditPart = null;
049:
050:            // the selected environment entry
051:            private EnvEntry envEntry = null;
052:
053:            // the Info Object to refacter
054:            private RefactorInfo info = new RefactorInfo();
055:
056:            private Log log = LogFactory.getLog(getClass());
057:
058:            // FIXME
059:            // the viewer set is needed to execute the table model update
060:            // after an environment entry has been changed. It will be
061:            // transmitted from EnvEntryList, to RefactorEnvEntryAction,
062:            // to EnvEntryProcessor and finally to EnvEntryDelegate where the
063:            // update will be performed.
064:            private Set<IEnvEntryViewer> changeListeners = null;
065:
066:            /**
067:             * Constructor
068:             * 
069:             * @param selectedEditPart the selected EditPart
070:             * @param envEntry the selected environment entry
071:             */
072:            public RefactorEnvEntryAction(EditPart selectedEditPart,
073:                    EnvEntry envEntry, Set<IEnvEntryViewer> changeListeners) {
074:                super ();
075:                this .selectedEditPart = selectedEditPart;
076:                this .envEntry = envEntry;
077:                this .changeListeners = changeListeners;
078:            }
079:
080:            /* 
081:             * Starts the action. Before the refactorig wizard appears we check
082:             * if a java class exists for the selected model element.
083:             * If so we check if the selected environment entry exists.
084:             * If so the source code refactoring will be performed, otherwise
085:             * the environment entry source variable will be created. 
086:             * 
087:             * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
088:             */
089:            @Override
090:            public void run() {
091:                super .run();
092:
093:                // check if the context is ok
094:                if (selectedEditPart == null || envEntry == null) {
095:                    refuse();
096:                } else {
097:                    // apply the values of the current environment entry
098:                    applySelection();
099:
100:                    // check if source code is available
101:                    ICompilationUnit unit = getCompilationUnit();
102:                    if (unit == null) {
103:                        noSourceCodeMessage();
104:                        return;
105:                    } else {
106:                        // add the source code file to the info object
107:                        info.setUnit(unit);
108:                    }
109:
110:                    // check if the environment entry already exist
111:                    FieldDeclaration fDecl = new FieldDeclarationParser()
112:                            .parseFieldDeclarations(unit, envEntry);
113:                    info.setElement(fDecl);
114:
115:                    if (ActionUtil.saveAll()) {
116:                        openWizard();
117:                    }
118:                }
119:            }
120:
121:            /**
122:             * helper method which is called if the current
123:             * selection cannot be used for that refactoring.
124:             */
125:            private void refuse() {
126:                String title = "Environment Entry Refactoring";
127:                String message = "This refactoring is only available on Java field properties.";
128:                MessageDialog.openInformation(ActionUtil.getShell(), title,
129:                        message);
130:            }
131:
132:            /**
133:             * helper method wich is called if no underlying java source
134:             * file has been found for the model element.
135:             */
136:            private void noSourceCodeMessage() {
137:                String title = "Environment Entry Refactoring";
138:                String message = "No concerning Java source file available.";
139:                MessageDialog.openInformation(ActionUtil.getShell(), title,
140:                        message);
141:            }
142:
143:            /**
144:             * helper method which applies the selection 
145:             * and stores it in the info object.
146:             */
147:            private void applySelection() {
148:                info.setNewName(envEntry.getType());
149:                info.setOldName(envEntry.getType());
150:                info.setNewVarName(envEntry.getName());
151:                info.setOldVarName(envEntry.getName());
152:            }
153:
154:            /**
155:             * helper method which searchs the compilation
156:             * unit for the selected EditPart.
157:             * 
158:             * @return unit the compilation unit
159:             */
160:            private ICompilationUnit getCompilationUnit() {
161:                // get the implementation statement of the EditPart
162:                String epImpl = ModelUtil
163:                        .getModelImplProperty(selectedEditPart);
164:                if (epImpl == null)
165:                    return null;
166:
167:                // get all compilation units
168:                List<ICompilationUnit> units = Util.getICompilationUnits();
169:                for (Iterator<ICompilationUnit> iterator = units.iterator(); iterator
170:                        .hasNext();) {
171:                    ICompilationUnit unit = (ICompilationUnit) iterator.next();
172:                    String sourceImpl = Util.getImplementation(unit);
173:
174:                    // check the concerning cu has been found
175:                    if (epImpl.equals(sourceImpl))
176:                        return unit;
177:                }
178:                return null;
179:            }
180:
181:            /**
182:             * helper method for opening the type refactoring wizard.
183:             */
184:            private void openWizard() {
185:                RefactoringProcessor processor = new EnvEntryProcessor(info,
186:                        envEntry, changeListeners);
187:                RenameProcessorHolder ref = new RenameProcessorHolder(processor);
188:                RenameTypeWizard wizard = new RenameTypeWizard(ref, info);
189:                RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(
190:                        wizard);
191:                try {
192:                    String titleForFailedChecks = "";
193:                    op.run(ActionUtil.getShell(), titleForFailedChecks);
194:                } catch (final InterruptedException irex) {
195:                    String message = "operation was canceled";
196:                    ILog logger = LoggingPlugin.getDefault().getLog();
197:                    String symName = LoggingPlugin.getDefault().getBundle()
198:                            .getSymbolicName();
199:                    logger.log(new Status(IStatus.ERROR, symName, 0, message,
200:                            irex));
201:                    throw new RuntimeException(irex + message);
202:                }
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.