Search in sources :

Example 96 with TableEditor

use of org.eclipse.swt.custom.TableEditor in project cicada by aquariusStudio.

the class PTDateEditor method render.

/**
 * @see org.eclipse.nebula.widgets.opal.propertytable.editor.PTEditor#render(org.eclipse.nebula.widgets.opal.propertytable.PTWidget,
 *      org.eclipse.swt.widgets.Item,
 *      org.eclipse.nebula.widgets.opal.propertytable.PTProperty)
 */
@Override
public ControlEditor render(final PTWidget widget, final Item item, final PTProperty property) {
    ControlEditor editor;
    if (widget.getWidget() instanceof Table) {
        editor = new TableEditor((Table) widget.getWidget());
    } else {
        editor = new TreeEditor((Tree) widget.getWidget());
    }
    final DateTime dateEditor = new DateTime(widget.getWidget(), SWT.DATE | SWT.MEDIUM | SWT.DROP_DOWN);
    final Date date = (Date) property.getValue();
    final Calendar c = Calendar.getInstance();
    if (date != null) {
        c.setTime(date);
        dateEditor.setDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
    }
    dateEditor.addListener(SWT.Selection, e -> {
        c.setTime(new Date());
        c.clear();
        c.set(dateEditor.getYear(), dateEditor.getMonth(), dateEditor.getDay());
        property.setValue(c.getTime());
    });
    dateEditor.addListener(SWT.FocusIn, event -> {
        widget.updateDescriptionPanel(property);
    });
    editor.grabHorizontal = true;
    editor.horizontalAlignment = SWT.LEFT;
    if (widget.getWidget() instanceof Table) {
        ((TableEditor) editor).setEditor(dateEditor, (TableItem) item, 1);
    } else {
        ((TreeEditor) editor).setEditor(dateEditor, (TreeItem) item, 1);
    }
    dateEditor.setEnabled(property.isEnabled());
    return editor;
}
Also used : ControlEditor(org.eclipse.swt.custom.ControlEditor) Table(org.eclipse.swt.widgets.Table) TreeEditor(org.eclipse.swt.custom.TreeEditor) Calendar(java.util.Calendar) Tree(org.eclipse.swt.widgets.Tree) TableEditor(org.eclipse.swt.custom.TableEditor) DateTime(org.eclipse.swt.widgets.DateTime) Date(java.util.Date)

Example 97 with TableEditor

use of org.eclipse.swt.custom.TableEditor in project cicada by aquariusStudio.

the class PTSpinnerEditor method render.

/**
 * @see org.eclipse.nebula.widgets.opal.propertytable.editor.PTEditor#render(org.eclipse.nebula.widgets.opal.propertytable.PTWidget,
 *      org.eclipse.swt.widgets.Item,
 *      org.eclipse.nebula.widgets.opal.propertytable.PTProperty)
 */
@Override
public ControlEditor render(final PTWidget widget, final Item item, final PTProperty property) {
    ControlEditor editor;
    if (widget.getWidget() instanceof Table) {
        editor = new TableEditor((Table) widget.getWidget());
    } else {
        editor = new TreeEditor((Tree) widget.getWidget());
    }
    final Spinner spinner = new Spinner(widget.getWidget(), SWT.HORIZONTAL);
    spinner.setMinimum(min);
    spinner.setMaximum(max);
    final Integer originalValue = (Integer) property.getValue();
    spinner.setSelection(originalValue == null ? min : originalValue.intValue());
    spinner.addListener(SWT.FocusIn, event -> {
        widget.updateDescriptionPanel(property);
    });
    spinner.addListener(SWT.Modify, event -> {
        property.setValue(Integer.valueOf(spinner.getSelection()));
    });
    editor.grabHorizontal = true;
    if (widget.getWidget() instanceof Table) {
        ((TableEditor) editor).setEditor(spinner, (TableItem) item, 1);
    } else {
        ((TreeEditor) editor).setEditor(spinner, (TreeItem) item, 1);
    }
    spinner.setEnabled(property.isEnabled());
    return editor;
}
Also used : ControlEditor(org.eclipse.swt.custom.ControlEditor) Table(org.eclipse.swt.widgets.Table) TreeEditor(org.eclipse.swt.custom.TreeEditor) Spinner(org.eclipse.swt.widgets.Spinner) Tree(org.eclipse.swt.widgets.Tree) TableEditor(org.eclipse.swt.custom.TableEditor)

Example 98 with TableEditor

use of org.eclipse.swt.custom.TableEditor in project convertigo by convertigo.

the class SharedComponentWizardPage2Composite method initialize.

private void initialize() {
    setLayout(new GridLayout(1, false));
    Label labelTable = new Label(this, SWT.NONE);
    labelTable.setText("The table below helps selecting a variable to change its name. Click on the 'Finish' button when done.");
    table = new Table(this, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn columnVar = new TableColumn(table, SWT.NONE);
    columnVar.setWidth(500);
    columnVar.setText("Informations");
    TableColumn columnInfos = new TableColumn(table, SWT.NONE);
    columnInfos.setWidth(100);
    columnInfos.setText("Variable");
    for (String var_name : tableMap.keySet()) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, tableMap.get(var_name));
        item.setText(1, var_name);
    }
    tableEditor = new TableEditor(table);
    tableEditor.horizontalAlignment = SWT.LEFT;
    tableEditor.grabHorizontal = true;
    tableEditor.minimumWidth = 50;
    final int EDITABLECOLUMN = 1;
    table.addSelectionListener(widgetSelectedAdapter(e -> {
        Control oldEditor = tableEditor.getEditor();
        if (oldEditor != null)
            oldEditor.dispose();
        TableItem item = (TableItem) e.item;
        if (item == null)
            return;
        Text newEditor = new Text(table, SWT.NONE);
        newEditor.setText(item.getText(EDITABLECOLUMN));
        newEditor.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                updatePageStatus(((Text) tableEditor.getEditor()).getText(), false);
            }
        });
        newEditor.addTraverseListener(new TraverseListener() {

            public void keyTraversed(TraverseEvent e) {
                if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN) {
                    updatePageStatus(null, true);
                    Text text = (Text) tableEditor.getEditor();
                    String name = text.getText();
                    if (e.detail == SWT.TRAVERSE_RETURN && isValidName(name)) {
                        tableEditor.getItem().setText(EDITABLECOLUMN, name);
                        updatePageStatus(name, true);
                    }
                    text.dispose();
                    e.doit = false;
                }
            }
        });
        newEditor.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                updatePageStatus(null, true);
            }

            @Override
            public void focusGained(FocusEvent e) {
                updatePageStatus(null, false);
            }
        });
        newEditor.selectAll();
        newEditor.setFocus();
        tableEditor.setEditor(newEditor, item, EDITABLECOLUMN);
    }));
    this.setSize(new org.eclipse.swt.graphics.Point(514, 264));
}
Also used : TableEditor(org.eclipse.swt.custom.TableEditor) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) StringUtils(com.twinsoft.convertigo.engine.util.StringUtils) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) FocusEvent(org.eclipse.swt.events.FocusEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) Table(org.eclipse.swt.widgets.Table) Collectors(java.util.stream.Collectors) FocusListener(org.eclipse.swt.events.FocusListener) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) SWT(org.eclipse.swt.SWT) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Table(org.eclipse.swt.widgets.Table) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) TraverseListener(org.eclipse.swt.events.TraverseListener) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) TableEditor(org.eclipse.swt.custom.TableEditor) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) FocusListener(org.eclipse.swt.events.FocusListener)

Example 99 with TableEditor

use of org.eclipse.swt.custom.TableEditor in project convertigo by convertigo.

the class SharedComponentWizardPage2Composite method initialize.

private void initialize() {
    setLayout(new GridLayout(1, false));
    Label labelTable = new Label(this, SWT.NONE);
    labelTable.setText("The table below helps selecting a variable to change its name. Click on the 'Finish' button when done.");
    table = new Table(this, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn columnVar = new TableColumn(table, SWT.NONE);
    columnVar.setWidth(500);
    columnVar.setText("Informations");
    TableColumn columnInfos = new TableColumn(table, SWT.NONE);
    columnInfos.setWidth(100);
    columnInfos.setText("Variable");
    for (String var_name : tableMap.keySet()) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, tableMap.get(var_name));
        item.setText(1, var_name);
    }
    tableEditor = new TableEditor(table);
    tableEditor.horizontalAlignment = SWT.LEFT;
    tableEditor.grabHorizontal = true;
    tableEditor.minimumWidth = 50;
    final int EDITABLECOLUMN = 1;
    table.addSelectionListener(widgetSelectedAdapter(e -> {
        Control oldEditor = tableEditor.getEditor();
        if (oldEditor != null)
            oldEditor.dispose();
        TableItem item = (TableItem) e.item;
        if (item == null)
            return;
        Text newEditor = new Text(table, SWT.NONE);
        newEditor.setText(item.getText(EDITABLECOLUMN));
        newEditor.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                updatePageStatus(((Text) tableEditor.getEditor()).getText(), false);
            }
        });
        newEditor.addTraverseListener(new TraverseListener() {

            public void keyTraversed(TraverseEvent e) {
                if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN) {
                    updatePageStatus(null, true);
                    Text text = (Text) tableEditor.getEditor();
                    String name = text.getText();
                    if (e.detail == SWT.TRAVERSE_RETURN && isValidName(name)) {
                        tableEditor.getItem().setText(EDITABLECOLUMN, name);
                        updatePageStatus(name, true);
                    }
                    text.dispose();
                    e.doit = false;
                }
            }
        });
        newEditor.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                updatePageStatus(null, true);
            }

            @Override
            public void focusGained(FocusEvent e) {
                updatePageStatus(null, false);
            }
        });
        newEditor.selectAll();
        newEditor.setFocus();
        tableEditor.setEditor(newEditor, item, EDITABLECOLUMN);
    }));
    this.setSize(new org.eclipse.swt.graphics.Point(514, 264));
}
Also used : TableEditor(org.eclipse.swt.custom.TableEditor) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) StringUtils(com.twinsoft.convertigo.engine.util.StringUtils) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) FocusEvent(org.eclipse.swt.events.FocusEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) Table(org.eclipse.swt.widgets.Table) Collectors(java.util.stream.Collectors) FocusListener(org.eclipse.swt.events.FocusListener) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) SWT(org.eclipse.swt.SWT) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Table(org.eclipse.swt.widgets.Table) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) TraverseListener(org.eclipse.swt.events.TraverseListener) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) TableEditor(org.eclipse.swt.custom.TableEditor) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) FocusListener(org.eclipse.swt.events.FocusListener)

Example 100 with TableEditor

use of org.eclipse.swt.custom.TableEditor in project ecf by eclipse.

the class SearchContactDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    final int editableColumn = 1;
    try {
        parent = (Composite) super.createDialogArea(parent);
        parent.setLayout(new GridLayout(2, false));
        String[] fields = null;
        IUserSearchManager userManager = account.getPresenceContainerAdapter().getUserSearchManager();
        fields = userManager.getUserPropertiesFields();
        GridData searchButtonData = new GridData(SWT.RIGHT, GridData.FILL_HORIZONTAL, false, false, 1, 1);
        GridData addContactData = new GridData(SWT.RIGHT, GridData.FILL_HORIZONTAL, true, false, 1, 1);
        Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
        group.setLayout(new GridLayout(2, false));
        group.setText(Messages.SearchContactDialog_InfoSearchFields);
        Group groupContact = new Group(parent, SWT.SHADOW_ETCHED_IN);
        groupContact.setLayout(new GridLayout(2, false));
        groupContact.setText(Messages.SearchContactDialog_InfoContactFields);
        tableResult = new Table(groupContact, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
        tableResult.setLinesVisible(true);
        tableResult.setHeaderVisible(true);
        GridData dataTable = new GridData(GridData.FILL_HORIZONTAL, GridData.FILL_VERTICAL, true, true, 2, 1);
        dataTable.heightHint = 200;
        tableResult.setLayoutData(dataTable);
        new TableColumn(tableResult, SWT.NONE).setText(Messages.SearchContactDialog_TableResultColumnName);
        new TableColumn(tableResult, SWT.NONE).setText(Messages.SearchContactDialog_TableResultColumnUsername);
        new TableItem(tableResult, SWT.NONE);
        for (int i = 0; i < 2; i++) {
            tableResult.getColumn(i).setWidth(130);
        }
        addContactButton = new Button(groupContact, SWT.PUSH | SWT.RIGHT);
        addContactButton.setText(Messages.SearchContactDialog_ButtonAddContact);
        addContactButton.setLayoutData(addContactData);
        tableFields = new Table(group, SWT.BORDER | SWT.MULTI | SWT.CHECK);
        tableFields.setLinesVisible(true);
        tableFields.setHeaderVisible(true);
        dataTable = new GridData(GridData.FILL_HORIZONTAL, GridData.FILL_VERTICAL, true, true, 2, 1);
        dataTable.heightHint = 200;
        tableFields.setLayoutData(dataTable);
        TableColumn colField = new TableColumn(tableFields, SWT.NONE);
        colField.setText(Messages.SearchContactDialog_TableSearchColumnField);
        TableColumn colValue = new TableColumn(tableFields, SWT.NONE);
        colValue.setText(Messages.SearchContactDialog_TableSearchColumnValue);
        colValue.setWidth(130);
        for (int i = 0; i < fields.length; i++) {
            TableItem item = new TableItem(tableFields, SWT.NONE);
            // $NON-NLS-1$
            item.setText(new String[] { fields[i], "" });
            item.setChecked(true);
        }
        TableItem[] items = tableFields.getItems();
        for (int i = 0; i < items.length; i++) {
            final TableEditor editor = new TableEditor(tableFields);
            Text text = new Text(tableFields, SWT.NONE);
            text.setText(items[i].getText(editableColumn));
            text.addModifyListener(new ModifyListener() {

                public void modifyText(ModifyEvent e) {
                    editor.getItem().setText(editableColumn, ((Text) editor.getEditor()).getText());
                }
            });
            text.selectAll();
            text.setFocus();
            editor.grabHorizontal = true;
            editor.setEditor(text, items[i], editableColumn);
        }
        colField.pack();
        runInBackgroundButton = new Button(group, SWT.CHECK);
        runInBackgroundButton.setText(Messages.SearchContactDialog_RunInBackground);
        runInBackgroundButton.setToolTipText(Messages.SearchContactDialog_RunInBackGroundToolTip);
        searchButton = new Button(group, SWT.PUSH | SWT.RIGHT);
        searchButton.setText(Messages.SearchContactDialog_ButtonSearch);
        searchButton.setLayoutData(searchButtonData);
    } catch (ECFException e) {
        Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getLocalizedMessage(), e));
        new Label(parent, SWT.LEFT).setText(e.getLocalizedMessage());
    }
    addListeners();
    applyDialogFont(parent);
    return parent;
}
Also used : TableEditor(org.eclipse.swt.custom.TableEditor) GridLayout(org.eclipse.swt.layout.GridLayout) ECFException(org.eclipse.ecf.core.util.ECFException) GridData(org.eclipse.swt.layout.GridData)

Aggregations

TableEditor (org.eclipse.swt.custom.TableEditor)124 TableItem (org.eclipse.swt.widgets.TableItem)60 GridData (org.eclipse.swt.layout.GridData)52 Table (org.eclipse.swt.widgets.Table)49 Button (org.eclipse.swt.widgets.Button)41 Text (org.eclipse.swt.widgets.Text)40 GridLayout (org.eclipse.swt.layout.GridLayout)36 Point (org.eclipse.swt.graphics.Point)33 SelectionEvent (org.eclipse.swt.events.SelectionEvent)31 Composite (org.eclipse.swt.widgets.Composite)30 Label (org.eclipse.swt.widgets.Label)29 TableColumn (org.eclipse.swt.widgets.TableColumn)27 CCombo (org.eclipse.swt.custom.CCombo)26 SWT (org.eclipse.swt.SWT)23 Control (org.eclipse.swt.widgets.Control)23 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)20 Rectangle (org.eclipse.swt.graphics.Rectangle)17 FocusEvent (org.eclipse.swt.events.FocusEvent)15 ModifyEvent (org.eclipse.swt.events.ModifyEvent)14 ModifyListener (org.eclipse.swt.events.ModifyListener)14