Search in sources :

Example 1 with Clipboard

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

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

the class CopyAction method run.

/*
     * @see Action#run()
     */
@Override
public void run() {
    if (textData == null || textData.length() == 0) {
        return;
    }
    Clipboard clipboard = new Clipboard(Display.getDefault());
    if (filesData.size() > 0) {
        Object[] clipboardData = new Object[] { filesData.toArray(new String[0]), textData };
        Transfer[] clipboardDataTypes = new Transfer[] { FileTransfer.getInstance(), TextTransfer.getInstance() };
        clipboard.setContents(clipboardData, clipboardDataTypes);
    } else {
        clipboard.setContents(new Object[] { textData }, new Transfer[] { TextTransfer.getInstance() });
    }
}
Also used : Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 3 with Clipboard

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

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

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

the class MultiDBQueryComposite method initialize.

/**
	 * Create the SQL history composite
	 */
public void initialize() {
    Composite toolBarComposite = new Composite(this, SWT.NONE);
    GridLayout gridLayout = new GridLayout(2, false);
    gridLayout.verticalSpacing = 0;
    gridLayout.horizontalSpacing = 10;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    toolBarComposite.setLayout(gridLayout);
    toolBarComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    ToolBar toolBar = new ToolBar(toolBarComposite, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
    ToolItem refreshToolItem = new ToolItem(toolBar, SWT.PUSH);
    refreshToolItem.setText(Messages.lblItemRefreshMulti);
    refreshToolItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
    refreshToolItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
    refreshToolItem.setToolTipText(Messages.refresh);
    refreshToolItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            //refresh may set tree to group type or not
            //so mark the select db then set it to checked after set input
            //				Object[] checkedObject = ctv.getCheckedElements();
            setInput();
        //				for (Object o : checkedObject) {
        //					if (o instanceof CubridDatabase) {
        //						ctv.setChecked(o, true);
        //					}
        //				}
        //				refresh(editor.getSelectedDatabase());
        }
    });
    runItem = new ToolItem(toolBar, SWT.PUSH);
    runItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_run.png"));
    runItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_run_disabled.png"));
    runItem.setText(Messages.lblItemRunMulti);
    runItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            editor.runMultiQuery();
        }
    });
    Label lblNotice = new Label(toolBarComposite, SWT.None);
    lblNotice.setText(Messages.qedit_multiDBQueryComp_noticeToolbarMsg);
    lblNotice.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, true, false));
    // create the query result tab folder
    multiDBQueryCompTabFolder = new CTabFolder(this, SWT.BOTTOM);
    multiDBQueryCompTabFolder.setSimple(false);
    multiDBQueryCompTabFolder.setUnselectedImageVisible(true);
    multiDBQueryCompTabFolder.setUnselectedCloseVisible(true);
    multiDBQueryCompTabFolder.setSelectionBackground(CombinedQueryEditorComposite.BACK_COLOR);
    multiDBQueryCompTabFolder.setSelectionForeground(ResourceManager.getColor(SWT.COLOR_BLACK));
    multiDBQueryCompTabFolder.setLayout(new GridLayout(1, true));
    multiDBQueryCompTabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
    //TabContextMenuManager tabContextMenuManager = new TabContextMenuManager(multiDBQueryCompTabFolder);
    //tabContextMenuManager.createContextMenu();
    multiDBQueryCompTabItem = new CTabItem(resultTabFolder, SWT.NONE);
    multiDBQueryCompTabItem.setText(Messages.qedit_multiDBQueryComp_folder);
    multiDBQueryCompTabItem.setControl(this);
    multiDBQueryCompTabItem.setShowClose(false);
    SashForm bottomSash = new SashForm(multiDBQueryCompTabFolder, SWT.VERTICAL);
    bottomSash.SASH_WIDTH = SASH_WIDTH;
    bottomSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    SashForm tailSash = new SashForm(bottomSash, SWT.HORIZONTAL);
    tailSash.SASH_WIDTH = SASH_WIDTH;
    tailSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    Composite treeComp = new Composite(tailSash, SWT.NONE);
    {
        treeComp.setLayoutData(new GridData(GridData.FILL_BOTH));
        treeComp.setLayout(new GridLayout());
    }
    ctv = new ContainerCheckedTreeViewer(treeComp, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    ctv.getControl().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
    ctv.setContentProvider(new MultiDBQueryTreeContentProvider());
    ctv.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            if (lastSelectedTime != 0 && lastSelectedTime > System.currentTimeMillis()) {
                ctv.setChecked(event.getElement(), true);
                return;
            }
            ctv.setChecked(event.getElement(), false);
            lastSelectedTime = System.currentTimeMillis() + 100;
            if (getQueryDatabaseList().size() > 0 && editor.getAllQueries().trim().length() != 0) {
                editor.setMultiQueryRunItemStatus(true);
            } else if (getQueryDatabaseList().size() == 0) {
                editor.setMultiQueryRunItemStatus(false);
            }
            //if (!event.getChecked()) {
            selectedNodes.remove(event.getElement());
            if (event.getElement() instanceof CubridDatabase) {
                CubridDatabase database = (CubridDatabase) event.getElement();
                if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                    //ctv.setChecked(event.getElement(), false);
                    selectedNodes.remove(database);
                } else {
                    if (database.getData(INDEXKEY) == null) {
                        database.setData(INDEXKEY, String.valueOf(databaseIndex++));
                    }
                }
            } else if (event.getElement() instanceof CubridServer) {
                CubridServer serverNode = (CubridServer) event.getElement();
                for (ICubridNode dbFolderNode : serverNode.getChildren()) {
                    for (ICubridNode dbNode : dbFolderNode.getChildren()) {
                        if (dbNode instanceof CubridDatabase) {
                            CubridDatabase database = (CubridDatabase) dbNode;
                            if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                                //ctv.setChecked(dbNode, false);
                                selectedNodes.remove(database);
                            } else if (ctv.getChecked(dbNode)) {
                                ctv.setChecked(dbNode, true);
                                if (dbNode.getData(INDEXKEY) == null) {
                                    dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
                                }
                            } else {
                                ctv.setChecked(dbNode, true);
                            }
                        }
                    }
                    //only has one db folder  so first time break it
                    break;
                }
            } else if (event.getElement() instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) event.getElement();
                if (node.getType().equals(NodeType.DATABASE_FOLDER)) {
                    for (ICubridNode dbNode : node.getChildren()) {
                        if (dbNode instanceof CubridDatabase) {
                            CubridDatabase database = (CubridDatabase) dbNode;
                            if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                                ctv.setChecked(dbNode, false);
                            } else if (ctv.getChecked(dbNode)) {
                                ctv.setChecked(dbNode, true);
                                if (dbNode.getData(INDEXKEY) == null) {
                                    dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
                                }
                            } else {
                                ctv.setChecked(dbNode, false);
                            }
                        }
                    }
                }
            //					else if (node.getType().equals(NodeType.GROUP)) {
            //						for (ICubridNode childNode : node.getChildren()) {
            //							//CQB tree
            //							if(childNode instanceof CubridDatabase) {
            //								CubridDatabase database = (CubridDatabase) childNode;
            //								if (database.getRunningType() == DbRunningType.STANDALONE
            //										|| !database.isLogined()) {
            //									if (childNode.getData(INDEXKEY) == null) {
            //										childNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
            //									}
            //								}
            //								continue;
            //							}
            //							//CM tree
            //							for (ICubridNode dbFolderNode : childNode.getChildren()) {
            //								for (ICubridNode dbNode : dbFolderNode.getChildren()) {
            //									if(dbNode instanceof CubridDatabase) {
            //										CubridDatabase database = (CubridDatabase) dbNode;
            //										if (database.getRunningType() == DbRunningType.STANDALONE
            //												|| !database.isLogined()) {
            //											ctv.setChecked(dbNode, false);
            //										} else if (ctv.getChecked(dbNode)) {
            //											ctv.setChecked(dbNode, true);
            //											if (dbNode.getData(INDEXKEY) == null) {
            //												dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
            //											}
            //										} else {
            //											ctv.setChecked(dbNode, false);
            //										}
            //									}
            //								}
            //							}
            //							//only has one db folder  so first time break it
            //							break;
            //						}
            //					}
            }
            ctv.refresh();
        }
    });
    ctv.getTree().addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent event) {
            //mac can't drag and drop,so support copy and paste db node
            if (((event.stateMask & SWT.CTRL) != 0) || ((event.stateMask & SWT.COMMAND) != 0) && event.keyCode == 'v') {
                final Clipboard cb = new Clipboard(getShell().getDisplay());
                String plainText = (String) cb.getContents(TextTransfer.getInstance());
                String[] databaseNameArray = plainText.split(",");
                selectedNodes.addAll(getDatabaseNode(databaseNameArray));
                setInput();
            }
        }
    });
    //		ctv.addDoubleClickListener(LayoutManager.getInstance());
    //		ctv.addTreeListener(new ITreeViewerListener() {
    //			public void treeCollapsed(TreeExpansionEvent event) {
    //				CommonTool.clearExpandedElements(ctv);
    //			}
    //
    //			public void treeExpanded(TreeExpansionEvent event) {
    //				CommonTool.clearExpandedElements(ctv);
    //			}
    //		});
    final Tree tableTree = ctv.getTree();
    tableTree.setHeaderVisible(true);
    tableTree.setLinesVisible(true);
    final TreeViewerColumn dbCol = new TreeViewerColumn(ctv, SWT.NONE);
    dbCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    dbCol.getColumn().setWidth(250);
    dbCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_dbCol);
    final TreeViewerColumn indexCol = new TreeViewerColumn(ctv, SWT.NONE);
    indexCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    indexCol.getColumn().setWidth(50);
    indexCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_indexCol);
    indexCol.setEditingSupport(new EditingSupport(ctv) {

        TextCellEditor textCellEditor;

        protected boolean canEdit(Object element) {
            if (element instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) element;
                if (node.getType() == NodeType.DATABASE) {
                    CubridDatabase database = (CubridDatabase) element;
                    if ((database.getRunningType() == DbRunningType.CS && database.isLogined())) {
                        return true;
                    }
                }
            }
            return false;
        }

        protected CellEditor getCellEditor(Object element) {
            if (textCellEditor == null) {
                textCellEditor = new TextCellEditor(ctv.getTree());
                textCellEditor.setValidator(new IndexCellEditorValidator());
                textCellEditor.addListener(new ICellEditorListener() {

                    public void applyEditorValue() {
                    }

                    public void cancelEditor() {
                    }

                    public void editorValueChanged(boolean oldValidState, boolean newValidState) {
                    }
                });
            }
            return textCellEditor;
        }

        protected Object getValue(Object element) {
            final ICubridNode node = (ICubridNode) element;
            String index = (String) node.getData(INDEXKEY);
            if (index == null) {
                return "";
            } else {
                return index;
            }
        }

        protected void setValue(Object element, Object value) {
            if (value == null) {
                return;
            }
            try {
                Integer.valueOf((String) value);
            } catch (Exception e) {
                return;
            }
            final ICubridNode node = (ICubridNode) element;
            node.setData(INDEXKEY, value);
            //				setAllParentExpandOrCollapse(node.getParent(), true);
            ctv.refresh();
        }

        /**
			 * MyCellEditorValidator
			 *
			 * @author fulei
			 *
			 */
        class IndexCellEditorValidator implements ICellEditorValidator {

            /**
				 * isValid
				 *
				 * @param value Object
				 * @return String
				 */
            public String isValid(Object value) {
                try {
                    Integer.valueOf((String) value);
                } catch (Exception e) {
                    CommonUITool.openErrorBox(Messages.qedit_multiDBQueryComp_tree_indexErr);
                    return Messages.qedit_multiDBQueryComp_tree_indexErr;
                }
                return null;
            }
        }
    });
    final TreeViewerColumn commentCol = new TreeViewerColumn(ctv, SWT.NONE);
    commentCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    commentCol.getColumn().setWidth(200);
    commentCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_commentCol);
    CTabItem tabItem = new CTabItem(multiDBQueryCompTabFolder, SWT.NONE);
    tabItem.setText(Messages.qedit_multiDBQueryComp_tabItem);
    tabItem.setControl(bottomSash);
    tabItem.setShowClose(false);
    setInput();
    //		HostNodePersistManager.getInstance().getAllServer();
    multiDBQueryCompTabFolder.setSelection(tabItem);
    dragController = new MultiDBQueryDNDController(this, ctv);
    dragController.registerDropTarget();
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) EditingSupport(org.eclipse.jface.viewers.EditingSupport) CTabItem(org.eclipse.swt.custom.CTabItem) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) ToolItem(org.eclipse.swt.widgets.ToolItem) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) SashForm(org.eclipse.swt.custom.SashForm) ICellEditorValidator(org.eclipse.jface.viewers.ICellEditorValidator) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) Clipboard(org.eclipse.swt.dnd.Clipboard) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

Clipboard (org.eclipse.swt.dnd.Clipboard)158 TextTransfer (org.eclipse.swt.dnd.TextTransfer)90 Transfer (org.eclipse.swt.dnd.Transfer)42 Point (org.eclipse.swt.graphics.Point)20 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 Composite (org.eclipse.swt.widgets.Composite)13 TableItem (org.eclipse.swt.widgets.TableItem)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)12 ISelection (org.eclipse.jface.viewers.ISelection)11 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)11 GridLayout (org.eclipse.swt.layout.GridLayout)11 StyledText (org.eclipse.swt.custom.StyledText)10 GridData (org.eclipse.swt.layout.GridData)9 Control (org.eclipse.swt.widgets.Control)9 Display (org.eclipse.swt.widgets.Display)8 Label (org.eclipse.swt.widgets.Label)8 Button (org.eclipse.swt.widgets.Button)7 ArrayList (java.util.ArrayList)6 IAction (org.eclipse.jface.action.IAction)6 Test (org.junit.Test)6