Search in sources :

Example 11 with TableEditor

use of org.eclipse.swt.custom.TableEditor in project tdi-studio-se by Talend.

the class PromptDefaultValueDialog method createCheckboxEditor.

private void createCheckboxEditor(TableItem item, int column, boolean checked) {
    TableEditor editor = new TableEditor(table);
    // bgColorCheck = new Color(check.getDisplay(), 28, 81, 128);
    final Button check = new Button(table, SWT.CHECK);
    check.setSelection(checked);
    check.setBackground(table.getBackground());
    editor.setEditor(check, item, column);
    editor.grabHorizontal = true;
    editor.layout();
    editors.add(editor);
}
Also used : Button(org.eclipse.swt.widgets.Button) TableEditor(org.eclipse.swt.custom.TableEditor)

Example 12 with TableEditor

use of org.eclipse.swt.custom.TableEditor 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 13 with TableEditor

use of org.eclipse.swt.custom.TableEditor in project cubrid-manager by CUBRID.

the class BatchRunComposite method createTableGroup.

private void createTableGroup(Composite composite) {
    final String[] columnNames = new String[] { "", com.cubrid.common.ui.query.Messages.msgBatchRunSqlFile, com.cubrid.common.ui.query.Messages.msgBatchRunMemo, com.cubrid.common.ui.query.Messages.msgBatchRunRegdate };
    tv = (CheckboxTableViewer) CommonUITool.createCheckBoxTableViewer(composite, null, columnNames, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
    tv.setInput(listData);
    TableLayout tableLayout = new TableLayout();
    tv.getTable().setLayout(tableLayout);
    tableLayout.addColumnData(new ColumnPixelData(30));
    tableLayout.addColumnData(new ColumnPixelData(209));
    tableLayout.addColumnData(new ColumnPixelData(272));
    tableLayout.addColumnData(new ColumnPixelData(118));
    editor = new TableEditor(tv.getTable());
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;
    tv.getTable().addListener(SWT.MouseUp, new Listener() {

        public void handleEvent(Event event) {
            if (event.button != 1) {
                return;
            }
            validateCheck();
            Point pt = new Point(event.x, event.y);
            int newIndex = tv.getTable().getSelectionIndex();
            if (tv.getTable().getItemCount() <= newIndex || newIndex < 0) {
                return;
            }
            final TableItem item = tv.getTable().getItem(newIndex);
            if (item == null) {
                return;
            }
            Rectangle rect = item.getBounds(2);
            if (rect.contains(pt)) {
                focusCell(item, newIndex, 2);
            }
        }
    });
}
Also used : Listener(org.eclipse.swt.widgets.Listener) TraverseListener(org.eclipse.swt.events.TraverseListener) TableItem(org.eclipse.swt.widgets.TableItem) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Rectangle(org.eclipse.swt.graphics.Rectangle) Event(org.eclipse.swt.widgets.Event) TraverseEvent(org.eclipse.swt.events.TraverseEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Point(org.eclipse.swt.graphics.Point) TableLayout(org.eclipse.jface.viewers.TableLayout) TableEditor(org.eclipse.swt.custom.TableEditor)

Example 14 with TableEditor

use of org.eclipse.swt.custom.TableEditor in project cubrid-manager by CUBRID.

the class MultiHostConnectionDialog method initTask.

public void initTask() {
    if (container == null)
        return;
    for (ConnectionTaskContainer con : container) {
        ServerInfo info = con.getServerInfo();
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(1, info.getServerName());
        TableEditor editor = new TableEditor(table);
        editor.grabHorizontal = editor.grabVertical = true;
        ProgressBar bar = new ProgressBar(table, SWT.NONE);
        editor.setEditor(bar, item, 2);
        con.setItem(item);
        item.setData(KEY_BAR, bar);
        item.setData(KEY_CONNECTION, con);
    }
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TableItem(org.eclipse.swt.widgets.TableItem) TableEditor(org.eclipse.swt.custom.TableEditor) ProgressBar(org.eclipse.swt.widgets.ProgressBar)

Example 15 with TableEditor

use of org.eclipse.swt.custom.TableEditor in project cubrid-manager by CUBRID.

the class DBSpaceLabelProvider method setDatabaseData.

private void setDatabaseData(final List<DatabaseInfo> databaseInfoList, final List<String> orignAutoStartDBList) {
    for (TableEditor editor : checkEditors) {
        editor.getEditor().dispose();
    }
    checkEditors.clear();
    databaseTable.removeAll();
    if (databaseInfoList != null) {
        for (int i = 0; i < databaseInfoList.size(); i++) {
            DatabaseInfo dbInfo = databaseInfoList.get(i);
            final TableItem item = new TableItem(databaseTable, SWT.None);
            item.setText(0, dbInfo.getDbName());
            TableEditor editor = null;
            /* check box */
            editor = new TableEditor(databaseTable);
            final Button check = new Button(databaseTable, SWT.CHECK);
            check.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
            check.setData(i);
            check.setFocus();
            check.pack();
            boolean isChecked = orignAutoStartDBList.contains(dbInfo.getDbName());
            check.setSelection(isChecked);
            item.setData("isChecked", isChecked);
            editor.minimumWidth = check.getSize().x;
            editor.horizontalAlignment = SWT.CENTER;
            editor.setEditor(check, item, 1);
            checkEditors.add(editor);
            check.addSelectionListener(new SelectionListener() {

                public void widgetSelected(SelectionEvent e) {
                    widgetDefaultSelected(e);
                }

                public void widgetDefaultSelected(SelectionEvent e) {
                    databaseTable.getItem((Integer) check.getData()).setData("isChecked", check.getSelection());
                    /*Update save item*/
                    Set<String> newSet = getNewAutoStartDB();
                    if (newSet.size() != orignAutoStartDBList.size()) {
                        isDirty = true;
                    } else {
                        boolean isChanged = false;
                        for (String dbName : orignAutoStartDBList) {
                            if (!newSet.contains(dbName)) {
                                isChanged = true;
                                break;
                            }
                        }
                        isDirty = isChanged;
                    }
                    updateToolBar();
                }
            });
            /* Status */
            if (dbInfo.getRunningType().equals(DbRunningType.STANDALONE)) {
                item.setText(2, Messages.lblStoped);
            } else {
                item.setText(2, Messages.lblRunning);
            }
        }
        if (bar != null && bar.getItemCount() > 4) {
            int height = databaseTable.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
            if (height < 80) {
                height = 80;
            }
            bar.getItem(3).setHeight(height);
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) Button(org.eclipse.swt.widgets.Button) TableItem(org.eclipse.swt.widgets.TableItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableEditor(org.eclipse.swt.custom.TableEditor) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

TableEditor (org.eclipse.swt.custom.TableEditor)39 TableItem (org.eclipse.swt.widgets.TableItem)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 GridData (org.eclipse.swt.layout.GridData)11 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 Point (org.eclipse.swt.graphics.Point)10 GridLayout (org.eclipse.swt.layout.GridLayout)7 Button (org.eclipse.swt.widgets.Button)7 CCombo (org.eclipse.swt.custom.CCombo)6 MouseEvent (org.eclipse.swt.events.MouseEvent)6 Event (org.eclipse.swt.widgets.Event)6 Listener (org.eclipse.swt.widgets.Listener)6 TraverseEvent (org.eclipse.swt.events.TraverseEvent)5 TraverseListener (org.eclipse.swt.events.TraverseListener)5 Rectangle (org.eclipse.swt.graphics.Rectangle)5 Composite (org.eclipse.swt.widgets.Composite)5 Label (org.eclipse.swt.widgets.Label)5 Table (org.eclipse.swt.widgets.Table)5 Text (org.eclipse.swt.widgets.Text)5 TableLayout (org.eclipse.jface.viewers.TableLayout)4