Source Code Cross Referenced for AddJavaDocStubAction.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » ui » 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 » IDE Eclipse » jdt » org.eclipse.jdt.ui.actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.ui.actions;
011:
012:        import java.lang.reflect.InvocationTargetException;
013:        import java.util.List;
014:
015:        import org.eclipse.core.runtime.CoreException;
016:
017:        import org.eclipse.jdt.core.ICompilationUnit;
018:        import org.eclipse.jdt.core.IField;
019:        import org.eclipse.jdt.core.IJavaElement;
020:        import org.eclipse.jdt.core.IMember;
021:        import org.eclipse.jdt.core.IMethod;
022:        import org.eclipse.jdt.core.IType;
023:
024:        import org.eclipse.jface.dialogs.MessageDialog;
025:        import org.eclipse.jface.text.ITextSelection;
026:        import org.eclipse.jface.viewers.IStructuredSelection;
027:
028:        import org.eclipse.ui.IEditorPart;
029:        import org.eclipse.ui.IWorkbenchSite;
030:        import org.eclipse.ui.PlatformUI;
031:
032:        import org.eclipse.jdt.internal.corext.codemanipulation.AddJavaDocStubOperation;
033:        import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
034:
035:        import org.eclipse.jdt.ui.JavaUI;
036:
037:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
038:        import org.eclipse.jdt.internal.ui.actions.ActionMessages;
039:        import org.eclipse.jdt.internal.ui.actions.ActionUtil;
040:        import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
041:        import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
042:        import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
043:        import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
044:        import org.eclipse.jdt.internal.ui.util.ElementValidator;
045:        import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
046:
047:        /**
048:         * Create Javadoc comment stubs for the selected members.
049:         * <p>
050:         * Will open the parent compilation unit in a Java editor. The result is 
051:         * unsaved, so the user can decide if the changes are acceptable.
052:         * <p>
053:         * The action is applicable to structured selections containing elements
054:         * of type <code>IMember</code>.
055:         * 
056:         * <p>
057:         * This class may be instantiated; it is not intended to be subclassed.
058:         * </p>
059:         * 
060:         * @since 2.0
061:         */
062:        public class AddJavaDocStubAction extends SelectionDispatchAction {
063:
064:            private CompilationUnitEditor fEditor;
065:
066:            /**
067:             * Creates a new <code>AddJavaDocStubAction</code>. The action requires
068:             * that the selection provided by the site's selection provider is of type <code>
069:             * org.eclipse.jface.viewers.IStructuredSelection</code>.
070:             * 
071:             * @param site the site providing context information for this action
072:             */
073:            public AddJavaDocStubAction(IWorkbenchSite site) {
074:                super (site);
075:                setText(ActionMessages.AddJavaDocStubAction_label);
076:                setDescription(ActionMessages.AddJavaDocStubAction_description);
077:                setToolTipText(ActionMessages.AddJavaDocStubAction_tooltip);
078:                PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
079:                        IJavaHelpContextIds.ADD_JAVADOC_STUB_ACTION);
080:            }
081:
082:            /**
083:             * Note: This constructor is for internal use only. Clients should not call this constructor.
084:             * @param editor the compilation unit editor
085:             */
086:            public AddJavaDocStubAction(CompilationUnitEditor editor) {
087:                this (editor.getEditorSite());
088:                fEditor = editor;
089:                setEnabled(checkEnabledEditor());
090:            }
091:
092:            //---- Structured Viewer -----------------------------------------------------------
093:
094:            /* (non-Javadoc)
095:             * Method declared on SelectionDispatchAction
096:             */
097:            public void selectionChanged(IStructuredSelection selection) {
098:                IMember[] members = getSelectedMembers(selection);
099:                setEnabled(members != null && members.length > 0);
100:            }
101:
102:            /* (non-Javadoc)
103:             * Method declared on SelectionDispatchAction
104:             */
105:            public void run(IStructuredSelection selection) {
106:                IMember[] members = getSelectedMembers(selection);
107:                if (members == null || members.length == 0) {
108:                    return;
109:                }
110:
111:                try {
112:                    ICompilationUnit cu = members[0].getCompilationUnit();
113:                    if (!ActionUtil.isEditable(getShell(), cu)) {
114:                        return;
115:                    }
116:
117:                    // open the editor, forces the creation of a working copy
118:                    IEditorPart editor = JavaUI.openInEditor(cu);
119:
120:                    if (ElementValidator.check(members, getShell(),
121:                            getDialogTitle(), false))
122:                        run(cu, members);
123:                    JavaModelUtil.reconcile(cu);
124:                    EditorUtility.revealInEditor(editor, members[0]);
125:
126:                } catch (CoreException e) {
127:                    ExceptionHandler
128:                            .handle(
129:                                    e,
130:                                    getShell(),
131:                                    getDialogTitle(),
132:                                    ActionMessages.AddJavaDocStubsAction_error_actionFailed);
133:                }
134:            }
135:
136:            //---- Java Editor --------------------------------------------------------------
137:
138:            /* (non-Javadoc)
139:             * Method declared on SelectionDispatchAction
140:             */
141:            public void selectionChanged(ITextSelection selection) {
142:            }
143:
144:            private boolean checkEnabledEditor() {
145:                return fEditor != null
146:                        && SelectionConverter.canOperateOn(fEditor);
147:            }
148:
149:            /* (non-Javadoc)
150:             * Method declared on SelectionDispatchAction
151:             */
152:            public void run(ITextSelection selection) {
153:                try {
154:                    IJavaElement element = SelectionConverter
155:                            .getElementAtOffset(fEditor);
156:                    if (!ActionUtil.isEditable(fEditor, getShell(), element))
157:                        return;
158:                    int type = element != null ? element.getElementType() : -1;
159:                    if (type != IJavaElement.METHOD
160:                            && type != IJavaElement.TYPE
161:                            && type != IJavaElement.FIELD) {
162:                        element = SelectionConverter.getTypeAtOffset(fEditor);
163:                        if (element == null) {
164:                            MessageDialog
165:                                    .openInformation(
166:                                            getShell(),
167:                                            getDialogTitle(),
168:                                            ActionMessages.AddJavaDocStubsAction_not_applicable);
169:                            return;
170:                        }
171:                    }
172:                    IMember[] members = new IMember[] { (IMember) element };
173:                    if (ElementValidator.checkValidateEdit(members, getShell(),
174:                            getDialogTitle()))
175:                        run(members[0].getCompilationUnit(), members);
176:                } catch (CoreException e) {
177:                    ExceptionHandler
178:                            .handle(
179:                                    e,
180:                                    getShell(),
181:                                    getDialogTitle(),
182:                                    ActionMessages.AddJavaDocStubsAction_error_actionFailed);
183:                }
184:            }
185:
186:            //---- Helpers -------------------------------------------------------------------
187:
188:            /**
189:             * Note this method is for internal use only. 
190:             * 
191:             * @param cu the compilation unit
192:             * @param members an array of members
193:             */
194:            public void run(ICompilationUnit cu, IMember[] members) {
195:                try {
196:                    AddJavaDocStubOperation op = new AddJavaDocStubOperation(
197:                            members);
198:                    PlatformUI.getWorkbench().getProgressService().runInUI(
199:                            PlatformUI.getWorkbench().getProgressService(),
200:                            new WorkbenchRunnableAdapter(op, op
201:                                    .getScheduleRule()), op.getScheduleRule());
202:                } catch (InvocationTargetException e) {
203:                    ExceptionHandler
204:                            .handle(
205:                                    e,
206:                                    getShell(),
207:                                    getDialogTitle(),
208:                                    ActionMessages.AddJavaDocStubsAction_error_actionFailed);
209:                } catch (InterruptedException e) {
210:                    // operation canceled
211:                }
212:            }
213:
214:            private IMember[] getSelectedMembers(IStructuredSelection selection) {
215:                List elements = selection.toList();
216:                int nElements = elements.size();
217:                if (nElements > 0) {
218:                    IMember[] res = new IMember[nElements];
219:                    ICompilationUnit cu = null;
220:                    for (int i = 0; i < nElements; i++) {
221:                        Object curr = elements.get(i);
222:                        if (curr instanceof  IMethod || curr instanceof  IType
223:                                || curr instanceof  IField) {
224:                            IMember member = (IMember) curr; // limit to methods, types & fields
225:                            if (!member.exists()) {
226:                                return null;
227:                            }
228:                            if (i == 0) {
229:                                cu = member.getCompilationUnit();
230:                                if (cu == null) {
231:                                    return null;
232:                                }
233:                            } else if (!cu.equals(member.getCompilationUnit())) {
234:                                return null;
235:                            }
236:                            if (member instanceof  IType
237:                                    && member.getElementName().length() == 0) {
238:                                return null; // anonymous type
239:                            }
240:                            res[i] = member;
241:                        } else {
242:                            return null;
243:                        }
244:                    }
245:                    return res;
246:                }
247:                return null;
248:            }
249:
250:            private String getDialogTitle() {
251:                return ActionMessages.AddJavaDocStubsAction_error_dialogTitle;
252:            }
253:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.