1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.adt.internal.editors.layout.refactoring;
18 
19 import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate;
20 
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
23 import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
24 
25 /**
26  * Action executed when the "Wrap In" menu item is invoked.
27  */
28 public class WrapInAction extends VisualRefactoringAction {
29     @Override
run(IAction action)30     public void run(IAction action) {
31         if ((mTextSelection != null || mTreeSelection != null) && mFile != null) {
32             WrapInRefactoring ref = new WrapInRefactoring(mFile, mDelegate,
33                     mTextSelection, mTreeSelection);
34             RefactoringWizard wizard = new WrapInWizard(ref, mDelegate);
35             RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
36             try {
37                 op.run(mWindow.getShell(), wizard.getDefaultPageTitle());
38             } catch (InterruptedException e) {
39                 // Interrupted. Pass.
40             }
41         }
42     }
43 
create(LayoutEditorDelegate editorDelegate)44     public static IAction create(LayoutEditorDelegate editorDelegate) {
45         return create("Wrap in Container...", editorDelegate, WrapInAction.class);
46     }
47 }
48