Home » Eclipse Projects » Nebula » Grid widget: is copy/cut/paste supported?
| |
Re: Grid widget: is copy/cut/paste supported? [message #636834 is a reply to message #636816] |
Wed, 03 November 2010 03:26 |
Jon Svede 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. 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 |
Thomas Schindl Messages: 6651 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 #637224 is a reply to message #636941] |
Thu, 04 November 2010 16:19 |
Jon Svede 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 #638031 is a reply to message #638021] |
Tue, 09 November 2010 16:43 |
Thomas Schindl Messages: 6651 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
>
>
|
|
|
Goto Forum:
Current Time: Tue Sep 24 23:47:59 GMT 2024
Powered by FUDForum. Page generated in 0.03883 seconds
|