X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FmodelBrowser2%2Flabel%2FSubscriptionItemLabelDecorationRule.java;fp=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FmodelBrowser2%2Flabel%2FSubscriptionItemLabelDecorationRule.java;h=c94d1f205fa8e71fc4d940f08c4bf51bbef38922;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=64d5a76aa42f44be1f55d9a22ca0c668835a60b4;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/label/SubscriptionItemLabelDecorationRule.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/label/SubscriptionItemLabelDecorationRule.java index 64d5a76aa..c94d1f205 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/label/SubscriptionItemLabelDecorationRule.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/label/SubscriptionItemLabelDecorationRule.java @@ -1,115 +1,115 @@ -/******************************************************************************* - * Copyright (c) 2012 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.modeling.ui.modelBrowser2.label; - -import org.eclipse.jface.resource.ColorDescriptor; -import org.eclipse.jface.resource.FontDescriptor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.RGB; -import org.simantics.browsing.ui.content.LabelDecorator; -import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule; -import org.simantics.databoard.Bindings; -import org.simantics.databoard.Databoard; -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.type.BooleanType; -import org.simantics.databoard.type.Datatype; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.request.PossibleModel; -import org.simantics.db.layer0.request.PossibleVariableValue; -import org.simantics.db.layer0.variable.RVI; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.modeling.ModelingResources; -import org.simantics.modeling.subscription.ModelContexts; -import org.simantics.modeling.subscription.ModelContextsRequest; - -/** - * @author Tuukka Lehtonen - */ -public class SubscriptionItemLabelDecorationRule implements LabelDecorationRule { - - public static final SubscriptionItemLabelDecorationRule INSTANCE = new SubscriptionItemLabelDecorationRule(); - - private static final ColorDescriptor RED = ColorDescriptor.createFrom(new RGB(255, 0, 0)); - private static final ColorDescriptor INVALID = ColorDescriptor.createFrom(new RGB(255, 128, 128)); - private static final ColorDescriptor GREEN = ColorDescriptor.createFrom(new RGB(0, 160, 0)); - - static LabelDecorator RED_DECO = new LabelDecorator.Stub() { - @SuppressWarnings("unchecked") - public C decorateForeground(C color, String column, int itemIndex) { - return (C) RED; - } - }; - - static LabelDecorator GREEN_DECO = new LabelDecorator.Stub() { - @SuppressWarnings("unchecked") - public C decorateForeground(C color, String column, int itemIndex) { - return (C) GREEN; - } - }; - - static LabelDecorator UNRESOLVABLE = new LabelDecorator.Stub() { - @Override - public String decorateLabel(String label, String column, int itemIndex) { - return label + " (INVALID)"; - } - @SuppressWarnings("unchecked") - public C decorateForeground(C color, String column, int itemIndex) { - return (C) INVALID; - } - @SuppressWarnings("unchecked") - public F decorateFont(F font, String column, int itemIndex) { - return (F) ((FontDescriptor) font).withStyle(SWT.ITALIC); - } - }; - - @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; - ModelingResources MOD = ModelingResources.getInstance(graph); - - Binding rviBinding = graph.getService(Databoard.class).getBindingUnchecked( RVI.class ); - RVI rvi = graph.getPossibleRelatedValue(item, MOD.Subscription_Item_VariableId, rviBinding); - if (rvi == null) - return null; - - Resource model = graph.sync( new PossibleModel(item) ); - if (model == null) - return null; - - ModelContexts contexts = graph.syncRequest(new ModelContextsRequest(model)); - if (contexts.getExperimentContext() == null) - return null; - - Variable variable = rvi.resolvePossible(graph, contexts.getExperimentContext()); - if (variable == null) - return UNRESOLVABLE; - - Datatype datatype = graph.getPossibleRelatedValue(item, MOD.Subscription_Item_Datatype, Bindings.getBindingUnchecked(Datatype.class)); - if (!(datatype instanceof BooleanType)) - return null; - - Object value = graph.sync( new PossibleVariableValue(variable) ); - if (!(value instanceof Boolean)) - return null; - - Boolean v = (Boolean) value; - return v ? GREEN_DECO : RED_DECO; - } - -} +/******************************************************************************* + * Copyright (c) 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.ui.modelBrowser2.label; + +import org.eclipse.jface.resource.ColorDescriptor; +import org.eclipse.jface.resource.FontDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.RGB; +import org.simantics.browsing.ui.content.LabelDecorator; +import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Databoard; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.type.BooleanType; +import org.simantics.databoard.type.Datatype; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.PossibleModel; +import org.simantics.db.layer0.request.PossibleVariableValue; +import org.simantics.db.layer0.variable.RVI; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.subscription.ModelContexts; +import org.simantics.modeling.subscription.ModelContextsRequest; + +/** + * @author Tuukka Lehtonen + */ +public class SubscriptionItemLabelDecorationRule implements LabelDecorationRule { + + public static final SubscriptionItemLabelDecorationRule INSTANCE = new SubscriptionItemLabelDecorationRule(); + + private static final ColorDescriptor RED = ColorDescriptor.createFrom(new RGB(255, 0, 0)); + private static final ColorDescriptor INVALID = ColorDescriptor.createFrom(new RGB(255, 128, 128)); + private static final ColorDescriptor GREEN = ColorDescriptor.createFrom(new RGB(0, 160, 0)); + + static LabelDecorator RED_DECO = new LabelDecorator.Stub() { + @SuppressWarnings("unchecked") + public C decorateForeground(C color, String column, int itemIndex) { + return (C) RED; + } + }; + + static LabelDecorator GREEN_DECO = new LabelDecorator.Stub() { + @SuppressWarnings("unchecked") + public C decorateForeground(C color, String column, int itemIndex) { + return (C) GREEN; + } + }; + + static LabelDecorator UNRESOLVABLE = new LabelDecorator.Stub() { + @Override + public String decorateLabel(String label, String column, int itemIndex) { + return label + " (INVALID)"; + } + @SuppressWarnings("unchecked") + public C decorateForeground(C color, String column, int itemIndex) { + return (C) INVALID; + } + @SuppressWarnings("unchecked") + public F decorateFont(F font, String column, int itemIndex) { + return (F) ((FontDescriptor) font).withStyle(SWT.ITALIC); + } + }; + + @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; + ModelingResources MOD = ModelingResources.getInstance(graph); + + Binding rviBinding = graph.getService(Databoard.class).getBindingUnchecked( RVI.class ); + RVI rvi = graph.getPossibleRelatedValue(item, MOD.Subscription_Item_VariableId, rviBinding); + if (rvi == null) + return null; + + Resource model = graph.sync( new PossibleModel(item) ); + if (model == null) + return null; + + ModelContexts contexts = graph.syncRequest(new ModelContextsRequest(model)); + if (contexts.getExperimentContext() == null) + return null; + + Variable variable = rvi.resolvePossible(graph, contexts.getExperimentContext()); + if (variable == null) + return UNRESOLVABLE; + + Datatype datatype = graph.getPossibleRelatedValue(item, MOD.Subscription_Item_Datatype, Bindings.getBindingUnchecked(Datatype.class)); + if (!(datatype instanceof BooleanType)) + return null; + + Object value = graph.sync( new PossibleVariableValue(variable) ); + if (!(value instanceof Boolean)) + return null; + + Boolean v = (Boolean) value; + return v ? GREEN_DECO : RED_DECO; + } + +}