use of org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent in project tdi-studio-se by Talend.
the class InputDataMapTableView method initColumnsOfTableColumns.
@Override
public void initColumnsOfTableColumns(final TableViewerCreator tableViewerCreatorForColumns) {
TableViewerCreatorColumn column = null;
//$NON-NLS-1$
String useInJoinTitle = Messages.getString("InputDataMapTableView.columnTitle.ExplicitJoin");
column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
column.setTitle(useInJoinTitle);
column.setId(ID_EXPLICIT_JOIN);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, Boolean>() {
public Boolean get(InputColumnTableEntry bean) {
return bean.isJoin();
}
public void set(InputColumnTableEntry bean, Boolean value) {
bean.setJoin(value);
boolean enable = true;
if (dropDownItem != null && !dropDownItem.isDisposed()) {
enable = dropDownItem.isEnabled();
}
if (enable && value && mapperManager.getCurrentLanguage().unuseWithExplicitJoin().contains(getInputTable().getJoinType())) {
if (menu != null) {
MenuItem[] menuItems = menu.getItems();
for (MenuItem mi : menuItems) {
if (mi.getImage() == null) {
continue;
}
if (mi.getText().equals(getInputTable().getJoinType().getLabel())) {
mi.setImage(null);
}
}
menuItems[1].setImage(ImageProviderMapper.getImage(ImageInfo.CHECKED_ICON));
}
getInputTable().setJoinType(JOIN.INNER_JOIN);
refreshLabelForJoinDropDown();
mapperManager.getUiManager().refreshSqlExpression();
}
}
});
column.setModifiable(true);
// column.setWidth(12);
column.setWidth(65);
//$NON-NLS-1$
column.setDisplayedValue("");
// column.setResizable(false);
CheckboxTableEditorContent checkboxTableEditorContent = new CheckboxTableEditorContent();
checkboxTableEditorContent.setToolTipText(useInJoinTitle);
column.setTableEditorContent(checkboxTableEditorContent);
column.setToolTipHeader(useInJoinTitle);
column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
column.setTitle(DataMapTableView.COLUMN_NAME);
column.setId(DataMapTableView.ID_NAME_COLUMN);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, String>() {
public String get(InputColumnTableEntry bean) {
return bean.getMetadataColumn().getLabel();
}
public void set(InputColumnTableEntry bean, String value) {
bean.getMetadataColumn().setLabel(value);
}
});
column.setWeight(COLUMN_NAME_SIZE_WEIGHT);
final TableViewerCreatorColumn columnOperator = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
//$NON-NLS-1$
columnOperator.setTitle(Messages.getString("InputDataMapTableView.columnTitle.Operator"));
columnOperator.setId(DataMapTableView.ID_OPERATOR);
//$NON-NLS-1$
columnOperator.setToolTipHeader(Messages.getString("InputDataMapTableView.Operator"));
columnOperator.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, String>() {
public String get(InputColumnTableEntry bean) {
return bean.getOperator();
}
public void set(InputColumnTableEntry bean, String value) {
bean.setOperator(value);
mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
}
});
columnOperator.setModifiable(true);
columnOperator.setWidth(85);
final IDbOperatorManager operatorsManager = mapperManager.getCurrentLanguage().getOperatorsManager();
IDbOperator[] operators = operatorsManager.getOperators();
String[] arrayOperators = new String[operators.length + 1];
//$NON-NLS-1$
arrayOperators[0] = "";
for (int i = 0; i < operators.length; i++) {
arrayOperators[i + 1] = operators[i].getOperator();
}
final ComboxCellEditorImproved typeComboEditor = new ComboxCellEditorImproved(tableViewerCreatorForColumns.getTable(), arrayOperators, SWT.NONE);
typeComboEditor.addListener(new ICellEditorListener() {
public void applyEditorValue() {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
InputColumnTableEntry currentInputEntry = (InputColumnTableEntry) modifiedObjectInfo.getCurrentModifiedBean();
currentInputEntry.setOriginalExpression(null);
Combo combo = (Combo) typeComboEditor.getControl();
String selectedText = combo.getText();
IDbOperator operatorFromValue = operatorsManager.getOperatorFromValue(selectedText);
if (operatorFromValue != null && operatorFromValue.isMonoOperand()) {
//$NON-NLS-1$
currentInputEntry.setExpression("");
}
}
public void cancelEditor() {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
InputColumnTableEntry currentInputEntry = (InputColumnTableEntry) modifiedObjectInfo.getCurrentModifiedBean();
// currentInputEntry.setExpression(currentInputEntry.getOriginalExpression());
}
public void editorValueChanged(boolean oldValidState, boolean newValidState) {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
InputColumnTableEntry currentInputEntry = (InputColumnTableEntry) modifiedObjectInfo.getCurrentModifiedBean();
if (modifiedObjectInfo.getCurrentModifiedColumn() == columnOperator) {
if (currentInputEntry != modifiedObjectInfo.getPreviousModifiedBean()) {
currentInputEntry.setOriginalExpression(currentInputEntry.getExpression());
}
Combo combo = (Combo) typeComboEditor.getControl();
String selectedText = combo.getText();
if (//$NON-NLS-1$
!selectedText.equals("") && (currentInputEntry.getExpression() == null || currentInputEntry.getExpression().trim().length() == 0)) {
IDbOperator operatorFromValue = operatorsManager.getOperatorFromValue(selectedText);
if (operatorFromValue.getAssociatedExpression() != null) {
currentInputEntry.setExpression(operatorFromValue.getAssociatedExpression());
}
}
}
}
});
Combo typeCombo = (Combo) typeComboEditor.getControl();
// typeCombo.setEditable(true);
columnOperator.setCellEditor(typeComboEditor, CellEditorValueAdapterFactory.getComboAdapterForComboCellEditorImproved());
columnOperator.setAlignment(ALIGNMENT.CENTER);
final TableViewerCreatorColumn columnExpression = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
//$NON-NLS-1$
columnExpression.setTitle(Messages.getString("InputDataMapTableView.columnTitle.Expr"));
columnExpression.setId(DataMapTableView.ID_EXPRESSION_COLUMN);
columnExpression.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, String>() {
public String get(InputColumnTableEntry bean) {
return bean.getExpression();
}
public void set(InputColumnTableEntry bean, String value) {
bean.setExpression(value);
// mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
}
});
columnExpression.setModifiable(true);
//$NON-NLS-1$
columnExpression.setDefaultInternalValue("");
createExpressionCellEditor(tableViewerCreatorForColumns, columnExpression, new Zone[] { Zone.INPUTS }, false);
columnExpression.setWeight(COLUMN_EXPRESSION_SIZE_WEIGHT);
columnExpression.setColorProvider(new IColumnColorProvider() {
public Color getBackgroundColor(Object bean) {
if (!cellModifier.canModify(bean, columnExpression.getId())) {
return READONLY_CELL_BG_COLOR;
}
return null;
}
public Color getForegroundColor(Object bean) {
return null;
}
});
configureCellModifier(tableViewerCreatorForColumns);
}
use of org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent in project tdi-studio-se by Talend.
the class XmlTreeSchemaTableView method createColumns.
@Override
protected void createColumns(final TableViewerCreator<TreeNode> tableViewerCreator, Table table) {
TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("XPath");
column.setId(ID_COLUMN_XPATH);
column.setWeight(20);
column.setModifiable(true);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, Object>() {
@Override
public Object get(TreeNode bean) {
return bean.getXpath();
}
@Override
public void set(TreeNode bean, Object value) {
if (isValidName) {
bean.setName((String) value);
// String xPath = bean.getXPath();
// xPath = xPath.substring(0, xPath.lastIndexOf(XmlMapUtil.XPATH_SEPARATOR) + 1);
// NodeType nodeType = bean.getTreeNode().getNodeType();
// String typedValue = null;
// if (NodeType.ATTRIBUT.equals(nodeType)) {
// typedValue = xPath + XmlMapUtil.XPATH_ATTRIBUTE + bean.getName();
// } else if (NodeType.NAME_SPACE.equals(nodeType)) {
// typedValue = xPath + XmlMapUtil.XPATH_NAMESPACE + bean.getName();
// } else {
// typedValue = xPath + bean.getName();
// }
// bean.setXPath(typedValue);
XmlMapData mapperData = XmlMapUtil.getXmlMapData(bean);
XmlMapExpressionManager expressionManager = new XmlMapExpressionManager();
XmlMapUtil.updateXPathAndExpression(mapperData, expressionManager, bean, bean.getName(), XmlMapUtil.getXPathLength(bean.getXpath()), true);
if (!bean.getChildren().isEmpty()) {
refresh();
}
}
}
});
final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreator.getTable());
cellEditor.addListener(new DialogErrorForCellEditorListener(cellEditor, column) {
@Override
public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
}
@Override
public String validateValue(String newValue, int beanPosition) {
return validateXPath(newValue, beanPosition);
}
});
column.setCellEditor(cellEditor);
column.setColumnCellModifier(new ColumnCellModifier(column) {
@Override
public Object getValue(Object bean) {
TreeNode entry = (TreeNode) bean;
return entry.getName();
}
@Override
public boolean modify(Object bean, Object value) {
return false;
}
});
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("Key");
column.setToolTipHeader("Key");
column.setId(ID_COLUMN_KEY);
//$NON-NLS-1$
column.setDisplayedValue("");
column.setWeight(10);
column.setModifiable(true);
CheckboxTableEditorContent checkbox = new CheckboxTableEditorContent();
column.setTableEditorContent(checkbox);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, Boolean>() {
@Override
public Boolean get(TreeNode bean) {
return bean.isKey();
}
@Override
public void set(TreeNode bean, Boolean value) {
bean.setKey(value);
}
});
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("Type");
column.setToolTipHeader("Type");
column.setId(ID_COLUMN_TYPE);
column.setBeanPropertyAccessors(getTalendTypeAccessor());
column.setModifiable(true);
column.setWeight(20);
TreeSchemaJavaTypeComboValueAdapter comboValueAdapter = new TreeSchemaJavaTypeComboValueAdapter<TreeNode>(JavaTypesManager.getDefaultJavaType(), getNullableAccessor());
ComboBoxCellEditor typeComboEditor = new ComboBoxCellEditor(tableViewerCreator.getTable(), comboValueAdapter.getTalendTypesLabels(), SWT.READ_ONLY);
CCombo typeCombo = (CCombo) typeComboEditor.getControl();
typeCombo.setEditable(false);
column.setCellEditor(typeComboEditor, comboValueAdapter);
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("Nullable");
column.setToolTipHeader("Nullable");
column.setId(ID_COLUMN_NULLABLE);
column.setBeanPropertyAccessors(getNullableAccessor());
column.setWeight(20);
//$NON-NLS-1$
column.setDisplayedValue("");
column.setModifiable(true);
column.setTableColumnSelectionListener(new CheckColumnSelectionListener(column, tableViewerCreator));
column.setImageHeader(ImageProvider.getImage(EImage.CHECKED_ICON));
CheckboxTableEditorContent nullableCheckbox = new CheckboxTableEditorContent();
column.setTableEditorContent(nullableCheckbox);
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("Pattern");
column.setId(ID_COLUMN_PATTERN);
column.setWeight(20);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, String>() {
@Override
public String get(TreeNode bean) {
return bean.getPattern();
}
@Override
public void set(TreeNode bean, String value) {
bean.setPattern(value);
}
});
final ColumnCellModifier columnCellModifier = new ColumnCellModifier(column) {
@Override
public boolean canModify(Object bean) {
boolean typeIsDate = currentBeanHasJavaDateType(bean) && !isReadOnly();
return typeIsDate;
}
};
column.setColorProvider(new IColumnColorProvider() {
@Override
public Color getBackgroundColor(Object bean) {
if (!columnCellModifier.canModify(bean)) {
return READONLY_CELL_BG_COLOR;
}
return null;
}
@Override
public Color getForegroundColor(Object bean) {
return null;
}
});
column.setLabelProvider(new IColumnLabelProvider() {
/*
* (non-Javadoc)
*
* @see org.talend.commons.ui.swt.tableviewer.behavior.IColumnLabelProvider#getLabel(java.lang.Object)
*/
@Override
public String getLabel(Object bean) {
if (!currentBeanHasJavaDateType(bean)) {
//$NON-NLS-1$
return "";
}
return null;
}
});
column.setColumnCellModifier(columnCellModifier);
JavaSimpleDateFormatProposalProvider proposalProvider = new JavaSimpleDateFormatProposalProvider();
TextCellEditorWithProposal patternCellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), column);
ContentProposalAdapterExtended contentProposalAdapter = patternCellEditor.getContentProposalAdapter();
contentProposalAdapter.setFilterStyle(ContentProposalAdapterExtended.FILTER_NONE);
contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapterExtended.PROPOSAL_INSERT);
patternCellEditor.setContentProposalProvider(proposalProvider);
column.setCellEditor(patternCellEditor, CellEditorValueAdapterFactory.getNullToEmptyStringTextAdapater());
tableViewerCreator.setCellModifier(new XmlCellModifier(tableViewerCreator));
}
Aggregations