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