]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemLabelDecorationRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / ui / ChartItemLabelDecorationRule.java
1 package org.simantics.charts.ui;
2
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;
13
14 /**
15  * Used for labeling both chart plots and subscription items.
16  * 
17  * @author Tuukka Lehtonen
18  */
19 public class ChartItemLabelDecorationRule implements LabelDecorationRule {
20
21     public static final ChartItemLabelDecorationRule INSTANCE = new ChartItemLabelDecorationRule();
22
23     @Override
24     public boolean isCompatible(Class<?> contentType) {
25         return contentType.equals(Resource.class);
26     }
27
28     @Override
29     public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
30         Resource item = (Resource) content;
31         ChartResource CHART = ChartResource.getInstance(graph);
32
33         Boolean hidden = graph.getPossibleRelatedValue(item, CHART.Chart_Item_hidden, Bindings.BOOLEAN);
34         if (hidden == null || !hidden)
35             return null;
36
37         return HIDDEN_DECORATOR;
38     }
39
40     private static class HiddenLabelDecorator extends AbstractLabelDecorator {
41         @SuppressWarnings("unchecked")
42         @Override
43         public <F> F decorateFont(F font, String column, int itemIndex) {
44             return (F) ((FontDescriptor) font).withStyle(SWT.ITALIC);
45         }
46         @Override
47         public String decorateLabel(String label, String column, int itemIndex) {
48             return label + " (hidden)";
49         }
50     };
51
52     private static HiddenLabelDecorator HIDDEN_DECORATOR = new HiddenLabelDecorator();
53
54 }