Search in sources :

Example 46 with TextTransfer

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

the class CommonUITool method getTextContentFromClipboard.

/**
	 *
	 * Get text content from clipboard
	 *
	 * @return the string from clipboard
	 */
public static String getTextContentFromClipboard() {
    Clipboard clipboard = CommonUITool.getClipboard();
    TextTransfer textTransfer = TextTransfer.getInstance();
    Object obj = clipboard.getContents(textTransfer);
    if (obj == null) {
        return "";
    } else {
        return (String) obj;
    }
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 47 with TextTransfer

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

the class CopyAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    TextTransfer textTransfer = TextTransfer.getInstance();
    Clipboard clipboard = CommonUITool.getClipboard();
    Control control = getFocusProvider();
    if (control instanceof StyledText) {
        StyledText stext = (StyledText) control;
        String data = stext.getSelectionText();
        if (data != null && !data.equals("")) {
            clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            FocusAction.changeActionStatus(pasteAction, stext);
        }
    } else {
        /*Copy from the active editor*/
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window != null) {
            IEditorPart editor = window.getActivePage().getActiveEditor();
            if (editor != null && editor instanceof ICopiableFromTable) {
                ICopiableFromTable copyAbleEditor = (ICopiableFromTable) editor;
                copyAbleEditor.copySelectedItems();
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ICopiableFromTable(com.cubrid.common.ui.query.editor.ICopiableFromTable) Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) IAction(org.eclipse.jface.action.IAction) Clipboard(org.eclipse.swt.dnd.Clipboard) IEditorPart(org.eclipse.ui.IEditorPart) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 48 with TextTransfer

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

the class CreateSqlJavaCodeAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    // FIXME move this logic to core module
    Control control = getFocusProvider();
    if (control instanceof StyledText) {
        StyledText stext = (StyledText) control;
        String data = stext.getSelectionText();
        if (data != null && !data.equals("")) {
            StringBuilder res = new StringBuilder();
            Vector<String> list = QueryUtil.queriesToQuery(data);
            for (int i = 0; i < list.size(); i++) {
                String row = list.get(i);
                if (res.length() > 0) {
                    res.append("\n\n");
                }
                res.append(parseToJavaCode(row));
            }
            if (res.length() == 0) {
                CommonUITool.openErrorBox(Messages.errCreatedSqlNotSelected);
                return;
            }
            Clipboard clipboard = CommonUITool.getClipboard();
            TextTransfer textTransfer = TextTransfer.getInstance();
            clipboard.setContents(new Object[] { res.toString() }, new Transfer[] { textTransfer });
            CommonUITool.openInformationBox(Messages.titleCreateCode, Messages.msgCreatedSqlJavaCode);
        } else {
            CommonUITool.openErrorBox(Messages.errCreatedSqlNotSelected);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 49 with TextTransfer

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

the class CreateSqlPhpCodeAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    // FIXME move this logic to core module
    Control control = getFocusProvider();
    if (control instanceof StyledText) {
        StyledText stext = (StyledText) control;
        String data = stext.getSelectionText();
        if (StringUtil.isNotEmpty(data)) {
            StringBuilder res = new StringBuilder();
            Vector<String> list = QueryUtil.queriesToQuery(data);
            for (int i = 0; i < list.size(); i++) {
                String row = list.get(i);
                if (res.length() > 0) {
                    res.append("\n\n");
                }
                res.append(parseToPhpCode(row));
            }
            if (res.length() == 0) {
                CommonUITool.openErrorBox(Messages.errCreatedSqlNotSelected);
                return;
            }
            Clipboard clipboard = CommonUITool.getClipboard();
            TextTransfer textTransfer = TextTransfer.getInstance();
            clipboard.setContents(new Object[] { res.toString() }, new Transfer[] { textTransfer });
            CommonUITool.openInformationBox(Messages.titleCreateCode, Messages.msgCreatedSqlPhpCode);
        } else {
            CommonUITool.openErrorBox(Messages.errCreatedSqlNotSelected);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 50 with TextTransfer

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

the class PasteAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    TextTransfer textTransfer = TextTransfer.getInstance();
    Clipboard clipboard = CommonUITool.getClipboard();
    Control control = getFocusProvider();
    if (control instanceof StyledText) {
        Object contents = clipboard.getContents(textTransfer);
        if (contents instanceof String) {
            String str = (String) contents;
            StyledText text = (StyledText) control;
            Point range = text.getSelectionRange();
            text.replaceTextRange(range.x, range.y, str);
            text.setSelection(range.x + str.length());
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) Clipboard(org.eclipse.swt.dnd.Clipboard) Point(org.eclipse.swt.graphics.Point) 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