private void updateStringValueCombo() { String resFile = mResFileCombo.getText(); Map<String, String> ids = mXmlHelper.getResIdsForFile(mProject, resFile); // get the current text from the combo, to make sure we don't change it String currText = mStringIdCombo.getText(); // erase the choices and fill with the given ids mStringIdCombo.removeAll(); mStringIdCombo.setItems(ids.keySet().toArray(new String[ids.size()])); // set the current text to preserve it in case it changed if (!currText.equals(mStringIdCombo.getText())) { mStringIdCombo.setText(currText); } }
/** * Validates fields of the wizard input page. Displays errors as appropriate and enable the "Next" * button (or not) by calling {@link #setPageComplete(boolean)}. * * <p>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. */ private boolean validatePage() { boolean success = true; ExtractStringRefactoring ref = getOurRefactoring(); // Analyze fatal errors. String text = mStringIdCombo.getText().trim(); if (text == null || text.length() < 1) { setErrorMessage("Please provide a resource ID."); success = false; } else { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); boolean ok = i == 0 ? Character.isJavaIdentifierStart(c) : Character.isJavaIdentifierPart(c); if (!ok) { setErrorMessage( String.format( "The resource ID must be a valid Java identifier. The character %1$c at position %2$d is not acceptable.", c, i + 1)); success = false; break; } } // update the field in the refactoring object in case of success if (success) { ref.setNewStringId(text); } } String resFile = mResFileCombo.getText(); if (success) { if (resFile == null || resFile.length() == 0) { setErrorMessage("A resource file name is required."); success = false; } else if (!RES_XML_FILE_REGEX.matcher(resFile).matches()) { setErrorMessage("The XML file name is not valid."); success = false; } } // Analyze info & warnings. if (success) { setErrorMessage(null); ref.setTargetFile(resFile); sLastResFilePath.put(mProject.getFullPath().toPortableString(), resFile); String idValue = mXmlHelper.valueOfStringId(mProject, resFile, text); if (idValue != null) { String msg = String.format( "%1$s already contains a string ID '%2$s' with value '%3$s'.", resFile, text, idValue); if (ref.getMode() == ExtractStringRefactoring.Mode.SELECT_NEW_ID) { setErrorMessage(msg); success = false; } else { setMessage(msg, WizardPage.WARNING); } } else if (mProject.findMember(resFile) == null) { setMessage( String.format("File %2$s does not exist and will be created.", text, resFile), WizardPage.INFORMATION); } else { setMessage(null); } } if (success) { // Also update the text value in case of success. ref.setNewStringValue(mStringValueField.getText()); } setPageComplete(success); return success; }