Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Freeze question
Freeze question [message #1050085] Fri, 26 April 2013 17:23 Go to next message
Nandita Uppalapati is currently offline Nandita UppalapatiFriend
Messages: 16
Registered: March 2013
Junior Member
I am trying to get the first 2 columns of the table to freeze. I am trying this out on an example and trying to get it to work. But it doesn't freeze. This is the modified FreezeGridExample which I am trying to run


import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.examples.AbstractNatExample;
import org.eclipse.nebula.widgets.nattable.examples.runner.StandaloneNatExampleRunner;
import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer;
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
import org.eclipse.nebula.widgets.nattable.freeze.command.FreezeSelectionCommand;
import org.eclipse.nebula.widgets.nattable.freeze.config.DefaultFreezeGridBindings;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.ui.menu.BodyMenuConfiguration;
import org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/**
 * This fixture creates a simple, minimal 3x3 table with resizable columns whose
 * cells are of the form 'Row X, Col Y'.
 */
public class FreezableGridExample extends AbstractNatExample {
	
	
	public static void main(String[] args) throws Exception {
		StandaloneNatExampleRunner.run(new FreezableGridExample());
	}
	@Override
	public String getDescription() {
		return
				"This example demonstrates the column and row freezing functionality of NatTable.\n" +
				"\n" +
				"* FREEZE COLUMNS AND ROWS by selecting a cell and using ctrl-shift-f. The columns to the left and the rows to the right " +
				"of the selected cell will be frozen such that they will always remain on screen even when the viewport is scrolled.\n" +
				"* UNFREEZE COLUMNS AND ROWS with ctrl-shift-u.";
	}
	
	@Override
	public Control createExampleControl(Composite parent) {
		// Body
		final DummyBodyDataProvider bodyDataProvider = new DummyBodyDataProvider(20, 1000);
		final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
		final DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(bodyDataLayer);
		final SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
		final FreezeLayer freezeLayer = new FreezeLayer(selectionLayer);
	    final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(freezeLayer, bodyLayer.getViewportLayer(), selectionLayer);
	    
	    // Column header
		final IDataProvider columnHeaderDataProvider = new DummyColumnHeaderDataProvider(bodyDataProvider);
		final ILayer columnHeaderLayer = new ColumnHeaderLayer(new DefaultColumnHeaderDataLayer(columnHeaderDataProvider), compositeFreezeLayer, selectionLayer);
		
		// Row header
		final IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
		final ILayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(rowHeaderDataProvider), compositeFreezeLayer, selectionLayer);
	    
		// Corner
		final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
		final CornerLayer cornerLayer = new CornerLayer(new DataLayer(cornerDataProvider), rowHeaderLayer, columnHeaderLayer);
		
	    // Grid
	    final GridLayer gridLayer = new GridLayer(compositeFreezeLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
	    
		NatTable natTable = new NatTable(parent, gridLayer, false);

		// Configuration
		natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
	    natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
	    natTable.addConfiguration(new DefaultFreezeGridBindings());

		natTable.configure();
		selectionLayer.setSelectedCell(2, 0);
		selectionLayer.doCommand(new FreezeSelectionCommand());
		selectionLayer.clear();
		
		
		return natTable;
	}
	
	

	
	
}


What am I doing wrong? I am using the NatTable core 0.9.0 and NatTableExamples 0.9.0 jars in my buildpath.
Re: Freeze question [message #1050533 is a reply to message #1050085] Sat, 27 April 2013 10:14 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
You are executing the freeze command on the SelectionLayer. As the FreezeLayer is on top of it, it doesn't know that the command is executed. But the FreezeLayer is the one that knows what to do when a freeze command is executed. You should call doCommand() on the NatTable instance.

I know I wrote about the workaround with the selection, but there should be also a FreezeColumnCommand you could use for programmatically freezing.
Re: Freeze question [message #1050662 is a reply to message #1050085] Sat, 27 April 2013 14:49 Go to previous message
Nandita Uppalapati is currently offline Nandita UppalapatiFriend
Messages: 16
Registered: March 2013
Junior Member
Thanks Dirk Fauth for the detailed explanation. It is working.
Previous Topic:Eclipse plugin
Next Topic:NPEs on empty table (BodyCellEditorMouseEventMatcher)
Goto Forum:
  


Current Time: Thu Mar 28 23:20:05 GMT 2024

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

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

Back to the top