Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » event.doit in DragFinished
event.doit in DragFinished [message #451861] Fri, 04 March 2005 16:37 Go to next message
Eclipse UserFriend
Originally posted by: tmsc_kitz.yahoo.com

Hi,

I have got a working SWT implementation of Drag & Drop with a slight
problem. I can drop my objects whereever I like and the event.doit in
the DragSourceEvent in dragFinished() is always true, even on another
application. Since I move objects from one table to another and the
business logic for removing those objects from the source table lies in
the dragFinished() method, I want to be sure, that the dropTarget is the
right table. Am I doing my logic at the wrong place or how do I know in
the drag section of the source that the object is dropped on the correct
target?

Thanks for any help,

Thorsten.

My code follows:

Drag Code from table "source":

------------------------------------------------------------ -------

Transfer[] types = new Transfer[] { FahrzeugTransfer.getInstance()};

DragSource source = new DragSource(oTabelle, DND.DROP_MOVE);
source.setTransfer(types);
source.addDragListener(new DragSourceAdapter() {
public void dragSetData(DragSourceEvent event) {

ArrayList<BigDecimal> alIDs = new ArrayList<BigDecimal>();
for (int i = 0; i < oTabelle.getSelection().length; i++) {
Fahrzeug oFahrzeug = (Fahrzeug)oTabelle.getSelection()[i].getData();
alIDs.add(oFahrzeug.getID());
}
event.data = alIDs.toArray(new BigDecimal[]{});
event.doit = false;
}

public void dragFinished(DragSourceEvent event) {
if(event.doit) {
for (int i = 0; i < oTabelle.getSelection().length; i++) {
Fahrzeug oFahrzeug = (Fahrzeug)oTabelle.getSelection()[i].getData();
oFahrzeugTest.move2Reservierung(oFahrzeug.getID());
}
}
oTabellenViewer.setInput(oFahrzeugTest.getFahrzeuge());
}

});

------------------------------------------------------------ -----

Drop Code from table "Target":
------------------------------------------------------------ -----

DropTarget target = new DropTarget(oTabelle,
DND.DROP_MOVE | DND.DROP_DEFAULT );
target.setTransfer(types);
target.addDropListener(new DropTargetAdapter() {
public void dragEnter(DropTargetEvent event) {
if (event.detail == DND.DROP_DEFAULT) {
event.detail = DND.DROP_MOVE;
}

for (int i = 0, n = event.dataTypes.length; i < n; i++) {
if
(FahrzeugTransfer.getInstance().isSupportedType(event.dataTy pes[i])) {
event.currentDataType = event.dataTypes[i];
}
}
}

public void dragOver(DropTargetEvent event) {
// Provide visual feedback
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
}

public void drop(DropTargetEvent event) {
if
(FahrzeugTransfer.getInstance().isSupportedType(event.curren tDataType)) {

BigDecimal[] aIDs = (BigDecimal[]) event.data;

for (int i = 0; i < aIDs.length; i++) {
oFahrzeugTest.move2Reservierung(aIDs[i]);
}

oTabellenViewer.setInput(oFahrzeugTest.getReservierungen());

}
}
});
Re: event.doit in DragFinished [message #451863 is a reply to message #451861] Wed, 09 March 2005 20:35 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
If the event.doit field is true you also need to look at the event.detail
field:

DND.DROP_MOVE - The drop target made a copy of the data and the drag source
should now delete the original and update its display.

DND.DROP_TARGET_MOVE - The drop target moved the data from its original
location to a new location. This is usually only used with files. In this
case, the drag source does not need to delete the original; it just needs to
update its display information.

If the object was not dropped on the right place, the event.doit field
should be false and/or the event.detail field will be DND.DROP_NONE.

There is no way to have the drop target defer the moving to the drag source.
You probably need to change your logic. You could also make your transfer
type identifier unique to the applciation so that data is not transferred
between applications.

For more info see:

http://eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html

http://eclipse.org/articles/Article-Workbench-DND/drag_drop. html

"Thorsten Kitz" <tmsc_kitz@yahoo.com> wrote in message
news:d0nkcg$ou7$1@www.eclipse.org...
> Hi,
>
> I have got a working SWT implementation of Drag & Drop with a slight
> problem. I can drop my objects whereever I like and the event.doit in the
> DragSourceEvent in dragFinished() is always true, even on another
> application. Since I move objects from one table to another and the
> business logic for removing those objects from the source table lies in
> the dragFinished() method, I want to be sure, that the dropTarget is the
> right table. Am I doing my logic at the wrong place or how do I know in
> the drag section of the source that the object is dropped on the correct
> target?
>
> Thanks for any help,
>
> Thorsten.
>
> My code follows:
>
> Drag Code from table "source":
>
> ------------------------------------------------------------ -------
>
> Transfer[] types = new Transfer[] { FahrzeugTransfer.getInstance()};
>
> DragSource source = new DragSource(oTabelle, DND.DROP_MOVE);
> source.setTransfer(types);
> source.addDragListener(new DragSourceAdapter() {
> public void dragSetData(DragSourceEvent event) {
>
> ArrayList<BigDecimal> alIDs = new ArrayList<BigDecimal>();
> for (int i = 0; i < oTabelle.getSelection().length; i++) {
> Fahrzeug oFahrzeug = (Fahrzeug)oTabelle.getSelection()[i].getData();
> alIDs.add(oFahrzeug.getID());
> }
> event.data = alIDs.toArray(new BigDecimal[]{});
> event.doit = false;
> }
>
> public void dragFinished(DragSourceEvent event) {
> if(event.doit) {
> for (int i = 0; i < oTabelle.getSelection().length; i++) {
> Fahrzeug oFahrzeug = (Fahrzeug)oTabelle.getSelection()[i].getData();
> oFahrzeugTest.move2Reservierung(oFahrzeug.getID());
> }
> }
> oTabellenViewer.setInput(oFahrzeugTest.getFahrzeuge());
> }
>
> });
>
> ------------------------------------------------------------ -----
>
> Drop Code from table "Target":
> ------------------------------------------------------------ -----
>
> DropTarget target = new DropTarget(oTabelle,
> DND.DROP_MOVE | DND.DROP_DEFAULT );
> target.setTransfer(types);
> target.addDropListener(new DropTargetAdapter() {
> public void dragEnter(DropTargetEvent event) {
> if (event.detail == DND.DROP_DEFAULT) {
> event.detail = DND.DROP_MOVE;
> }
>
> for (int i = 0, n = event.dataTypes.length; i < n; i++) {
> if
> (FahrzeugTransfer.getInstance().isSupportedType(event.dataTy pes[i])) {
> event.currentDataType = event.dataTypes[i];
> }
> }
> }
>
> public void dragOver(DropTargetEvent event) {
> // Provide visual feedback
> event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
> }
>
> public void drop(DropTargetEvent event) {
> if
> (FahrzeugTransfer.getInstance().isSupportedType(event.curren tDataType)) {
>
> BigDecimal[] aIDs = (BigDecimal[]) event.data;
>
> for (int i = 0; i < aIDs.length; i++) {
> oFahrzeugTest.move2Reservierung(aIDs[i]);
> }
>
> oTabellenViewer.setInput(oFahrzeugTest.getReservierungen());
>
> }
> }
> });
Previous Topic:TreeItem setText mixed font style
Next Topic:SWT runtime library not found on GTK under 3.1M5A
Goto Forum:
  


Current Time: Fri Sep 18 14:35:22 GMT 2020

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

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

Back to the top