1 11 12 package org.eclipse.jdt.internal.ui.refactoring; 13 14 import org.eclipse.core.runtime.Assert; 15 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.events.ModifyEvent; 18 import org.eclipse.swt.events.ModifyListener; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Text; 21 22 23 import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler; 24 25 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 26 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; 27 28 33 public abstract class TextInputWizardPage extends UserInputWizardPage{ 34 35 private String fInitialValue; 36 private Text fTextField; 37 38 public static final String PAGE_NAME= "TextInputPage"; 40 45 public TextInputWizardPage(String description, boolean isLastUserPage) { 46 this(description, isLastUserPage, ""); } 48 49 55 public TextInputWizardPage(String description, boolean isLastUserPage, String initialValue) { 56 super(PAGE_NAME); 57 Assert.isNotNull(initialValue); 58 setDescription(description); 59 fInitialValue= initialValue; 60 } 61 62 68 protected boolean isInitialInputValid(){ 69 return false; 70 } 71 72 78 protected boolean isEmptyInputValid(){ 79 return false; 80 } 81 82 88 protected String getText() { 89 if (fTextField == null) 90 return null; 91 return fTextField.getText(); 92 } 93 94 98 protected void setText(String text) { 99 if (fTextField == null) 100 return; 101 fTextField.setText(text); 102 } 103 104 109 protected Text getTextField() { 110 return fTextField; 111 } 112 113 118 public String getInitialValue() { 119 return fInitialValue; 120 } 121 122 127 protected RefactoringStatus validateTextField(String text){ 128 return null; 129 } 130 131 protected Text createTextInputField(Composite parent) { 132 return createTextInputField(parent, SWT.BORDER); 133 } 134 135 protected Text createTextInputField(Composite parent, int style) { 136 fTextField= new Text(parent, style); 137 fTextField.addModifyListener(new ModifyListener() { 138 public void modifyText(ModifyEvent e) { 139 textModified(getText()); 140 } 141 }); 142 fTextField.setText(fInitialValue); 143 TextFieldNavigationHandler.install(fTextField); 144 return fTextField; 145 } 146 147 151 protected void textModified(String text) { 152 if (! isEmptyInputValid() && "".equals(text)){ setPageComplete(false); 154 setErrorMessage(null); 155 restoreMessage(); 156 return; 157 } 158 if ((! isInitialInputValid()) && fInitialValue.equals(text)){ 159 setPageComplete(false); 160 setErrorMessage(null); 161 restoreMessage(); 162 return; 163 } 164 165 RefactoringStatus status= validateTextField(text); 166 if (status == null) 167 status= new RefactoringStatus(); 168 setPageComplete(status); 169 } 170 171 176 protected void restoreMessage(){ 177 setMessage(null); 178 } 179 180 183 public void dispose() { 184 fTextField= null; 185 } 186 187 190 public void setVisible(boolean visible) { 191 if (visible) { 192 textModified(getText()); 193 } 194 super.setVisible(visible); 195 if (visible && fTextField != null) { 196 fTextField.setFocus(); 197 } 198 } 199 } 200 | Popular Tags |