use of org.eclipse.swt.dnd.Transfer in project cubrid-manager by CUBRID.
the class TableDashboardComposite method copyTablesDetailToClipboard.
public void copyTablesDetailToClipboard() {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
final Clipboard cb = new Clipboard(shell.getDisplay());
StringBuilder sb = new StringBuilder();
List<Integer> selectIndex = new ArrayList<Integer>();
SchemaInfo schema = (SchemaInfo) columnTableView.getInput();
List<DBAttribute> list = schema.getAttributes();
for (int i = 0; i < columnTableView.getTable().getSelectionIndices().length; i++) {
selectIndex.add(columnTableView.getTable().getSelectionIndices()[i]);
}
for (int i = 0; i < selectIndex.size(); i++) {
if (i != 0) {
sb.append(StringUtil.NEWLINE);
}
DBAttribute attr = list.get(i);
sb.append(attr.getName());
}
TextTransfer textTransfer = TextTransfer.getInstance();
Transfer[] transfers = new Transfer[] { textTransfer };
Object[] data = new Object[] { sb.toString() };
cb.setContents(data, transfers);
cb.dispose();
}
use of org.eclipse.swt.dnd.Transfer in project translationstudio8 by heartsome.
the class TableHierarchicalExample method initDND.
/**
* Init a simple drag and drop operation for moving rows in the table.
*
* @param table
* @param parent
*/
private void initDND(final JaretTable table, Composite parent) {
// support move only
int operations = DND.DROP_MOVE;
final DragSource source = new DragSource(table, operations);
// Provide data in Text format
Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
source.setTransfer(types);
source.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
// check whether drag occured on the hierarchy column
IColumn column = table.colForX(event.x);
if (column != null && table.isHierarchyColumn(column)) {
// TODO check whether a resize may have
// higher priority
// possible row drag
IRow row = table.rowForY(event.y);
if (row != null) {
// row hit, start row drag
_draggedRow = row;
// capture the data for internal use
// row drag: use row at starting position
_parentTableNode = getParent(table.getHierarchicalModel().getRootNode(), (ITableNode) row);
} else {
event.doit = false;
}
}
}
public void dragSetData(DragSourceEvent event) {
// Provide the data of the requested type.
if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
if (_draggedRow != null) {
event.data = "row: " + _draggedRow.getId();
}
}
}
public void dragFinished(DragSourceEvent event) {
// for this simple case we do all the manipulations in the drop
// target
// this is more of a hack ...
_draggedRow = null;
}
});
// ////////////////////
// Drop target
// moved to the drop target
operations = DND.DROP_MOVE;
final DropTarget target = new DropTarget(table, operations);
// Receive data in Text
final TextTransfer textTransfer = TextTransfer.getInstance();
types = new Transfer[] { textTransfer };
target.setTransfer(types);
target.addDropListener(new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
}
public void dragOver(DropTargetEvent event) {
if (_draggedRow != null) {
// no drag over effect right now
}
}
public void dragOperationChanged(DropTargetEvent event) {
}
public void dragLeave(DropTargetEvent event) {
}
public void dropAccept(DropTargetEvent event) {
}
public void drop(DropTargetEvent event) {
// this is kind of a hack ...
if (textTransfer.isSupportedType(event.currentDataType)) {
String text = (String) event.data;
System.out.println("DROP: " + text);
if (_draggedRow != null) {
int destY = Display.getCurrent().map(null, table, event.x, event.y).y;
int destX = Display.getCurrent().map(null, table, event.x, event.y).x;
IRow overRow = table.rowForY(destY);
if (overRow != null) {
System.out.println("over row " + overRow.getId());
// this is an action from the drag source listener
// ...
// this has to be done right here because otherwise
// the node would be at two places
// at the same time causing some redraw trouble ...
_parentTableNode.remNode((ITableNode) _draggedRow);
ITableNode node = (ITableNode) overRow;
node.addNode((ITableNode) _draggedRow);
}
}
}
}
});
// Dispose listener on parent of timebar viewer to dispose the
// dragsource and dragtarget BEFORE the timebar
// viewer
// this prevents an exception beeing thrown by SWT
parent.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
source.dispose();
target.dispose();
}
});
}
use of org.eclipse.swt.dnd.Transfer in project translationstudio8 by heartsome.
the class SegmentViewer method copy.
/**
* 执行复制时对标记的处理,复制后在OS系统中不能包含标记占位符 ;
*/
private void copy() {
super.doOperation(ITextOperationTarget.COPY);
TextTransfer plainTextTransfer = TextTransfer.getInstance();
XLiffTextTransfer hsTextTransfer = XLiffTextTransfer.getInstance();
Clipboard clipboard = new Clipboard(getTextWidget().getDisplay());
String plainText = (String) clipboard.getContents(plainTextTransfer);
if (plainText == null || plainText.length() == 0) {
return;
}
plainText = plainText.replaceAll(Utils.getLineSeparator(), "\n");
plainText = plainText.replaceAll(Constants.LINE_SEPARATOR_CHARACTER + "", "");
plainText = plainText.replaceAll(Constants.TAB_CHARACTER + "", "\t");
plainText = plainText.replaceAll(Constants.SPACE_CHARACTER + "", " ");
plainText = plainText.replaceAll("", "");
clipboard.clearContents();
Object[] data = new Object[] { PATTERN.matcher(plainText).replaceAll(""), plainText };
Transfer[] types = new Transfer[] { plainTextTransfer, hsTextTransfer };
clipboard.setContents(data, types, DND.CLIPBOARD);
clipboard.dispose();
}
use of org.eclipse.swt.dnd.Transfer in project translationstudio8 by heartsome.
the class GetActiveKeyDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite tparent = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout();
layout.marginWidth = 10;
layout.marginTop = 10;
tparent.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(tparent);
Composite compNav = new Composite(tparent, SWT.NONE);
GridLayout navLayout = new GridLayout();
compNav.setLayout(navLayout);
createNavigation(compNav);
Group groupActivekey = new Group(tparent, SWT.NONE);
groupActivekey.setText(Messages.getString("license.GetActiveKeyDialog.activekey"));
GridDataFactory.fillDefaults().grab(true, true).applyTo(groupActivekey);
GridLayout layoutGroup = new GridLayout(2, false);
layoutGroup.marginWidth = 5;
layoutGroup.marginHeight = 20;
groupActivekey.setLayout(layoutGroup);
StyledText text = new StyledText(groupActivekey, SWT.WRAP | SWT.READ_ONLY);
text.setBackground(text.getParent().getBackground());
text.setText(Messages.getString("license.GetActiveKeyDialog.activemessage"));
GridData dataText = new GridData();
dataText.horizontalSpan = 2;
dataText.widthHint = 470;
text.setLayoutData(dataText);
int start = Messages.getString("license.GetActiveKeyDialog.activemessage").indexOf(Messages.getString("license.GetActiveKeyDialog.ts"));
int length = Messages.getString("license.GetActiveKeyDialog.ts").length();
StyleRange styleRange = new StyleRange();
styleRange.start = start;
styleRange.length = length;
styleRange.fontStyle = SWT.BOLD;
styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
text.setStyleRange(styleRange);
Label label = new Label(groupActivekey, SWT.WRAP | SWT.NONE);
label.setText(Messages.getString("license.GetActiveKeyDialog.activemessage1"));
GridDataFactory.fillDefaults().span(2, 1).applyTo(label);
textActivekey = new Text(groupActivekey, SWT.MULTI | SWT.WRAP);
textActivekey.setEditable(false);
textActivekey.setText(activekey);
textActivekey.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 150).applyTo(textActivekey);
Button btnCopy = new Button(groupActivekey, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.END).applyTo(btnCopy);
btnCopy.setImage(Activator.getImageDescriptor("images/help/copy.png").createImage());
btnCopy.setToolTipText(Messages.getString("license.GetActiveKeyDialog.copytoclipboard"));
btnCopy.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Clipboard cb = new Clipboard(Display.getCurrent());
String textData = textActivekey.getText();
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
}
});
return tparent;
}
use of org.eclipse.swt.dnd.Transfer in project translationstudio8 by heartsome.
the class GridCopyEnable method copy.
void copy() {
if (focusContent == null || focusContent.equals("")) {
return;
}
if (selection.x != selection.y) {
String plainText = focusContent.substring(selection.x, selection.y);
Object[] data = new Object[] { plainText };
TextTransfer plainTextTransfer = TextTransfer.getInstance();
Transfer[] types = new Transfer[] { plainTextTransfer };
clipboard.setContents(data, types);
}
}
Aggregations