Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Fauth2014-08-26 19:49:30 +0000
committerDirk Fauth2014-08-26 19:49:30 +0000
commit573d4d2f04500438e5c4ba25599565f1ca5ee670 (patch)
tree9ded5bebfa77120e61a33dea4575fd18cb041ec8
parent95976d22423d49667093d332b796e26d82492be0 (diff)
downloadorg.eclipse.nebula.widgets.nattable-573d4d2f04500438e5c4ba25599565f1ca5ee670.tar.gz
org.eclipse.nebula.widgets.nattable-573d4d2f04500438e5c4ba25599565f1ca5ee670.tar.xz
org.eclipse.nebula.widgets.nattable-573d4d2f04500438e5c4ba25599565f1ca5ee670.zip
Bug 440932 - modifications to edit style action so all columns can be styled if nothing is selected
-rw-r--r--org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/cell/ColumnOverrideLabelAccumulatorTest.java144
-rw-r--r--org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/style/editor/command/DisplayColumnStyleEditorCommandHandlerTest.java26
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/cell/AbstractOverrider.java23
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/cell/ColumnOverrideLabelAccumulator.java147
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/style/editor/command/DisplayColumnStyleEditorCommandHandler.java89
-rw-r--r--org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/examples/_104_Styling/_000_Styled_grid.java7
6 files changed, 386 insertions, 50 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/cell/ColumnOverrideLabelAccumulatorTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/cell/ColumnOverrideLabelAccumulatorTest.java
index cc1a46bf..fef5013b 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/cell/ColumnOverrideLabelAccumulatorTest.java
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/cell/ColumnOverrideLabelAccumulatorTest.java
@@ -12,10 +12,11 @@ package org.eclipse.nebula.widgets.nattable.layer.cell;
import static org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator.PERSISTENCE_KEY;
+import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator;
+import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
import org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture;
import org.junit.Assert;
import org.junit.Before;
@@ -27,6 +28,10 @@ public class ColumnOverrideLabelAccumulatorTest {
private static final String TEST_PREFIX = "TestPrefix";
private static final String TEST_LABEL1 = "TestLabel1";
private static final String TEST_LABEL2 = "TestLabel2";
+ private static final String TEST_LABEL3 = "TestLabel3";
+
+ private static final String TEST_MIX_KEY = "BASE";
+ private static final String TEST_MIX_LABEL = "TestMixLabel";
private ColumnOverrideLabelAccumulator labelAccumulator;
private Properties testProperties;
@@ -38,6 +43,94 @@ public class ColumnOverrideLabelAccumulatorTest {
}
@Test
+ public void testRegisterOverrides() {
+ labelAccumulator.registerColumnOverrides(0, TEST_LABEL1);
+ labelAccumulator.registerColumnOverrides(0, TEST_LABEL2);
+
+ LabelStack configLabels = new LabelStack();
+ labelAccumulator.accumulateConfigLabels(configLabels, 0, 0);
+
+ Assert.assertEquals(2, configLabels.getLabels().size());
+ Assert.assertEquals(TEST_LABEL1, configLabels.getLabels().get(0));
+ Assert.assertEquals(TEST_LABEL2, configLabels.getLabels().get(1));
+ }
+
+ @Test
+ public void testRegisterOverridesEllipse() {
+ labelAccumulator.registerColumnOverrides(0, TEST_LABEL1);
+ labelAccumulator.registerColumnOverrides(0, TEST_LABEL2, TEST_LABEL3);
+
+ LabelStack configLabels = new LabelStack();
+ labelAccumulator.accumulateConfigLabels(configLabels, 0, 0);
+
+ Assert.assertEquals(3, configLabels.getLabels().size());
+ Assert.assertEquals(TEST_LABEL1, configLabels.getLabels().get(0));
+ Assert.assertEquals(TEST_LABEL2, configLabels.getLabels().get(1));
+ Assert.assertEquals(TEST_LABEL3, configLabels.getLabels().get(2));
+ }
+
+ @Test
+ public void testRegisterOverridesCollection() {
+ labelAccumulator.registerColumnOverrides(0, TEST_LABEL1);
+ List<String> labels = new ArrayList<String>();
+ labels.add(TEST_LABEL2);
+ labels.add(TEST_LABEL3);
+ labelAccumulator.registerColumnOverrides(0, labels);
+
+ LabelStack configLabels = new LabelStack();
+ labelAccumulator.accumulateConfigLabels(configLabels, 0, 0);
+
+ Assert.assertEquals(3, configLabels.getLabels().size());
+ Assert.assertEquals(TEST_LABEL1, configLabels.getLabels().get(0));
+ Assert.assertEquals(TEST_LABEL2, configLabels.getLabels().get(1));
+ Assert.assertEquals(TEST_LABEL3, configLabels.getLabels().get(2));
+ }
+
+ @Test
+ public void testRegisterOverridesOnTop() {
+ labelAccumulator.registerColumnOverridesOnTop(0, TEST_LABEL1);
+ labelAccumulator.registerColumnOverridesOnTop(0, TEST_LABEL2);
+
+ LabelStack configLabels = new LabelStack();
+ labelAccumulator.accumulateConfigLabels(configLabels, 0, 0);
+
+ Assert.assertEquals(2, configLabels.getLabels().size());
+ Assert.assertEquals(TEST_LABEL2, configLabels.getLabels().get(0));
+ Assert.assertEquals(TEST_LABEL1, configLabels.getLabels().get(1));
+ }
+
+ @Test
+ public void testRegisterOverridesEllipseOnTop() {
+ labelAccumulator.registerColumnOverridesOnTop(0, TEST_LABEL1);
+ labelAccumulator.registerColumnOverridesOnTop(0, TEST_LABEL2, TEST_LABEL3);
+
+ LabelStack configLabels = new LabelStack();
+ labelAccumulator.accumulateConfigLabels(configLabels, 0, 0);
+
+ Assert.assertEquals(3, configLabels.getLabels().size());
+ Assert.assertEquals(TEST_LABEL2, configLabels.getLabels().get(0));
+ Assert.assertEquals(TEST_LABEL3, configLabels.getLabels().get(1));
+ Assert.assertEquals(TEST_LABEL1, configLabels.getLabels().get(2));
+ }
+
+ @Test
+ public void testRegisterOverridesCollectionOnTop() {
+ labelAccumulator.registerColumnOverridesOnTop(0, TEST_LABEL1);
+ List<String> labels = new ArrayList<String>();
+ labels.add(TEST_LABEL2);
+ labels.add(TEST_LABEL3);
+ labelAccumulator.registerColumnOverridesOnTop(0, labels);
+
+ LabelStack configLabels = new LabelStack();
+ labelAccumulator.accumulateConfigLabels(configLabels, 0, 0);
+
+ Assert.assertEquals(3, configLabels.getLabels().size());
+ Assert.assertEquals(TEST_LABEL2, configLabels.getLabels().get(0));
+ Assert.assertEquals(TEST_LABEL3, configLabels.getLabels().get(1));
+ Assert.assertEquals(TEST_LABEL1, configLabels.getLabels().get(2));
+ }
+
+ @Test
public void testSaveStateToProperties() throws Exception {
labelAccumulator.registerColumnOverrides(0, TEST_LABEL1, TEST_LABEL2);
labelAccumulator.registerColumnOverrides(1, TEST_LABEL2);
@@ -49,10 +142,29 @@ public class ColumnOverrideLabelAccumulatorTest {
Assert.assertEquals(TEST_LABEL1 + "," + TEST_LABEL2, testProperties.getProperty(baseKey + ".0"));
Assert.assertEquals(TEST_LABEL2, testProperties.getProperty(baseKey + ".1"));
}
+
+ @Test
+ public void testMixedSaveStateToProperties() throws Exception {
+ labelAccumulator.registerOverrides(TEST_MIX_KEY, TEST_MIX_LABEL);
+
+ labelAccumulator.registerColumnOverrides(0, TEST_LABEL1, TEST_LABEL2);
+ labelAccumulator.registerColumnOverrides(1, TEST_LABEL2);
+
+ labelAccumulator.registerOverrides(TEST_LABEL3);
+
+ labelAccumulator.saveState(TEST_PREFIX, testProperties);
+
+ String baseKey = TEST_PREFIX + PERSISTENCE_KEY;
+
+ Assert.assertEquals(TEST_MIX_LABEL, testProperties.getProperty(baseKey + "." + TEST_MIX_KEY));
+ Assert.assertEquals(TEST_LABEL1 + "," + TEST_LABEL2, testProperties.getProperty(baseKey + ".0"));
+ Assert.assertEquals(TEST_LABEL2, testProperties.getProperty(baseKey + ".1"));
+ Assert.assertEquals(TEST_LABEL3, testProperties.getProperty(baseKey + "." + ColumnOverrideLabelAccumulator.ALL_COLUMN_KEY));
+ }
@SuppressWarnings("boxing")
@Test
- public void testLoadLablesFromProperties() throws Exception {
+ public void testLoadLabelsFromProperties() throws Exception {
testProperties.setProperty(TEST_PREFIX + PERSISTENCE_KEY + ".0", TEST_LABEL1);
testProperties.setProperty(TEST_PREFIX + PERSISTENCE_KEY + ".5", TEST_LABEL1+","+TEST_LABEL2);
@@ -67,4 +179,32 @@ public class ColumnOverrideLabelAccumulatorTest {
Assert.assertEquals(TEST_LABEL1, overrides.get(0));
Assert.assertEquals(TEST_LABEL2, overrides.get(1));
}
+
+ @SuppressWarnings("boxing")
+ @Test
+ public void testLoadMixedLabelsFromProperties() throws Exception {
+ testProperties.setProperty(TEST_PREFIX + PERSISTENCE_KEY + "." + TEST_MIX_KEY, TEST_MIX_LABEL);
+ testProperties.setProperty(TEST_PREFIX + PERSISTENCE_KEY + ".0", TEST_LABEL1);
+ testProperties.setProperty(TEST_PREFIX + PERSISTENCE_KEY + ".5", TEST_LABEL1+","+TEST_LABEL2);
+ testProperties.setProperty(TEST_PREFIX + PERSISTENCE_KEY + "." + ColumnOverrideLabelAccumulator.ALL_COLUMN_KEY, TEST_LABEL3);
+
+ labelAccumulator.loadState(TEST_PREFIX, testProperties);
+
+ List<String> overrides = labelAccumulator.getOverrides(0);
+ Assert.assertEquals(1, overrides.size());
+ Assert.assertEquals(TEST_LABEL1, overrides.get(0));
+
+ overrides = labelAccumulator.getOverrides(5);
+ Assert.assertEquals(2, overrides.size());
+ Assert.assertEquals(TEST_LABEL1, overrides.get(0));
+ Assert.assertEquals(TEST_LABEL2, overrides.get(1));
+
+ overrides = labelAccumulator.getOverrides(TEST_MIX_KEY);
+ Assert.assertEquals(1, overrides.size());
+ Assert.assertEquals(TEST_MIX_LABEL, overrides.get(0));
+
+ overrides = labelAccumulator.getOverrides(ColumnOverrideLabelAccumulator.ALL_COLUMN_KEY);
+ Assert.assertEquals(1, overrides.size());
+ Assert.assertEquals(TEST_LABEL3, overrides.get(0));
+ }
}
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/style/editor/command/DisplayColumnStyleEditorCommandHandlerTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/style/editor/command/DisplayColumnStyleEditorCommandHandlerTest.java
index 9a8ea551..2088e2a5 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/style/editor/command/DisplayColumnStyleEditorCommandHandlerTest.java
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/style/editor/command/DisplayColumnStyleEditorCommandHandlerTest.java
@@ -12,13 +12,12 @@ package org.eclipse.nebula.widgets.nattable.style.editor.command;
import static org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes.CELL_STYLE;
import static org.eclipse.nebula.widgets.nattable.style.DisplayMode.NORMAL;
-import static org.eclipse.nebula.widgets.nattable.style.editor.command.DisplayColumnStyleEditorCommandHandler.USER_EDITED_STYLE_LABEL;
+import static org.eclipse.nebula.widgets.nattable.style.editor.command.DisplayColumnStyleEditorCommandHandler.USER_EDITED_COLUMN_STYLE_LABEL_PREFIX;
import static org.junit.Assert.assertEquals;
import java.util.List;
import java.util.Properties;
-
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
@@ -31,8 +30,6 @@ import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
import org.eclipse.nebula.widgets.nattable.style.Style;
import org.eclipse.nebula.widgets.nattable.style.VerticalAlignmentEnum;
import org.eclipse.nebula.widgets.nattable.style.editor.ColumnStyleEditorDialog;
-import org.eclipse.nebula.widgets.nattable.style.editor.command.DisplayColumnStyleEditorCommand;
-import org.eclipse.nebula.widgets.nattable.style.editor.command.DisplayColumnStyleEditorCommandHandler;
import org.eclipse.nebula.widgets.nattable.test.fixture.CellStyleFixture;
import org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture;
import org.eclipse.nebula.widgets.nattable.test.fixture.PropertiesFixture;
@@ -72,7 +69,7 @@ public class DisplayColumnStyleEditorCommandHandlerTest {
List<String> columnLableOverrides = handlerUnderTest.columnLabelAccumulator.getOverrides(Integer.valueOf(0));
assertEquals(1, columnLableOverrides.size());
- assertEquals(USER_EDITED_STYLE_LABEL + "0", columnLableOverrides.get(0));
+ assertEquals(USER_EDITED_COLUMN_STYLE_LABEL_PREFIX + "0", columnLableOverrides.get(0));
}
@Test
@@ -131,4 +128,23 @@ public class DisplayColumnStyleEditorCommandHandlerTest {
assertEquals(VerticalAlignmentEnum.TOP, style.getAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT));
}
+
+ @Test
+ public void loadStateForMultipleMixedLabels() throws Exception {
+ PropertiesFixture propertiesFixture = new PropertiesFixture()
+ .addStyleProperties("prefix.userDefinedColumnStyle.USER_EDITED_STYLE_FOR_INDEX_0")
+ .addStyleProperties("prefix.userDefinedColumnStyle.USER_EDITED_STYLE_FOR_INDEX_1")
+ .addStyleProperties("prefix.userDefinedColumnStyle.USER_EDITED_STYLE");
+
+ handlerUnderTest.loadState("prefix", propertiesFixture);
+
+ Style style = (Style) configRegistryFixture.getConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, "USER_EDITED_STYLE_FOR_INDEX_0");
+ assertEquals(HorizontalAlignmentEnum.LEFT, style.getAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT));
+
+ style = (Style) configRegistryFixture.getConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, "USER_EDITED_STYLE_FOR_INDEX_1");
+ assertEquals(VerticalAlignmentEnum.TOP, style.getAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT));
+
+ style = (Style) configRegistryFixture.getConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, "USER_EDITED_STYLE");
+ assertEquals(VerticalAlignmentEnum.TOP, style.getAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT));
+ }
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/cell/AbstractOverrider.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/cell/AbstractOverrider.java
index 4ebda57e..61e3475e 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/cell/AbstractOverrider.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/cell/AbstractOverrider.java
@@ -27,9 +27,13 @@ public abstract class AbstractOverrider implements IConfigLabelAccumulator {
}
public void registerOverrides(Serializable key, String...configLabels) {
+ registerOverrides(key, ArrayUtil.asList(configLabels));
+ }
+
+ public void registerOverrides(Serializable key, List<String> configLabels) {
List<String> existingOverrides = getOverrides(key);
- if(existingOverrides == null){
- registerOverrides(key, ArrayUtil.asList(configLabels));
+ if (existingOverrides == null){
+ overrides.put(key, configLabels);
} else {
for (String configLabel : configLabels) {
if (!existingOverrides.contains(configLabel)) {
@@ -40,21 +44,22 @@ public abstract class AbstractOverrider implements IConfigLabelAccumulator {
}
public void registerOverridesOnTop(Serializable key, String...configLabels) {
+ registerOverridesOnTop(key, ArrayUtil.asList(configLabels));
+ }
+
+ public void registerOverridesOnTop(Serializable key, List<String> configLabels) {
List<String> existingOverrides = getOverrides(key);
- if(existingOverrides == null){
- registerOverrides(key, ArrayUtil.asList(configLabels));
+ if (existingOverrides == null){
+ overrides.put(key, configLabels);
} else {
- for (String configLabel : configLabels) {
+ for (int i = configLabels.size()-1; i >= 0; i--) {
+ String configLabel = configLabels.get(i);
if (!existingOverrides.contains(configLabel)) {
existingOverrides.add(0, configLabel);
}
}
}
}
-
- public void registerOverrides(Serializable key, List<String> configLabels) {
- overrides.put(key, configLabels);
- }
public Map<Serializable, List<String>> getOverrides() {
return overrides;
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/cell/ColumnOverrideLabelAccumulator.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/cell/ColumnOverrideLabelAccumulator.java
index cbfe9cc0..9caccbe2 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/cell/ColumnOverrideLabelAccumulator.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/cell/ColumnOverrideLabelAccumulator.java
@@ -23,6 +23,7 @@ import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;
import org.eclipse.nebula.widgets.nattable.persistence.IPersistable;
import org.eclipse.nebula.widgets.nattable.style.IStyle;
+import org.eclipse.nebula.widgets.nattable.util.ArrayUtil;
/**
@@ -36,6 +37,11 @@ public class ColumnOverrideLabelAccumulator extends AbstractOverrider implements
public static final String PERSISTENCE_KEY = ".columnOverrideLabelAccumulator"; //$NON-NLS-1$
private final ILayer layer;
+
+ /**
+ * This key is used to register overrides for all columns.
+ */
+ public static final String ALL_COLUMN_KEY = "ALL_COLUMNS"; //$NON-NLS-1$
public ColumnOverrideLabelAccumulator(ILayer layer) {
this.layer = layer;
@@ -44,9 +50,18 @@ public class ColumnOverrideLabelAccumulator extends AbstractOverrider implements
/**
* {@inheritDoc}
*/
+ @Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
int columnIndex = layer.getColumnIndexByPosition(columnPosition);
- List<String> overrides = getOverrides(Integer.valueOf(columnIndex));
+
+ addOverrides(configLabels, Integer.valueOf(columnIndex));
+
+ //first add the labels that should be applied for all columns
+ addOverrides(configLabels, ALL_COLUMN_KEY);
+ }
+
+ private void addOverrides(LabelStack configLabels, Serializable key) {
+ List<String> overrides = getOverrides(key);
if (overrides != null) {
for (String configLabel : overrides) {
configLabels.addLabel(configLabel);
@@ -57,17 +72,131 @@ public class ColumnOverrideLabelAccumulator extends AbstractOverrider implements
/**
* Register labels to be contributed a column. This label will be applied to
* all cells in the column.
+ * @param columnIndex The column index of the column to which the config label should
+ * be contributed.
+ * @param configLabels The config labels to add.
*/
public void registerColumnOverrides(int columnIndex, String... configLabels) {
- super.registerOverrides(Integer.valueOf(columnIndex), configLabels);
+ super.registerOverrides(columnIndex, configLabels);
+ }
+
+ /**
+ * Register labels to be contributed a column. This label will be applied to
+ * all cells in the column.
+ * @param columnIndex The column index of the column to which the config label should
+ * be contributed.
+ * @param configLabels The config labels to add.
+ */
+ public void registerColumnOverrides(int columnIndex, List<String> configLabels) {
+ super.registerOverrides(columnIndex, configLabels);
}
/**
* Register labels to be contributed a column. This label will be applied to
* all cells in the column.
+ * Using this method will add the labels on top of the label stack.
+ * @param columnIndex The column index of the column to which the config label should
+ * be contributed.
+ * @param configLabels The config labels to add.
*/
public void registerColumnOverridesOnTop(int columnIndex, String... configLabels) {
- super.registerOverridesOnTop(Integer.valueOf(columnIndex), configLabels);
+ super.registerOverridesOnTop(columnIndex, configLabels);
+ }
+
+ /**
+ * Register labels to be contributed a column. This label will be applied to
+ * all cells in the column.
+ * Using this method will add the labels on top of the label stack.
+ * @param columnIndex The column index of the column to which the config label should
+ * be contributed.
+ * @param configLabels The config labels to add.
+ */
+ public void registerColumnOverridesOnTop(int columnIndex, List<String> configLabels) {
+ super.registerOverridesOnTop(columnIndex, configLabels);
+ }
+
+ /**
+ * Unregister a label that was contributed for a column.
+ * @param columnIndex The column index of the column to which a config label was contributed.
+ * @param configLabel The config label to remove.
+ */
+ public void unregisterOverrides(int columnIndex, String configLabel) {
+ List<String> overrides = getOverrides(columnIndex);
+ if (overrides != null) {
+ overrides.remove(configLabel);
+ }
+ }
+
+ /**
+ * Unregister labels that were contributed for a column.
+ * @param columnIndex The column index of the column to which a config label was contributed.
+ * @param configLabels The config labels to remove.
+ */
+ public void unregisterOverrides(int columnIndex, String... configLabels) {
+ List<String> overrides = getOverrides(columnIndex);
+ if (overrides != null) {
+ overrides.removeAll(ArrayUtil.asList(configLabels));
+ }
+ }
+
+ /**
+ * Register a label to be contributed to all columns.
+ * This label will be applied to all cells.
+ * @param configLabel The config label that should be added to all cells.
+ */
+ public void registerOverrides(String configLabel) {
+ super.registerOverrides(ALL_COLUMN_KEY, configLabel);
+ }
+
+ /**
+ * Register labels to be contributed to all columns.
+ * These labels will be applied to all cells.
+ * @param configLabels The config labels that should be added to all cells.
+ */
+ public void registerOverrides(List<String> configLabels) {
+ super.registerOverrides(ALL_COLUMN_KEY, configLabels);
+ }
+
+ /**
+ * Register a label to be contributed to all columns.
+ * This label will be applied to all cells.
+ * @param configLabel The config label that should be added to all cells.
+ */
+ public void registerOverridesOnTop(String configLabel) {
+ super.registerOverridesOnTop(ALL_COLUMN_KEY, configLabel);
+ }
+
+ /**
+ * Register labels to be contributed to all columns.
+ * These labels will be applied to all cells.
+ * @param configLabels The config labels that should be added to all cells.
+ */
+ public void registerOverridesOnTop(List<String> configLabels) {
+ super.registerOverridesOnTop(ALL_COLUMN_KEY, configLabels);
+ }
+
+ /**
+ * Unregister a label that was contributed for all columns.
+ * @param configLabel The config label to remove.
+ */
+ public void unregisterOverrides(String configLabel) {
+ List<String> overrides = getOverrides(ALL_COLUMN_KEY);
+ overrides.remove(configLabel);
+ if (overrides.isEmpty()) {
+ removeOverride(ALL_COLUMN_KEY);
+ }
+ }
+
+ /**
+ * Unregister labels that were contributed for all columns.
+ * @param configLabels The config labels to remove.
+ */
+ public void unregisterOverrides(List<String> configLabels) {
+ List<String> overrides = getOverrides(ALL_COLUMN_KEY);
+ overrides.removeAll(configLabels);
+ if (overrides.isEmpty()) {
+ removeOverride(ALL_COLUMN_KEY);
+ }
}
/**
@@ -76,6 +205,7 @@ public class ColumnOverrideLabelAccumulator extends AbstractOverrider implements
* Example for column 0:
* prefix.columnOverrideLabelAccumulator.0 = LABEL1,LABEL2
*/
+ @Override
public void saveState(String prefix, Properties properties) {
Map<Serializable, List<String>> overrides = getOverrides();
@@ -99,14 +229,21 @@ public class ColumnOverrideLabelAccumulator extends AbstractOverrider implements
* Load the overrides state from the given properties file.
* @see #saveState(String, Properties)
*/
+ @Override
public void loadState(String prefix, Properties properties) {
Set<Object> keySet = properties.keySet();
for (Object key : keySet) {
String keyString = (String) key;
if(keyString.contains(PERSISTENCE_KEY)){
String labelsFromPropertyValue = properties.getProperty(keyString).trim();
- String columnIndexFromKey = keyString.substring(keyString.lastIndexOf(DOT) + 1);
- registerColumnOverrides(Integer.parseInt(columnIndexFromKey), labelsFromPropertyValue.split(VALUE_SEPARATOR));
+ String overrideKey = keyString.substring(keyString.lastIndexOf(DOT) + 1);
+ try {
+ registerColumnOverrides(Integer.parseInt(overrideKey), labelsFromPropertyValue.split(VALUE_SEPARATOR));
+ }
+ catch (NumberFormatException e) {
+ //if the last part of the key can not be parsed to an Integer, we use the key as is
+ registerOverrides(overrideKey, labelsFromPropertyValue.split(VALUE_SEPARATOR));
+ }
}
}
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/style/editor/command/DisplayColumnStyleEditorCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/style/editor/command/DisplayColumnStyleEditorCommandHandler.java
index cc410e74..cda9c202 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/style/editor/command/DisplayColumnStyleEditorCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/style/editor/command/DisplayColumnStyleEditorCommandHandler.java
@@ -21,9 +21,9 @@ import java.util.Set;
import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
-import org.eclipse.nebula.widgets.nattable.layer.LayerUtil;
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator;
import org.eclipse.nebula.widgets.nattable.layer.event.ColumnVisualUpdateEvent;
+import org.eclipse.nebula.widgets.nattable.layer.event.VisualRefreshEvent;
import org.eclipse.nebula.widgets.nattable.persistence.IPersistable;
import org.eclipse.nebula.widgets.nattable.persistence.StylePersistor;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
@@ -42,7 +42,8 @@ import org.eclipse.swt.widgets.Display;
public class DisplayColumnStyleEditorCommandHandler extends AbstractLayerCommandHandler<DisplayColumnStyleEditorCommand> implements IPersistable {
protected static final String PERSISTENCE_PREFIX = "userDefinedColumnStyle"; //$NON-NLS-1$
- protected static final String USER_EDITED_STYLE_LABEL = "USER_EDITED_STYLE_FOR_INDEX_"; //$NON-NLS-1$
+ protected static final String USER_EDITED_STYLE_LABEL = "USER_EDITED_STYLE"; //$NON-NLS-1$
+ protected static final String USER_EDITED_COLUMN_STYLE_LABEL_PREFIX = "USER_EDITED_STYLE_FOR_INDEX_"; //$NON-NLS-1$
protected final SelectionLayer selectionLayer;
protected ColumnOverrideLabelAccumulator columnLabelAccumulator;
@@ -76,22 +77,21 @@ public class DisplayColumnStyleEditorCommandHandler extends AbstractLayerCommand
int[] selectedColumns = getSelectedColumnIndeces();
if (selectedColumns.length > 0) {
- applySelectedStyleToColumns(command, getSelectedColumnIndeces());
+ applySelectedStyleToColumns(command, selectedColumns);
//fire refresh event
this.selectionLayer.fireLayerEvent(new ColumnVisualUpdateEvent(selectionLayer, selectionLayer.getSelectedColumnPositions()));
}
else {
- applySelectedStyleToColumns(command, new int[] {columnIndexOfClick});
+ applySelectedStyle();
//fire refresh event
- int pos = LayerUtil.convertColumnPosition(command.getNattableLayer(), command.columnPosition, selectionLayer);
- this.selectionLayer.fireLayerEvent(new ColumnVisualUpdateEvent(selectionLayer, pos));
+ this.selectionLayer.fireLayerEvent(new VisualRefreshEvent(selectionLayer));
}
return true;
}
private int[] getSelectedColumnIndeces() {
- int[] selectedColumnPositions = selectionLayer.getSelectedColumnPositions();
+ int[] selectedColumnPositions = selectionLayer.getFullySelectedColumnPositions();
int[] selectedColumnIndeces = new int[selectedColumnPositions.length];
for (int i=0; i<selectedColumnPositions.length; i++) {
selectedColumnIndeces[i] = selectionLayer.getColumnIndexByPosition(selectedColumnPositions[i]);
@@ -112,19 +112,43 @@ public class DisplayColumnStyleEditorCommandHandler extends AbstractLayerCommand
final int columnIndex = columnIndeces[i];
String configLabel = getConfigLabel(columnIndex);
- if (newColumnCellStyle == null) {
- stylesToPersist.remove(configLabel);
- } else {
- newColumnCellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, dialog.getNewColumnBorderStyle());
- stylesToPersist.put(configLabel, newColumnCellStyle);
+ applySelectedStyle(newColumnCellStyle, configLabel);
+
+ if (newColumnCellStyle != null) {
+ columnLabelAccumulator.registerColumnOverridesOnTop(columnIndex, configLabel);
+ }
+ else {
+ columnLabelAccumulator.unregisterOverrides(columnIndex, configLabel);
}
- configRegistry.registerConfigAttribute(CELL_STYLE, newColumnCellStyle, NORMAL, configLabel);
- columnLabelAccumulator.registerColumnOverridesOnTop(columnIndex, configLabel);
}
}
+ protected void applySelectedStyle() {
+ // Read the edited styles
+ Style newColumnCellStyle = dialog.getNewColumnCellStyle();
+
+ applySelectedStyle(newColumnCellStyle, USER_EDITED_STYLE_LABEL);
+
+ if (newColumnCellStyle != null) {
+ columnLabelAccumulator.registerOverridesOnTop(USER_EDITED_STYLE_LABEL);
+ }
+ else {
+ columnLabelAccumulator.unregisterOverrides(USER_EDITED_STYLE_LABEL);
+ }
+ }
+
+ protected void applySelectedStyle(Style newColumnCellStyle, String configLabel) {
+ if (newColumnCellStyle == null) {
+ stylesToPersist.remove(configLabel);
+ } else {
+ newColumnCellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, dialog.getNewColumnBorderStyle());
+ stylesToPersist.put(configLabel, newColumnCellStyle);
+ }
+ configRegistry.registerConfigAttribute(CELL_STYLE, newColumnCellStyle, NORMAL, configLabel);
+ }
+
protected String getConfigLabel(int columnIndex) {
- return USER_EDITED_STYLE_LABEL + columnIndex;
+ return USER_EDITED_COLUMN_STYLE_LABEL_PREFIX + columnIndex;
}
@Override
@@ -137,22 +161,35 @@ public class DisplayColumnStyleEditorCommandHandler extends AbstractLayerCommand
// Relevant Key
if (keyString.contains(PERSISTENCE_PREFIX)) {
- int colIndex = parseColumnIndexFromKey(keyString);
-
- // Has the config label been processed
- if (!stylesToPersist.keySet().contains(getConfigLabel(colIndex))) {
- Style savedStyle = StylePersistor.loadStyle(prefix + DOT + getConfigLabel(colIndex), properties);
-
- configRegistry.registerConfigAttribute(CELL_STYLE, savedStyle, NORMAL, getConfigLabel(colIndex));
- stylesToPersist.put(getConfigLabel(colIndex), savedStyle);
- columnLabelAccumulator.registerColumnOverrides(colIndex, getConfigLabel(colIndex));
+ if (keyString.contains(USER_EDITED_COLUMN_STYLE_LABEL_PREFIX)) {
+ int colIndex = parseColumnIndexFromKey(keyString);
+
+ // Has the config label been processed
+ String configLabel = getConfigLabel(colIndex);
+ if (!stylesToPersist.keySet().contains(configLabel)) {
+ Style savedStyle = StylePersistor.loadStyle(prefix + DOT + configLabel, properties);
+
+ configRegistry.registerConfigAttribute(CELL_STYLE, savedStyle, NORMAL, configLabel);
+ stylesToPersist.put(configLabel, savedStyle);
+ columnLabelAccumulator.registerColumnOverrides(colIndex, configLabel);
+ }
+ }
+ else {
+ // Has the config label been processed
+ if (!stylesToPersist.keySet().contains(USER_EDITED_STYLE_LABEL)) {
+ Style savedStyle = StylePersistor.loadStyle(prefix + DOT + USER_EDITED_STYLE_LABEL, properties);
+
+ configRegistry.registerConfigAttribute(CELL_STYLE, savedStyle, NORMAL, USER_EDITED_STYLE_LABEL);
+ stylesToPersist.put(USER_EDITED_STYLE_LABEL, savedStyle);
+ columnLabelAccumulator.registerOverrides(USER_EDITED_STYLE_LABEL, USER_EDITED_STYLE_LABEL);
+ }
}
}
}
}
-
+
protected int parseColumnIndexFromKey(String keyString) {
- int colLabelStartIndex = keyString.indexOf(USER_EDITED_STYLE_LABEL);
+ int colLabelStartIndex = keyString.indexOf(USER_EDITED_COLUMN_STYLE_LABEL_PREFIX);
String columnConfigLabel = keyString.substring(colLabelStartIndex, keyString.indexOf('.', colLabelStartIndex));
int lastUnderscoreInLabel = columnConfigLabel.lastIndexOf('_', colLabelStartIndex);
diff --git a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/examples/_104_Styling/_000_Styled_grid.java b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/examples/_104_Styling/_000_Styled_grid.java
index 52046ae8..b528b345 100644
--- a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/examples/_104_Styling/_000_Styled_grid.java
+++ b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/examples/_104_Styling/_000_Styled_grid.java
@@ -30,12 +30,12 @@ import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter;
import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator;
import org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionStyleConfiguration;
import org.eclipse.nebula.widgets.nattable.style.BorderStyle;
+import org.eclipse.nebula.widgets.nattable.style.BorderStyle.LineStyleEnum;
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
import org.eclipse.nebula.widgets.nattable.style.Style;
import org.eclipse.nebula.widgets.nattable.style.VerticalAlignmentEnum;
-import org.eclipse.nebula.widgets.nattable.style.BorderStyle.LineStyleEnum;
import org.eclipse.nebula.widgets.nattable.style.editor.command.DisplayColumnStyleEditorCommandHandler;
import org.eclipse.nebula.widgets.nattable.ui.menu.DebugMenuConfiguration;
import org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration;
@@ -76,6 +76,7 @@ public class _000_Styled_grid extends AbstractNatExample {
" Support is provided for automatic creation and disposal for SWT colors/fonts (see GUIHelper)";
}
+ @Override
public Control createExampleControl(Composite parent) {
NatTable natTable = setup(parent);
@@ -102,8 +103,8 @@ public class _000_Styled_grid extends AbstractNatExample {
ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
ColumnOverrideLabelAccumulator bodyLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
- aggregrateConfigLabelAccumulator.add(bodyLabelAccumulator);
aggregrateConfigLabelAccumulator.add(columnLabelAccumulator);
+ aggregrateConfigLabelAccumulator.add(bodyLabelAccumulator);
// Add a label for the highlighted column
// We will add a style for this label to the config registry in a bit
@@ -137,7 +138,7 @@ public class _000_Styled_grid extends AbstractNatExample {
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, // attribute to apply
style, // value of the attribute
DisplayMode.NORMAL, // apply during normal rendering i.e not during selection or edit
- COLUMN_LABEL_1); // apply the above for all cells with this label
+ BODY_LABEL_1); // apply the above for all cells with this label
}
private void addCustomStyling(NatTable natTable) {

Back to the top