简体   繁体   中英

Color some specific trees in a JFace treeviewer

I have to visually differentiate certain nodes and its children in a JFace tree. 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那么将要求它们提供各种元素的颜色。

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