use of org.talend.core.model.process.IConnection 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.process.IConnection in project tdi-studio-se by Talend.
the class ComponentListController method updateComponentList.
protected static void updateComponentList(Collection<INode> nodeList, INode currentNode, IElementParameter param, boolean isSelectDefaultItem) {
final Collection<String> componentDisplayNames = new ArrayList<String>();
final Collection<String> componentUniqueNames = new ArrayList<String>();
for (INode node : nodeList) {
if (node.getJobletNode() != null) {
node = node.getJobletNode();
}
final String uniqueName = node.getUniqueName();
if (uniqueName.equals(currentNode.getUniqueName())) {
continue;
}
//$NON-NLS-1$
String displayName = (String) node.getElementParameter("LABEL").getValue();
if (displayName == null) {
displayName = uniqueName;
}
if (displayName.indexOf("__UNIQUE_NAME__") != -1) {
//$NON-NLS-1$
//$NON-NLS-1$
displayName = displayName.replaceAll("__UNIQUE_NAME__", uniqueName);
}
if (!displayName.equals(uniqueName)) {
//$NON-NLS-1$
displayName = uniqueName + " - " + displayName;
}
componentUniqueNames.add(uniqueName);
componentDisplayNames.add(displayName);
}
param.setListItemsDisplayName(componentDisplayNames.toArray(new String[0]));
final String[] componentValueList = componentUniqueNames.toArray(new String[0]);
param.setListItemsValue(componentValueList);
Object value = param.getValue();
if (!componentUniqueNames.contains(value) && isSelectDefaultItem) {
String newValue = null;
if (!param.isDynamicSettings()) {
if (!componentUniqueNames.isEmpty()) {
if (value == null || value.equals("")) {
//$NON-NLS-1$
currentNode.setPropertyValue(getParameterName(param), componentValueList[0]);
if (currentNode instanceof IGraphicalNode) {
IGraphicalNode node = (IGraphicalNode) currentNode;
node.checkAndRefreshNode();
((IProcess2) node.getProcess()).setProcessModified(true);
} else if (currentNode instanceof IConnection) {
((IProcess2) ((IConnection) currentNode).getSource().getProcess()).setProcessModified(true);
}
} else {
newValue = componentValueList[0];
}
} else {
// removed the old value.
//$NON-NLS-1$
newValue = "";
}
}
if (!("".equals(newValue)) && newValue != null) {
//$NON-NLS-1$
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (part instanceof AbstractMultiPageTalendEditor) {
AbstractTalendEditor te = ((AbstractMultiPageTalendEditor) part).getTalendEditor();
CommandStack cmdStack = (CommandStack) te.getAdapter(CommandStack.class);
cmdStack.execute(new PropertyChangeCommand(currentNode, getParameterName(param), ""));
}
}
}
}
use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.
the class ColumnListController method updateColumnList.
// only set synWidthWithMhaoetadataColumn =true, when use the metadataDialog to set the metadata.
// see issue 0001676
public static void updateColumnList(INode node, List<ColumnNameChanged> columnsChanged, boolean synWidthWithMetadataColumn) {
Map<String, Boolean> customColMap = new HashMap<String, Boolean>();
List<String> columnList = null;
List<String> prevColumnList = getPrevColumnList(node, customColMap);
Map<IConnection, List<String>> refColumnLists = getRefColumnLists(node, customColMap);
String[] columnNameList = null;
String[] prevColumnNameList = prevColumnList.toArray(new String[0]);
String[] curColumnNameList = null;
String[] curColumnValueList = null;
List<String> refColumnListNamesTmp = new ArrayList<String>();
List<String> refColumnListNamesTmpWithSourceName = new ArrayList<String>();
List<String> refColumnListValuesTmp = new ArrayList<String>();
for (IConnection connection : refColumnLists.keySet()) {
String oldSourceName = connection.getSource().getUniqueName() + ".";
//$NON-NLS-1$
String name = connection.getName() + ".";
for (String column : refColumnLists.get(connection)) {
refColumnListNamesTmpWithSourceName.add(oldSourceName + column);
refColumnListNamesTmp.add(name + column);
refColumnListValuesTmp.add(column);
}
}
String[] refColumnListNames = refColumnListNamesTmp.toArray(new String[0]);
String[] refColumnListValues = refColumnListValuesTmp.toArray(new String[0]);
//$NON-NLS-1$
boolean isSCDComponent = node.getComponent().getName().endsWith("SCD");
boolean isEdifactComponent = node.getComponent().getName().equals("tExtractEDIField");
updateColumnsOnElement(node, columnsChanged, synWidthWithMetadataColumn, prevColumnNameList, curColumnNameList, curColumnValueList, refColumnListNamesTmpWithSourceName, refColumnListValuesTmp, refColumnListNames, refColumnListValues, isSCDComponent, isEdifactComponent, customColMap);
for (IConnection connection : node.getOutgoingConnections()) {
updateColumnsOnElement(connection, columnsChanged, synWidthWithMetadataColumn, prevColumnNameList, curColumnNameList, curColumnValueList, refColumnListNamesTmpWithSourceName, refColumnListValuesTmp, refColumnListNames, refColumnListValues, isSCDComponent, isEdifactComponent, customColMap);
}
synLengthTipFlag = null;
}
use of org.talend.core.model.process.IConnection 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.process.IConnection in project tdi-studio-se by Talend.
the class ConnectionListController method updateConnectionList.
public static void updateConnectionList(IElement elem, IElementParameter param) {
IConnection[] connections;
INode source = null;
if (elem instanceof INode) {
source = ((INode) elem);
} else if (elem instanceof IConnection) {
source = ((IConnection) elem).getSource();
} else {
return;
}
String filter = param.getFilter();
if (filter.startsWith("INPUT:")) {
//$NON-NLS-1$
Set<IConnection> conns = new HashSet<IConnection>();
conns.addAll(source.getIncomingConnections());
//$NON-NLS-1$ //$NON-NLS-2$
String[] f = filter.substring("INPUT:".length()).split("\\|");
List<String> filterArray = new ArrayList<String>(f.length);
for (String element : f) {
filterArray.add(element.trim());
}
for (Iterator<IConnection> iter = conns.iterator(); iter.hasNext(); ) {
IConnection con = iter.next();
if (!filterArray.contains(con.getLineStyle().toString())) {
iter.remove();
}
}
connections = conns.toArray(new IConnection[conns.size()]);
} else if (filter.startsWith("OUTPUT:")) {
//$NON-NLS-1$
Set<IConnection> conns = new HashSet<IConnection>();
conns.addAll(source.getOutgoingConnections());
//$NON-NLS-1$ //$NON-NLS-2$
String[] f = filter.substring("OUTPUT:".length()).split("\\|");
List<String> filterArray = new ArrayList<String>(f.length);
for (String element : f) {
filterArray.add(element.trim());
}
for (Iterator<IConnection> iter = conns.iterator(); iter.hasNext(); ) {
IConnection con = iter.next();
if (!filterArray.contains(con.getLineStyle().toString())) {
iter.remove();
}
}
connections = conns.toArray(new IConnection[conns.size()]);
} else {
connections = source.getProcess().getAllConnections(filter);
}
String[] connectionNames = new String[connections.length + 1];
connectionNames[0] = "";
for (int i = 0; i < connections.length; i++) {
connectionNames[i + 1] = connections[i].getUniqueName();
}
Arrays.sort(connectionNames);
String[] connectionNameList = (String[]) ArrayUtils.clone(connectionNames);
String[] connectionValueList = connectionNames;
connectionNameList[0] = "<Empty>";
param.setListItemsDisplayName(connectionNameList);
param.setListItemsValue(connectionValueList);
if (!ArrayUtils.contains(connectionValueList, param.getValue())) {
//$NON-NLS-1$
param.setValue("");
}
}
Aggregations