use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.
the class XmlmapBranchContent method createContent.
@Override
protected void createContent() {
super.createContent();
statusFigure = new Label();
statusFigure.setForegroundColor(ColorConstants.red);
statusFigure.setText(getStatus());
defaultValue = new Label();
defaultValue.setForegroundColor(ColorConstants.blue);
defaultValue.setText(getDefaultValue());
ImageInfo infor = ImageInfo.SETLOOPFUNCTION_BUTTON;
if (treeNode instanceof OutputTreeNode) {
InputLoopNodesTable inputLoopNodesTable = ((OutputTreeNode) treeNode).getInputLoopNodesTable();
infor = (inputLoopNodesTable == null || inputLoopNodesTable.getInputloopnodes().isEmpty()) ? ImageInfo.SETLOOPFUNCTION_BUTTON_ERROR : ImageInfo.SETLOOPFUNCTION_BUTTON;
}
loopButtonFigure = new ToolBarButtonImageFigure(ImageProviderMapper.getImage(infor));
loopButtonFigure.addMouseListener(new MouseListener.Stub() {
@Override
public void mousePressed(MouseEvent me) {
OutputTreeNode outputTreeNode = (OutputTreeNode) treeNode;
List<TreeNode> loopNodes = new ArrayList<TreeNode>();
if (manager.isMainTableMultiLoop()) {
loopNodes.addAll(XmlMapUtil.getMultiLoopsForXmlTree(manager.getMainInputTree()));
}
InputLoopNodesTable inputLoopNodesTable = null;
if (outputTreeNode.getInputLoopNodesTable() != null) {
inputLoopNodesTable = outputTreeNode.getInputLoopNodesTable();
} else {
inputLoopNodesTable = XmlmapFactory.eINSTANCE.createInputLoopNodesTable();
outputTreeNode.setInputLoopNodesTable(inputLoopNodesTable);
AbstractInOutTree abstractInOutTree = XmlMapUtil.getAbstractInOutTree(outputTreeNode);
if (abstractInOutTree != null) {
((OutputXmlTree) abstractInOutTree).getInputLoopNodesTables().add(inputLoopNodesTable);
}
}
SetLoopFunctionDialog nsDialog = new SetLoopFunctionDialog(null, outputTreeNode.getInputLoopNodesTable(), loopNodes);
if (nsDialog.open() == Window.OK) {
manager.getProblemsAnalyser().checkProblems(XmlMapUtil.getAbstractInOutTree(outputTreeNode));
manager.getMapperUI().updateStatusBar();
}
}
});
if (treeNode != null && treeNode instanceof OutputTreeNode) {
// display loop setup button only when input main is multiloop
if (treeNode.isLoop() && manager.isMainTableMultiLoop()) {
this.add(loopButtonFigure);
}
}
this.add(statusFigure);
this.add(defaultValue);
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.
the class SetLoopAction method run.
@Override
public void run() {
TreeNode model = (TreeNode) nodePart.getModel();
TreeNode docRoot = XmlMapUtil.getTreeNodeRoot(model);
AbstractInOutTree abstractTree = (AbstractInOutTree) docRoot.eContainer();
boolean isLookup = abstractTree != mapperManager.getMainInputTree() && !(abstractTree instanceof OutputXmlTree);
// remove old group
if (model instanceof OutputTreeNode) {
OutputTreeNode outputNode = (OutputTreeNode) model;
if (docRoot != null) {
XmlMapUtil.cleanSubGroup(outputNode);
List<TreeNode> newLoopUpGroups = new ArrayList<TreeNode>();
findUpGroupNode(newLoopUpGroups, outputNode);
// clean all groups except the ancestor of new loop
XmlMapUtil.cleanSubGroup(docRoot, newLoopUpGroups);
// reset the group in case some element ancestor of loop element are not group but under the group
if (!newLoopUpGroups.isEmpty()) {
TreeNode rootGroup = newLoopUpGroups.get(newLoopUpGroups.size() - 1);
upsetGroup(outputNode, rootGroup);
}
}
}
if (!isLookup) {
// TDI-20147
List<TreeNode> loopNodes = new ArrayList<TreeNode>();
checkSubElementIsLoop(model, loopNodes);
checkParentElementIsLoop(model, loopNodes);
if (!loopNodes.isEmpty()) {
if (MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.getString("SetLoopAction.cleanSubLoopTitle"), Messages.getString("SetLoopAction.cleanSubLoopMessages"))) {
} else {
return;
}
}
for (TreeNode treeNode : loopNodes) {
treeNode.setLoop(false);
}
model.setLoop(true);
XmlMapUtil.clearMainNode(model);
XmlMapUtil.upsetMainNode(model);
abstractTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(abstractTree));
if (input) {
// check if child is mapped to output remove the old loop in output node
XmlMapUtil.removeloopInOutputTree(mapperManager, loopNodes);
// disable the function to add sourceloop into InputLoopNodesTable automatically
// add input loopNodes to InputLoopNodesTable
// addInputLoopNodesToOutput(model, model);
} else {
// clean the InputLoopNodesTable for the old loops
InputXmlTree mainInput = mapperManager.getMainInputTree();
XmlMapUtil.removeLoopTableForOutput((OutputXmlTree) abstractTree, loopNodes, mainInput == null ? false : mainInput.isMultiLoops());
}
} else {
if (docRoot != null) {
cleanSubLoop(docRoot);
}
model.setLoop(true);
XmlMapUtil.clearMainNode(docRoot);
XmlMapUtil.upsetMainNode(model);
}
if (abstractTree != null) {
mapperManager.getProblemsAnalyser().checkProblems(abstractTree);
mapperManager.getMapperUI().updateStatusBar();
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.
the class SetAggregateAction method calculateEnabled.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
*/
@Override
protected boolean calculateEnabled() {
if (getSelectedObjects().isEmpty()) {
return false;
}
Object s = getSelectedObjects().get(0);
if (s instanceof List && !((List) s).isEmpty()) {
List selectedarts = (List) s;
Object obj = selectedarts.get(selectedarts.size() - 1);
if (obj instanceof OutputTreeNodeEditPart) {
nodePart = (OutputTreeNodeEditPart) obj;
OutputTreeNode model = (OutputTreeNode) nodePart.getModel();
// root can't be aggregate
if (NodeType.NAME_SPACE.equals(model.getNodeType()) || !(model.eContainer() instanceof OutputTreeNode) || model.isChoice() || model.isSubstitution()) {
return false;
}
if (!XmlMapUtil.isExpressionEditable(model)) {
return false;
}
boolean isInputMultiLoops = false;
if (mapperManager.getMainInputTree() != null && mapperManager.getMainInputTree().isMultiLoops()) {
isInputMultiLoops = true;
}
AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(model);
if (abstractTree instanceof OutputXmlTree) {
OutputXmlTree outputTree = ((OutputXmlTree) abstractTree);
if (outputTree.isAllInOne()) {
return false;
}
// fixed for TDI-20808 ,disable group and aggregate for 501
if (isInputMultiLoops && outputTree.isMultiLoops()) {
return false;
}
}
if (!model.isAggregate()) {
setText("As aggregate element");
} else {
setText("Remove aggregate element");
}
} else {
return false;
}
}
return true;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.
the class SetGroupAction method calculateEnabled.
@Override
protected boolean calculateEnabled() {
subGroupTraceNames.clear();
if (getSelectedObjects().isEmpty()) {
return false;
}
Object s = getSelectedObjects().get(0);
if (s instanceof List && !((List) s).isEmpty()) {
List selectedarts = (List) s;
Object obj = selectedarts.get(selectedarts.size() - 1);
if (obj instanceof OutputTreeNodeEditPart) {
nodePart = (OutputTreeNodeEditPart) obj;
OutputTreeNode model = (OutputTreeNode) nodePart.getModel();
if (model.eContainer() instanceof TreeNode && XmlMapUtil.DOCUMENT.equals(((TreeNode) model.eContainer()).getType())) {
return false;
}
if (NodeType.ATTRIBUT.equals(model.getNodeType()) || NodeType.NAME_SPACE.equals(model.getNodeType()) || !(model.eContainer() instanceof TreeNode) || model.isChoice() || model.isSubstitution()) {
//$NON-NLS-N$
return false;
}
// fixed for TDI-20808 ,disable group and aggregate for 501
AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(model);
if (abstractTree instanceof OutputXmlTree) {
OutputXmlTree outputTree = ((OutputXmlTree) abstractTree);
if (outputTree.isMultiLoops()) {
return false;
}
}
OutputTreeNode findDownLoopNode = findDownLoopNode(model);
if (findDownLoopNode == null) {
return false;
}
if (!model.isGroup()) {
setText("As group element");
isRemove = false;
} else {
setText("Remove group element");
isRemove = true;
}
if (isRemove) {
if (model.isGroup()) {
return true;
} else {
return false;
}
}
} else {
return false;
}
}
return true;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.
the class ImportTreeFromRepository method run.
@Override
public void run() {
targetAbsolutePath = null;
loopNode = null;
xpathAndOrder.clear();
RepositoryXmlSelectionDialog reviewDialog = new RepositoryXmlSelectionDialog(shell, new String[] { "XML", "MDM" });
if (reviewDialog.open() == Window.OK) {
TreeNode treeNodeRoot = XmlMapUtil.getTreeNodeRoot(schemaNode);
XmlMapUtil.detachNodeConnections(treeNodeRoot, mapperManager.getExternalData(), true);
RepositoryNode repositoryNode = reviewDialog.getResult();
Item item = repositoryNode.getObject().getProperty().getItem();
String detailedMessage = "";
try {
if (item instanceof XmlFileConnectionItem) {
XmlFileConnectionItem xmlitem = (XmlFileConnectionItem) item;
XmlFileConnection connection = (XmlFileConnection) xmlitem.getConnection();
prepareEmfTreeFromXml(connection);
} else if (item instanceof MDMConnectionItem) {
String selectedSchema = (String) repositoryNode.getProperties(EProperties.LABEL);
MDMConnection connection = (MDMConnection) ((MDMConnectionItem) item).getConnection();
prepareEmfTreeFromMdm(connection, selectedSchema);
}
} catch (Exception e) {
ExceptionHandler.process(e);
StringBuffer sb = new StringBuffer();
sb.append(e.toString());
sb.append("\n");
if (e.getStackTrace() != null) {
for (StackTraceElement trace : e.getStackTrace()) {
sb.append(trace.toString());
sb.append("\n");
}
}
detailedMessage = sb.toString();
}
boolean childrenEmpty = false;
if (schemaNode.getChildren().isEmpty()) {
childrenEmpty = true;
TreeNode rootNode = createModel();
rootNode.setName("root");
rootNode.setNodeType(NodeType.ELEMENT);
rootNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
rootNode.setXpath(XmlMapUtil.getXPath(schemaNode.getXpath(), "root", NodeType.ELEMENT));
schemaNode.getChildren().add(rootNode);
if (loopNode == null) {
schemaNode.getChildren().get(0).setLoop(true);
schemaNode.getChildren().get(0).setMain(true);
}
}
if (childrenEmpty || (detailedMessage != null && !"".equals(detailedMessage))) {
showError(detailedMessage);
}
AbstractInOutTree tree = null;
if (schemaNode.eContainer() instanceof InputXmlTree) {
XmlMapConnectionBuilder connectionBuilder = new XmlMapConnectionBuilder();
connectionBuilder.setCheckRootNodePrefix(true);
connectionBuilder.rebuildLinks(schemaNode, mapperManager.getExternalData());
mapperManager.refreshTreeSchemaEditor((InputXmlTree) schemaNode.eContainer());
// mapperManager.inputTreeSchemaBeanListModified();
tree = (InputXmlTree) schemaNode.eContainer();
} else if (schemaNode.eContainer() instanceof OutputXmlTree) {
// mapperManager.outputTreeSchemaBeanListModified();
mapperManager.refreshTreeSchemaEditor((OutputXmlTree) schemaNode.eContainer());
tree = (OutputXmlTree) schemaNode.eContainer();
}
if (tree != null) {
mapperManager.getProblemsAnalyser().checkProblems(tree);
mapperManager.getMapperUI().updateStatusBar();
}
}
}
Aggregations