Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Grid widget: is copy/cut/paste supported?
Grid widget: is copy/cut/paste supported? [message #636782] Tue, 02 November 2010 18:36 Go to next message
Jon Svede is currently offline Jon SvedeFriend
Messages: 83
Registered: July 2009
Member
Does the grid widget support selecting a region and being able to copy/cut from the grid as well as pasting a region to the grid? In other words, can I select a grid of cells, 3 by 3 for example, copy them and paste them into a spreadsheet or vice versa?

If so, how? I've been looking around for examples and not found any which leads me to believe it's really easy or very difficult.

Thanks,

Jon
Re: Grid widget: is copy/cut/paste supported? [message #636816 is a reply to message #636782] Tue, 02 November 2010 22:10 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5467
Registered: July 2009
Senior Member
Not out of the box but using SWT-Clipboard all you need to do is copy
those cells as Text seperated by \t and \n in there and then you can
paste it to Excel.

Tom

Am 02.11.10 19:36, schrieb Jon Svede:
> Does the grid widget support selecting a region and being able to
> copy/cut from the grid as well as pasting a region to the grid? In
> other words, can I select a grid of cells, 3 by 3 for example, copy them
> and paste them into a spreadsheet or vice versa?
> If so, how? I've been looking around for examples and not found any
> which leads me to believe it's really easy or very difficult.
>
> Thanks,
>
> Jon
>
Re: Grid widget: is copy/cut/paste supported? [message #636834 is a reply to message #636816] Wed, 03 November 2010 03:26 Go to previous messageGo to next message
Jon Svede is currently offline Jon SvedeFriend
Messages: 83
Registered: July 2009
Member
Thanks, Tom! Later in the day I was browsing the Javadocs for the platform and noticed the swt.dnd package (well, it was more like I stumbled across it). From there I used that info to find Lar Vogel's tutorial:

http://www.vogella.de/articles/EclipseJFaceTable/article.htm l

I should have looked there first. Smile Lars' tutorial does as you suggest, delimits information with tabs and line feeds.

It has an example from a TreeViewer. My code isn't working yet but I am much further along than I was earlier. The problem I am having now is that when I select a "grid" of cells, the selection that I get back in the code is the complete row, not my cells. Even if I select one cell, I still get the whole row, so I am missing something.

This also doesn't get me to the part where I can paste from the clipboard, but I am hopefully that once I figure out how to copy from the GridTableViewer I can figure out to paste to it.

Thanks again,

Jon
Re: Grid widget: is copy/cut/paste supported? [message #636853 is a reply to message #636834] Wed, 03 November 2010 06:52 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5467
Registered: July 2009
Senior Member
IIRC Grid#getSelectedCells(): Point[] where the x in the point is the
column index and y is the row.

Tom

Am 03.11.10 04:27, schrieb Jon Svede:
> Thanks, Tom! Later in the day I was browsing the Javadocs for the
> platform and noticed the swt.dnd package (well, it was more like I
> stumbled across it). From there I used that info to find Lar Vogel's
> tutorial:
> http://www.vogella.de/articles/EclipseJFaceTable/article.htm l
>
> I should have looked there first. :) Lars' tutorial does as you
> suggest, delimits information with tabs and line feeds.
>
> It has an example from a TreeViewer. My code isn't working yet but I am
> much further along than I was earlier. The problem I am having now is
> that when I select a "grid" of cells, the selection that I get back in
> the code is the complete row, not my cells. Even if I select one cell,
> I still get the whole row, so I am missing something.
> This also doesn't get me to the part where I can paste from the
> clipboard, but I am hopefully that once I figure out how to copy from
> the GridTableViewer I can figure out to paste to it.
>
> Thanks again,
>
> Jon
>
Re: Grid widget: is copy/cut/paste supported? [message #636941 is a reply to message #636853] Wed, 03 November 2010 13:32 Go to previous messageGo to next message
Jon Svede is currently offline Jon SvedeFriend
Messages: 83
Registered: July 2009
Member
Thanks, Tom. You recalled correctly.

After banging away at last night for a few more hours, I realized that I needed to expose my viewer from my IViewPart. Doing that allows me to access the Grid instance in my Handler - and from that point I was assuming that the widget itself would have some method for accessing the selection.

Sincerely,

Jon
Re: Grid widget: is copy/cut/paste supported? [message #637224 is a reply to message #636941] Thu, 04 November 2010 16:19 Go to previous messageGo to next message
Jon Svede is currently offline Jon SvedeFriend
Messages: 83
Registered: July 2009
Member
How do I leverage the Grid to help with the cut and paste? I wrote an example that uses String[][] as the input to the GridTableViewer. When I implement this in my example I exposed the GridViewer from my IViewPart so that my CopyHandler (Instance of AbstractHandler) could access the data via the getInput() method.

In the code that I am working on, this won't work.

What would be great is if I could get an array of GridItem objects, because these will have the right object references for my model.

To that end, I tried the following:

  Point[] points = viewer.getGrid().getCellSelection() ;
  for( Point p : points ) {
    GridItem item = grid.getItem( p ) ; // always returns null due to the way this method considers the p.y value
  }


Next, I tried this:

  GridItem[] items = myViewer.getGrid().getSelection() ;


This returns the first element in each selected row.

Another thing I looked at was the Grid.getSelectionIndex() which returns the row index of the selection. None of these seem to let me leverage the Point[] to get at the cell data.

Ideally, if that getItem( Point p) method returned the GridItem I think I'd be set.

In that method, there is this:

  if (columnHeaderVisible)
  {
    if (p.y <= headerHeight)
    {
      return null ;
    }
    y2 += headerHeight ;
  }


When I run my code in the debugger, it falls into this if block and hits that 'return null' statement. I don't see what header height has to do with returning an item from the Grid - but I am sure I am missing something.

So, at the end of this long diatribe, my question is how do I get past this so that I can use the Point[] array? Am i doing something wrong? Or is this working as expected? Is there another way to get the selection information with the underlying objects? In my case, these items will have the necessary elements for updating the model.
Re: Grid widget: is copy/cut/paste supported? [message #638021 is a reply to message #637224] Tue, 09 November 2010 16:25 Go to previous messageGo to next message
Jon Svede is currently offline Jon SvedeFriend
Messages: 83
Registered: July 2009
Member
I was able to get my copy/paste to work but I can't believe this is right.

Here is what I had to do:

1. in my ViewPart, add my viewer as a selection provider:
getSite().setSelectionProvider( myGridTableViewer ) ;

2. in my command impl class, get the row selection:
ISelection selection = page.getSelection() ;

3. again in the command, from the Grid object, get the actual selection:
Point[] selections = myGridTableViewer.getGrid().getCellSelection();

4. Using the Point[] and the selected rows, get the actual cell contents and add them to a StringBuilder object, tab and new line delimited.

Is that right? The part where I got the selected rows from the viewer and then had to use the Point[] array is awkward....but it works. Is there a better way to do that?

Thanks for the help to this point, it has been greatly appreciated!

Sincerely,

Jon

Re: Grid widget: is copy/cut/paste supported? [message #638031 is a reply to message #638021] Tue, 09 November 2010 16:43 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5467
Registered: July 2009
Senior Member
Did you check the selection you got from the GridViewer. IIRC we have
our own subclass which holds the selected cells as well.

Tom

Am 09.11.10 17:25, schrieb Jon Svede:
> I was able to get my copy/paste to work but I can't believe this is right.
>
> Here is what I had to do:
>
> 1. in my ViewPart, add my viewer as a selection provider:
>
> getSite().setSelectionProvider( myGridTableViewer ) ;
>
> 2. in my command impl class, get the row selection:
>
> ISelection selection = page.getSelection() ;
>
> 3. again in the command, from the Grid object, get the actual selection:
>
> Point[] selections = myGridTableViewer.getGrid().getCellSelection();
>
> 4. Using the Point[] and the selected rows, get the actual cell contents
> and add them to a StringBuilder object, tab and new line delimited.
>
> Is that right? The part where I got the selected rows from the viewer
> and then had to use the Point[] array is awkward....but it works. Is
> there a better way to do that?
>
> Thanks for the help to this point, it has been greatly appreciated!
>
> Sincerely,
>
> Jon
>
>
Previous Topic:CompositeTable
Next Topic:unable to compile nebula
Goto Forum:
  


Current Time: Wed Nov 26 04:36:39 GMT 2014

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

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