--- /dev/null
+package org.simantics.charts.ui;\r
+\r
+import org.eclipse.jface.resource.FontDescriptor;\r
+import org.eclipse.swt.SWT;\r
+import org.simantics.browsing.ui.content.LabelDecorator;\r
+import org.simantics.browsing.ui.model.labeldecorators.AbstractLabelDecorator;\r
+import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;\r
+import org.simantics.charts.ontology.ChartResource;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+/**\r
+ * Used for labeling both chart plots and subscription items.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class ChartItemLabelDecorationRule implements LabelDecorationRule {\r
+\r
+ public static final ChartItemLabelDecorationRule INSTANCE = new ChartItemLabelDecorationRule();\r
+\r
+ @Override\r
+ public boolean isCompatible(Class<?> contentType) {\r
+ return contentType.equals(Resource.class);\r
+ }\r
+\r
+ @Override\r
+ public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {\r
+ Resource item = (Resource) content;\r
+ ChartResource CHART = ChartResource.getInstance(graph);\r
+\r
+ Boolean hidden = graph.getPossibleRelatedValue(item, CHART.Chart_Item_hidden, Bindings.BOOLEAN);\r
+ if (hidden == null || !hidden)\r
+ return null;\r
+\r
+ return HIDDEN_DECORATOR;\r
+ }\r
+\r
+ private static class HiddenLabelDecorator extends AbstractLabelDecorator {\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public <F> F decorateFont(F font, String column, int itemIndex) {\r
+ return (F) ((FontDescriptor) font).withStyle(SWT.ITALIC);\r
+ }\r
+ @Override\r
+ public String decorateLabel(String label, String column, int itemIndex) {\r
+ return label + " (hidden)";\r
+ }\r
+ };\r
+\r
+ private static HiddenLabelDecorator HIDDEN_DECORATOR = new HiddenLabelDecorator();\r
+\r
+}
\ No newline at end of file