1 package org.simantics.browsing.ui.nattable;
3 import java.util.HashMap;
7 import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
8 import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
9 import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
10 import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
11 import org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper;
12 import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;
13 import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
14 import org.eclipse.nebula.widgets.nattable.style.ConfigAttribute;
15 import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
16 import org.eclipse.nebula.widgets.nattable.style.IDisplayModeOrdering;
17 import org.eclipse.nebula.widgets.nattable.style.Style;
18 import org.eclipse.swt.graphics.GC;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.graphics.Rectangle;
22 public class GEStyler extends CellPainterWrapper{
24 private GETreeData treeData;
26 public GEStyler(GETreeData treeData, ICellPainter painter) {
28 this.treeData = treeData;
31 private ConfigRegistryWrapper wrapper = new ConfigRegistryWrapper();
34 public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
36 wrapper.wrappedRegistry = configRegistry;
37 TreeNode node = treeData.getDataAtIndex(cell.getRowIndex());
38 Style style = new Style();
39 node.getStyle(cell.getColumnIndex(), style);
40 Image image = node.getImage(cell.getColumnIndex());
42 style.setAttributeValue(CellStyleAttributes.IMAGE, image);
44 wrapper.setSpecificConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, "BODY", style);
45 wrapper.setSpecificConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.SELECT, "BODY", style);
46 wrapper.setSpecificConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.SELECT_HOVER, "BODY", style);
47 // wrapper.setSpecificConfigAttribute(CellStyleAttributes.FOREGROUND_COLOR, DisplayMode.NORMAL, "BODY", style.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
48 // wrapper.setSpecificConfigAttribute(CellStyleAttributes.BACKGROUND_COLOR, DisplayMode.NORMAL, "BODY", style.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
49 // wrapper.setSpecificConfigAttribute(CellStyleAttributes.FONT, DisplayMode.NORMAL, "BODY", style.getAttributeValue(CellStyleAttributes.FONT));
50 super.paintCell(cell, gc, rectangle, wrapper);
53 private class ConfigRegistryWrapper extends ConfigRegistry {
54 IConfigRegistry wrappedRegistry;
55 Map<ConfigAttribute<?>, Map<String, Map<String, ?>>> configRegistry = new HashMap<ConfigAttribute<?>, Map<String, Map<String, ?>>>();
58 configRegistry.clear();
62 public <T> T getConfigAttribute(ConfigAttribute<T> configAttribute, String targetDisplayMode,
63 String... configLabels) {
64 return wrappedRegistry.getConfigAttribute(configAttribute, targetDisplayMode, configLabels);
68 public <T> T getConfigAttribute(ConfigAttribute<T> configAttribute, String targetDisplayMode,
69 List<String> configLabels) {
70 return wrappedRegistry.getConfigAttribute(configAttribute, targetDisplayMode, configLabels);
74 public <T> T getSpecificConfigAttribute(ConfigAttribute<T> configAttribute, String displayMode,
76 T value = _getSpecificConfigAttribute(configAttribute, displayMode, configLabel);
79 return wrappedRegistry.getSpecificConfigAttribute(configAttribute, displayMode, configLabel);
82 public <T> T _getSpecificConfigAttribute(ConfigAttribute<T> configAttribute,
83 String displayMode, String configLabel) {
84 T attributeValue = null;
86 Map<String, Map<String, ?>> displayModeConfigAttributeMap = this.configRegistry
87 .get(configAttribute);
88 if (displayModeConfigAttributeMap != null) {
89 Map<String, T> configAttributeMap = (Map<String, T>) displayModeConfigAttributeMap.get(displayMode);
90 if (configAttributeMap != null) {
91 attributeValue = configAttributeMap.get(configLabel);
92 if (attributeValue != null) {
93 return attributeValue;
98 return attributeValue;
101 public <T> void setSpecificConfigAttribute(ConfigAttribute<T> configAttribute, String displayMode,
102 String configLabel, T attributeValue) {
103 Map<String, Map<String, ?>> displayModeConfigAttributeMap = this.configRegistry
104 .get(configAttribute);
105 if (displayModeConfigAttributeMap == null) {
106 displayModeConfigAttributeMap = new HashMap<String, Map<String, ?>>();
107 this.configRegistry.put(configAttribute, displayModeConfigAttributeMap);
110 Map<String, T> configAttributeMap = (Map<String, T>) displayModeConfigAttributeMap.get(displayMode);
111 if (configAttributeMap == null) {
112 configAttributeMap = new HashMap<String, T>();
113 displayModeConfigAttributeMap.put(displayMode, configAttributeMap);
116 configAttributeMap.put(configLabel, attributeValue);
120 public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue) {
121 wrappedRegistry.registerConfigAttribute(configAttribute, attributeValue);
126 public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue,
127 String targetDisplayMode) {
128 wrappedRegistry.registerConfigAttribute(configAttribute, attributeValue, targetDisplayMode);
133 public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue,
134 String targetDisplayMode, String configLabel) {
135 wrappedRegistry.registerConfigAttribute(configAttribute, attributeValue, targetDisplayMode, configLabel);
140 public <T> void unregisterConfigAttribute(ConfigAttribute<T> configAttributeType) {
141 wrappedRegistry.unregisterConfigAttribute(configAttributeType);
146 public <T> void unregisterConfigAttribute(ConfigAttribute<T> configAttributeType, String displayMode) {
147 wrappedRegistry.unregisterConfigAttribute(configAttributeType, displayMode);
152 public <T> void unregisterConfigAttribute(ConfigAttribute<T> configAttributeType, String displayMode,
153 String configLabel) {
154 wrappedRegistry.unregisterConfigAttribute(configAttributeType, displayMode, configLabel);
158 public IDisplayModeOrdering getDisplayModeOrdering() {
159 return wrappedRegistry.getDisplayModeOrdering();