简体   繁体   English

将标题添加到MultiColumnListModel

[英]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. 我正在使用Pharo 3中的 Spec库 ,但没有找到将标题添加到多列列表的方法。 However, adding headers is feasible through TreeColumnModel and TreeModel like this: 但是,像这样通过TreeColumnModel和TreeModel添加标头是可行的:

| 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中获得标题?

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. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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