use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class AbstractSchemaController method createComboCommand.
@Override
protected Command createComboCommand(CCombo combo) {
IMetadataTable repositoryMetadata = null;
String fullParamName = (String) combo.getData(PARAMETER_NAME);
IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
//$NON-NLS-1$
String value = new String("");
IElementParameter param = elem.getElementParameter(fullParamName);
for (int j = 0; j < param.getListItemsValue().length; j++) {
if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
value = (String) param.getListItemsValue()[j];
}
}
// if change to build-in, unuse the validation rule if the component has.
boolean isValRulesLost = false;
IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
if (value.equals(EmfComponent.BUILTIN) && currentValRuleObj != null) {
if (!MessageDialog.openConfirm(combo.getShell(), //$NON-NLS-1$
Messages.getString("AbstractSchemaController.validationrule.title.confirm"), Messages.getString("AbstractSchemaController.validationrule.selectBuildInMsg"))) {
//$NON-NLS-1$
return null;
} else {
isValRulesLost = true;
}
}
org.talend.core.model.metadata.builder.connection.Connection connection = null;
if (elem instanceof Node) {
Node node = (Node) elem;
Command baseCommand = null;
boolean isReadOnly = false;
String newRepositoryIdValue = null;
if (node.getMetadataFromConnector(param.getContext()) != null) {
isReadOnly = node.getMetadataFromConnector(param.getContext()).isReadOnly();
}
if (//$NON-NLS-1$
value.equals(EmfComponent.BUILTIN) && isReadOnly && !"tLogCatcher".equals(node.getComponent().getName()) && !"tStatCatcher".equals(node.getComponent().getName())) {
//$NON-NLS-1$
boolean hasMetadataInput = false;
if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0) {
hasMetadataInput = true;
}
repositoryMetadata = new MetadataTable();
if (hasMetadataInput) {
for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE))) {
repositoryMetadata = connec.getMetadataTable().clone();
}
}
}
} else if (value.equals(EmfComponent.REPOSITORY)) {
// Map<String, IMetadataTable> repositoryTableMap = dynamicProperty.getRepositoryTableMap();
IElementParameter property = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
if ((property != null) && EmfComponent.REPOSITORY.equals(property.getValue())) {
String propertySelected = (String) ((Node) elem).getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
/* 16969 */
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(propertySelected);
if (repobj != null) {
Property tmpproperty = repobj.getProperty();
if (tmpproperty != null) {
item = tmpproperty.getItem();
}
}
// item = factory.getLastVersion(propertySelected).getProperty().getItem();
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
final ConnectionItem connectionItem = (ConnectionItem) item;
if (connectionItem != null) {
connection = connectionItem.getConnection();
}
}
}
IElementParameter repositorySchemaType = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
String schemaSelected = (String) repositorySchemaType.getValue();
if (schemaSelected == null) {
//$NON-NLS-1$
schemaSelected = "";
}
/* value can be devided means the value like "connectionid - label" */
//$NON-NLS-1$
String[] keySplitValues = schemaSelected.toString().split(" - ");
if (keySplitValues.length > 1) {
String connectionId = keySplitValues[0];
String tableLabel = keySplitValues[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property tmpproperty = repobj.getProperty();
if (tmpproperty != null) {
item = tmpproperty.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
final ConnectionItem connectionItem = (ConnectionItem) item;
if (connectionItem != null) {
connection = connectionItem.getConnection();
}
}
if (item != null && item instanceof ConnectionItem) {
boolean findTable = false;
Set<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = null;
IGenericWizardService wizardService = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
}
if (wizardService != null && wizardService.isGenericItem(item)) {
tables = new HashSet<>(wizardService.getMetadataTables(connection));
} else {
tables = ConnectionHelper.getTables(connection);
}
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : tables) {
if (table.getLabel().equals(tableLabel)) {
repositoryMetadata = ConvertionHelper.convert(table);
newRepositoryIdValue = schemaSelected;
findTable = true;
break;
}
}
if (!findTable) {
repositoryMetadata = new MetadataTable();
}
} else {
repositoryMetadata = new MetadataTable();
}
} else {
// value only got a empty string
repositoryMetadata = new MetadataTable();
}
} else {
baseCommand = new PropertyChangeCommand(elem, fullParamName, value);
}
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
CompoundCommand cc = new CompoundCommand();
if (baseCommand != null) {
cc.add(baseCommand);
} else {
RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, newRepositoryIdValue, null);
changeMetadataCommand.setConnection(connection);
cc.add(changeMetadataCommand);
}
// unuse the validation rules of the component.
if (isValRulesLost) {
ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
}
return cc;
}
return null;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ComboController method createButtonCommand.
/**
* This method is used for "Guess Query" button.
*
* @return
*/
private Command createButtonCommand() {
IMetadataTable repositoryMetadata = null;
IMetadataTable newRepositoryMetadata = null;
String realTableName = null;
String realTableId = null;
// Only for getting the real table name.
if (elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
String paramName;
IElementParameter repositorySchemaTypeParameter = elem.getElementParameter(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
Object repositoryControl = hashCurControls.get(repositorySchemaTypeParameter.getName());
paramName = EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
if (repositoryControl != null) {
String selectedComboItem = ((CCombo) repositoryControl).getText();
if (selectedComboItem != null && selectedComboItem.length() > 0) {
//$NON-NLS-1$
String value = new String("");
for (int i = 0; i < elem.getElementParameters().size(); i++) {
IElementParameter param = elem.getElementParameters().get(i);
if (param.getName().equals(paramName)) {
for (int j = 0; j < param.getListItemsValue().length; j++) {
if (selectedComboItem.equals(param.getListItemsDisplayName()[j])) {
value = (String) param.getListItemsValue()[j];
}
}
}
}
if (elem instanceof Node) {
// this.dynamicProperty.updateRepositoryList();
String connectionId = value.toString().split(" - ")[0];
String tableLabel = value.toString().split(" - ")[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
boolean findTable = false;
Connection connection = ((ConnectionItem) item).getConnection();
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
if (table.getLabel().equals(tableLabel)) {
repositoryMetadata = ConvertionHelper.convert(table);
findTable = true;
break;
}
}
if (!findTable) {
repositoryMetadata = new MetadataTable();
}
}
// if (repositoryTableMap.containsKey(value)) {
// repositoryMetadata = repositoryTableMap.get(value);
// realTableName = repositoryMetadata.getTableName();
// realTableId = repositoryMetadata.getId();
// } else {
// repositoryMetadata = new MetadataTable();
// }
}
}
}
}
// Ends
QueryGuessCommand cmd = null;
INode node = null;
if (elem instanceof INode) {
node = (INode) elem;
} else {
// else instanceof Connection
node = ((IConnection) elem).getSource();
}
newRepositoryMetadata = node.getMetadataList().get(0);
if (newRepositoryMetadata == null) {
String schemaSelected = (String) node.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
if (schemaSelected != null) {
String connectionId = schemaSelected.toString().split(" - ")[0];
String tableLabel = schemaSelected.toString().split(" - ")[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
boolean findTable = false;
Connection connection = ((ConnectionItem) item).getConnection();
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
if (table.getLabel().equals(tableLabel)) {
repositoryMetadata = ConvertionHelper.convert(table);
findTable = true;
break;
}
}
if (!findTable) {
repositoryMetadata = new MetadataTable();
}
}
// repositoryMetadata = repositoryTableMap.get(schemaSelected);
} else if (newRepositoryMetadata == null) {
MessageDialog.openWarning(new Shell(), Messages.getString("ComboController.alert"), //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("ComboController.nothingGuess"));
return cmd;
}
}
cmd = new QueryGuessCommand(node, newRepositoryMetadata);
/* parameter can be null,the setMaps won't use the third parameter */
cmd.setMaps(dynamicProperty.getTableIdAndDbTypeMap(), dynamicProperty.getTableIdAndDbSchemaMap(), null);
//$NON-NLS-1$
String type = getValueFromRepositoryName("TYPE");
cmd.setParameters(realTableId, realTableName, type);
return cmd;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ColumnListController method setColumnSize.
/**
* bqian Comment method "setSize".
*
* @param newLine
* @param node
* @param codes
* @param param
*/
private static void setColumnSize(Map<String, Object> newLine, IElement element, String[] codes, IElementParameter param) {
if (element instanceof INode && ((INode) element).getMetadataList().size() > 0) {
/* FORMATS should be syn whether this parameter is invisible or not */
// if (!param.isShow(((INode) element).getElementParameters()) && param.getName().equals("FORMATS")) {
// return;
// }
IMetadataTable table = ((INode) element).getMetadataList().get(0);
//$NON-NLS-1$
String lineName = (String) newLine.get("SCHEMA_COLUMN");
for (IMetadataColumn column : table.getListColumns()) {
if (lineName.equals(column.getLabel())) {
//$NON-NLS-1$
final Object size = newLine.get("SIZE");
final Integer length = column.getLength();
// wzhang modified to fix 12131.
if (size != null && length != null && length.intValue() > 0 && Integer.parseInt((String) size) == column.getLength()) {
break;
}
// }
if (length != null && length.intValue() > 0) {
// codes[1] is "SIZE"
//$NON-NLS-1$
newLine.put("SIZE", length.toString());
} else {
//$NON-NLS-1$
newLine.put("SIZE", null);
}
break;
}
}
}
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ColumnListController method getColumnList.
private static List<String> getColumnList(IElement element, String context, Map<String, Boolean> customColMap) {
List<String> columnList = new ArrayList<String>();
IMetadataTable table = null;
if (element instanceof INode) {
table = ((INode) element).getMetadataFromConnector(context);
if (table == null) {
List<IMetadataTable> tableList = ((INode) element).getMetadataList();
if (tableList.size() == 1) {
table = tableList.get(0);
} else {
for (IMetadataTable itable : tableList) {
if (itable.getAttachedConnector() != null && !itable.getAttachedConnector().equals("REJECT")) {
table = itable;
break;
}
}
}
// if (tableList.size() > 0) {
// table = tableList.get(0);
// }
}
} else if (element instanceof IConnection) {
table = ((IConnection) element).getMetadataTable();
}
if (table != null) {
for (IMetadataColumn column : table.getListColumns()) {
// add for bug 12034
String label = column.getLabel();
// if (element instanceof INode && ((INode) element).getComponent().getName().endsWith("tFileInputXML")) {//$NON-NLS-1$
// if (label.length() > 1) {
// String labelSub = label.substring(1);
// if (labelSub != null && KeywordsValidator.isKeyword(labelSub)) {
// label = labelSub;
// }
// }
// }
columnList.add(label);
if (customColMap != null) {
customColMap.put(column.getLabel(), column.isCustom());
}
}
}
return columnList;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class PropertiesTableEditorView method createColumns.
/*
* (non-Javadoc)
*
* @see
* org.talend.commons.ui.swt.extended.macrotable.AbstractExtendedTableViewer#createColumns(org.talend.commons.ui
* .swt.tableviewer.TableViewerCreator, org.eclipse.swt.widgets.Table)
*/
@SuppressWarnings("unchecked")
@Override
protected void createColumns(final TableViewerCreator<B> tableViewerCreator, final Table table) {
// there's two lists of values, one that will be in the table
// and the other will be stored as the current value in the property
// there is two lists because of the undo / redo capabilities
PropertiesTableEditorModel model = getModel();
TalendProposalProvider processProposalProvider = new TalendProposalProvider(model.getProcess());
String[] titles = model.getTitles();
final Object[] itemsValue = model.getItemsValue();
final String[] items = model.getItems();
// final Element elem = model.getElement();
final IElementParameter param = model.getElemParameter();
final IElement element = model.getElement();
for (int i = 0; i < titles.length; i++) {
final int curCol = i;
final IElementParameter currentParam = (IElementParameter) itemsValue[i];
// if all is empty, show it always.
boolean toDisplay = currentParam.isShow(currentParam.getShowIf(), currentParam.getNotShowIf(), element.getElementParameters());
if (!toDisplay) {
List<Map<String, Object>> fullTable = (List<Map<String, Object>>) param.getValue();
for (int curLine = 0; curLine < fullTable.size(); curLine++) {
((ElementParameter) currentParam).setCurrentRow(curLine);
if (currentParam.isShow(element.getElementParameters())) {
toDisplay = true;
break;
}
}
}
if (toDisplay) {
final TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle(titles[i]);
column.setModifiable(true);
column.setMinimumWidth(100);
column.setWeight(20);
switch(currentParam.getFieldType()) {
case CONTEXT_PARAM_NAME_LIST:
case CLOSED_LIST:
case LOOKUP_COLUMN_LIST:
case COLUMN_LIST:
case CONNECTION_LIST:
case DBTYPE_LIST:
case COMPONENT_LIST:
case PREV_COLUMN_LIST:
final ComboBoxCellEditor cellEditor = new ComboBoxCellEditor(table, currentParam.getListItemsDisplayName());
final IElementParameter copyOfTmpParam = currentParam;
((CCombo) cellEditor.getControl()).setEditable(false);
((CCombo) cellEditor.getControl()).setEnabled(!(param.isRepositoryValueUsed() || param.isReadOnly() || currentParam.isReadOnly()));
column.setCellEditor(cellEditor, new CellEditorValueAdapter() {
@Override
public String getColumnText(CellEditor cellEditor, Object bean, Object cellEditorValue) {
return (String) cellEditorValue;
}
@Override
public Object getOriginalTypedValue(CellEditor cellEditor, Object cellEditorTypedValue) {
Object returnedValue = null;
if (cellEditorTypedValue != null && cellEditorTypedValue instanceof Integer) {
int index = (Integer) cellEditorTypedValue;
String[] namesSet = ((CCombo) cellEditor.getControl()).getItems();
if (namesSet.length > 0 && index > -1 && index < namesSet.length) {
returnedValue = namesSet[index];
} else {
returnedValue = null;
}
} else {
returnedValue = null;
}
return returnedValue;
}
;
@Override
public Object getCellEditorTypedValue(CellEditor cellEditor, Object originalTypedValue) {
CCombo combo = (CCombo) cellEditor.getControl();
int rowNumber = ((Table) combo.getParent()).getSelectionIndex();
String[] listToDisplay = getItemsToDisplay(element, copyOfTmpParam, rowNumber);
if (!Arrays.equals(listToDisplay, ((ComboBoxCellEditor) cellEditor).getItems())) {
((ComboBoxCellEditor) cellEditor).setItems(listToDisplay);
}
Object returnedValue = 0;
if (originalTypedValue != null) {
String[] namesSet = listToDisplay;
for (int j = 0; j < namesSet.length; j++) {
if (namesSet[j].equals(originalTypedValue)) {
returnedValue = j;
break;
}
}
}
return returnedValue;
}
;
});
break;
case OPENED_LIST:
final EditableComboBoxCellEditor editCellEditor = new EditableComboBoxCellEditor(table, currentParam.getListItemsDisplayName());
table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String oldValue = null;
if (editCellEditor != null) {
if (!(editCellEditor.getValue() instanceof String)) {
return;
}
oldValue = (String) editCellEditor.getValue();
}
String[] columnItems = null;
if (table.getSelection() != null && table.getSelection().length > 0) {
TableItem tableItem = table.getSelection()[0];
if (tableItem.getData() instanceof Map) {
Map map = (Map) tableItem.getData();
if (currentParam.getFilter() != null && map.get(currentParam.getFilter()) instanceof String) {
String value = (String) map.get(currentParam.getFilter());
if (element instanceof Node) {
List<IConnection> listConnection = (List<IConnection>) ((Node) element).getInputs();
for (IConnection con : listConnection) {
if (con.getName().equals(value)) {
List<IMetadataColumn> columns = con.getMetadataTable().getListColumns();
columnItems = new String[columns.size()];
for (int i = 0; i < columns.size(); i++) {
columnItems[i] = columns.get(i).getLabel();
}
if (editCellEditor != null) {
List<String> ret = new ArrayList<String>();
for (String columnItem : columnItems) {
ret.add(columnItem);
}
for (int i = 0; i < currentParam.getListItemsDisplayName().length; i++) {
ret.add(currentParam.getListItemsDisplayName()[i]);
}
editCellEditor.setItems(ret.toArray(new String[0]));
editCellEditor.setValue(oldValue);
}
}
}
}
}
}
}
}
});
column.setCellEditor(editCellEditor);
break;
case MODULE_LIST:
column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
ModuleListCellEditor moduleEditor = new ModuleListCellEditor(table, currentParam, param);
moduleEditor.setTableEditorView(this);
column.setCellEditor(moduleEditor);
break;
case COLOR:
column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
// column.setDisplayedValue("");
column.setLabelProvider(null);
column.setCellEditor(new ColorCellEditor(table) {
@Override
protected void doSetValue(Object value) {
if (value instanceof String) {
super.doSetValue(ColorUtils.stringToRGB((String) value));
} else {
super.doSetValue(value);
}
}
@Override
protected void updateContents(Object value) {
if (value != null) {
if (value instanceof String) {
super.updateContents(ColorUtils.stringToRGB((String) value));
} else {
super.updateContents(value);
}
}
}
});
column.setColorProvider(new IColumnColorProvider() {
@Override
public Color getBackgroundColor(Object bean) {
Object value = ((Map<String, Object>) bean).get(items[curCol]);
if (value == null || (!(value instanceof String))) {
return Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
}
return new Color(null, ColorUtils.stringToRGB((String) value));
}
@Override
public Color getForegroundColor(Object bean) {
return null;
}
});
break;
case CHECK:
column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
CheckColumnSelectionListener tableColumnSelectionListener = new CheckColumnSelectionListener(column, tableViewerCreator, currentParam);
if (!currentParam.isReadOnly()) {
column.setTableColumnSelectionListener(tableColumnSelectionListener);
}
column.setTableEditorContent(new CheckboxTableEditorContent());
Boolean curValue = (Boolean) currentParam.getValue();
if (curValue == null) {
curValue = Boolean.FALSE;
}
tableColumnSelectionListener.setChecked(curValue.booleanValue());
if (curValue.booleanValue()) {
column.setImageHeader(ImageProvider.getImage(EImage.CHECKED_ICON));
} else {
column.setImageHeader(ImageProvider.getImage(EImage.UNCHECKED_ICON));
}
//$NON-NLS-1$
column.setDisplayedValue("");
break;
case SCHEMA_TYPE:
case SCHEMA_REFERENCE:
column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
final INode node = (INode) element;
// List<IMetadataTable> tables = node.getMetadataList();
// if (isEBCDICNode(node)) { // ebcdic
column.setLabelProvider(new IColumnLabelProvider() {
@Override
public String getLabel(Object bean) {
if (bean instanceof Map) {
Map<String, Object> valueMap = (Map<String, Object>) bean;
String value = (String) valueMap.get(IEbcdicConstant.FIELD_SCHEMA);
if (value != null && !"".equals(value)) {
//$NON-NLS-1$
IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeTableName(node, value);
if (metadataTable != null) {
if (isEBCDICNode(node)) {
if (isRepositorySchemaLine(node, valueMap)) {
//$NON-NLS-1$ //$NON-NLS-2$
return "Repository (" + metadataTable.getTableName() + ")";
} else {
//$NON-NLS-1$ //$NON-NLS-2$
return "Built-In (" + metadataTable.getTableName() + ")";
}
} else {
return metadataTable.getTableName();
}
} else {
return value;
}
}
}
//$NON-NLS-1$
return "";
}
});
// } else {
// column.setLabelProvider(null);
// }
SchemaCellEditor schemaEditor = new SchemaCellEditor(table, node);
schemaEditor.setTableEditorView(this);
column.setCellEditor(schemaEditor);
break;
case SAP_SCHEMA_TYPE:
column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
final INode sapNode = (INode) element;
column.setLabelProvider(new IColumnLabelProvider() {
@Override
public String getLabel(Object bean) {
if (bean instanceof Map) {
Map<String, Object> valueMap = (Map<String, Object>) bean;
String value = (String) valueMap.get(IEbcdicConstant.FIELD_SCHEMA);
if (value != null && !"".equals(value)) {
//$NON-NLS-1$
IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeTableName(sapNode, value);
if (metadataTable != null) {
if (isEBCDICNode(sapNode)) {
if (isRepositorySchemaLine(sapNode, valueMap)) {
//$NON-NLS-1$ //$NON-NLS-2$
return "Repository (" + metadataTable.getTableName() + ")";
} else {
//$NON-NLS-1$ //$NON-NLS-2$
return "Built-In (" + metadataTable.getTableName() + ")";
}
} else if (isSAPNode(sapNode)) {
Object type = valueMap.get(ISAPConstant.TYPE);
if (type instanceof Integer) {
return "";
}
if (type.toString().equals(SINGLE) || type.toString().equals(STRUCTURE)) {
List<IMetadataColumn> columns = metadataTable.getListColumns(true);
StringBuffer values = new StringBuffer();
values.append(metadataTable.getTableName() + ":");
if (metadataTable.getListColumns(true).size() > 0) {
for (IMetadataColumn column : columns) {
values.append(column.getDefault() + ",");
}
String ret = values.toString();
return ret.substring(0, ret.length() - 1);
}
} else {
return metadataTable.getTableName();
}
} else {
return metadataTable.getTableName();
}
} else {
return value;
}
}
}
//$NON-NLS-1$
return "";
}
});
schemaEditor = new SchemaCellEditor(table, sapNode);
schemaEditor.setTableEditorView(this);
column.setCellEditor(schemaEditor);
break;
// hywang add for feature 6484
case RULE_TYPE:
//$NON-NLS-1$
column.setTitle("Rule");
column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
final INode node1 = (INode) element;
column.setLabelProvider(new IColumnLabelProvider() {
@Override
public String getLabel(Object bean) {
if (bean instanceof Map) {
Map<String, Object> valueMap = (Map<String, Object>) bean;
String value = (String) valueMap.get(IRuleConstant.FIELD_RULE);
if (value != null && !"".equals(value)) {
//$NON-NLS-1$
IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeTableName(node1, value);
if (metadataTable != null) {
return metadataTable.getTableName();
} else {
return value;
}
}
}
//$NON-NLS-1$
return "";
}
});
RuleCellEditor ruleEditor = new RuleCellEditor(table, node1);
ruleEditor.setTableEditorView(this);
column.setCellEditor(ruleEditor);
break;
case SCHEMA_XPATH_QUERYS:
column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
final INode node2 = (INode) element;
SchemaXPathQuerysCellEditor schemaXPathEditor = new SchemaXPathQuerysCellEditor(table, node2);
schemaXPathEditor.setTableEditorView(this);
column.setCellEditor(schemaXPathEditor);
break;
case MULTI_PATTERN:
column.setModifiable(true);
PatternCellEditor patternEditor = new PatternCellEditor(table, element);
patternEditor.setTableEditorView(this);
column.setCellEditor(patternEditor);
break;
case PATTERN_PROPERTY:
column.setModifiable(true);
PatternPropertyCellEditor patternPropertyEditor = new PatternPropertyCellEditor(table, element);
patternPropertyEditor.setTableEditorView(this);
column.setCellEditor(patternPropertyEditor);
break;
default:
// TEXT
TextCellEditor tcEditor = null;
if (((i == 0) && (param.isBasedOnSchema() || param.isBasedOnSubjobStarts())) || (param.isRepositoryValueUsed()) || (param.isReadOnly()) || currentParam.isReadOnly()) {
// read only cell
if (!param.getElement().isReadOnly() && (param.getName().equals("HADOOP_ADVANCED_PROPERTIES") || param.getName().equals("SPARK_ADVANCED_PROPERTIES") || param.getName().equals("HBASE_PARAMETERS"))) {
if (currentParam.isNoContextAssist()) {
tcEditor = new TextCellEditor(table);
} else {
TextCellEditorWithProposal textCellEditor = new TextCellEditorWithProposal(table, column);
textCellEditor.setContentProposalProvider(processProposalProvider);
tcEditor = textCellEditor;
}
}
} else {
// writable cell
if (currentParam.isNoContextAssist()) {
tcEditor = new TextCellEditor(table);
} else {
TextCellEditorWithProposal textCellEditor = new TextCellEditorWithProposal(table, column);
textCellEditor.setContentProposalProvider(processProposalProvider);
tcEditor = textCellEditor;
}
}
if (tcEditor != null) {
column.setCellEditor(tcEditor);
column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
}
}
// for all kinds of column, check if read only or not when edit the field.
column.setColumnCellModifier(new ColumnCellModifier(column) {
@Override
public boolean canModify(Object bean) {
if (param.getName().equals("HADOOP_ADVANCED_PROPERTIES") || param.getName().equals("SPARK_ADVANCED_PROPERTIES") || param.getName().equals("HBASE_PARAMETERS")) {
boolean canModify = super.canModify(bean);
if (canModify) {
Map<String, Object> valueMap = (Map<String, Object>) bean;
List<Map<String, Object>> fullValues = (List<Map<String, Object>>) param.getValue();
((ElementParameter) currentParam).setCurrentRow(fullValues.indexOf(valueMap));
if (currentParam.isReadOnly(element.getElementParameters())) {
return false;
}
} else {
Map<String, Object> valueMap = (Map<String, Object>) bean;
if (valueMap.get("BUILDIN") != null && valueMap.get("BUILDIN").equals("TRUE")) {
return true;
} else {
return false;
}
}
return canModify;
}
boolean canModify = super.canModify(bean);
if (canModify) {
Map<String, Object> valueMap = (Map<String, Object>) bean;
List<Map<String, Object>> fullValues = (List<Map<String, Object>>) param.getValue();
((ElementParameter) currentParam).setCurrentRow(fullValues.indexOf(valueMap));
if (currentParam.isReadOnly(element.getElementParameters())) {
return false;
}
}
return canModify;
}
});
column.setColorProvider(new IColumnColorProvider<B>() {
@Override
public Color getBackgroundColor(B bean) {
Map<String, Object> valueMap = (Map<String, Object>) bean;
List<Map<String, Object>> fullValues = (List<Map<String, Object>>) param.getValue();
// hyWang add varriable index for bug 7294
int index = fullValues.indexOf(valueMap);
if (index >= 0) {
((ElementParameter) currentParam).setCurrentRow(index);
if (currentParam.isReadOnly(element.getElementParameters())) {
return AbstractMetadataTableEditorView.READONLY_CELL_BG_COLOR;
}
}
if (param.getName().equals("HADOOP_ADVANCED_PROPERTIES") || param.getName().equals("SPARK_ADVANCED_PROPERTIES") || param.getName().equals("HBASE_PARAMETERS")) {
if (valueMap.get("BUILDIN") == null || valueMap.get("BUILDIN") != null && valueMap.get("BUILDIN").equals("")) {
return Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
}
}
if (currentParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
Object value = ((Map<String, Object>) bean).get(items[curCol]);
boolean found = false;
Object[] items = currentParam.getListItemsValue();
for (Object item : items) {
if (item.equals(value)) {
found = true;
break;
}
}
if (!found) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
}
return null;
}
@Override
public Color getForegroundColor(B bean) {
return null;
}
});
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<B, Object>() {
@Override
public Object get(B bean) {
Object value = ((Map<String, Object>) bean).get(items[curCol]);
if (value == null) {
//$NON-NLS-1$
return "";
}
if (itemsValue[curCol] instanceof IElementParameter) {
IElementParameter tmpParam = (IElementParameter) itemsValue[curCol];
boolean hideValue = false;
if (!tmpParam.isReadOnly()) {
if ((tmpParam.getReadOnlyIf() != null || tmpParam.getNotReadOnlyIf() != null) && tmpParam.isReadOnly(element.getElementParameters())) {
hideValue = true;
}
}
switch(tmpParam.getFieldType()) {
case CONTEXT_PARAM_NAME_LIST:
case CLOSED_LIST:
case COMPONENT_LIST:
case COLUMN_LIST:
case CONNECTION_LIST:
case LOOKUP_COLUMN_LIST:
case PREV_COLUMN_LIST:
case DBTYPE_LIST:
if (hideValue) {
//$NON-NLS-1$
return "";
}
String[] namesSet = tmpParam.getListItemsDisplayName();
if (namesSet.length == 0) {
return tmpParam.getDefaultClosedListValue();
}
if (value instanceof String) {
boolean found = false;
int index = 0;
if (currentParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
// if not found, won't use first(index 0) instead
index = -1;
}
Object[] items = currentParam.getListItemsValue();
for (int j = 0; j < items.length && !found; j++) {
if (items[j].equals(value)) {
found = true;
index = j;
}
}
value = new Integer(index);
}
if (value != null && ((Integer) value) >= 0) {
return namesSet[(Integer) value];
}
return null;
case OPENED_LIST:
if (hideValue) {
//$NON-NLS-1$
return "";
}
String[] listItemsValue = tmpParam.getListItemsDisplayName();
if (listItemsValue.length == 0) {
return value;
}
int index = -1;
if (value instanceof String) {
boolean found = false;
Object[] items = ((IElementParameter) itemsValue[curCol]).getListItemsValue();
for (int j = 0; j < items.length && !found; j++) {
if (items[j].equals(value)) {
found = true;
index = j;
}
}
}
Integer count = new Integer(index);
if (count >= 0) {
return listItemsValue[count];
} else if (count < 0) {
return value;
}
return value;
case CHECK:
if (hideValue) {
return false;
}
if (value instanceof String) {
return new Boolean((String) value);
}
return value;
case RADIO:
if (hideValue) {
return false;
}
if (value instanceof String) {
return new Boolean((String) value);
}
return value;
case COLOR:
if (value instanceof String) {
return ColorUtils.stringToRGB((String) value);
}
// already RGB
return value;
default:
// TEXT
if (hideValue) {
//$NON-NLS-1$
return "";
}
return value;
}
}
return value;
}
@Override
public void set(B bean, Object value) {
Object finalValue = value;
IElementParameter tmpParam = (IElementParameter) itemsValue[curCol];
// TODO should test if this parameter is contained in any other show if / not show if, etc..
boolean included = false;
for (Object object : param.getListItemsValue()) {
if (object instanceof IElementParameter) {
if (((IElementParameter) object).getShowIf() != null && ((IElementParameter) object).getShowIf().contains(tmpParam.getName())) {
included = true;
break;
}
if (((IElementParameter) object).getNotShowIf() != null && ((IElementParameter) object).getNotShowIf().contains(tmpParam.getName())) {
included = true;
break;
}
if (((IElementParameter) object).getReadOnlyIf() != null && ((IElementParameter) object).getReadOnlyIf().contains(tmpParam.getName())) {
included = true;
break;
}
if (((IElementParameter) object).getNotReadOnlyIf() != null && ((IElementParameter) object).getNotReadOnlyIf().contains(tmpParam.getName())) {
included = true;
break;
}
}
}
if (included) {
IElementParameter param = element.getElementParameter(EParameterName.UPDATE_COMPONENTS.getName());
if (param != null) {
param.setValue(Boolean.TRUE);
}
}
boolean isNeedReCheck = false;
switch(tmpParam.getFieldType()) {
case CONTEXT_PARAM_NAME_LIST:
case CLOSED_LIST:
case COLUMN_LIST:
case COMPONENT_LIST:
case CONNECTION_LIST:
case LOOKUP_COLUMN_LIST:
case PREV_COLUMN_LIST:
isNeedReCheck = true;
if (value instanceof String) {
Object[] itemNames = ((IElementParameter) itemsValue[curCol]).getListItemsDisplayName();
Object[] itemValues = ((IElementParameter) itemsValue[curCol]).getListItemsValue();
boolean found = false;
int index = 0;
for (int j = 0; j < itemNames.length && !found; j++) {
if (itemNames[j].equals(value)) {
found = true;
index = j;
}
}
if (value != null && (index >= 0)) {
finalValue = itemValues[new Integer(index)];
}
}
break;
case OPENED_LIST:
if (value instanceof String) {
Object[] itemNames = ((IElementParameter) itemsValue[curCol]).getListItemsDisplayName();
Object[] itemValues = ((IElementParameter) itemsValue[curCol]).getListItemsValue();
boolean found = false;
int index = -1;
for (int j = 0; j < itemNames.length && !found; j++) {
if (itemNames[j].equals(value)) {
found = true;
index = j;
}
}
if (value != null && (index >= 0)) {
finalValue = itemValues[new Integer(index)];
} else if (value != null && (index < 0)) {
finalValue = value;
}
}
break;
case COLOR:
if (value instanceof RGB) {
RGB rgb = (RGB) value;
//$NON-NLS-1$ //$NON-NLS-2$
finalValue = rgb.red + ";" + rgb.green + ";" + rgb.blue;
}
default:
}
((Map<String, Object>) bean).put(items[curCol], finalValue);
resetValuesIfNeeded(element, param, (Map<String, Object>) bean);
/*
* TDI-6568, in fact, no need reset the value. just want to enable
* "firePropertyChange(RETURNS_CHANGED, null, null)" in Node.
*/
if (param.getFieldType().equals(EParameterFieldType.TABLE)) {
element.setPropertyValue(param.getName(), param.getValue());
}
if (isNeedReCheck && element instanceof Node) {
IProcess process = ((Node) element).getProcess();
if (process instanceof IProcess2) {
((IProcess2) process).checkProcess();
}
// enable to refresh component setting after change modules.
// so far, for cMessagingEndpoint (TUP-1119)
final IElementParameter copyOfTmpParam = currentParam;
if (element != null && "LIBPATH".equals(copyOfTmpParam.getName())) {
//$NON-NLS-1$
IElementParameter updateComponentsParam = element.getElementParameter(EParameterName.UPDATE_COMPONENTS.getName());
if (updateComponentsParam != null) {
updateComponentsParam.setValue(Boolean.TRUE);
}
}
}
}
});
}
}
}
Aggregations