Search in sources :

Example 41 with TableEditor

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

the class TableEditorManager method createLabelEditor.

public TableEditor createLabelEditor(TableEditor editor, Table table, String displayText, TableItem item, int column) {
    if (editor == null) {
        editor = new TableEditor(table);
        editor.grabHorizontal = true;
        addEditor(item, column, editor);
    }
    final Label label = new Label(table, SWT.NONE);
    if (displayText != null) {
        label.setText(displayText);
    }
    editor.setEditor(label, item, column);
    addEditor(item, column, editor);
    return editor;
}
Also used : Label(org.eclipse.swt.widgets.Label) TableEditor(org.eclipse.swt.custom.TableEditor)

Example 42 with TableEditor

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

the class TableEditorManager method createComboEditor.

public TableEditor createComboEditor(Table table, String[] displayText, TableItem item, int column, int selectIndex, final IPropertySetter<Integer> accessor) {
    TableEditor editor = new TableEditor(table);
    final ColorCombo combo = new ColorCombo(table, SWT.READ_ONLY);
    for (String text : displayText) {
        combo.add(text);
    }
    if (accessor != null) {
        combo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                accessor.set(combo.getSelectionIndex());
            }
        });
    }
    combo.select(selectIndex);
    editor.grabHorizontal = true;
    editor.setEditor(combo, item, column);
    editor.minimumWidth = combo.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
    table.getColumn(column).setWidth(editor.minimumWidth);
    addEditor(item, column, editor);
    return editor;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableEditor(org.eclipse.swt.custom.TableEditor) ColorCombo(org.talend.designer.scd.ui.ColorCombo)

Example 43 with TableEditor

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

the class StatusManagerSettingPage method addItemElements.

private void addItemElements(List<RepositoryObject> elements) {
    if (elements == null || elements.isEmpty()) {
        return;
    }
    final Color redColor = Display.getDefault().getSystemColor(SWT.COLOR_RED);
    for (final RepositoryObject object : elements) {
        if (object.isDeleted()) {
            continue;
        }
        TableItem tableItem = null;
        // for bug 17692
        ERepositoryObjectType objectType = object.getRepositoryNode().getObjectType();
        ERepositoryObjectType type = object.getRepositoryNode().getContentType();
        if (!objectType.equals(ERepositoryObjectType.JOB_DOC) && !objectType.equals(ERepositoryObjectType.JOBLET_DOC)) {
            if (isTechinalStatus()) {
                // obj.equals(constant) that will cause NPE.
                if (!type.equals(ERepositoryObjectType.DOCUMENTATION) && !type.equals(ERepositoryObjectType.BUSINESS_PROCESS) && !type.equals(ERepositoryObjectType.JOBLET_DOC)) {
                    // if (!type.equals(ERepositoryObjectType.DOCUMENTATION) &&
                    // !type.equals(ERepositoryObjectType.BUSINESS_PROCESS)
                    // && !type.equals(ERepositoryObjectType.JOBLETS)) {
                    itemTable.setRedraw(false);
                    tableItem = new TableItem(itemTable, SWT.NONE);
                }
            } else if (isDocumentStatus()) {
                if (type.equals(ERepositoryObjectType.DOCUMENTATION) || type.equals(ERepositoryObjectType.BUSINESS_PROCESS)) {
                    itemTable.setRedraw(false);
                    tableItem = new TableItem(itemTable, SWT.NONE);
                }
            } else // bug 20078
            {
                itemTable.setRedraw(false);
                tableItem = new TableItem(itemTable, SWT.NONE);
            }
        } else {
            if (isDocumentStatus()) {
                if (type.equals(ERepositoryObjectType.JOB_DOC) || type.equals(ERepositoryObjectType.JOBLET_DOC)) {
                    itemTable.setRedraw(false);
                    tableItem = new TableItem(itemTable, SWT.NONE);
                }
            }
        }
        if (tableItem != null) {
            tableItem.setData(object);
            try {
                statusHelper.getStatusList(object.getProperty());
            } catch (PersistenceException e1) {
            // TODO Auto-generated catch block
            }
            object.getProperty().setOldStatusCode(statusHelper.getStatusCode(object.getStatusCode()));
            Image itemsImage = null;
            IBaseLabelProvider labelProvider = treeViewer.getLabelProvider();
            if (labelProvider instanceof NavigatorDecoratingLabelProvider) {
                NavigatorDecoratingLabelProvider navigatorProvider = (NavigatorDecoratingLabelProvider) labelProvider;
                itemsImage = navigatorProvider.getImage(object.getRepositoryNode());
            } else {
                ERepositoryObjectType itemType = object.getRepositoryObjectType();
                itemsImage = getItemsImage(CoreImageProvider.getIcon(itemType));
            }
            tableItem.setImage(itemsImage);
            tableItem.setText(object.getLabel());
            // old version
            tableItem.setText(1, statusHelper.getStatusLabel(object.getStatusCode()));
            TableEditor versionEditor = null;
            if (isFixedstatus()) {
                String version = statusCombo.getText();
                tableItem.setText(2, version);
                if (!object.getProperty().getOldStatusCode().equals(statusHelper.getStatusCode(version))) {
                    tableItem.setForeground(2, redColor);
                } else {
                    tableItem.setForeground(2, Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
                }
            } else {
                // new version
                versionEditor = new TableEditor(itemTable);
                Composite versionComposit = new Composite(itemTable, SWT.NONE);
                GridLayout layout = new GridLayout(3, false);
                layout.horizontalSpacing = 1;
                layout.verticalSpacing = 0;
                layout.marginHeight = 0;
                layout.marginWidth = 0;
                versionComposit.setLayout(layout);
                final CCombo statusItemCombo = new CCombo(versionComposit, SWT.BORDER | SWT.READ_ONLY);
                GridData data = new GridData(GridData.FILL_HORIZONTAL);
                statusItemCombo.setLayoutData(data);
                statusItemCombo.setEditable(false);
                if (!type.equals(ERepositoryObjectType.DOCUMENTATION) && !type.equals(ERepositoryObjectType.BUSINESS_PROCESS)) {
                    statusItemCombo.setItems(toArray(technicalStatusList));
                    statusItemCombo.select(0);
                    if (!object.getProperty().getOldStatusCode().equals("DEV")) {
                        statusItemCombo.setForeground(redColor);
                    } else {
                        statusItemCombo.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
                    }
                } else {
                    statusItemCombo.setItems(toArray(documentStatusList));
                    statusItemCombo.select(0);
                    if (!object.getProperty().getOldStatusCode().equals("UCK")) {
                        statusItemCombo.setForeground(redColor);
                    } else {
                        statusItemCombo.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
                    }
                }
                statusItemCombo.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        String version = statusItemCombo.getText();
                        String status = statusHelper.getStatusCode(version);
                        if (!status.equals(object.getProperty().getOldStatusCode())) {
                            statusItemCombo.setForeground(redColor);
                        }
                        object.getProperty().setStatusCode(statusHelper.getStatusCode(version));
                    }
                });
                versionEditor.minimumWidth = itemTable.getColumn(2).getWidth();
                versionEditor.setEditor(versionComposit, tableItem, 2);
            }
            TableEditor delEditor = new TableEditor(itemTable);
            Label delLabel = new Label(itemTable, SWT.CENTER);
            delLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
            delLabel.setImage(ImageProvider.getImage(EImage.DELETE_ICON));
            //$NON-NLS-1$
            delLabel.setToolTipText(Messages.getString("VersionManagementDialog.DeletedTip"));
            delLabel.pack();
            addLabelMouseListener(delLabel, object, tableItem);
            delEditor.minimumWidth = 25;
            delEditor.horizontalAlignment = SWT.CENTER;
            delEditor.setEditor(delLabel, tableItem, 3);
            if (isFixedstatus()) {
                tableItem.setData(ITEM_EDITOR_KEY, new TableEditor[] { delEditor });
            } else if (versionEditor != null) {
                tableItem.setData(ITEM_EDITOR_KEY, new TableEditor[] { versionEditor, delEditor });
            }
            itemTable.setRedraw(true);
        }
    }
}
Also used : RepositoryObject(org.talend.core.model.repository.RepositoryObject) Composite(org.eclipse.swt.widgets.Composite) NavigatorDecoratingLabelProvider(org.eclipse.ui.internal.navigator.NavigatorDecoratingLabelProvider) Color(org.eclipse.swt.graphics.Color) TableItem(org.eclipse.swt.widgets.TableItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) IImage(org.talend.commons.ui.runtime.image.IImage) Image(org.eclipse.swt.graphics.Image) EImage(org.talend.commons.ui.runtime.image.EImage) TableEditor(org.eclipse.swt.custom.TableEditor) GridLayout(org.eclipse.swt.layout.GridLayout) CCombo(org.eclipse.swt.custom.CCombo) PersistenceException(org.talend.commons.exception.PersistenceException) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 44 with TableEditor

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

the class VersionManagementPage method addItemElements.

@Override
protected void addItemElements(List<ItemVersionObject> elements) {
    if (elements == null || elements.isEmpty()) {
        return;
    }
    itemTable.setRedraw(false);
    final Color redColor = Display.getDefault().getSystemColor(SWT.COLOR_RED);
    for (final ItemVersionObject object : elements) {
        final TableItem tableItem = new TableItem(itemTable, SWT.NONE);
        tableItem.setData(object);
        Item item = object.getItem();
        IBaseLabelProvider labelProvider = treeViewer.getLabelProvider();
        Image itemsImage = null;
        if (labelProvider instanceof NavigatorDecoratingLabelProvider) {
            NavigatorDecoratingLabelProvider navigatorProvider = (NavigatorDecoratingLabelProvider) labelProvider;
            itemsImage = navigatorProvider.getImage(object.getRepositoryNode());
        } else {
            ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
            itemsImage = getItemsImage(CoreImageProvider.getIcon(itemType));
        }
        tableItem.setImage(itemsImage);
        tableItem.setText(item.getProperty().getLabel());
        // old version
        tableItem.setText(1, object.getOldVersion());
        TableEditor versionEditor = null;
        if (isFixedVersion()) {
            String version = fixedVersionText.getText();
            tableItem.setText(2, version);
            if (VersionUtils.compareTo(version, object.getOldVersion()) > 0) {
                tableItem.setForeground(2, redColor);
            } else {
                tableItem.setForeground(2, Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
            }
        } else {
            // new version
            versionEditor = new TableEditor(itemTable);
            Composite versionComposit = new Composite(itemTable, SWT.NONE);
            GridLayout layout = new GridLayout(3, false);
            layout.horizontalSpacing = 1;
            layout.verticalSpacing = 0;
            layout.marginHeight = 0;
            layout.marginWidth = 0;
            versionComposit.setLayout(layout);
            final Text text = new Text(versionComposit, SWT.BORDER | SWT.READ_ONLY);
            GridData data = new GridData(GridData.FILL_HORIZONTAL);
            text.setLayoutData(data);
            text.setEditable(false);
            text.setText(object.getNewVersion());
            if (VersionUtils.compareTo(object.getNewVersion(), object.getOldVersion()) > 0) {
                text.setForeground(redColor);
            } else {
                text.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
            }
            Button tableMajorBtn = new Button(versionComposit, SWT.NONE);
            //$NON-NLS-1$
            tableMajorBtn.setText("M");
            //$NON-NLS-1$
            tableMajorBtn.setToolTipText(Messages.getString("VersionManagementDialog.MajorVersionTip"));
            Button tableMinorBtn = new Button(versionComposit, SWT.NONE);
            //$NON-NLS-1$
            tableMinorBtn.setText("m");
            //$NON-NLS-1$
            tableMinorBtn.setToolTipText(Messages.getString("VersionManagementDialog.MinorVersionTip"));
            tableMajorBtn.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String version = object.getNewVersion();
                    version = VersionUtils.upMajor(version);
                    text.setText(version);
                    text.setForeground(redColor);
                    object.setNewVersion(version);
                }
            });
            tableMinorBtn.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String version = object.getNewVersion();
                    version = VersionUtils.upMinor(version);
                    text.setText(version);
                    text.setForeground(redColor);
                    object.setNewVersion(version);
                }
            });
            versionEditor.minimumWidth = itemTable.getColumn(2).getWidth();
            versionEditor.setEditor(versionComposit, tableItem, 2);
        }
        TableEditor delEditor = new TableEditor(itemTable);
        Label delLabel = new Label(itemTable, SWT.CENTER);
        delLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
        delLabel.setImage(ImageProvider.getImage(EImage.DELETE_ICON));
        //$NON-NLS-1$
        delLabel.setToolTipText(Messages.getString("VersionManagementDialog.DeletedTip"));
        delLabel.pack();
        delLabel.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                checkedObjects.remove(object);
                removeTableItem(tableItem);
                refreshCheckedTreeView();
                checkButtonsState();
                checkButtonsState(false);
            }
        });
        delEditor.minimumWidth = 25;
        delEditor.horizontalAlignment = SWT.CENTER;
        delEditor.setEditor(delLabel, tableItem, 3);
        if (isFixedVersion()) {
            tableItem.setData(ITEM_EDITOR_KEY, new TableEditor[] { delEditor });
        } else if (versionEditor != null) {
            tableItem.setData(ITEM_EDITOR_KEY, new TableEditor[] { versionEditor, delEditor });
        }
        itemTable.setRedraw(true);
    }
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) NavigatorDecoratingLabelProvider(org.eclipse.ui.internal.navigator.NavigatorDecoratingLabelProvider) Color(org.eclipse.swt.graphics.Color) TableItem(org.eclipse.swt.widgets.TableItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) Image(org.eclipse.swt.graphics.Image) EImage(org.talend.commons.ui.runtime.image.EImage) TableEditor(org.eclipse.swt.custom.TableEditor) Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 45 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)

Aggregations

TableEditor (org.eclipse.swt.custom.TableEditor)48 TableItem (org.eclipse.swt.widgets.TableItem)25 GridData (org.eclipse.swt.layout.GridData)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)17 Point (org.eclipse.swt.graphics.Point)15 Button (org.eclipse.swt.widgets.Button)15 GridLayout (org.eclipse.swt.layout.GridLayout)14 Text (org.eclipse.swt.widgets.Text)14 CCombo (org.eclipse.swt.custom.CCombo)12 Label (org.eclipse.swt.widgets.Label)12 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 Table (org.eclipse.swt.widgets.Table)10 Rectangle (org.eclipse.swt.graphics.Rectangle)9 Composite (org.eclipse.swt.widgets.Composite)9 Control (org.eclipse.swt.widgets.Control)9 TableColumn (org.eclipse.swt.widgets.TableColumn)8 Event (org.eclipse.swt.widgets.Event)7 Group (org.eclipse.swt.widgets.Group)7 Listener (org.eclipse.swt.widgets.Listener)7 SWT (org.eclipse.swt.SWT)6