org.eclipse.swt.dnd.DragSourceAdapter Java Examples
The following examples show how to use
org.eclipse.swt.dnd.DragSourceAdapter.
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: View.java From codeexamples-eclipse with Eclipse Public License 1.0 | 5 votes |
private void addDragListener(Control control) { LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); DragSourceAdapter dragAdapter = new DragSourceAdapter() { @Override public void dragSetData(DragSourceEvent event) { transfer.setSelection(new StructuredSelection(control)); } }; DragSource dragSource = new DragSource(control, DND.DROP_MOVE | DND.DROP_COPY); dragSource.setTransfer(new Transfer[] { transfer }); dragSource.addDragListener(dragAdapter); }
Example #2
Source File: ThemePreferencePage.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
private void createButton(final Table table, final TableItem tableItem, final int index, final RGBa color) { TableEditor editor = new TableEditor(table); Button button = new Button(table, SWT.PUSH | SWT.FLAT); Image image = createColorImage(table, color); button.setImage(image); button.pack(); editor.minimumWidth = button.getSize().x - 4; editor.horizontalAlignment = SWT.CENTER; editor.setEditor(button, tableItem, index); fTableEditors.add(editor); button.setData("color", color); //$NON-NLS-1$ button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ColorDialog colorDialog = new ColorDialog(table.getShell()); Button self = ((Button) e.widget); RGBa theColor = (RGBa) self.getData("color"); //$NON-NLS-1$ if (theColor == null) { theColor = color; } colorDialog.setRGB(theColor.toRGB()); RGB newRGB = colorDialog.open(); if (newRGB == null) { return; } ThemeRule token = (ThemeRule) tableItem.getData(); RGBa newColor = new RGBa(newRGB); if (index == 1) { getTheme().updateRule(table.indexOf(tableItem), token.updateFG(newColor)); } else { getTheme().updateRule(table.indexOf(tableItem), token.updateBG(newColor)); } // Update the image for this button! self.setImage(createColorImage(table, newColor)); self.setData("color", newColor); //$NON-NLS-1$ tableViewer.refresh(); } }); // Allow dragging the button out of it's location to remove the fg/bg for the rule! Transfer[] types = new Transfer[] { TextTransfer.getInstance() }; final DragSource source = new DragSource(button, DND.DROP_MOVE); source.setTransfer(types); source.addDragListener(new DragSourceAdapter() { public void dragSetData(DragSourceEvent event) { event.data = "button:" + table.indexOf(tableItem) + ":" + index; //$NON-NLS-1$ //$NON-NLS-2$ } }); }