简体   繁体   English

在JFace树状视图中为某些特定树着色

[英]Color some specific trees in a JFace treeviewer

I have to visually differentiate certain nodes and its children in a JFace tree. 我必须在视觉上区分JFace树中的某些节点及其子节点。 Due to limitations, I can only extend the label provider. 由于限制,我只能扩展标签提供商。

How can I color the nodes and their children? 如何为节点及其子节点颜色? I'm open to other methods for making the nodes stand out. 我对其他让节点脱颖而出的方法持开放态度。

class ExistingScheduleLabelProvider extends LabelProvider {
    @Override
    public String getText(Object element) {
        if (element instanceof Schedule) {
            Schedule schedule = (Schedule) element;
            return schedule.getDescription();
        } else if (element instanceof BatchReport) {
            BatchReport report = (BatchReport) element;
            Schedule schedule = (Schedule)report.eContainer();
            return (schedule.getBatchReports().indexOf(report)+1) + " - " + report.getDescription(); //$NON-NLS-1$
        }
        return null;
    }
    @Override
    public Image getImage(Object element) {
        if (element instanceof Schedule)
            return SchedulingUIPlugin.getImage(SchedulingImageConstants.IMG_SCHEDULE);
        else if (element instanceof BatchReport)
            return SchedulingUIPlugin.getImage(SchedulingImageConstants.IMG_BATCH_REPORT);
        return super.getImage(element);
    }   

}

From the available nodes in the tree, can I color only the nodes which I want based on a condition in order to differentiate them from other nodes? 从树中的可用节点,我可以根据条件仅为我想要的节点着色,以便将它们与其他节点区分开来吗?

如果您的标签提供者实现了org.eclipse.jface.viewers.IColorProvider那么将要求它们提供各种元素的颜色。

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

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