use of org.talend.designer.dbmap.language.operator.IDbOperator in project tdi-studio-se by Talend.
the class ProblemsManager method checkProblemsForTableEntry.
public void checkProblemsForTableEntry(ITableEntry tableEntry, boolean forceRefreshData) {
// if (forceRefreshData) {
// mapperManager.getComponent().refreshMapperConnectorData();
// checkProblems();
// }
List<Problem> problems = new ArrayList<Problem>(0);
String expression = tableEntry.getExpression();
if (tableEntry instanceof InputColumnTableEntry) {
InputColumnTableEntry inputEntry = (InputColumnTableEntry) tableEntry;
IDbOperatorManager operatorsManager = mapperManager.getCurrentLanguage().getOperatorsManager();
IDbOperator dbOperator = operatorsManager.getOperatorFromValue(inputEntry.getOperator());
boolean operatorIsSet = dbOperator != null;
boolean expressionIsSet = expression != null && expression.trim().length() > 0;
Problem problem = null;
String errorMessage = null;
String key = null;
if (!operatorIsSet && expressionIsSet) {
errorMessage = //$NON-NLS-1$
Messages.getString(//$NON-NLS-1$
"ProblemsManager.operatorNotSet", new Object[] { inputEntry.getName() });
key = KEY_OPERATOR_EMPTY;
problem = new Problem(null, errorMessage, ProblemStatus.ERROR);
problem.setKey(key);
problems.add(problem);
}
if (operatorIsSet && !expressionIsSet && !dbOperator.isMonoOperand()) {
errorMessage = //$NON-NLS-1$
Messages.getString(//$NON-NLS-1$
"ProblemsManager.inputExpressionEmpty", new Object[] { inputEntry.getParentName(), inputEntry.getName() });
key = KEY_INPUT_EXPRESSION_EMPTY;
problem = new Problem(null, errorMessage, ProblemStatus.ERROR);
problem.setKey(key);
problems.add(problem);
}
Problem warningProblem = null;
if (inputEntry.isUnmatchingEntry()) {
InputTable inputTable = (InputTable) inputEntry.getParent();
String message = //$NON-NLS-1$
Messages.getString(//$NON-NLS-1$
"ProblemsManager.entryDoesntMatch", new Object[] { inputEntry.getParentName(), inputEntry.getName(), inputTable.getTableName() });
warningProblem = new Problem(null, message, ProblemStatus.WARNING);
warningProblem.setKey(KEY_NO_MATCHING);
problems.add(warningProblem);
}
} else if (tableEntry instanceof OutputColumnTableEntry) {
String errorMessage = null;
Problem problem = null;
if (expression == null || EMPTY_STRING.equals(expression.trim())) {
errorMessage = //$NON-NLS-1$
Messages.getString(//$NON-NLS-1$
"ProblemsManager.outputExpressionEmpty", new Object[] { tableEntry.getParentName(), tableEntry.getName() });
}
if (errorMessage != null) {
problem = new Problem(null, errorMessage, ProblemStatus.ERROR);
problem.setKey(KEY_OUTPUT_EXPRESSION_EMPTY);
problems.add(problem);
}
}
tableEntry.setProblems(problems.size() > 0 ? problems : null);
}
use of org.talend.designer.dbmap.language.operator.IDbOperator in project tdi-studio-se by Talend.
the class DbGenerationManager method buildCondition.
/**
* DOC amaumont Comment method "buildCondition".
*
* @param sbWhere
* @param table
* @param isFirstClause
* @param dbMapEntry
* @param writeCr TODO
*/
private boolean buildCondition(DbMapComponent component, StringBuilder sbWhere, ExternalDbMapTable table, boolean isFirstClause, ExternalDbMapEntry dbMapEntry, boolean writeCr) {
String expression = dbMapEntry.getExpression();
expression = initExpression(component, dbMapEntry);
IDbOperator dbOperator = getOperatorsManager().getOperatorFromValue(dbMapEntry.getOperator());
boolean operatorIsSet = dbOperator != null;
boolean expressionIsSet = expression != null && expression.trim().length() > 0;
boolean conditionWritten = false;
if (operatorIsSet) {
if (writeCr) {
sbWhere.append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString);
sbWhere.append(DbMapSqlConstants.SPACE);
}
if (!isFirstClause) {
sbWhere.append(DbMapSqlConstants.SPACE);
sbWhere.append(DbMapSqlConstants.AND);
sbWhere.append(DbMapSqlConstants.SPACE);
}
String entryName = dbMapEntry.getName();
entryName = getOriginalColumnName(entryName, component, table);
String tableName = table.getName();
if (table.getAlias() == null) {
tableName = getHandledTableName(component, table.getName());
} else {
tableName = getHandledField(table.getAlias());
}
String locationInputEntry = language.getLocation(tableName, getHandledField(entryName));
sbWhere.append(DbMapSqlConstants.SPACE);
sbWhere.append(locationInputEntry);
sbWhere.append(getSpecialRightJoin(table));
sbWhere.append(DbMapSqlConstants.SPACE);
if (operatorIsSet) {
sbWhere.append(dbOperator.getOperator()).append(DbMapSqlConstants.SPACE);
} else if (!operatorIsSet && expressionIsSet) {
sbWhere.append(DbMapSqlConstants.LEFT_COMMENT);
sbWhere.append(DbMapSqlConstants.SPACE);
//$NON-NLS-1$
sbWhere.append(Messages.getString("DbGenerationManager.InputOperationSetMessage", entryName));
sbWhere.append(DbMapSqlConstants.SPACE);
sbWhere.append(DbMapSqlConstants.RIGHT_COMMENT);
}
if (operatorIsSet && !expressionIsSet && !dbOperator.isMonoOperand()) {
String str = table.getName() + DbMapSqlConstants.DOT + entryName;
sbWhere.append(DbMapSqlConstants.LEFT_COMMENT);
sbWhere.append(DbMapSqlConstants.SPACE);
//$NON-NLS-1$
sbWhere.append(Messages.getString("DbGenerationManager.InputExpSetMessage", str));
sbWhere.append(DbMapSqlConstants.SPACE);
sbWhere.append(DbMapSqlConstants.RIGHT_COMMENT);
} else if (expressionIsSet) {
sbWhere.append(expression);
sbWhere.append(getSpecialLeftJoin(table));
}
conditionWritten = true;
}
return conditionWritten;
}
use of org.talend.designer.dbmap.language.operator.IDbOperator 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);
}
Aggregations