gibts eine möglichkeit per drag and drop eigene object zu kopieren?
das ganze natürlich in swt... :roll:
mfg matthias
das ganze natürlich in swt... :roll:
mfg matthias
public class DNDtest {
private Table table;
protected Shell shell;
public static void main(String[] args) {
try {
DNDtest window = new DNDtest();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display;
display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
protected void createContents() {
TableColumn tableColumn;
shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
final Label lblSource = new Label(shell, SWT.NONE);
lblSource.setText("von hier");
lblSource.setBounds(110, 105, 120, 30);
Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
int operations = DND.DROP_MOVE | DND.DROP_COPY;
DragSource source = new DragSource (lblSource, operations);
source.setTransfer(types);
table = new Table(shell, SWT.BORDER);
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setBounds(65, 190, 158, 138);
DragSource source2 = new DragSource (table, operations);
source2.setTransfer(types);
tableColumn = new TableColumn(table, SWT.NONE);
tableColumn.setWidth(100);
tableColumn.setText("New column");
TableItem pickerItem = new TableItem(table, SWT.LEFT);
pickerItem.setText(0, "hallo");
final Text lblTarget;
lblTarget = new Text(shell, SWT.NONE);
lblTarget.setText("nach hier");
lblTarget.setBounds(369, 223, 120, 30);
DropTarget target = new DropTarget(lblTarget, operations);
target.setTransfer(types);
source.addDragListener (new DragSourceAdapter() {
public void dragStart(DragSourceEvent event) {
if (lblSource.getText().length() == 0) {
event.doit = false;
}
};
public void dragSetData (DragSourceEvent event) {
if
(TextTransfer.getInstance().isSupportedType(event.dataType)){
event.data = lblSource.getText();
}
}
public void dragFinished(DragSourceEvent event) {
if (event.detail == DND.DROP_MOVE)
lblSource.setText("");
}
});
source2.addDragListener (new DragSourceAdapter() {
public void dragStart(DragSourceEvent event) {}
public void dragSetData (DragSourceEvent event) {
System.out.println(table.getItem(table.getSelectionIndex()));
if
(TextTransfer.getInstance().isSupportedType(event.dataType)){
event.data = table.getItem(table.getSelectionIndex()).getText();
}
}
public void dragFinished(DragSourceEvent event) {}
});
target.addDropListener (new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
if (event.data == null) {
event.detail = DND.DROP_NONE;
return;
}
lblTarget.setText ((String) event.data);
}
});
}
}
private void drag() {
Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
int operations = DND.DROP_COPY;
DragSource source = new DragSource(table_search, operations);
source.setTransfer(types);
source.addDragListener (new DragSourceAdapter() {
public void dragStart(DragSourceEvent event) {
System.out.println(table_search.getItem(table_search.getSelectionIndex()));};
public void dragSetData (DragSourceEvent event) {
if(TextTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = table_search.getItem(table_search.getSelectionIndex()).getText(1);
}
}
public void dragFinished(DragSourceEvent event) {}
});
}
private void drop() {
Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
int operations = DND.DROP_COPY;
DropTarget target = new DropTarget(txt_name, operations);
target.setTransfer(types);
target.addDropListener (new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
if (event.data == null) {
event.detail = DND.DROP_NONE;
System.out.println("leer");
return;
}
txt_name.setText((String) event.data);
}
});
}
public class DNDtest {
private Table table;
protected Shell shell;
private Label lblSource;
private Text lblTarget;
private TableColumn tableColumn;
public static void main(String[] args) {
try {
DNDtest window = new DNDtest();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display;
display = Display.getDefault();
createContents();
drag();
drop();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
lblSource = new Label(shell, SWT.NONE);
lblSource.setText("von hier");
lblSource.setBounds(110, 105, 120, 30);
table = new Table(shell, SWT.BORDER);
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setBounds(65, 190, 158, 138);
tableColumn = new TableColumn(table, SWT.NONE);
tableColumn.setWidth(100);
tableColumn.setText("New column");
TableItem pickerItem = new TableItem(table, SWT.LEFT);
pickerItem.setText(0, "hallo");
lblTarget = new Text(shell, SWT.NONE);
lblTarget.setText("nach hier");
lblTarget.setBounds(369, 223, 120, 30);
}
private void drag() {
Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
int operations = DND.DROP_MOVE | DND.DROP_COPY;
DragSource source = new DragSource (lblSource, operations);
source.setTransfer(types);
DragSource source2 = new DragSource (table, operations);
source2.setTransfer(types);
source.addDragListener (new DragSourceAdapter() {
public void dragStart(DragSourceEvent event) {
if (lblSource.getText().length() == 0) {
event.doit = false;
}
};
public void dragSetData (DragSourceEvent event) {
if
(TextTransfer.getInstance().isSupportedType(event.dataType)){
event.data = lblSource.getText();
}
}
public void dragFinished(DragSourceEvent event) {
if (event.detail == DND.DROP_MOVE)
lblSource.setText("");
}
});
source2.addDragListener (new DragSourceAdapter() {
public void dragStart(DragSourceEvent event) {}
public void dragSetData (DragSourceEvent event) {
System.out.println(table.getItem(table.getSelectionIndex()));
if
(TextTransfer.getInstance().isSupportedType(event.dataType)){
event.data = table.getItem(table.getSelectionIndex()).getText();
}
}
public void dragFinished(DragSourceEvent event) {}
});
}
private void drop() {
Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
int operations = DND.DROP_MOVE | DND.DROP_COPY;
DropTarget target = new DropTarget(lblTarget, operations);
target.setTransfer(types);
target.addDropListener (new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
if (event.data == null) {
event.detail = DND.DROP_NONE;
return;
}
lblTarget.setText ((String) event.data);
}
});
}