use of org.eclipse.swt.dnd.TextTransfer in project cubrid-manager by CUBRID.
the class CommonUITool method copyContentToClipboard.
/**
* Copy the data to clipboard
*
* @param data String
*/
public static void copyContentToClipboard(String data) {
if (data == null || data.trim().length() == 0) {
return;
}
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
if (clipboard != null) {
clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
}
}
use of org.eclipse.swt.dnd.TextTransfer in project cubrid-manager by CUBRID.
the class CommonUITool method copyContentToClipboard.
/**
* Copy the styled text conent to clipboard
*
* @param text the StyledText object
*/
public static void copyContentToClipboard(StyledText text) {
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
String data = text.getSelectionText();
if (data == null || data.trim().length() == 0) {
data = text.getText();
}
if (data != null && !data.equals("")) {
clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
}
}
use of org.eclipse.swt.dnd.TextTransfer in project translationstudio8 by heartsome.
the class DefaultCCPStrategy method cutOrCopy.
/**
* Do the actual copy or cut operation.
*
* @param table table
* @param cut if set to true cells we be emptied
*/
protected void cutOrCopy(JaretTable table, boolean cut) {
IJaretTableSelection selection = table.getSelectionModel().getSelection();
Clipboard cb = getClipboard();
if (!selection.isEmpty()) {
Set<IJaretTableCell> cells = selection.getAllSelectedCells(table.getTableModel());
int minx = -1;
int maxx = -1;
int miny = -1;
int maxy = -1;
// line is the outer map
Map<Integer, Map<Integer, IJaretTableCell>> cellMap = new HashMap<Integer, Map<Integer, IJaretTableCell>>();
for (IJaretTableCell cell : cells) {
Point p = table.getCellDisplayIdx(cell);
Map<Integer, IJaretTableCell> lineMap = cellMap.get(p.y);
if (lineMap == null) {
lineMap = new HashMap<Integer, IJaretTableCell>();
cellMap.put(p.y, lineMap);
}
if (miny == -1 || p.y < miny) {
miny = p.y;
}
if (maxy == -1 || p.y > maxy) {
maxy = p.y;
}
lineMap.put(p.x, cell);
if (minx == -1 || p.x < minx) {
minx = p.x;
}
if (maxx == -1 || p.x > maxx) {
maxx = p.x;
}
}
StringBuilder buf = new StringBuilder();
if (_includeHeadersInCopy) {
for (int x = minx; x <= maxx; x++) {
String headerLabel = table.getColumn(x).getHeaderLabel();
buf.append(headerLabel);
buf.append(COPY_DELIMITER);
}
buf.append("\n");
}
for (int y = miny; y <= maxy; y++) {
Map<Integer, IJaretTableCell> lineMap = cellMap.get(y);
// empty lines are ommitted
if (lineMap != null) {
for (int x = minx; x <= maxx; x++) {
IJaretTableCell cell = lineMap.get(x);
String value = null;
if (cell != null) {
Object val = cell.getColumn().getValue(cell.getRow());
value = val != null ? val.toString() : null;
if (cut) {
emptyCell(cell);
}
}
if (value != null) {
buf.append(value);
}
buf.append(COPY_DELIMITER);
}
buf.append("\n");
}
}
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { buf.toString() }, new Transfer[] { textTransfer });
}
}
use of org.eclipse.swt.dnd.TextTransfer 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.TextTransfer in project translationstudio8 by heartsome.
the class TableControlPanel method createControls.
/**
* @param panel
*/
private void createControls() {
RowLayout rl = new RowLayout();
rl.type = SWT.HORIZONTAL;
this.setLayout(rl);
Composite col1 = new Composite(this, SWT.NULL);
rl = new RowLayout();
rl.type = SWT.VERTICAL;
col1.setLayout(rl);
Composite col2 = new Composite(this, SWT.NULL);
rl = new RowLayout();
rl.type = SWT.VERTICAL;
col2.setLayout(rl);
Composite col3 = new Composite(this, SWT.NULL);
rl = new RowLayout();
rl.type = SWT.VERTICAL;
col3.setLayout(rl);
final Button autoFilterCheck = new Button(col1, SWT.CHECK);
autoFilterCheck.setText("AutoFilter");
autoFilterCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setAutoFilterEnable(autoFilterCheck.getSelection());
}
});
final Button drawHeaderCheck = new Button(col1, SWT.CHECK);
drawHeaderCheck.setSelection(_table.getDrawHeader());
drawHeaderCheck.setText("Draw header");
drawHeaderCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setDrawHeader(drawHeaderCheck.getSelection());
}
});
final Button fillDragCheck = new Button(col1, SWT.CHECK);
fillDragCheck.setSelection(_table.isSupportFillDragging());
fillDragCheck.setText("Support fill dragging");
fillDragCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setSupportFillDragging(fillDragCheck.getSelection());
}
});
Button b = new Button(col2, SWT.PUSH);
b.setText("Print");
b.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
print();
}
});
final Scale headerRotationScale = new Scale(col2, SWT.HORIZONTAL);
headerRotationScale.setMaximum(90);
headerRotationScale.setMinimum(0);
headerRotationScale.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent ev) {
int val = headerRotationScale.getSelection();
((DefaultTableHeaderRenderer) _table.getHeaderRenderer()).setRotation(val);
if (val > 0) {
_table.setHeaderHeight(50);
} else {
_table.setHeaderHeight(18);
}
_table.redraw();
}
});
final Button allowHeaderResizeCheck = new Button(col1, SWT.CHECK);
allowHeaderResizeCheck.setSelection(_table.getDrawHeader());
allowHeaderResizeCheck.setText("Allow header resize");
allowHeaderResizeCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setHeaderResizeAllowed(allowHeaderResizeCheck.getSelection());
}
});
final Button allowRowResizeCheck = new Button(col1, SWT.CHECK);
allowRowResizeCheck.setSelection(_table.getDrawHeader());
allowRowResizeCheck.setText("Allow row resize");
allowRowResizeCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setRowResizeAllowed(allowRowResizeCheck.getSelection());
}
});
final Button allowColResizeCheck = new Button(col1, SWT.CHECK);
allowColResizeCheck.setSelection(_table.getDrawHeader());
allowColResizeCheck.setText("Allow column resize");
allowColResizeCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setColumnResizeAllowed(allowColResizeCheck.getSelection());
}
});
Label l = new Label(col2, SWT.NULL);
l.setText("Fixed columns");
final Combo fixedColCombo = new Combo(col2, SWT.BORDER | SWT.READ_ONLY);
fixedColCombo.setItems(new String[] { "0", "1", "2", "3", "4" });
fixedColCombo.select(0);
fixedColCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setFixedColumns(fixedColCombo.getSelectionIndex());
}
});
l = new Label(col2, SWT.NULL);
l.setText("Fixed rows");
final Combo fixedRowCombo = new Combo(col2, SWT.BORDER | SWT.READ_ONLY);
fixedRowCombo.setItems(new String[] { "0", "1", "2", "3", "4" });
fixedRowCombo.select(0);
fixedRowCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setFixedRows(fixedRowCombo.getSelectionIndex());
}
});
final Button resizeRestrictionCheck = new Button(col1, SWT.CHECK);
resizeRestrictionCheck.setSelection(_table.getResizeRestriction());
resizeRestrictionCheck.setText("Restrict resizing to headers/row headers");
resizeRestrictionCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setResizeRestriction(resizeRestrictionCheck.getSelection());
}
});
final Button excludeFixedRowsCheck = new Button(col1, SWT.CHECK);
excludeFixedRowsCheck.setSelection(_table.getExcludeFixedRowsFromSorting());
excludeFixedRowsCheck.setText("Exclude fixed rows from sorting");
excludeFixedRowsCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setExcludeFixedRowsFromSorting(excludeFixedRowsCheck.getSelection());
}
});
final Button rowFilterCheck = new Button(col1, SWT.CHECK);
rowFilterCheck.setSelection(false);
rowFilterCheck.setText("Set rowfilter (even char count on col2)");
rowFilterCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = rowFilterCheck.getSelection();
if (sel) {
_table.setRowFilter(new AbstractRowFilter() {
public boolean isInResult(IRow row) {
return ((DummyRow) row).getT2() != null && ((DummyRow) row).getT2().length() % 2 == 0;
}
});
} else {
_table.setRowFilter(null);
}
}
});
final Button rowSorterCheck = new Button(col1, SWT.CHECK);
rowSorterCheck.setSelection(false);
rowSorterCheck.setText("Set rowsorter (char count on col3)");
rowSorterCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = rowSorterCheck.getSelection();
if (sel) {
_table.setRowSorter(new AbstractRowSorter() {
public int compare(IRow o1, IRow o2) {
int c1 = ((DummyRow) o1).getT3() != null ? ((DummyRow) o1).getT3().length() : 0;
int c2 = ((DummyRow) o2).getT3() != null ? ((DummyRow) o2).getT3().length() : 0;
return c1 - c2;
}
});
} else {
_table.setRowSorter(null);
}
}
});
final Button onlyRowSelectionCheck = new Button(col1, SWT.CHECK);
onlyRowSelectionCheck.setSelection(false);
onlyRowSelectionCheck.setText("Only row selection allowed");
onlyRowSelectionCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = onlyRowSelectionCheck.getSelection();
_table.getSelectionModel().setOnlyRowSelectionAllowed(sel);
_table.getSelectionModel().clearSelection();
}
});
final Button optimizeScrollingCheck = new Button(col1, SWT.CHECK);
optimizeScrollingCheck.setSelection(_table.getOptimizeScrolling());
optimizeScrollingCheck.setText("Optimize scrolling");
optimizeScrollingCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = optimizeScrollingCheck.getSelection();
_table.setOptimizeScrolling(sel);
}
});
/**
* Style strategy coloring the background of odd row indizes. The implementation is brute force creating
* tons of objects underway ... so be careful.
*/
final IStyleStrategy _styleStrategy = new IStyleStrategy() {
public ICellStyle getCellStyle(IRow row, IColumn column, ICellStyle incomingStyle, ICellStyle defaultCellStyle) {
if (_table.getInternalRowIndex(row) % 2 == 0) {
return incomingStyle;
} else {
ICellStyle s = incomingStyle.copy();
s.setBackgroundColor(new RGB(230, 230, 230));
return s;
}
}
};
final Button bgColoringCheck = new Button(col1, SWT.CHECK);
bgColoringCheck.setSelection(_table.getTableViewState().getCellStyleProvider().getStyleStrategy() != null);
bgColoringCheck.setText("BG coloring (IStyleStrategy)");
bgColoringCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = bgColoringCheck.getSelection();
if (!sel) {
_table.getTableViewState().getCellStyleProvider().setStyleStrategy(null);
_table.redraw();
} else {
_table.getTableViewState().getCellStyleProvider().setStyleStrategy(_styleStrategy);
_table.redraw();
}
}
});
Button b2 = new Button(col2, SWT.PUSH);
b2.setText("Spawn new window");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
// hack
if (_table.getHierarchicalModel() == null) {
if (_table.getTableModel() instanceof SimpleJaretTableModel) {
new SimpleModelExample(_table.getTableModel());
} else {
new TableExample(_table.getTableModel());
}
} else {
new TableHierarchicalExample(_table.getHierarchicalModel());
}
}
});
b2 = new Button(col2, SWT.PUSH);
b2.setText("Start changing bars");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
for (int i = 0; i < _table.getTableModel().getRowCount(); i++) {
Runnable r = new Changer(_table.getTableModel(), i);
Thread t = new Thread(r);
t.start();
}
}
});
b2 = new Button(col3, SWT.PUSH);
b2.setText("Set heightmode OPTIMAL");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.getTableViewState().setRowHeightMode(ITableViewState.RowHeightMode.OPTIMAL);
}
});
b2 = new Button(col3, SWT.PUSH);
b2.setText("Set heightmode OPTANDVAR");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.getTableViewState().setRowHeightMode(ITableViewState.RowHeightMode.OPTANDVAR);
}
});
b2 = new Button(col3, SWT.PUSH);
b2.setText("Set heightmode VARIABLE");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.getTableViewState().setRowHeightMode(ITableViewState.RowHeightMode.VARIABLE);
}
});
b2 = new Button(col3, SWT.PUSH);
b2.setText("Set heightmode FIXED");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.getTableViewState().setRowHeightMode(ITableViewState.RowHeightMode.FIXED);
}
});
l = new Label(col3, SWT.NULL);
l.setText("Column resize mode");
final Combo colModeCombo = new Combo(col3, SWT.BORDER | SWT.READ_ONLY);
colModeCombo.setItems(new String[] { "NONE", "SUBSEQUENT", "ALLSUBSEQUENT", "ALL" });
colModeCombo.select(0);
colModeCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
String sel = colModeCombo.getText();
_table.getTableViewState().setColumnResizeMode(ITableViewState.ColumnResizeMode.valueOf(sel));
}
});
b2 = new Button(col3, SWT.PUSH);
b2.setText("Clipboard info");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
Clipboard cb = new Clipboard(Display.getCurrent());
System.out.println("Clipboard info");
TextTransfer textTransfer = TextTransfer.getInstance();
Object content = cb.getContents(textTransfer);
if (content != null) {
System.out.println("TEXT: " + content.getClass() + ":" + content.toString());
}
RTFTransfer rtfTransfer = RTFTransfer.getInstance();
content = cb.getContents(rtfTransfer);
if (content != null) {
System.out.println("RTF: " + content.getClass() + ":" + content.toString());
}
HTMLTransfer htmlTransfer = HTMLTransfer.getInstance();
content = cb.getContents(htmlTransfer);
if (content != null) {
System.out.println("HTML: " + content.getClass() + ":" + content.toString());
}
}
});
final Button includeColHeadingsWhenCopying = new Button(col3, SWT.CHECK);
includeColHeadingsWhenCopying.setText("Include col header when copying");
if (_table.getCcpStrategy() instanceof DefaultCCPStrategy) {
DefaultCCPStrategy stategy = (DefaultCCPStrategy) _table.getCcpStrategy();
includeColHeadingsWhenCopying.setSelection(stategy.getIncludeHeadersInCopy());
includeColHeadingsWhenCopying.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = includeColHeadingsWhenCopying.getSelection();
DefaultCCPStrategy stategy = (DefaultCCPStrategy) _table.getCcpStrategy();
stategy.setIncludeHeadersInCopy(sel);
}
});
} else {
includeColHeadingsWhenCopying.setEnabled(false);
}
}
Aggregations