use of org.talend.designer.core.ui.editor.cmd.PropertyTablePasteCommand 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;
}
Aggregations