Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Strange behavior with RowResizeCommand
Strange behavior with RowResizeCommand [message #1032241] Tue, 02 April 2013 19:08 Go to next message
Joachim Fuchs is currently offline Joachim FuchsFriend
Messages: 34
Registered: February 2013
Member
Hi,

I just tried out the row resize feature and it went pretty well. The code draws a nattable and two buttons. The lower button is responsible for resizing of the selected row. This is done in a thread because I wanted to check out some 'animation'. Using 2 as a step width (see the variable) works fine. The row grows or shrinks and cell selection still works. Using 3 for the step width breaks it: the button is now useless nad it is not possible to select a cell, the selected row grows instead.

Where is the problem? Is it my code or my approach wit hthe animation? Is it a bug somewhere? I'm running Ubuntu here and the latest nattable build from the p2 repo.

Thanks for your help.

J

...
public class NatTable01 {

	private NatTable natTable;
	private DataLayer bodyDataLayer;
	private Button btnRowHeight;
	private ILayerCell selectedCell;

	private int step = 1;

// FINDME setting rowHeightNormal to 0 results in grid only painted table experience
	private int rowHeightNormal = 20;
	private int rowHeightBig = 77;

	private int timerdelay = 5;

	public static void main(String[] args) {

		Display d = Display.getDefault();
		Shell s = new Shell(d, SWT.CLOSE | SWT.RESIZE | SWT.DOUBLE_BUFFERED);

		NatTable01 nt = new NatTable01();
		nt.createControl(s);

		s.open();
		while (!s.isDisposed()) {
			if (!d.readAndDispatch()) {
				d.sleep();
			}
		}
		d.dispose();
	}

	public NatTable01() {
	}

	public void createControl(Composite parent) {

		parent.setLayout(new GridLayout(1, false));

		final DummyBodyDataProvider bodyDataProvider = new DummyBodyDataProvider(5, 5);
		bodyDataLayer = new DataLayer(bodyDataProvider);
		final DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(bodyDataLayer);
		final SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
		selectionLayer.addLayerListener(new ILayerListener() {

			@Override
			public void handleLayerEvent(ILayerEvent event) {
				System.out.println(event);
				if (event instanceof CellSelectionEvent) {
					CellSelectionEvent cse = (CellSelectionEvent) event;
					ILayerCell selectedCell = natTable.getCellByPosition(cse.getColumnPosition(), cse.getRowPosition());
					if (selectedCell != null) {
						setSelectedCell(selectedCell);
					}
				} else if (event instanceof ColumnSelectionEvent) {
					setSelectedCell(null);
				} else if (event instanceof RowSelectionEvent) {
					setSelectedCell(null);
				}
			}
		});
		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 = new NatTable(parent, gridLayer, false);

		ColumnLabelAccumulator columnLabelAccumulator = new ColumnLabelAccumulator() {
			@Override
			public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
				super.accumulateConfigLabels(configLabels, columnPosition, rowPosition);
				configLabels.addLabelOnTop("LABEL");
			}
		};
		bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
		// Configuration
		natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
			@Override
			public void configureRegistry(IConfigRegistry configRegistry) {
				super.configureRegistry(configRegistry);
				configRegistry.registerConfigAttribute(CellStyleAttributes.VERTICAL_ALIGNMENT,
						VerticalAlignmentEnum.TOP, DisplayMode.NORMAL, "LABEL");
			}
		});
		natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
		natTable.addConfiguration(new DefaultFreezeGridBindings());
		// ADD BODY CONTEXT MENU CONFIG
		natTable.addConfiguration(new BodyMenuConfiguration(natTable, selectionLayer));

		natTable.configure();

		natTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		Button btnResize = new Button(parent, SWT.PUSH);
		btnResize.setText("Resize");
		btnResize.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				for (int i = 0; i < bodyDataLayer.getRowCount(); i++) {
					bodyDataLayer.doCommand(new RowResizeCommand(bodyDataLayer, i, (int) (bodyDataLayer
							.getRowHeightByPosition(i) * 1.1)));
				}
			}
		});
		btnRowHeight = new Button(parent, SWT.PUSH);
		btnRowHeight.setText("Change Row Height");
		btnRowHeight.setEnabled(false);
		btnRowHeight.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int currentRowHeight = bodyDataLayer.getRowHeightByPosition(selectedCell.getRowPosition());
				BiggerSmallerRunner bsr = new BiggerSmallerRunner();
				bsr.cell = selectedCell;
				if (currentRowHeight == rowHeightBig) {
					bsr.targetSize = rowHeightNormal;
				} else {
					bsr.targetSize = rowHeightBig;
				}
				timer.scheduleAtFixedRate(bsr, 0, timerdelay);
				selectionLayer.setSelectedCell(selectedCell.getColumnPosition(), selectedCell.getRowPosition());
			}
		});
	}

	Timer timer = new Timer();

	class BiggerSmallerRunner extends TimerTask {

		ILayerCell cell;
		int targetSize;

		@Override
		public void run() {
			natTable.getDisplay().asyncExec(new Runnable() {
				@Override
				public void run() {
					int currentRowHeight = bodyDataLayer.getRowHeightByPosition(cell.getRowPosition());
					if (targetSize + step < currentRowHeight) {
						bodyDataLayer.doCommand(new RowResizeCommand(bodyDataLayer, cell.getRowPosition(),
								currentRowHeight - step));
					} else if (targetSize - step > currentRowHeight) {
						bodyDataLayer.doCommand(new RowResizeCommand(bodyDataLayer, cell.getRowPosition(),
								currentRowHeight + step));
					} else if (currentRowHeight + step >= targetSize) {
						bodyDataLayer.doCommand(new RowResizeCommand(bodyDataLayer, cell.getRowPosition(), targetSize));
						cancel();
					}
				}
			});
		}
	}

	protected void setSelectedCell(ILayerCell selectedCell) {
		this.selectedCell = selectedCell;
		btnRowHeight.setEnabled(this.selectedCell != null);
	}
}

[Updated on: Thu, 04 April 2013 08:39]

Report message to a moderator

Re: Strange behavior with RowResizeCommand [message #1033380 is a reply to message #1032241] Thu, 04 April 2013 07:20 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I'm not sure, but it seems to be more related to your code. Maybe some calculation issue with your member variables in the background processing.
Re: Strange behavior with RowResizeCommand [message #1033415 is a reply to message #1033380] Thu, 04 April 2013 08:02 Go to previous messageGo to next message
Joachim Fuchs is currently offline Joachim FuchsFriend
Messages: 34
Registered: February 2013
Member
You are right, the problem sat there.

BTW, if I set a single row's height to 0 none of the table cells are being painted, only the grid lines are left. Is that intended behavior?

Thank you.

J
Re: Strange behavior with RowResizeCommand [message #1033437 is a reply to message #1033415] Thu, 04 April 2013 08:16 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Quote:
if I set a single row's height to 0 none of the table cells are being painted


The table cells of that row or all table cells in the whole table? For the first one I would say that's intended because the height of 0 should show nothing. The last one might be a bug. Do you have a screenshot or example? But I would rather hide or filter a row instead of setting the height to 0. Wink
Re: Strange behavior with RowResizeCommand [message #1033459 is a reply to message #1033437] Thu, 04 April 2013 08:43 Go to previous messageGo to next message
Joachim Fuchs is currently offline Joachim FuchsFriend
Messages: 34
Registered: February 2013
Member
Yes, the whole table including all headers is affected. I modified the code in the starting post. Set the FINDME variable to 0 to reproduce.

J


Dirk Fauth wrote on Thu, 04 April 2013 10:16

The table cells of that row or all table cells in the whole table? For the first one I would say that's intended because the height of 0 should show nothing. The last one might be a bug. Do you have a screenshot or example? But I would rather hide or filter a row instead of setting the height to 0. Wink

Re: Strange behavior with RowResizeCommand [message #1033464 is a reply to message #1033459] Thu, 04 April 2013 08:49 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Ok, seems to be a bug in rendering. Possibly because of some issues with calculations regarding the 0 in somewhere. Please file a bug.
Re: Strange behavior with RowResizeCommand [message #1033490 is a reply to message #1033464] Thu, 04 April 2013 09:28 Go to previous message
Joachim Fuchs is currently offline Joachim FuchsFriend
Messages: 34
Registered: February 2013
Member
https://bugs.eclipse.org/bugs/show_bug.cgi?id=404880

J
Previous Topic:Row selection when right clicking row header
Next Topic:Selected columns indexes in collapsed groups
Goto Forum:
  


Current Time: Thu Mar 28 20:27:14 GMT 2024

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

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

Back to the top