Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to get TableViewer to select cell, not row
How to get TableViewer to select cell, not row [message #723737] Fri, 09 September 2011 09:49 Go to next message
Yo is currently offline YoFriend
Messages: 10
Registered: July 2009
Junior Member
Hi,
I have implemented a context menu for a TableViewer and configured a
command handler to process when a specific item in the menu is
right-clicked. My plan is to implemented cell copy a la Ctrl-C.

The selection event gives me the whole role but I need to know which
cell in that row was selected at the time (ie, which cell was right-clicked.

Do I need to set things up differently?

Here is the set up in the viewer class:

MenuManager menuManager = new MenuManager();
Menu menu = menuManager.createContextMenu(viewer.getTable());

viewer.getTable().setMenu(menu);
getSite().registerContextMenu(menuManager, viewer);

Here is my handler. The data in the event (Object element, below) is a
String[] of the row's content:

public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).
getActivePage().getSelection();
if (selection != null & selection instanceof IStructuredSelection) {
IStructuredSelection strucSel = (IStructuredSelection) selection;
for (Iterator<?> iterator = strucSel.iterator();
iterator.hasNext();) {
Object element = iterator.next();
System.out.println(element.toString());
}
}
return null;
}

How do i get an event indicating the specific cell?

Thanks,
y
Re: How to get TableViewer to select cell, not row [message #725322 is a reply to message #723737] Wed, 14 September 2011 14:06 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

This may not be quite what you were looking for, but could probably help
with what you want. The snippets below demonstrate how to do this at
the swt level, including how to get the clicked column index.

-
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet3.java
-
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet110.java

HTH,
Grant


On 9/9/2011 5:49 AM, Yo wrote:
> Hi,
> I have implemented a context menu for a TableViewer and configured a
> command handler to process when a specific item in the menu is
> right-clicked. My plan is to implemented cell copy a la Ctrl-C.
>
> The selection event gives me the whole role but I need to know which
> cell in that row was selected at the time (ie, which cell was
> right-clicked.
>
> Do I need to set things up differently?
>
> Here is the set up in the viewer class:
>
> MenuManager menuManager = new MenuManager();
> Menu menu = menuManager.createContextMenu(viewer.getTable());
>
> viewer.getTable().setMenu(menu);
> getSite().registerContextMenu(menuManager, viewer);
>
> Here is my handler. The data in the event (Object element, below) is a
> String[] of the row's content:
>
> public Object execute(ExecutionEvent event) throws ExecutionException {
> ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).
> getActivePage().getSelection();
> if (selection != null & selection instanceof IStructuredSelection) {
> IStructuredSelection strucSel = (IStructuredSelection) selection;
> for (Iterator<?> iterator = strucSel.iterator();
> iterator.hasNext();) {
> Object element = iterator.next();
> System.out.println(element.toString());
> }
> }
> return null;
> }
>
> How do i get an event indicating the specific cell?
>
> Thanks,
> y
Re: How to get TableViewer to select cell, not row [message #728672 is a reply to message #725322] Fri, 23 September 2011 15:56 Go to previous message
Yo is currently offline YoFriend
Messages: 10
Registered: July 2009
Junior Member
Hi Grant,
Your tip saved me! Working! Thanks very, very much!
Yo


On 9/14/2011 4:06 PM, Grant Gayed wrote:
> Hi,
>
> This may not be quite what you were looking for, but could probably help
> with what you want. The snippets below demonstrate how to do this at the
> swt level, including how to get the clicked column index.
>
> -
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet3.java
>
> -
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet110.java
>
>
> HTH,
> Grant
>
>
> On 9/9/2011 5:49 AM, Yo wrote:
>> Hi,
>> I have implemented a context menu for a TableViewer and configured a
>> command handler to process when a specific item in the menu is
>> right-clicked. My plan is to implemented cell copy a la Ctrl-C.
>>
>> The selection event gives me the whole role but I need to know which
>> cell in that row was selected at the time (ie, which cell was
>> right-clicked.
>>
>> Do I need to set things up differently?
>>
>> Here is the set up in the viewer class:
>>
>> MenuManager menuManager = new MenuManager();
>> Menu menu = menuManager.createContextMenu(viewer.getTable());
>>
>> viewer.getTable().setMenu(menu);
>> getSite().registerContextMenu(menuManager, viewer);
>>
>> Here is my handler. The data in the event (Object element, below) is a
>> String[] of the row's content:
>>
>> public Object execute(ExecutionEvent event) throws ExecutionException {
>> ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).
>> getActivePage().getSelection();
>> if (selection != null & selection instanceof IStructuredSelection) {
>> IStructuredSelection strucSel = (IStructuredSelection) selection;
>> for (Iterator<?> iterator = strucSel.iterator();
>> iterator.hasNext();) {
>> Object element = iterator.next();
>> System.out.println(element.toString());
>> }
>> }
>> return null;
>> }
>>
>> How do i get an event indicating the specific cell?
>>
>> Thanks,
>> y
>
Previous Topic:Where is "Platform Plug-in Developer Guide" in eclipse indigo help
Next Topic:complex label provider for multi-level tree viewer
Goto Forum:
  


Current Time: Wed Apr 24 20:30:49 GMT 2024

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

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

Back to the top