use of org.eclipse.swt.dnd.Clipboard in project xtext-eclipse by eclipse.
the class ClipboardUtil method clipboardOperation.
/**
* Applies the passed function to the default {@link Clipboard}
*
* @param function
* operation to perform
*/
public static <T> T clipboardOperation(Function<Clipboard, T> function) {
Clipboard clipboard = null;
T contents;
try {
Display display = SWTUtil.getStandardDisplay();
clipboard = new Clipboard(display);
contents = function.apply(clipboard);
} finally {
if (clipboard != null) {
clipboard.dispose();
}
}
return contents;
}
use of org.eclipse.swt.dnd.Clipboard in project translationstudio8 by heartsome.
the class SegmentViewer method parse.
/**
* 执行粘贴前对标记的处理 ;
*/
private void parse() {
Clipboard clipboard = null;
try {
if (getTextWidget().isDisposed()) {
return;
}
clipboard = new Clipboard(getTextWidget().getDisplay());
XLiffTextTransfer hsTextTransfer = XLiffTextTransfer.getInstance();
String hsText = (String) clipboard.getContents(hsTextTransfer);
String osText = (String) clipboard.getContents(TextTransfer.getInstance());
if (hsText == null || hsText.length() == 0) {
if (osText == null || osText.length() == 0) {
return;
}
super.doOperation(ITextOperationTarget.PASTE);
return;
}
String clearedTagText = hsText;
String selText = getTextWidget().getSelectionText();
if (selText.equals(hsText)) {
return;
}
if (getTextWidget().getSelectionCount() != getTextWidget().getText().length()) {
// 过滤掉系统剪切板中的标记。
clearedTagText = filterInnerTag(hsText);
} else {
StringBuffer bf = new StringBuffer(hsText);
Matcher matcher = PATTERN.matcher(hsText);
List<String> needRemove = new ArrayList<String>();
while (matcher.find()) {
String placeHolder = matcher.group();
InnerTag tag = InnerTagUtil.getInnerTag(innerTagCacheList, placeHolder);
if (tag == null) {
needRemove.add(placeHolder);
}
}
clearedTagText = bf.toString();
for (String r : needRemove) {
clearedTagText = clearedTagText.replaceAll(r, "");
}
}
if (clearedTagText == null || clearedTagText.length() == 0) {
return;
}
if (clearedTagText.equals(osText)) {
super.doOperation(ITextOperationTarget.PASTE);
return;
}
Object[] data = new Object[] { clearedTagText, hsText };
Transfer[] types = new Transfer[] { TextTransfer.getInstance(), hsTextTransfer };
try {
clipboard.setContents(data, types);
} catch (Exception e) {
e.printStackTrace();
}
super.doOperation(ITextOperationTarget.PASTE);
data = new Object[] { osText, hsText };
try {
clipboard.setContents(data, types);
} catch (Exception e) {
e.printStackTrace();
}
} finally {
if (clipboard != null && !clipboard.isDisposed()) {
clipboard.dispose();
}
}
}
use of org.eclipse.swt.dnd.Clipboard in project cogtool by cogtool.
the class WindowsImageTransfer method main.
public static void main(String[] args) throws Exception {
Display display = new Display();
Shell shell = new Shell(display);
Clipboard c = new Clipboard(display);
System.out.println("types on the clipboard: " + Arrays.asList(c.getAvailableTypeNames()));
Object o = c.getContents(WindowsImageTransfer.getInstance());
ImageData d = (ImageData) o;
if (d == null) {
System.out.println("no image found on clipboard. try hitting the printscreen key, or using MS Paint to put an image on the clipboard.");
return;
}
//Change what's on the clipboard to show we can also put images on the
// clipboard.
c.setContents(new Object[] { "howdy" }, new Transfer[] { TextTransfer.getInstance() });
System.out.println("types on the clipboard: " + Arrays.asList(c.getAvailableTypeNames()));
//now put the ImageData back onto the clipboard.
c.setContents(new Object[] { d }, new Transfer[] { WindowsImageTransfer.getInstance() });
System.out.println("types on the clipboard: " + Arrays.asList(c.getAvailableTypeNames()));
//now read the CF_DIB (ImageData) back off the clipboard.
// and display it by using it as the image for the button.
ImageData imgData = (ImageData) c.getContents(WindowsImageTransfer.getInstance());
Image img = new Image(display, imgData);
Button button = new Button(shell, SWT.NONE);
button.setImage(img);
shell.pack();
button.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
button.dispose();
}
use of org.eclipse.swt.dnd.Clipboard in project translationstudio8 by heartsome.
the class DefaultCCPStrategy method paste.
/**
* Paste pastes textual context starting at the focussed cell (does not use the selection by now). Uses TAB and
* semicolon as delimiters (Excel uses TAB, semicolon for pasting csv).
*
* @param table the jaret table
*/
public void paste(JaretTable table) {
Clipboard cb = getClipboard();
TextTransfer textTransfer = TextTransfer.getInstance();
Object content = cb.getContents(textTransfer);
if (content != null) {
if (content instanceof String) {
String string = (String) content;
List<String> lines = new ArrayList<String>();
StringTokenizer tokenizer = new StringTokenizer(string, "\n");
while (tokenizer.hasMoreTokens()) {
lines.add(tokenizer.nextToken());
}
Point focus = table.getFocussedCellIdx();
if (focus == null) {
table.setFocus();
focus = table.getFocussedCellIdx();
}
int lineOff = 0;
for (String line : lines) {
tokenizer = new StringTokenizer(line, PASTE_DELIMITERS, true);
int colOff = 0;
String last = null;
while (tokenizer.hasMoreTokens()) {
String value = tokenizer.nextToken();
boolean ignore = false;
if (PASTE_DELIMITERS.indexOf(value) != -1) {
// delimiter
if (last != null && last.equals(value)) {
value = "";
} else {
ignore = true;
}
}
if (!ignore) {
try {
table.setValue(focus.x + colOff, focus.y + lineOff, value);
} catch (Exception e) {
// silently ignore -- this can happen
}
colOff++;
}
last = value;
}
lineOff++;
}
}
}
}
use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.
the class TableSchemaCompareInfoPart method copyTableAlterDDL.
/**
* copyTableLeftAlterDDL
*/
private void copyTableAlterDDL(CubridDatabase leftDB, CubridDatabase rightDB, boolean leftToRight) {
// FIXME logic code move to core module
StringBuffer clipboardDataString = new StringBuffer();
TableItem[] tableItems = tablesSchemaCompareTable.getTable().getSelection();
String title = "";
String msg = "";
for (int i = 0; i < tableItems.length; i++) {
if (i > 0) {
clipboardDataString.append(StringUtil.NEWLINE);
clipboardDataString.append(StringUtil.NEWLINE);
}
TableSchemaCompareModel compareModel = (TableSchemaCompareModel) tableItems[i].getData();
TableSchema leftTableSchema = (TableSchema) compareModel.getLeft();
TableSchema rightTableSchema = (TableSchema) compareModel.getRight();
String tableCompare = leftTableSchema.getName();
if (StringUtil.isEmpty(leftTableSchema.getName())) {
tableCompare = rightTableSchema.getName();
}
String alterDDL = null;
if (compareModel.getCompareStatus() != TableSchemaCompareModel.SCHEMA_EQUAL && compareModel.getCompareStatus() != TableSchemaCompareModel.RECORDS_DIFF) {
Map<String, SchemaInfo> sourceSchemas = compareModel.getSourceSchemas();
Map<String, SchemaInfo> targetSchemas = compareModel.getTargetSchemas();
SchemaInfo sourceTableSchemaInfo = null;
SchemaInfo targetTableSchemaInfo = null;
if (leftToRight) {
sourceTableSchemaInfo = sourceSchemas.get(tableCompare);
targetTableSchemaInfo = targetSchemas.get(tableCompare);
} else {
targetTableSchemaInfo = sourceSchemas.get(tableCompare);
sourceTableSchemaInfo = targetSchemas.get(tableCompare);
}
alterDDL = tableComp.getTableAlterScript(leftDB, rightDB, tableCompare, sourceTableSchemaInfo, targetTableSchemaInfo);
if (StringUtil.isNotEmpty(alterDDL)) {
clipboardDataString.append(alterDDL.trim());
}
}
}
Clipboard clipboard = CommonUITool.getClipboard();
if (clipboardDataString.length() != 0) {
if ("--NotSupportAlterAutoIncrement".equals(clipboardDataString.toString())) {
title = Messages.compareStatusTip;
msg = Messages.alterAutoIncrementNotSupport;
} else {
TextTransfer textTransfer = TextTransfer.getInstance();
Transfer[] transfers = new Transfer[] { textTransfer };
Object[] data = new Object[] { clipboardDataString.toString() };
clipboard.setContents(data, transfers);
title = Messages.alterScript;
msg = Messages.tableSchemaAlterCopyMessage;
}
} else {
clipboard.clearContents();
title = Messages.emptyAlterScript;
msg = Messages.schemaIdenticalMessage;
}
CommonUITool.openInformationBox(title, msg);
}
Aggregations