Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Keyboard accessibility on TableViewerColumn with a combo box
Keyboard accessibility on TableViewerColumn with a combo box [message #1276658] Mon, 24 March 2014 21:58 Go to next message
Free Bird is currently offline Free BirdFriend
Messages: 2
Registered: March 2014
Junior Member
I have a relatively simple question to ask. I am working on SWT Table widget with 2 columns. I simply want to be able to select the 2nd column using keyboard.

I have already tried using SWT.SINGLE and SWT.MULTI while creating the table. but I am not able to go to 2nd column using keyboard (preferrably tab key). FYI, 2nd column is a drop down and I want user to be able to select the value using keyboard thats y i prefer to go between cells using tab so that I can use arrow keys on this drop down box once selected(I am using a comboBoxCellEditor on this column). but my current code lets me only navigate through 1st column.

Also, only the second column is editable and not the 1st column
Here is the code:

{
//created table with SWT.FULL_SELECTION
Table table = new Table(contentArea, SWT.BORDER | SWT.FULL_SELECTION);

//create table viewer
viewer = new TableViewer(table);

viewer.setContentProvider(new IStructuredContentProvider());

//1st column
TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
        column1 .getColumn().setText("Coulm 1");
        viewer.getColumn().setWidth(200);

//2nd Column
TableViewerColumn column2 = new TableViewerColumn(viewer, SWT.NONE);
column2.getColumn().setText("Column 2");
column2.getColumn().setWidth(200);

//some other code
}


Any help is much appreciated.

Thanks
Re: Keyboard accessibility on TableViewerColumn with a combo box [message #1277333 is a reply to message #1276658] Tue, 25 March 2014 21:34 Go to previous message
Free Bird is currently offline Free BirdFriend
Messages: 2
Registered: March 2014
Junior Member
I tried using the cellNAvigationStrategy but couldnt get the desired behaviour. I want to be bale to navigate to 2nd column using tab or arrow and activate the combobox and its cell editor.

Please guide what am i doing wrong in the code below ?

Thanks

{
    //created table with SWT.FULL_SELECTION
    Table table = new Table(contentArea, SWT.BORDER | SWT.FULL_SELECTION);

    //create table viewer
    viewer = new TableViewer(table);

    viewer.setContentProvider(new IStructuredContentProvider());

    //1st column
    TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
            column1 .getColumn().setText("Coulm 1");
            viewer.getColumn().setWidth(200);

    //2nd Column
    TableViewerColumn column2 = new TableViewerColumn(viewer, SWT.NONE);
    column2.getColumn().setText("Column 2");
    column2.getColumn().setWidth(200);

    CellNavigationStrategy strategy = new CellNavigationStrategy() {

        @Override
        public ViewerCell findSelectedCell(ColumnViewer viewer,
                ViewerCell currentSelectedCell, Event event) {
            ViewerCell cell = null;
            switch (event.keyCode) {
            case SWT.TAB:
                if (event.stateMask == 0) {
                    cell = currentSelectedCell.getNeighbor(ViewerCell.RIGHT, true);
                } else {
                    cell = currentSelectedCell.getNeighbor(ViewerCell.LEFT, true);
                }
                break;
            }

            if (cell != null) {
                TableColumn t = runtimesTableViewer.getTable().getColumn(
                        cell.getColumnIndex());
                runtimesTableViewer.getTable().showColumn(t);
            }
            return cell;

        }

        @Override
        public boolean isNavigationEvent(ColumnViewer viewer, Event event) {
            switch (event.keyCode) {
            case SWT.TAB:
                return true;
            default:
                return super.isNavigationEvent(viewer, event);
            }
        }

    };

    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer,new FocusCellOwnerDrawHighlighter(runtimesTableViewer), strategy);

    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(runtimesTableViewer) {

        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL 
                || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION                                   
                || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.TAB) 
                || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
           }
    };

    TableViewerEditor.create(viewer, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
            | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
            | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);

    runtimesTableViewer.getColumnViewerEditor().addEditorActivationListener(new ColumnViewerEditorActivationListener(){

        @Override
        public void afterEditorActivated(
                ColumnViewerEditorActivationEvent event) {

        }

        @Override
        public void afterEditorDeactivated(
                ColumnViewerEditorDeactivationEvent event) {

        }

        @Override
        public void beforeEditorActivated(
                ColumnViewerEditorActivationEvent event) {
            ViewerCell cell = (ViewerCell) event.getSource();
            runtimesTableViewer.getTable().showColumn(viewer.getTable().getColumn(cell.getColumnIndex()));
        }

        @Override
        public void beforeEditorDeactivated(
                ColumnViewerEditorDeactivationEvent event) {

        }

    });

Previous Topic:Combining different cell editors in one editing support
Next Topic:Ctrl + A in SourceViewer returns empty TextSelection
Goto Forum:
  


Current Time: Wed Nov 14 21:23:49 GMT 2018

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

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

Back to the top