Skip to main content
Known Participant
July 21, 2009
Answered

[CS2/CS3] - TreeViewWidgetMgr & NodeID

  • July 21, 2009
  • 2 replies
  • 2504 views

Hello,

   I'm trying to use WListBoxComposite SDK sample to modify TreeView and add CheckBox for each TreeNode. I changed resource file:

resource WLBCmpNodeWidget (kWLBCmpListElementRsrcID + index_enUS)
{
    __FILE__, __LINE__,
    kWLBCmpListParentWidgetId, kPMRsrcID_None,    // WidgetId, RsrcId
    kBindLeft | kBindRight,            // Frame binding
    Frame(0, 0, 194, 20),            // Frame
    kTrue, kTrue,                    // Visible, Enabled
    "",                                // Panel name

    {

        CheckBoxWidget
        (
            // CControlView properties
            kCheckBoxWidgetID, // widget ID
            kSysCheckBoxPMRsrcId, // PMRsrc ID
            kBindNone, // frame binding
            Frame(15,1,40,18) //  left, top, right, bottom
            kTrue, // visible
            kTrue, // enabled
            // TriStateControlAttributes properties
            kAlignLeft, // alignment
            // CTextControlData properties
            "", // control label
        ),

        // Just a info-static text widget with about-box text view to get white bg.
        WLBCmpTextWidget
        (
            kWLBCmpTextWidgetID, kPMRsrcID_None,        // WidgetId, RsrcId
            kBindLeft | kBindRight,                                // Frame binding
            Frame(45,1,194,18)                                    // Frame
            kTrue, kTrue, kAlignLeft,kEllipsizeEnd                // Visible, Enabled, Ellipsize style
            "",                                                    // Initial text
            0,                                                    // Associated widget for focus
            kPaletteWindowSystemScriptFontId,                    // default font
            kPaletteWindowSystemScriptHiliteFontId,                // for highlight state.
        ),
      
    }

I know that method TreeViewWidgetMgr::ApplyDataToWidget uses informations from WLBCmpNodeID class which represents data of tree node. I tried to add a variable to this class which is refering about checkbox state (selected/unselected). But now I have problem to get information in checkbox observer to get NodeID to save state of checkbox in node ? Please could you help me with this problem ?

Thanks, marxin

This topic has been closed for replies.
Correct answer Dirk Becker

Matching your example:

write and implement a SoccerClubMgr interface.

Aggregate that on the appropriate boss - e.g. kDocWorkspaceBoss if its data is persistent per document. In that case you'll also have to consider the whole shebang of own commands, notifications, suites, selection observer, preferences ...

If you load the clubs from a flat file or external database, for laziness sake you could even aggregate the interface in the tree boss, or on gSession.

That SoccerClubMgr would have int32 GetClubCount(), GetName(int32), bool GetFlag(int32), SetFlag(int32,bool) methods, or QuerySoccerClub(int32) if you store them as separate boss. In your TreeViewWidgetMgr, you then use a private QueryClubManager() method to find the interface, then invoke the methods. Or use an additional Util<> class for another level of wrappers.

With this approach you can even reuse IntNodeID to store those int32 index values, rather than creating your own NodeID.

Dirk

2 replies

Legend
July 21, 2009

Don't populate the Tree from resource.

Your TVWM is used to create widgets with its CreateWidgetForNode(), after the ITreeViewHierarchyAdapter is asked for the number of nodes. Each node widget's sub widgets (cbox and text) is populated by ApplyNodeIDToWidget(). When you scroll it out of sight, the node widget is reused for a different NodeID, thus you have to change the name every time you're asked.

For the same reason your backing storage for the cbox also is the ClubMgr - as soon the widget is out of sight it is gone. You have to observe changes and immediately store them in the ClubMgr.

Dirk

marxinAuthor
Known Participant
July 21, 2009

When I see resource file, there is definition of StringListData to storing names of clubs( which is in sample), should I replace it with IID_IBOOLLISTDATA to store vector of checkboxes:

Class

{

        kWLBCmpListBoxWidgetBoss,
        kTreeViewWidgetBoss,
        {
            /** Furnishes application framework with widgets as needed */
            IID_ITREEVIEWWIDGETMGR,  kWLBCmpTVWidgetMgrImpl,
            /** Adapts our data model to the needs of the application framework */
            IID_ITREEVIEWHIERARCHYADAPTER,  kWLBCmpTVHierarchyAdapterImpl,
            /** Hold names of the list item */
            IID_ISTRINGLISTDATA,        kStringListDataImpl,

            /** Adding for saving checkboxes states ? */

            IID_ISTRINGLISTDATA,        kBoolListDataImp,
            /** Display selection message */  
              IID_IOBSERVER,    kWLBCmpListBoxObserverImpl,
        }

}

In WLBCmp sample TreeViewAdapter get strings (names) from IStringListData, but I don't know how to save the state from CBoxes and store it to this BoolListData ?

I hope you'll have some time to help me

Thank you, marxin

Legend
July 21, 2009

You must not reuse the IID - (here IID_ISTRINGLISTDATA), use your own IID.

You must not reuse kStringListDataImpl, it is persistent.

There is no kBoolListDataImpl, write your own (aka ClubMgr). If you want to use the implementation of kStringListDataImpl, search the SDK for ImplementationAlias.

Have an observer in your node widget.

In AutoAttach() use IPanelControlData to find / subscribe to the checkbox.

In Update() use IWidgetParent to find the ClubMgr by IID, and set/clear the value.

Dirk

Inspiring
July 21, 2009

Storing actual, changeable data in the NodeID is a very misleading pattern, do not follow this over-simplified approach of the SDK.

Instead, keep the NodeID unchanged per referenced entity. Your TreeViewWidgetMgr is the bottleneck to translate the NodeID into the real object, to look up the data in the actual backing model. E.g. you'd store the UID of some entity in the NodeID, mix in the commonly shared DB pointer from some other place in order to access the real object.

Dirk

marxinAuthor
Known Participant
July 21, 2009

Thank you Dirk for your post, you wrote me that approach of insert data into NodeID is bad approach, could you suggest me solution of storing states of checkboxes which I have in my TreeView. My purpose is to be able to generate list of checkboxes, I have spent a lot of time, ListBox doesn't support inserting checkboxes (thay are paint incorrect outside of panel) and in this forum I found advices about generating checkboxes into TreeViewWidget.

Thank you for your helpfull advices, marxin

Dirk BeckerCorrect answer
Legend
July 21, 2009

Matching your example:

write and implement a SoccerClubMgr interface.

Aggregate that on the appropriate boss - e.g. kDocWorkspaceBoss if its data is persistent per document. In that case you'll also have to consider the whole shebang of own commands, notifications, suites, selection observer, preferences ...

If you load the clubs from a flat file or external database, for laziness sake you could even aggregate the interface in the tree boss, or on gSession.

That SoccerClubMgr would have int32 GetClubCount(), GetName(int32), bool GetFlag(int32), SetFlag(int32,bool) methods, or QuerySoccerClub(int32) if you store them as separate boss. In your TreeViewWidgetMgr, you then use a private QueryClubManager() method to find the interface, then invoke the methods. Or use an additional Util<> class for another level of wrappers.

With this approach you can even reuse IntNodeID to store those int32 index values, rather than creating your own NodeID.

Dirk