use of org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack in project nebula.widgets.nattable by eclipse.
the class _000_Styled_grid method setup.
private NatTable setup(Composite parent) {
DummyGridLayerStack gridLayer = new DummyGridLayerStack();
final NatTable natTable = new NatTable(parent, gridLayer, false);
DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
// Add an AggregateConfigLabelAccumulator - we can add other
// accumulators to this as required
AggregateConfigLabelAccumulator aggregrateConfigLabelAccumulator = new AggregateConfigLabelAccumulator();
bodyDataLayer.setConfigLabelAccumulator(aggregrateConfigLabelAccumulator);
ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
ColumnOverrideLabelAccumulator bodyLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
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
bodyLabelAccumulator.registerColumnOverrides(2, BODY_LABEL_1);
columnLabelAccumulator.registerColumnOverrides(2, COLUMN_LABEL_1);
// Register a command handler for the StyleEditorDialog
DisplayColumnStyleEditorCommandHandler styleChooserCommandHandler = new DisplayColumnStyleEditorCommandHandler(gridLayer.getBodyLayer().getSelectionLayer(), columnLabelAccumulator, natTable.getConfigRegistry());
DefaultBodyLayerStack bodyLayer = gridLayer.getBodyLayer();
bodyLayer.registerCommandHandler(styleChooserCommandHandler);
// Register the style editor as persistable
// This will persist the style applied to the columns when
// NatTable#saveState is invoked
bodyLayer.registerPersistable(styleChooserCommandHandler);
bodyLayer.registerPersistable(columnLabelAccumulator);
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerSummaryRowConcurrencyTest method setup.
@Before
public void setup() {
List<Value> values = new ArrayList<Value>();
values.add(new Value(1));
values.add(new Value(2));
values.add(new Value(3));
values.add(new Value(4));
values.add(new Value(5));
values.add(new Value(6));
values.add(new Value(7));
values.add(new Value(8));
values.add(new Value(9));
values.add(new Value(10));
IColumnAccessor<Value> columnAccessor = new IColumnAccessor<Value>() {
@Override
public Object getDataValue(Value rowObject, int columnIndex) {
if (columnIndex % 2 == 0) {
try {
Thread.sleep(80);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return rowObject.value;
}
@Override
public void setDataValue(Value rowObject, int columnIndex, Object newValue) {
}
@Override
public int getColumnCount() {
return 10;
}
};
EventList<Value> eventList = GlazedLists.eventList(values);
TransformedList<Value, Value> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
ConfigRegistry configRegistry = new ConfigRegistry();
final GroupByDataLayer<Value> dataLayer = new GroupByDataLayer<Value>(new GroupByModel(), eventList, columnAccessor);
// DataLayer dataLayer = new DataLayer(dataProvider);
GlazedListsEventLayer<Value> glazedListsEventLayer = new GlazedListsEventLayer<Value>(dataLayer, rowObjectsGlazedList);
DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(glazedListsEventLayer);
this.summaryRowLayer = new FixedSummaryRowLayer(dataLayer, bodyLayerStack, configRegistry, false);
this.summaryRowLayer.setHorizontalCompositeDependency(false);
CompositeLayer composite = new CompositeLayer(1, 2);
composite.setChildLayer("SUMMARY", this.summaryRowLayer, 0, 0);
composite.setChildLayer(GridRegion.BODY, bodyLayerStack, 0, 1);
NatTable natTable = new NatTableFixture(composite, false);
natTable.addConfiguration(new DefaultSummaryRowConfiguration() {
@Override
protected void addSummaryProviderConfig(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, new SummationSummaryProvider(dataLayer.getDataProvider(), false), DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL);
}
});
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.setConfigRegistry(configRegistry);
natTable.configure();
}
use of org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack in project nebula.widgets.nattable by eclipse.
the class ReorderColumnEventTest method reorderEventMustPropagateToTheTop.
/**
* Fix for http://nattable.org/jira/browse/NTBL-476
*/
@Test
public void reorderEventMustPropagateToTheTop() throws Exception {
DefaultBodyLayerStack underlyingLayer = new DefaultBodyLayerStack(new DataLayerFixture(20, 10, 100, 20));
NatTableFixture natTableFixture = new NatTableFixture(underlyingLayer);
// Add listener
LayerListenerFixture listenerFixture = new LayerListenerFixture();
natTableFixture.addLayerListener(listenerFixture);
assertEquals(6, natTableFixture.getColumnCount());
assertEquals(1, natTableFixture.getColumnIndexByPosition(1));
// Move to outside the visible range
List<Integer> columnToMove = Arrays.asList(1, 2, 3);
int destinationPosition = 10;
natTableFixture.doCommand(new MultiColumnReorderCommand(natTableFixture, columnToMove, destinationPosition));
// Ensure that the event propagates to the top
assertEquals(1, listenerFixture.getEventsCount());
assertNotNull(listenerFixture.getReceivedEvent(ColumnReorderEvent.class));
assertEquals(4, natTableFixture.getColumnIndexByPosition(1));
}
use of org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack in project nebula.widgets.nattable by eclipse.
the class ReorderRowEventTest method reorderEventMustPropagateToTheTop.
@Test
public void reorderEventMustPropagateToTheTop() throws Exception {
DefaultBodyLayerStack underlyingLayer = new DefaultBodyLayerStack(new RowReorderLayer(new DataLayerFixture(10, 10, 100, 20)));
NatTableFixture natTableFixture = new NatTableFixture(underlyingLayer);
// Add listener
LayerListenerFixture listenerFixture = new LayerListenerFixture();
natTableFixture.addLayerListener(listenerFixture);
Assert.assertEquals(10, natTableFixture.getRowCount());
Assert.assertEquals(1, natTableFixture.getRowIndexByPosition(1));
// Move to outside the visible range
List<Integer> rowsToMove = Arrays.asList(1, 2, 3);
int destinationPosition = 10;
natTableFixture.doCommand(new MultiRowReorderCommand(natTableFixture, rowsToMove, destinationPosition));
// Ensure that the event propagates to the top
Assert.assertEquals(1, listenerFixture.getEventsCount());
Assert.assertNotNull(listenerFixture.getReceivedEvent(RowReorderEvent.class));
Assert.assertEquals(4, natTableFixture.getRowIndexByPosition(1));
}
use of org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack in project nebula.widgets.nattable by eclipse.
the class AutoResizeColumnsTest method shouldAutoResizeCorrectlyIfMultipleColumnsAreSelected.
/**
* Scenario: Multiple columns are selected but a non selected column is auto
* resized.
*/
@Test
public void shouldAutoResizeCorrectlyIfMultipleColumnsAreSelected() throws Exception {
GridLayer gridLayer = new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
setClientAreaProvider(gridLayer);
// Resize grid column 1, 2
gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 1, 10));
gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 2, 10));
assertEquals(10, gridLayer.getColumnWidthByPosition(1));
assertEquals(10, gridLayer.getColumnWidthByPosition(2));
// Fully select columns 1, 2
SelectionLayer selectionLayer = ((DefaultBodyLayerStack) gridLayer.getBodyLayer()).getSelectionLayer();
selectionLayer.doCommand(new SelectColumnCommand(selectionLayer, 0, 0, false, false));
selectionLayer.doCommand(new SelectColumnCommand(selectionLayer, 1, 0, true, false));
assertEquals(2, selectionLayer.getFullySelectedColumnPositions().length);
// Resize grid column 5
gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 5, 10));
assertEquals(10, gridLayer.getColumnWidthByPosition(5));
// Auto resize column 5
InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(gridLayer, 5, this.configRegistry, this.gcFactory);
gridLayer.doCommand(command);
// Columns 1 and 2 should not be resized
assertEquals(10, gridLayer.getColumnWidthByPosition(1));
assertEquals(10, gridLayer.getColumnWidthByPosition(2));
assertTrue(gridLayer.getColumnWidthByPosition(5) > 10);
}
Aggregations