use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.
the class ImportResultDialog method copyDataToClipboard.
/**
*
* Copy the selected data to clipboard
*
*/
private void copyDataToClipboard() {
// FIXME move this logic to core module
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(1) + System.getProperty("line.separator"));
}
String data = content.toString();
if (data != null && !data.equals("")) {
clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
}
}
use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.
the class CommonUITool method getClipboard.
/**
* Return clipboard object
*
* @return the Clipboard object
*/
public static Clipboard getClipboard() {
synchronized (CommonUITool.class) {
if (clipboard == null) {
clipboard = new Clipboard(Display.getDefault());
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
clipboard.dispose();
clipboard = null;
}
});
}
return clipboard;
}
}
use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.
the class CommonUITool method getTextContentFromClipboard.
/**
*
* Get text content from clipboard
*
* @return the string from clipboard
*/
public static String getTextContentFromClipboard() {
Clipboard clipboard = CommonUITool.getClipboard();
TextTransfer textTransfer = TextTransfer.getInstance();
Object obj = clipboard.getContents(textTransfer);
if (obj == null) {
return "";
} else {
return (String) obj;
}
}
use of org.eclipse.swt.dnd.Clipboard in project dbeaver by serge-rider.
the class ResultSetUtils method getAttributeValueFromClipboard.
@Nullable
public static Object getAttributeValueFromClipboard(DBDAttributeBinding attribute) throws DBCException {
DBPDataSource dataSource = attribute.getDataSource();
Clipboard clipboard = new Clipboard(Display.getCurrent());
try (DBCSession session = DBUtils.openUtilSession(VoidProgressMonitor.INSTANCE, dataSource, "Copy from clipboard")) {
String strValue = (String) clipboard.getContents(TextTransfer.getInstance());
return attribute.getValueHandler().getValueFromObject(session, attribute.getAttribute(), strValue, true);
} finally {
clipboard.dispose();
}
}
use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.
the class CopyAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
Control control = getFocusProvider();
if (control instanceof StyledText) {
StyledText stext = (StyledText) control;
String data = stext.getSelectionText();
if (data != null && !data.equals("")) {
clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
FocusAction.changeActionStatus(pasteAction, stext);
}
} else {
/*Copy from the active editor*/
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IEditorPart editor = window.getActivePage().getActiveEditor();
if (editor != null && editor instanceof ICopiableFromTable) {
ICopiableFromTable copyAbleEditor = (ICopiableFromTable) editor;
copyAbleEditor.copySelectedItems();
}
}
}
}
Aggregations