use of org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry in project tdi-studio-se by Talend.
the class LinkManager method registerLevelForNewLink.
/**
* DOC amaumont Comment method "registerLevelForNewLink".
*
* @param link
* @param graphicalLinksFromTarget
*/
protected void registerLevelForNewLink(IMapperLink link, Set<IMapperLink> graphicalLinksFromTarget) {
boolean hasAlreadyInputTarget = false;
boolean hasAlreadyVarTarget = false;
ITableEntry sourceEntry = link.getPointLinkDescriptor1().getTableEntry();
ITableEntry targetEntry = link.getPointLinkDescriptor2().getTableEntry();
boolean hasSameZone = sourceEntry.getClass() == targetEntry.getClass();
boolean isInput = targetEntry instanceof InputColumnTableEntry;
boolean isOutput = targetEntry instanceof OutputColumnTableEntry;
if (hasSameZone) {
List<List<IMapperLink>> leveledLinks = null;
if (isInput) {
leveledLinks = getInputLinksForLevels();
}
if (isOutput) {
leveledLinks = getOutputLinksForLevels();
}
int lstSize = leveledLinks.size();
for (int indexOfLeveledLink = 0; indexOfLeveledLink < lstSize; indexOfLeveledLink++) {
List<IMapperLink> linksFromLevelsList = leveledLinks.get(indexOfLeveledLink);
if (linksFromLevelsList != null && linksFromLevelsList.size() > 0) {
IMapperLink linkFromLevelsList = linksFromLevelsList.get(0);
ITableEntry sourceTableEntry = linkFromLevelsList.getPointLinkDescriptor1().getTableEntry();
ITableEntry targetTableEntry = linkFromLevelsList.getPointLinkDescriptor2().getTableEntry();
if (targetEntry == targetTableEntry) {
if (sourceTableEntry instanceof InputColumnTableEntry && targetTableEntry instanceof InputColumnTableEntry) {
hasAlreadyInputTarget = true;
}
if (sourceTableEntry instanceof VarTableEntry && targetTableEntry instanceof VarTableEntry) {
hasAlreadyVarTarget = true;
}
if (hasAlreadyInputTarget || hasAlreadyVarTarget) {
linksFromLevelsList.add(link);
link.setLevel(indexOfLeveledLink + 1);
break;
}
}
}
}
if (isInput && !hasAlreadyInputTarget) {
ArrayList<IMapperLink> list = new ArrayList<IMapperLink>();
int firstEmptyIndex = searchFirstEmptyIndexLeveledList(leveledLinks);
link.setLevel(firstEmptyIndex + 1);
list.add(link);
if (firstEmptyIndex < leveledLinks.size()) {
leveledLinks.set(firstEmptyIndex, list);
} else {
leveledLinks.add(list);
}
}
}
}
Aggregations