Search in sources :

Example 41 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project bndtools by bndtools.

the class ResolutionFailurePanel method copyUnresolvedToClipboard.

// private void switchFailureViewMode() {
// Object input = unresolvedViewer.getInput();
// unresolvedViewer.setInput(null);
// setFailureViewMode();
// unresolvedViewer.setInput(input);
// unresolvedViewer.expandToLevel(2);
// }
private void copyUnresolvedToClipboard() {
    StringBuilder builder = new StringBuilder();
    Object input = unresolvedViewer.getInput();
    if (input == null)
        return;
    ITreeContentProvider contentProvider = (ITreeContentProvider) unresolvedViewer.getContentProvider();
    Object[] roots = contentProvider.getElements(input);
    ViewerSorter sorter = unresolvedViewer.getSorter();
    if (sorter != null)
        Arrays.sort(roots, new SorterComparatorAdapter(unresolvedViewer, sorter));
    for (Object root : roots) {
        appendLabels(root, contentProvider, builder, 0);
    }
    /*
         * TODO if (result != null) { StringBuilder buffer = new StringBuilder(); List<Reason> unresolved =
         * result.getUnresolved(); if (unresolved != null) for (Iterator<Reason> iter = unresolved.iterator();
         * iter.hasNext(); ) { Reason reason = iter.next();
         * buffer.append(unresolvedLabelProvider.getLabel(reason.getRequirement ()).getString()); buffer.append('\t');
         * buffer.append(unresolvedLabelProvider .getLabel(reason.getResource())); if (iter.hasNext())
         * buffer.append('\n'); } }
         */
    Clipboard clipboard = new Clipboard(composite.getDisplay());
    TextTransfer transfer = TextTransfer.getInstance();
    clipboard.setContents(new Object[] { builder.toString() }, new Transfer[] { transfer });
    clipboard.dispose();
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) Clipboard(org.eclipse.swt.dnd.Clipboard) SorterComparatorAdapter(bndtools.model.obr.SorterComparatorAdapter) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 42 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer 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();
        }
    }
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 43 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer 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++;
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) Clipboard(org.eclipse.swt.dnd.Clipboard) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 44 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer 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);
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) TableItem(org.eclipse.swt.widgets.TableItem) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 45 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project cubrid-manager by CUBRID.

the class ImportResultDialog method copyDataToClipboard.

/**
	 *
	 * Copy the selected data to clipboard
	 *
	 */
private void copyDataToClipboard() {
    // FIXME move this logic to core module
    TextTransfer textTransfer = TextTransfer.getInstance();
    Clipboard clipboard = CommonUITool.getClipboard();
    StringBuilder content = new StringBuilder();
    TableItem[] items = table.getSelection();
    for (int i = 0; i < items.length; i++) {
        content.append(items[i].getText(1) + System.getProperty("line.separator"));
    }
    String data = content.toString();
    if (data != null && !data.equals("")) {
        clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Aggregations

TextTransfer (org.eclipse.swt.dnd.TextTransfer)77 Clipboard (org.eclipse.swt.dnd.Clipboard)65 Point (org.eclipse.swt.graphics.Point)19 Transfer (org.eclipse.swt.dnd.Transfer)18 TableItem (org.eclipse.swt.widgets.TableItem)14 StyledText (org.eclipse.swt.custom.StyledText)10 Control (org.eclipse.swt.widgets.Control)8 Text (org.eclipse.swt.widgets.Text)6 IAction (org.eclipse.jface.action.IAction)5 HTMLTransfer (org.eclipse.swt.dnd.HTMLTransfer)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Button (org.eclipse.swt.widgets.Button)5 Composite (org.eclipse.swt.widgets.Composite)5 ArrayList (java.util.ArrayList)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Label (org.eclipse.swt.widgets.Label)4