0

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?

4

1 回答 1

2

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

于 2013-09-06T16:23:08.520 回答