Search in sources :

Example 56 with Clipboard

use of org.eclipse.swt.dnd.Clipboard 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 57 with Clipboard

use of org.eclipse.swt.dnd.Clipboard 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 58 with Clipboard

use of org.eclipse.swt.dnd.Clipboard 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)

Example 59 with Clipboard

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

the class PasteAction method isHasContent.

/**
	 * Return whether has content in clipboard
	 * 
	 * @return boolean
	 */
private boolean isHasContent() {
    TextTransfer textTransfer = TextTransfer.getInstance();
    Clipboard clipboard = CommonUITool.getClipboard();
    if (clipboard != null) {
        Object contents = clipboard.getContents(textTransfer);
        if (contents instanceof String) {
            String str = (String) contents;
            return str != null && str.length() > 0;
        }
    }
    return false;
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 60 with Clipboard

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

the class QueryExecuter method copySelectedItems.

public void copySelectedItems() {
    CommonUITool.clearClipboard();
    StringBuilder content = new StringBuilder();
    List<Point> selectedList = selectableSupport.getSelectedLocations();
    int currentRow = -1;
    int len = selectedList.size();
    for (int i = 0; i < len; i++) {
        Point location = selectedList.get(i);
        if (i == 0) {
            currentRow = location.y;
        } else if (currentRow != location.y) {
            content.append(StringUtil.NEWLINE);
            currentRow = location.y;
        }
        TableItem item = tblResult.getItem(currentRow);
        if (!DataType.VALUE_NULL.equals(item.getData(location.x + ""))) {
            content.append(item.getText(location.x));
        } else {
            content.append("");
        }
        if (i + 1 < len) {
            content.append("\t");
        }
    }
    TextTransfer textTransfer = TextTransfer.getInstance();
    Clipboard clipboard = CommonUITool.getClipboard();
    if (clipboard != null) {
        IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
        pasteAction.setEnabled(true);
        clipboard.setContents(new Object[] { content.toString() }, new Transfer[] { textTransfer });
    }
}
Also used : IAction(org.eclipse.jface.action.IAction) TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Aggregations

Clipboard (org.eclipse.swt.dnd.Clipboard)73 TextTransfer (org.eclipse.swt.dnd.TextTransfer)50 Transfer (org.eclipse.swt.dnd.Transfer)19 Point (org.eclipse.swt.graphics.Point)12 StyledText (org.eclipse.swt.custom.StyledText)8 Composite (org.eclipse.swt.widgets.Composite)7 Display (org.eclipse.swt.widgets.Display)7 IAction (org.eclipse.jface.action.IAction)6 ISelection (org.eclipse.jface.viewers.ISelection)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Control (org.eclipse.swt.widgets.Control)6 TableItem (org.eclipse.swt.widgets.TableItem)6 ArrayList (java.util.ArrayList)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 GridData (org.eclipse.swt.layout.GridData)5 Event (org.eclipse.swt.widgets.Event)4 Shell (org.eclipse.swt.widgets.Shell)4 Rectangle (org.eclipse.swt.graphics.Rectangle)3