Search in sources :

Example 26 with TableEditor

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

the class FunParaTableView2 method updateData.

private void updateData(List<Parameter> params) {
    final Table table = this.getTable();
    final TableViewer viewer = this.getTableViewerCreator().getTableViewer();
    final TableEditor editor = new TableEditor(table);
    // The editor must have the same size as the cell and must
    // editing the Third column
    final int eDITABLECOLUMN = 2;
    table.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // Clean up any previous editor control
            Control oldEditor = editor.getEditor();
            if (oldEditor != null) {
                oldEditor.dispose();
            }
            // Identify the selected row
            TableItem item = (TableItem) e.item;
            if (item == null) {
                return;
            }
            Parameter param = (Parameter) item.getData();
            if (param instanceof ListParameter) {
                createCombo((ListParameter) param, item);
            }
        }

        private void createCombo(final ListParameter list, TableItem item) {
            final CCombo combo = new CCombo(table, SWT.NONE);
            combo.setItems(list.getValues());
            combo.setFocus();
            editor.setEditor(combo, item, eDITABLECOLUMN);
            combo.setText(list.getValue());
            Point size = combo.computeSize(SWT.DEFAULT, table.getItemHeight());
            // Set attributes of the editor
            editor.horizontalAlignment = SWT.LEFT;
            editor.minimumHeight = size.y;
            editor.minimumWidth = size.x;
            combo.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    list.setValue(combo.getText());
                    viewer.refresh(list);
                    ext.setChanged(true);
                    rowGenTableEditor2.getTableViewerCreator().getTableViewer().refresh();
                }
            });
            combo.addFocusListener(new FocusListener() {

                public void focusGained(FocusEvent e) {
                }

                /**
                     * Sent when a control loses focus.
                     * 
                     * @param e an event containing information about the focus change
                     */
                public void focusLost(FocusEvent e) {
                    combo.dispose();
                }
            });
        }
    });
    getTableViewerCreator().setInputList(params);
}
Also used : Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point) TableEditor(org.eclipse.swt.custom.TableEditor) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) Control(org.eclipse.swt.widgets.Control) CCombo(org.eclipse.swt.custom.CCombo) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Parameter(org.talend.designer.rowgenerator.data.Parameter) ListParameter(org.talend.designer.rowgenerator.data.ListParameter) ListParameter(org.talend.designer.rowgenerator.data.ListParameter) TableViewer(org.eclipse.jface.viewers.TableViewer) FocusListener(org.eclipse.swt.events.FocusListener)

Example 27 with TableEditor

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

the class PromptDefaultValueDialog method createTextEditor.

private void createTextEditor(TableItem item, int column, String displayText) {
    TableEditor editor = new TableEditor(table);
    final Text text = new Text(table, SWT.NONE);
    text.setText(displayText);
    editor.setEditor(text, item, column);
    editor.grabHorizontal = true;
    editor.layout();
    editors.add(editor);
}
Also used : Text(org.eclipse.swt.widgets.Text) TableEditor(org.eclipse.swt.custom.TableEditor)

Example 28 with TableEditor

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

the class PromptDefaultValueDialog method close.

@Override
public boolean close() {
    for (TableEditor editor : editors) {
        Control control = editor.getEditor();
        if (control != null && !control.isDisposed()) {
            control.dispose();
        }
        editor.dispose();
    }
    editors.clear();
    return super.close();
}
Also used : Control(org.eclipse.swt.widgets.Control) TableEditor(org.eclipse.swt.custom.TableEditor)

Example 29 with TableEditor

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

the class PromptDefaultValueDialog method createTable.

/**
     * DOC hcw Comment method "createTableViewer".
     * 
     * @param parent
     */
private void createTable(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    table = new Table(composite, SWT.BORDER);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    table.setLayoutData(gd);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    TableColumn nameColumn = new TableColumn(table, SWT.NONE);
    nameColumn.setWidth(120);
    //$NON-NLS-1$
    nameColumn.setText(Messages.getString("PromptDefaultValueDialog.column"));
    TableColumn defaultColumn = new TableColumn(table, SWT.NONE);
    defaultColumn.setWidth(108);
    //$NON-NLS-1$
    defaultColumn.setText(Messages.getString("PromptDefaultValueDialog.defaultValue"));
    editors = new ArrayList<TableEditor>();
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) TableColumn(org.eclipse.swt.widgets.TableColumn) TableEditor(org.eclipse.swt.custom.TableEditor)

Example 30 with TableEditor

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

the class PromptDefaultValueDialog method okPressed.

@Override
protected void okPressed() {
    for (TableEditor editor : editors) {
        Control control = editor.getEditor();
        TableItem item = editor.getItem();
        ColumnInfo row = (ColumnInfo) item.getData();
        EParameterFieldType field = row.parameter.getFieldType();
        if (field == EParameterFieldType.CHECK) {
            Button button = (Button) control;
            row.defaultValue = button.getSelection();
        } else if (field == EParameterFieldType.TEXT) {
            Text text = (Text) control;
            row.defaultValue = text.getText();
        } else if (field == EParameterFieldType.CLOSED_LIST || field == EParameterFieldType.PREV_COLUMN_LIST) {
            CCombo combo = (CCombo) control;
            int index = combo.getSelectionIndex();
            Object[] values = row.parameter.getListItemsValue();
            if (values.length > index && index != -1) {
                row.defaultValue = values[index];
            }
        }
    }
    super.okPressed();
}
Also used : Control(org.eclipse.swt.widgets.Control) EParameterFieldType(org.talend.core.model.process.EParameterFieldType) CCombo(org.eclipse.swt.custom.CCombo) Button(org.eclipse.swt.widgets.Button) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) TableEditor(org.eclipse.swt.custom.TableEditor)

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