use of org.eclipse.swt.dnd.DropTarget in project tdq-studio-se by Talend.
the class ExpressionEditDialog method addDropVariableListenerToText.
/**
* add Drop Variable Listener To Text.
*
* @param text
*/
public void addDropVariableListenerToText(final Text text) {
DropTarget dt = new DropTarget(text, DND.DROP_MOVE);
dt.setTransfer(new Transfer[] { TextTransfer.getInstance() });
dt.addDropListener(new DropTargetAdapter() {
@Override
public void drop(DropTargetEvent event) {
String head, end;
Text editText = text;
head = editText.getText().substring(0, editText.getSelection().x);
end = editText.getText().substring(editText.getSelection().x + editText.getSelectionCount());
editText.setText(head + (String) event.data + end);
editText.setFocus();
}
});
}
use of org.eclipse.swt.dnd.DropTarget in project tdq-studio-se by Talend.
the class ColumnViewerDND method installDND.
/**
* DOC xqliu Comment method "installDND". bug 8791 2009-08-31.
*
* @param myTable
*/
public static void installDND(final Table targetControl) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
final CommonViewer commonViewer = findView.getCommonViewer();
final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
int operations = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { transfer };
DropTarget dropTarget = new DropTarget(targetControl, operations);
dropTarget.setTransfer(transfers);
DropTargetListener dndListener = new TableDropTargetEffect(targetControl) {
ISelectionReceiver receiver = null;
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
Object object = selection.getFirstElement();
// MOD klliu 2011-03-08 bug 19286
if (object instanceof DBColumnRepNode) {
receiver = new ColumnReceiverTable();
}
if (receiver == null) {
event.detail = DND.DROP_NONE;
} else {
event.feedback = DND.FEEDBACK_EXPAND;
receiver.doDropValidation(event, commonViewer);
}
}
@Override
public void dragOver(DropTargetEvent event) {
if (receiver == null) {
return;
}
super.dragOver(event);
receiver.doDropValidation(event, commonViewer);
}
@Override
public void drop(DropTargetEvent event) {
if (receiver == null) {
return;
}
int index = targetControl.getItemCount();
super.drop(event);
if (event.item == null) {
index = -1;
} else {
// Widget widget = event.widget;
// Object data = event.data;
TableItem item = (TableItem) event.item;
TableItem[] items = targetControl.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
index = i;
break;
}
}
}
receiver.drop(event, commonViewer, index);
}
};
dropTarget.addDropListener(dndListener);
}
use of org.eclipse.swt.dnd.DropTarget in project tdq-studio-se by Talend.
the class TableViewerDND method installDND.
/**
* DOC xqliu Comment method "installDND".
*
* @param targetControl
*/
public static void installDND(final Tree targetControl) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
final CommonViewer commonViewer = findView.getCommonViewer();
final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
int operations = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { transfer };
DropTarget dropTarget = new DropTarget(targetControl, operations);
dropTarget.setTransfer(transfers);
DropTargetListener dndListener = new TreeDropTargetEffect(targetControl) {
ISelectionReceiver receiver = null;
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
Object object = selection.getFirstElement();
if (object instanceof RuleRepNode) {
receiver = new DQRuleReceiver();
}
if (object instanceof NamedColumnSet) {
receiver = new TableReceiver();
}
if (object instanceof DBTableRepNode) {
receiver = new TableReceiver();
}
if (object instanceof DBViewRepNode) {
receiver = new TableReceiver();
}
if (receiver == null) {
event.detail = DND.DROP_NONE;
} else {
event.feedback = DND.FEEDBACK_EXPAND;
receiver.doDropValidation(event, commonViewer);
}
}
@Override
public void dragOver(DropTargetEvent event) {
super.dragOver(event);
if (receiver != null) {
receiver.doDropValidation(event, commonViewer);
}
}
@Override
public void drop(DropTargetEvent event) {
int index = targetControl.getItemCount();
super.drop(event);
if (event.item == null) {
// TreeItem item = new TreeItem(targetControl, SWT.NONE);
// item.setText(texts);
// item.setText(text);
} else {
TreeItem item = (TreeItem) event.item;
TreeItem[] items = targetControl.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
index = i;
break;
}
}
}
if (receiver != null) {
receiver.drop(event, commonViewer, index);
}
}
};
dropTarget.addDropListener(dndListener);
}
use of org.eclipse.swt.dnd.DropTarget in project tdq-studio-se by Talend.
the class ComparisonTableViewerDNDDecorate method installDND.
/**
* Install a drag&drop function for target table viewer.
*
* @param targetViewer the target table viewer for installing drag&drop, it's input value must a <code>List</code>
* type.
* @param installDragListener decide to whether install a drag listener for targetViewer: if true, will install the
* listener; else, will not install.
* @param validateType
* @see ComparisonTableViewerDNDDecorate#NON_VALIDATETYPE
* @see ComparisonTableViewerDNDDecorate#COLUMN_VALIDATETYPE
*/
public void installDND(final TableViewer targetViewer, final boolean installDragListener, final int validateType, final boolean isLeftPart) {
int operations = DND.DROP_COPY | DND.DROP_MOVE;
if (installDragListener) {
installDragListener(targetViewer, operations);
}
DropTarget dropTarget = new DropTarget(targetViewer.getTable(), operations);
dropTarget.setTransfer(transferTypes);
DropTargetListener dndListener = new AbstractSelectionReceiver(targetViewer.getTable(), null) {
@Override
@SuppressWarnings("unchecked")
public void drop(DropTargetEvent event, LocalSelectionTransfer transfer) {
List inputElements = (List) targetViewer.getInput();
// MOD mzhao bug:12766,Avoid an null pointer exception error.
if (inputElements == null) {
inputElements = new ArrayList();
}
if (dragSelectedElement != null) {
TableItem item = (TableItem) event.item;
TableItem[] items = targetViewer.getTable().getItems();
int index = 0;
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
index = i;
break;
}
}
inputElements.remove(dragSelectedElement);
inputElements.add(index, dragSelectedElement);
dragSelectedElement = null;
} else {
StructuredSelection selection = (StructuredSelection) transfer.getSelection();
List selectionElements = selection.toList();
inputElements.addAll(selectionElements);
}
targetViewer.setInput(inputElements);
// Update connection widget.
compareTreeViewer.updateBindConnection(masterPage, tableViewerPosStack);
compareTreeViewer.setDirty(true);
// TDQ-11606 msjian: when add a column, will update the datapreview part
compareTreeViewer.computeRefreshDataPreviewPart(isLeftPart, inputElements, targetViewer);
}
@Override
public boolean doDropValidation(DropTargetEvent event, LocalSelectionTransfer transfer) {
StructuredSelection selection = (StructuredSelection) transfer.getSelection();
if (dragSelectedElement != null && selection != null) {
return true;
}
// boolean doDropValidation = super.doDropValidation(event, transfer);
boolean doDropValidation = false;
// if (doDropValidation) {
switch(validateType) {
case COLUMN_VALIDATETYPE:
doDropValidation = validateColumnType(selection, targetViewer);
break;
default:
doDropValidation = true;
}
// }
return doDropValidation;
}
};
dropTarget.addDropListener(dndListener);
}
use of org.eclipse.swt.dnd.DropTarget in project pentaho-kettle by pentaho.
the class RipDatabaseWizardPage2 method createControl.
public void createControl(Composite parent) {
shell = parent.getShell();
int margin = Const.MARGIN;
// create the composite to hold the widgets
Composite composite = new Composite(parent, SWT.NONE);
props.setLook(composite);
FormLayout compLayout = new FormLayout();
compLayout.marginHeight = Const.FORM_MARGIN;
compLayout.marginWidth = Const.FORM_MARGIN;
composite.setLayout(compLayout);
// Put it all on the composite!
// //////////////////////////////////////////////////
// Top & Bottom regions.
// //////////////////////////////////////////////////
Composite top = new Composite(composite, SWT.NONE);
FormLayout topLayout = new FormLayout();
topLayout.marginHeight = margin;
topLayout.marginWidth = margin;
top.setLayout(topLayout);
FormData fdTop = new FormData();
fdTop.left = new FormAttachment(0, 0);
fdTop.top = new FormAttachment(0, 0);
fdTop.right = new FormAttachment(100, 0);
fdTop.bottom = new FormAttachment(100, -50);
top.setLayoutData(fdTop);
props.setLook(top);
Composite bottom = new Composite(composite, SWT.NONE);
bottom.setLayout(new FormLayout());
FormData fdBottom = new FormData();
fdBottom.left = new FormAttachment(0, 0);
fdBottom.top = new FormAttachment(top, 0);
fdBottom.right = new FormAttachment(100, 0);
fdBottom.bottom = new FormAttachment(100, 0);
bottom.setLayoutData(fdBottom);
props.setLook(bottom);
// //////////////////////////////////////////////////
// Sashform
// //////////////////////////////////////////////////
SashForm sashform = new SashForm(top, SWT.HORIZONTAL);
sashform.setLayout(new FormLayout());
FormData fdSashform = new FormData();
fdSashform.left = new FormAttachment(0, 0);
fdSashform.top = new FormAttachment(0, 0);
fdSashform.right = new FormAttachment(100, 0);
fdSashform.bottom = new FormAttachment(100, 0);
sashform.setLayoutData(fdSashform);
// ////////////////////////
// / LEFT
// ////////////////////////
Composite leftsplit = new Composite(sashform, SWT.NONE);
leftsplit.setLayout(new FormLayout());
FormData fdLeftsplit = new FormData();
fdLeftsplit.left = new FormAttachment(0, 0);
fdLeftsplit.top = new FormAttachment(0, 0);
fdLeftsplit.right = new FormAttachment(100, 0);
fdLeftsplit.bottom = new FormAttachment(100, 0);
leftsplit.setLayoutData(fdLeftsplit);
props.setLook(leftsplit);
// Source list to the left...
wlListSource = new Label(leftsplit, SWT.NONE);
wlListSource.setText("Available items:");
props.setLook(wlListSource);
FormData fdlListSource = new FormData();
fdlListSource.left = new FormAttachment(0, 0);
fdlListSource.top = new FormAttachment(0, 0);
wlListSource.setLayoutData(fdlListSource);
wListSource = new List(leftsplit, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
props.setLook(wListSource);
FormData fdListSource = new FormData();
fdListSource.left = new FormAttachment(0, 0);
fdListSource.top = new FormAttachment(wlListSource, 0);
fdListSource.right = new FormAttachment(100, 0);
fdListSource.bottom = new FormAttachment(100, 0);
wListSource.setLayoutData(fdListSource);
// /////////////////////////
// MIDDLE
// /////////////////////////
Composite compmiddle = new Composite(sashform, SWT.NONE);
compmiddle.setLayout(new FormLayout());
FormData fdCompMiddle = new FormData();
fdCompMiddle.left = new FormAttachment(0, 0);
fdCompMiddle.top = new FormAttachment(0, 0);
fdCompMiddle.right = new FormAttachment(100, 0);
fdCompMiddle.bottom = new FormAttachment(100, 0);
compmiddle.setLayoutData(fdCompMiddle);
props.setLook(compmiddle);
wAddOne = new Button(compmiddle, SWT.PUSH);
wAddOne.setText(" > ");
wAddOne.setToolTipText("Add the selected items on the left.");
wAddAll = new Button(compmiddle, SWT.PUSH);
wAddAll.setText(" >> ");
wAddAll.setToolTipText("Add all items on the left.");
wRemoveOne = new Button(compmiddle, SWT.PUSH);
wRemoveOne.setText(" < ");
wRemoveOne.setToolTipText("Remove the selected items on the right.");
wRemoveAll = new Button(compmiddle, SWT.PUSH);
wRemoveAll.setText(" << ");
wRemoveAll.setToolTipText("Add all items on the right.");
FormData fdAddOne = new FormData();
fdAddOne.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
fdAddOne.top = new FormAttachment(30, 0);
wAddOne.setLayoutData(fdAddOne);
FormData fdAddAll = new FormData();
fdAddAll.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
fdAddAll.top = new FormAttachment(wAddOne, margin);
wAddAll.setLayoutData(fdAddAll);
FormData fdRemoveAll = new FormData();
fdRemoveAll.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
fdRemoveAll.top = new FormAttachment(wAddAll, margin);
wRemoveAll.setLayoutData(fdRemoveAll);
FormData fdRemoveOne = new FormData();
fdRemoveOne.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
fdRemoveOne.top = new FormAttachment(wRemoveAll, margin);
wRemoveOne.setLayoutData(fdRemoveOne);
// ///////////////////////////////
// RIGHT
// ///////////////////////////////
Composite rightsplit = new Composite(sashform, SWT.NONE);
rightsplit.setLayout(new FormLayout());
FormData fdRightsplit = new FormData();
fdRightsplit.left = new FormAttachment(0, 0);
fdRightsplit.top = new FormAttachment(0, 0);
fdRightsplit.right = new FormAttachment(100, 0);
fdRightsplit.bottom = new FormAttachment(100, 0);
rightsplit.setLayoutData(fdRightsplit);
props.setLook(rightsplit);
wlListDest = new Label(rightsplit, SWT.NONE);
wlListDest.setText("Your selection:");
props.setLook(wlListDest);
FormData fdlListDest = new FormData();
fdlListDest.left = new FormAttachment(0, 0);
fdlListDest.top = new FormAttachment(0, 0);
wlListDest.setLayoutData(fdlListDest);
wListDest = new List(rightsplit, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
props.setLook(wListDest);
FormData fdListDest = new FormData();
fdListDest.left = new FormAttachment(0, 0);
fdListDest.top = new FormAttachment(wlListDest, 0);
fdListDest.right = new FormAttachment(100, 0);
fdListDest.bottom = new FormAttachment(100, 0);
wListDest.setLayoutData(fdListDest);
sashform.setWeights(new int[] { 45, 10, 45 });
// Drag & Drop for steps
Transfer[] ttypes = new Transfer[] { TextTransfer.getInstance() };
DragSource ddSource = new DragSource(wListSource, DND.DROP_MOVE | DND.DROP_COPY);
ddSource.setTransfer(ttypes);
ddSource.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
}
public void dragSetData(DragSourceEvent event) {
String[] ti = wListSource.getSelection();
String data = new String();
for (int i = 0; i < ti.length; i++) {
data += ti[i] + Const.CR;
}
event.data = data;
}
public void dragFinished(DragSourceEvent event) {
}
});
DropTarget ddTarget = new DropTarget(wListDest, DND.DROP_MOVE | DND.DROP_COPY);
ddTarget.setTransfer(ttypes);
ddTarget.addDropListener(new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
}
public void dragLeave(DropTargetEvent event) {
}
public void dragOperationChanged(DropTargetEvent event) {
}
public void dragOver(DropTargetEvent event) {
}
public void drop(DropTargetEvent event) {
if (event.data == null) {
// no data to copy, indicate failure in event.detail
event.detail = DND.DROP_NONE;
return;
}
StringTokenizer strtok = new StringTokenizer((String) event.data, Const.CR);
while (strtok.hasMoreTokens()) {
String source = strtok.nextToken();
addToDestination(source);
}
}
public void dropAccept(DropTargetEvent event) {
}
});
wListSource.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.CR) {
addToSelection(wListSource.getSelection());
}
}
});
wListDest.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.CR) {
delFromSelection(wListDest.getSelection());
}
}
});
// Double click adds to destination.
wListSource.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
addToSelection(wListSource.getSelection());
}
});
// Double click adds to source
wListDest.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
String[] sel = wListDest.getSelection();
delFromSelection(sel);
}
});
wAddOne.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
addToSelection(wListSource.getSelection());
}
});
wRemoveOne.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
delFromSelection(wListDest.getSelection());
}
});
wAddAll.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
addAllToSelection();
}
});
wRemoveAll.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
removeAllFromSelection();
}
});
// set the composite as the control for this page
setControl(composite);
}
Aggregations