You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by pan peter <pa...@gmail.com> on 2011/11/11 09:09:17 UTC

how to use drag and drop swap table columns

I need to swap table columns. i don't really understand how to set drag and
drop  for table view header as described in another thread, i made the
following methods, actually i have no idea what code should be used inside
those methods,

        tableView = (TableView)  namespace.get("tableView"); 
        TableViewHeader tvh = (TableViewHeader)
namespace.get("tableViewHeader"); 
        tvh.setDropTarget(new DropTarget() {...}); 
        tvh.setDragSource(new DragSource() {...}); 
        tableView.setDropTarget(new DropTarget() {...}); 
        tableView.setDragSource(new DragSource() {...}); 

and I put some break point within the dragEnter and drop method, but program
doesn't stop at anywhere. 

can anyone tells me more detail in implementing this? 

i'm using win7 and i need this work for a java application. i'm trying with
the demo table from pivot tutorials.


--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/how-to-use-drag-and-drop-swap-table-columns-tp3499066p3499066.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: how to use drag and drop swap table columns

Posted by Greg Brown <gk...@verizon.net>.
Nice!

On Nov 14, 2011, at 9:18 AM, pan peter wrote:

> OK. eventually i got everything works for drag and drop. The trick is I have
> to remove the dragged column, then insert it again with preferred index
> 
>                TableView.ColumnSequence tc = 
> tableViewHeader.getTableView().getColumns();
>                TableView.Column col0 =
> tableViewHeader.getTableView().getColumns().get(dragIndex);
>                tc.remove(col0);
>                tc.insert(col0, selectedIndex);
> 
> Where the dragIndex is a static parameter which got its value from
> DragSource.
> 
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/how-to-use-drag-and-drop-swap-table-columns-tp3499066p3506944.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: how to use drag and drop swap table columns

Posted by pan peter <pa...@gmail.com>.
OK. eventually i got everything works for drag and drop. The trick is I have
to remove the dragged column, then insert it again with preferred index

                TableView.ColumnSequence tc = 
tableViewHeader.getTableView().getColumns();
                TableView.Column col0 =
tableViewHeader.getTableView().getColumns().get(dragIndex);
                tc.remove(col0);
                tc.insert(col0, selectedIndex);

Where the dragIndex is a static parameter which got its value from
DragSource.

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/how-to-use-drag-and-drop-swap-table-columns-tp3499066p3506944.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: how to use drag and drop swap table columns

Posted by pan peter <pa...@gmail.com>.
got java.lang.UnsupportedOperationException while drag and drop a table
header column 

public DropAction drop(Component arg0, Manifest arg1, int arg2,
                    int arg3, int arg4, DropAction arg5)
            {
                tableViewHeader = (TableViewHeader) arg0;
                /** here get the relative x for selected header  */
                int xx = horizantalSplitTwo.getBounds().x;
                int selectedIndex = tableViewHeader.getHeaderAt(arg3 - xx);
                System.out.println("---------- drop !!!!-----------" +
selectedIndex);
                /**  i can see the index is correct */
                TableView.ColumnSequence tc = 
tableViewHeader.getTableView().getColumns();
                /**   i can see all columns are correct */

                TableView.Column col0 =
tableViewHeader.getTableView().getColumns().get(0);
                TableView.Column col3 =
tableViewHeader.getTableView().getColumns().get(3);
                
                tc.update(3, col0);
                /**  Then I got exception for the update ??  **/

                ........                
                return null;
            }

anything wrong in my code?


--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/how-to-use-drag-and-drop-swap-table-columns-tp3499066p3506546.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: how to use drag and drop swap table columns

Posted by pan peter <pa...@gmail.com>.
OK. I fixed it by myself :-)

The paint() method should be called by table header viewer, like this,

      tableViewHeader.paint(graphics);

Then it takes the correct image.

But how to drop then?



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/how-to-use-drag-and-drop-swap-table-columns-tp3499066p3506387.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: how to use drag and drop swap table columns

Posted by pan peter <pa...@gmail.com>.
that's the problem. how can i paint with table view header? i tried to
calculate the absolue value of start x and y for table header in
graphics.translate(), or in getOffset(), it then gives me a black box.

what value should i pass to graphics.translate() and getOffset()? 

when i use getBounds() for table header viewer, it always returns (0,0,
width, height).



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/how-to-use-drag-and-drop-swap-table-columns-tp3499066p3506209.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: how to use drag and drop swap table columns

Posted by Greg Brown <gk...@verizon.net>.
Looks like you are painting your root component into the buffered image in getRepresentation(). Try painting the TableViewHeader instead.

On Nov 11, 2011, at 11:05 AM, pan peter wrote:

> actually with following code i did manage to drag some thing while press on
> the table header, but it doesn't drag the table header, but somewhere else
> in the page, simply from (0, 0), not the actual table header location. See
> attached picture.
> 
> how to fix this?
> 
>        tableViewHeader = (TableViewHeader)namespace.get("tableViewHeader");
>        tableViewHeader.setDropTarget(new DropTarget(){
>            @Override
>            public DropAction dragEnter(Component arg0, Manifest arg1, int
> arg2, DropAction arg3)
>            {                return null;            }
> 
>            @Override
>            public void dragExit(Component arg0)            {            }
> 
>            @Override
>            public DropAction dragMove(Component arg0, Manifest arg1, int
> arg2,
>                    int arg3, int arg4, DropAction arg5)            {
>                return null;
>            }
> 
>            @Override
>            public DropAction drop(Component arg0, Manifest arg1, int arg2,
>                    int arg3, int arg4, DropAction arg5)
>            {
>                return null;
>            }
> 
>            @Override
>            public DropAction userDropActionChange(Component arg0,
>                    Manifest arg1, int arg2, int arg3, int arg4, DropAction
> arg5)
>            {
>                return null;
>            }});
> 
>        tableViewHeader.setDragSource(new DragSource(){
>            int selectedIndex;
>            @Override
>            public boolean beginDrag(Component arg0, int arg1, int arg2)
>            {
>                tableViewHeader = (TableViewHeader) arg0;
>                selectedIndex = tableViewHeader.getHeaderAt(arg1);
>                return true;
>            }
> 
>            @Override
>            public void endDrag(Component arg0, DropAction arg1){}
> 
>            @Override
>            public LocalManifest getContent(){
>                return null;
>            }
> 
>            @Override 
>            public Point getOffset() { 
>                    Point point = new Point(0, 0); 
>                    return point; 
>            } 
> 
> 
>            @Override
>            public Visual getRepresentation()
>            {
>                Picture picture = null; 
>                if (selectedIndex!=-1){ 
> 
>                    Bounds headerBounds = getHeaderBounds(selectedIndex);
>                    BufferedImage bImg = new
> BufferedImage(headerBounds.width, 
>                            headerBounds.height,
> BufferedImage.TYPE_INT_RGB); 
>                    Graphics2D graphics =  bImg.createGraphics();
>                    graphics.translate(headerBounds.x, headerBounds.y); 
>                    paint(graphics); 
>                    graphics.dispose(); 
>                    picture = new Picture(bImg); 
>                } 
> 
>                return picture; 
>            }
> 
>            private Bounds getHeaderBounds(int selectedIndex2)
>            {
>                return tableViewHeader.getHeaderBounds(selectedIndex2);
> 
>            }
> 
>            @Override
>            public int getSupportedDropActions()
>            {  return 0;        }
> 
>            @Override
>            public boolean isNative()
>            {
>                return false;
>            }});
> http://apache-pivot-users.399431.n3.nabble.com/file/n3500121/drag.jpg 
> 
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/how-to-use-drag-and-drop-swap-table-columns-tp3499066p3500121.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: how to use drag and drop swap table columns

Posted by pan peter <pa...@gmail.com>.
actually with following code i did manage to drag some thing while press on
the table header, but it doesn't drag the table header, but somewhere else
in the page, simply from (0, 0), not the actual table header location. See
attached picture.

how to fix this?

        tableViewHeader = (TableViewHeader)namespace.get("tableViewHeader");
        tableViewHeader.setDropTarget(new DropTarget(){
            @Override
            public DropAction dragEnter(Component arg0, Manifest arg1, int
arg2, DropAction arg3)
            {                return null;            }

            @Override
            public void dragExit(Component arg0)            {            }

            @Override
            public DropAction dragMove(Component arg0, Manifest arg1, int
arg2,
                    int arg3, int arg4, DropAction arg5)            {
                return null;
            }

            @Override
            public DropAction drop(Component arg0, Manifest arg1, int arg2,
                    int arg3, int arg4, DropAction arg5)
            {
                return null;
            }

            @Override
            public DropAction userDropActionChange(Component arg0,
                    Manifest arg1, int arg2, int arg3, int arg4, DropAction
arg5)
            {
                return null;
            }});
        
        tableViewHeader.setDragSource(new DragSource(){
            int selectedIndex;
            @Override
            public boolean beginDrag(Component arg0, int arg1, int arg2)
            {
                tableViewHeader = (TableViewHeader) arg0;
                selectedIndex = tableViewHeader.getHeaderAt(arg1);
                return true;
            }

            @Override
            public void endDrag(Component arg0, DropAction arg1){}

            @Override
            public LocalManifest getContent(){
                return null;
            }

            @Override 
            public Point getOffset() { 
                    Point point = new Point(0, 0); 
                    return point; 
            } 


            @Override
            public Visual getRepresentation()
            {
                Picture picture = null; 
                if (selectedIndex!=-1){ 

                    Bounds headerBounds = getHeaderBounds(selectedIndex);
                    BufferedImage bImg = new
BufferedImage(headerBounds.width, 
                            headerBounds.height,
BufferedImage.TYPE_INT_RGB); 
                    Graphics2D graphics =  bImg.createGraphics();
                    graphics.translate(headerBounds.x, headerBounds.y); 
                    paint(graphics); 
                    graphics.dispose(); 
                    picture = new Picture(bImg); 
                } 

                return picture; 
            }

            private Bounds getHeaderBounds(int selectedIndex2)
            {
                return tableViewHeader.getHeaderBounds(selectedIndex2);
                 
            }

            @Override
            public int getSupportedDropActions()
            {  return 0;        }

            @Override
            public boolean isNative()
            {
                return false;
            }});
http://apache-pivot-users.399431.n3.nabble.com/file/n3500121/drag.jpg 

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/how-to-use-drag-and-drop-swap-table-columns-tp3499066p3500121.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.