Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 254972 - [ds tooling] Service Component wizard: Improve field validation
Summary: [ds tooling] Service Component wizard: Improve field validation
Status: RESOLVED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M4   Edit
Assignee: Chris Aniszczyk CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-11 22:00 EST by Simon Archer CLA
Modified: 2008-12-08 12:20 EST (History)
2 users (show)

See Also:


Attachments
DSFileWizard update (4.34 KB, patch)
2008-11-19 10:06 EST, Rafael Oliveira Nóbrega CLA
no flags Details | Diff
DSFileWizard updates (4.39 KB, patch)
2008-11-19 11:23 EST, Rafael Oliveira Nóbrega CLA
caniszczyk: iplog+
Details | Diff
mylyn/context/zip (631 bytes, application/octet-stream)
2008-12-08 12:20 EST, Chris Aniszczyk CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Archer CLA 2008-11-11 22:00:09 EST
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.
Comment 1 Rafael Oliveira Nóbrega CLA 2008-11-18 17:39:03 EST
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 "$"?
Comment 2 Simon Archer CLA 2008-11-18 19:08:33 EST
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.
Comment 3 Danail Nachev CLA 2008-11-19 02:53:49 EST
IWorkspace.validateName(String) can be used to validate file names.
Comment 4 Rafael Oliveira Nóbrega CLA 2008-11-19 10:06:18 EST
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?
Comment 5 Simon Archer CLA 2008-11-19 11:01:27 EST
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.
Comment 6 Rafael Oliveira Nóbrega CLA 2008-11-19 11:23:20 EST
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();
+	}
Comment 7 Simon Archer CLA 2008-11-19 11:37:18 EST
The latest patch works great!  Thanks Rafael.
Comment 8 Chris Aniszczyk CLA 2008-12-08 12:19:59 EST
done.

> 20081208

Thanks Rafael and Simon!
Comment 9 Chris Aniszczyk CLA 2008-12-08 12:20:03 EST
Created attachment 119820 [details]
mylyn/context/zip