X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fui%2FChartItemLabelDecorationRule.java;fp=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fui%2FChartItemLabelDecorationRule.java;h=b4d72392c7364992c36be45e20e22bb4b5194a56;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemLabelDecorationRule.java b/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemLabelDecorationRule.java new file mode 100644 index 000000000..b4d72392c --- /dev/null +++ b/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemLabelDecorationRule.java @@ -0,0 +1,54 @@ +package org.simantics.charts.ui; + +import org.eclipse.jface.resource.FontDescriptor; +import org.eclipse.swt.SWT; +import org.simantics.browsing.ui.content.LabelDecorator; +import org.simantics.browsing.ui.model.labeldecorators.AbstractLabelDecorator; +import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule; +import org.simantics.charts.ontology.ChartResource; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; + +/** + * Used for labeling both chart plots and subscription items. + * + * @author Tuukka Lehtonen + */ +public class ChartItemLabelDecorationRule implements LabelDecorationRule { + + public static final ChartItemLabelDecorationRule INSTANCE = new ChartItemLabelDecorationRule(); + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException { + Resource item = (Resource) content; + ChartResource CHART = ChartResource.getInstance(graph); + + Boolean hidden = graph.getPossibleRelatedValue(item, CHART.Chart_Item_hidden, Bindings.BOOLEAN); + if (hidden == null || !hidden) + return null; + + return HIDDEN_DECORATOR; + } + + private static class HiddenLabelDecorator extends AbstractLabelDecorator { + @SuppressWarnings("unchecked") + @Override + public F decorateFont(F font, String column, int itemIndex) { + return (F) ((FontDescriptor) font).withStyle(SWT.ITALIC); + } + @Override + public String decorateLabel(String label, String column, int itemIndex) { + return label + " (hidden)"; + } + }; + + private static HiddenLabelDecorator HIDDEN_DECORATOR = new HiddenLabelDecorator(); + +} \ No newline at end of file