Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Programatically manipulating checkboxes in CheckboxTreeViewer
Programatically manipulating checkboxes in CheckboxTreeViewer [message #109211] Wed, 15 October 2008 04:47 Go to next message
Eclipse UserFriend
Originally posted by: spanprevention-nursubscriptions.gmail.com

Hi,

Following is the background of the problem being faced.

The RAP app has a dialog that displays a Tree using a CheckboxTreeViewer.
Some of the requirements are as follows:
- When one of the root items is checked by the user, all its child items
should automatically get checked. If the root item is unchecked, its child
items should also be unchecked
- If the root item is checked and one of its child items is unchecked by
the user, then the root item should automatically be unchecked

There are other similar requirements. To automatically change the checked
state of child items when the root item's checked state changed, a
CheckStateListener was added. In the listener,
viewer.setSubtreeChecked(rootElement, true); was used to check all
sub-items of the node. Visually this worked fine.

The problem (i believe) is that these changes are not propagated to the
client-side code that maintains checked state. If the user manually clicks
on the checkbox of one of the automatically checked child items, it is
expected that since the item is currently checked, the checked state
received from the client should be unchecked. However, the HTTP request
sends the state as checked. This means that the programatically changed
checked state was not recognized by the client code. Visually this means
that when an already checked item (programatically checked) is checked
again, it remains checked. If this clicked a second time, it then becomes
unchecked.

Any pointers to resolving this issue are highly appreciated.

TIA,
Best Regards,
-abhi
Re: Programatically manipulating checkboxes in CheckboxTreeViewer [message #109551 is a reply to message #109211] Fri, 17 October 2008 09:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rherrmann.innoopract.com

Hi,

sorry, but I don't quite understand what you are pointing at. Could
you post a small self-contained code snippet that reproduces what
you described.

Cheers,
Rüdiger

abhi wrote:
> Hi,
>
> Following is the background of the problem being faced.
>
> The RAP app has a dialog that displays a Tree using a
> CheckboxTreeViewer. Some of the requirements are as follows:
> - When one of the root items is checked by the user, all its child items
> should automatically get checked. If the root item is unchecked, its
> child items should also be unchecked
> - If the root item is checked and one of its child items is unchecked by
> the user, then the root item should automatically be unchecked
>
> There are other similar requirements. To automatically change the
> checked state of child items when the root item's checked state changed,
> a CheckStateListener was added. In the listener,
> viewer.setSubtreeChecked(rootElement, true); was used to check all
> sub-items of the node. Visually this worked fine.
> The problem (i believe) is that these changes are not propagated to the
> client-side code that maintains checked state. If the user manually
> clicks on the checkbox of one of the automatically checked child items,
> it is expected that since the item is currently checked, the checked
> state received from the client should be unchecked. However, the HTTP
> request sends the state as checked. This means that the programatically
> changed checked state was not recognized by the client code. Visually
> this means that when an already checked item (programatically checked)
> is checked again, it remains checked. If this clicked a second time, it
> then becomes unchecked.
>
> Any pointers to resolving this issue are highly appreciated.
>
> TIA,
> Best Regards,
> -abhi
>
>
Re: Programatically manipulating checkboxes in CheckboxTreeViewer [message #109819 is a reply to message #109551] Mon, 20 October 2008 05:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: span-prevention-nursubscriptions.gmail.com

Hallo Rüdiger,

Thanks for your message! Please find below the relevant code snippet. If
the toplevel node is checked, the children node get checked. If i then hit
the checkbox of a child node, since it is appearing checked, i expect it
to get unchecked, but the node remains checked.

----------------
protected Control createDialogArea(Composite parent) {
Composite dialogArea = (Composite) super.createDialogArea(parent);

Composite composite = new Composite(dialogArea, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
composite.setLayout(new GridLayout());

final Tree tree = new Tree(composite, SWT.CHECK | SWT.BORDER);
// viewer is an attribute of this class (datatype = CheckboxTreeViewer)
viewer = new CheckboxTreeViewer(tree);
viewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setInput("dummy input to be ignored");

viewer.addCheckStateListener(new ICheckStateListener() {

@Override
public void checkStateChanged(CheckStateChangedEvent event) {
Object element = event.getElement();
if (element.equals(TOPLEVEL)) {
// all children of TOPLEVEL should be checked
if (event.getChecked()) {
viewer.setSubtreeChecked(element, true);
}
} else if (element instanceof ChildNode) {
if (!event.getChecked()) {
ViewContentProvider contentProvider = (ViewContentProvider)
viewer.getContentProvider();
String groupRoot = (String) contentProvider.getParent(element);
if (viewer.getChecked(groupRoot)) {
viewer.setChecked(groupRoot, false);
}
}
}
}
});

return dialogArea;
}
------------------------
Please feel free to revert in case of any further queries.

TIA,
Best Wishes,
-abhi
Re: Programatically manipulating checkboxes in CheckboxTreeViewer [message #109899 is a reply to message #109819] Mon, 20 October 2008 09:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rherrmann.innoopract.com

I tried a simplified version and it seems that *sometimes* a child
node that was checked by the listener code, remains checked when
clicking it.

viewer.addCheckStateListener( new ICheckStateListener() {
public void checkStateChanged( CheckStateChangedEvent event ) {
viewer.setSubtreeChecked( event.getElement(),
event.getChecked() );
}
} );

Feel free to file a bugzilla.

Rüdiger

abhi wrote:
> Hallo Rüdiger,
>
> Thanks for your message! Please find below the relevant code snippet. If
> the toplevel node is checked, the children node get checked. If i then
> hit the checkbox of a child node, since it is appearing checked, i
> expect it to get unchecked, but the node remains checked.
>
> ----------------
> protected Control createDialogArea(Composite parent) {
> Composite dialogArea = (Composite) super.createDialogArea(parent);
>
> Composite composite = new Composite(dialogArea, SWT.NONE);
> composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
> composite.setLayout(new GridLayout());
>
> final Tree tree = new Tree(composite, SWT.CHECK | SWT.BORDER);
> // viewer is an attribute of this class (datatype = CheckboxTreeViewer)
> viewer = new CheckboxTreeViewer(tree);
> viewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL,
> true, true));
> viewer.setContentProvider(new ViewContentProvider());
> viewer.setLabelProvider(new ViewLabelProvider());
> viewer.setInput("dummy input to be ignored");
> viewer.addCheckStateListener(new ICheckStateListener() {
>
> @Override
> public void checkStateChanged(CheckStateChangedEvent event) {
> Object element = event.getElement();
> if (element.equals(TOPLEVEL)) {
> // all children of TOPLEVEL should be checked
> if (event.getChecked()) {
> viewer.setSubtreeChecked(element, true);
> } } else if (element instanceof ChildNode) {
> if (!event.getChecked()) {
> ViewContentProvider contentProvider =
> (ViewContentProvider) viewer.getContentProvider();
> String groupRoot = (String)
> contentProvider.getParent(element);
> if (viewer.getChecked(groupRoot)) {
> viewer.setChecked(groupRoot, false);
> }
> }
> }
> } });
> return dialogArea;
> }
> ------------------------
> Please feel free to revert in case of any further queries.
>
> TIA,
> Best Wishes,
> -abhi
>
>
Re: Programatically manipulating checkboxes in CheckboxTreeViewer [message #109972 is a reply to message #109899] Tue, 21 October 2008 09:28 Go to previous message
Eclipse UserFriend
Originally posted by: spanprevention-nursubscriptions.gmail.com

Hi Rüdiger,

Have added in bugzilla at the following link:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=251387

Thanks,
Best Regards,
-abhi
Previous Topic:job.join() and setUser(true)
Next Topic:Which plugins do I need from CVS?
Goto Forum:
  


Current Time: Wed Apr 24 22:06:13 GMT 2024

Powered by FUDForum. Page generated in 0.03233 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top