Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » GridTableViewer previous tab traversal?
GridTableViewer previous tab traversal? [message #540670] Wed, 16 June 2010 22:47 Go to next message
Lars Butler is currently offline Lars ButlerFriend
Messages: 6
Registered: July 2009
Junior Member
Hello,

I've been doing a bunch of research on the web and have spent the better part of a day trying to figure this out. Can anyone help?

I have a GridTableViewer in my application. I have a requirement which states that the user shall be able to tab and shift+tab to navigate between cells (like Excel).

Tab works by default, but I cannot get shift+tab to work. I've tried a lot different things, including adding a KeyListener to the GridTableViewer's Grid and sending a call to grid.traverse(SWT.TRAVERSE_*) on keyPressed. I've tried passing in tab traverse and arrow traverse, but neither have any significant effect.

My GridTableViewer in my application exists in a Composite with two buttons. When I shift+tab in my application, the focus moves to the previous component: a button. Is there any way to work around this to get the functionality I'm looking for?

I've stripped everything down to an example View that demonstrates the issue. Tabbing works, but shift+tabbing does not.

Any help is appreciated.

Thanks!
Lars


import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
import org.eclipse.nebula.widgets.grid.GridColumn;

public class View extends ViewPart {
	public static final String ID = "GridTableViewerTest.view";

	private GridTableViewer gridViewer;
	
	public void createPartControl(Composite parent) {
		gridViewer = new GridTableViewer(
		parent, SWT.V_SCROLL | SWT.H_SCROLL);

		gridViewer.setLabelProvider(new ColumnLabelProvider());
		gridViewer.setContentProvider(new TableContentProvider());
		gridViewer.getGrid().setCellSelectionEnabled(true);

		gridViewer.getGrid().setLinesVisible(true);
		gridViewer.getGrid().setHeaderVisible(true);
		
		GridColumn column1 = new GridColumn(gridViewer.getGrid(), SWT.NONE);
		column1.setWidth(100);
		column1.setText("Column 1");
		
		GridColumn column2 = new GridColumn(gridViewer.getGrid(), SWT.NONE);
		column2.setWidth(100);
		column2.setText("Column 2");
		
		GridColumn column3 = new GridColumn(gridViewer.getGrid(), SWT.NONE);
		column3.setWidth(100);
		column3.setText("Column 3");
		
		gridViewer.setInput(this.getViewSite());


	}


	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
		gridViewer.getControl().setFocus();
	}	
}

class ColumnLabelProvider extends LabelProvider implements
ITableLabelProvider {
	@Override
	public String getColumnText(Object element, int columnIndex) {
		return "foo";
	}

	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		return null;
	}	
}

class TableContentProvider implements IStructuredContentProvider {


	private List<TableRow> tableRows;
	
	public TableContentProvider() {
		tableRows = new ArrayList<TableRow>();
		
		for (int row=1; row<=10; row++) {
			TableRow tableRow = new TableRow();
			tableRows.add(tableRow);
		}
	}
	
	@Override
	public Object[] getElements(Object inputElement) {
		// TODO Auto-generated method stub
		return tableRows.toArray();
	}


	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void inputChanged(Viewer viewer,
			Object oldInput, Object newInput) {
		// TODO Auto-generated method stub
		
	}
}

class TableRow {
	public TableRow() {}			
}

Re: GridTableViewer previous tab traversal? [message #545541 is a reply to message #540670] Thu, 08 July 2010 08:29 Go to previous messageGo to next message
Arne Jans is currently offline Arne JansFriend
Messages: 9
Registered: December 2009
Junior Member
Hi,

you have to suppress Tabbing the focus via a TraverseListener in createPartControl:

				gridViewer.getGrid().addTraverseListener(new TraverseListener()  {
					public void keyTraversed(TraverseEvent e)  {
						switch (e.detail)  {
							case SWT.TRAVERSE_TAB_NEXT:
							case SWT.TRAVERSE_TAB_PREVIOUS:
								e.doit = false;
						}
					}
				});


Best regards,

Arne Jans
Re: GridTableViewer previous tab traversal? [message #545566 is a reply to message #545541] Thu, 08 July 2010 09:27 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
You should be able to get Tabs working by configuring your when setting
up the GridViewerEditor like this:

-------8<-------
GridViewerEditor.create(v, actSupport,
ColumnViewerEditor.TABBING_HORIZONTAL |
ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL
-------8<-------


Am 08.07.10 10:29, schrieb Arne Jans:
> Hi,
>
> you have to suppress Tabbing the focus via a TraverseListener in
> createPartControl:
>
>
> gridViewer.getGrid().addTraverseListener(new
> TraverseListener() {
> public void keyTraversed(TraverseEvent e) {
> switch (e.detail) {
> case SWT.TRAVERSE_TAB_NEXT:
> case SWT.TRAVERSE_TAB_PREVIOUS:
> e.doit = false;
> }
> }
> });
>
>
> Best regards,
>
> Arne Jans
Re: GridTableViewer previous tab traversal? [message #545736 is a reply to message #540670] Thu, 08 July 2010 19:58 Go to previous messageGo to next message
Lars Butler is currently offline Lars ButlerFriend
Messages: 6
Registered: July 2009
Junior Member
Arne/Tom,

Thanks for the responses. I've tried your suggestions, but neither of them seem to have an effect. (I've tried each of them individually and together... no difference.) Shift+tab still does not traverse to the previous cell.

Code is below; am I doing something wrong?

package gridtableviewertest;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.ColumnViewerEditor;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
import org.eclipse.nebula.jface.gridviewer.GridViewerEditor;
import org.eclipse.nebula.widgets.grid.GridColumn;

public class View extends ViewPart {
	public static final String ID = "GridTableViewerTest.view";

	private GridTableViewer gridViewer;
	
	public void createPartControl(Composite parent) {
		gridViewer = new GridTableViewer(
		parent, SWT.V_SCROLL | SWT.H_SCROLL);

		ColumnViewerEditorActivationStrategy actSupport 
			= new ColumnViewerEditorActivationStrategy(gridViewer);

		/**
		 * Additions
		 */
		GridViewerEditor.create(gridViewer, actSupport,
				ColumnViewerEditor.TABBING_HORIZONTAL |
				ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
				| ColumnViewerEditor.TABBING_VERTICAL);

		gridViewer.getGrid().addTraverseListener(new TraverseListener()  {
			public void keyTraversed(TraverseEvent e)  {
				switch (e.detail)  {
					case SWT.TRAVERSE_TAB_NEXT:
					case SWT.TRAVERSE_TAB_PREVIOUS:
						e.doit = false;
				}
			}
		});
		/**
		 * End Additions
		 */

		gridViewer.setLabelProvider(new ColumnLabelProvider());
		gridViewer.setContentProvider(new TableContentProvider());
		gridViewer.getGrid().setCellSelectionEnabled(true);

		gridViewer.getGrid().setLinesVisible(true);
		gridViewer.getGrid().setHeaderVisible(true);
		
		GridColumn column1 = new GridColumn(gridViewer.getGrid(), SWT.NONE);
		column1.setWidth(100);
		column1.setText("Column 1");
		
		GridColumn column2 = new GridColumn(gridViewer.getGrid(), SWT.NONE);
		column2.setWidth(100);
		column2.setText("Column 2");
		
		GridColumn column3 = new GridColumn(gridViewer.getGrid(), SWT.NONE);
		column3.setWidth(100);
		column3.setText("Column 3");
		
		gridViewer.setInput(this.getViewSite());


	}


	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
		gridViewer.getControl().setFocus();
	}	
}

class ColumnLabelProvider extends LabelProvider implements
ITableLabelProvider {
	@Override
	public String getColumnText(Object element, int columnIndex) {
		return "foo";
	}

	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		return null;
	}	
}

class TableContentProvider implements IStructuredContentProvider {


	private List<TableRow> tableRows;
	
	public TableContentProvider() {
		tableRows = new ArrayList<TableRow>();
		
		for (int row=1; row<=10; row++) {
			TableRow tableRow = new TableRow();
			tableRows.add(tableRow);
		}
	}
	
	@Override
	public Object[] getElements(Object inputElement) {
		// TODO Auto-generated method stub
		return tableRows.toArray();
	}


	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void inputChanged(Viewer viewer,
			Object oldInput, Object newInput) {
		// TODO Auto-generated method stub
		
	}
}

class TableRow {
	public TableRow() {}			
}
		


Thanks,
Lars
Re: GridTableViewer previous tab traversal? [message #545786 is a reply to message #545736] Fri, 09 July 2010 07:02 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
Ok. I guess I now understand your problem. You are not talking about
editing but simply navigation.

I need to take a look into the code.

Tom

Am 08.07.10 21:58, schrieb Lars Butler:
> Arne/Tom,
>
> Thanks for the responses. I've tried your suggestions, but neither of
> them seem to have an effect. (I've tried each of them individually and
> together... no difference.) Shift+tab still does not traverse to the
> previous cell.
>
> Code is below; am I doing something wrong?
>
>
> package gridtableviewertest;
>
> import java.util.ArrayList;
> import java.util.List;
>
> import org.eclipse.jface.viewers.ColumnViewerEditor;
> import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrate gy;
> import org.eclipse.jface.viewers.IStructuredContentProvider;
> import org.eclipse.jface.viewers.ITableLabelProvider;
> import org.eclipse.jface.viewers.LabelProvider;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.TraverseEvent;
> import org.eclipse.swt.events.TraverseListener;
> import org.eclipse.swt.graphics.Image;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.ui.part.ViewPart;
>
> import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
> import org.eclipse.nebula.jface.gridviewer.GridViewerEditor;
> import org.eclipse.nebula.widgets.grid.GridColumn;
>
> public class View extends ViewPart {
> public static final String ID = "GridTableViewerTest.view";
>
> private GridTableViewer gridViewer;
>
> public void createPartControl(Composite parent) {
> gridViewer = new GridTableViewer(
> parent, SWT.V_SCROLL | SWT.H_SCROLL);
>
> ColumnViewerEditorActivationStrategy actSupport =
> new ColumnViewerEditorActivationStrategy(gridViewer);
>
> /**
> * Additions
> */
> GridViewerEditor.create(gridViewer, actSupport,
> ColumnViewerEditor.TABBING_HORIZONTAL |
> ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
> | ColumnViewerEditor.TABBING_VERTICAL);
>
> gridViewer.getGrid().addTraverseListener(new TraverseListener() {
> public void keyTraversed(TraverseEvent e) {
> switch (e.detail) {
> case SWT.TRAVERSE_TAB_NEXT:
> case SWT.TRAVERSE_TAB_PREVIOUS:
> e.doit = false;
> }
> }
> });
> /**
> * End Additions
> */
>
> gridViewer.setLabelProvider(new ColumnLabelProvider());
> gridViewer.setContentProvider(new TableContentProvider());
> gridViewer.getGrid().setCellSelectionEnabled(true);
>
> gridViewer.getGrid().setLinesVisible(true);
> gridViewer.getGrid().setHeaderVisible(true);
>
> GridColumn column1 = new GridColumn(gridViewer.getGrid(),
> SWT.NONE);
> column1.setWidth(100);
> column1.setText("Column 1");
>
> GridColumn column2 = new GridColumn(gridViewer.getGrid(),
> SWT.NONE);
> column2.setWidth(100);
> column2.setText("Column 2");
>
> GridColumn column3 = new GridColumn(gridViewer.getGrid(),
> SWT.NONE);
> column3.setWidth(100);
> column3.setText("Column 3");
>
> gridViewer.setInput(this.getViewSite());
>
>
> }
>
>
> /**
> * Passing the focus request to the viewer's control.
> */
> public void setFocus() {
> gridViewer.getControl().setFocus();
> }
> }
>
> class ColumnLabelProvider extends LabelProvider implements
> ITableLabelProvider {
> @Override
> public String getColumnText(Object element, int columnIndex) {
> return "foo";
> }
>
> @Override
> public Image getColumnImage(Object element, int columnIndex) {
> // TODO Auto-generated method stub
> return null;
> }
> }
>
> class TableContentProvider implements IStructuredContentProvider {
>
>
> private List<TableRow> tableRows;
>
> public TableContentProvider() {
> tableRows = new ArrayList<TableRow>();
>
> for (int row=1; row<=10; row++) {
> TableRow tableRow = new TableRow();
> tableRows.add(tableRow);
> }
> }
>
> @Override
> public Object[] getElements(Object inputElement) {
> // TODO Auto-generated method stub
> return tableRows.toArray();
> }
>
>
> @Override
> public void dispose() {
> // TODO Auto-generated method stub
>
> }
>
> @Override
> public void inputChanged(Viewer viewer,
> Object oldInput, Object newInput) {
> // TODO Auto-generated method stub
>
> }
> }
>
> class TableRow {
> public TableRow() {}
> }
>
>
>
> Thanks,
> Lars
Re: GridTableViewer previous tab traversal? [message #545881 is a reply to message #545786] Fri, 09 July 2010 14:18 Go to previous message
Lars Butler is currently offline Lars ButlerFriend
Messages: 6
Registered: July 2009
Junior Member
Hey Tom,

Yes, that is correct; I'm only concerned with navigation at this point. Sorry if I didn't make that initially clear.

Thanks for your time.
-Lars
Re: GridTableViewer previous tab traversal? [message #599907 is a reply to message #545541] Thu, 08 July 2010 09:27 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
You should be able to get Tabs working by configuring your when setting
up the GridViewerEditor like this:

-------8<-------
GridViewerEditor.create(v, actSupport,
ColumnViewerEditor.TABBING_HORIZONTAL |
ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL
-------8<-------


Am 08.07.10 10:29, schrieb Arne Jans:
> Hi,
>
> you have to suppress Tabbing the focus via a TraverseListener in
> createPartControl:
>
>
> gridViewer.getGrid().addTraverseListener(new
> TraverseListener() {
> public void keyTraversed(TraverseEvent e) {
> switch (e.detail) {
> case SWT.TRAVERSE_TAB_NEXT:
> case SWT.TRAVERSE_TAB_PREVIOUS:
> e.doit = false;
> }
> }
> });
>
>
> Best regards,
>
> Arne Jans
Re: GridTableViewer previous tab traversal? [message #599923 is a reply to message #545736] Fri, 09 July 2010 07:02 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
Ok. I guess I now understand your problem. You are not talking about
editing but simply navigation.

I need to take a look into the code.

Tom

Am 08.07.10 21:58, schrieb Lars Butler:
> Arne/Tom,
>
> Thanks for the responses. I've tried your suggestions, but neither of
> them seem to have an effect. (I've tried each of them individually and
> together... no difference.) Shift+tab still does not traverse to the
> previous cell.
>
> Code is below; am I doing something wrong?
>
>
> package gridtableviewertest;
>
> import java.util.ArrayList;
> import java.util.List;
>
> import org.eclipse.jface.viewers.ColumnViewerEditor;
> import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrate gy;
> import org.eclipse.jface.viewers.IStructuredContentProvider;
> import org.eclipse.jface.viewers.ITableLabelProvider;
> import org.eclipse.jface.viewers.LabelProvider;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.TraverseEvent;
> import org.eclipse.swt.events.TraverseListener;
> import org.eclipse.swt.graphics.Image;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.ui.part.ViewPart;
>
> import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
> import org.eclipse.nebula.jface.gridviewer.GridViewerEditor;
> import org.eclipse.nebula.widgets.grid.GridColumn;
>
> public class View extends ViewPart {
> public static final String ID = "GridTableViewerTest.view";
>
> private GridTableViewer gridViewer;
>
> public void createPartControl(Composite parent) {
> gridViewer = new GridTableViewer(
> parent, SWT.V_SCROLL | SWT.H_SCROLL);
>
> ColumnViewerEditorActivationStrategy actSupport =
> new ColumnViewerEditorActivationStrategy(gridViewer);
>
> /**
> * Additions
> */
> GridViewerEditor.create(gridViewer, actSupport,
> ColumnViewerEditor.TABBING_HORIZONTAL |
> ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
> | ColumnViewerEditor.TABBING_VERTICAL);
>
> gridViewer.getGrid().addTraverseListener(new TraverseListener() {
> public void keyTraversed(TraverseEvent e) {
> switch (e.detail) {
> case SWT.TRAVERSE_TAB_NEXT:
> case SWT.TRAVERSE_TAB_PREVIOUS:
> e.doit = false;
> }
> }
> });
> /**
> * End Additions
> */
>
> gridViewer.setLabelProvider(new ColumnLabelProvider());
> gridViewer.setContentProvider(new TableContentProvider());
> gridViewer.getGrid().setCellSelectionEnabled(true);
>
> gridViewer.getGrid().setLinesVisible(true);
> gridViewer.getGrid().setHeaderVisible(true);
>
> GridColumn column1 = new GridColumn(gridViewer.getGrid(),
> SWT.NONE);
> column1.setWidth(100);
> column1.setText("Column 1");
>
> GridColumn column2 = new GridColumn(gridViewer.getGrid(),
> SWT.NONE);
> column2.setWidth(100);
> column2.setText("Column 2");
>
> GridColumn column3 = new GridColumn(gridViewer.getGrid(),
> SWT.NONE);
> column3.setWidth(100);
> column3.setText("Column 3");
>
> gridViewer.setInput(this.getViewSite());
>
>
> }
>
>
> /**
> * Passing the focus request to the viewer's control.
> */
> public void setFocus() {
> gridViewer.getControl().setFocus();
> }
> }
>
> class ColumnLabelProvider extends LabelProvider implements
> ITableLabelProvider {
> @Override
> public String getColumnText(Object element, int columnIndex) {
> return "foo";
> }
>
> @Override
> public Image getColumnImage(Object element, int columnIndex) {
> // TODO Auto-generated method stub
> return null;
> }
> }
>
> class TableContentProvider implements IStructuredContentProvider {
>
>
> private List<TableRow> tableRows;
>
> public TableContentProvider() {
> tableRows = new ArrayList<TableRow>();
>
> for (int row=1; row<=10; row++) {
> TableRow tableRow = new TableRow();
> tableRows.add(tableRow);
> }
> }
>
> @Override
> public Object[] getElements(Object inputElement) {
> // TODO Auto-generated method stub
> return tableRows.toArray();
> }
>
>
> @Override
> public void dispose() {
> // TODO Auto-generated method stub
>
> }
>
> @Override
> public void inputChanged(Viewer viewer,
> Object oldInput, Object newInput) {
> // TODO Auto-generated method stub
>
> }
> }
>
> class TableRow {
> public TableRow() {}
> }
>
>
>
> Thanks,
> Lars
Re: GridTableViewer previous tab traversal? [message #599930 is a reply to message #545786] Fri, 09 July 2010 14:18 Go to previous message
Lars Butler is currently offline Lars ButlerFriend
Messages: 6
Registered: July 2009
Junior Member
Hey Tom,

Yes, that is correct; I'm only concerned with navigation at this point. Sorry if I didn't make that initially clear.

Thanks for your time.
-Lars
Previous Topic:GridTableViewer previous tab traversal?
Next Topic:CalendarCombo
Goto Forum:
  


Current Time: Sun Dec 21 18:58:03 GMT 2014

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

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