Bug 76509 - Wrong behavior of grayed table items
Summary: Wrong behavior of grayed table items
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0.1   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-18 18:14 EDT by Sergey Prigogin CLA
Modified: 2004-10-19 11:48 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Prigogin CLA 2004-10-18 18:14:20 EDT
Clicking on a grayed item in a Table with SWT.CHECK style changes its checked 
state. Grayed items should behave as disabled and should not change their 
checked state in response to a click.

The following line in Table.WM_LBUTTONDOWN(int wParam, int lParam) and in
Table.WM_KEYDOWN (int wParam, int lParam):

    item.setChecked (!item.getChecked (), true);

should be changed to:

    if (!item.getGrayed())
      item.setChecked (!item.getChecked (), true);
Comment 1 Grant Gayed CLA 2004-10-18 19:01:16 EDT
Gray checkboxes do not necessarily mean that the checkbox is disabled, but are 
usually used to show a "partial" selection.  For an example of this, go to the 
Import - from File System wizard, select a directory to import from, and then 
un-check one of its children.  The parent item's check box turns gray to 
indicate "most but not all of my children".

Closing report since checking of gray checkboxes is behaving as intended.
Comment 2 Sergey Prigogin CLA 2004-10-18 19:25:39 EDT
How can I get the disabled behavior if grayed items are not disabled? 
Unfortunately the methods participating in checking/unchecking behavior are 
package protected and cannot be overriden.
Comment 3 Grant Gayed CLA 2004-10-19 11:48:55 EDT
You'll need to manage this in a selection listener, as shown in the snippet 
below.  As a side note, it is still not advised to use setGrayed() to indicate 
a disabled checkbox because on gtk this draws as a partial selection (a 
horizontal line, not a gray checkbox), which would be very confusing to users.  
Perhaps "setPartialCheck()" would have been a more appropriate name 
than "setGrayed()".

public static void main(String[] args) {
	final Display display = new Display();
	Shell shell = new Shell(display);
	shell.setBounds(10, 10, 200, 200);
	final Table table = new Table(shell, SWT.CHECK);
	table.setBounds(10, 10, 170, 150);
	table.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent e) {
			if (e.detail == SWT.CHECK) {
				TableItem item = (TableItem) e.item;
				if (item.getData() != null) {	// disabled
					item.setChecked(!item.getChecked());
				}
			}
		}
	});
	for (int i = 0; i < 20; i++) {
		TableItem item = new TableItem(table, SWT.NONE);
		item.setText("item" + i);
		item.setChecked(i % 2 == 0);
		if (i % 3 == 0) {
			item.setText(item.getText() + " (disabled)");
			item.setData("disabled");
		}
	}
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
	}
	display.dispose();
}