Bug 151469 - [Preferences] StringFieldEditor claims to allow subclassing, but prevents it
Summary: [Preferences] StringFieldEditor claims to allow subclassing, but prevents it
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows XP
: P5 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: hasPatch
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2006-07-21 16:59 EDT by Paul E. Keyser CLA
Modified: 2013-09-24 15:00 EDT (History)
2 users (show)

See Also:


Attachments
proposed patch for StringFieldEditor (15.42 KB, patch)
2007-06-28 21:52 EDT, Paul E. Keyser CLA
no flags Details | Diff
test-case #1 (example subclass) for patch (3.70 KB, application/octet-stream)
2007-06-28 21:54 EDT, Paul E. Keyser CLA
no flags Details
test-case #2 (example subclass) for patch (5.32 KB, application/octet-stream)
2007-06-28 21:57 EDT, Paul E. Keyser CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paul E. Keyser CLA 2006-07-21 16:59:15 EDT
Try subclassing -- there are only about two or three methods that can be overridden since nearly all methods use private fields. 

E.g., I wanted to experiment with an alternate validation strategy, which should only require a new c'tor, and overriding "Text getTextControl(Composite parent)" and "void setValidateStrategy(int value)". But because those methods (and the c'tor) use *private* fields, one has to copy all those fields and all the methods that use them, and then all the fields *those* methods use, plus all the methods that use that second set of fields; the transitive closure is the entire class except for: "void setEnabled(boolean enabled, Composite parent)" and "int getNumberOfControls()"

(And then in the end, something else goes wrong and the result has a 0-width text-field. Ugh.) 

So, please either make all the fields protected, or at least remove from the javadoc the claim that the class can be subclassed.
Comment 1 Paul Webster CLA 2006-07-28 09:57:10 EDT
I see 10 protected methods + a number of public ... it can be subclassed.

This is an enhancement request to try provide different validation strategies over the provided VALIDATE_ON_KEY_STROKE and VALIDATE_ON_FOCUS_LOST.

PW
Comment 2 Tod Creasey CLA 2007-06-13 16:21:41 EDT
There are currently no plans to work on this however I would be happy to look over a contribution
Comment 3 Paul E. Keyser CLA 2007-06-19 16:46:34 EDT
(In reply to comment #2)
> There are currently no plans to work on this however I would be happy to look
> over a contribution
> 
I am currently on vacation, but could work on this in July/August. There are indeed a bunch of protected methods etc., but some of them use *private* members... My contribution would deal with that. If that sounds good to you, I will provide more details and re-open in July/Aug?

Paul K 
Comment 4 Tod Creasey CLA 2007-06-19 17:04:32 EDT
Sure.
Comment 5 Paul E. Keyser CLA 2007-06-26 16:08:54 EDT
(In reply to comment #4)
> Sure.
> 
How important is it that I keep to the coding style implied by the current state of StringFieldEditor? (E.g., it gives all but one of its methods in alpha order -- but other Eclipse code follows other conventions.)
Comment 6 Tod Creasey CLA 2007-06-26 16:15:34 EDT
The order was not a convention - just someone hitting sort. Not to worry.
Comment 7 Paul E. Keyser CLA 2007-06-27 20:21:00 EDT
Tod -- 

Sooner than I expected, I have this ready -- (1) modified StringFieldEditor, plus (2) two example extensions (InetAddress.. and Regex...) showing how/why to allow subclasses to "extend" the validation-scheme. 

So -- how to submit? reopen the bug (and perhaps rename in some way), and attach the java files? (They are stuffed in some random package-of-convenience in one of my projects.) 
Comment 8 Tod Creasey CLA 2007-06-28 08:49:21 EDT
Please feel free to reopen and attach your patch. I'll try and get to it in the milestone you attach it in.
Comment 9 Paul E. Keyser CLA 2007-06-28 21:52:52 EDT
Created attachment 72750 [details]
proposed patch for StringFieldEditor

NOTE: the class was created in my own package (since I do not have the Eclipse code checked out) -- you'll need to change the package (and perhaps organize imports).
Comment 10 Paul E. Keyser CLA 2007-06-28 21:54:49 EDT
Created attachment 72752 [details]
test-case #1 (example subclass) for patch

This subclass allows the user to enter a regex, but does not validate until the user presses ENTER or UP or DOWN (since validating on each keystroke would be intrusive/annoying, as most partial regex's are invalid).
Comment 11 Paul E. Keyser CLA 2007-06-28 21:57:21 EDT
Created attachment 72753 [details]
test-case #2 (example subclass) for patch

This subclass allows the user to enter an InetAddress, either numerical or textual, but does not validate until the user presses ENTER or UP or DOWN -- since valdation is usually lengthy and validating on each keystroke would be annoying; validating on loss-of-focus would also be annoying, since the error-message would not appear until the user re-focussed. (One might think of placing a "wait" message as a temporary error-message, or else asking that pref-pages be like wizards and have a progress-mon available.)
Comment 12 Tod Creasey CLA 2007-09-28 15:03:47 EDT
Paul comment #9 isn't a patch - it is a whole class. Could you attach a patch against HEAD please? As this bug is against 3.1.2 I need to see it as compared to the current codebase.
Comment 13 Paul E. Keyser CLA 2007-10-03 08:32:49 EDT
(In reply to comment #12)
> Paul comment #9 isn't a patch - it is a whole class. Could you attach a patch
> against HEAD please? As this bug is against 3.1.2 I need to see it as compared
> to the current codebase.
> 
Oops, didn't think of patch as in the special file. My problem with that is that I do not have the code checked out -- can you give me a pointer to how to do that? (I dunno the values I should enter in the "Define Repository" dialog, nor how to find that data on the Eclipse.org webpage.) I presume I need an id/pwd which I also lack. 
Comment 14 Paul Webster CLA 2007-10-03 08:49:45 EDT
There is a CVS HOWTO off of http://www.eclipse.org/ but basically you want

dev.eclipse.org
anonymous
/cvsroot/eclipse
pserver

If you go to the bottom of HEAD, there is a module called platform-ui that you can check out that will give you most of the Platform UI plugins.

From there you can make your changes, self host, and create a patch.

PW
Comment 15 Susan McCourt CLA 2009-07-09 19:28:08 EDT
As per http://wiki.eclipse.org/Platform_UI/Bug_Triage_Change_2009
Comment 16 Paul Webster CLA 2013-09-24 15:00:01 EDT
The StringFieldEditor code is now in http://git.eclipse.org/c/platform/eclipse.platform.ui.git

I tried to just overwrite the StringFieldEditor with the class from comment #9 but it looks like the methods have been re-sorted so I can't consume that.

PW