Java Code Examples for org.eclipse.swt.dnd.DragSource#setTransfer()

The following examples show how to use org.eclipse.swt.dnd.DragSource#setTransfer() . 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 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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();
}