Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » How to initial check elements in a CheckboxTreeviewer
How to initial check elements in a CheckboxTreeviewer [message #1164270] Thu, 31 October 2013 15:04 Go to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
I'm using a custom Dialog with a CheckboxTreeViewer inside my GMF Editor, which works fine so far, as you can see below:


After closing the Dialog, the selected element are saved so far. Now my Problem:

When I open the dialog again, all elements are unchecked. So I thought it would be easy to tell the treeViewer that specific elements should be initially checked.

But it turned out that it's not that easy, as the Tree initially consist of the root element. The other elements are not added until the tree expands. Elements are added by calling the getChildren(Object parentElement) of the ContentProvider.

So it seems that I can't check specific elements initially, but rather have to provide a dynamically approach. I'm looking for something like an element added listener, but there seems none to exist.

Here is the part, where I'm creating the CheckboxTreeViewer:

Composite container = (Composite) super.createDialogArea(parent);
        tv = new CheckboxTreeViewer(container, SWT.MULTI | SWT.H_SCROLL
                | SWT.V_SCROLL);
        tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
        tv.setContentProvider(new FeaturePropertyDialogContentProvider(this));
        tv.setLabelProvider(new FeaturePropertyDialogLabelProvider());
        return container;

And here is the getChildren method of my ContentProvider:

    public Object[] getChildren(Object parentElement) {
        if (parentElement instanceof PL) {
            PL p = (PL) parentElement;
            return new Object[] { p.getPropertyList() };
        else if (parentElement instanceof PropertyList) {
            PropertyList propertyList = (PropertyList) parentElement;
            return propertyList.getGeneralPlatforms().toArray();
        } else if (parentElement instanceof GeneralPlatform) {
            GeneralPlatform platform = (GeneralPlatform) parentElement;
            return platform.getHardwareElements().toArray();
        } else {
            return null;

Any ideas on this?
  • Attachment: mAuap.jpg
    (Size: 29.83KB, Downloaded 1649 times)
Re: How to initial check elements in a CheckboxTreeviewer [message #1171377 is a reply to message #1164270] Tue, 05 November 2013 07:32 Go to previous message
Thorsten Schlathölter is currently offline Thorsten SchlathölterFriend
Messages: 309
Registered: February 2012
Location: Düsseldorf
Senior Member
Try setting an ICheckStateProvider. That provider is called to retrieve the check/gray state of an item whenever it is added/updated.
Previous Topic:Listen to disposing of a binding?
Next Topic:docking windows/views
Goto Forum:

Current Time: Sat Sep 19 22:39:31 GMT 2020

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

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

Back to the top