Search in sources :

Example 1 with ListParameter

use of org.talend.designer.rowgenerator.data.ListParameter 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)

Aggregations

TableViewer (org.eclipse.jface.viewers.TableViewer)1 CCombo (org.eclipse.swt.custom.CCombo)1 TableEditor (org.eclipse.swt.custom.TableEditor)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 FocusListener (org.eclipse.swt.events.FocusListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 Control (org.eclipse.swt.widgets.Control)1 Table (org.eclipse.swt.widgets.Table)1 TableItem (org.eclipse.swt.widgets.TableItem)1 ListParameter (org.talend.designer.rowgenerator.data.ListParameter)1 Parameter (org.talend.designer.rowgenerator.data.Parameter)1