Search in sources :

Example 1 with PastePushButton

use of org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButton 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 PastePushButton (org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButton)1 PastePushButtonForExtendedTable (org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButtonForExtendedTable)1 ExtendedTableModel (org.talend.commons.ui.swt.extended.table.ExtendedTableModel)1 PropertyTablePasteCommand (org.talend.designer.core.ui.editor.cmd.PropertyTablePasteCommand)1