use of org.eclipse.gef.commands.CompoundCommand 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.eclipse.gef.commands.CompoundCommand in project tdi-studio-se by Talend.
the class TalendConnectionCreationTool method getReturnValues.
public Collection getReturnValues(Command c) {
if (c instanceof CompoundCommand) {
CompoundCommand cc = (CompoundCommand) c;
List l = new ArrayList(cc.size());
for (Iterator i = cc.getCommands().iterator(); i.hasNext(); ) {
l.addAll(getReturnValues((Command) i.next()));
}
return l;
}
return Collections.EMPTY_LIST;
}
use of org.eclipse.gef.commands.CompoundCommand 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.eclipse.gef.commands.CompoundCommand in project tdi-studio-se by Talend.
the class PropertyTypeController method createButtonCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createControl(org.eclipse
* .swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
* org.eclipse.swt.widgets.Control)
*/
@Override
protected Command createButtonCommand(Button button) {
// hwang add for feature 6484
FileItem repositoryFileItem = null;
LinkRulesItem linkItem = null;
Map<String, FileItem> repositoryFileItemMap = null;
Map<String, LinkRulesItem> repositoryLinkRulesItemMap = null;
String paramName = (String) button.getData(PARAMETER_NAME);
IElementParameter param = elem.getElementParameter(paramName);
Object data = button.getData(NAME);
if (data != null && data.equals(REPOSITORY_CHOICE)) {
IElementParameter dbTypeParam = null;
if (elem instanceof org.talend.designer.core.ui.editor.process.Process || elem instanceof StatsAndLogsElement || elem instanceof ImplicitContextLoadElement) {
if (EParameterName.PROPERTY_TYPE.getName().equals(paramName)) {
dbTypeParam = elem.getElementParameter(EParameterName.DB_TYPE.getName());
} else if (JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTY_TYPE.getName()).equals(paramName)) {
dbTypeParam = elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_TYPE.getName()));
}
}
Item item = null;
String id = null;
RepositoryNode selectNode = null;
if (id == null) {
RepositoryReviewDialog dialog = null;
if (dbTypeParam != null) {
String[] listRepositoryItems = dbTypeParam.getListRepositoryItems();
dialog = new RepositoryReviewDialog(Display.getCurrent().getActiveShell(), ERepositoryObjectType.METADATA, param.getRepositoryValue(), listRepositoryItems);
} else {
// Added TDQ-11688
ITDQPatternService service = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQPatternService.class)) {
service = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
}
if (service != null && service.isSinglePatternNode(elem)) {
return processPattern(elem);
}
// ~
dialog = new RepositoryReviewDialog(Display.getCurrent().getActiveShell(), ERepositoryObjectType.METADATA, elem, param);
}
if (dialog.open() == RepositoryReviewDialog.OK) {
selectNode = dialog.getResult();
id = selectNode.getObject().getId();
}
}
if (id != null && !"".equals(id)) {
//$NON-NLS-1$
IElementParameter repositoryParam = param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
//$NON-NLS-1$
String fullParamName = paramName + ":" + getRepositoryChoiceParamName();
Connection repositoryConnection = null;
// Map<String, ConnectionItem> repositoryConnectionItemMap =
// dynamicProperty.getRepositoryConnectionItemMap();
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
try {
IRepositoryViewObject repobj = factory.getLastVersion(id);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null) {
if (item instanceof ConnectionItem) {
repositoryConnection = ((ConnectionItem) item).getConnection();
}
} else {
repositoryConnection = null;
if (repositoryParam != null) {
item = selectNode.getObject().getProperty().getItem();
if (item instanceof ConnectionItem) {
repositoryConnection = ((ConnectionItem) item).getConnection();
}
}
}
if (repositoryConnection != null) {
CompoundCommand compoundCommand = new CompoundCommand();
ChangeValuesFromRepository changeValuesFromRepository = null;
if (selectNode.getObjectType() == ERepositoryObjectType.SERVICESOPERATION && GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
IESBService service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
IProcess2 process = (IProcess2) RepositoryPlugin.getDefault().getDesignerCoreService().getCurrentProcess();
String currentJobId = process.getProperty().getId();
String serviceId = item.getProperty().getId();
String portId = selectNode.getParent().getObject().getId();
String operationId = selectNode.getObject().getId();
changeValuesFromRepository = new ChangeValuesFromRepository(elem, repositoryConnection, param.getName() + ":" + //$NON-NLS-1$
EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$ //$NON-NLS-2$
serviceId + " - " + portId + " - " + operationId);
service.deleteOldRelation(currentJobId);
//$NON-NLS-1$ //$NON-NLS-2$
service.updateOperation((INode) elem, serviceId + " - " + portId + " - " + operationId, selectNode);
} else {
changeValuesFromRepository = new ChangeValuesFromRepository(elem, repositoryConnection, fullParamName, id);
}
if (changeValuesFromRepository != null) {
compoundCommand.add(changeValuesFromRepository);
}
updateDBType(compoundCommand, repositoryConnection);
return compoundCommand;
}
// for ruleItem,hywang add
if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
repositoryFileItemMap = ((MultipleThreadDynamicComposite) dynamicProperty).getRepositoryFileItemMap();
repositoryLinkRulesItemMap = ((MultipleThreadDynamicComposite) dynamicProperty).getRepositoryLinkRulesItemMap();
}
if (repositoryFileItemMap.containsKey(id)) {
repositoryFileItem = repositoryFileItemMap.get(id);
} else if (repositoryLinkRulesItemMap.containsKey(id)) {
linkItem = repositoryLinkRulesItemMap.get(id);
} else {
if (!repositoryFileItemMap.isEmpty()) {
repositoryFileItem = repositoryFileItemMap.values().iterator().next();
} else {
repositoryFileItem = null;
}
}
if (repositoryFileItem == null && item instanceof FileItem) {
repositoryFileItem = (FileItem) item;
}
if (repositoryFileItem != null) {
CompoundCommand compoundCommand = new CompoundCommand();
final String showId = repositoryFileItem.getProperty().getId();
Command command = new PropertyChangeCommand(elem, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
compoundCommand.add(command);
return compoundCommand;
}
if (linkItem != null) {
CompoundCommand compoundCommand = new CompoundCommand();
final String showId = linkItem.getProperty().getId();
Command command = new PropertyChangeCommand(elem, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
compoundCommand.add(command);
return compoundCommand;
}
}
} else {
// 1. open wizard
if (elem instanceof INode) {
INode node = (INode) elem;
final IRepositoryService repositoryService = CorePlugin.getDefault().getRepositoryService();
if (param != null) {
RepositoryNode realNode = null;
String repositoryValue = param.getRepositoryValue();
if (repositoryValue != null && repositoryValue.startsWith(ERepositoryCategoryType.DATABASE.getName())) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_CONNECTIONS);
} else // file delimited
if (ERepositoryCategoryType.DELIMITED.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_DELIMITED);
}
// file positional
if (ERepositoryCategoryType.POSITIONAL.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_POSITIONAL);
}
// file regexp
if (ERepositoryCategoryType.REGEX.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_REGEXP);
}
// file xml
if (ERepositoryCategoryType.XML.getName().equals(repositoryValue) || // bug 18012
repositoryValue.startsWith(ERepositoryCategoryType.XML.getName())) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_XML);
}
// file ldif
if (ERepositoryCategoryType.LDIF.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_LDIF);
}
// excel
if (ERepositoryCategoryType.EXCEL.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_EXCEL);
}
// generic schema
if (ERepositoryCategoryType.GENERIC.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_GENERIC_SCHEMA);
}
// ldap
if (ERepositoryCategoryType.LDAP.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_LDAP_SCHEMA);
}
// wsdl
if (ERepositoryCategoryType.WSDL.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_WSDL_SCHEMA);
}
if (ERepositoryCategoryType.WEBSERVICE.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_WSDL_SCHEMA);
}
// salesforce
if (ERepositoryCategoryType.SALESFORCE.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA);
}
// ebcdic
if (ERepositoryCategoryType.EBCDIC.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_EBCDIC);
}
// mdm
if (ERepositoryCategoryType.MDM.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_MDMCONNECTION);
}
// sap
if (ERepositoryCategoryType.SAP.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SAPCONNECTIONS);
}
// sapIDoc
if (ERepositoryCategoryType.SAPIDOC.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SAP_IDOC);
}
if (ERepositoryCategoryType.HEADERFOOTER.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_HEADER_FOOTER);
}
// brms
if (ERepositoryCategoryType.BRMS.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_BRMS);
}
// hl7
if (ERepositoryCategoryType.HL7.getName().equals(repositoryValue)) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_HL7);
}
// last resort we assume that the repository value was named after the root component type key
if (realNode == null) {
realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.getTypeFromKey(repositoryValue));
}
if (realNode != null) {
final IMetadataService metadataService = CorePlugin.getDefault().getMetadataService();
if (metadataService != null) {
ConnectionItem connItem = metadataService.openMetadataConnection(true, realNode, node);
if (connItem != null) {
IElementParameter propertyParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
// 2. commnd
Command cmd = new ChangeValuesFromRepository(node, connItem.getConnection(), //$NON-NLS-1$
propertyParam.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), connItem.getProperty().getId());
executeCommand(cmd);
// see bug in feature 5998.refresh repositoryList.
if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
((MultipleThreadDynamicComposite) dynamicProperty).updateRepositoryList();
}
}
}
}
}
}
}
return null;
}
use of org.eclipse.gef.commands.CompoundCommand in project tdi-studio-se by Talend.
the class SapSchemaTypeController method createComboCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
* .eclipse.swt.custom.CCombo)
*/
@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("SchemaTypeController.validationrule.title.confirm"), Messages.getString("SchemaTypeController.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();
/* 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;
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
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();
}
/* see bug 16969 */
// if (repositoryTableMap.containsKey(schemaSelected)) {
// repositoryMetadata = repositoryTableMap.get(schemaSelected);
// // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
// newRepositoryIdValue = schemaSelected;// + " - " + repositoryMetadata.getLabel();
// } else {
// if (repositoryTableMap.keySet().size() == 0) {
// repositoryMetadata = new MetadataTable();
// } else {
// newRepositoryIdValue = repositoryTableMap.keySet().iterator().next();
// // Gets the schema of the first item in repository schema type combo.
// repositoryMetadata = repositoryTableMap.get(newRepositoryIdValue);
// // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
// // newRepositoryIdValue = newRepositoryIdValue + " - " + repositoryMetadata.getLabel();
// }
// }
} 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;
}
Aggregations