use of org.eclipse.swt.dnd.Clipboard in project pentaho-kettle by pentaho.
the class TableView method pasteSelected.
private void pasteSelected() {
int rownr = getCurrentRownr();
if (clipboard != null) {
clipboard.dispose();
clipboard = null;
}
clipboard = new Clipboard(getDisplay());
TextTransfer tran = TextTransfer.getInstance();
String text = (String) clipboard.getContents(tran);
if (text != null) {
String[] lines = text.split(Const.CR);
if (lines.length > 1) {
// ALlocate complete paste grid!
String[][] grid = new String[lines.length - 1][];
int[] idx = new int[lines.length - 1];
for (int i = 1; i < lines.length; i++) {
grid[i - 1] = lines[i].split("\t");
idx[i - 1] = rownr + i;
addItem(idx[i - 1], grid[i - 1]);
}
TransAction ta = new TransAction();
ta.setNew(grid, idx);
addUndo(ta);
}
if (rownr == 0 && table.getItemCount() > rownr + 1) {
if (isEmpty(rownr, -1)) {
table.remove(rownr);
}
}
setRowNums();
unEdit();
setModified();
}
}
use of org.eclipse.swt.dnd.Clipboard in project pentaho-kettle by pentaho.
the class ExpandedContentManager method createExpandedContent.
/**
* createExpandedContent( TransGraph parent )
*
* Create a web browser for the TransGraph argument.
*
* @param parent
* a TransGraph that will be the parent of the web browser.
* @param url
* The content to open and expand
*/
public static void createExpandedContent(TransGraph parent, String url) {
if (parent == null) {
return;
}
Browser browser = getExpandedContentForTransGraph(parent);
if (browser == null) {
browser = new Browser(parent, SWT.NONE);
browser.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
int state = keyEvent.stateMask, key = keyEvent.keyCode;
boolean copyContent = state == SWT.CTRL && key == SWT.F6, arrowNavigation = (state == SWT.COMMAND || state == SWT.ALT) && (key == SWT.ARROW_LEFT || key == SWT.ARROW_RIGHT), backslashNavigation = (state == SWT.SHIFT && key == SWT.BS), reloadContent = state == SWT.CTRL && (key == SWT.F5 || key == 114) || key == SWT.F5, zoomContent = state == SWT.CTRL && (key == SWT.KEYPAD_ADD || key == SWT.KEYPAD_SUBTRACT || key == 61 || /* + key */
key == 45);
if (copyContent) {
Browser thisBrowser = (Browser) keyEvent.getSource();
Clipboard clipboard = new Clipboard(thisBrowser.getDisplay());
clipboard.setContents(new String[] { lastNavigateURL }, new Transfer[] { TextTransfer.getInstance() });
clipboard.dispose();
} else if (arrowNavigation || backslashNavigation || reloadContent || zoomContent) {
keyEvent.doit = false;
}
}
@Override
public void keyReleased(KeyEvent keyEvent) {
}
});
}
browser.setUrl(url);
lastNavigateURL = url;
}
use of org.eclipse.swt.dnd.Clipboard in project dbeaver by dbeaver.
the class UIUtils method setClipboardContents.
public static void setClipboardContents(Display display, Transfer transfer, Object contents) {
Clipboard clipboard = new Clipboard(display);
clipboard.setContents(new Object[] { contents }, new Transfer[] { transfer });
clipboard.dispose();
}
use of org.eclipse.swt.dnd.Clipboard in project dbeaver by dbeaver.
the class BaseChartComposite method doCopyToClipboard.
protected void doCopyToClipboard() {
Image image = new Image(Display.getDefault(), this.getBounds());
GC gc = new GC(image);
try {
this.print(gc);
} finally {
gc.dispose();
}
ImageTransfer imageTransfer = ImageTransfer.getInstance();
Clipboard clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new Object[] { image.getImageData() }, new Transfer[] { imageTransfer });
}
use of org.eclipse.swt.dnd.Clipboard in project dbeaver by dbeaver.
the class NavigatorHandlerObjectCreateCopy method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell activeShell = HandlerUtil.getActiveShell(event);
Control focusControl = activeShell.getDisplay().getFocusControl();
if (focusControl instanceof Text) {
((Text) focusControl).paste();
return null;
} else if (focusControl instanceof StyledText) {
((StyledText) focusControl).paste();
return null;
} else if (focusControl instanceof Combo) {
((Combo) focusControl).paste();
return null;
}
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode curNode = NavigatorUtils.getSelectedNode(selection);
if (curNode != null) {
Clipboard clipboard = new Clipboard(Display.getDefault());
try {
@SuppressWarnings("unchecked") Collection<DBNNode> cbNodes = (Collection<DBNNode>) clipboard.getContents(TreeNodeTransfer.getInstance());
if (cbNodes != null) {
for (DBNNode nodeObject : cbNodes) {
if (nodeObject instanceof DBNDatabaseNode) {
createNewObject(HandlerUtil.getActiveWorkbenchWindow(event), curNode, ((DBNDatabaseNode) nodeObject));
} else if (nodeObject instanceof DBNResource && curNode instanceof DBNResource) {
pasteResource((DBNResource) nodeObject, (DBNResource) curNode);
}
}
} else if (curNode instanceof DBNResource) {
String[] files = (String[]) clipboard.getContents(FileTransfer.getInstance());
if (files != null) {
for (String fileName : files) {
final File file = new File(fileName);
if (file.exists()) {
pasteResource(file, (DBNResource) curNode);
}
}
} else {
log.debug("Paste error: unsupported clipboard format. File or folder were expected.");
Display.getCurrent().beep();
}
} else {
log.debug("Paste error: clipboard contains data in unsupported format");
Display.getCurrent().beep();
}
} finally {
clipboard.dispose();
}
}
return null;
}
Aggregations