/******************************************************************************* * Copyright (c) 2021 Syntevo and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * * Contributors: * Syntevo - initial API and implementation *******************************************************************************/ package org.eclipse.swt.tests.manual; import org.eclipse.swt.*; import org.eclipse.swt.dnd.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public final class Bug577878_GTK_TreeTable_NoDragImageWithPaintItem { public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout (new GridLayout (1, true)); Label hint = new Label(shell, 0); hint.setText ( "1) Run on GTK\n" + "2) Drag rows from regular Table/Tree - there will be a drag image\n" + "3) Bug 577878: Table/Tree with SWT.PaintItem do not have drag image\n" ); Composite composite = new Composite (shell, 0); composite.setLayout (new GridLayout (2, true)); DragSourceListener listener = new DragSourceListener () { @Override public void dragStart(DragSourceEvent event) { } @Override public void dragSetData(DragSourceEvent event) { } @Override public void dragFinished(DragSourceEvent event) { } }; new Label(composite, 0).setText ("Table"); new Label(composite, 0).setText ("Table+PaintItem"); // Table { Table control = new Table (composite, SWT.BORDER); new TableItem (control, 0).setText ("Item#1"); new TableItem (control, 0).setText ("Item#2"); DragSource dragSource = new DragSource (control, DND.DROP_MOVE | DND.DROP_COPY); dragSource.setTransfer (TextTransfer.getInstance ()); dragSource.addDragListener (listener); } // Table with SWT.PaintItem { Table control = new Table (composite, SWT.BORDER); new TableItem (control, 0); new TableItem (control, 0); control.addListener (SWT.MeasureItem, e -> { e.width = 100; e.height = 20; }); control.addListener (SWT.PaintItem, e -> { TableItem item = (TableItem)e.item; String text = "Item#" + item.getParent ().indexOf (item); e.gc.drawString (text, e.x, e.y, true); }); DragSource dragSource = new DragSource (control, DND.DROP_MOVE | DND.DROP_COPY); dragSource.setTransfer (TextTransfer.getInstance ()); dragSource.addDragListener (listener); } new Label(composite, 0).setText ("Tree"); new Label(composite, 0).setText ("Tree+PaintItem"); // Tree { Tree control = new Tree (composite, SWT.BORDER); new TreeItem (control, 0).setText ("Item#1"); new TreeItem (control, 0).setText ("Item#2"); DragSource dragSource = new DragSource (control, DND.DROP_MOVE | DND.DROP_COPY); dragSource.setTransfer (TextTransfer.getInstance ()); dragSource.addDragListener (listener); } // Tree with SWT.PaintItem { Tree control = new Tree (composite, SWT.BORDER); new TreeItem (control, 0); new TreeItem (control, 0); control.addListener (SWT.MeasureItem, e -> { e.width = 100; e.height = 20; }); control.addListener (SWT.PaintItem, e -> { TreeItem item = (TreeItem)e.item; String text = "Item#" + item.getParent ().indexOf (item); e.gc.drawString (text, e.x, e.y, true); }); DragSource dragSource = new DragSource (control, DND.DROP_MOVE | DND.DROP_COPY); dragSource.setTransfer (TextTransfer.getInstance ()); dragSource.addDragListener (listener); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }