use of org.eclipse.swt.dnd.Transfer in project tdi-studio-se by Talend.
the class AbstractElementPropertySectionController method addDragAndDropTarget.
/**
* Accept Text and StyledText control.
*
* @param labelText
*/
public void addDragAndDropTarget(final Control textControl) {
DropTargetListener dropTargetListener = new DropTargetListener() {
String propertyName = null;
@Override
public void dragEnter(final DropTargetEvent event) {
}
@Override
public void dragLeave(final DropTargetEvent event) {
}
@Override
public void dragOperationChanged(final DropTargetEvent event) {
}
@Override
public void dragOver(final DropTargetEvent event) {
if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
propertyName = getParameterName(textControl);
for (int i = 0; i < elem.getElementParameters().size(); i++) {
IElementParameter param = elem.getElementParameters().get(i);
if (param.getName().equals(propertyName)) {
if (param.isReadOnly()) {
event.detail = DND.ERROR_INVALID_DATA;
}
}
}
}
}
@Override
public void drop(final DropTargetEvent event) {
if (propertyName != null) {
String text;
if (textControl instanceof StyledText) {
text = ((StyledText) textControl).getText() + (String) event.data;
((StyledText) textControl).setText(text);
} else {
text = ((Text) textControl).getText() + (String) event.data;
((Text) textControl).setText(text);
}
Command cmd = new PropertyChangeCommand(elem, propertyName, text);
// getCommandStack().execute(cmd);
executeCommand(cmd);
}
}
@Override
public void dropAccept(final DropTargetEvent event) {
}
};
DropTarget target = new DropTarget(textControl, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
target.setTransfer(transfers);
target.addDropListener(dropTargetListener);
}
use of org.eclipse.swt.dnd.Transfer in project tdi-studio-se by Talend.
the class CopyAction method run.
/*
* @see Action#run()
*/
@Override
public void run() {
if (textData == null || textData.length() == 0) {
return;
}
Clipboard clipboard = new Clipboard(Display.getDefault());
if (filesData.size() > 0) {
Object[] clipboardData = new Object[] { filesData.toArray(new String[0]), textData };
Transfer[] clipboardDataTypes = new Transfer[] { FileTransfer.getInstance(), TextTransfer.getInstance() };
clipboard.setContents(clipboardData, clipboardDataTypes);
} else {
clipboard.setContents(new Object[] { textData }, new Transfer[] { TextTransfer.getInstance() });
}
}
use of org.eclipse.swt.dnd.Transfer in project cubrid-manager by CUBRID.
the class CubridNavigatorView method addDragDropSupport.
/**
* Add the drag drop support of tree.
*
* @param tree the tree need to drag and drop.
*/
protected void addDragDropSupport(final Tree tree) {
// Define 'Transfer Type', 'Operation'
Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
int operations = DND.DROP_MOVE | DND.DROP_COPY;
// DragSource
final DragSource source = new DragSource(tree, operations);
source.setTransfer(types);
source.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
event.doit = false;
if (!dataSupportDND(tree.getSelection())) {
return;
}
event.doit = true;
}
public void dragSetData(DragSourceEvent event) {
event.data = ((ICubridNode) tree.getSelection()[0].getData()).getLabel();
}
public void dragFinished(DragSourceEvent event) {
}
});
addTreeDropTarget(tree);
String perspectiveId = PerspectiveManager.getInstance().getCurrentPerspectiveId();
// DropTarget for query editor.
QueryEditorDNDController.registerDragSource(perspectiveId, tv);
// DropTarget for multiple query
MultiDBQueryDNDController.registerDragSource(perspectiveId, tv);
// DropTarget for Run SQL file
RunSQLFileDialogDNDController.registerDragSource(perspectiveId, tv);
//DropTarget for ERD
ERDNDController.registerDragSource(perspectiveId, tv);
}
use of org.eclipse.swt.dnd.Transfer in project cubrid-manager by CUBRID.
the class ParamDumpResultDialog method createDialogArea.
/**
* @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
* @param parent The parent composite to contain the dialog area
* @return the dialog area control
*/
protected Control createDialogArea(Composite parent) {
Composite parentComp = (Composite) super.createDialogArea(parent);
Composite composite = new Composite(parentComp, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
layout.numColumns = 5;
composite.setLayout(layout);
//dynamicHelp end
createdbNameGroup(composite);
table = new Table(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
table.setHeaderVisible(true);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.horizontalSpan = 7;
gridData.verticalSpan = 10;
gridData.heightHint = 300;
table.setLayoutData(gridData);
table.setLinesVisible(true);
CommonUITool.hackForYosemite(table);
/*
* // fill in context menu
*/
Menu menu = new Menu(parent.getShell(), SWT.POP_UP);
table.setMenu(menu);
MenuItem copy = new MenuItem(menu, SWT.PUSH);
copy.setText(Messages.bind(com.cubrid.cubridmanager.ui.logs.Messages.contextCopy, "Ctrl+C"));
copy.setAccelerator(SWT.CTRL + 'C');
copy.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
StringBuilder content = new StringBuilder();
TableItem[] items = table.getSelection();
for (int i = 0; i < items.length; i++) {
content.append(items[i].getText(0) + blank + items[i].getText(1) + blank + items[i].getText(2) + blank + System.getProperty("line.separator"));
}
String data = content.toString();
if (data != null && !data.equals("")) {
clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
}
}
});
table.addKeyListener(new org.eclipse.swt.events.KeyAdapter() {
public void keyPressed(org.eclipse.swt.events.KeyEvent event) {
if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0 && event.keyCode == 'c') {
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
StringBuilder content = new StringBuilder();
TableItem[] items = table.getSelection();
for (int i = 0; i < items.length; i++) {
content.append(items[i].getText(0) + blank + items[i].getText(1) + blank + items[i].getText(2) + blank + System.getProperty("line.separator"));
}
String data = content.toString();
if (data != null && !data.equals("")) {
clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
}
}
}
});
setTitle(Messages.titleParamDumpDialog);
setMessage(Messages.msgParamDumpDialog);
initial();
return parentComp;
}
use of org.eclipse.swt.dnd.Transfer in project cubrid-manager by CUBRID.
the class ColumnViewerSorter method copyNamesToClipboard.
public void copyNamesToClipboard(List<String> nameList) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
final Clipboard cb = new Clipboard(shell.getDisplay());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < nameList.size(); i++) {
if (i != 0) {
sb.append(StringUtil.NEWLINE);
}
sb.append(nameList.get(i));
}
TextTransfer textTransfer = TextTransfer.getInstance();
Transfer[] transfers = new Transfer[] { textTransfer };
Object[] data = new Object[] { sb.toString() };
cb.setContents(data, transfers);
cb.dispose();
}
Aggregations