Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » "Interrupted Selection" creates Multiselection effect
"Interrupted Selection" creates Multiselection effect [message #1722782] Tue, 09 February 2016 06:46 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 450
Registered: July 2009
Senior Member
Hello,

i'm using NatTable to modify objects from a database.
my framework saves the object whenever a row is changed.
i do pop up a dialog which shows the user the data, which got changed, and asks if changes shall be discarded or saved.
the problem is, that after the popup got closed and i move up and down with my mouse NatTable tries to create a Selection (multiselection, like when you hold down your shift key)
this seems like an interrupted selection - problem.

exact event order:
MouseDown - for changing row.
Dialog Shell opens. user decides and closes
Dialog Shell closes.
the table receives the MouseUp whenever the user hovers over it.

this last step should be skipped in this case, as it makes no sense here at all.

any ideas how to work around this problem?
Re: "Interrupted Selection" creates Multiselection effect [message #1722787 is a reply to message #1722782] Tue, 09 February 2016 07:41 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
Not sure. Sounds either like the drag issue, which means you accidentially create a mouse drag because on click you are moving the mouse, or there is an issue with your binding configuration. How did you configure that behaviour?

And which version of NatTable do you use?
Re: "Interrupted Selection" creates Multiselection effect [message #1722792 is a reply to message #1722787] Tue, 09 February 2016 08:13 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 450
Registered: July 2009
Senior Member
i'm using NatTable 1.3

i did not bind that behaviour in NatTable. When NatTable changes the selection (single element - but multiselection must be still possible) the current-element is sent to my controller. the contoller then processes the change (saving the old current and binding the new current to my formular etc...)
Re: "Interrupted Selection" creates Multiselection effect [message #1722794 is a reply to message #1722792] Tue, 09 February 2016 08:36 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
But how do you implement that the selection is sent to your controller? If the cause for the described behavior is there, this code is interrupting the ui interaction.

Hard to tell why your implementation behaves that way. IMO it is stuck in a drag mode. You could try to look at MouseModeEventHandler or DragModeEventHandler to see where something goes wrong.
Re: "Interrupted Selection" creates Multiselection effect [message #1722807 is a reply to message #1722794] Tue, 09 February 2016 10:01 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 450
Registered: July 2009
Senior Member
this is the code that updates the controller
natTable.addLayerListener(new ILayerListener() {
	public void handleLayerEvent(ILayerEvent event) {
		if (event instanceof CellSelectionEvent) {
			CellSelectionEvent cellEvent = (CellSelectionEvent) event;
			int index = natTable.getColumnIndexByPosition(cellEvent.getColumnPosition());
			if (index < 0)
				return;
			String label = dataSource.getLabels()[index];
			List<Listener> cellSelectionListeners = viewer.getCellSelectionListeners();
			if (cellSelectionListeners != null && !cellSelectionListeners.isEmpty()) {
				for (int i = 0; i < cellSelectionListeners.size(); i++) {
					Event e = new Event();
					e.time = (int) System.nanoTime();
					e.x = cellEvent.getRowPosition();
					e.y = cellEvent.getColumnPosition();
					e.data = natTable.getDataValueByPosition(cellEvent.getColumnPosition(),
						cellEvent.getRowPosition());
					e.index = index;
					e.text = label;
					cellSelectionListeners.get(i).handleEvent(e);
				}
			}
		}
	}
});


second is for context menu (but i doubt this affects it)

package lumo.swt.widget.table;

import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.command.LayerCommandUtil;
import org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate;
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.selection.action.AbstractMouseSelectionAction;
import org.eclipse.nebula.widgets.nattable.viewport.command.ViewportSelectRowCommand;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Menu;

/**
 * First selects a row and then opens the context menu. Needed to support
 * RowSelectionProvider and configured context menus.
 * 
 * @author fipro
 * 
 */
public class SelectPopupMenuAction extends AbstractMouseSelectionAction {
	private Menu menu;
	private SelectionLayer selectionLayer;

	/**
	 * 
	 * @param menu
	 * @param selectionLayer needed to expand Selection to complete Row
	 */
	public SelectPopupMenuAction(Menu menu, SelectionLayer selectionLayer) {
		 this.menu = menu;
		this.selectionLayer = selectionLayer;
	}

	@Override
	public void run(NatTable natTable, MouseEvent event) {
		super.run(natTable, event);

		if (!rowsSelected(natTable, selectionLayer)) {
			// select the row
			natTable.doCommand(new ViewportSelectRowCommand(natTable,
					getGridRowPosition(), isWithShiftMask(),
					isWithControlMask()));
		}

		// make the popup menu visible
		menu = natTable.getMenu();
		if ( menu != null) {
			try {
				menu.setData(event.data);
				menu.setVisible(true);
			} catch (NullPointerException npe) {
				npe.printStackTrace();
			}
		}

	}

	/**
	 * Checks if at least one row is selected and if the row on which a click
	 * was performed is one of them.
	 * 
	 * @param natTable
	 *            The current {@link NatTable} which is base for the grid row
	 *            position
	 * @param selectionLayer
	 *            The {@link FunctionalGridLayer} which is needed to access the
	 *            body layer stack and the {@link SelectionLayer}.
	 * @return <code>true</code> if at least one row is selected which was
	 *         clicked on, <code>false</code> if nothing is selected
	 */
	protected boolean rowsSelected(NatTable natTable,
			SelectionLayer selectionLayer) {
		// check current selection
		RowPositionCoordinate coord = LayerCommandUtil
				.convertRowPositionToTargetContext(new RowPositionCoordinate(
						natTable, getGridRowPosition()), ((GridLayer) natTable
						.getLayer()).getBodyLayer());

		return (selectionLayer != null
				&& selectionLayer.getSelectedRowCount() > 0 && selectionLayer
					.isRowPositionFullySelected(coord.rowPosition));
	}
}
Re: "Interrupted Selection" creates Multiselection effect [message #1722818 is a reply to message #1722807] Tue, 09 February 2016 11:44 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
Looks to me like some sort of race condition in your code. In your SelectPopupMenuAction you trigger the selection and then immediately open the menu after command execution. But on the other side you have a listener that is triggered on CellSelectionEvent.

Honestly I am not 100% sure if there is a race condition, but it feels like the listener doesn't need to be executed before opening the menu. Although I can't remember right know if we have asynchronous processing at this point. Probably not, but it looks strange.

It could also be that while the selection is still processed internally, you open the dialog, and therefore loose the focus, which keeps the NatTable in the middle of a state. There should be code to prevent this, e.g. AbstractModeEventHandler#focusLost(), that doesn't seem to be triggered.

Are you registering your SelectPopupMenuAction on mouseDown or on click?
Re: "Interrupted Selection" creates Multiselection effect [message #1722819 is a reply to message #1722818] Tue, 09 February 2016 12:04 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 450
Registered: July 2009
Senior Member
currently its registered to MouseDown / RMB
but why should this affect the table? (normal selection is LMB, and the popupmenu is RMB.

just for completeness i tried registering the binding to Click and remove the binding completely.
as expected there was no change in behaviour.

Quote:
It could also be that while the selection is still processed internally, you open the dialog, and therefore loose the focus, which keeps the NatTable in the middle of a state. There should be code to prevent this, e.g. AbstractModeEventHandler#focusLost(), that doesn't seem to be triggered.

how can i test that?
Re: "Interrupted Selection" creates Multiselection effect [message #1722824 is a reply to message #1722819] Tue, 09 February 2016 12:28 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
Quote:
but why should this affect the table?


mouseDown is triggered when the mouse button is pressed, click is processed when a mouseDown is followed by a mouseUp. If something happens in between, things might get messy. But as you register for mouseDown this shouldn't be the issue.

The only way to test I know is to debug in MouseModeEventHandler while processing.

You could also try to give the 1.4 SNAPSHOT build a try. Although I'm not sure if we worked on something related there.

You could also try in first place to place a little sleep after the command. Just to be sure that there is no race condition.
Re: "Interrupted Selection" creates Multiselection effect [message #1723032 is a reply to message #1722824] Thu, 11 February 2016 07:47 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 450
Registered: July 2009
Senior Member
i tried NatTable 1.4.0 - 2016-02-08_17-01-13 Build 484
same issue.

adding sleep only resulted in slowdown (seems all is synchron)

only leaves the debugging in MouseModeEventHandler...
but i have no clue what to look for in the Handler.

[Updated on: Thu, 11 February 2016 08:04]

Report message to a moderator

Re: "Interrupted Selection" creates Multiselection effect [message #1723046 is a reply to message #1723032] Thu, 11 February 2016 08:58 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
I have found the issue. It is hidden in ConfigurableModeEventHandler#mouseDown(). First the registered mouseDown binding is executed (e.g. SelectionAction) and after that, if a click binding is registered, the MouseModeEventHandler gets activated to check for a mouseUp. So the CellSelectionEvent is triggered on mouseDown. You open the dialog and skip the further user interaction processing since we are in a synchronized process. After closing the dialog the processing in NatTable is further executed and the mode the MouseModeEventHandler is activated because another click action was registered.

I don't have a solution in NatTable for this. But you could try to open the dialog asynchronously to avoid stopping the NatTable processing.

Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialog.openInformation(null, "Test", "Test");
                        }
                    });


Now that I see the solution, I think I explained that quite a while ago in the forum or to a customer and completely forgot about it. Smile
Re: "Interrupted Selection" creates Multiselection effect [message #1723383 is a reply to message #1723046] Mon, 15 February 2016 10:21 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 450
Registered: July 2009
Senior Member
i do not know which click it registers, as this happens just on mouse move (no click happens, beside closing the dialog)
so the next position, where the mouse hovers above the table gets used as selection. (even though loads of time passed between the click (on the dialog) and the hover over the table...)
and in rare cases it even tries to change the selection (increase the selection by cells)

what about setting a timeout (between click and selection)
as it does not make sense to process click-selections which are off.

beside that:
is it possible to DISABLE/REMOVE the default handling for LMB-down to select multiple cells?
usually users select multiple rows by selecting a single row, then pressing ctrl/or shift to add more selections

in my Configuration, the first click selects a row, the second click selects the cell.
this makes sense, as the first click selects the row for the user, second click focuses my formular to the selected column (scrolls into view) - i have no editing support in the table (on purpose)

ad Asynchron handling:
I now tried to work this out with an asynchron dialog, as you mentioned.
but this does not work due the design of the save method (and the underlying db-persistence).

the persistence creates a new item and this item needs to be put back into the controller, therefore my save method returns the item and gets further processed.

when using asynchron processing i cannot return the item, which results as unsaved/untracked changes.

Re: "Interrupted Selection" creates Multiselection effect [message #1723465 is a reply to message #1723383] Mon, 15 February 2016 19:46 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
Quote:
what about setting a timeout (between click and selection)


As I tried to explain above, that wouldn't change anything. There seems to be a registered click action, probably some default. And the UI event processing in NatTable is executed further when the dialog is closed. So you can not do anything despite opening the dialog in another thread.

Quote:
is it possible to DISABLE/REMOVE the default handling for LMB-down to select multiple cells?


As with everything in NatTable, yes. You just need to register your own configuration and avoid the default selection configuration. Typically you extend the default configuration and override the behavior you don't need.

For me it sounds like the way you are trying to solve your requirement is not correct. Personally I think opening a dialog on a simple selection is mostly wrong regarding UX because you are losing the focus. But that is my personal opinion.

I would suggest to perform the action in charge in a custom command handler instead of listening for the selection event. Or create a custom command and command handler that you register on first single click.
Re: "Interrupted Selection" creates Multiselection effect [message #1765287 is a reply to message #1723383] Thu, 08 June 2017 07:40 Go to previous messageGo to next message
Björn Seebeck is currently offline Björn SeebeckFriend
Messages: 9
Registered: April 2012
Junior Member
We have the same issue.
Did you solve this problem? If yes, how did you solve this? Have you registered your own configuration as Dirk suggested in his answer? If yes, could you post your configuration solution?
Re: "Interrupted Selection" creates Multiselection effect [message #1765322 is a reply to message #1765287] Thu, 08 June 2017 12:29 Go to previous message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 450
Registered: July 2009
Senior Member
i was not able to solve this problem.
if you find a way, please post it here, as i would love to have a solution for this too
Previous Topic: Nattable Export Excel Report contains filter string also
Next Topic:Create nattable with two column ,the second column has multiple dynamic rows inside.
Goto Forum:
  


Current Time: Sat Sep 22 07:26:44 GMT 2018

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

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

Back to the top