use of org.eclipse.swt.dnd.TextTransfer in project tdi-studio-se by Talend.
the class CopyCellAction method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
try {
Clipboard clipBoard = new Clipboard(Display.getCurrent());
TextTransfer textTransfer = TextTransfer.getInstance();
TableItem[] items = ptable.getSelection();
if (items == null || items.length == 0) {
return;
}
int columnIndex = pcursor.getColumn();
clipBoard.setContents(new Object[] { items[0].getText(columnIndex) }, new Transfer[] { textTransfer });
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(org.talend.sqlbuilder.Messages.getString("CopyCellAction.logMessage"), e);
}
}
use of org.eclipse.swt.dnd.TextTransfer in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method initializeDND.
/**
* Initializes drag and drop the template items
*/
private void initializeDND() {
DragSourceAdapter dragListener = new DragSourceAdapter() {
@Override
public void dragStart(DragSourceEvent event) {
if (getSelectedTemplates().length == 0) {
event.doit = false;
}
}
@Override
public void dragSetData(DragSourceEvent event) {
if (TemplatesTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = getSelectedTemplates();
}
}
};
fTreeViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { TemplatesTransfer.getInstance() }, dragListener);
DropTargetAdapter dropListener = new DropTargetAdapter() {
Transfer textTransfer = TextTransfer.getInstance();
Transfer templateTransfer = TemplatesTransfer.getInstance();
@Override
public void dragEnter(DropTargetEvent event) {
if (event.detail == DND.DROP_DEFAULT)
event.detail = DND.DROP_COPY;
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
if (event.detail == DND.DROP_DEFAULT)
event.detail = DND.DROP_COPY;
}
@Override
public void dragOver(DropTargetEvent event) {
event.feedback |= DND.FEEDBACK_SCROLL;
if (event.item == null) {
event.detail = DND.DROP_NONE;
return;
}
int index = 0;
boolean isTemplateTransfer = false;
while (index < event.dataTypes.length) {
if (textTransfer.isSupportedType(event.dataTypes[index])) {
break;
}
if (templateTransfer.isSupportedType(event.dataTypes[index])) {
isTemplateTransfer = true;
break;
}
index++;
}
if (index < event.dataTypes.length) {
event.currentDataType = event.dataTypes[index];
if (event.detail == DND.DROP_DEFAULT || !isTemplateTransfer)
event.detail = DND.DROP_COPY;
return;
}
}
@Override
public void drop(DropTargetEvent event) {
if (event.item == null)
return;
Object object = ((TreeItem) event.item).getData();
final String contextId;
if (object instanceof TemplateContextType)
contextId = ((TemplateContextType) object).getId();
else
contextId = ((TemplatePersistenceData) object).getTemplate().getContextTypeId();
if (textTransfer.isSupportedType(event.currentDataType)) {
// $NON-NLS-1$ //$NON-NLS-2$
String text = ((String) event.data).replaceAll("\\$", "\\$\\$");
final Template template = new Template(createTemplateName(), TemplatesMessages.TemplatesPage_paste_description, contextId, text, true);
getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
addTemplate(template);
}
});
return;
}
if (templateTransfer.isSupportedType(event.currentDataType)) {
final TemplatePersistenceData[] templates = (TemplatePersistenceData[]) event.data;
final int dropType = event.detail;
getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (dropType == DND.DROP_COPY)
copyTemplates(templates, contextId);
else
moveTemplates(templates, contextId);
}
});
}
}
};
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance(), TemplatesTransfer.getInstance() };
fTreeViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, dropListener);
}
use of org.eclipse.swt.dnd.TextTransfer in project linuxtools by eclipse.
the class PrepareCommitHandler method populateClipboardBuffer.
private void populateClipboardBuffer(String input) {
TextTransfer plainTextTransfer = TextTransfer.getInstance();
Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
clipboard.setContents(new String[] { input }, new Transfer[] { plainTextTransfer });
clipboard.dispose();
}
use of org.eclipse.swt.dnd.TextTransfer in project cubrid-manager by CUBRID.
the class CopyNodeAction method run.
public void run() {
Object[] selectedObjs = this.getSelectedObj();
if (selectedObjs == null || selectedObjs.length == 0) {
return;
}
StringBuilder names = new StringBuilder();
for (Object obj : selectedObjs) {
if (!(obj instanceof ICubridNode)) {
continue;
}
ICubridNode cubridNode = (ICubridNode) obj;
String type = cubridNode.getType();
if (names.length() > 0) {
names.append(",");
}
if (type.equals(NodeType.TABLE_COLUMN)) {
TableColumn tc = (TableColumn) cubridNode.getAdapter(TableColumn.class);
names.append(tc.getColumnName());
} else {
names.append(cubridNode.getLabel());
}
}
if (names.length() > 0) {
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
clipboard.setContents(new Object[] { names.toString() }, new Transfer[] { textTransfer });
}
}
use of org.eclipse.swt.dnd.TextTransfer in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_StyledText method test_cut.
@Test
public void test_cut() {
if (SwtTestUtil.isCocoa) {
// TODO Fix Cocoa failure.
if (SwtTestUtil.verbose) {
System.out.println("Excluded test_cut(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_custom_StyledText).");
}
return;
}
Clipboard clipboard = new Clipboard(text.getDisplay());
TextTransfer transfer = TextTransfer.getInstance();
String clipboardText;
String convertedText;
String before = (String) clipboard.getContents(transfer);
text.setSelectionRange(0, 0);
text.cut();
clipboardText = (String) clipboard.getContents(transfer);
assertTrue(":a:", before == null ? clipboardText == null : before.equals(clipboardText));
before = (String) clipboard.getContents(transfer);
text.setText("0123456789");
text.setSelectionRange(0, 0);
text.cut();
clipboardText = (String) clipboard.getContents(transfer);
assertTrue(":c:", before == null ? clipboardText == null : before.equals(clipboardText));
text.setSelectionRange(0, 1);
text.cut();
clipboardText = (String) clipboard.getContents(transfer);
assertTrue(":d:", clipboardText != null && clipboardText.equals("0"));
text.setSelectionRange(1, 2);
text.cut();
clipboardText = (String) clipboard.getContents(transfer);
assertTrue(":e:", clipboardText != null && clipboardText.equals("23"));
// test line delimiter conversion
text.setText("\rLine1\nLine2\r\nLine3\n\rLine4\n");
text.setSelectionRange(0, text.getCharCount());
text.cut();
clipboardText = (String) clipboard.getContents(transfer);
if (SwtTestUtil.isWindowsOS) {
convertedText = "\r\nLine1\r\nLine2\r\nLine3\r\n\r\nLine4\r\n";
} else {
convertedText = "\nLine1\nLine2\nLine3\n\nLine4\n";
}
assertTrue(":f:", clipboardText != null && clipboardText.equals(convertedText));
// test line delimiter conversion
text.setText("Line1\r\nLine2");
text.setSelectionRange(0, text.getCharCount());
text.cut();
clipboardText = (String) clipboard.getContents(transfer);
if (SwtTestUtil.isWindowsOS) {
convertedText = "Line1\r\nLine2";
} else {
convertedText = "Line1\nLine2";
}
assertTrue(":g:", clipboardText != null && clipboardText.equals(convertedText));
clipboard.dispose();
}
Aggregations