Search in sources :

Example 1 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project tdi-studio-se by Talend.

the class DataSetTableKeyListener method keyPressed.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
     */
public void keyPressed(KeyEvent e) {
    switch(e.character) {
        case CTRL_C:
            try {
                Clipboard clipBoard = new Clipboard(Display.getCurrent());
                TextTransfer textTransfer = TextTransfer.getInstance();
                TableItem[] items = ptable.getSelection();
                if (items == null || items.length == 0) {
                    return;
                }
                int columnIndex = pcursor.getColumn();
                clipBoard.setContents(new Object[] { items[0].getText(columnIndex) }, new Transfer[] { textTransfer });
            } catch (Exception ex) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("DataSetTableKeyListener.logMessage1"), ex);
            }
            break;
        case CTRL_F:
            // column name typeahead
            createPopup();
            break;
        default:
            return;
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Clipboard(org.eclipse.swt.dnd.Clipboard) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 2 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project tdi-studio-se by Talend.

the class NodeTransferDragSourceListener method getNodeTransferDragSourceListener.

public TransferDragSourceListener getNodeTransferDragSourceListener() {
    if (dragDropListener == null)
        dragDropListener = new TransferDragSourceListener() {

            TextTransfer transfer;

            public Transfer getTransfer() {
                transfer = TextTransfer.getInstance();
                return transfer;
            }

            public void dragFinished(final DragSourceEvent event) {
            }

            public void dragSetData(final DragSourceEvent event) {
                if (currentEditPart != null && currentEditPart.getParent() != null) {
                    INode node = (INode) currentEditPart.getParent().getModel();
                    String value = ElementParameterParser.parse(node, ((INodeReturn) currentEditPart.getModel()).getVarName());
                    event.data = value;
                }
            }

            public void dragStart(final DragSourceEvent event) {
                if (currentEditPart != null && currentEditPart.getParent() != null) {
                    // Make sure the process node can not be dragged and dropped.
                    if (currentEditPart.getParent().getModel() instanceof org.talend.designer.core.ui.editor.nodes.Node) {
                        event.doit = true;
                        return;
                    }
                }
                event.doit = false;
            }
        };
    return dragDropListener;
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) INode(org.talend.core.model.process.INode) INode(org.talend.core.model.process.INode) TransferDragSourceListener(org.eclipse.jface.util.TransferDragSourceListener) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 3 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project ACS by ACS-Community.

the class CopyDetailsToClipboardHandler method execute.

/**
	 * Receives the selection from the event detail part.
	 * <p>
	 * It may be my lack of understanding of good Eclipse 4 RCP practices that I wish
	 * I could handle the mouse menu action locally in the event detail part,
	 * instead of sending the data via selection service to separate handler.
	 * Perhaps to be refactored once this becomes clearer. 
	 */
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) ParsedAnyData[] parsedAnyData) throws ExecutionException {
    if (parsedAnyData == null || parsedAnyData.length == 0) {
        return;
    }
    System.out.println("Will copy event details to the clipboard...");
    // Convert selected table rows into a multi-line String
    StringBuilder sb = new StringBuilder();
    for (ParsedAnyData parsedAny : parsedAnyData) {
        sb.append(parsedAnyDataToString(parsedAny));
    }
    // Write that data to the system clipboard
    Clipboard cb = new Clipboard(Display.getCurrent());
    TextTransfer textTransfer = TextTransfer.getInstance();
    cb.setContents(new Object[] { sb.toString() }, new Transfer[] { textTransfer });
    cb.dispose();
}
Also used : ParsedAnyData(alma.acs.eventbrowser.parts.ParsedAnyData) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 4 with TextTransfer

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

the class PstmtSQLDialog method createEmptyTable.

/**
	 * Create the empty parameter table
	 *
	 * @param parent Composite
	 * @param isMulti boolean
	 */
protected void createEmptyTable(Composite parent) {
    Group typeGroup = new Group(parent, SWT.SHADOW_ETCHED_IN);
    GridData groupGd = new GridData(GridData.FILL_HORIZONTAL);
    groupGd.heightHint = 70;
    typeGroup.setLayoutData(groupGd);
    typeGroup.setLayout(new GridLayout());
    typeGroup.setText(Messages.colParaType);
    parameterTypeTable = new Table(typeGroup, SWT.BORDER | SWT.H_SCROLL);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 45;
    parameterTypeTable.setLayoutData(gd);
    parameterTypeTable.setHeaderVisible(true);
    parameterTypeTable.setLinesVisible(false);
    parameterTypeTable.setDragDetect(false);
    TableColumn columnNO = new TableColumn(parameterTypeTable, SWT.CENTER);
    columnNO.setWidth(40);
    columnNO.setText("");
    tableEditor = new TableEditor(parameterTypeTable);
    tableEditor.horizontalAlignment = SWT.LEFT;
    tableEditor.grabHorizontal = true;
    parameterTypeTable.addListener(SWT.MouseUp, new Listener() {

        public void handleEvent(Event event) {
            if (event.button != 1) {
                return;
            }
            if (isChanging) {
                return;
            }
            Point pt = new Point(event.x, event.y);
            final TableItem item = parameterTypeTable.getItem(0);
            for (int i = 1; i < parameterTypeTable.getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    handleType(item, i);
                }
            }
        }
    });
    Group parameterGroup = new Group(parent, SWT.SHADOW_IN);
    parameterGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    parameterGroup.setLayout(new GridLayout(2, false));
    parameterGroup.setText(Messages.colParaValue);
    ToolBar toolBar = new ToolBar(parameterGroup, SWT.FLAT);
    ToolItem addRecordItem = new ToolItem(toolBar, SWT.PUSH);
    addRecordItem.setImage(CommonUIPlugin.getImage("icons/action/table_record_insert.png"));
    addRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            addData();
        }
    });
    ToolItem delRecordItem = new ToolItem(toolBar, SWT.PUSH);
    delRecordItem.setImage(CommonUIPlugin.getImage("icons/action/table_record_delete.png"));
    delRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (parameterTable.getTable().getSelectionIndices().length == 0) {
                setErrorMessage(Messages.errDeleteMsg);
                return;
            }
            List<Integer> deleteIndex = new ArrayList<Integer>();
            for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
                deleteIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
            }
            int lastSelectedIndex = 0;
            for (int i = 0; i < deleteIndex.size(); i++) {
                int seletectIndex = deleteIndex.get(i);
                int newIndex = seletectIndex - i;
                valueList.remove(newIndex);
                lastSelectedIndex = newIndex;
            }
            //reset the index in data
            for (int i = 0; i < valueList.size(); i++) {
                ParamValueObject paramValueObject = valueList.get(i);
                paramValueObject.getValue().set(0, String.valueOf(i + 1));
            }
            parameterTable.setInput(valueList);
            parameterTable.refresh();
            if (parameterTable.getTable().getItemCount() > 0) {
                parameterTable.getTable().setSelection(lastSelectedIndex < 1 ? 0 : lastSelectedIndex - 1);
                parameterTable.getTable().setFocus();
            }
            validate();
        }
    });
    parameterTable = new TableViewer(parameterGroup, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    // press the tab key, it is moved next input area
    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(parameterTable, new FocusCellOwnerDrawHighlighter(parameterTable));
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(parameterTable) {

        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION && ((MouseEvent) event.sourceEvent).button == 1) || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
        //				|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    TableViewerEditor.create(parameterTable, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
    //		new Table(parameterGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    parameterTable.getTable().setLayoutData(gridData);
    parameterTable.getTable().setHeaderVisible(true);
    parameterTable.getTable().setLinesVisible(true);
    parameterTable.setUseHashlookup(true);
    final TableViewerColumn columnNO2 = new TableViewerColumn(parameterTable, SWT.CENTER);
    columnNO2.getColumn().setWidth(40);
    columnNO2.getColumn().setText("");
    parameterTable.setContentProvider(new ParamValueContentProvider());
    parameterTable.setLabelProvider(new ParamValueLabelProvider(parameterTable.getTable()));
    parameterTable.getTable().addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {
            if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'c') {
                final Clipboard cb = new Clipboard(getShell().getDisplay());
                StringBuffer clipboardDataString = new StringBuffer();
                List<Integer> replaceIndex = new ArrayList<Integer>();
                for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
                    replaceIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
                }
                for (int i = 0; i < replaceIndex.size(); i++) {
                    if (i != 0) {
                        clipboardDataString.append(EXCELDATASEPRATOR);
                    }
                    ParamValueObject paramValueObject = valueList.get(replaceIndex.get(i));
                    for (int j = 1; j < parameterTypeTable.getColumnCount(); j++) {
                        if (j != 1) {
                            clipboardDataString.append(EXCELCOLUMNSEPRATOR);
                        }
                        String value = paramValueObject.getValue().get(j);
                        clipboardDataString.append(value);
                    }
                }
                TextTransfer textTransfer = TextTransfer.getInstance();
                Transfer[] transfers = new Transfer[] { textTransfer };
                Object[] data = new Object[] { clipboardDataString.toString() };
                cb.setContents(data, transfers);
                cb.dispose();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'v') {
                final Clipboard cb = new Clipboard(getShell().getDisplay());
                //					boolean supportFlag = false;
                //					TransferData[] transferDatas = cb.getAvailableTypes();
                //					for(int i=0; i<transferDatas.length; i++) {
                //						// Checks whether RTF format is available.
                //						if(RTFTransfer.getInstance().isSupportedType(transferDatas[i])) {
                //							supportFlag = true;
                //							break;
                //						}
                //					}
                //					if (!supportFlag) {
                //						setErrorMessage(Messages.pstmtSQLUnsupportPasteType);
                //						return;
                //					}
                String plainText = (String) cb.getContents(TextTransfer.getInstance());
                List<ParamValueObject> list = generateParamValueObjectListFromClipboardString(plainText);
                if (list.size() == 0 || list.get(0).getValue().size() != parameterTypeTable.getColumnCount()) {
                    setErrorMessage(Messages.pstmtSQLUnsupportPasteType);
                    return;
                }
                //					String rtfText = (String)cb.getContents(RTFTransfer.getInstance());
                int startIndex = parameterTable.getTable().getSelectionIndex();
                //if the copy line bigger than the value list, add new ParamValueObject to the end
                if (parameterTable.getTable().getSelectionCount() <= 1) {
                    if (startIndex < 0 || startIndex > valueList.size()) {
                        for (ParamValueObject copyParamValueObject : list) {
                            valueList.add(copyParamValueObject);
                        }
                    } else {
                        for (ParamValueObject copyParamValueObject : list) {
                            if (startIndex > valueList.size() - 1) {
                                valueList.add(copyParamValueObject);
                            } else {
                                ParamValueObject paramValueObject = valueList.get(startIndex);
                                List<String> oldValue = paramValueObject.getValue();
                                for (int i = 1; i < oldValue.size(); i++) {
                                    List<String> newValue = copyParamValueObject.getValue();
                                    if (i > newValue.size() - 1) {
                                        break;
                                    }
                                    oldValue.set(i, newValue.get(i));
                                }
                            }
                            startIndex++;
                        }
                    }
                } else {
                    // replay the select line
                    List<Integer> replaceIndex = new ArrayList<Integer>();
                    for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
                        replaceIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
                    }
                    for (int i = 0; i < replaceIndex.size(); i++) {
                        ParamValueObject paramValueObject = valueList.get(replaceIndex.get(i));
                        List<String> oldValue = paramValueObject.getValue();
                        if (i > list.size()) {
                            break;
                        }
                        List<String> newValue = list.get(i).getValue();
                        for (int j = 1; j < oldValue.size(); j++) {
                            if (j > newValue.size()) {
                                break;
                            }
                            oldValue.set(j, newValue.get(j));
                        }
                    }
                }
                cb.dispose();
                refreshValueListIndex();
                parameterTable.refresh();
                validate();
            }
        }
    });
    // use to mark click point, the right click menu use this point
    parameterTable.getTable().addListener(SWT.MouseDown, new Listener() {

        public void handleEvent(Event event) {
            clickPoint = new Point(event.x, event.y);
        }
    });
    registerContextMenu();
    parameterTable.setInput(valueList);
}
Also used : Group(org.eclipse.swt.widgets.Group) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) TraverseListener(org.eclipse.swt.events.TraverseListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) TableItem(org.eclipse.swt.widgets.TableItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) FocusCellOwnerDrawHighlighter(org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ToolItem(org.eclipse.swt.widgets.ToolItem) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) TableEditor(org.eclipse.swt.custom.TableEditor) Point(org.eclipse.swt.graphics.Point) TableViewerFocusCellManager(org.eclipse.jface.viewers.TableViewerFocusCellManager) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) FocusEvent(org.eclipse.swt.events.FocusEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Clipboard(org.eclipse.swt.dnd.Clipboard) TableViewer(org.eclipse.jface.viewers.TableViewer) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 5 with TextTransfer

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

the class ExportConnectionUtil method buttonPressed.

/**
	 * Call this method when the button in button bar is pressed
	 *
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == COPY_CLIPBOARD_ID) {
        List<CubridDatabase> databaseList = getCheckedDatabases();
        if (databaseList.size() <= 0) {
            CommonUITool.openErrorBox(getShell(), Messages.expConDialogCopyErrorMsg);
            return;
        }
        StringBuilder sb = new StringBuilder();
        for (CubridDatabase db : databaseList) {
            if (sb.length() > 0) {
                sb.append(StringUtil.NEWLINE);
            }
            sb.append(NodeUtil.getJavaConnectionUrl(db.getDatabaseInfo()));
        }
        TextTransfer textTransfer = TextTransfer.getInstance();
        Clipboard clipboard = CommonUITool.getClipboard();
        clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { textTransfer });
        CommonUITool.openInformationBox(Messages.titleSuccess, Messages.expConDialogCopySucessMsg);
        return;
    } else if (buttonId == IDialogConstants.OK_ID) {
        if (!verify()) {
            return;
        }
        FileDialog dialog = new FileDialog(getShell(), SWT.SAVE | SWT.APPLICATION_MODAL);
        String[] filterExtensions = new String[] { "*.xls" };
        //Windows wild cards
        dialog.setFilterExtensions(filterExtensions);
        String fileName = dialog.open();
        if (fileName == null) {
            return;
        }
        /*Process the file extensions*/
        if (!ExportConnectionUtil.isTxtFile(fileName) && !ExportConnectionUtil.isXlsFile(fileName) && !ExportConnectionUtil.isXlsxFile(fileName)) {
            int filterIndex = dialog.getFilterIndex();
            if (filterIndex == 0 || filterIndex == 2) {
                fileName = fileName + ".xls";
            } else if (filterIndex == 1) {
                fileName = fileName + ".txt";
            }
        }
        TaskExecutor taskExec = new CommonTaskExec(Messages.nameExportConnectionTask);
        File file = new File(fileName);
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                LOGGER.error("Create file failed:" + e.getMessage());
            }
        }
        ExportConnectionsTask task = new ExportConnectionsTask(getCheckedDatabases(), file);
        taskExec.addTask(task);
        new ExecTaskWithProgress(taskExec).busyCursorWhile();
        if (taskExec.isSuccess()) {
            CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgConnectionUrlExported);
            super.okPressed();
        }
    }
    super.buttonPressed(buttonId);
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IOException(java.io.IOException) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) Clipboard(org.eclipse.swt.dnd.Clipboard) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) 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