Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » DND: can't set up DragSource as in article example
DND: can't set up DragSource as in article example [message #448608] Tue, 11 January 2005 22:52 Go to next message
Eclipse UserFriend
Originally posted by: mmaercker.tripper-bullet.com

Hi all,

I am trying to implement drag and drop. To familiarize myself with the API I
copied the DragSource code from the DND in SWT article. I wound up with the,
as far as I can tell, smallest possible DND program (see below). When run,
the program shows the label including text. Whenever I try to drag the text,
though, the "no dragging allowed" cursor (circle with diagonal line) is
immediately and continuously shown. So, to me, it looks like the minimal
example does not work. What could I be doing wrong?


Any help greatly appreciated,

Martin Maercker


import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.widgets.*;

public class MainMethClass {
public static void main(String [] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("test");
shell.setLayout(new FillLayout());

// Enable a label as a Drag Source
final Label dragLabel = new Label(shell, SWT.BORDER);
dragLabel.setText("text to be transferred");

// Allow data to be copied or moved from the drag source
int operations = DND.DROP_MOVE | DND.DROP_COPY;
DragSource source = new DragSource(dragLabel, operations);

// Provide data in Text format
Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
source.setTransfer(types);

source.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
// Only start the drag if there is actually text in the
// label - this text will be what is dropped on the target.
if (dragLabel.getText().length() == 0) {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
// Provide the data of the requested type.
if
(TextTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = dragLabel.getText();
}
}
public void dragFinished(DragSourceEvent event) {
// If a move operation has been performed, remove the data
// from the source
if (event.detail == DND.DROP_MOVE)
dragLabel.setText("");
}
}
);

shell.open();
shell.setBounds(100,100,400,400);
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();

}
Re: can't set up DragSource as in article example [message #448617 is a reply to message #448608] Wed, 12 January 2005 11:59 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
You have implemented a drag source but you do not have a drop target.
Something that supplies that data for a drag is not automatically a drop
target for the same data. See the next part of the article.


"Martin Maercker" <mmaercker@tripper-bullet.com> wrote in message
news:cs1l6t$roh$1@www.eclipse.org...
> Hi all,
>
> I am trying to implement drag and drop. To familiarize myself with the API
> I
> copied the DragSource code from the DND in SWT article. I wound up with
> the,
> as far as I can tell, smallest possible DND program (see below). When run,
> the program shows the label including text. Whenever I try to drag the
> text,
> though, the "no dragging allowed" cursor (circle with diagonal line) is
> immediately and continuously shown. So, to me, it looks like the minimal
> example does not work. What could I be doing wrong?
>
>
> Any help greatly appreciated,
>
> Martin Maercker
>
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.dnd.*;
> import org.eclipse.swt.widgets.*;
>
> public class MainMethClass {
> public static void main(String [] args)
> {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setText("test");
> shell.setLayout(new FillLayout());
>
> // Enable a label as a Drag Source
> final Label dragLabel = new Label(shell, SWT.BORDER);
> dragLabel.setText("text to be transferred");
>
> // Allow data to be copied or moved from the drag source
> int operations = DND.DROP_MOVE | DND.DROP_COPY;
> DragSource source = new DragSource(dragLabel, operations);
>
> // Provide data in Text format
> Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
> source.setTransfer(types);
>
> source.addDragListener(new DragSourceListener() {
> public void dragStart(DragSourceEvent event) {
> // Only start the drag if there is actually text in the
> // label - this text will be what is dropped on the target.
> if (dragLabel.getText().length() == 0) {
> event.doit = false;
> }
> }
> public void dragSetData(DragSourceEvent event) {
> // Provide the data of the requested type.
> if
> (TextTransfer.getInstance().isSupportedType(event.dataType)) {
> event.data = dragLabel.getText();
> }
> }
> public void dragFinished(DragSourceEvent event) {
> // If a move operation has been performed, remove the data
> // from the source
> if (event.detail == DND.DROP_MOVE)
> dragLabel.setText("");
> }
> }
> );
>
> shell.open();
> shell.setBounds(100,100,400,400);
> while(!shell.isDisposed())
> {
> if(!display.readAndDispatch())
> {
> display.sleep();
> }
> }
> display.dispose();
>
> }
>
>
>
>
>
>
Re: DND problem solved (for the most part ;) [message #448618 is a reply to message #448608] Wed, 12 January 2005 12:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mmaercker.tripper-bullet.com

My example did not include a properly configured drop target. I've got dnd
within one application working now.

I was expecting other windows, at least those in the Eclipse IDE, to offer
themselves as drop targets, at least for things like TextTransfer. How do I
get a cross-application drag and drop set up?


Thanks,

Martin Maercker


"Martin Maercker" <mmaercker@tripper-bullet.com> schrieb im Newsbeitrag
news:cs1l6t$roh$1@www.eclipse.org...
> Hi all,
>
> I am trying to implement drag and drop. To familiarize myself with the API
I
> copied the DragSource code from the DND in SWT article. I wound up with
the,
> as far as I can tell, smallest possible DND program (see below). When run,
> the program shows the label including text. Whenever I try to drag the
text,
> though, the "no dragging allowed" cursor (circle with diagonal line) is
> immediately and continuously shown. So, to me, it looks like the minimal
> example does not work. What could I be doing wrong?
>
>
> Any help greatly appreciated,
>
> Martin Maercker
>
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.dnd.*;
> import org.eclipse.swt.widgets.*;
>
> public class MainMethClass {
> public static void main(String [] args)
> {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setText("test");
> shell.setLayout(new FillLayout());
>
> // Enable a label as a Drag Source
> final Label dragLabel = new Label(shell, SWT.BORDER);
> dragLabel.setText("text to be transferred");
>
> // Allow data to be copied or moved from the drag source
> int operations = DND.DROP_MOVE | DND.DROP_COPY;
> DragSource source = new DragSource(dragLabel, operations);
>
> // Provide data in Text format
> Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
> source.setTransfer(types);
>
> source.addDragListener(new DragSourceListener() {
> public void dragStart(DragSourceEvent event) {
> // Only start the drag if there is actually text in the
> // label - this text will be what is dropped on the
target.
> if (dragLabel.getText().length() == 0) {
> event.doit = false;
> }
> }
> public void dragSetData(DragSourceEvent event) {
> // Provide the data of the requested type.
> if
> (TextTransfer.getInstance().isSupportedType(event.dataType)) {
> event.data = dragLabel.getText();
> }
> }
> public void dragFinished(DragSourceEvent event) {
> // If a move operation has been performed, remove the data
> // from the source
> if (event.detail == DND.DROP_MOVE)
> dragLabel.setText("");
> }
> }
> );
>
> shell.open();
> shell.setBounds(100,100,400,400);
> while(!shell.isDisposed())
> {
> if(!display.readAndDispatch())
> {
> display.sleep();
> }
> }
> display.dispose();
>
> }
>
>
>
>
>
>
Re: can't set up DragSource as in article example [message #448620 is a reply to message #448617] Wed, 12 January 2005 12:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mmaercker.tripper-bullet.com

Hi Veronika,

thanks for your input. I had originally expected other applications to be
the target. I've now got it running within my own application. I'm still
interested in cross-application possibilities, though.

The other mail in this thread (Re: DND problem solved) was sent before your
reply was downloaded.


Best regards,

Martin

I had assumed as much
"Veronika Irvine" <veronika_irvine@oti.com> schrieb im Newsbeitrag
news:cs33gf$rif$1@www.eclipse.org...
> You have implemented a drag source but you do not have a drop target.
> Something that supplies that data for a drag is not automatically a drop
> target for the same data. See the next part of the article.
>
>
> "Martin Maercker" <mmaercker@tripper-bullet.com> wrote in message
> news:cs1l6t$roh$1@www.eclipse.org...
> > Hi all,
> >
> > I am trying to implement drag and drop. To familiarize myself with the
API
> > I
> > copied the DragSource code from the DND in SWT article. I wound up with
> > the,
> > as far as I can tell, smallest possible DND program (see below). When
run,
> > the program shows the label including text. Whenever I try to drag the
> > text,
> > though, the "no dragging allowed" cursor (circle with diagonal line) is
> > immediately and continuously shown. So, to me, it looks like the minimal
> > example does not work. What could I be doing wrong?
> >
> >
> > Any help greatly appreciated,
> >
> > Martin Maercker
> >
> >
> > import org.eclipse.swt.SWT;
> > import org.eclipse.swt.dnd.*;
> > import org.eclipse.swt.widgets.*;
> >
> > public class MainMethClass {
> > public static void main(String [] args)
> > {
> > Display display = new Display();
> > Shell shell = new Shell(display);
> > shell.setText("test");
> > shell.setLayout(new FillLayout());
> >
> > // Enable a label as a Drag Source
> > final Label dragLabel = new Label(shell, SWT.BORDER);
> > dragLabel.setText("text to be transferred");
> >
> > // Allow data to be copied or moved from the drag source
> > int operations = DND.DROP_MOVE | DND.DROP_COPY;
> > DragSource source = new DragSource(dragLabel, operations);
> >
> > // Provide data in Text format
> > Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
> > source.setTransfer(types);
> >
> > source.addDragListener(new DragSourceListener() {
> > public void dragStart(DragSourceEvent event) {
> > // Only start the drag if there is actually text in the
> > // label - this text will be what is dropped on the
target.
> > if (dragLabel.getText().length() == 0) {
> > event.doit = false;
> > }
> > }
> > public void dragSetData(DragSourceEvent event) {
> > // Provide the data of the requested type.
> > if
> > (TextTransfer.getInstance().isSupportedType(event.dataType)) {
> > event.data = dragLabel.getText();
> > }
> > }
> > public void dragFinished(DragSourceEvent event) {
> > // If a move operation has been performed, remove the data
> > // from the source
> > if (event.detail == DND.DROP_MOVE)
> > dragLabel.setText("");
> > }
> > }
> > );
> >
> > shell.open();
> > shell.setBounds(100,100,400,400);
> > while(!shell.isDisposed())
> > {
> > if(!display.readAndDispatch())
> > {
> > display.sleep();
> > }
> > }
> > display.dispose();
> >
> > }
> >
> >
> >
> >
> >
> >
>
>
Re: DND problem solved (for the most part ;) [message #448622 is a reply to message #448618] Wed, 12 January 2005 13:54 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Just run your application twice and you will see that you can drag from one
application to another. You can also drag your text into another
application like Word. Eclipse editors are not set up as drop targets for
text.

"Martin Maercker" <mmaercker@tripper-bullet.com> wrote in message
news:cs34h5$vlg$1@www.eclipse.org...
> My example did not include a properly configured drop target. I've got dnd
> within one application working now.
>
> I was expecting other windows, at least those in the Eclipse IDE, to offer
> themselves as drop targets, at least for things like TextTransfer. How do
> I
> get a cross-application drag and drop set up?
>
>
> Thanks,
>
> Martin Maercker
>
>
> "Martin Maercker" <mmaercker@tripper-bullet.com> schrieb im Newsbeitrag
> news:cs1l6t$roh$1@www.eclipse.org...
>> Hi all,
>>
>> I am trying to implement drag and drop. To familiarize myself with the
>> API
> I
>> copied the DragSource code from the DND in SWT article. I wound up with
> the,
>> as far as I can tell, smallest possible DND program (see below). When
>> run,
>> the program shows the label including text. Whenever I try to drag the
> text,
>> though, the "no dragging allowed" cursor (circle with diagonal line) is
>> immediately and continuously shown. So, to me, it looks like the minimal
>> example does not work. What could I be doing wrong?
>>
>>
>> Any help greatly appreciated,
>>
>> Martin Maercker
>>
>>
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.dnd.*;
>> import org.eclipse.swt.widgets.*;
>>
>> public class MainMethClass {
>> public static void main(String [] args)
>> {
>> Display display = new Display();
>> Shell shell = new Shell(display);
>> shell.setText("test");
>> shell.setLayout(new FillLayout());
>>
>> // Enable a label as a Drag Source
>> final Label dragLabel = new Label(shell, SWT.BORDER);
>> dragLabel.setText("text to be transferred");
>>
>> // Allow data to be copied or moved from the drag source
>> int operations = DND.DROP_MOVE | DND.DROP_COPY;
>> DragSource source = new DragSource(dragLabel, operations);
>>
>> // Provide data in Text format
>> Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
>> source.setTransfer(types);
>>
>> source.addDragListener(new DragSourceListener() {
>> public void dragStart(DragSourceEvent event) {
>> // Only start the drag if there is actually text in the
>> // label - this text will be what is dropped on the
> target.
>> if (dragLabel.getText().length() == 0) {
>> event.doit = false;
>> }
>> }
>> public void dragSetData(DragSourceEvent event) {
>> // Provide the data of the requested type.
>> if
>> (TextTransfer.getInstance().isSupportedType(event.dataType)) {
>> event.data = dragLabel.getText();
>> }
>> }
>> public void dragFinished(DragSourceEvent event) {
>> // If a move operation has been performed, remove the data
>> // from the source
>> if (event.detail == DND.DROP_MOVE)
>> dragLabel.setText("");
>> }
>> }
>> );
>>
>> shell.open();
>> shell.setBounds(100,100,400,400);
>> while(!shell.isDisposed())
>> {
>> if(!display.readAndDispatch())
>> {
>> display.sleep();
>> }
>> }
>> display.dispose();
>>
>> }
>>
>>
>>
>>
>>
>>
>
>
Re: DND problem solved (for the most part ;) [message #448625 is a reply to message #448622] Wed, 12 January 2005 14:54 Go to previous message
Eclipse UserFriend
Originally posted by: mmaercker.tripper-bullet.com

Thanks for the hint! I hadn't thought to try Word, thinking the Eclipse text
editors must be "closer" somehow... but you are right, it works like a
charm.

Martin

"Veronika Irvine" <veronika_irvine@oti.com> schrieb im Newsbeitrag
news:cs3a6s$meq$2@www.eclipse.org...
> Just run your application twice and you will see that you can drag from
one
> application to another. You can also drag your text into another
> application like Word. Eclipse editors are not set up as drop targets for
> text.
>
> "Martin Maercker" <mmaercker@tripper-bullet.com> wrote in message
> news:cs34h5$vlg$1@www.eclipse.org...
> > My example did not include a properly configured drop target. I've got
dnd
> > within one application working now.
> >
> > I was expecting other windows, at least those in the Eclipse IDE, to
offer
> > themselves as drop targets, at least for things like TextTransfer. How
do
> > I
> > get a cross-application drag and drop set up?
> >
> >
> > Thanks,
> >
> > Martin Maercker
> >
> >
> > "Martin Maercker" <mmaercker@tripper-bullet.com> schrieb im Newsbeitrag
> > news:cs1l6t$roh$1@www.eclipse.org...
> >> Hi all,
> >>
> >> I am trying to implement drag and drop. To familiarize myself with the
> >> API
> > I
> >> copied the DragSource code from the DND in SWT article. I wound up with
> > the,
> >> as far as I can tell, smallest possible DND program (see below). When
> >> run,
> >> the program shows the label including text. Whenever I try to drag the
> > text,
> >> though, the "no dragging allowed" cursor (circle with diagonal line) is
> >> immediately and continuously shown. So, to me, it looks like the
minimal
> >> example does not work. What could I be doing wrong?
> >>
> >>
> >> Any help greatly appreciated,
> >>
> >> Martin Maercker
> >>
> >>
> >> import org.eclipse.swt.SWT;
> >> import org.eclipse.swt.dnd.*;
> >> import org.eclipse.swt.widgets.*;
> >>
> >> public class MainMethClass {
> >> public static void main(String [] args)
> >> {
> >> Display display = new Display();
> >> Shell shell = new Shell(display);
> >> shell.setText("test");
> >> shell.setLayout(new FillLayout());
> >>
> >> // Enable a label as a Drag Source
> >> final Label dragLabel = new Label(shell, SWT.BORDER);
> >> dragLabel.setText("text to be transferred");
> >>
> >> // Allow data to be copied or moved from the drag source
> >> int operations = DND.DROP_MOVE | DND.DROP_COPY;
> >> DragSource source = new DragSource(dragLabel, operations);
> >>
> >> // Provide data in Text format
> >> Transfer[] types = new Transfer[]
{TextTransfer.getInstance()};
> >> source.setTransfer(types);
> >>
> >> source.addDragListener(new DragSourceListener() {
> >> public void dragStart(DragSourceEvent event) {
> >> // Only start the drag if there is actually text in the
> >> // label - this text will be what is dropped on the
> > target.
> >> if (dragLabel.getText().length() == 0) {
> >> event.doit = false;
> >> }
> >> }
> >> public void dragSetData(DragSourceEvent event) {
> >> // Provide the data of the requested type.
> >> if
> >> (TextTransfer.getInstance().isSupportedType(event.dataType)) {
> >> event.data = dragLabel.getText();
> >> }
> >> }
> >> public void dragFinished(DragSourceEvent event) {
> >> // If a move operation has been performed, remove the
data
> >> // from the source
> >> if (event.detail == DND.DROP_MOVE)
> >> dragLabel.setText("");
> >> }
> >> }
> >> );
> >>
> >> shell.open();
> >> shell.setBounds(100,100,400,400);
> >> while(!shell.isDisposed())
> >> {
> >> if(!display.readAndDispatch())
> >> {
> >> display.sleep();
> >> }
> >> }
> >> display.dispose();
> >>
> >> }
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
>
>
Previous Topic:Table - LabelProvider - Images
Next Topic:Tutorial for development desktop database application
Goto Forum:
  


Current Time: Sat Apr 20 03:46:25 GMT 2024

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

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

Back to the top