use of org.eclipse.swt.dnd.Clipboard in project dbeaver by dbeaver.
the class ResultSetUtils method copyToClipboard.
public static void copyToClipboard(String string) {
if (string != null && string.length() > 0) {
Clipboard clipboard = new Clipboard(Display.getCurrent());
try {
TextTransfer textTransfer = TextTransfer.getInstance();
clipboard.setContents(new Object[] { string }, new Transfer[] { textTransfer });
} finally {
clipboard.dispose();
}
}
}
use of org.eclipse.swt.dnd.Clipboard in project erlide_eclipse by erlang.
the class ClipboardAction method run.
@Override
public void run() {
final Clipboard cb = new Clipboard(display);
final TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { text }, new TextTransfer[] { textTransfer });
}
use of org.eclipse.swt.dnd.Clipboard in project archi by archimatetool.
the class StatusDialog method copyToClipboard.
private void copyToClipboard() {
Clipboard clipboard = null;
try {
clipboard = new Clipboard(getShell().getDisplay());
clipboard.setContents(new Object[] { textControl.getText() }, new Transfer[] { TextTransfer.getInstance() });
} finally {
if (clipboard != null) {
clipboard.dispose();
}
}
}
use of org.eclipse.swt.dnd.Clipboard in project xtext-eclipse by eclipse.
the class TraceEditor method createPageContainer.
@Override
protected Composite createPageContainer(final Composite parent) {
Composite tree = new Composite(parent, SWT.NONE);
final Sash sash = new Sash(parent, SWT.HORIZONTAL);
text = new StyledText(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
text.setFont(JFaceResources.getTextFont());
final FormLayout form = new FormLayout();
parent.setLayout(form);
FormData treeData = new FormData();
treeData.left = new FormAttachment(0, 0);
treeData.right = new FormAttachment(100, 0);
treeData.top = new FormAttachment(0, 0);
treeData.bottom = new FormAttachment(sash, 0);
tree.setLayoutData(treeData);
final int limit = 20, percent = 50;
final FormData sashData = new FormData();
sashData.left = new FormAttachment(0, 0);
sashData.top = new FormAttachment(percent, 0);
sashData.right = new FormAttachment(100, 0);
sash.setLayoutData(sashData);
sash.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
Rectangle sashRect = sash.getBounds();
Rectangle parentRect = parent.getClientArea();
int bottom = parentRect.height - sashRect.height - limit;
e.y = Math.max(Math.min(e.y, bottom), limit);
if (e.y != sashRect.y) {
sashData.top = new FormAttachment(0, e.y);
parent.layout();
}
}
});
FormData textData = new FormData();
textData.left = new FormAttachment(0, 0);
textData.right = new FormAttachment(100, 0);
textData.top = new FormAttachment(sash, 0);
textData.bottom = new FormAttachment(100, 0);
text.setLayoutData(textData);
addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
try {
Object x = ((IStructuredSelection) selection).getFirstElement();
if (x instanceof EObject)
updateText((EObject) x);
if (x instanceof Resource)
updateText(((Resource) x).getContents().get(0));
} catch (Exception e) {
text.setText(Throwables.getStackTraceAsString(e));
}
}
}
});
Menu contextMenu = new Menu(text);
MenuItem copyItem = new MenuItem(contextMenu, SWT.PUSH);
copyItem.setText("&Copy");
copyItem.setAccelerator(SWT.MOD1 | 'C');
copyItem.setEnabled(false);
final Clipboard cb = new Clipboard(Display.getDefault());
copyItem.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
String textData = text.getSelectionText();
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
text.setMenu(contextMenu);
text.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
final String selectionText = text.getSelectionText();
copyItem.setEnabled(!"".equals(selectionText));
final Point range = text.getSelectionRange();
TraceEditor.super.setSelection(new ITextSelection() {
@Override
public boolean isEmpty() {
return "".equals(selectionText);
}
@Override
public String getText() {
return selectionText;
}
@Override
public int getStartLine() {
return -1;
}
@Override
public int getOffset() {
return range.x;
}
@Override
public int getLength() {
return range.y;
}
@Override
public int getEndLine() {
return -1;
}
});
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
return tree;
}
use of org.eclipse.swt.dnd.Clipboard in project archi by archimatetool.
the class StyledTextControl method fillContextMenu.
/**
* Fill context menu when user right-clicks
* @param manager
*/
private void fillContextMenu(IMenuManager manager) {
int textLength = fStyledText.getText().length();
boolean hasText = textLength > 0;
boolean hasSelectedText = fStyledText.getSelectionText().length() > 0;
// Cut
fActionCut.setEnabled(hasSelectedText);
manager.add(fActionCut);
// Copy
fActionCopy.setEnabled(hasSelectedText);
manager.add(fActionCopy);
// Paste
Clipboard cb = new Clipboard(null);
Object content = cb.getContents(TextTransfer.getInstance());
cb.dispose();
fActionPaste.setEnabled(content != null);
manager.add(fActionPaste);
// Delete
fActionDelete.setEnabled(hasSelectedText);
manager.add(fActionDelete);
// Select All
manager.add(new Separator());
fActionSelectAll.setEnabled(hasText);
manager.add(fActionSelectAll);
}
Aggregations