简体   繁体   中英

Adding a header to MultiColumnListModel

I am working with Spec library in Pharo 3 and I have found no way to add a header to a multi column list. However, adding headers is feasible through TreeColumnModel and TreeModel like this:

| m col1 col2 |
m := TreeModel new.
m roots: #(#a #b #c #d).
m rootNodeHolder: [ :item | 
    TreeNodeModel new
        content: item;
        icon: Smalltalk ui icons smallConfigurationIcon ].
m openWithSpec.
col1 := TreeColumnModel new
    displayBlock: [ :node | node content asString ];
    headerLabel: 'Character'.
col2 := TreeColumnModel new
    displayBlock: [ :node | (Character value: node content asString first asciiValue + 1) asString ];
    headerLabel: 'Character +1';
    headerIcon: Smalltalk ui icons smallBackIcon.
m
    columns: {col1. col2};
    acceptDropBlock: [ :transfer :event :source :receiver | self halt ].
col2 
    headerLabel: 'Character +2';
    headerIcon: Smalltalk ui icons smallBackIcon;
    displayBlock: [ :node | (Character value: node content asString first asciiValue + 2) asString ].
m rootNodeHolder: [ :item | 
    TreeNodeModel new
        content: (Character value: (item asString first asciiValue + 5)) asSymbol;
        icon: Smalltalk ui icons smallFullscreenIcon ].

How could I get a header in the following MultiColumnListModel?

MultiColumnListModel new
    items: {$a. $b. $c. $d. $f.};
    displayBlock: [:e | {e asString. e isVowel asString} ];
    openWithSpec.

Will this work for you?

    model := MultiColumnListModel new
    items: { {'Letter'. 'isVowel'.}. $a. $b. $c. $d. $f.};
    displayBlock: [:e | 
    e isArray 
    ifTrue:[{e first asString. e last asString} ]
    ifFalse:[
    {e asString. e isVowel asString} ]].
model 
    whenSelectionChanged:[  
        model getIndex  =  1 ifTrue:[       
        model setIndex:0].
    ];
    openWithSpec. 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM