|
|
|
|
Re: "Interrupted Selection" creates Multiselection effect [message #1722807 is a reply to message #1722794] |
Tue, 09 February 2016 10:01 |
Ludwig Moser Messages: 476 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 #1723383 is a reply to message #1723046] |
Mon, 15 February 2016 10:21 |
Ludwig Moser Messages: 476 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.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05191 seconds