ADT #1843641: fix 'Extract string from layout creates blank string'

Issue was that the 2 input fields where only update when the page
was correctly validate.
This commit is contained in:
Raphael
2009-06-29 14:15:02 -07:00
parent 14b3c0c9a4
commit b156e94ff3

View File

@@ -58,8 +58,10 @@ class ExtractStringInputPage extends UserInputWizardPage implements IWizardPage
/** The project where the user selection happened. */ /** The project where the user selection happened. */
private final IProject mProject; private final IProject mProject;
/** Test field where the user enters the new ID to be generated or replaced with. */ /** Text field where the user enters the new ID to be generated or replaced with. */
private Text mStringIdField; private Text mStringIdField;
/** Text field where the user enters the new string value. */
private Text mStringValueField;
/** The configuration selector, to select the resource path of the XML file. */ /** The configuration selector, to select the resource path of the XML file. */
private ConfigurationSelector mConfigSelector; private ConfigurationSelector mConfigSelector;
/** The combo to display the existing XML files or enter a new one. */ /** The combo to display the existing XML files or enter a new one. */
@@ -80,6 +82,7 @@ class ExtractStringInputPage extends UserInputWizardPage implements IWizardPage
private XmlStringFileHelper mXmlHelper = new XmlStringFileHelper(); private XmlStringFileHelper mXmlHelper = new XmlStringFileHelper();
public ExtractStringInputPage(IProject project) { public ExtractStringInputPage(IProject project) {
super("ExtractStringInputPage"); //$NON-NLS-1$ super("ExtractStringInputPage"); //$NON-NLS-1$
mProject = project; mProject = project;
@@ -133,17 +136,15 @@ class ExtractStringInputPage extends UserInputWizardPage implements IWizardPage
String selectedString = ref.getTokenString(); String selectedString = ref.getTokenString();
final Text stringValueField = new Text(group, SWT.SINGLE | SWT.LEFT | SWT.BORDER); mStringValueField = new Text(group, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
stringValueField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); mStringValueField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
stringValueField.setText(selectedString != null ? selectedString : ""); //$NON-NLS-1$ mStringValueField.setText(selectedString != null ? selectedString : ""); //$NON-NLS-1$
ref.setNewStringValue(stringValueField.getText()); ref.setNewStringValue(mStringValueField.getText());
stringValueField.addModifyListener(new ModifyListener() { mStringValueField.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
if (validatePage()) { validatePage();
ref.setNewStringValue(stringValueField.getText());
}
} }
}); });
@@ -170,9 +171,7 @@ class ExtractStringInputPage extends UserInputWizardPage implements IWizardPage
mStringIdField.addModifyListener(new ModifyListener() { mStringIdField.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
if (validatePage()) { validatePage();
ref.setNewStringId(mStringIdField.getText().trim());
}
} }
}); });
} }
@@ -259,11 +258,15 @@ class ExtractStringInputPage extends UserInputWizardPage implements IWizardPage
* Validates fields of the wizard input page. Displays errors as appropriate and * Validates fields of the wizard input page. Displays errors as appropriate and
* enable the "Next" button (or not) by calling {@link #setPageComplete(boolean)}. * enable the "Next" button (or not) by calling {@link #setPageComplete(boolean)}.
* *
* If validation succeeds, this udpates the text id & value in the refactoring object.
*
* @return True if the page has been positively validated. It may still have warnings. * @return True if the page has been positively validated. It may still have warnings.
*/ */
private boolean validatePage() { private boolean validatePage() {
boolean success = true; boolean success = true;
ExtractStringRefactoring ref = getOurRefactoring();
// Analyze fatal errors. // Analyze fatal errors.
String text = mStringIdField.getText().trim(); String text = mStringIdField.getText().trim();
@@ -284,6 +287,11 @@ class ExtractStringInputPage extends UserInputWizardPage implements IWizardPage
break; break;
} }
} }
// update the field in the refactoring object in case of success
if (success) {
ref.setNewStringId(text);
}
} }
String resFile = mResFileCombo.getText(); String resFile = mResFileCombo.getText();
@@ -302,8 +310,6 @@ class ExtractStringInputPage extends UserInputWizardPage implements IWizardPage
if (success) { if (success) {
setErrorMessage(null); setErrorMessage(null);
ExtractStringRefactoring ref = getOurRefactoring();
ref.setTargetFile(resFile); ref.setTargetFile(resFile);
sLastResFilePath.put(mProject.getFullPath().toPortableString(), resFile); sLastResFilePath.put(mProject.getFullPath().toPortableString(), resFile);
@@ -326,6 +332,11 @@ class ExtractStringInputPage extends UserInputWizardPage implements IWizardPage
} }
} }
if (success) {
// Also update the text value in case of success.
ref.setNewStringValue(mStringValueField.getText());
}
setPageComplete(success); setPageComplete(success);
return success; return success;
} }