Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 22261

Summary: SWT should support a tri-state check box
Product: [Eclipse Project] Platform Reporter: Olaf Kindel <ok2>
Component: SWTAssignee: Steve Northover <snorthov>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: alamothe, arnaud.chassagne, bogofilter+eclipse.org, bradleyjames, chs, cocoakevin, daniel.kruegler, eclipse.felipe, eclipse, evgeniyos, hudsonr, IngedevTeam.fr, mark.melvin, mlists, mm, mseele, oleg.krasilnikov, pombredanne, rohit_1004, roman.porotnikov
Version: 2.0Keywords: helpwanted
Target Milestone: 3.4 M5   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 182450    
Attachments:
Description Flags
Windows Folder Attributes
none
Display Properties/Effects
none
FrontPage Table Cell Properties
none
Tristate check box
none
TriButton: possible implementation of 3-state control.
none
Non-Windows-specifc version of Klaus Wenger's class none

Description Olaf Kindel CLA 2002-08-08 06:11:35 EDT
Motivation:

Tri-state check boxes are often used in property dialogs that are based on a 
multiple selection to express a varying boolean feature of the selected 
elements. Another common usage is e. g. a query-by-example (QBE) form that 
contains boolean attributes. The user must be able to express three different 
cases: "search for true", "search for false" and "search either". 

There is native support for tri-state check boxes in many operating systems: at 
least for  Windows, Motif 2.x and the Mac. A portable application should be 
able to reflect the check box design familiar to the user.

Some workarounds suggest to change the color of the check box manually - or 
even suggest to disable it. Apart from the fact that disabled buttons are 
useless for the user, each operating system has its own way to express the 
indeterminate state. A Mac e. g. commonly shows a small dash on the button in 
that case. Therefore, painting a grey button is just a poor hack for a Windows 
machine.

Features:

a) It should be possible to modify and query the state of the check box in only 
*one* atomic operation, everything else is error-prone.
b) The three states are named: CHECKED, UNCHECKED and INDETERMINATE. 
c) It should be possible to switch an AutoCheckBox from 3-state to 2-state mode 
and vice versa at runtime.
Comment 1 Mike Wilson CLA 2002-08-08 09:56:38 EDT
We frequently get requests for new widgets which would be valuable to some set 
of Eclipse users but not all of them. Since we are a small team, we typically 
focus only on implementing widgets which are required by the Eclipse UI team. 
One way for you to proceed would be to convince the Eclipse UI developers that 
they want this widget.

Alternatively, you (or someone else in the community) could implement a widget 
like this and submit it via the platform-swt-dev mailing list. We could then 
look at including it in the SWT distribution. For this to happen, the code 
would have to be of high quality, and include both platform specific 
implementations on platforms which support it, and a generic implementation 
(i.e. a custom widget) for use on platforms which do not.
Comment 2 Veronika Irvine CLA 2002-09-11 14:05:55 EDT
Moving from Later.
Comment 3 Steve Northover CLA 2004-04-26 10:36:46 EDT
*** Bug 59865 has been marked as a duplicate of this bug. ***
Comment 4 Anthony Bennis CLA 2004-10-15 10:42:27 EDT
If the intermediate state is not been implemented, it would be helpful if it was
possible to get a handle on the composite the check appears in, to change it's
foreground and background colour to imitate this behaviour through a selection
Listener.

Regards,
Anthony Bennis.
Comment 5 Randy Hudson CLA 2005-10-06 10:13:28 EDT
Created attachment 27940 [details]
Windows Folder Attributes

Dialog from windows explorer showing multiple selection with mixed values.
Comment 6 Randy Hudson CLA 2005-10-06 10:19:51 EDT
Created attachment 27941 [details]
Display Properties/Effects

Windows Display Properties/Effects dialog showing partially enabled setting
Comment 7 Randy Hudson CLA 2005-10-06 10:22:32 EDT
Created attachment 27942 [details]
FrontPage Table Cell Properties

Dialog in MS FrontPage showing attribute with mixed values in multiple select
case.
Comment 8 Klaus Wenger CLA 2006-06-23 10:41:48 EDT
Created attachment 45177 [details]
Tristate check box

for the meantime, I attached a TristateButton class for the people who can't wait - it's not perfect but sure does the job for me. enjoy!
Comment 9 Grant Gayed CLA 2006-08-21 11:15:09 EDT
*** Bug 154187 has been marked as a duplicate of this bug. ***
Comment 10 Mark Melvin CLA 2006-10-17 17:53:52 EDT
Are there any plans to implement this support in SWT?  I have been using the example provided on Windows and it works well, but now we are looking at Linux support and I currently don't have a good solution for it.
Comment 11 Oleg Krasilnikov CLA 2007-04-27 05:26:39 EDT
Created attachment 65176 [details]
TriButton: possible implementation of 3-state control.

TriButton class is not platform-specific.

It can look like either checkbox (compatibility mode)
or combo box with text label (3-state mode, default). 
Combo contains 3 choices: Yes, No, ?.

Most existing Button's methods are preserved,
so it's possible simply to replace "Button" 
with "TriButton" in existing code.

2 new methods added: 
public int getTriSelection ();
public void setTriSelection(int selection);

Currently class is located in CDT and used from it,
but it can be moved anywhere, since it depends of 
SWT only.
Comment 12 Mark Melvin CLA 2007-04-27 09:35:45 EDT
Created attachment 65206 [details]
Non-Windows-specifc version of Klaus Wenger's class

For completeness, here is a copy of the code we ended up with.  One of our guys took Klaus Wenger's version posted earlier and made it compile and work on Linux or Windows.

I have not tried the CDT version, but it sounds interesting and is probably a better solution.  I'm not sure what it looks like though.  This code *looks* native, but has only been tested on Windows and Linux/GTK.
Comment 13 Mark Melvin CLA 2007-04-27 09:37:01 EDT
Comment on attachment 65206 [details]
Non-Windows-specifc version of Klaus Wenger's class

So much for "auto-detect" of attachment type...
Comment 14 Oleg Krasilnikov CLA 2007-04-28 06:15:58 EDT
Thanks to Mark. It works !!!

The only feature of the latest attach:
New control is derived from SWT.Button, so
it can always be in SWT package, otherwise
it would not work. So stand-alone developer
cannot distribute it in own package. 

It would be very useful to place it to 
custom widgets directory.
"Eclipse SWT Custom Widgets\common\org\eclipse\swt\custom\" 

Is it possible ?
Comment 15 Steve Northover CLA 2008-01-14 13:58:44 EST
Fixed > 20080114

See Button.getGrayed() and Button.setGrayed().
Comment 16 Mark Melvin CLA 2008-01-14 15:38:41 EST
Sweet...
Comment 17 Nikola Mihajloviæ CLA 2009-03-02 14:00:37 EST
It doesn't work for me. The user can still observe just two states. After setGrayed(true), these states are unchecked and grayed from a user perspective, or unchecked and checked from a developer perspective. getGrayed() always returns true after setGrayed(true). This behaviour is not consistent with that of Windows' tristate checkbox (I don't think it can be considered tristate at all)

I'm using Eclipse 3.4.1 and Windows XP