Source Code Cross Referenced for SurroundWithTryCatchAction.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:         *     Sebastian Davids - Fixed bug 25898
011:         *******************************************************************************/package org.eclipse.jdt.ui.actions;
012:
013:        import java.lang.reflect.InvocationTargetException;
014:
015:        import org.eclipse.core.runtime.CoreException;
016:        import org.eclipse.core.runtime.NullProgressMonitor;
017:
018:        import org.eclipse.swt.widgets.Button;
019:        import org.eclipse.swt.widgets.Composite;
020:        import org.eclipse.swt.widgets.Shell;
021:
022:        import org.eclipse.jface.dialogs.IDialogConstants;
023:        import org.eclipse.jface.dialogs.MessageDialog;
024:
025:        import org.eclipse.jface.text.ITextSelection;
026:
027:        import org.eclipse.ui.PlatformUI;
028:
029:        import org.eclipse.ltk.core.refactoring.Change;
030:        import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
031:        import org.eclipse.ltk.core.refactoring.RefactoringStatus;
032:        import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
033:        import org.eclipse.ltk.ui.refactoring.RefactoringUI;
034:
035:        import org.eclipse.jdt.core.ICompilationUnit;
036:        import org.eclipse.jdt.core.ISourceRange;
037:
038:        import org.eclipse.jdt.internal.corext.refactoring.base.JavaStatusContext;
039:        import org.eclipse.jdt.internal.corext.refactoring.surround.ISurroundWithTryCatchQuery;
040:        import org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatchRefactoring;
041:
042:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
043:        import org.eclipse.jdt.internal.ui.actions.ActionUtil;
044:        import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
045:        import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
046:        import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
047:        import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
048:        import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
049:        import org.eclipse.jdt.internal.ui.util.ElementValidator;
050:        import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
051:
052:        /**
053:         * Action to surround a set of statements with a try/catch block.
054:         * 
055:         * <p>
056:         * This class may be instantiated; it is not intended to be subclassed.
057:         * </p>
058:         * 
059:         * @since 2.0
060:         */
061:        public class SurroundWithTryCatchAction extends SelectionDispatchAction {
062:
063:            private CompilationUnitEditor fEditor;
064:
065:            private static class Query implements  ISurroundWithTryCatchQuery {
066:                private Shell fParent;
067:
068:                public Query(Shell shell) {
069:                    fParent = shell;
070:                }
071:
072:                public boolean catchRuntimeException() {
073:                    MessageDialog dialog = new MessageDialog(
074:                            fParent,
075:                            getDialogTitle(),
076:                            null, // accept the default window icon
077:                            RefactoringMessages.SurroundWithTryCatchAction_no_exceptions,
078:                            MessageDialog.QUESTION, new String[] {
079:                                    IDialogConstants.YES_LABEL,
080:                                    IDialogConstants.NO_LABEL }, 1) {
081:                        // Work around for http://dev.eclipse.org/bugs/show_bug.cgi?id=18303
082:                        protected void createButtonsForButtonBar(
083:                                Composite parent) {
084:                            super .createButtonsForButtonBar(parent);
085:                            Button button = getButton(1);
086:                            if (button != null)
087:                                button.setFocus();
088:                        }
089:                    };
090:                    return dialog.open() == 0; // yes selected
091:                }
092:            }
093:
094:            /**
095:             * Note: This constructor is for internal use only. Clients should not call this constructor.
096:             * @param editor the compilation unit editor
097:             */
098:            public SurroundWithTryCatchAction(CompilationUnitEditor editor) {
099:                super (editor.getEditorSite());
100:                setText(RefactoringMessages.SurroundWithTryCatchAction_label);
101:                fEditor = editor;
102:                setEnabled((fEditor != null && SelectionConverter
103:                        .getInputAsCompilationUnit(fEditor) != null));
104:                PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
105:                        IJavaHelpContextIds.SURROUND_WITH_TRY_CATCH_ACTION);
106:            }
107:
108:            public void run(ITextSelection selection) {
109:                if (!ActionUtil.isEditable(fEditor))
110:                    return;
111:                ICompilationUnit cu = SelectionConverter
112:                        .getInputAsCompilationUnit(fEditor);
113:                if (cu == null
114:                        || !ElementValidator.checkValidateEdit(cu, getShell(),
115:                                getDialogTitle()))
116:                    return;
117:                SurroundWithTryCatchRefactoring refactoring = SurroundWithTryCatchRefactoring
118:                        .create(cu, selection, new Query(getShell()));
119:
120:                if (refactoring == null)
121:                    return;
122:                try {
123:                    RefactoringStatus status = refactoring
124:                            .checkInitialConditions(new NullProgressMonitor());
125:                    if (status.hasFatalError()) {
126:                        RefactoringStatusEntry entry = status
127:                                .getEntryMatchingSeverity(RefactoringStatus.FATAL);
128:                        MessageDialog.openInformation(getShell(),
129:                                getDialogTitle(), entry.getMessage());
130:                        if (entry.getContext() instanceof  JavaStatusContext
131:                                && fEditor != null) {
132:                            JavaStatusContext context = (JavaStatusContext) entry
133:                                    .getContext();
134:                            ISourceRange range = context.getSourceRange();
135:                            fEditor.setHighlightRange(range.getOffset(), range
136:                                    .getLength(), true);
137:                        }
138:                        return;
139:                    }
140:                    if (refactoring.stopExecution())
141:                        return;
142:                    Change change = refactoring
143:                            .createChange(new NullProgressMonitor());
144:                    change.initializeValidationData(new NullProgressMonitor());
145:                    PerformChangeOperation op = RefactoringUI
146:                            .createUIAwareChangeOperation(change);
147:                    // must be fork == false since file buffers can't be manipulated in a different thread.
148:                    WorkbenchRunnableAdapter adapter = new WorkbenchRunnableAdapter(
149:                            op);
150:                    PlatformUI.getWorkbench().getProgressService().runInUI(
151:                            new BusyIndicatorRunnableContext(), adapter,
152:                            adapter.getSchedulingRule());
153:                } catch (CoreException e) {
154:                    ExceptionHandler
155:                            .handle(
156:                                    e,
157:                                    getDialogTitle(),
158:                                    RefactoringMessages.SurroundWithTryCatchAction_exception);
159:                } catch (InvocationTargetException e) {
160:                    ExceptionHandler
161:                            .handle(
162:                                    e,
163:                                    getDialogTitle(),
164:                                    RefactoringMessages.SurroundWithTryCatchAction_exception);
165:                } catch (InterruptedException e) {
166:                    // not cancelable
167:                }
168:            }
169:
170:            public void selectionChanged(ITextSelection selection) {
171:                setEnabled(selection.getLength() > 0
172:                        && (fEditor != null && SelectionConverter
173:                                .getInputAsCompilationUnit(fEditor) != null));
174:            }
175:
176:            private static String getDialogTitle() {
177:                return RefactoringMessages.SurroundWithTryCatchAction_dialog_title;
178:            }
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.