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