org.eclipse.swt.dnd.DropTarget Java Examples
The following examples show how to use
org.eclipse.swt.dnd.DropTarget.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SWTUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the shell for the given widget. If the widget doesn't represent * a SWT object that manage a shell, <code>null</code> is returned. * @param widget the widget * * @return the shell for the given widget */ public static Shell getShell(Widget widget) { if (widget instanceof Control) return ((Control)widget).getShell(); if (widget instanceof Caret) return ((Caret)widget).getParent().getShell(); if (widget instanceof DragSource) return ((DragSource)widget).getControl().getShell(); if (widget instanceof DropTarget) return ((DropTarget)widget).getControl().getShell(); if (widget instanceof Menu) return ((Menu)widget).getParent().getShell(); if (widget instanceof ScrollBar) return ((ScrollBar)widget).getParent().getShell(); return null; }
Example #2
Source File: Tables.java From olca-app with Mozilla Public License 2.0 | 6 votes |
public static void onDrop(TableViewer table, Consumer<List<Descriptor>> fn) { Transfer transfer = ModelTransfer.getInstance(); DropTarget target = new DropTarget(table.getTable(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT); target.setTransfer(new Transfer[] { transfer }); target.addDropListener(new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { if (!transfer.isSupportedType(event.currentDataType)) return; var list = ModelTransfer.getDescriptors(event.data); fn.accept(list); } }); }
Example #3
Source File: Trees.java From olca-app with Mozilla Public License 2.0 | 6 votes |
public static void addDropSupport(TreeViewer tree, Consumer<List<Descriptor>> handler) { Transfer transfer = ModelTransfer.getInstance(); DropTarget dropTarget = new DropTarget(tree.getTree(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT); dropTarget.setTransfer(new Transfer[] { transfer }); dropTarget.addDropListener(new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { if (!transfer.isSupportedType(event.currentDataType)) return; var list = ModelTransfer.getDescriptors(event.data); handler.accept(list); } }); }
Example #4
Source File: PersistentObjectDropTarget.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * Register the provided target as {@link DropTarget} for a {@link PersistentObject} * @param target * @param r * @param colorizeControl whether the target control should change color during selection * @since 3.1.0 */ public PersistentObjectDropTarget(String name, Control target, IReceiver r, boolean colorizeControl){ if (colorizeControl) { normalColor = target.getBackground(); highlightColor = target.getDisplay().getSystemColor(SWT.COLOR_RED); } else { normalColor = null; highlightColor = null; } this.name = name; mine = target; rc = r; DropTarget dtarget = new DropTarget(target, DND.DROP_COPY); final TextTransfer textTransfer = TextTransfer.getInstance(); Transfer[] types = new Transfer[] { textTransfer }; dtarget.setTransfer(types); dtarget.addDropListener(this); }
Example #5
Source File: GenericObjectDropTarget.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * Register the provided target as {@link DropTarget} for a {@link PersistentObject} * @param target * @param r * @param colorizeControl whether the target control should change color during selection * @since 3.1.0 */ public GenericObjectDropTarget(String name, Control target, IReceiver r, boolean colorizeControl){ if (colorizeControl) { normalColor = target.getBackground(); highlightColor = target.getDisplay().getSystemColor(SWT.COLOR_RED); } else { normalColor = null; highlightColor = null; } this.name = name; mine = target; rc = r; DropTarget dtarget = new DropTarget(target, DND.DROP_COPY); final TextTransfer textTransfer = TextTransfer.getInstance(); Transfer[] types = new Transfer[] { textTransfer }; dtarget.setTransfer(types); dtarget.addDropListener(this); }
Example #6
Source File: SWTUtil.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Returns the shell for the given widget. If the widget doesn't represent * a SWT object that manage a shell, <code>null</code> is returned. * @param widget the widget * * @return the shell for the given widget */ public static Shell getShell(Widget widget) { if (widget instanceof Control) { return ((Control) widget).getShell(); } if (widget instanceof Caret) { return ((Caret) widget).getParent().getShell(); } if (widget instanceof DragSource) { return ((DragSource) widget).getControl().getShell(); } if (widget instanceof DropTarget) { return ((DropTarget) widget).getControl().getShell(); } if (widget instanceof Menu) { return ((Menu) widget).getParent().getShell(); } if (widget instanceof ScrollBar) { return ((ScrollBar) widget).getParent().getShell(); } return null; }
Example #7
Source File: TmxEditorViewer.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
@Override public void createPartControl(Composite parent) { parent.setLayout(new FillLayout()); this.container = parent; CellEditorGlobalActionHanlder.getInstance().setIActionBars(getViewSite().getActionBars()); DropTarget target = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY); Transfer[] tfs = new Transfer[] { FileTransfer.getInstance() }; target.setTransfer(tfs); target.addDropListener(new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { Object o = event.data; if (o instanceof String[]) { String[] s = (String[]) o; if (s.length == 0 && s[0] == null || s[0].length() == 0) { return; } File f = new File(s[0]); if (f.exists() && f.isFile()) { open(f); } } } }); }
Example #8
Source File: SWTUtil.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * Returns the shell for the given widget. If the widget doesn't represent a SWT object that manage a shell, * <code>null</code> is returned. * * @return the shell for the given widget */ public static Shell getShell(Widget widget) { if (widget instanceof Control) return ((Control) widget).getShell(); if (widget instanceof Caret) return ((Caret) widget).getParent().getShell(); if (widget instanceof DragSource) return ((DragSource) widget).getControl().getShell(); if (widget instanceof DropTarget) return ((DropTarget) widget).getControl().getShell(); if (widget instanceof Menu) return ((Menu) widget).getParent().getShell(); if (widget instanceof ScrollBar) return ((ScrollBar) widget).getParent().getShell(); return null; }
Example #9
Source File: ExampleDropTargetListener.java From statecharts with Eclipse Public License 1.0 | 6 votes |
@Override public void drop(DropTargetEvent event) { if (!URLTransfer.getInstance().isSupportedType(event.currentDataType)) { return; } final String url = getUrl(event.data); if (ExampleURLHandler.isValidExample(url)) { DropTarget source = (DropTarget) event.getSource(); Display display = source.getDisplay(); display.asyncExec(new Runnable() { public void run() { proceedInstallation(url); } }); } }
Example #10
Source File: SWTUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * Returns the shell for the given widget. If the widget doesn't represent a SWT object that manage a shell, * <code>null</code> is returned. * * @param widget * the widget * * @return the shell for the given widget */ public static Shell getShell(Widget widget) { if (widget instanceof Control) return ((Control) widget).getShell(); if (widget instanceof Caret) return ((Caret) widget).getParent().getShell(); if (widget instanceof DragSource) return ((DragSource) widget).getControl().getShell(); if (widget instanceof DropTarget) return ((DropTarget) widget).getControl().getShell(); if (widget instanceof Menu) return ((Menu) widget).getParent().getShell(); if (widget instanceof ScrollBar) return ((ScrollBar) widget).getParent().getShell(); return null; }
Example #11
Source File: ExampleDropTargetInstaller.java From statecharts with Eclipse Public License 1.0 | 6 votes |
protected void registerWithExistingTarget(DropTarget target) { Transfer[] transfers = target.getTransfer(); boolean exists = false; if (transfers != null) { for (Transfer transfer : transfers) { if (transfer instanceof URLTransfer) { exists = true; break; } } if (!exists) { Transfer[] newTransfers = new Transfer[transfers.length + 1]; System.arraycopy(transfers, 0, newTransfers, 0, transfers.length); newTransfers[transfers.length] = URLTransfer.getInstance(); target.setTransfer(newTransfers); } } }
Example #12
Source File: LogViewer.java From LogViewer with Eclipse Public License 2.0 | 5 votes |
public void createPartControl(Composite parent) { //viewer this.parent = parent; documentListener = new ViewDocumentListener(); tabfolder = new TabFolder(parent,0); tabfolder.addSelectionListener(new TabSelectionListener()); viewer = new LogFileViewer(tabfolder,SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); // DnD DropTarget target = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK); target.setTransfer(new Transfer[] {FileTransfer.getInstance(), TextTransfer.getInstance()}); target.addDropListener (new DropTargetAdapter() { public void dragEnter(DropTargetEvent e) { if (e.detail == DND.DROP_NONE) e.detail = DND.DROP_COPY; } public void drop(DropTargetEvent event) { if (event.data == null || ((String[])event.data).length < 1) { event.detail = DND.DROP_NONE; return; } //File file = new File(((String[])event.data)[0]); if (!checkAndOpenFile(LogFileType.LOGFILE_SYSTEM_FILE,((String[])event.data)[0], null, false)) event.detail = DND.DROP_NONE; } }); // fill the menues makeActions(); hookContextMenu(); contributeToActionBars(); openAllLastOpenFiles(); }
Example #13
Source File: NavigationDropAssistant.java From olca-app with Mozilla Public License 2.0 | 5 votes |
@Override public IStatus handleDrop(CommonDropAdapter dropAdapter, DropTargetEvent dropTargetEvent, Object target) { Navigator navigator = (Navigator) PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage() .findView(Navigator.ID); DropTarget dropTarget = (DropTarget) dropTargetEvent.getSource(); INavigationElement<?> targetElement = (INavigationElement<?>) target; if (dropTarget.getControl() == navigator.getCommonViewer().getTree()) doIt(dropTargetEvent, targetElement); return null; }
Example #14
Source File: IdentifiableDropTarget.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
public IdentifiableDropTarget(Control target, IReceiver receiver){ this.receiver = receiver; DropTarget dtarget = new DropTarget(target, DND.DROP_COPY); final TextTransfer textTransfer = TextTransfer.getInstance(); Transfer[] types = new Transfer[] { textTransfer }; dtarget.setTransfer(types); dtarget.addDropListener(this); }
Example #15
Source File: ScriptConsoleViewer.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private void initDragDrop() { DragSource dragSource = new DragSource(this, DND.DROP_COPY | DND.DROP_MOVE); dragSource.addDragListener(new DragSourceAdapter()); dragSource.setTransfer(new Transfer[] { org.eclipse.swt.dnd.TextTransfer.getInstance() }); DropTarget dropTarget = new DropTarget(this, DND.DROP_COPY | DND.DROP_MOVE); dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer(), org.eclipse.swt.dnd.TextTransfer.getInstance() }); dropTarget.addDropListener(new DragTargetAdapter()); }
Example #16
Source File: ExampleDropTargetInstaller.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected void hookRecursive(Control child, DropTargetListener dropListener) { DropTarget childTarget = findDropTarget(child); if (childTarget != null) { registerWithExistingTarget(childTarget); registerDropListener(childTarget, dropListener); } if (child instanceof Composite) { Composite composite = (Composite) child; Control[] children = composite.getChildren(); for (Control control : children) { hookRecursive(control, dropListener); } } }
Example #17
Source File: View.java From codeexamples-eclipse with Eclipse Public License 1.0 | 5 votes |
private void addDropListener(Composite parent) { LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); DropTargetAdapter dragAdapter = new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { Control droppedObj = (Control) ((StructuredSelection) transfer.getSelection()).getFirstElement(); // Get the existing parent of the dragged control Composite oldParent = droppedObj.getParent(); if (oldParent == parent) { return; } if (droppedObj instanceof Label) { System.out.println("Dropped"); } // handle the drop if (droppedObj instanceof Label) { Label droppedLabel = (Label) droppedObj; droppedLabel.setParent(parent); // Change parent } if (droppedObj instanceof Button) { Button droppedButton = (Button) droppedObj; droppedButton.setParent(parent); // Change parent } // request a layout pass oldParent.requestLayout(); // If you change that to layout the layout will be correct parent.layout(); } }; DropTarget dropTarget = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY); dropTarget.setTransfer(new Transfer[] { transfer }); dropTarget.addDropListener(dragAdapter); }
Example #18
Source File: ChartManager.java From neoscada with Eclipse Public License 1.0 | 5 votes |
public DropTarget createDropTarget ( final Transfer[] transfers, final DropTargetListener dropTargetListener ) { checkWidget (); final DropTarget target = new DropTarget ( this.chartArea, DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_LINK ); target.setTransfer ( transfers ); target.addDropListener ( dropTargetListener ); return target; }
Example #19
Source File: TypeHierarchyViewPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void initDragAndDrop() { for (int i= 0; i < fAllViewers.length; i++) { addDragAdapters(fAllViewers[i]); addDropAdapters(fAllViewers[i]); } addDragAdapters(fMethodsViewer); fMethodsViewer.addDropSupport(DND.DROP_NONE, new Transfer[0], new DropTargetAdapter()); //DND on empty hierarchy DropTarget dropTarget = new DropTarget(fPagebook, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT); dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getInstance() }); dropTarget.addDropListener(new TypeHierarchyTransferDropAdapter(this, fAllViewers[0])); }
Example #20
Source File: CallHierarchyViewPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void initDragAndDrop() { addDragAdapters(fCallHierarchyViewer); addDropAdapters(fCallHierarchyViewer); addDropAdapters(fLocationViewer); //dnd on empty hierarchy DropTarget dropTarget = new DropTarget(fPagebook, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT); dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getInstance() }); dropTarget.addDropListener(new CallHierarchyTransferDropAdapter(this, fCallHierarchyViewer)); }
Example #21
Source File: AbstractThemeableEditor.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@Override protected void initializeDragAndDrop(ISourceViewer viewer) { super.initializeDragAndDrop(viewer); // Adds snippet drag/drop support IDragAndDropService dndService = (IDragAndDropService) getSite().getService(IDragAndDropService.class); if (dndService == null) { return; } StyledText st = viewer.getTextWidget(); DropTarget dropTarget = (DropTarget) st.getData(DND.DROP_TARGET_KEY); if (dropTarget != null) { Transfer[] transfers = dropTarget.getTransfer(); List<Transfer> allTransfers = CollectionsUtil.newList(transfers); allTransfers.add(SnippetTransfer.getInstance()); dropTarget.setTransfer(allTransfers.toArray(new Transfer[allTransfers.size()])); dropTarget.addDropListener(new SnippetDropTargetListener()); } else { dndService.addMergedDropTarget(st, DND.DROP_COPY, new Transfer[] { SnippetTransfer.getInstance() }, new SnippetDropTargetListener()); } }
Example #22
Source File: ExampleDropTargetInstaller.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected DropTarget findDropTarget(Control control) { Object object = control.getData(DND.DROP_TARGET_KEY); if (object instanceof DropTarget) { return (DropTarget) object; } return null; }
Example #23
Source File: PhotoShuffler.java From codeexamples-eclipse with Eclipse Public License 1.0 | 4 votes |
/** * @param parentComposite - the composite that holds all pictures * @param target - the drop target */ public MyDropTargetListener(Composite parentComposite, DropTarget target) { this.parentComposite = parentComposite; this.target = target; }
Example #24
Source File: PhotoShuffler.java From codeexamples-eclipse with Eclipse Public License 1.0 | 4 votes |
public static void main(String[] args) { // setup the SWT window Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("Photo Shuffler"); // initialize a parent composite with a grid layout manager Composite parent = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; gridLayout.marginWidth=20; parent.setLayout(gridLayout); // determine the path where the pictures are stored String path = System.getProperty("user.dir") + "/images/"; // initialize an array with the photograph names File imageDir= new File(path); // loop over the photo array and establish all listeners List<File> files = Arrays.stream(imageDir.listFiles()) .filter(f -> f.isFile() && f.getName().endsWith(".png")) .collect(Collectors.toList()); for (File file : files) { // labels serve as containers for the images Label label = new Label(parent, SWT.NONE); Image img = new Image(display,file.getAbsolutePath()); label.setImage(img); // enable each label to be draggable DragSource source = new DragSource(label, DND.DROP_NONE); source.setTransfer(TextTransfer.getInstance()); // varargs are supported as of 4.7 // add a drag listener source.addDragListener(new MyDragSourceListener(parent, source)); // enable each label to be a drop target DropTarget target = new DropTarget(label, DND.DROP_NONE); target.setTransfer(new Transfer[] { TextTransfer.getInstance() }); // varargs are not yet supported see https://git.eclipse.org/r/#/c/92236 // add a drop listener target.addDropListener(new MyDropTargetListener(parent, target)); } // show the SWT window shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } // tear down the SWT window display.dispose(); }
Example #25
Source File: DataTextDropListener.java From birt with Eclipse Public License 1.0 | 4 votes |
public void dragEnter( DropTargetEvent event ) { // indicate a copy event.detail = DND.DROP_COPY; // check if valid expression // Get Data in a Java format // Since in Mac os x / Linux, the event.currentDataType.data is still // null, so here ignores validation under Mac os x /Linux. if ( Platform.OS_WIN32.equals( Platform.getOS( ) ) ) { Object object = null; Transfer[] transferAgents = ( (DropTarget) event.widget ).getTransfer( ); for ( int i = 0; i < transferAgents.length; i++ ) { Transfer transfer = transferAgents[i]; if ( transfer != null && transfer instanceof SimpleTextTransfer ) { object = SimpleTextTransfer.getInstance( ) .nativeToJava( event.currentDataType ); break; } } if ( object != null ) { // object is a binding name. expression is needed for // validation. ExpressionCodec expCodec = ChartModelHelper.instance( ) .createExpressionCodec( ); expCodec.setType( btnBuilder.getExpressionType( ) ); expCodec.setBindingName( object.toString( ), btnBuilder.isCube( ) ); if ( !DataDefinitionTextManager.getInstance( ) .isValidExpression( txtDataDefn, expCodec.getExpression( ) ) ) { event.detail = DND.DROP_NONE; } } } }
Example #26
Source File: ExampleDropTargetInstaller.java From statecharts with Eclipse Public License 1.0 | 4 votes |
protected void registerDropListener(DropTarget target, DropTargetListener dropListener) { target.removeDropListener(dropListener); target.addDropListener(dropListener); }
Example #27
Source File: FilterViewer.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
public FilterViewer(Composite parent, int style, boolean isDialog) { super(parent, style); this.fIsDialog = isDialog; setLayout(new FillLayout()); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); setLayoutData(gd); final SashForm sash = new SashForm(this, SWT.HORIZONTAL); // Create the tree viewer to display the filter tree fViewer = new TreeViewer(sash, SWT.NONE); fViewer.setContentProvider(new FilterTreeContentProvider()); fViewer.setLabelProvider(new FilterTreeLabelProvider()); // Create the empty filter node properties panel fComposite = new Composite(sash, SWT.NONE); GridLayout gl = new GridLayout(); gl.marginHeight = 0; gl.marginWidth = 0; fComposite.setLayout(gl); createContextMenu(); fViewer.addSelectionChangedListener(event -> { if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) { // Update the filter node properties panel to the selection IStructuredSelection selection = (IStructuredSelection) event.getSelection(); ITmfFilterTreeNode node = (ITmfFilterTreeNode) selection.getFirstElement(); updateFilterNodeComposite(node); } else { updateFilterNodeComposite(null); } }); fViewer.getTree().addPaintListener(e -> { TmfFilterTreeNode root = (TmfFilterTreeNode) fViewer.getInput(); if (root == null || root.getChildrenCount() == 0) { e.gc.setForeground(FOREGROUND_COLOR); e.gc.drawText(Messages.FilterViewer_EmptyTreeHintText, 5, 0); } }); int operations = DND.DROP_MOVE | DND.DROP_COPY; DragSource dragSource = new org.eclipse.swt.dnd.DragSource(fViewer.getTree(), operations); dragSource.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() }); dragSource.addDragListener(new FilterDragSourceAdapter(this)); DropTarget dropTarget = new DropTarget(fViewer.getTree(), operations); dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() }); dropTarget.addDropListener(new FilterDropTargetAdapter(this)); }
Example #28
Source File: TableViewSWT.java From BiglyBT with GNU General Public License v2.0 | 2 votes |
/** * Set a Drop Target and handle its disposal * <br/> * Should be called on {@link TableLifeCycleListener#EVENT_TABLELIFECYCLE_INITIALIZED} event trigger */ DropTarget createDropTarget(int style);