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 package com.android.ide.eclipse.adt.internal.editors.layout.refactoring; 17 18 import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate; 19 20 import org.eclipse.ltk.core.refactoring.Refactoring; 21 import org.eclipse.ltk.ui.refactoring.RefactoringWizard; 22 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; 23 import org.eclipse.swt.events.ModifyEvent; 24 import org.eclipse.swt.events.ModifyListener; 25 import org.eclipse.swt.events.SelectionAdapter; 26 import org.eclipse.swt.events.SelectionEvent; 27 28 public abstract class VisualRefactoringWizard extends RefactoringWizard { 29 protected final LayoutEditorDelegate mDelegate; 30 31 public VisualRefactoringWizard(Refactoring refactoring, LayoutEditorDelegate editor) { 32 super(refactoring, DIALOG_BASED_USER_INTERFACE | PREVIEW_EXPAND_FIRST_NODE); 33 mDelegate = editor; 34 } 35 36 @Override 37 public boolean performFinish() { 38 mDelegate.getEditor().setIgnoreXmlUpdate(true); 39 try { 40 return super.performFinish(); 41 } finally { 42 mDelegate.getEditor().setIgnoreXmlUpdate(false); 43 mDelegate.refreshXmlModel(); 44 } 45 } 46 47 protected abstract static class VisualRefactoringInputPage extends UserInputWizardPage { 48 public VisualRefactoringInputPage(String name) { 49 super(name); 50 } 51 52 /** 53 * Listener which can be attached on any widget in the wizard page to force 54 * modifications of the associated widget to validate the page again 55 */ 56 protected ModifyListener mModifyValidateListener = new ModifyListener() { 57 @Override 58 public void modifyText(ModifyEvent e) { 59 validatePage(); 60 } 61 }; 62 63 /** 64 * Listener which can be attached on any widget in the wizard page to force 65 * selection changes of the associated widget to validate the page again 66 */ 67 protected SelectionAdapter mSelectionValidateListener = new SelectionAdapter() { 68 @Override 69 public void widgetSelected(SelectionEvent e) { 70 validatePage(); 71 } 72 }; 73 74 protected abstract boolean validatePage(); 75 } 76 } 77