1 11 package org.eclipse.jdt.internal.ui.refactoring; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.events.ModifyEvent; 15 import org.eclipse.swt.events.ModifyListener; 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.Label; 23 import org.eclipse.swt.widgets.Text; 24 25 import org.eclipse.jface.dialogs.Dialog; 26 27 import org.eclipse.ui.PlatformUI; 28 29 import org.eclipse.ltk.core.refactoring.Refactoring; 30 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 31 import org.eclipse.ltk.ui.refactoring.RefactoringWizard; 32 33 import org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring; 34 35 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 36 37 public class MoveInnerToTopWizard extends RefactoringWizard { 38 39 private class MoveInnerToToplnputPage extends TextInputWizardPage { 40 41 private Text fFieldNameEntryText; 42 43 private Label fFieldNameLabel; 44 45 private Button fFinalCheckBox; 46 47 private final boolean fInitialInputValid; 48 49 public MoveInnerToToplnputPage(String initialValue) { 50 super(RefactoringMessages.MoveInnerToToplnputPage_description, true, initialValue); 51 final MoveInnerToTopRefactoring refactoring= getMoveRefactoring(); 52 final boolean mandatory= refactoring.isCreatingInstanceFieldMandatory(); 53 fInitialInputValid= (!initialValue.equals("")) || !mandatory; if (!mandatory) 55 refactoring.setCreateInstanceField(false); 56 } 57 58 private void addFieldNameEntry(Composite newControl) { 59 fFieldNameLabel= new Label(newControl, SWT.NONE); 60 if (getMoveRefactoring().isCreatingInstanceFieldMandatory()) 61 fFieldNameLabel.setText(RefactoringMessages.MoveInnerToToplnputPage_enter_name_mandatory); 62 else 63 fFieldNameLabel.setText(RefactoringMessages.MoveInnerToToplnputPage_enter_name); 64 fFieldNameLabel.setLayoutData(new GridData()); 65 66 fFieldNameEntryText= createTextInputField(newControl); 67 fFieldNameEntryText.selectAll(); 68 fFieldNameEntryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 69 } 70 71 private void addFinalCheckBox(Composite newControl) { 72 fFinalCheckBox= new Button(newControl, SWT.CHECK); 73 fFinalCheckBox.setText(RefactoringMessages.MoveInnerToToplnputPage_instance_final); 74 GridData data= new GridData(GridData.FILL_HORIZONTAL); 75 data.horizontalSpan= 2; 76 fFinalCheckBox.setLayoutData(data); 77 fFinalCheckBox.addSelectionListener(new SelectionAdapter() { 78 79 public void widgetSelected(SelectionEvent event) { 80 getMoveRefactoring().setMarkInstanceFieldAsFinal(fFinalCheckBox.getSelection()); 81 } 82 }); 83 fFieldNameEntryText.addModifyListener(new ModifyListener() { 84 85 public final void modifyText(ModifyEvent event) { 86 final String text= fFieldNameEntryText.getText(); 87 final MoveInnerToTopRefactoring refactoring= getMoveRefactoring(); 88 if (refactoring.isCreatingInstanceFieldMandatory()) 89 setPageComplete(validateTextField(text)); 90 final boolean empty= text.length() == 0; 91 if (refactoring.isCreatingInstanceFieldMandatory()) { 92 } else if (refactoring.isCreatingInstanceFieldPossible()) { 94 fFinalCheckBox.setEnabled(!empty); 95 } 96 if (!refactoring.isCreatingInstanceFieldMandatory()) 97 refactoring.setCreateInstanceField(!empty); 98 } 99 }); 100 } 101 102 public void createControl(Composite parent) { 103 initializeDialogUnits(parent); 104 Composite newControl= new Composite(parent, SWT.NONE); 105 setControl(newControl); 106 PlatformUI.getWorkbench().getHelpSystem().setHelp(newControl, IJavaHelpContextIds.MOVE_INNER_TO_TOP_WIZARD_PAGE); 107 newControl.setLayout(new GridLayout()); 108 Dialog.applyDialogFont(newControl); 109 110 GridLayout layout= new GridLayout(); 111 layout.numColumns= 2; 112 layout.verticalSpacing= 8; 113 newControl.setLayout(layout); 114 115 addFieldNameEntry(newControl); 116 addFinalCheckBox(newControl); 117 118 if (getMoveRefactoring().isCreatingInstanceFieldPossible()) { 119 fFinalCheckBox.setSelection(getMoveRefactoring().isInstanceFieldMarkedFinal()); 120 fFinalCheckBox.setEnabled(true); 121 } else { 122 fFinalCheckBox.setSelection(false); 123 fFinalCheckBox.setEnabled(false); 124 } 125 } 126 127 130 protected boolean isEmptyInputValid() { 131 return !getMoveRefactoring().isCreatingInstanceFieldMandatory(); 132 } 133 134 137 protected boolean isInitialInputValid() { 138 return fInitialInputValid; 139 } 140 141 144 public void setVisible(boolean visible) { 145 super.setVisible(visible); 146 if (visible) { 147 String message= getMoveRefactoring().isCreatingInstanceFieldMandatory() ? RefactoringMessages.MoveInnerToToplnputPage_mandatory_info : RefactoringMessages.MoveInnerToToplnputPage_optional_info; 148 setPageComplete(RefactoringStatus.createInfoStatus(message)); 149 } else { 150 setPageComplete(new RefactoringStatus()); 151 getContainer().updateMessage(); 152 } 153 } 154 155 158 protected RefactoringStatus validateTextField(String text) { 159 final MoveInnerToTopRefactoring refactoring= getMoveRefactoring(); 160 refactoring.setEnclosingInstanceName(text); 161 if (refactoring.isCreatingInstanceFieldMandatory()) 162 return refactoring.checkEnclosingInstanceName(text); 163 else if (!text.equals("")) return refactoring.checkEnclosingInstanceName(text); 165 else 166 return new RefactoringStatus(); 167 } 168 } 169 170 public MoveInnerToTopWizard(Refactoring refactoring) { 171 super(refactoring, DIALOG_BASED_USER_INTERFACE); 172 setDefaultPageTitle(RefactoringMessages.MoveInnerToTopWizard_Move_Inner); 173 } 174 175 178 protected void addUserInputPages() { 179 final MoveInnerToTopRefactoring refactoring= getMoveRefactoring(); 180 if (refactoring.isCreatingInstanceFieldPossible()) 181 addPage(new MoveInnerToToplnputPage(refactoring.isCreatingInstanceFieldMandatory() ? refactoring.getEnclosingInstanceName() : "")); else 183 setChangeCreationCancelable(false); 184 } 185 186 private MoveInnerToTopRefactoring getMoveRefactoring() { 187 return (MoveInnerToTopRefactoring) getRefactoring(); 188 } 189 } 190 | Popular Tags |