TableViewerFocusCellManager and Using Tabulator to Navigate [message #18500] |
Wed, 01 July 2009 10:30  |
Eclipse User |
|
|
|
I want to navigate through a JFace TableViewer using the
TableViewerFocusCellManager.
I tried the Snippet058CellNavigationIn34 Snippet from JFace Sources.
But I'm not able to listen to the keyDownEvent when Tab is pressed.
Know I did something like this... but its just a greate Hack...
--->
public class MyFocusCellManager extends TableViewerFocusCellManager {
public MyFocusCellManager(TableViewer viewer,FocusCellHighlighter
focusDrawingDelegate,CellNavigationStrategy navigationStrategy) {
super(viewer, focusDrawingDelegate, navigationStrategy);
viewer.getControl().addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
// We just want the Tab event to be recognized
if(e.keyCode != SWT.TAB){
return;
}
Event event = new Event();
event.character=e.character;
event.keyCode=e.keyCode;
event.time=e.time;
event.widget=e.widget;
event.stateMask=e.stateMask;
event.display=e.display;
try {
Method m =
DelfinFocusCellManager.this.getClass().getSuperclass().getSu perclass().getDeclaredMethod( "handleKeyDown",
Event.class);
m.setAccessible(true);
m.invoke(DelfinFocusCellManager.this, event);
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (NoSuchMethodException e1) {
e1.printStackTrace();
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (InvocationTargetException e1) {
e1.printStackTrace();
}
}
});
}
}
--->
Is there a better solution out there for getting the Tab Event from a
TableViewer to Navigate ?
THX
Andreas
|
|
|
|
Re: TableViewerFocusCellManager and Using Tabulator to Navigate [message #18538 is a reply to message #18512] |
Wed, 01 July 2009 11:51  |
Eclipse User |
|
|
|
First:
If do rebuild an existing table.
This table supported browsing through it using ArrowKeys, CR , Home/Pos1
and Tab Key.
As soon as you press one of these keys you should jump to a cell and be
able to edit its content (using ContentAssist, Combo, Text or what ever
:-) )
If you reach the end of a table. a new item should be added at the end
of this table.
So if i provide a cell editor for each cell, i will be able to browse
through it using ArrowKeys/CR/Home/Pos1/Tab ?
What do i have to do, do activate the cellEditor as soon as the
TableViewer gets the Focus ?
Second, if you press the Tab button, the onKeyDown Event will not be
fired (Using Eclipse 3.5 an running the snippet), if you press the Tab
Key. So CellNavigationStrategy was of no use :-(
My CellNavigationStrategy --->
CellNavigationStrategy naviStrategy = new CellNavigationStrategy(){
@Override
public ViewerCell findSelectedCell(ColumnViewer viewer,ViewerCell
currentSelectedCell, Event event) {
ViewerCell cell;
switch (event.keyCode) {
case SWT.TAB:
if(event.stateMask == 0){
cell = currentSelectedCell.getNeighbor(ViewerCell.RIGHT, true);
}else{
cell = currentSelectedCell.getNeighbor(ViewerCell.LEFT, true);
}
break;
case SWT.CR:
if(event.stateMask == 0){
cell = currentSelectedCell.getNeighbor(ViewerCell.RIGHT, true);
}else{
cell = currentSelectedCell.getNeighbor(ViewerCell.LEFT, true);
}
break;
default:
cell = super.findSelectedCell(viewer, currentSelectedCell, event);
break;
}
if( cell != null ) {
table.getViewer().getTable().showColumn(table.getViewer().ge tTable().getColumn(cell.getColumnIndex()));
}
return cell;
}
@Override
public boolean isNavigationEvent(ColumnViewer viewer, Event event) {
switch (event.keyCode) {
case SWT.TAB:
return true;
case SWT.CR:
return true;
default:
return super.isNavigationEvent(viewer, event);
}
}
};
<---
Thanks
Andreas
Tom Schindl schrieb:
> Hi,
>
> So you want to move from cell to cell (shift the focus-cell) using the
> tab-key instead of the standard ARROW-Keys or are we talking about
> navigating from CellEditor to CellEditor (which is supported out of the
> box).
>
> Can you explain what you are trying to achieve because using the Tab-Key
> to shift the focus cell is a bit strange but would normally get achieved
> by creating your CellNavigationStrategy.
>
> Tom
>
> Andreas Schmid schrieb:
>> I want to navigate through a JFace TableViewer using the
>> TableViewerFocusCellManager.
>>
>> I tried the Snippet058CellNavigationIn34 Snippet from JFace Sources.
>>
>> But I'm not able to listen to the keyDownEvent when Tab is pressed.
>>
>> Know I did something like this... but its just a greate Hack...
>>
>> --->
>> public class MyFocusCellManager extends TableViewerFocusCellManager {
>>
>> public MyFocusCellManager(TableViewer viewer,FocusCellHighlighter
>> focusDrawingDelegate,CellNavigationStrategy navigationStrategy) {
>> super(viewer, focusDrawingDelegate, navigationStrategy);
>> viewer.getControl().addTraverseListener(new TraverseListener()
>> {
>> public void keyTraversed(TraverseEvent e) {
>> // We just want the Tab event to be recognized
>> if(e.keyCode != SWT.TAB){
>> return;
>> }
>> Event event = new Event();
>> event.character=e.character;
>> event.keyCode=e.keyCode;
>> event.time=e.time;
>> event.widget=e.widget;
>> event.stateMask=e.stateMask;
>> event.display=e.display;
>>
>> try {
>> Method m =
>> DelfinFocusCellManager.this.getClass().getSuperclass().getSu perclass().getDeclaredMethod( "handleKeyDown",
>> Event.class);
>> m.setAccessible(true);
>> m.invoke(DelfinFocusCellManager.this, event);
>> } catch (SecurityException e1) {
>> e1.printStackTrace();
>> } catch (NoSuchMethodException e1) {
>> e1.printStackTrace();
>> } catch (IllegalArgumentException e1) {
>> e1.printStackTrace();
>> } catch (IllegalAccessException e1) {
>> e1.printStackTrace();
>> } catch (InvocationTargetException e1) {
>> e1.printStackTrace();
>> }
>> }
>> });
>> }
>> }
>>
>> --->
>>
>> Is there a better solution out there for getting the Tab Event from a
>> TableViewer to Navigate ?
>>
>> THX
>>
>> Andreas
|
|
|
Powered by
FUDForum. Page generated in 0.03871 seconds