Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » How to combine FreezeLayer and ColumnGroupHeaderLayer
How to combine FreezeLayer and ColumnGroupHeaderLayer [message #1081586] Wed, 07 August 2013 12:22 Go to next message
Joachim Fuchs is currently offline Joachim FuchsFriend
Messages: 34
Registered: February 2013
Member
Hi,

I need to introduce freezing to my table. What is the recommended order of layers to have column grouping and freezing?

Regards
J
Re: How to combine FreezeLayer and ColumnGroupHeaderLayer [message #1081642 is a reply to message #1081586] Wed, 07 August 2013 13:50 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1434
Registered: July 2012
Senior Member
Freezing is related to the body layer stack, column grouping to the column header layer stack..
Re: How to combine FreezeLayer and ColumnGroupHeaderLayer [message #1082227 is a reply to message #1081642] Thu, 08 August 2013 09:14 Go to previous messageGo to next message
Joachim Fuchs is currently offline Joachim FuchsFriend
Messages: 34
Registered: February 2013
Member
Thank you for the hint. So far I managed to merge the freeze and the column group example that it looks decent and almost behaves as expected. Unfortunately pushing a freeze command to the table the columns/rows to freeze are simply being hidden. What is wrong here?

Here is the interesting part of my code:
private void createBoth(Composite parent) {
		ColumnGroupModel columnGroupModel = new ColumnGroupModel();
		ColumnHeaderLayer columnHeaderLayer;

		// Body

		String[] propertyNames = RowDataListFixture.getPropertyNames();
		Map propertyToLabelMap = RowDataListFixture.getPropertyToLabelMap();
		DefaultBodyDataProvider bodyDataProvider = new DefaultBodyDataProvider(RowDataListFixture.getList(200),
				propertyNames);
		final FreezeLayerStack freezeLayerStack = new FreezeLayerStack(new DataLayer(bodyDataProvider),
				columnGroupModel);

		// Column header

		DefaultColumnHeaderDataProvider defaultColumnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
				propertyNames, propertyToLabelMap);
		DefaultColumnHeaderDataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(
				defaultColumnHeaderDataProvider);
		columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, freezeLayerStack,
				freezeLayerStack.getSelectionLayer());
		ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(columnHeaderLayer,
				freezeLayerStack.getSelectionLayer(), columnGroupModel);

		columnGroupHeaderLayer.addColumnsIndexesToGroup("Group 1", 1, 2);
		columnGroupHeaderLayer.addColumnsIndexesToGroup("UnBreakable group 2", 4, 5, 6, 7);
		columnGroupHeaderLayer.addColumnsIndexesToGroup("UnBreakable group 3", 8, 9, 10);
		columnGroupHeaderLayer.addColumnsIndexesToGroup("Group 4", 11, 12, 13);
		columnGroupHeaderLayer.addColumnsIndexesToGroup("Group 5", 14, 15, 16, 17);
		columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Group 5", 15, 17);
		columnGroupHeaderLayer.setGroupUnbreakable(4);
		columnGroupHeaderLayer.setGroupUnbreakable(8);
		columnGroupHeaderLayer.setGroupAsCollapsed(11);

		// Row header

		final DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
		DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
		ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, freezeLayerStack,
				freezeLayerStack.getSelectionLayer());

		// Corner

		final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(
				defaultColumnHeaderDataProvider, rowHeaderDataProvider);
		DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
		ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnGroupHeaderLayer);

		// Grid

		CompositeLayer gridLayer = new CompositeLayer(1, 2);
		gridLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnGroupHeaderLayer, 0, 0);
		gridLayer.setChildLayer(GridRegion.BODY, freezeLayerStack, 0, 1);
		gridLayer.setConfigLabelAccumulatorForRegion(GridRegion.BODY, new AlternatingRowConfigLabelAccumulator());

		//		GridLayer gridLayer = new GridLayer(freezeLayerStack, columnGroupHeaderLayer, rowHeaderLayer, cornerLayer);

		NatTable bothTable = new NatTable(parent, gridLayer, false);
		bothTable.addConfiguration(new DefaultRowStyleConfiguration());

		// Register create column group command handler

		// Register column chooser
		DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(
				freezeLayerStack.getSelectionLayer(), freezeLayerStack.getColumnHideShowLayer(), columnHeaderLayer,
				columnHeaderDataLayer, columnGroupHeaderLayer, columnGroupModel);
		freezeLayerStack.registerCommandHandler(columnChooserCommandHandler);

		bothTable.addConfiguration(new DefaultNatTableStyleConfiguration());
		bothTable.getUiBindingRegistry().registerKeyBinding(new KeyEventMatcher(SWT.CTRL | SWT.SHIFT, 'f'),
				new FreezeGridAction(true));
		bothTable.configure();

	}

	class FreezeLayerStack extends AbstractIndexLayerTransform {

		private ColumnReorderLayer columnReorderLayer;
		private ColumnGroupReorderLayer columnGroupReorderLayer;
		private ColumnHideShowLayer columnHideShowLayer;
		private ColumnGroupExpandCollapseLayer columnGroupExpandCollapseLayer;
		private SelectionLayer selectionLayer;
		private FreezeLayer freezeLayer;
		private CompositeFreezeLayer compositeFreezeLayer;
		private ViewportLayer viewportLayer;

		public FreezeLayerStack(IUniqueIndexLayer underlyingLayer, ColumnGroupModel columnGroupModel) {
			columnReorderLayer = new ColumnReorderLayer(underlyingLayer);
			columnGroupReorderLayer = new ColumnGroupReorderLayer(columnReorderLayer, columnGroupModel);
			columnHideShowLayer = new ColumnHideShowLayer(columnGroupReorderLayer);
			columnGroupExpandCollapseLayer = new ColumnGroupExpandCollapseLayer(columnHideShowLayer, columnGroupModel);
			selectionLayer = new SelectionLayer(columnGroupExpandCollapseLayer);
			viewportLayer = new ViewportLayer(selectionLayer);
			freezeLayer = new FreezeLayer(viewportLayer);
			compositeFreezeLayer = new CompositeFreezeLayer(freezeLayer, viewportLayer, selectionLayer);
			setUnderlyingLayer(viewportLayer);

			registerCommandHandler(new CopyDataCommandHandler(selectionLayer));
			registerCommandHandler(new FreezeCommandHandler(freezeLayer, viewportLayer, selectionLayer));
		}

		public ColumnReorderLayer getColumnReorderLayer() {
			return columnReorderLayer;
		}

		public ColumnGroupReorderLayer getColumnGroupReorderLayer() {
			return columnGroupReorderLayer;
		}

		public ColumnHideShowLayer getColumnHideShowLayer() {
			return columnHideShowLayer;
		}

		public ColumnGroupExpandCollapseLayer getColumnGroupExpandCollapseLayer() {
			return columnGroupExpandCollapseLayer;
		}

		public SelectionLayer getSelectionLayer() {
			return selectionLayer;
		}

		public ViewportLayer getViewportLayer() {
			return viewportLayer;
		}

		/**
		 * @return the freezeLayer
		 */
		public FreezeLayer getFreezeLayer() {
			return freezeLayer;
		}

		/**
		 * @return the compositeFreezeLayer
		 */
		public CompositeFreezeLayer getCompositeFreezeLayer() {
			return compositeFreezeLayer;
		}

	}


J
Re: How to combine FreezeLayer and ColumnGroupHeaderLayer [message #1082261 is a reply to message #1082227] Thu, 08 August 2013 10:04 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1434
Registered: July 2012
Senior Member
Instead of doing this

selectionLayer = new SelectionLayer(columnGroupExpandCollapseLayer);
viewportLayer = new ViewportLayer(selectionLayer);
freezeLayer = new FreezeLayer(viewportLayer);
compositeFreezeLayer = new CompositeFreezeLayer(freezeLayer, viewportLayer, selectionLayer);
setUnderlyingLayer(viewportLayer);


you should compose your layer stack like this

selectionLayer = new SelectionLayer(columnGroupExpandCollapseLayer);
viewportLayer = new ViewportLayer(selectionLayer);
freezeLayer = new FreezeLayer(selectionLayer);
compositeFreezeLayer = new CompositeFreezeLayer(freezeLayer, viewportLayer, selectionLayer);
setUnderlyingLayer(compositeFreezeLayer);
Re: How to combine FreezeLayer and ColumnGroupHeaderLayer [message #1082310 is a reply to message #1082261] Thu, 08 August 2013 11:48 Go to previous messageGo to next message
Joachim Fuchs is currently offline Joachim FuchsFriend
Messages: 34
Registered: February 2013
Member
Thanks for your quick response, Dirk!

With this little modification the CTRL-f keystroke leads to a StackOverflowError. It looks like there are some calculations going that need information from underlying layers and somehow there is a loop which I could not identify so far. Looks like it is related to the hidden instead of frozen problem.

J

Exception in thread "main" java.lang.StackOverflowError
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:165)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4688)
	at org.eclipse.nebula.widgets.nattable.NatTable$2.getClientArea(NatTable.java:204)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.getChildClientArea(CompositeLayer.java:618)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.access$3(CompositeLayer.java:615)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer$1.getClientArea(CompositeLayer.java:583)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.getChildClientArea(CompositeLayer.java:618)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.access$3(CompositeLayer.java:615)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer$1.getClientArea(CompositeLayer.java:583)
	at org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer.getClientAreaHeight(ViewportLayer.java:897)
	at org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer.getRowCount(ViewportLayer.java:409)
	at org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer.getRowCount(FreezeLayer.java:135)
	at org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer.getHeight(FreezeLayer.java:169)
	at org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer.getPreferredHeight(FreezeLayer.java:177)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.getPreferredHeight(CompositeLayer.java:381)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractIndexLayerTransform.getPreferredHeight(AbstractIndexLayerTransform.java:258)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.getChildClientArea(CompositeLayer.java:624)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.access$3(CompositeLayer.java:615)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer$1.getClientArea(CompositeLayer.java:583)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.getChildClientArea(CompositeLayer.java:618)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.access$3(CompositeLayer.java:615)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer$1.getClientArea(CompositeLayer.java:583)
	at org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer.getClientAreaHeight(ViewportLayer.java:897)
	at org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer.getRowCount(ViewportLayer.java:409)
	at org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer.getRowCount(FreezeLayer.java:135)
	at org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer.getHeight(FreezeLayer.java:169)
...
Re: How to combine FreezeLayer and ColumnGroupHeaderLayer [message #1082315 is a reply to message #1082310] Thu, 08 August 2013 11:57 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1434
Registered: July 2012
Senior Member
Please have a look at the FreezableGridExample for the composition of the layer stack. As column groups and freezing should relate to each other, it should help you in finding the issue.
Previous Topic:Selection multiple cells - possible bug
Next Topic:ColumnGroupHeaderLayer expand/collapse and Selection, ColumnResize, etc.
Goto Forum:
  


Current Time: Mon Dec 22 22:58:50 GMT 2014

Powered by FUDForum. Page generated in 0.02031 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software