1 package org.simantics.charts.ui;
3 import org.eclipse.jface.resource.FontDescriptor;
4 import org.eclipse.swt.SWT;
5 import org.simantics.browsing.ui.content.LabelDecorator;
6 import org.simantics.browsing.ui.model.labeldecorators.AbstractLabelDecorator;
7 import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;
8 import org.simantics.charts.ontology.ChartResource;
9 import org.simantics.databoard.Bindings;
10 import org.simantics.db.ReadGraph;
11 import org.simantics.db.Resource;
12 import org.simantics.db.exception.DatabaseException;
15 * Used for labeling both chart plots and subscription items.
17 * @author Tuukka Lehtonen
19 public class ChartItemLabelDecorationRule implements LabelDecorationRule {
21 public static final ChartItemLabelDecorationRule INSTANCE = new ChartItemLabelDecorationRule();
24 public boolean isCompatible(Class<?> contentType) {
25 return contentType.equals(Resource.class);
29 public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
30 Resource item = (Resource) content;
31 ChartResource CHART = ChartResource.getInstance(graph);
33 Boolean hidden = graph.getPossibleRelatedValue(item, CHART.Chart_Item_hidden, Bindings.BOOLEAN);
34 if (hidden == null || !hidden)
37 return HIDDEN_DECORATOR;
40 private static class HiddenLabelDecorator extends AbstractLabelDecorator {
41 @SuppressWarnings("unchecked")
43 public <F> F decorateFont(F font, String column, int itemIndex) {
44 return (F) ((FontDescriptor) font).withStyle(SWT.ITALIC);
47 public String decorateLabel(String label, String column, int itemIndex) {
48 return label + " (hidden)";
52 private static HiddenLabelDecorator HIDDEN_DECORATOR = new HiddenLabelDecorator();