fIsTextDragAndDropEnabled= true;
final StyledText st= viewer.getTextWidget();
// Install drag source
final ISelectionProvider selectionProvider= viewer.getSelectionProvider();
final DragSource source= new DragSource(st, DND.DROP_COPY | DND.DROP_MOVE);
source.setTransfer(new Transfer[] {TextTransfer.getInstance()});
source.addDragListener(new DragSourceAdapter() {
String fSelectedText;
Point fSelection;
public void dragStart(DragSourceEvent event) {
fTextDragAndDropToken= null;
// XXX: This is only a workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=162192
if (!fIsTextDragAndDropEnabled) {
event.doit= false;
event.image= null;
return;
}
try {
fSelection= st.getSelection();
int offset= st.getOffsetAtLocation(new Point(event.x, event.y));
Point p= st.getLocationAtOffset(offset);
if (p.x > event.x)
offset--;
event.doit= offset > fSelection.x && offset < fSelection.y;
ISelection selection= selectionProvider.getSelection();
if (selection instanceof ITextSelection)
fSelectedText= ((ITextSelection)selection).getText();
else // fallback to widget
fSelectedText= st.getSelectionText();
} catch (IllegalArgumentException ex) {