import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
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.IStyle;
import org.eclipse.nebula.widgets.nattable.style.Style;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
wrapper.clear();
wrapper.wrappedRegistry = configRegistry;
TreeNode node = treeData.getDataAtIndex(cell.getRowIndex());
- Style style = new Style();
+ PubStyle style = new PubStyle();
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));
+ {
+ // Attempt to reuse existing style, so that we override only those parts that GE contributions define.
+ Style defStyle = getStyle("BODY");
+ style.applyTo(defStyle);
+ wrapper.setSpecificConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, "BODY", defStyle);
+ }
+ if (configRegistry.getSpecificConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, "ODD_BODY") != null) {
+ Style oddStyle = getStyle("ODD_BODY");
+ style.applyTo(oddStyle);
+ wrapper.setSpecificConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, "ODD_BODY", oddStyle);
+ }
+ if (configRegistry.getSpecificConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, "EVEN_BODY") != null) {
+ Style evenStyle = getStyle("EVEN_BODY");
+ style.applyTo(evenStyle);
+ wrapper.setSpecificConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, "EVEN_BODY", evenStyle);
+ }
super.paintCell(cell, gc, rectangle, wrapper);
}
+ private static class PubStyle implements IStyle {
+ Map<ConfigAttribute<?>, Object> styleAttributeValueMap = new HashMap<ConfigAttribute<?>, Object>();
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> T getAttributeValue(ConfigAttribute<T> styleAttribute) {
+ return (T) this.styleAttributeValueMap.get(styleAttribute);
+ }
+
+ @Override
+ public <T> void setAttributeValue(ConfigAttribute<T> styleAttribute, T value) {
+ this.styleAttributeValueMap.put(styleAttribute, value);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder resultBuilder = new StringBuilder();
+ resultBuilder.append(this.getClass().getSimpleName() + ": "); //$NON-NLS-1$
+
+ for (Entry<ConfigAttribute<?>, Object> entry : this.styleAttributeValueMap.entrySet()) {
+ resultBuilder.append(entry.getKey()
+ + ": " + entry.getValue() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return resultBuilder.toString();
+ }
+
+ public void applyTo(IStyle style) {
+ for (Entry<ConfigAttribute<?>, Object> e : styleAttributeValueMap.entrySet()) {
+ style.setAttributeValue((ConfigAttribute)e.getKey(), e.getValue());
+ }
+ }
+
+ }
+
+ private Style getStyle(String configLabel) {
+ Style s = (Style)wrapper.getSpecificConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, configLabel);
+ if (s == null)
+ s = new Style();
+ else
+ s = s.clone();
+ return s;
+ }
+
private class ConfigRegistryWrapper extends ConfigRegistry {
IConfigRegistry wrappedRegistry;
Map<ConfigAttribute<?>, Map<String, Map<String, ?>>> configRegistry = new HashMap<ConfigAttribute<?>, Map<String, Map<String, ?>>>();
import org.eclipse.jface.resource.FontDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
-import org.eclipse.nebula.widgets.nattable.style.Style;
+import org.eclipse.nebula.widgets.nattable.style.IStyle;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
}
}
- public void getStyle(int column, Style style) {
+ public void getStyle(int column, IStyle style) {
String key = explorerContext.getGe().getColumns()[column].getKey();
FontDescriptor font = explorerContext.getGe().originalFont;
ColorDescriptor bg = explorerContext.getGe().originalBackground;
}
if (bg != explorerContext.getGe().originalBackground)
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR,(Color) explorerContext.getGe().localResourceManager.get(bg));
- else
- style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR,(Color) (explorerContext.getGe().originalBackground != null ? explorerContext.getGe().localResourceManager.get(explorerContext.getGe().originalBackground) : null));
+ else if (explorerContext.getGe().originalBackground != null)
+ style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR,(Color) (explorerContext.getGe().localResourceManager.get(explorerContext.getGe().originalBackground)));
if (fg != explorerContext.getGe().originalForeground)
style.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR,(Color) explorerContext.getGe().localResourceManager.get(fg));
- else
- style.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR,(Color) (explorerContext.getGe().originalForeground != null ? explorerContext.getGe().localResourceManager.get(explorerContext.getGe().originalForeground) : null));
+ else if (explorerContext.getGe().originalForeground != null)
+ style.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR,(Color) (explorerContext.getGe().localResourceManager.get(explorerContext.getGe().originalForeground)));
}