1 11 package org.eclipse.jdt.internal.ui.refactoring.code; 12 13 import org.eclipse.jdt.core.JavaModelException; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.events.SelectionAdapter; 17 import org.eclipse.swt.events.SelectionEvent; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.Button; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Group; 23 24 import org.eclipse.jface.dialogs.Dialog; 25 26 import org.eclipse.ui.PlatformUI; 27 28 import org.eclipse.jdt.internal.corext.refactoring.code.InlineMethodRefactoring; 29 30 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 31 import org.eclipse.jdt.internal.ui.JavaPluginImages; 32 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; 33 34 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 35 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; 36 37 public class InlineMethodInputPage extends UserInputWizardPage { 38 39 public static final String PAGE_NAME= "InlineMethodInputPage"; private static final String DESCRIPTION = RefactoringMessages.InlineMethodInputPage_description; 41 42 private InlineMethodRefactoring fRefactoring; 43 private Group fInlineMode; 44 private Button fRemove; 45 46 public InlineMethodInputPage() { 47 super(PAGE_NAME); 48 setImageDescriptor(JavaPluginImages.DESC_WIZBAN_REFACTOR_CU); 49 setDescription(DESCRIPTION); 50 } 51 52 public void createControl(Composite parent) { 53 initializeDialogUnits(parent); 54 fRefactoring= (InlineMethodRefactoring)getRefactoring(); 55 56 Composite result= new Composite(parent, SWT.NONE); 57 setControl(result); 58 GridLayout layout= new GridLayout(); 59 result.setLayout(layout); 60 GridData gd= null; 61 62 boolean all= fRefactoring.getInitialMode() == InlineMethodRefactoring.Mode.INLINE_ALL; 63 fInlineMode= new Group(result, SWT.NONE); 64 fInlineMode.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 65 fInlineMode.setLayout(new GridLayout()); 66 fInlineMode.setText(RefactoringMessages.InlineMethodInputPage_inline); 67 68 Button radio= new Button(fInlineMode, SWT.RADIO); 69 radio.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 70 radio.setText(RefactoringMessages.InlineMethodInputPage_all_invocations); 71 radio.setSelection(all); 72 radio.addSelectionListener(new SelectionAdapter() { 73 public void widgetSelected(SelectionEvent event) { 74 fRemove.setEnabled(fRefactoring.canEnableDeleteSource()); 75 if (((Button)event.widget).getSelection()) 76 changeRefactoring(InlineMethodRefactoring.Mode.INLINE_ALL); 77 } 78 }); 79 80 fRemove= new Button(fInlineMode, SWT.CHECK); 81 gd= new GridData(GridData.FILL_HORIZONTAL); 82 gd.horizontalIndent= convertWidthInCharsToPixels(3); 83 fRemove.setLayoutData(gd); 84 fRemove.setText(RefactoringMessages.InlineMethodInputPage_delete_declaration); 85 fRemove.setEnabled(all && fRefactoring.canEnableDeleteSource()); 86 fRemove.setSelection(fRefactoring.canEnableDeleteSource()); 87 fRefactoring.setDeleteSource(fRefactoring.canEnableDeleteSource()); 88 fRemove.addSelectionListener(new SelectionAdapter() { 89 public void widgetSelected(SelectionEvent e) { 90 fRefactoring.setDeleteSource(((Button)e.widget).getSelection()); 91 } 92 }); 93 94 95 radio= new Button(fInlineMode, SWT.RADIO); 96 radio.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 97 radio.setText(RefactoringMessages.InlineMethodInputPage_only_selected); 98 radio.setSelection(!all); 99 if (all) { 100 radio.setEnabled(false); 101 } 102 radio.addSelectionListener(new SelectionAdapter() { 103 public void widgetSelected(SelectionEvent event) { 104 fRemove.setEnabled(false); 105 if (((Button)event.widget).getSelection()) 106 changeRefactoring(InlineMethodRefactoring.Mode.INLINE_SINGLE); 107 } 108 }); 109 Dialog.applyDialogFont(result); 110 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.INLINE_METHOD_WIZARD_PAGE); 111 } 112 113 private void changeRefactoring(InlineMethodRefactoring.Mode mode) { 114 RefactoringStatus status; 115 try { 116 status= fRefactoring.setCurrentMode(mode); 117 } catch (JavaModelException e) { 118 status= RefactoringStatus.createFatalErrorStatus(e.getMessage()); 119 } 120 setPageComplete(status); 121 } 122 } 123 | Popular Tags |