use of org.eclipse.swt.dnd.Clipboard in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_StyledText method test_copy.
@Test
public void test_copy() {
if (SwtTestUtil.isCocoa) {
// TODO Fix Cocoa failure.
if (SwtTestUtil.verbose) {
System.out.println("Excluded test_copy(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.copy();
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.copy();
clipboardText = (String) clipboard.getContents(transfer);
assertTrue(":c:", before == null ? clipboardText == null : before.equals(clipboardText));
text.setSelectionRange(0, 1);
text.copy();
clipboardText = (String) clipboard.getContents(transfer);
assertTrue(":d:", clipboardText != null && clipboardText.equals("0"));
text.setSelectionRange(1, 2);
text.copy();
clipboardText = (String) clipboard.getContents(transfer);
assertTrue(":e:", clipboardText != null && clipboardText.equals("12"));
// test line delimiter conversion
text.setText("\rLine1\nLine2\r\nLine3\n\rLine4\n");
text.setSelectionRange(0, text.getCharCount());
text.copy();
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.copy();
clipboardText = (String) clipboard.getContents(transfer);
if (SwtTestUtil.isWindowsOS) {
convertedText = "Line1\r\nLine2";
} else {
convertedText = "Line1\nLine2";
}
assertTrue(":g:", clipboardText != null && clipboardText.equals(convertedText));
rtfCopy();
clipboard.dispose();
}
use of org.eclipse.swt.dnd.Clipboard in project yamcs-studio by yamcs.
the class CopyCommandHistoryEntryDetailsHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
if (sel != null && sel instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) sel;
String property = event.getParameter(CommandHistory.CMDPARAM_EVENT_PROPERTY);
StringBuilder text = new StringBuilder();
Iterator<?> it = selection.iterator();
while (it.hasNext()) {
CommandHistoryRecord rec = (CommandHistoryRecord) it.next();
switch(property) {
case PARAM_GENTIME:
text.append(rec.getGenerationTime());
break;
case PARAM_COMMAND:
text.append(rec.getCommandString());
break;
case PARAM_SOURCE:
text.append(rec.getUsername() + "@" + rec.getOrigin());
break;
case PARAM_SEQNO:
text.append(rec.getSequenceNumber());
break;
default:
throw new IllegalStateException("Unexpected property: " + property);
}
if (it.hasNext()) {
text.append("\n");
}
}
Display display = Display.getCurrent();
Clipboard clipboard = new Clipboard(display);
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
clipboard.setContents(new Object[] { text.toString() }, transfers);
clipboard.dispose();
}
return null;
}
use of org.eclipse.swt.dnd.Clipboard in project yamcs-studio by yamcs.
the class CopyCommandHistoryEntryHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
if (sel != null && sel instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) sel;
StringBuilder text = new StringBuilder("T\tCommand\tSource\tSequence Number\n");
List<CommandHistoryRecord> recList = new ArrayList<>();
Iterator<?> it = selection.iterator();
while (it.hasNext()) {
CommandHistoryRecord rec = (CommandHistoryRecord) it.next();
recList.add(rec);
text.append(rec.getGenerationTime()).append("\t").append(rec.getCommandString()).append("\t").append(rec.getUsername() + "@" + rec.getOrigin()).append("\t").append(rec.getSequenceNumber()).append("\n");
}
if (!recList.isEmpty()) {
CommandClipboard.addCommandHistoryRecords(recList);
}
Display display = Display.getCurrent();
Clipboard clipboard = new Clipboard(display);
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
clipboard.setContents(new Object[] { text.toString() }, transfers);
clipboard.dispose();
}
return null;
}
use of org.eclipse.swt.dnd.Clipboard in project yamcs-studio by yamcs.
the class CommandClipboard method textToClipboard.
private static void textToClipboard(String text, Display display) {
final Clipboard cb = new Clipboard(display);
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { text }, new Transfer[] { textTransfer });
}
use of org.eclipse.swt.dnd.Clipboard in project yamcs-studio by yamcs.
the class RuntimePatchedSelectionTool method handleButtonDown.
/**
* Intercept middle clicks and copy PV name to pastebuffer if available.
* Change cursor to copy symbol.
*/
@Override
protected boolean handleButtonDown(int button) {
if (button == 2) {
EditPart editPart = getTargetEditPart();
if (editPart instanceof AbstractPVWidgetEditPart) {
AbstractPVWidgetEditPart apvwep = (AbstractPVWidgetEditPart) editPart;
String pvName = ((AbstractPVWidgetModel) editPart.getModel()).getPVName();
if (pvName != "" && pvName != null) {
Display display = Display.getCurrent();
Clipboard clipboard = new Clipboard(display);
// Copies to middle button paste buffer,
// to be pasted via another middle-button click
clipboard.setContents(new Object[] { pvName }, new Transfer[] { TextTransfer.getInstance() }, DND.SELECTION_CLIPBOARD);
// Copies to normal clipboard,
// to be pasted via Ctrl-V or Edit/Paste
clipboard.setContents(new String[] { pvName }, new Transfer[] { TextTransfer.getInstance() });
clipboard.dispose();
IFigure figure = apvwep.getFigure();
oldCursor = figure.getCursor();
figure.setCursor(ResourceUtil.getCopyPvCursor());
cursorChanged = true;
}
}
return true;
} else {
return super.handleButtonDown(button);
}
}
Aggregations