use of org.talend.commons.ui.runtime.swt.tableviewer.data.ModifiedObjectInfo in project tdi-studio-se by Talend.
the class XmlCellModifier method getValue.
@Override
public Object getValue(Object bean, String idColumn) {
if (!AbstractXmlTreeSchemaTableView.ID_COLUMN_XPATH.equals(idColumn)) {
return super.getValue(bean, idColumn);
} else {
TableViewerCreatorColumnNotModifiable column = tableViewerCreator.getColumn(idColumn);
ModifiedObjectInfo modifiedObjectInfo = this.tableViewerCreator.getModifiedObjectInfo();
modifiedObjectInfo.setCurrentModifiedBean(bean);
modifiedObjectInfo.setCurrentModifiedColumn(column);
modifiedObjectInfo.setCurrentModifiedIndex(this.tableViewerCreator.getInputList().indexOf(bean));
Object returnValue = null;
if (column.getColumnCellModifier() != null) {
returnValue = column.getColumnCellModifier().getValue(bean);
}
if (returnValue == null) {
Object value = AccessorUtils.get(bean, column);
if (column.getCellEditorValueAdapter() != null) {
returnValue = column.getCellEditorValueAdapter().getCellEditorTypedValue(column.getCellEditor(), value);
} else {
returnValue = value;
}
if (returnValue == null && column.getDefaultInternalValue() != null) {
returnValue = column.getDefaultInternalValue();
}
}
modifiedObjectInfo.setOriginalPropertyBeanValue(returnValue);
modifiedObjectInfo.setPreviousPropertyBeanValue(returnValue);
return returnValue;
}
}
use of org.talend.commons.ui.runtime.swt.tableviewer.data.ModifiedObjectInfo in project tdi-studio-se by Talend.
the class DataMapTableView method createExpressionCellEditor.
protected TextCellEditor createExpressionCellEditor(final TableViewerCreator tableViewerCreator, TableViewerCreatorColumn column, final Zone[] zones, boolean isConstraintExpressionCellEditor) {
final TextCellEditorWithProposal cellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), SWT.MULTI | SWT.BORDER, column);
final Text expressionTextEditor = (Text) cellEditor.getControl();
if (isConstraintExpressionCellEditor) {
// moved to it's caller to execute
// constraintExpressionTextEditor = expressionTextEditor;
} else {
columnExpressionTextEditor = expressionTextEditor;
}
cellEditor.addListener(new ICellEditorListener() {
Text text = (Text) cellEditor.getControl();
@Override
public void applyEditorValue() {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
mapperManager.getUiManager().parseNewExpression(text.getText(), (ITableEntry) modifiedObjectInfo.getCurrentModifiedBean(), true);
}
@Override
public void cancelEditor() {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
text.setText((String) modifiedObjectInfo.getOriginalPropertyBeanValue());
ITableEntry tableEntry = (ITableEntry) (modifiedObjectInfo.getCurrentModifiedBean() != null ? modifiedObjectInfo.getCurrentModifiedBean() : modifiedObjectInfo.getPreviousModifiedBean());
String originalExpression = (String) modifiedObjectInfo.getOriginalPropertyBeanValue();
mapperManager.getUiManager().parseNewExpression(originalExpression, tableEntry, true);
}
@Override
public void editorValueChanged(boolean oldValidState, boolean newValidState) {
if (expressionTextEditor.isFocusControl() || lastExpressionEditorTextWhichLostFocus == expressionTextEditor) {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
ITableEntry tableEntry = (ITableEntry) (modifiedObjectInfo.getCurrentModifiedBean() != null ? modifiedObjectInfo.getCurrentModifiedBean() : modifiedObjectInfo.getPreviousModifiedBean());
mapperManager.getUiManager().parseNewExpression(text.getText(), tableEntry, false);
resizeTextEditor(text, tableViewerCreator);
}
}
});
expressionTextEditor.addControlListener(new ControlListener() {
ExecutionLimiter executionLimiter = null;
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
if (executionLimiter == null) {
executionLimiter = new ExecutionLimiter(50, true) {
@Override
public void execute(boolean isFinalExecution, Object data) {
if (isFinalExecution && !expressionTextEditor.isDisposed()) {
expressionTextEditor.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
if (expressionTextEditor.isDisposed()) {
return;
}
resizeTextEditor(expressionTextEditor, tableViewerCreator);
}
});
}
}
};
}
executionLimiter.startIfExecutable();
}
});
expressionTextEditor.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
ITableEntry currentModifiedEntry = (ITableEntry) tableViewerCreator.getModifiedObjectInfo().getCurrentModifiedBean();
initExpressionProposals(cellEditor, zones, tableViewerCreator, currentModifiedEntry);
resizeTextEditor(expressionTextEditor, tableViewerCreator);
StyledTextHandler styledTextHandler = mapperManager.getUiManager().getTabFolderEditors().getStyledTextHandler();
styledTextHandler.setCurrentEntry(currentModifiedEntry);
//$NON-NLS-1$
styledTextHandler.setTextWithoutNotifyListeners(currentModifiedEntry.getExpression() == null ? "" : currentModifiedEntry.getExpression());
}
@Override
public void focusLost(FocusEvent e) {
expressionEditorTextSelectionBeforeFocusLost = expressionTextEditor.getSelection();
lastExpressionEditorTextWhichLostFocus = expressionTextEditor;
}
});
column.setCellEditor(cellEditor, new CellEditorValueAdapter() {
@Override
public Object getCellEditorTypedValue(CellEditor cellEditor, Object originalTypedValue) {
return super.getCellEditorTypedValue(cellEditor, originalTypedValue);
}
@Override
public String getColumnText(CellEditor cellEditor, Object bean, Object cellEditorTypedValue) {
//$NON-NLS-1$ //$NON-NLS-2$
return super.getColumnText(cellEditor, bean, cellEditorTypedValue).replaceAll("[\r\n\t]+", " ... ");
}
@Override
public Object getOriginalTypedValue(CellEditor cellEditor, Object cellEditorTypedValue) {
return super.getOriginalTypedValue(cellEditor, cellEditorTypedValue);
}
});
return cellEditor;
}
use of org.talend.commons.ui.runtime.swt.tableviewer.data.ModifiedObjectInfo 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.runtime.swt.tableviewer.data.ModifiedObjectInfo in project tdi-studio-se by Talend.
the class VarsDataMapTableView method initColumnsOfTableColumns.
@Override
public void initColumnsOfTableColumns(final TableViewerCreator tableViewerCreatorForColumns) {
ECodeLanguage codeLanguage = LanguageProvider.getCurrentLanguage().getCodeLanguage();
TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
//$NON-NLS-1$
column.setTitle(Messages.getString("VarsDataMapTableView.columnTitle.expression"));
column.setId(DataMapTableView.ID_EXPRESSION_COLUMN);
expressionCellEditor = createExpressionCellEditor(tableViewerCreatorForColumns, column, new Zone[] { Zone.INPUTS, Zone.VARS }, false);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, String>() {
public String get(VarTableEntry bean) {
return bean.getExpression();
}
public void set(VarTableEntry bean, String value) {
bean.setExpression(value);
mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
}
});
column.setModifiable(!mapperManager.componentIsReadOnly());
//$NON-NLS-1$
column.setDefaultInternalValue("");
if (codeLanguage == ECodeLanguage.JAVA) {
column.setWeight(40);
} else {
column.setWeight(COLUMN_EXPRESSION_SIZE_WEIGHT);
}
if (codeLanguage == ECodeLanguage.JAVA) {
String[] arrayTalendTypes = new String[0];
try {
arrayTalendTypes = MetadataTalendType.getTalendTypesLabels();
arrayTalendTypes = this.talendTypeFilter.filter(arrayTalendTypes);
} catch (NoClassDefFoundError e) {
// shouln't be happend
// e.printStackTrace();
ExceptionHandler.process(e);
} catch (ExceptionInInitializerError e) {
// shouln't be happend
// e.printStackTrace();
ExceptionHandler.process(e);
}
IBeanPropertyAccessors<VarTableEntry, Boolean> nullableAccessors = new IBeanPropertyAccessors<VarTableEntry, Boolean>() {
public Boolean get(VarTableEntry bean) {
return bean.isNullable() ? Boolean.TRUE : Boolean.FALSE;
}
public void set(VarTableEntry bean, Boolean value) {
bean.setNullable(value.booleanValue());
}
};
CellEditorValueAdapter comboValueAdapter = new JavaTypeComboValueAdapter(JavaTypesManager.getDefaultJavaType(), nullableAccessors, this.talendTypeFilter);
column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
//$NON-NLS-1$
column.setTitle(Messages.getString("VarsDataMapTableView.columnTitle.type"));
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, String>() {
public String get(VarTableEntry bean) {
return bean.getType();
}
public void set(VarTableEntry bean, String value) {
bean.setType(value);
mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
}
});
column.setModifiable(!mapperManager.componentIsReadOnly());
column.setWeight(18);
column.setCellEditor(new ComboBoxCellEditor(tableViewerCreatorForColumns.getTable(), arrayTalendTypes), comboValueAdapter);
column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
//$NON-NLS-1$
column.setTitle("Nullable");
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, Boolean>() {
public Boolean get(VarTableEntry bean) {
return bean.isNullable();
}
public void set(VarTableEntry bean, Boolean value) {
bean.setNullable(value);
mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
}
});
column.setModifiable(!mapperManager.componentIsReadOnly());
column.setWidth(WindowSystem.isWIN32() ? 12 : 20);
//$NON-NLS-1$
column.setDisplayedValue("");
column.setResizable(false);
CheckboxTableEditorContent checkboxTableEditorContent = new CheckboxTableEditorContent();
//$NON-NLS-1$
String nullable = Messages.getString("VarsDataMapTableView.nullable");
checkboxTableEditorContent.setToolTipText(nullable);
column.setTableEditorContent(checkboxTableEditorContent);
column.setToolTipHeader(nullable);
}
column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
//$NON-NLS-1$
column.setTitle(Messages.getString("VarsDataMapTableView.columnTitle.variable"));
column.setId(DataMapTableView.ID_NAME_COLUMN);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, String>() {
public String get(VarTableEntry bean) {
return bean.getName();
}
public void set(VarTableEntry bean, String value) {
bean.setName(value);
}
});
column.setModifiable(!mapperManager.componentIsReadOnly());
if (codeLanguage == ECodeLanguage.JAVA) {
column.setWeight(25);
} else {
column.setWeight(COLUMN_NAME_SIZE_WEIGHT);
}
final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreatorForColumns.getTable());
cellEditor.addListener(new DialogErrorForCellEditorListener(cellEditor, column) {
@Override
public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
if (state == CELL_EDITOR_STATE.APPLYING) {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
String originalValue = (String) modifiedObjectInfo.getOriginalPropertyBeanValue();
Object currentModifiedBean = modifiedObjectInfo.getCurrentModifiedBean();
mapperManager.getUiManager().processColumnNameChanged(originalValue.toString(), newValue.toString(), VarsDataMapTableView.this, (ITableEntry) currentModifiedBean);
}
}
@Override
public String validateValue(String newValue, int beanPosition) {
return ((VarsTable) getDataMapTable()).validateColumnName(newValue, beanPosition);
}
});
column.setCellEditor(cellEditor);
}
Aggregations