Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAparna Argade2017-02-28 14:18:07 +0000
committerAparna Argade2017-04-27 14:06:06 +0000
commitf5bab67728a5cdf5e3094ea34b01a610330d3a74 (patch)
tree96f5eb99d2f3ecfd0313e487a4ce9d4c5fd2671f
parentcb7f3a50c8d747bdf3981254383c136da69fe5fb (diff)
downloadorg.eclipse.swtbot-f5bab67728a5cdf5e3094ea34b01a610330d3a74.tar.gz
org.eclipse.swtbot-f5bab67728a5cdf5e3094ea34b01a610330d3a74.tar.xz
org.eclipse.swtbot-f5bab67728a5cdf5e3094ea34b01a610330d3a74.zip
Bug 512815: SWTBotNatTable Cell Style using ConfigRegistry labels
Checks that the cell has the label used to register style. Change-Id: I651e1acf77d6e1090d771e7b2918b6eeec1fa39f Signed-off-by: Aparna Argade <aprsac@yahoo.com>
-rw-r--r--org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test2/TestNatTableOtherFeatures.java15
-rw-r--r--org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test2/_801_VerticalCompositionWithFeaturesExample.java27
-rw-r--r--org.eclipse.swtbot.nebula.nattable.finder/src/org/eclipse/swtbot/nebula/nattable/finder/widgets/SWTBotNatTable.java23
3 files changed, 65 insertions, 0 deletions
diff --git a/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test2/TestNatTableOtherFeatures.java b/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test2/TestNatTableOtherFeatures.java
index 0e76c5a8..aca73685 100644
--- a/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test2/TestNatTableOtherFeatures.java
+++ b/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test2/TestNatTableOtherFeatures.java
@@ -8,12 +8,15 @@
* Contributors:
* Aparna Argade(Cadence Design Systems, Inc.) - initial API and implementation
* Patrick Tasse - Test viewport scrolling (Bug 504483)
+ * Aparna Argade(Cadence Design Systems, Inc.) - Bug 512815
*******************************************************************************/
package org.eclipse.swtbot.nebula.nattable.finder.test2;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import org.eclipse.swtbot.nebula.nattable.finder.widgets.Position;
import org.eclipse.swtbot.nebula.nattable.finder.widgets.SWTBotNatTable;
@@ -131,4 +134,16 @@ public class TestNatTableOtherFeatures extends _801_VerticalCompositionWithFeatu
nattable.scrollViewport(position, 0, 30);
}
+ /**
+ * Tests labels used for custom style.
+ */
+ @Test
+ public void testCellLabel() {
+ SWTBotNatTable nattable = bot.nattable();
+
+ // Only the specific cell has the label and any other cell doesn't have it
+ assertTrue(nattable.hasConfigLabel(7, 1, "FOO"));
+ assertFalse(nattable.hasConfigLabel(7, 0, "FOO"));
+ }
+
}
diff --git a/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test2/_801_VerticalCompositionWithFeaturesExample.java b/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test2/_801_VerticalCompositionWithFeaturesExample.java
index 34eca770..182723f0 100644
--- a/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test2/_801_VerticalCompositionWithFeaturesExample.java
+++ b/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test2/_801_VerticalCompositionWithFeaturesExample.java
@@ -8,6 +8,7 @@
* Contributors:
* Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation
* Aparna Argade (Cadence Design Systems, Inc.) - Simplification for SWTBotNatTable tests
+ * Aparna Argade(Cadence Design Systems, Inc.) - Bug 512815
*******************************************************************************/
package org.eclipse.swtbot.nebula.nattable.finder.test2;
@@ -44,11 +45,16 @@ import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator;
+import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
+import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.nebula.widgets.nattable.style.Style;
+import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
@@ -107,6 +113,8 @@ public class _801_VerticalCompositionWithFeaturesExample {
return shell;
}
+ private static final String FOO_LABEL = "FOO";
+
private Control createNatTable(final Shell shell) {
ConfigRegistry configRegistry = new ConfigRegistry();
@@ -180,6 +188,20 @@ public class _801_VerticalCompositionWithFeaturesExample {
compositeLayer.addConfiguration(new DefaultEditConfiguration());
compositeLayer.addConfiguration(new DefaultEditBindings());
+ // Reference:_001_Custom_styling_of_specific_cells from NatTableExamples
+ // Custom label "FOO" for cell at column, row index (1, 5)
+ IConfigLabelAccumulator cellLabelAccumulator = new IConfigLabelAccumulator() {
+ @Override
+ public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
+ int columnIndex = bodyDataLayer.getColumnIndexByPosition(columnPosition);
+ int rowIndex = bodyDataLayer.getRowIndexByPosition(rowPosition);
+ if (columnIndex == 1 && rowIndex == 5) {
+ configLabels.addLabel(FOO_LABEL);
+ }
+ }
+ };
+ bodyDataLayer.setConfigLabelAccumulator(cellLabelAccumulator);
+
final NatTable natTable = new NatTable(gridPanel, compositeLayer, false);
natTable.setConfigRegistry(configRegistry);
@@ -209,6 +231,11 @@ public class _801_VerticalCompositionWithFeaturesExample {
new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL,
ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
+ Style cellStyle = new Style();
+ cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_GREEN);
+ configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL,
+ FOO_LABEL);
+
}
});
natTable.configure();
diff --git a/org.eclipse.swtbot.nebula.nattable.finder/src/org/eclipse/swtbot/nebula/nattable/finder/widgets/SWTBotNatTable.java b/org.eclipse.swtbot.nebula.nattable.finder/src/org/eclipse/swtbot/nebula/nattable/finder/widgets/SWTBotNatTable.java
index 86ae44f0..a6cdd1bd 100644
--- a/org.eclipse.swtbot.nebula.nattable.finder/src/org/eclipse/swtbot/nebula/nattable/finder/widgets/SWTBotNatTable.java
+++ b/org.eclipse.swtbot.nebula.nattable.finder/src/org/eclipse/swtbot/nebula/nattable/finder/widgets/SWTBotNatTable.java
@@ -8,6 +8,7 @@
* Contributors:
* Aparna Argade(Cadence Design Systems, Inc.) - initial API and implementation
* Patrick Tasse - Support viewport scrolling (Bug 504483)
+ * Aparna Argade(Cadence Design Systems, Inc.) - Bug 512815
*******************************************************************************/
package org.eclipse.swtbot.nebula.nattable.finder.widgets;
@@ -15,6 +16,7 @@ import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.coordinate.PixelCoordinate;
import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
@@ -497,4 +499,25 @@ public class SWTBotNatTable extends AbstractSWTBot<NatTable> {
return new Position(headerRow, column);
}
+ /**
+ * Returns <code>true</code> if the given label is associated with the cell;
+ * <code>false</code> otherwise.
+ *
+ * @param row
+ * the visible row position in the NatTable
+ * @param column
+ * the visible column position in the NatTable
+ * @param label
+ * the config label
+ *
+ * @return <code>true</code> if the cell has label; <code>false</code>
+ * otherwise
+ * @since 2.6
+ */
+ public boolean hasConfigLabel(int row, int column, String label) {
+ assertIsLegalCell(row, column);
+ LabelStack labels = widget.getConfigLabelsByPosition(column, row);
+ return labels.hasLabel(label);
+ }
+
}

Back to the top