Search in sources :

Example 1 with PastePushButtonForExtendedTable

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

the class PropertiesTableToolbarEditorView method createPastePushButton.

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

        @Override
        public boolean getEnabledState() {
            PropertiesTableEditorModel tableEditorModel = (PropertiesTableEditorModel) getExtendedTableViewer().getExtendedControlModel();
            Object data = SimpleClipboard.getInstance().getData();
            if (data == null || !(data instanceof List) || tableEditorModel.getElemParameter() == null || tableEditorModel.getElemParameter().getListItemsDisplayCodeName() == null) {
                return false;
            }
            @SuppressWarnings("rawtypes") List dataList = (List) data;
            boolean sameNumberOfParamAssSourceTable = true;
            if (dataList.isEmpty() || !(dataList.get(0) instanceof HashMap)) {
                // only accept data from another property (list of HashMap)
                return false;
            }
            @SuppressWarnings("rawtypes") HashMap sourceMap = (HashMap) dataList.get(0);
            int sourceColumnNumber = sourceMap.size();
            Object[] sourceArray = sourceMap.keySet().toArray();
            ArrayList<Object> sourceList = new ArrayList<Object>(Arrays.asList(sourceArray));
            String[] listItemsDisplayCodeName = tableEditorModel.getElemParameter().getListItemsDisplayCodeName();
            List<String> itemDisCodeNameList = null;
            int colNum = 0;
            if (listItemsDisplayCodeName != null) {
                itemDisCodeNameList = Arrays.asList(listItemsDisplayCodeName);
                colNum = listItemsDisplayCodeName.length;
            }
            ArrayList<String> list = new ArrayList<String>(itemDisCodeNameList);
            list.removeAll(sourceList);
            if (data != null) {
                if (colNum <= sourceColumnNumber && list.size() == 0) {
                    sameNumberOfParamAssSourceTable = true;
                } else {
                    sameNumberOfParamAssSourceTable = false;
                }
            }
            return super.getEnabledState() && (model == null || !model.getElemParameter().isBasedOnSubjobStarts()) && sameNumberOfParamAssSourceTable;
        }

        @Override
        protected Command getCommandToExecute(ExtendedTableModel extendedTableModel, Integer indexWhereInsert) {
            return new PropertyTablePasteCommand<Map<String, Object>>(extendedTableModel, indexWhereInsert);
        }
    };
    // TDI-6568, after paste, fire change
    pastePushButton.addListener(getPropertyChangeListener(), false);
    return pastePushButton;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PastePushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButtonForExtendedTable) PropertyTablePasteCommand(org.talend.designer.core.ui.editor.cmd.PropertyTablePasteCommand) ArrayList(java.util.ArrayList) List(java.util.List) ExtendedTableModel(org.talend.commons.ui.swt.extended.table.ExtendedTableModel) PastePushButton(org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButton)

Example 2 with PastePushButtonForExtendedTable

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

the class HL7MetadataEmfToolbarEditor method createPastePushButton.

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

        @Override
        protected Command getCommandToExecute(ExtendedTableModel extendedTableModel, Integer indexWhereInsert) {
            return new MetadataEmfPasteCommand(extendedTableModel, indexWhereInsert);
        }

        @Override
        public boolean getEnabledState() {
            // 13749
            return super.getEnabledState() && !isRepository;
        }

        @Override
        protected void afterCommandExecution(Command executedCommand) {
            MetadataEmfTableEditor tableEditorModel = (MetadataEmfTableEditor) getExtendedTableViewer().getExtendedControlModel();
            IStructuredSelection selection = (IStructuredSelection) ((HL7MultiSchemaUI) linker.getMainui()).getMetaTableViewer().getSelection();
            Object selectedObj = selection.getFirstElement();
            if (selectedObj != null) {
                String key = ((IModel) selectedObj).getDisplayName();
                List<MetadataColumn> metadataColumnList = tableEditorModel.getMetadataColumnList();
                Map<String, List<MetadataColumn>> schemaRelationMap = linker.getManager().getSchemaRelationMap();
                if (schemaRelationMap != null) {
                    List<MetadataColumn> schemas = new ArrayList<MetadataColumn>();
                    schemas.addAll(metadataColumnList);
                    schemaRelationMap.put(key, schemas);
                }
            }
        }
    };
}
Also used : IModel(org.talend.designer.hl7.model.IModel) ArrayList(java.util.ArrayList) PastePushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButtonForExtendedTable) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MetadataEmfPasteCommand(org.talend.core.ui.metadata.extended.command.MetadataEmfPasteCommand) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataEmfExportXmlCommand(org.talend.core.ui.metadata.extended.command.MetadataEmfExportXmlCommand) MetadataEmfPasteCommand(org.talend.core.ui.metadata.extended.command.MetadataEmfPasteCommand) ExtendedTableResetDBTypesCommand(org.talend.core.ui.metadata.extended.command.ExtendedTableResetDBTypesCommand) MetadataEmfImportXmlCommand(org.talend.core.ui.metadata.extended.command.MetadataEmfImportXmlCommand) Command(org.eclipse.gef.commands.Command) MetadataEmfTableEditor(org.talend.core.ui.metadata.editor.MetadataEmfTableEditor) HL7MultiSchemaUI(org.talend.designer.hl7.ui.HL7MultiSchemaUI) ArrayList(java.util.ArrayList) List(java.util.List) ExtendedTableModel(org.talend.commons.ui.swt.extended.table.ExtendedTableModel)

Example 3 with PastePushButtonForExtendedTable

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

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

the class AutoConversionTypesEditorView method 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() {
                    AutoConversionType bean = new AutoConversionType();
                    bean.setSourceDataType(JavaTypesManager.getDefaultJavaType().getId());
                    bean.setTargetDataType(JavaTypesManager.getDefaultJavaType().getId());
                    //$NON-NLS-1$
                    bean.setConversionFunction("String.valueOf(${0})");
                    return bean;
                }
            };
        }

        @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<AutoConversionType> createPastableBeansList(ExtendedTableModel extendedTableModel, List copiedObjectsList) {
                            List<AutoConversionType> beans = new ArrayList<>();
                            beans.addAll(copiedObjectsList);
                            return beans;
                        }
                    };
                }
            };
        }
    };
}
Also used : AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) AutoConversionType(org.talend.core.model.metadata.types.AutoConversionType) ExtendedTablePasteCommand(org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTablePasteCommand) ArrayList(java.util.ArrayList) PastePushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButtonForExtendedTable) 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)

Aggregations

ArrayList (java.util.ArrayList)4 List (java.util.List)4 PastePushButtonForExtendedTable (org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButtonForExtendedTable)4 ExtendedTableModel (org.talend.commons.ui.swt.extended.table.ExtendedTableModel)4 ExtendedToolbarView (org.talend.commons.ui.swt.advanced.dataeditor.ExtendedToolbarView)2 AddPushButtonForExtendedTable (org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable)2 ExtendedTablePasteCommand (org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTablePasteCommand)2 HashMap (java.util.HashMap)1 Command (org.eclipse.gef.commands.Command)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 PastePushButton (org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButton)1 UniqueStringGenerator (org.talend.commons.utils.data.list.UniqueStringGenerator)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1 AutoConversionType (org.talend.core.model.metadata.types.AutoConversionType)1 MetadataEmfTableEditor (org.talend.core.ui.metadata.editor.MetadataEmfTableEditor)1 ExtendedTableResetDBTypesCommand (org.talend.core.ui.metadata.extended.command.ExtendedTableResetDBTypesCommand)1 MetadataEmfExportXmlCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfExportXmlCommand)1 MetadataEmfImportXmlCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfImportXmlCommand)1 MetadataEmfPasteCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfPasteCommand)1 PropertyTablePasteCommand (org.talend.designer.core.ui.editor.cmd.PropertyTablePasteCommand)1