Return-Path: X-Original-To: apmail-pivot-user-archive@www.apache.org Delivered-To: apmail-pivot-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6032DD2DE for ; Thu, 6 Dec 2012 17:44:24 +0000 (UTC) Received: (qmail 98423 invoked by uid 500); 6 Dec 2012 17:44:24 -0000 Delivered-To: apmail-pivot-user-archive@pivot.apache.org Received: (qmail 98197 invoked by uid 500); 6 Dec 2012 17:44:22 -0000 Mailing-List: contact user-help@pivot.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@pivot.apache.org Delivered-To: mailing list user@pivot.apache.org Received: (qmail 98178 invoked by uid 99); 6 Dec 2012 17:44:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Dec 2012 17:44:22 +0000 X-ASF-Spam-Status: No, hits=3.9 required=5.0 tests=HTML_MESSAGE,MANY_SPAN_IN_TEXT,MIME_QP_LONG_LINE,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [173.201.192.102] (HELO p3plsmtpa06-01.prod.phx3.secureserver.net) (173.201.192.102) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Dec 2012 17:44:11 +0000 Received: from [10.171.184.225] ([166.137.184.88]) by p3plsmtpa06-01.prod.phx3.secureserver.net with id YHjn1k0021ur97q01HjnTd; Thu, 06 Dec 2012 10:43:47 -0700 Subject: Re: Use Drag and Drop in TableView Header References: From: Roger Whitcomb Content-Type: multipart/alternative; boundary=Apple-Mail-849F6746-4007-4C35-8429-B84E5F82BE46 X-Mailer: iPhone Mail (10A525) In-Reply-To: Message-Id: <6FD06B20-12DE-4474-9F99-DEB6E1BE4F19@rbwhitcomb.com> Date: Thu, 6 Dec 2012 09:42:59 -0800 To: "user@pivot.apache.org" Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (1.0) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-849F6746-4007-4C35-8429-B84E5F82BE46 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Hi Brendan, My guess would be that you are putting the column back in the same place t= hat it was. I would check indexes and things in the end drop method. Without= analyzing the code in detail that would be the first thing I would check.=20= If that is not the case (the indexes are all what you expect) then I woul= d make sure that all the proper methods are being called at the right time.=20= After that, you will have to do some old-fashioned debugging on it. Do yo= u have a Java debugger setup (like Eclipse or NetBeans or jswat)? On first examination it seems like most everything is correct, so it's pr= obably something pretty simple.=20 HTH, ~Roger Whitcomb Sent from my iPhone On Dec 6, 2012, at 4:44 AM, Brendan cheng wrote: > Hi, >=20 >=20 >=20 > I tried to implement a drag and drop function on column of table view head= er. I followed an example of Demo and coded as followed but nothing happene= d. Could you give me some advice on my code? >=20 >=20 >=20 > Brendan >=20 >=20 >=20 > Here is: >=20 > primaryHeader.setDragSource(new DragSource() { >=20 >=20 >=20 > private LocalManifest content =3D null; >=20 >=20 >=20 > @Override >=20 > public boolean beginDrag(Component component, int x= , int y) { >=20 > int columnIndex =3D primaryHeader.getTableV= iew().getColumnAt(x); >=20 > Column column =3D primaryHeader.getTableVie= w() >=20 > .getColumns().get(columnInd= ex); >=20 > if (column !=3D null) { >=20 > content =3D new LocalManifest(); >=20 > dragDropKey =3D column.getName(); >=20 > content.putValue(dragDropKey, colum= n); >=20 > } >=20 >=20 >=20 > return (content !=3D null); >=20 > } >=20 >=20 >=20 > @Override >=20 > public void endDrag(Component component, DropAction= dropAction) { >=20 > content =3D null; >=20 >=20 >=20 > } >=20 >=20 >=20 > @Override >=20 > public boolean isNative() { >=20 > return true; >=20 > } >=20 >=20 >=20 > @Override >=20 > public LocalManifest getContent() { >=20 > return content; >=20 > } >=20 >=20 >=20 > @Override >=20 > public Visual getRepresentation() { >=20 > // TODO Auto-generated method stub >=20 > return null; >=20 > } >=20 >=20 >=20 > @Override >=20 > public Point getOffset() { >=20 > // TODO Auto-generated method stub >=20 > return null; >=20 > } >=20 >=20 >=20 > @Override >=20 > public int getSupportedDropActions() { >=20 > return DropAction.COPY.getMask(); >=20 > } >=20 > }); >=20 >=20 >=20 > primaryHeader.setDropTarget(new DropTarget() { >=20 > @Override >=20 > public DropAction dragEnter(Component component, >=20 > Manifest dragContent, int supported= DropActions, >=20 > DropAction userDropAction) { >=20 > DropAction dropAction =3D null; >=20 >=20 >=20 > if (dragContent.containsValue(dragDropKey) >=20 > && DropAction.COPY.isSelect= ed(supportedDropActions)) { >=20 > dropAction =3D DropAction.COPY; >=20 > } >=20 >=20 >=20 > return dropAction; >=20 > } >=20 >=20 >=20 > @Override >=20 > public void dragExit(Component component) { >=20 > // empty block >=20 > } >=20 >=20 >=20 > @Override >=20 > public DropAction dragMove(Component component, >=20 > Manifest dragContent, int supported= DropActions, int x, >=20 > int y, DropAction userDropAction) {= >=20 > return (dragContent.containsValue(dragDropK= ey) ? DropAction.COPY : null); >=20 > } >=20 >=20 >=20 > @Override >=20 > public DropAction userDropActionChange(Component co= mponent, >=20 > Manifest dragContent, int supported= DropActions, int x, >=20 > int y, DropAction userDropAction) {= >=20 > return (dragContent.containsValue(dragDropK= ey) ? DropAction.COPY : null); >=20 > } >=20 >=20 >=20 > @Override >=20 > public DropAction drop(Component component, Manifes= t dragContent, >=20 > int supportedDropActions, int x, in= t y, >=20 > DropAction userDropAction) { >=20 > DropAction dropAction =3D null; >=20 > int columnIndex =3D primaryHeader.getTableV= iew().getColumnAt(x); >=20 > if (dragContent.containsValue(dragDropKey))= { >=20 > try { >=20 > primaryHeader >=20 > .getTableVi= ew() >=20 > .getColumnS= ource() >=20 > .getColumns= () >=20 > .remove((Co= lumn) dragContent >=20 > = .getValue(dragDropKey)); >=20 > primaryHeader >=20 > .getTableVi= ew() >=20 > .getColumnS= ource() >=20 > .getColumns= () >=20 > .insert((Co= lumn) dragContent >=20 > = .getValue(dragDropKey), columnIndex); >=20 > dropAction =3D DropAction.C= OPY; >=20 > } catch (IOException exception) { >=20 > System.err.println(exceptio= n); >=20 > } >=20 > } >=20 >=20 >=20 > dragExit(component); >=20 >=20 >=20 > return dropAction; >=20 > } >=20 > }); >=20 >=20 --Apple-Mail-849F6746-4007-4C35-8429-B84E5F82BE46 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hi Brendan,
   My g= uess would be that you are putting the column back in the same place that it= was. I would check indexes and things in the end drop method. Without analy= zing the code in detail that would be the first thing I would check. 
   If that is not the case (the indexes are all what you e= xpect) then I would make sure that all the proper methods are being called a= t the right time. 
   After that, you will have to d= o some old-fashioned debugging on it. Do you have a Java debugger setup (lik= e Eclipse or NetBeans or jswat)?

   On fi= rst examination it seems like most everything is correct, so it's probably s= omething pretty simple. 

HTH,
~Roger= Whitcomb

Sent from my iPhone

On Dec 6, 2012, at 4:44 A= M, Brendan cheng <ccp999@hotmail.co= m> wrote:

Hi,

=


I tried to implement a drag and drop fun= ction on column of table view header.  I followed an example of Demo an= d coded as followed but nothing happened.  Could you give me some advic= e on my code?


Brendan


Here is:

= primaryHeader.setDragSource(new DragSource() {


private LocalManifest content =3D null;


@Override

public boolean= beginDrag(Component component, int x,= int y) {

int columnIndex =3D primaryHeader.getTableView().getColumnAt(x);

Colu= mn column =3D primaryHeader.getTableVi= ew()

= .getColumns().get(columnIndex);

if (column !=3D null) {

content =3D new LocalManifest();

dragDropKey =3D column.getName();<= /p>

content.putValue(dragDropKey, column);

}


return (con= tent !=3D null);

}


@Override

public void en= dDrag(Component component, DropAction dropAction) {

content =3D null;


}


@Override

public boolean= isNative() {

return true;

}


@Override

public LocalManifest getContent() {

return content;

}


@Override

public Visual getRepresentation() {

// TODO Auto-generated method stub

return null;

}


@Override

public Point getOffset() {

// TODO Auto-generated method stub

return null;

}


@Override

public int get= SupportedDropActions() {

return DropAction.COPY.getMask();

}

});


primaryHeader.setDropTarget(new DropTarget() {

@Override

public DropAction dragEnter(Component component,

=

Manifest dragContent, int supporte= dDropActions,

DropAction userDropAction) {

Drop= Action dropAction =3D null;


if (dragContent.containsValue(dragDropKey)

= && DropAction.COPY.isS= elected(supportedDropActions)) {

dropAction =3D DropAction.COPY;

}


return dropAction;

}


@Override

public void dr= agExit(Component component) {

// empty block

}


@Override

public DropAction dragMove(Component component,

Manifest dragContent, int supporte= dDropActions, int x,

int y, DropAction userDropAction) {=

return (dragContent.containsValue(dragDropKey) ? DropAction.COPY : null);

}


@Override

public DropAction userDropActionChange(Component com= ponent,

Manifest dragContent, int supporte= dDropActions, int x,

int y, DropAction userDropAction) {=

return (dragContent.containsValue(dragDropKey) ? DropAction.COPY : null);

}


@Override

public DropAction drop(Component component, Manifest= dragContent,

int supportedDropActions, int x, int y,

DropAction userDropAction) {

Drop= Action dropAction =3D null;

int columnIndex =3D primaryHeader.getTableView().getColumnAt(x);

if (dragContent.containsValue(dragDropKey)) {

try {

prima= ryHeader

= .getTableView()

= .getColumnSource()

= .getColumns()

= .remove((Column) dragContent

= .getValue(dragDropKey));

prima= ryHeader

= .getTableView()

= .getColumnSource()

= .getColumns()

= .insert((Column) dragContent

= .getValue(dragDropKey), columnIndex);

= dropAction =3D DropAction.COPY= ;

} catch (IOException exception) {<= /p>

= System.err.println(exception);=

}

}


drag= Exit(component);


return dropAction;

}

});


= --Apple-Mail-849F6746-4007-4C35-8429-B84E5F82BE46--