use of org.talend.core.ui.metadata.dialog.MetadataDialog in project tdi-studio-se by Talend.
the class SapSchemaTypeController method createButtonCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createButtonCommand(org
* .eclipse.swt.widgets.Button)
*/
@Override
protected Command createButtonCommand(Button button) {
// see 0003766: Problems with the read only mode of the properties on repository mode.
if (checkForRepositoryShema(button)) {
return null;
}
Button inputButton = button;
IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
if (inputButton.getData(NAME).equals(SCHEMA)) {
// this map wil hold the all input connection for the tUnite component
Map<INode, Map<IMetadataTable, Boolean>> inputInfos = new HashMap<INode, Map<IMetadataTable, Boolean>>();
INode node;
if (elem instanceof Node) {
node = (INode) elem;
} else {
// else instanceof Connection
node = ((IConnection) elem).getSource();
}
IMetadataTable inputMetadata = null, inputMetaCopy = null;
Connection inputConec = null;
String propertyName = (String) inputButton.getData(PARAMETER_NAME);
IElementParameter param = node.getElementParameter(propertyName);
IElementParameter connectionParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
String connectionName = null;
if (connectionParam != null) {
connectionName = (String) connectionParam.getValue();
}
Object obj = button.getData(FORCE_READ_ONLY);
boolean forceReadOnly = false;
if (obj != null) {
forceReadOnly = (Boolean) obj;
}
boolean inputReadOnly = false, outputReadOnly = false, inputReadOnlyNode = false, inputReadOnlyParam = false;
for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE) || connec.getLineStyle().equals(EConnectionType.FLOW_MERGE) || connec.getLineStyle() == EConnectionType.FLOW_REF)) {
if (connectionName != null && !connec.getName().equals(connectionName)) {
continue;
}
inputMetadata = connec.getMetadataTable();
inputMetaCopy = inputMetadata.clone();
inputConec = connec;
if (connec.getSource().isReadOnly()) {
inputReadOnlyNode = true;
} else {
for (IElementParameter curParam : connec.getSource().getElementParameters()) {
if (curParam.getFieldType() == EParameterFieldType.SCHEMA_TYPE) {
if (curParam.isReadOnly()) {
inputReadOnlyParam = true;
}
}
}
}
// check if the inputMetadata is readonly
if (inputMetadata != null) {
for (IMetadataColumn column : inputMetadata.getListColumns(true)) {
IMetadataColumn columnCopied = inputMetaCopy.getColumn(column.getLabel());
columnCopied.setCustom(column.isCustom());
columnCopied.setReadOnly(column.isReadOnly());
}
inputMetaCopy.setReadOnly(inputMetadata.isReadOnly());
inputReadOnly = prepareReadOnlyTable(inputMetaCopy, inputReadOnlyParam, inputReadOnlyNode);
}
// store the value for Dialog
Map<IMetadataTable, Boolean> oneInput = new HashMap<IMetadataTable, Boolean>();
oneInput.put(inputMetaCopy, inputReadOnly);
inputInfos.put(connec.getSource(), oneInput);
}
}
if (connectionParam != null && inputMetadata == null) {
//$NON-NLS-1$
MessageDialog.openError(//$NON-NLS-1$
button.getShell(), //$NON-NLS-1$
Messages.getString("SchemaTypeController.inputNotSet"), //$NON-NLS-1$
Messages.getString("SchemaTypeController.connectionNotAvaliable"));
return null;
}
IMetadataTable originaleMetadataTable = getMetadataTableFromXml(node);
// check if the outputMetadata is readonly
IMetadataTable originaleOutputTable = node.getMetadataFromConnector(param.getContext());
// when several schema_type button ,need get the right one which is opening
IElementParameter schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
// need setRepository here
if (!param.getContext().equals(schemaParam.getContext())) {
schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
}
if (schemaParam != null && EmfComponent.REPOSITORY.equals(schemaParam.getValue())) {
if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
((MetadataTable) originaleOutputTable).setRepository(true);
}
} else if (schemaParam != null && EmfComponent.BUILTIN.equals(schemaParam.getValue())) {
if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
((MetadataTable) originaleOutputTable).setRepository(false);
}
}
if ("tUniservBTGeneric".equals(node.getComponent().getName())) {
originaleOutputTable = node.getMetadataTable("OUTPUT_SCHEMA");
}
IMetadataTable outputMetaCopy = originaleOutputTable.clone(true);
for (IMetadataColumn column : originaleOutputTable.getListColumns(true)) {
IMetadataColumn columnCopied = outputMetaCopy.getColumn(column.getLabel());
columnCopied.setCustom(column.isCustom());
columnCopied.setReadOnly(column.isReadOnly());
if (//$NON-NLS-1$ //$NON-NLS-2$
("tLogCatcher".equals(node.getComponent().getName()) || "tStatCatcher".equals(node.getComponent().getName())) && !outputMetaCopy.sameMetadataAs(originaleMetadataTable, IMetadataColumn.OPTIONS_NONE)) {
columnCopied.setReadOnly(false);
}
// setColumnLength(node, param, columnCopied);
}
outputMetaCopy.setReadOnly(originaleOutputTable.isReadOnly() || param.isReadOnly(node.getElementParametersWithChildrens()));
if (//$NON-NLS-1$ //$NON-NLS-2$
("tLogCatcher".equals(node.getComponent().getName()) || "tStatCatcher".equals(node.getComponent().getName())) && !outputMetaCopy.sameMetadataAs(originaleMetadataTable, IMetadataColumn.OPTIONS_NONE)) {
outputMetaCopy.setReadOnly(false);
}
//$NON-NLS-1$
IElementParameter schemaTypeParam = param.getChildParameters().get("SCHEMA_TYPE");
List<IElementParameterDefaultValue> defaultValues = schemaTypeParam.getDefaultValues();
for (IElementParameterDefaultValue elementParameterDefaultValue : defaultValues) {
if (elementParameterDefaultValue.getDefaultValue() instanceof MetadataTable) {
MetadataTable table = (MetadataTable) elementParameterDefaultValue.getDefaultValue();
outputMetaCopy.setReadOnlyColumnPosition(table.getReadOnlyColumnPosition());
break;
}
}
outputMetaCopy.sortCustomColumns();
if (!forceReadOnly) {
outputReadOnly = prepareReadOnlyTable(outputMetaCopy, param.isReadOnly(), node.isReadOnly());
} else {
outputReadOnly = true;
}
// create the MetadataDialog
MetadataDialog metaDialog = null;
if (inputMetadata != null) {
if (inputInfos != null && inputInfos.size() > 1 && connectionName == null) {
MetadataDialogForMerge metaDialogForMerge = new MetadataDialogForMerge(composite.getShell(), inputInfos, outputMetaCopy, node, getCommandStack());
//$NON-NLS-1$
metaDialogForMerge.setText(Messages.getString("SchemaController.schemaOf") + node.getLabel());
metaDialogForMerge.setInputReadOnly(inputReadOnly);
metaDialogForMerge.setOutputReadOnly(outputReadOnly);
if (metaDialogForMerge.open() == MetadataDialogForMerge.OK) {
// inputMetaCopy = metaDialog.getInputMetaData();
outputMetaCopy = metaDialogForMerge.getOutputMetaData();
// check if the metadata is modified
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
} else {
if (inputMetadata != null) {
// Notice: the Map inputInfos maybe is modified by the dialog.
Set<INode> inputNodes = inputInfos.keySet();
for (INode inputNode : inputNodes) {
Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
if (!inputMetaCopy.sameMetadataAs(inputNode.getMetadataList().get(0), IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
}
}
}
// create the changeMetadataCommand
if (modified) {
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
Command changeMetadataCommand = null;
// only output, no input
if (inputInfos.isEmpty()) {
changeMetadataCommand = new ChangeMetadataCommand(node, param, null, null, null, originaleOutputTable, outputMetaCopy);
} else {
Set<INode> inputNodes = inputInfos.keySet();
int count = 0;
for (INode inputNode : inputNodes) {
Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
if (count == 0) {
changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy);
} else {
changeMetadataCommand = changeMetadataCommand.chain(new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy));
}
count++;
}
}
return changeMetadataCommand;
}
}
} else {
INode inputNode = (inputConec.getSource());
if (inputMetaCopy.getAttachedConnector() == null) {
INodeConnector mainConnector;
if (inputNode.isELTComponent()) {
mainConnector = inputNode.getConnectorFromType(EConnectionType.TABLE);
} else {
mainConnector = inputNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
}
inputMetaCopy.setAttachedConnector(mainConnector.getName());
}
// INodeConnector outputConnector = node.getConnectorFromName(param.getContext());
// if (outputConnector.getMaxLinkOutput() == 0 && (originaleOutputTable.getListColumns().size() ==
// 0)) {
// metaDialog = new MetadataDialog(composite.getShell(), inputMetaCopy, inputNode,
// getCommandStack());
// } else {
metaDialog = new MetadataDialog(composite.getShell(), inputMetaCopy, inputNode, outputMetaCopy, node, getCommandStack());
// }
}
} else {
metaDialog = new MetadataDialog(composite.getShell(), outputMetaCopy, node, getCommandStack());
}
if (metaDialog != null) {
//$NON-NLS-1$
metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", node.getLabel()));
metaDialog.setInputReadOnly(inputReadOnly);
metaDialog.setOutputReadOnly(outputReadOnly);
if (metaDialog.open() == MetadataDialog.OK) {
inputMetaCopy = metaDialog.getInputMetaData();
outputMetaCopy = metaDialog.getOutputMetaData();
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
} else {
if (inputMetadata != null) {
if (!inputMetaCopy.sameMetadataAs(inputMetadata, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
}
}
if (modified) {
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
INode inputNode = null;
if (inputConec != null) {
inputNode = inputConec.getSource();
}
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
return changeMetadataCommand;
}
}
}
} else if (inputButton.getData(NAME).equals(RETRIEVE_SCHEMA)) {
Node node = (Node) elem;
// String propertyName = (String) inputButton.getData(PARAMETER_NAME);
final Command cmd = RetrieveSchemaHelper.retrieveSchemasCommand(node);
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
return cmd;
} else if (inputButton.getData(NAME).equals(RESET_COLUMNS)) {
Node node = (Node) elem;
String propertyName = (String) inputButton.getData(PARAMETER_NAME);
IElementParameter param = node.getElementParameter(propertyName);
final Command cmd = SynchronizeSchemaHelper.createCommand(node, param);
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
return cmd;
} else if (button.getData(NAME).equals(REPOSITORY_CHOICE)) {
String paramName = (String) button.getData(PARAMETER_NAME);
IElementParameter schemaParam = elem.getElementParameter(paramName);
ERepositoryObjectType type = ERepositoryObjectType.METADATA_CON_TABLE;
String filter = schemaParam.getFilter();
if (elem instanceof Node) {
Node sapNode = (Node) elem;
if (sapNode.getComponent().getName().startsWith("tSAP") && !sapNode.getComponent().getName().startsWith("tSAPHana")) {
//$NON-NLS-1$ //$NON-NLS-2$
type = ERepositoryObjectType.METADATA_SAP_FUNCTION;
} else if (sapNode.getComponent().getName().startsWith("tESB")) {
//$NON-NLS-1$
filter = ERepositoryObjectType.SERVICESOPERATION.getType();
}
}
RepositoryReviewDialog dialog = new RepositoryReviewDialog(button.getShell(), type, filter);
if (dialog.open() == RepositoryReviewDialog.OK) {
RepositoryNode node = dialog.getResult();
while (node.getObject().getProperty().getItem() == null || (!(node.getObject().getProperty().getItem() instanceof ConnectionItem))) {
node = node.getParent();
}
String id = dialog.getResult().getObject().getProperty().getId();
// The name is Table Name.
String name = dialog.getResult().getObject().getLabel();
if (name != null) {
if (elem instanceof Node) {
Node nodeElement = (Node) elem;
//$NON-NLS-1$
String value = id + " - " + name;
IMetadataTable repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(value);
if (nodeElement.getComponent().getName().equals("tSQLTemplateMerge")) {
if (paramName.equals("SCHEMA")) {
paramName = "SOURCE_TABLE";
Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
executeCommand(dbSelectorCommand);
Text labelText = (Text) hashCurControls.get(paramName);
labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
paramName = "SCHEMA:REPOSITORY_SCHEMA_TYPE";
dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
executeCommand(dbSelectorCommand);
labelText = (Text) hashCurControls.get(paramName);
labelText.setText(TalendTextUtils.addQuotes(name));
paramName = "SCHEMA";
} else if (paramName.equals("SCHEMA_TARGET")) {
paramName = "TARGET_TABLE";
Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
executeCommand(dbSelectorCommand);
Text labelText = (Text) hashCurControls.get(paramName);
labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
paramName = "SCHEMA_TARGET:REPOSITORY_SCHEMA_TYPE";
dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
executeCommand(dbSelectorCommand);
labelText = (Text) hashCurControls.get(paramName);
labelText.setText(TalendTextUtils.addQuotes(name));
paramName = "SCHEMA_TARGET";
}
} else if (nodeElement.getComponent().getName().startsWith("tSQLTemplate")) {
if (paramName.equals("SCHEMA")) {
paramName = "TABLE_NAME";
Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
executeCommand(dbSelectorCommand);
Text labelText = (Text) hashCurControls.get(paramName);
labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
paramName = "SCHEMA:REPOSITORY_SCHEMA_TYPE";
dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
executeCommand(dbSelectorCommand);
labelText = (Text) hashCurControls.get(paramName);
labelText.setText(TalendTextUtils.addQuotes(name));
paramName = "SCHEMA";
} else if (paramName.equals("SCHEMA_TARGET")) {
paramName = "TABLE_NAME_TARGET";
Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
executeCommand(dbSelectorCommand);
Text labelText = (Text) hashCurControls.get(paramName);
labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
paramName = "SCHEMA_TARGET:REPOSITORY_SCHEMA_TYPE";
dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
executeCommand(dbSelectorCommand);
labelText = (Text) hashCurControls.get(paramName);
labelText.setText(TalendTextUtils.addQuotes(name));
paramName = "SCHEMA_TARGET";
}
} else {
Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
executeCommand(dbSelectorCommand);
Text labelText = (Text) hashCurControls.get(paramName);
if (labelText != null) {
labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
}
}
}
}
//$NON-NLS-1$
String value = id + " - " + name;
//$NON-NLS-1$
String fullParamName = paramName + ":" + getRepositoryChoiceParamName();
org.talend.core.model.metadata.builder.connection.Connection connection = null;
if (elem instanceof Node) {
IMetadataTable repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(value);
connection = MetadataToolHelper.getConnectionFromRepository(value);
// For SAP see bug 5423
String functionId = node.getParent().getId();
if (//$NON-NLS-1$//$NON-NLS-2$
((Node) elem).getUniqueName().startsWith("tSAP") && !((Node) elem).getUniqueName().startsWith("tSAPHana") && functionId != "-1") {
//$NON-NLS-1$
Node sapNode = (Node) elem;
repositoryMetadata = getMetadataFromRepository(id, functionId, name);
String functionName = node.getParent().getObject().getLabel();
for (IElementParameter param : sapNode.getElementParameters()) {
SAPParametersUtils.retrieveSAPParams(elem, connection, param, functionName);
}
}
// else {
// repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(value);
// }
// connection = MetadataTool.getConnectionFromRepository(value);
// For validation rule.
boolean isValRulesLost = false;
IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
if (currentValRuleObj != null) {
List<IRepositoryViewObject> valRuleObjs = ValidationRulesUtil.getRelatedValidationRuleObjs(value);
if (!ValidationRulesUtil.isCurrentValRuleObjInList(valRuleObjs, currentValRuleObj)) {
if (!MessageDialog.openConfirm(button.getShell(), //$NON-NLS-1$
Messages.getString("SchemaTypeController.validationrule.title.confirm"), Messages.getString("SchemaTypeController.validationrule.selectMetadataMsg"))) {
//$NON-NLS-1$
return null;
} else {
isValRulesLost = true;
}
}
}
if (repositoryMetadata == null) {
repositoryMetadata = new MetadataTable();
}
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
CompoundCommand cc = new CompoundCommand();
RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, null, null);
changeMetadataCommand.setConnection(connection);
cc.add(changeMetadataCommand);
if (isValRulesLost) {
ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
}
return cc;
}
}
} else if (button.getData(NAME).equals(COPY_CHILD_COLUMNS)) {
// 0004322: tRunJob can import the tBufferOutput schema from the son job
// 0010489 modify
String paramName = (String) button.getData(PARAMETER_NAME);
IElementParameter param = elem.getElementParameter(paramName);
IElementParameter processParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
IElementParameter processIdParam = processParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
String id = (String) processIdParam.getValue();
Item item = ItemCacheManager.getProcessItem(id);
Node node = (Node) elem;
copySchemaFromChildJob(node, item);
// pop up the schema dialog
MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), node.getMetadataList().get(0), node, getCommandStack());
//$NON-NLS-1$
metaDialog.setText(Messages.getString("SchemaController.schemaOf") + node.getLabel());
if (metaDialog.open() == MetadataDialog.OK) {
IMetadataTable outputMetaData = metaDialog.getOutputMetaData();
return new ChangeMetadataCommand(node, param, null, outputMetaData);
}
}
return null;
}
use of org.talend.core.ui.metadata.dialog.MetadataDialog in project tdi-studio-se by Talend.
the class DCSchemaController method createButtonCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createButtonCommand(org
* .eclipse.swt.widgets.Button)
*/
@SuppressWarnings("unchecked")
protected Command createButtonCommand(Button button) {
Button inputButton = button;
Map<INode, Map<IMetadataTable, Boolean>> inputInfos = new HashMap<INode, Map<IMetadataTable, Boolean>>();
Node node;
if (elem instanceof Node) {
node = (Node) elem;
} else {
// else instanceof Connection
node = (Node) ((Connection) elem).getSource();
}
String componentName = node.getComponent().getName();
initConnectionParameters();
IContextManager manager;
if (part == null) {
manager = new EmptyContextManager();
} else {
manager = part.getProcess().getContextManager();
}
IElement oldElement = elem;
if (isUseExistingConnection()) {
this.elem = connectionNode;
initConnectionParametersWithContext(connectionNode, manager.getDefaultContext());
} else {
initConnectionParametersWithContext(elem, manager.getDefaultContext());
}
this.elem = oldElement;
if (!GlobalServiceRegister.getDefault().isServiceRegistered(IDCService.class)) {
return null;
}
IDCService restService = (IDCService) GlobalServiceRegister.getDefault().getService(IDCService.class);
restService.setupRestHelperInstance(connParameters.getHost(), connParameters.getPort(), connParameters.getUserName(), connParameters.getPassword(), connParameters.getDirectory(), connParameters.isHttps());
String entityName = elem.getPropertyValue("ENTITY").toString().replaceAll("\"", "");
IMetadataTable inputMetadata = null, inputMetaCopy = null;
Connection inputConec = null;
String propertyName = (String) inputButton.getData(PARAMETER_NAME);
IElementParameter param = node.getElementParameter(propertyName);
IElementParameter connectionParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
String connectionName = null;
if (connectionParam != null) {
connectionName = (String) connectionParam.getValue();
}
boolean inputReadOnly = false, outputReadOnly = false, inputReadOnlyNode = false, inputReadOnlyParam = false;
for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
if (connec.isActivate() && (EConnectionType.FLOW_MAIN.equals(connec.getLineStyle()) || EConnectionType.TABLE.equals(connec.getLineStyle()) || EConnectionType.FLOW_MERGE.equals(connec.getLineStyle()) || EConnectionType.FLOW_REF.equals(connec.getLineStyle()))) {
if (connectionName != null && !connec.getName().equals(connectionName)) {
continue;
}
inputMetadata = connec.getMetadataTable();
inputMetaCopy = inputMetadata.clone();
inputConec = connec;
if (connec.getSource().isReadOnly()) {
inputReadOnlyNode = true;
} else {
for (IElementParameter curParam : connec.getSource().getElementParameters()) {
if (curParam.getFieldType() == EParameterFieldType.SCHEMA_TYPE || curParam.getFieldType() == EParameterFieldType.DCSCHEMA) {
if (curParam.isReadOnly()) {
inputReadOnlyParam = true;
}
}
}
}
// check if the inputMetadata is readonly
if (inputMetadata != null) {
for (IMetadataColumn column : inputMetadata.getListColumns()) {
IMetadataColumn columnCopied = inputMetaCopy.getColumn(column.getLabel());
columnCopied.setCustom(column.isCustom());
columnCopied.setReadOnly(column.isReadOnly());
}
inputMetaCopy.setReadOnly(inputMetadata.isReadOnly());
inputReadOnly = prepareReadOnlyTable(inputMetaCopy, inputReadOnlyParam, inputReadOnlyNode);
}
// store the value for Dialog
Map<IMetadataTable, Boolean> oneInput = new HashMap<IMetadataTable, Boolean>();
oneInput.put(inputMetaCopy, inputReadOnly);
inputInfos.put(connec.getSource(), oneInput);
}
}
if (connectionParam != null && inputMetadata == null) {
//$NON-NLS-1$
MessageDialog.openError(//$NON-NLS-1$
button.getShell(), //$NON-NLS-1$
Messages.getString("SchemaTypeController.inputNotSet"), //$NON-NLS-1$
Messages.getString("SchemaTypeController.connectionNotAvaliable"));
return null;
}
IMetadataTable originaleMetadataTable = getMetadataTableFromXml(node);
// check if the outputMetadata is readonly
IMetadataTable originaleOutputTable = node.getMetadataFromConnector(param.getContext());
IMetadataTable outputMetaCopy = originaleOutputTable.clone();
for (IMetadataColumn column : originaleOutputTable.getListColumns()) {
IMetadataColumn columnCopied = outputMetaCopy.getColumn(column.getLabel());
columnCopied.setCustom(column.isCustom());
columnCopied.setReadOnly(column.isReadOnly());
}
outputMetaCopy.setReadOnly(originaleOutputTable.isReadOnly() || param.isReadOnly(node.getElementParametersWithChildrens()));
outputMetaCopy.sortCustomColumns();
// create the MetadataDialog
MetadataDialog metaDialog = null;
if (inputMetadata != null) {
if (inputInfos != null && inputInfos.size() > 1 && connectionName == null) {
MetadataDialogForMerge metaDialogForMerge = new MetadataDialogForMerge(composite.getShell(), inputInfos, outputMetaCopy, node, getCommandStack());
//$NON-NLS-1$
metaDialogForMerge.setText(Messages.getString("SchemaController.schemaOf") + node.getLabel());
metaDialogForMerge.setInputReadOnly(inputReadOnly);
metaDialogForMerge.setOutputReadOnly(outputReadOnly);
if (metaDialogForMerge.open() == MetadataDialogForMerge.OK) {
outputMetaCopy = metaDialogForMerge.getOutputMetaData();
// check if the metadata is modified
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
} else {
if (inputMetadata != null) {
// Notice: the Map inputInfos maybe is modified by the dialog.
Set<INode> inputNodes = inputInfos.keySet();
for (INode inputNode : inputNodes) {
Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
if (!inputMetaCopy.sameMetadataAs(inputNode.getMetadataList().get(0), IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
}
}
}
// create the changeMetadataCommand
if (modified) {
Command changeMetadataCommand = null;
// only output, no input
if (inputInfos.isEmpty()) {
changeMetadataCommand = new ChangeMetadataCommand(node, param, null, null, null, originaleOutputTable, outputMetaCopy);
} else {
Set<INode> inputNodes = inputInfos.keySet();
int count = 0;
for (INode inputNode : inputNodes) {
Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
if (count == 0) {
changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy);
} else {
changeMetadataCommand = changeMetadataCommand.chain(new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy));
}
count++;
}
}
return changeMetadataCommand;
}
}
} else {
Node inputNode = (Node) (inputConec.getSource());
if (inputMetaCopy.getAttachedConnector() == null) {
INodeConnector mainConnector;
if (inputNode.isELTComponent()) {
mainConnector = inputNode.getConnectorFromType(EConnectionType.TABLE);
} else {
mainConnector = inputNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
}
inputMetaCopy.setAttachedConnector(mainConnector.getName());
}
metaDialog = new MetadataDialog(composite.getShell(), inputMetaCopy, inputNode, outputMetaCopy, node, getCommandStack());
}
} else {
metaDialog = new MetadataDialog(composite.getShell(), outputMetaCopy, node, getCommandStack());
}
/*
* Datacert: Populating data in the edit schema dialog
*
* @author : virtusa
*/
List<IMetadataColumn> columnList = new ArrayList<IMetadataColumn>();
String prefix = "";
if (componentName.equalsIgnoreCase(Messages.getString("DataCertController.tDataCertDenormalize.componentName"))) {
String denorCol = elem.getPropertyValue("DC_COLUMN_DENORMALIZE").toString().replaceAll("\"", "");
;
prefix = denorCol;
IMetadataTable inputTable = null;
if (node.getIncomingConnections() != null && node.getIncomingConnections().size() > 0) {
IConnection inputConn = node.getIncomingConnections().get(0);
if (inputConn != null) {
inputTable = inputConn.getMetadataTable();
}
}
if (inputTable != null) {
for (IMetadataColumn inCol : inputTable.getListColumns()) {
if (!inCol.getLabel().equals(denorCol)) {
columnList.add(inCol);
}
}
}
}
restService.addColumnsToSchema(entityName, componentName, prefix, columnList);
outputMetaCopy.setListColumns(columnList);
outputMetaCopy.setComment("Attribute Metadata");
outputMetaCopy.setLabel("Attribute Metadata");
outputMetaCopy.setTableName(entityName);
if (metaDialog != null) {
//$NON-NLS-1$
metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", node.getLabel()));
metaDialog.setInputReadOnly(false);
metaDialog.setOutputReadOnly(false);
if (metaDialog.open() == MetadataDialog.OK) {
outputMetaCopy = metaDialog.getOutputMetaData();
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
if (modified) {
Node inputNode = null;
if (inputConec != null) {
inputNode = (Node) inputConec.getSource();
}
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
return changeMetadataCommand;
}
}
}
return null;
}
use of org.talend.core.ui.metadata.dialog.MetadataDialog in project tdi-studio-se by Talend.
the class GuessSchemaController method createButtonCommand.
/**
* This method is used for "Guess Query" button.
*
* @return
*/
// modified by hyWang
private Command createButtonCommand(Button btn, IContextManager manager) {
this.btn = btn;
IElementParameter elementParameterFromField = elem.getElementParameterFromField(EParameterFieldType.MEMO_SQL);
memoSQL = (String) elementParameterFromField.getValue();
initConnectionParameters();
if (this.connParameters != null && memoSQL != null) {
initConnectionParametersWithContext(elem, manager.getDefaultContext());
// runShadowProcess();
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
useMockJob();
} else if (LanguageManager.getCurrentLanguage() == ECodeLanguage.PERL) {
IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
//$NON-NLS-1$ //$NON-NLS-2$
memoSQL = memoSQL.substring(1, memoSQL.length() - 1).trim().replace("\\'", "\'");
runShadowProcessForPerl();
if (columns != null && columns.size() > 0) {
Node node = (Node) elem;
IMetadataTable tempMetatable = new MetadataTable();
IMetadataTable inputMetaCopy, inputMetadata, outputMetaCopy, originaleOutputTable;
String propertyName = (String) btn.getData(PARAMETER_NAME);
IElementParameter param = node.getElementParameter(propertyName);
for (IElementParameter eParam : elem.getElementParameters()) {
if (eParam.getContext() != null) {
param = eParam;
}
}
originaleOutputTable = node.getMetadataFromConnector(param.getContext());
if (originaleOutputTable != null) {
outputMetaCopy = originaleOutputTable.clone();
}
tempMetatable.setListColumns(columns);
MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), tempMetatable, node, getCommandStack());
if (metaDialog != null) {
//$NON-NLS-1$
metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", node.getLabel()));
if (metaDialog.open() == MetadataDialog.OK) {
outputMetaCopy = metaDialog.getOutputMetaData();
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
if (modified) {
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, originaleOutputTable, outputMetaCopy);
return changeMetadataCommand;
}
}
}
}
}
if (changeMetadataCommand != null) {
return changeMetadataCommand;
}
}
return null;
}
use of org.talend.core.ui.metadata.dialog.MetadataDialog in project tdi-studio-se by Talend.
the class SchemaReferenceController method createButtonCommand.
@Override
protected Command createButtonCommand(Button button) {
if (checkForRepositoryShema(button)) {
return null;
}
Button inputButton = button;
IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
if (inputButton.getData(NAME).equals(SCHEMA)) {
// this map wil hold the all input connection for the tUnite component
Map<INode, Map<IMetadataTable, Boolean>> inputInfos = new HashMap<INode, Map<IMetadataTable, Boolean>>();
INode node;
if (elem instanceof Node) {
node = (INode) elem;
} else {
// else instanceof Connection
node = ((IConnection) elem).getSource();
}
IMetadataTable inputMetadata = null, inputMetaCopy = null;
Connection inputConec = null;
String propertyName = (String) inputButton.getData(PARAMETER_NAME);
IElementParameter param = node.getElementParameter(propertyName);
IElementParameter connectionParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
String connectionName = null;
if (connectionParam != null) {
connectionName = (String) connectionParam.getValue();
}
Object obj = button.getData(FORCE_READ_ONLY);
boolean forceReadOnly = false;
if (obj != null) {
forceReadOnly = (Boolean) obj;
}
boolean inputReadOnly = false, outputReadOnly = false, inputReadOnlyNode = false, inputReadOnlyParam = false;
for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE) || connec.getLineStyle().equals(EConnectionType.FLOW_MERGE) || connec.getLineStyle() == EConnectionType.FLOW_REF)) {
if (connectionName != null && !connec.getName().equals(connectionName)) {
continue;
}
inputMetadata = connec.getMetadataTable();
inputMetaCopy = inputMetadata.clone();
inputConec = connec;
if (connec.getSource().isReadOnly()) {
inputReadOnlyNode = true;
} else {
for (IElementParameter curParam : connec.getSource().getElementParameters()) {
if (curParam.getFieldType() == EParameterFieldType.SCHEMA_REFERENCE) {
if (curParam.isReadOnly()) {
inputReadOnlyParam = true;
}
}
}
}
// check if the inputMetadata is readonly
if (inputMetadata != null) {
for (IMetadataColumn column : inputMetadata.getListColumns(true)) {
IMetadataColumn columnCopied = inputMetaCopy.getColumn(column.getLabel());
columnCopied.setCustom(column.isCustom());
columnCopied.setReadOnly(column.isReadOnly());
}
inputMetaCopy.setReadOnly(inputMetadata.isReadOnly());
inputReadOnly = prepareReadOnlyTable(inputMetaCopy, inputReadOnlyParam, inputReadOnlyNode);
}
// store the value for Dialog
Map<IMetadataTable, Boolean> oneInput = new HashMap<IMetadataTable, Boolean>();
oneInput.put(inputMetaCopy, inputReadOnly);
inputInfos.put(connec.getSource(), oneInput);
}
}
if (connectionParam != null && inputMetadata == null) {
//$NON-NLS-1$
MessageDialog.openError(//$NON-NLS-1$
button.getShell(), //$NON-NLS-1$
Messages.getString("SchemaReferenceController.inputNotSet"), //$NON-NLS-1$
Messages.getString("SchemaReferenceController.connectionNotAvaliable"));
return null;
}
IMetadataTable originaleMetadataTable = getMetadataTableFromXml(node);
// check if the outputMetadata is readonly
IMetadataTable originaleOutputTable = node.getMetadataFromConnector(param.getContext());
// when several schema_type button ,need get the right one which is opening
//$NON-NLS-1$
IElementParameter schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
// need setRepository here
if (!param.getContext().equals(schemaParam.getContext())) {
//$NON-NLS-1$
schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
}
if (schemaParam != null && EmfComponent.REPOSITORY.equals(schemaParam.getValue())) {
if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
((MetadataTable) originaleOutputTable).setRepository(true);
}
} else if (schemaParam != null && EmfComponent.BUILTIN.equals(schemaParam.getValue())) {
if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
((MetadataTable) originaleOutputTable).setRepository(false);
}
}
IMetadataTable outputMetaCopy = originaleOutputTable.clone(true);
for (IMetadataColumn column : originaleOutputTable.getListColumns(true)) {
IMetadataColumn columnCopied = outputMetaCopy.getColumn(column.getLabel());
columnCopied.setCustom(column.isCustom());
columnCopied.setReadOnly(column.isReadOnly());
}
outputMetaCopy.setReadOnly(originaleOutputTable.isReadOnly() || param.isReadOnly(node.getElementParametersWithChildrens()));
//$NON-NLS-1$
IElementParameter schemaTypeParam = param.getChildParameters().get("SCHEMA_TYPE");
List<IElementParameterDefaultValue> defaultValues = schemaTypeParam.getDefaultValues();
for (IElementParameterDefaultValue elementParameterDefaultValue : defaultValues) {
if (elementParameterDefaultValue.getDefaultValue() instanceof MetadataTable) {
MetadataTable table = (MetadataTable) elementParameterDefaultValue.getDefaultValue();
outputMetaCopy.setReadOnlyColumnPosition(table.getReadOnlyColumnPosition());
break;
}
}
outputMetaCopy.sortCustomColumns();
if (!forceReadOnly) {
outputReadOnly = prepareReadOnlyTable(outputMetaCopy, param.isReadOnly(), node.isReadOnly());
} else {
outputReadOnly = true;
}
MetadataDialog metaDialog = null;
if (inputMetadata != null) {
if (inputInfos != null && inputInfos.size() > 1 && connectionName == null) {
MetadataDialogForMerge metaDialogForMerge = new MetadataDialogForMerge(composite.getShell(), inputInfos, outputMetaCopy, node, getCommandStack());
//$NON-NLS-1$
metaDialogForMerge.setText(Messages.getString("SchemaReferenceController.schemaOf") + node.getLabel());
metaDialogForMerge.setInputReadOnly(inputReadOnly);
metaDialogForMerge.setOutputReadOnly(outputReadOnly);
if (metaDialogForMerge.open() == MetadataDialogForMerge.OK) {
outputMetaCopy = metaDialogForMerge.getOutputMetaData();
// check if the metadata is modified
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
} else {
if (inputMetadata != null) {
// Notice: the Map inputInfos maybe is modified by the dialog.
Set<INode> inputNodes = inputInfos.keySet();
for (INode inputNode : inputNodes) {
Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
if (!inputMetaCopy.sameMetadataAs(inputNode.getMetadataList().get(0), IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
}
}
}
// create the changeMetadataCommand
if (modified) {
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
Command changeMetadataCommand = null;
// only output, no input
if (inputInfos.isEmpty()) {
changeMetadataCommand = new ChangeMetadataCommand(node, param, null, null, null, originaleOutputTable, outputMetaCopy);
} else {
Set<INode> inputNodes = inputInfos.keySet();
int count = 0;
for (INode inputNode : inputNodes) {
Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
if (count == 0) {
changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy);
} else {
changeMetadataCommand = changeMetadataCommand.chain(new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy));
}
count++;
}
}
return changeMetadataCommand;
}
}
} else {
INode inputNode = (inputConec.getSource());
if (inputMetaCopy.getAttachedConnector() == null) {
INodeConnector mainConnector;
if (inputNode.isELTComponent()) {
mainConnector = inputNode.getConnectorFromType(EConnectionType.TABLE);
} else {
mainConnector = inputNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
}
inputMetaCopy.setAttachedConnector(mainConnector.getName());
}
metaDialog = new MetadataDialog(composite.getShell(), inputMetaCopy, inputNode, outputMetaCopy, node, getCommandStack());
}
} else {
metaDialog = new MetadataDialog(composite.getShell(), outputMetaCopy, node, getCommandStack());
}
if (metaDialog != null) {
//$NON-NLS-1$
metaDialog.setText(Messages.getString("SchemaReferenceController.schema.title", node.getLabel()));
metaDialog.setInputReadOnly(inputReadOnly);
metaDialog.setOutputReadOnly(outputReadOnly);
if (metaDialog.open() == MetadataDialog.OK) {
inputMetaCopy = metaDialog.getInputMetaData();
outputMetaCopy = metaDialog.getOutputMetaData();
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
} else {
if (inputMetadata != null) {
if (!inputMetaCopy.sameMetadataAs(inputMetadata, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
}
}
if (modified) {
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
INode inputNode = null;
if (inputConec != null) {
inputNode = inputConec.getSource();
}
// update the component schema
if (param instanceof GenericElementParameter) {
GenericElementParameter genericElementParameter = (GenericElementParameter) param;
String paramName = genericElementParameter.getName();
ComponentProperties componentProperties = node.getComponentProperties();
if (componentProperties != null) {
org.talend.daikon.properties.property.Property schemaProperty = componentProperties.getValuedProperty(paramName);
if (schemaProperty != null) {
SchemaUtils.updateComponentSchema(node, outputMetaCopy, null);
}
}
}
if (node.getComponent().isSchemaAutoPropagated()) {
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
return changeMetadataCommand;
} else {
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
changeMetadataCommand.setPropagate(Boolean.FALSE);
return changeMetadataCommand;
}
}
}
}
} else if (inputButton.getData(NAME).equals(RETRIEVE_SCHEMA)) {
Node node = (Node) elem;
// String propertyName = (String) inputButton.getData(PARAMETER_NAME);
final Command cmd = RetrieveSchemaHelper.retrieveSchemasCommand(node);
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
return cmd;
} else if (inputButton.getData(NAME).equals(RESET_COLUMNS)) {
Node node = (Node) elem;
String propertyName = (String) inputButton.getData(PARAMETER_NAME);
IElementParameter param = node.getElementParameter(propertyName);
final Command cmd = SynchronizeSchemaHelper.createCommand(node, param);
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
return cmd;
} else if (button.getData(NAME).equals(REPOSITORY_CHOICE)) {
String paramName = (String) button.getData(PARAMETER_NAME);
IElementParameter schemaParam = elem.getElementParameter(paramName);
ERepositoryObjectType type = ERepositoryObjectType.METADATA_CON_TABLE;
String filter = schemaParam.getFilter();
RepositoryReviewDialog dialog = new RepositoryReviewDialog(button.getShell(), type, filter);
if (dialog.open() == RepositoryReviewDialog.OK) {
RepositoryNode node = dialog.getResult();
while (node.getObject().getProperty().getItem() == null || (!(node.getObject().getProperty().getItem() instanceof ConnectionItem))) {
node = node.getParent();
}
IRepositoryViewObject object = dialog.getResult().getObject();
Property property = object.getProperty();
String id = property.getId();
// The name is Table Name.
String name = object.getLabel();
if (name != null) {
if (elem instanceof Node) {
//$NON-NLS-1$
String value = id + " - " + name;
//$NON-NLS-1$
paramName = paramName + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
Command selectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(value));
executeCommand(selectorCommand);
}
}
//$NON-NLS-1$
String value = id + " - " + name;
//$NON-NLS-1$
String fullParamName = paramName + ":" + getRepositoryChoiceParamName();
org.talend.core.model.metadata.builder.connection.Connection connection = null;
if (elem instanceof Node) {
IMetadataTable repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(value);
connection = MetadataToolHelper.getConnectionFromRepository(value);
// For validation rule.
boolean isValRulesLost = false;
IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
if (currentValRuleObj != null) {
List<IRepositoryViewObject> valRuleObjs = ValidationRulesUtil.getRelatedValidationRuleObjs(value);
if (!ValidationRulesUtil.isCurrentValRuleObjInList(valRuleObjs, currentValRuleObj)) {
if (!MessageDialog.openConfirm(button.getShell(), //$NON-NLS-1$
Messages.getString("SchemaReferenceController.validationrule.title.confirm"), Messages.getString("SchemaReferenceController.validationrule.selectMetadataMsg"))) {
//$NON-NLS-1$
return null;
} else {
isValRulesLost = true;
}
}
}
if (repositoryMetadata == null) {
repositoryMetadata = new MetadataTable();
}
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
CompoundCommand cc = new CompoundCommand();
RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, null, null);
changeMetadataCommand.setConnection(connection);
cc.add(changeMetadataCommand);
if (isValRulesLost) {
ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
}
return cc;
}
}
} else if (button.getData(NAME).equals(COPY_CHILD_COLUMNS)) {
String paramName = (String) button.getData(PARAMETER_NAME);
IElementParameter param = elem.getElementParameter(paramName);
IElementParameter processParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
IElementParameter processIdParam = processParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
String id = (String) processIdParam.getValue();
Item item = ItemCacheManager.getProcessItem(id);
Node node = (Node) elem;
copySchemaFromChildJob(node, item);
// pop up the schema dialog
MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), node.getMetadataList().get(0), node, getCommandStack());
//$NON-NLS-1$
metaDialog.setText(Messages.getString("SchemaReferenceController.schemaOf") + node.getLabel());
if (metaDialog.open() == MetadataDialog.OK) {
IMetadataTable outputMetaData = metaDialog.getOutputMetaData();
return new ChangeMetadataCommand(node, param, null, outputMetaData);
}
}
return null;
}
use of org.talend.core.ui.metadata.dialog.MetadataDialog in project tdi-studio-se by Talend.
the class GuessSchemaController method runShadowProcess.
private void runShadowProcess(final Property property, final Node inputNode, final IContext selectContext, final IElementParameter switchParam) {
DatabaseConnection connt = TracesConnectionUtils.createConnection(connParameters);
String dbmsId = connt.getDbmsId();
if (dbmsId == null) {
Shell shell = Display.getCurrent().getActiveShell();
MessageDialog.openError(shell, "No info about DB found !", "Please choose the correct mapping file.\n Note: This is normal when using JDBC component");
MappingFileSelectDialog dialog = new MappingFileSelectDialog(shell);
dialog.open();
dbmsId = dialog.getSelectId();
}
GuessSchemaProcess gsp = new GuessSchemaProcess(property, inputNode, selectContext, memoSQL, info, part.getProcess());
try {
List<Integer> indexsForSameNamedColumn = new ArrayList<Integer>();
CsvArray array = gsp.run();
List<String[]> schemaContent = array.getRows();
List<String> columnLabels = new ArrayList<String>();
if (columns != null) {
columns.clear();
}
if (!schemaContent.isEmpty()) {
int numbOfColumn = schemaContent.get(0).length;
for (int i = 1; i <= numbOfColumn; i++) {
indexsForSameNamedColumn.clear();
Boolean b = false;
IMetadataColumn oneColum = new MetadataColumn();
// get the column name from the temp file genenrated by GuessSchemaProcess.java
String labelName = (schemaContent.get(0))[i - 1];
if (info != null && info.isHive()) {
if (labelName != null && labelName.indexOf(TalendTextUtils.JAVA_END_STRING) != -1) {
labelName = labelName.substring(labelName.lastIndexOf(TalendTextUtils.JAVA_END_STRING) + 1, labelName.length());
}
}
String name = labelName;
String sub = "";
String sub2 = "";
if (labelName != null && labelName.length() > 0 && labelName.startsWith("_")) {
//$NON-NLS-1$
sub = labelName.substring(1);
if (sub != null && sub.length() > 0) {
sub2 = sub.substring(1);
}
}
if (KeywordsValidator.isKeyword(labelName) || KeywordsValidator.isKeyword(sub) || KeywordsValidator.isKeyword(sub2)) {
labelName = "_" + labelName;
b = true;
}
// String label = labelName;
// findSameNamedColumnAndReplaceTheIndex(indexsForSameNamedColumn, i, oneColum, labelName);
oneColum.setLabel(MetadataToolHelper.validateColumnName(labelName, i, columnLabels));
// if (b && label != null && label.length() > 0 && label.startsWith("_")) { //$NON-NLS-1$
// String substring = label.substring(1);
// if (label.startsWith("_")
// && (KeywordsValidator.isKeyword(substring) || KeywordsValidator.isKeyword(sub) ||
// KeywordsValidator
// .isKeyword(sub2))) {
// label = substring;
// }
// }
oneColum.setOriginalDbColumnName(name);
if (schemaContent.size() > 5) {
oneColum.setPrecision(Integer.parseInt(schemaContent.get(2)[i - 1]));
oneColum.setLength(Integer.parseInt(schemaContent.get(3)[i - 1]));
}
try {
String talendType = null;
// to see if the language is java or perl
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (schemaContent.size() >= 5) {
talendType = MetadataTalendType.getMappingTypeRetriever(dbmsId).getDefaultSelectedTalendType(schemaContent.get(4)[i - 1]);
} else {
talendType = JavaTypesManager.STRING.getId();
}
} else {
if (schemaContent.size() >= 5) {
talendType = PerlDataTypeHelper.getNewTalendTypeOfValue(schemaContent.get(4)[i - 1]);
} else {
talendType = PerlTypesManager.STRING;
}
}
oneColum.setTalendType(talendType);
if (dbmsId != null) {
if (!TypesManager.checkDBType(dbmsId, oneColum.getTalendType(), oneColum.getType())) {
oneColum.setType(TypesManager.getDBTypeFromTalendType(dbmsId, oneColum.getTalendType()));
}
}
// oneColum.setTalendType(JavaTypesManager.STRING.getId());
} catch (Exception e) {
/*
* the table have no data at all ,to do nothing
*/
ExceptionHandler.process(e);
}
// get if a column is nullable from the temp file genenrated by GuessSchemaProcess.java
oneColum.setNullable((schemaContent.get(1))[i - 1].equals(Boolean.TRUE.toString()) ? true : false);
columns.add(oneColum);
columnLabels.add(oneColum.getLabel());
}
if (columns.size() > 0) {
IElementParameter dqRule = elem.getElementParameter("DQRULES_LIST");
if (dqRule != null) {
ITDQRuleService ruleService = null;
try {
ruleService = (ITDQRuleService) GlobalServiceRegister.getDefault().getService(ITDQRuleService.class);
} catch (RuntimeException e) {
// nothing to do
}
IElementParameter queryParam = elem.getElementParameter("QUERY");
if (ruleService != null && queryParam != null) {
ruleService.updateOriginalColumnNames(columns, queryParam);
}
}
}
IMetadataTable tempMetatable = new MetadataTable();
/* for bug 20973 */
if (tempMetatable.getTableName() == null) {
tempMetatable.setTableName(inputNode.getUniqueName());
}
IMetadataTable outputMetaCopy, originaleOutputTable;
String propertyName = "";
if (!btn.isDisposed()) {
propertyName = (String) btn.getData(PARAMETER_NAME);
}
IElementParameter param = inputNode.getElementParameter(propertyName);
for (IElementParameter eParam : elem.getElementParameters()) {
if (eParam.getContext() != null) {
param = eParam;
}
}
originaleOutputTable = inputNode.getMetadataFromConnector(param.getContext());
if (originaleOutputTable != null) {
outputMetaCopy = originaleOutputTable.clone();
}
tempMetatable.setListColumns(columns);
tempMetatable.setDbms(dbmsId);
MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), tempMetatable, inputNode, getCommandStack());
if (metaDialog != null) {
//$NON-NLS-1$
metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", inputNode.getLabel()));
}
// ok pressed
if (metaDialog.open() == MetadataDialog.OK) {
outputMetaCopy = metaDialog.getOutputMetaData();
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
if (modified) {
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
changeMetadataCommand = new ChangeMetadataCommand(inputNode, param, originaleOutputTable, outputMetaCopy);
changeMetadataCommand.execute();
}
}
}
} catch (ProcessorException e) {
ExtractMetaDataUtils.getInstance().closeConnection();
final String strExcepton = e.getMessage();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(composite.getShell(), Messages.getString("GuessSchemaController.connectionError"), //$NON-NLS-1$
strExcepton);
}
});
ExceptionHandler.process(e);
}
}
Aggregations