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