Search in sources :

Example 1 with AddPushButtonForExtendedTable

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

the class JSONFileMetadataEmfToolbarEditor method createAddPushButton.

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

        @Override
        protected Object getObjectToAdd() {
            MetadataEmfTableEditor tableEditorModel = (MetadataEmfTableEditor) getExtendedTableViewer().getExtendedControlModel();
            if (tableEditorModel.getMetadataTable() == null) {
                tableEditorModel.setMetadataTable(ConnectionFactory.eINSTANCE.createMetadataTable());
            }
            MetadataColumn metadatacolumn = tableEditorModel.createNewMetadataColumn(dbmsId);
            return metadatacolumn;
        }
    };
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) MetadataEmfTableEditor(org.talend.core.ui.metadata.editor.MetadataEmfTableEditor)

Example 2 with AddPushButtonForExtendedTable

use of org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable 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 3 with AddPushButtonForExtendedTable

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

the class HL7MetadataEmfToolbarEditor method createAddPushButton.

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

        boolean hasSchema = false;

        @Override
        protected Object getObjectToAdd() {
            if (hasSchema) {
                MetadataEmfTableEditor tableEditorModel = (MetadataEmfTableEditor) getExtendedTableViewer().getExtendedControlModel();
                if (tableEditorModel.getMetadataTable() == null) {
                    tableEditorModel.setMetadataTable(ConnectionFactory.eINSTANCE.createMetadataTable());
                }
                MetadataColumn metadatacolumn = tableEditorModel.createNewMetadataColumn(dbmsId);
                metadatacolumn.setLength(226);
                metadatacolumn.setPrecision(0);
                updateCurrentTableModelAndMap(tableEditorModel);
                return metadatacolumn;
            }
            return null;
        }

        @Override
        protected void beforeCommandExecution() {
            IStructuredSelection selection = (IStructuredSelection) ((HL7MultiSchemaUI) linker.getMainui()).getMetaTableViewer().getSelection();
            Object selectedObj = selection.getFirstElement();
            if (selectedObj != null) {
                hasSchema = true;
                super.beforeCommandExecution();
            } else {
                hasSchema = false;
                MessageDialog.openError(HL7MetadataEmfToolbarEditor.this.getParentComposite().getShell(), "Can't add new column!", "Need to init a schema by choosing a file at first");
            }
        }

        private void updateCurrentTableModelAndMap(MetadataEmfTableEditor tableEditorModel) {
            IStructuredSelection selection = (IStructuredSelection) ((HL7MultiSchemaUI) linker.getMainui()).getMetaTableViewer().getSelection();
            Object selectedObj = selection.getFirstElement();
            if (selectedObj != null) {
                String key = ((IModel) selectedObj).getDisplayName();
                linker.getManager().updateRelationMapping(key, tableEditorModel.createNewMetadataColumn(dbmsId), true);
            }
        }

        @Override
        public boolean getEnabledState() {
            // 13749
            return super.getEnabledState() && !isRepository;
        }
    };
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IModel(org.talend.designer.hl7.model.IModel) AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) MetadataEmfTableEditor(org.talend.core.ui.metadata.editor.MetadataEmfTableEditor) HL7MultiSchemaUI(org.talend.designer.hl7.ui.HL7MultiSchemaUI) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with AddPushButtonForExtendedTable

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

the class ExtractionFieldsWithJSONXPathEditorView method initToolBar.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.commons.ui.swt.advanced.dataeditor.AbstractDataTableEditorView#initToolBar()
     */
@Override
protected ExtendedToolbarView initToolBar() {
    return new ExtendedToolbarView(getMainComposite(), SWT.NONE, getExtendedTableViewer()) {

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

                @Override
                protected Object getObjectToAdd() {
                    UniqueStringGenerator<SchemaTarget> generator = new UniqueStringGenerator<SchemaTarget>("column", getModel().getBeansList()) {

                        @Override
                        protected String getBeanString(SchemaTarget bean) {
                            // TODO Auto-generated method stub
                            return bean.getRelativeXPathQuery();
                        }
                    };
                    SchemaTarget tarhe = getModel().createNewSchemaTarget();
                    tarhe.setRelativeXPathQuery(generator.getUniqueString());
                    tarhe.setTagName(generator.getUniqueString());
                    return tarhe;
                }
            };
        }

        /*
             * (non-Javadoc)
             * 
             * @see org.talend.core.ui.extended.ExtendedToolbarView#createPastePushButton()
             */
        @Override
        protected PastePushButton createPastePushButton() {
            return new PastePushButtonForExtendedTable(toolbar, extendedTableViewer) {

                @Override
                protected Command getCommandToExecute(ExtendedTableModel extendedTableModel, Integer indexWhereInsert) {
                    return new ExtendedTablePasteCommand(extendedTableModel, indexWhereInsert) {

                        @Override
                        public List createPastableBeansList(ExtendedTableModel extendedTableModel, List copiedObjectsList) {
                            ArrayList list = new ArrayList();
                            JSONExtractorFieldModel fieldsModel = (JSONExtractorFieldModel) extendedTableModel;
                            for (Object current : copiedObjectsList) {
                                if (current instanceof SchemaTarget) {
                                    SchemaTarget original = (SchemaTarget) current;
                                    SchemaTarget copy = fieldsModel.createNewSchemaTarget();
                                    copy.setRelativeXPathQuery(original.getRelativeXPathQuery());
                                    copy.setTagName(original.getTagName());
                                    list.add(copy);
                                }
                            }
                            return list;
                        }
                    };
                }
            };
        }
    };
}
Also used : AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) ExtendedTablePasteCommand(org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTablePasteCommand) ArrayList(java.util.ArrayList) PastePushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButtonForExtendedTable) SchemaTarget(org.talend.repository.model.json.SchemaTarget) UniqueStringGenerator(org.talend.commons.utils.data.list.UniqueStringGenerator) ArrayList(java.util.ArrayList) List(java.util.List) ExtendedTableModel(org.talend.commons.ui.swt.extended.table.ExtendedTableModel) ExtendedToolbarView(org.talend.commons.ui.swt.advanced.dataeditor.ExtendedToolbarView)

Example 5 with AddPushButtonForExtendedTable

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

the class ConnectionsListButtonsToolBar method createAddPushButton.

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

        @Override
        protected Object getObjectToAdd() {
            ConnectionBean newConnection = new ConnectionBean();
            newConnection.setName(NEW_CONNECTION_LABEL);
            return newConnection;
        }
    };
}
Also used : AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) ConnectionBean(org.talend.core.model.general.ConnectionBean)

Aggregations

AddPushButtonForExtendedTable (org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable)7 ArrayList (java.util.ArrayList)3 ExtendedToolbarView (org.talend.commons.ui.swt.advanced.dataeditor.ExtendedToolbarView)3 List (java.util.List)2 AddPushButton (org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButton)2 PastePushButtonForExtendedTable (org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButtonForExtendedTable)2 ExtendedTablePasteCommand (org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTablePasteCommand)2 ExtendedTableModel (org.talend.commons.ui.swt.extended.table.ExtendedTableModel)2 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)2 MetadataEmfTableEditor (org.talend.core.ui.metadata.editor.MetadataEmfTableEditor)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)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