]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
993d6138e93047bf15cf9c1f2ee246891f36f766
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.properties.widgets.modules;\r
2 \r
3 import org.eclipse.jface.resource.ColorDescriptor;\r
4 import org.eclipse.swt.graphics.RGB;\r
5 import org.simantics.browsing.ui.content.LabelDecorator;\r
6 import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;\r
7 import org.simantics.db.ReadGraph;\r
8 import org.simantics.db.exception.DatabaseException;\r
9 import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
10 \r
11 public class ParameterLabelDecorationRule implements LabelDecorationRule {\r
12 \r
13     @Override\r
14     public boolean isCompatible(Class<?> contentType) {\r
15         return contentType.equals(Object.class);\r
16     }\r
17 \r
18     @Override\r
19     public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {\r
20         if(content instanceof ParameterNode) {\r
21             ParameterNode node = (ParameterNode) content;\r
22             String notOverriding = ModuleParameterOverrideUtils.getParameterExpression(node.getIndependentVariable());\r
23             String overriding = ModuleParameterOverrideUtils.getParameterExpressionOrOverride(graph, node.getParent(), node.getIndependentVariable());\r
24 \r
25             if(notOverriding == null)\r
26                 return null;\r
27 \r
28             final boolean original = notOverriding.equals(overriding);\r
29 \r
30             return new LabelDecorator.Stub() {\r
31                 @Override\r
32                 public String decorateLabel(String label, String column, int itemIndex) {\r
33                     if(ColumnKeys.VALUE.equals(column)) {\r
34                         return original ? label : label + " [Overridden]";\r
35                     } else {\r
36                         return label;\r
37                     }\r
38                 }\r
39 \r
40                 @SuppressWarnings("unchecked")\r
41                 @Override\r
42                 public <Color> Color decorateForeground(Color color, String column, int itemIndex) {\r
43                     Color result = null;\r
44                     if(ColumnKeys.VALUE.equals(column)) {\r
45                         if(original)\r
46                             result = (Color) ColorDescriptor.createFrom(new RGB(125,125,125));\r
47                         else\r
48                             result = (Color) ColorDescriptor.createFrom(new RGB(0,0,0));\r
49                     }\r
50                     return result;\r
51                 }\r
52             };\r
53         }\r
54         return null;\r
55     }\r
56 \r
57 }\r