Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
11 changes: 11 additions & 0 deletions features/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>features</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions tests/org.eclipse.ui.tests.dnd/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
34 changes: 34 additions & 0 deletions tests/org.eclipse.ui.tests.dnd/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.ui.tests.dnd</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21
10 changes: 10 additions & 0 deletions tests/org.eclipse.ui.tests.dnd/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Dnd
Bundle-SymbolicName: org.eclipse.ui.tests.dnd
Bundle-Version: 1.0.0.qualifier
Require-Bundle: junit-jupiter-api;bundle-version="5.13.4",
org.eclipse.jface;bundle-version="3.38.0",
org.eclipse.e4.ui.workbench.addons.swt;bundle-version="1.5.800"
Automatic-Module-Name: org.eclipse.ui.tests.dnd
Bundle-RequiredExecutionEnvironment: JavaSE-21
4 changes: 4 additions & 0 deletions tests/org.eclipse.ui.tests.dnd/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.eclipse.ui.tests.dnd;

import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;

public class DataTypeValidator {

public boolean isValidDrop(Widget target, Object data) {
if (target == null || data == null) {
System.out.println("Invalid drop: target or data is null");
return false;
}

if (target instanceof List) {
boolean valid = data instanceof String;
if (!valid) System.out.println("Invalid drop: List can only accept String data");
return valid;
} else if (target instanceof Tree) {
boolean valid = data instanceof String || data instanceof TreeItem;
if (!valid) System.out.println("Invalid drop: Tree can only accept String or TreeItem data");
return valid;
} else if (target instanceof Table) {
boolean valid = data instanceof TableItem;
if (!valid) System.out.println("Invalid drop: Table can only accept TableItem data");
return valid;
}

System.out.println("Invalid drop: Unsupported widget type " + target.getClass().getSimpleName());
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.eclipse.ui.tests.dnd;

import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.widgets.Widget;
import java.util.Arrays;

public class DnDEventFactory {

public DragSourceEvent createDragStartEvent(Widget source, Object... items) {
if (source == null) {
throw new IllegalArgumentException("Source widget cannot be null");
}

DragSourceEvent event = new DragSourceEvent(null);
event.widget = source;
event.data = items != null ? items : new Object[0];
event.detail = 0;

System.out.println("DragStartEvent created for source: " + source
+ " with items: " + Arrays.toString((Object[]) event.data));

return event;
}

public DragSourceEvent createDragSetDataEvent(Widget source, Object data, int operation) {
if (source == null) throw new IllegalArgumentException("Source widget cannot be null");
DragSourceEvent event = new DragSourceEvent(null);
event.widget = source;
event.data = data;
event.detail = operation;

System.out.println("DragSetDataEvent created for source: " + source
+ ", data: " + data + ", operation: " + operation);
return event;
}

public DragSourceEvent createDragFinishedEvent(Widget source, int operation) {
if (source == null) throw new IllegalArgumentException("Source widget cannot be null");
DragSourceEvent event = new DragSourceEvent(null);
event.widget = source;
event.detail = operation;

System.out.println("DragFinishedEvent created for source: " + source
+ ", operation: " + operation);
return event;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package org.eclipse.ui.tests.dnd;

import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swt.widgets.Event;

public class DnDTestHelper {

public void selectItems(Widget widget, Object... items) {
if (items == null || items.length == 0) return;

if (widget instanceof Tree tree) {
for (Object item : items) {
if (item instanceof org.eclipse.swt.widgets.TreeItem) {
tree.setSelection((org.eclipse.swt.widgets.TreeItem) item);
} else {
System.out.println("Invalid item type for Tree: " + item);
}
}
} else if (widget instanceof Table table) {
for (Object item : items) {
if (item instanceof TableItem) {
table.setSelection((TableItem) item);
} else {
System.out.println("Invalid item type for Table: " + item);
}
}
} else if (widget instanceof List list) {
for (Object item : items) {
if (item instanceof String) {
int index = list.indexOf((String) item);
if (index >= 0) {
list.select(index);
} else {
System.out.println("Item not found in List: " + item);
}
} else {
System.out.println("Invalid item type for List: " + item);
}
}
}
}

public void simulateDrag(Widget source, Widget target, int dragType, Object... items) {
if (source == null || target == null || items == null || items.length == 0) {
System.out.println("Invalid drag parameters. Aborting simulation.");
return;
}

Display.getDefault().syncExec(() -> {
System.out.println("=== Starting drag from " + source + " to " + target + " ===");

// --- Drag Detect ---
Event dragDetect = new Event();
dragDetect.widget = source;
source.notifyListeners(SWT.DragDetect, dragDetect);

// --- Drag Set Data ---
Event setData = new Event();
setData.widget = source;
setData.data = items;
source.notifyListeners(DND.DragSetData, setData);

// --- Drag Finished ---
Event dragEnd = new Event();
dragEnd.widget = source;
dragEnd.detail = dragType;
source.notifyListeners(DND.DragEnd, dragEnd);

// --- Drop ---
Event dropEvent = new Event();
dropEvent.widget = target;
dropEvent.data = items;
target.notifyListeners(DND.Drop, dropEvent);

System.out.println("=== Drag simulation finished to " + target + " ===");
});
}

public void runEventLoop() {
Display display = Display.getDefault();
while (display.readAndDispatch()) {
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package org.eclipse.ui.tests.dnd;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.function.BiConsumer;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class DnDTests {

static Display display;
static Shell shell;

@BeforeAll
public static void setupDisplay() {
display = Display.getDefault();
shell = new Shell(display);
}

@AfterAll
public static void disposeDisplay() {
if (shell != null && !shell.isDisposed())
shell.dispose();
}

@Test
public void testSingleItemDragAndDrop() {
display.syncExec(() -> {
List source = new List(shell, SWT.BORDER);
List target = new List(shell, SWT.BORDER);
source.add("Item 1");

DnDTestHelper helper = new DnDTestHelper();
helper.selectItems(source, "Item 1");
helper.simulateDrag(source, target, DND.DROP_COPY, "Item 1");

assertEquals(1, source.getSelectionCount());
assertEquals("Item 1", source.getSelection()[0]);
});
}

@Test
public void testMultiItemDragAcrossWidgets() {
display.syncExec(() -> {
List listSource = new List(shell, SWT.BORDER);
Table tableSource = new Table(shell, SWT.BORDER);
Tree treeSource = new Tree(shell, SWT.BORDER);

List listTarget = new List(shell, SWT.BORDER);
Table tableTarget = new Table(shell, SWT.BORDER);
Tree treeTarget = new Tree(shell, SWT.BORDER);

listSource.add("L1");
listSource.add("L2");

TableItem t1 = new TableItem(tableSource, SWT.NONE);
t1.setText("T1");
TableItem t2 = new TableItem(tableSource, SWT.NONE);
t2.setText("T2");

TreeItem tr1 = new TreeItem(treeSource, SWT.NONE);
tr1.setText("TR1");
TreeItem tr2 = new TreeItem(treeSource, SWT.NONE);
tr2.setText("TR2");

DnDTestHelper helper = new DnDTestHelper();

BiConsumer<Widget, Object[]> assertTargetContent = (target, expectedItems) -> {
if(target instanceof List l) {
assertEquals(expectedItems.length, l.getItemCount());

}
};


});
}

@Test
public void testDropWithInvalidData() {
}

@Test
public void testDropOnDisposedWidget() {
}

@Test
public void testDropOnInvisibleWidget() {
}

@Test
public void testDragOperations() {
}

@Test
public void testCustomDataTransfer() {
}

@Test
public void testEventOrder() {
}

@Test
public void testSelectionClearedAfterDrag() {
}

@Test
public void testDragWithEmptySelection() {
}

}