]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/ui/org/eclipse/jdt/ui/actions/SurroundWithTryMultiCatchAction.java
ce4dc77b951868d6642cacdde14e48c95b981e5d
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / ui / actions / SurroundWithTryMultiCatchAction.java
1 /*******************************************************************************
2  * Copyright (c) 2011 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.ui.actions;
12
13 import org.eclipse.jface.dialogs.MessageDialog;
14
15 import org.eclipse.jface.text.ITextSelection;
16
17 import org.eclipse.jdt.core.ICompilationUnit;
18 import org.eclipse.jdt.core.IJavaProject;
19
20 import org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatchRefactoring;
21 import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
22 import org.eclipse.jdt.internal.corext.util.Messages;
23
24 import org.eclipse.jdt.internal.ui.JavaPlugin;
25 import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
26 import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
27 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
28 import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
29
30 /**
31  * Action to surround a set of statements with a try/multi-catch block.
32  * 
33  * <p>
34  * This class may be instantiated; it is not intended to be subclassed.
35  * </p>
36  * 
37  * @since 3.7.1
38  * 
39  * @noextend This class is not intended to be subclassed by clients.
40  */
41 public class SurroundWithTryMultiCatchAction extends SurroundWithTryCatchAction {
42
43         /**
44          * Note: This constructor is for internal use only. Clients should not call this constructor.
45          * @param editor the compilation unit editor
46          *
47          * @noreference This constructor is not intended to be referenced by clients.
48          */
49         public SurroundWithTryMultiCatchAction(CompilationUnitEditor editor) {
50                 super(editor);
51                 setText(RefactoringMessages.SurroundWithTryMultiCatchAction_label);
52         }
53
54         @Override
55         public void run(ITextSelection selection) {
56                 ICompilationUnit compilationUnit= SelectionConverter.getInputAsCompilationUnit(fEditor);
57                 IJavaProject javaProject= compilationUnit.getJavaProject();
58                 if (!JavaModelUtil.is17OrHigher(javaProject)) {
59                         String message= Messages.format(RefactoringMessages.SurroundWithTryMultiCatchAction_not17, BasicElementLabels.getJavaElementName(javaProject.getElementName()));
60                         MessageDialog.openInformation(JavaPlugin.getActiveWorkbenchShell(), getDialogTitle(), message);
61                         return;
62                 }
63                 super.run(selection);
64         }
65
66         @Override
67         SurroundWithTryCatchRefactoring createRefactoring(ITextSelection selection, ICompilationUnit cu) {
68                 return SurroundWithTryCatchRefactoring.create(cu, selection, true);
69         }
70
71         @Override
72         String getDialogTitle() {
73                 return RefactoringMessages.SurroundWithTryMultiCatchAction_dialog_title;
74         }
75
76         @Override
77         boolean isApplicable() {
78                 if (!super.isApplicable())
79                         return false;
80                 
81                 ICompilationUnit compilationUnit= SelectionConverter.getInputAsCompilationUnit(fEditor);
82                 IJavaProject javaProject= compilationUnit.getJavaProject();
83                 return JavaModelUtil.is17OrHigher(javaProject);
84         }
85
86 }