Search in sources :

Example 1 with AddPushButton

use of org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButton in project tdi-studio-se by Talend.

the class PropertiesTableToolbarEditorView method createAddPushButton.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.ui.extended.ExtendedToolbarView#createAddPushButton()
     */
@Override
protected AddPushButton createAddPushButton() {
    final AddPushButton addPushButton = new AddPushButtonForExtendedTable(this.toolbar, getExtendedTableViewer()) {

        @Override
        public boolean getEnabledState() {
            if (model != null && !model.getElemParameter().getElement().isReadOnly() && (model.getElemParameter().getName().equals("HADOOP_ADVANCED_PROPERTIES") || model.getElemParameter().getName().equals("HBASE_PARAMETERS") || model.getElemParameter().getName().equals("SPARK_ADVANCED_PROPERTIES")) && !model.getElemParameter().isRepositoryValueUsed()) {
                return true;
            }
            return super.getEnabledState() && (model == null || !model.getElemParameter().isBasedOnSubjobStarts());
        }

        @Override
        protected Object getObjectToAdd() {
            PropertiesTableEditorModel tableEditorModel = (PropertiesTableEditorModel) getExtendedTableViewer().getExtendedControlModel();
            if (!tableEditorModel.isButtonEnabled()) {
                MessageDialog.openInformation(tableEditorModel.getTableViewer().getControl().getShell(), "Information", "All output columns have been added already");
                return null;
            }
            Object newEntry = tableEditorModel.createNewEntry();
            if (tableEditorModel.isAggregateRow() && newEntry instanceof Map) {
                List<ColumnInfo> tableInputs = new ArrayList<ColumnInfo>();
                String[] displayNames = tableEditorModel.getElemParameter().getListItemsDisplayName();
                Object[] itemsValue = tableEditorModel.getElemParameter().getListItemsValue();
                // default name //$NON-NLS-1$
                String paramColumnsName = "COLUMN";
                for (int i = 0; i < itemsValue.length; i++) {
                    if (itemsValue[i] instanceof IElementParameter) {
                        IElementParameter tableParameter = (IElementParameter) itemsValue[i];
                        if (tableParameter.getFieldType().equals(EParameterFieldType.COLUMN_LIST)) {
                            paramColumnsName = tableParameter.getName();
                        } else {
                            ColumnInfo row = new ColumnInfo();
                            row.name = displayNames[i];
                            row.parameter = tableParameter;
                            row.defaultValue = "";
                            tableInputs.add(row);
                        }
                    }
                }
                Node node = (Node) tableEditorModel.getElement();
                String outputTableName = null;
                if (node.getMetadataList() != null && !node.getMetadataList().isEmpty()) {
                    IMetadataTable metadata = node.getMetadataList().get(0);
                    if (metadata.getListColumns() != null) {
                        for (IMetadataColumn column : metadata.getListColumns()) {
                            if (!tableEditorModel.exist(column.getLabel())) {
                                outputTableName = column.getLabel();
                                break;
                            }
                        }
                    }
                }
                if (outputTableName != null) {
                    Map mapObject = (Map) newEntry;
                    if (mapObject.containsKey(paramColumnsName)) {
                        mapObject.put(paramColumnsName, outputTableName);
                    }
                    for (ColumnInfo col : tableInputs) {
                        Object defaultValue = col.defaultValue;
                        Object found = findDefaultName(outputTableName, col);
                        if (found != null && !"".equals(found)) {
                            defaultValue = found;
                        }
                        if (defaultValue != null && !"".equals(defaultValue)) {
                            mapObject.put(col.parameter.getName(), defaultValue);
                        }
                    }
                }
            }
            return newEntry;
        }
    };
    // TDI-6568, after added, fire change
    addPushButton.addListener(getPropertyChangeListener(), false);
    return addPushButton;
}
Also used : AddPushButton(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButton) AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) ColumnInfo(org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PromptDefaultValueDialog.ColumnInfo) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AddPushButton

use of org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButton in project tdi-studio-se by Talend.

the class SetLoopFunctionDialog method createDialogArea.

public Control createDialogArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.BORDER);
    GridLayout layout = new GridLayout();
    composite.setLayout(layout);
    GridData data = new GridData(GridData.FILL_BOTH);
    composite.setLayoutData(data);
    tableViwer = new AbstractDataTableEditorView<TreeSchemaTableEntry>(composite, SWT.NONE, tableModel, false, true, false) {

        @Override
        protected void createColumns(TableViewerCreator<TreeSchemaTableEntry> tableViewerCreator, Table table) {
            TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
            column.setTitle("Sequence");
            column.setWeight(40);
            column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeSchemaTableEntry, Object>() {

                public Object get(TreeSchemaTableEntry bean) {
                    int index = getExtendedTableModel().getBeansList().indexOf(bean);
                    return getExtendedTableModel().getBeansList().indexOf(bean);
                }

                public void set(TreeSchemaTableEntry bean, Object value) {
                // do nothing
                }
            });
            column = new TableViewerCreatorColumn(tableViewerCreator);
            column.setTitle("Xpath");
            column.setWeight(60);
            String[] items = new String[inputLoops.size()];
            for (int i = 0; i < inputLoops.size(); i++) {
                items[i] = inputLoops.get(i).getXpath();
            }
            CellEditorValueAdapter comboValueAdapter = CellEditorValueAdapterFactory.getComboAdapterForComboCellEditor("String");
            ComboBoxCellEditor cellEditor = new ComboBoxCellEditor(tableViewerCreator.getTable(), items, SWT.READ_ONLY);
            column.setModifiable(true);
            column.setCellEditor(cellEditor, comboValueAdapter);
            column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeSchemaTableEntry, Object>() {

                public Object get(TreeSchemaTableEntry bean) {
                    return bean.getXPath();
                }

                public void set(TreeSchemaTableEntry bean, Object value) {
                    for (TreeNode loopNode : inputLoops) {
                        if (loopNode.getXpath().equals(value)) {
                            bean.setTreeNode(loopNode);
                        }
                    }
                }
            });
        }

        @Override
        protected ExtendedToolbarView initToolBar() {
            ExtendedToolbarView toolbarView = new ExtendedToolbarView(getMainComposite(), SWT.NONE, this.getExtendedTableViewer()) {

                @Override
                protected CopyPushButton createCopyPushButton() {
                    return null;
                }

                @Override
                protected AddPushButton createAddPushButton() {
                    return new AddPushButtonForExtendedTable(this.toolbar, getExtendedTableViewer()) {

                        @Override
                        public boolean getEnabledState() {
                            return super.getEnabledState();
                        }

                        @Override
                        protected Object getObjectToAdd() {
                            TreeNode loopNodetoAdd = null;
                            for (TreeNode loopNode : inputLoops) {
                                boolean found = false;
                                for (TreeSchemaTableEntry extendedModel : getExtendedTableModel().getBeansList()) {
                                    if (loopNode.getXpath().equals(extendedModel.getXPath())) {
                                        found = true;
                                        break;
                                    }
                                }
                                if (!found) {
                                    loopNodetoAdd = loopNode;
                                    break;
                                }
                            }
                            if (loopNodetoAdd == null && !inputLoops.isEmpty()) {
                                loopNodetoAdd = inputLoops.get(0);
                            }
                            if (loopNodetoAdd != null) {
                                TreeSchemaTableEntry entry = new TreeSchemaTableEntry(loopNodetoAdd);
                                return entry;
                            }
                            return null;
                        }
                    };
                }
            };
            return super.initToolBar();
        }
    };
    tableViwer.setGridDataSize(400, 120);
    statusLabel = new Label(composite, SWT.NONE);
    statusLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    tableModel.addAfterOperationListListener(new IListenableListListener<TreeSchemaTableEntry>() {

        public void handleEvent(ListenableListEvent<TreeSchemaTableEntry> event) {
            updateStatus(true);
        }
    });
    tableModel.setModifiedBeanListenable(tableViwer.getTableViewerCreator());
    tableModel.addModifiedBeanListener(new IModifiedBeanListener<TreeSchemaTableEntry>() {

        public void handleEvent(ModifiedBeanEvent<TreeSchemaTableEntry> event) {
            updateStatus(false);
        }
    });
    return composite;
}
Also used : AddPushButton(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButton) Table(org.eclipse.swt.widgets.Table) AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) InputLoopNodesTable(org.talend.designer.xmlmap.model.emf.xmlmap.InputLoopNodesTable) AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) GridLayout(org.eclipse.swt.layout.GridLayout) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) GridData(org.eclipse.swt.layout.GridData) IBeanPropertyAccessors(org.talend.commons.utils.data.bean.IBeanPropertyAccessors) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) CopyPushButton(org.talend.commons.ui.swt.advanced.dataeditor.button.CopyPushButton) TreeSchemaTableEntry(org.talend.designer.xmlmap.ui.tabs.table.TreeSchemaTableEntry) ExtendedToolbarView(org.talend.commons.ui.swt.advanced.dataeditor.ExtendedToolbarView)

Aggregations

AddPushButton (org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButton)2 AddPushButtonForExtendedTable (org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Table (org.eclipse.swt.widgets.Table)1 CellEditorValueAdapter (org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter)1 ExtendedToolbarView (org.talend.commons.ui.swt.advanced.dataeditor.ExtendedToolbarView)1 CopyPushButton (org.talend.commons.ui.swt.advanced.dataeditor.button.CopyPushButton)1 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)1 IBeanPropertyAccessors (org.talend.commons.utils.data.bean.IBeanPropertyAccessors)1 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 INode (org.talend.core.model.process.INode)1