Community
Participate
Working Groups
Using Eclipse 3.5M3. Extracted from bug 253635. The error message "Names cannot be empty." is not particularly helpful, plus, once you've entered something in the "Field name:" and "Name:" field there is no error message telling you to populate the "Class:" field, and the "Finish" button remains disabled. We also need some improvements to the field validation, since entering nonsense values, such as spaces seems to satisfy the field validation.
The Error Message: "Names cannot be empty." came from org.eclipse.ui.dialogs.WizardNewFileCreationPage validatePage() method. Should I override this method? Or extend another Class? What should of Class Name validation should we implement? Verify if it begins with Letter, Underscore or "$"?
Regarding the error message "Names cannot be empty.": I would be inclined to just leave it alone since it comes from elsewhere. Maybe this error message should be fixed separately, rather than in PDE. Regarding the class name validation: I've done this before using Character.isJavaIdentifierStart(char) and Character.isJavaIdentifierPart(char). I have also used org.eclipse.core.internal.resources.OS.isNameValid(String), but it's internal API, so use it at your peril. This method is great for validating anything that results in a file being created in the local file system, since there are only specific file name patterns that are legal. Take a peek at the OS class and you'll get the idea.
IWorkspace.validateName(String) can be used to validate file names.
Created attachment 118256 [details] DSFileWizard update Done. I used the IWorkspace.validateName() as suggested by Danail, thanks!! :) I also added a validatePage() call into ModifyListener methods. Thus, everytime we modify the textboxes, the page will be validated and the error messages will be shown. Simon, what do you think? Is that ok? I don't like that message too, I think we could override the common validation and call super.validatePage() only if we didn't find any error. What do you think?
Yes, using IWorkspace.validateName(String) seems to be the right way to go! So, I have tried out the latest patch and it works pretty well. The only problem I found was that we need to call setPageComplete(boolean) when the "File name:" field changes, since today you can enter an illegal file name (such as "con" on Windows), get an error message displayed, AND still have the Finish button enabled. Of course, clicking the Finish button results in some nasty lower-level file creation error dialogs that we certainly do not want. I think the right thing to do here is to move the call to setPageComplete(boolean) into the validatePage() method and the checkPageComplete() method, instead of calling it from the ModifyListeners.
Created attachment 118278 [details] DSFileWizard updates Ok, I changed the place where we call validatePage(). Now, I think it's working fine! public boolean isPageComplete() { - return checkPageComplete(); + return checkPageComplete() & validatePage(); + }
The latest patch works great! Thanks Rafael.
done. > 20081208 Thanks Rafael and Simon!
Created attachment 119820 [details] mylyn/context/zip