01 public class EditorAreaDropAdapter extends DropTargetAdapter {
02 private IWorkbenchWindow window;
03
04 public EditorAreaDropAdapter(IWorkbenchWindow window) {
05 this.window = window;
06 }
07
08 public void dragEnter(DropTargetEvent event) {
09 // always indicate a copy
10 event.detail = DND.DROP_COPY;
11 }
12
13 public void dragOperationChanged(DropTargetEvent event) {
14 // always indicate a copy
15 event.detail = DND.DROP_COPY;
16 }
17
18 public void drop(final DropTargetEvent event) {
19 Display d = window.getShell().getDisplay();
20 final IWorkbenchPage page = window.getActivePage();
21 if (page != null) {
22 d.asyncExec(new Runnable() {
23 public void run() {
24 asyncDrop(event, page);
25 }
26 });
27 }
28 }
29
30 private void asyncDrop(DropTargetEvent event, IWorkbenchPage page) {
31 if (LocalSelectionTransfer.getInstance().isSupportedType(
32 event.currentDataType)) {
33 StructuredSelection selection = (StructuredSelection) event.data;
34 for (Iterator iter = selection.iterator(); iter.hasNext();) {
35 Object o = iter.next();
36 if (o instanceof Record) {
37 IEditorInput input = new RecordEditorInput((Record) o);
38 try {
39 page.openEditor(input, RecordEditor.ID);
40 } catch (Exception e) {
41 PwdgatePlugin.log("open ediotr RecordEditor", e);
42 }
43 } else if (o instanceof Group) {
44 IEditorInput input = new GroupEditorInput((Group) o);
45 try {
46 page.openEditor(input, GroupEditor.ID);
47 } catch (PartInitException e) {
48 PwdgatePlugin.log("open ediotr GroupEditor", e);
49 }
50 }
51 }
52 }
53 }
54 }
--------------------next---------------------
01 public class LocalSelectionDragAdapter extends DragSourceAdapter {
02
03 ISelectionProvider selectionProvider;
04
05 public LocalSelectionDragAdapter(ISelectionProvider provider) {
06 selectionProvider = provider;
07 }
08
09 public void dragFinished(DragSourceEvent event) {
10 // TODO Auto-generated method stub
11 super.dragFinished(event);
12 System.out
13 .println("DragSourceListener.dragFinished(DragSourceEvent event)");
14 }
15
16 public void dragSetData(DragSourceEvent event) {
17 System.out
18 .println("DragSourceListener.dragSetData(DragSourceEvent event)");
19 DragSource dragSource = (DragSource) event.widget;
20 Control control = dragSource.getControl();
21 if (control != control.getDisplay().getFocusControl()) {
22 event.doit = false;
23 return;
24 }
25
26 IStructuredSelection selection = (IStructuredSelection) selectionProvider
27 .getSelection();
28
29 if (selection.isEmpty()) {
30 event.doit = false;
31 return;
32 }
33 LocalSelectionTransfer.getInstance().setSelection(selection);
34 event.doit = true;
35 }
36
37 public void dragStart(DragSourceEvent event) {
38 System.out
39 .println("DragSourceListener.dragStart(DragSourceEvent event)");
40 }
41 }
--------------------next---------------------
阅读(105) | 评论(0) | 转发(0) |