org.eclipse.swt.dnd.DragSource Java Examples

The following examples show how to use org.eclipse.swt.dnd.DragSource. 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 xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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: GamlEditorDragAndDropHandler.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
protected void uninstall() {
	if (getViewer() == null || !fIsTextDragAndDropInstalled) { return; }

	final IDragAndDropService dndService = editor.getSite().getService(IDragAndDropService.class);
	if (dndService == null) { return; }

	final StyledText st = getStyledText();
	dndService.removeMergedDropTarget(st);

	final DragSource dragSource = (DragSource) st.getData(DND.DRAG_SOURCE_KEY);
	if (dragSource != null) {
		dragSource.dispose();
		st.setData(DND.DRAG_SOURCE_KEY, null);
	}

	fIsTextDragAndDropInstalled = false;
}
 
Example #3
Source File: SWTUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #4
Source File: SWTUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #5
Source File: SWTUtil.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #6
Source File: IdentifiableDragSource.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void setup(){
	DragSource mine = new DragSource(viewer.getControl(), DND.DROP_COPY);
	mine.setTransfer(new Transfer[] {
		myTransfer
	});
	mine.addDragListener(this);
}
 
Example #7
Source File: GenericObjectDragSource.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void setup(){
	DragSource mine = new DragSource(dragSource, DND.DROP_COPY);
	mine.setTransfer(new Transfer[] {
		myTransfer
	});
	mine.addDragListener(this);
}
 
Example #8
Source File: PersistentObjectDragSource.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void setup(){
	DragSource mine = new DragSource(dragSource, DND.DROP_COPY);
	mine.setTransfer(new Transfer[] {
		myTransfer
	});
	mine.addDragListener(this);
}
 
Example #9
Source File: ScriptConsoleViewer.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
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 #10
Source File: CubeGroupContent.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void createDataField( )
{
	Composite dataField = new Composite( this, SWT.NONE );
	dataField.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	dataField.setLayout( new GridLayout( ) );

	Label dataLabel = new Label( dataField, SWT.NONE );
	dataLabel.setText( Messages.getString( "GroupsPage.Label.DataField" ) ); //$NON-NLS-1$
	dataFieldsViewer = new TreeViewer( dataField, SWT.SINGLE
			| SWT.H_SCROLL
			| SWT.V_SCROLL
			| SWT.BORDER );
	cubeLabelProvider = getCubeLabelProvider( );
	cubeLabelProvider.setProivderViewer( true );
	dataFieldsViewer.setLabelProvider( cubeLabelProvider );
	dataFieldsViewer.setContentProvider( dataContentProvider );
	dataFieldsViewer.setAutoExpandLevel( 3 );
	GridData gd = new GridData( GridData.FILL_BOTH );
	dataFieldsViewer.getTree( ).setLayoutData( gd );
	( (GridData) dataFieldsViewer.getTree( ).getLayoutData( ) ).heightHint = 250;
	( (GridData) dataFieldsViewer.getTree( ).getLayoutData( ) ).widthHint = 200;
	dataFieldsViewer.addSelectionChangedListener( new ISelectionChangedListener( ) {

		public void selectionChanged( SelectionChangedEvent event )
		{
			updateButtons( );
		}

	} );

	final DragSource fieldsSource = new DragSource( dataFieldsViewer.getTree( ),
			operations );
	fieldsSource.setTransfer( types );
	fieldsSource.addDragListener( new CustomDragListener( dataFieldsViewer ) );

}
 
Example #11
Source File: CustomPreviewTable.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void addDragListenerToHeaderButton( Button button )
{
	DragSource ds = new DragSource( button, DND.DROP_COPY );
	ds.setTransfer( new Transfer[]{
		SimpleTextTransfer.getInstance( )
	} );
	CustomPreviewTableDragListener dragSourceAdapter = new CustomPreviewTableDragListener( this,
			button.getText( ) );
	ds.addDragListener( dragSourceAdapter );
}
 
Example #12
Source File: View.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
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 #13
Source File: PhotoShuffler.java    From codeexamples-eclipse with Eclipse Public License 1.0 4 votes vote down vote up
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 #14
Source File: ThemePreferencePage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
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$
		}
	});
}
 
Example #15
Source File: FilterViewer.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
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 #16
Source File: PhotoShuffler.java    From codeexamples-eclipse with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * @param parentComposite - the composite that holds all pictures
 * @param source - the drag source
 * 
 */
public MyDragSourceListener(Composite parentComposite, DragSource source) {
	this.parentComposite = parentComposite;
	this.source = source;
}
 
Example #17
Source File: TableViewSWT.java    From BiglyBT with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set a Drag Source and handle its disposal.
 * <br/>
 * Should be called on {@link TableLifeCycleListener#EVENT_TABLELIFECYCLE_INITIALIZED} event trigger
 */
DragSource createDragSource(int style);