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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.ui.actions;
13 import org.eclipse.jface.dialogs.MessageDialog;
15 import org.eclipse.jface.text.ITextSelection;
17 import org.eclipse.jdt.core.ICompilationUnit;
18 import org.eclipse.jdt.core.IJavaProject;
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;
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;
31 * Action to surround a set of statements with a try/multi-catch block.
34 * This class may be instantiated; it is not intended to be subclassed.
39 * @noextend This class is not intended to be subclassed by clients.
41 public class SurroundWithTryMultiCatchAction extends SurroundWithTryCatchAction {
44 * Note: This constructor is for internal use only. Clients should not call this constructor.
45 * @param editor the compilation unit editor
47 * @noreference This constructor is not intended to be referenced by clients.
49 public SurroundWithTryMultiCatchAction(CompilationUnitEditor editor) {
51 setText(RefactoringMessages.SurroundWithTryMultiCatchAction_label);
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);
67 SurroundWithTryCatchRefactoring createRefactoring(ITextSelection selection, ICompilationUnit cu) {
68 return SurroundWithTryCatchRefactoring.create(cu, selection, true);
72 String getDialogTitle() {
73 return RefactoringMessages.SurroundWithTryMultiCatchAction_dialog_title;
77 boolean isApplicable() {
78 if (!super.isApplicable())
81 ICompilationUnit compilationUnit= SelectionConverter.getInputAsCompilationUnit(fEditor);
82 IJavaProject javaProject= compilationUnit.getJavaProject();
83 return JavaModelUtil.is17OrHigher(javaProject);