--- /dev/null
+package org.simantics.browsing.ui.nattable;\r
+\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;\r
+import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;\r
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;\r
+import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;\r
+import org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper;\r
+import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;\r
+import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;\r
+import org.eclipse.nebula.widgets.nattable.style.ConfigAttribute;\r
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;\r
+import org.eclipse.nebula.widgets.nattable.style.IDisplayModeOrdering;\r
+import org.eclipse.nebula.widgets.nattable.style.Style;\r
+import org.eclipse.swt.graphics.GC;\r
+import org.eclipse.swt.graphics.Image;\r
+import org.eclipse.swt.graphics.Rectangle;\r
+\r
+public class GEStyler extends CellPainterWrapper{\r
+ \r
+ private GETreeData treeData;\r
+ \r
+ public GEStyler(GETreeData treeData, ICellPainter painter) {\r
+ super(painter);\r
+ this.treeData = treeData;\r
+ }\r
+ \r
+ private ConfigRegistryWrapper wrapper = new ConfigRegistryWrapper();\r
+\r
+ @Override\r
+ public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {\r
+ wrapper.clear();\r
+ wrapper.wrappedRegistry = configRegistry;\r
+ TreeNode node = treeData.getDataAtIndex(cell.getRowIndex());\r
+ Style style = new Style();\r
+ node.getStyle(cell.getColumnIndex(), style);\r
+ Image image = node.getImage(cell.getColumnIndex());\r
+ if (image != null)\r
+ style.setAttributeValue(CellStyleAttributes.IMAGE, image);\r
+ \r
+ wrapper.setSpecificConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, "BODY", style);\r
+// wrapper.setSpecificConfigAttribute(CellStyleAttributes.FOREGROUND_COLOR, DisplayMode.NORMAL, "BODY", style.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));\r
+// wrapper.setSpecificConfigAttribute(CellStyleAttributes.BACKGROUND_COLOR, DisplayMode.NORMAL, "BODY", style.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));\r
+// wrapper.setSpecificConfigAttribute(CellStyleAttributes.FONT, DisplayMode.NORMAL, "BODY", style.getAttributeValue(CellStyleAttributes.FONT));\r
+ super.paintCell(cell, gc, rectangle, wrapper);\r
+ }\r
+ \r
+ private class ConfigRegistryWrapper extends ConfigRegistry {\r
+ IConfigRegistry wrappedRegistry;\r
+ Map<ConfigAttribute<?>, Map<String, Map<String, ?>>> configRegistry = new HashMap<ConfigAttribute<?>, Map<String, Map<String, ?>>>();\r
+ \r
+ public void clear() {\r
+ configRegistry.clear();\r
+ }\r
+\r
+ @Override\r
+ public <T> T getConfigAttribute(ConfigAttribute<T> configAttribute, String targetDisplayMode,\r
+ String... configLabels) {\r
+ return wrappedRegistry.getConfigAttribute(configAttribute, targetDisplayMode, configLabels);\r
+ }\r
+\r
+ @Override\r
+ public <T> T getConfigAttribute(ConfigAttribute<T> configAttribute, String targetDisplayMode,\r
+ List<String> configLabels) {\r
+ return wrappedRegistry.getConfigAttribute(configAttribute, targetDisplayMode, configLabels);\r
+ }\r
+\r
+ @Override\r
+ public <T> T getSpecificConfigAttribute(ConfigAttribute<T> configAttribute, String displayMode,\r
+ String configLabel) {\r
+ T value = _getSpecificConfigAttribute(configAttribute, displayMode, configLabel);\r
+ if (value != null)\r
+ return value;\r
+ return wrappedRegistry.getSpecificConfigAttribute(configAttribute, displayMode, configLabel);\r
+ }\r
+ \r
+ public <T> T _getSpecificConfigAttribute(ConfigAttribute<T> configAttribute,\r
+ String displayMode, String configLabel) {\r
+ T attributeValue = null;\r
+\r
+ Map<String, Map<String, ?>> displayModeConfigAttributeMap = this.configRegistry\r
+ .get(configAttribute);\r
+ if (displayModeConfigAttributeMap != null) {\r
+ Map<String, T> configAttributeMap = (Map<String, T>) displayModeConfigAttributeMap.get(displayMode);\r
+ if (configAttributeMap != null) {\r
+ attributeValue = configAttributeMap.get(configLabel);\r
+ if (attributeValue != null) {\r
+ return attributeValue;\r
+ }\r
+ }\r
+ }\r
+\r
+ return attributeValue;\r
+ }\r
+ \r
+ public <T> void setSpecificConfigAttribute(ConfigAttribute<T> configAttribute, String displayMode,\r
+ String configLabel, T attributeValue) {\r
+ Map<String, Map<String, ?>> displayModeConfigAttributeMap = this.configRegistry\r
+ .get(configAttribute);\r
+ if (displayModeConfigAttributeMap == null) {\r
+ displayModeConfigAttributeMap = new HashMap<String, Map<String, ?>>();\r
+ this.configRegistry.put(configAttribute, displayModeConfigAttributeMap);\r
+ }\r
+\r
+ Map<String, T> configAttributeMap = (Map<String, T>) displayModeConfigAttributeMap.get(displayMode);\r
+ if (configAttributeMap == null) {\r
+ configAttributeMap = new HashMap<String, T>();\r
+ displayModeConfigAttributeMap.put(displayMode, configAttributeMap);\r
+ }\r
+\r
+ configAttributeMap.put(configLabel, attributeValue);\r
+ }\r
+\r
+ @Override\r
+ public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue) {\r
+ wrappedRegistry.registerConfigAttribute(configAttribute, attributeValue);\r
+ \r
+ }\r
+\r
+ @Override\r
+ public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue,\r
+ String targetDisplayMode) {\r
+ wrappedRegistry.registerConfigAttribute(configAttribute, attributeValue, targetDisplayMode);\r
+ \r
+ }\r
+\r
+ @Override\r
+ public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue,\r
+ String targetDisplayMode, String configLabel) {\r
+ wrappedRegistry.registerConfigAttribute(configAttribute, attributeValue, targetDisplayMode, configLabel);\r
+ \r
+ }\r
+\r
+ @Override\r
+ public <T> void unregisterConfigAttribute(ConfigAttribute<T> configAttributeType) {\r
+ wrappedRegistry.unregisterConfigAttribute(configAttributeType);\r
+ \r
+ }\r
+\r
+ @Override\r
+ public <T> void unregisterConfigAttribute(ConfigAttribute<T> configAttributeType, String displayMode) {\r
+ wrappedRegistry.unregisterConfigAttribute(configAttributeType, displayMode);\r
+ \r
+ }\r
+\r
+ @Override\r
+ public <T> void unregisterConfigAttribute(ConfigAttribute<T> configAttributeType, String displayMode,\r
+ String configLabel) {\r
+ wrappedRegistry.unregisterConfigAttribute(configAttributeType, displayMode, configLabel);\r
+ }\r
+\r
+ @Override\r
+ public IDisplayModeOrdering getDisplayModeOrdering() {\r
+ return wrappedRegistry.getDisplayModeOrdering();\r
+ }\r
+ \r
+ }\r
+}\r