use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class TreeSettingDirectEditCommand method calculateFilterConnections.
private void calculateFilterConnections(AbstractInOutTree abstractTree, String newValue) {
XmlMapData mapperData = (XmlMapData) abstractTree.eContainer();
List<TableEntryLocation> matchedLocations = expressionManager.parseTableEntryLocation((String) newValue);
EList<FilterConnection> connections = abstractTree.getFilterIncomingConnections();
List usefullConnections = new ArrayList();
if (!matchedLocations.isEmpty()) {
for (int i = 0; i < matchedLocations.size(); i++) {
TableEntryLocation currentLocation = matchedLocations.get(i);
boolean found = false;
for (FilterConnection conn : connections) {
TableEntryLocation sourceLocation = null;
if (conn.getSource() instanceof TreeNode) {
sourceLocation = expressionManager.parseTableEntryLocation(XmlMapUtil.convertToExpression(((TreeNode) conn.getSource()).getXpath())).get(0);
} else if (conn.getSource() instanceof VarNode) {
VarNode varNode = (VarNode) conn.getSource();
sourceLocation = new TableEntryLocation(((VarTable) varNode.eContainer()).getName(), varNode.getName());
}
if (currentLocation.equals(sourceLocation)) {
found = true;
usefullConnections.add(conn);
break;
}
}
if (!found) {
if (mapperData != null) {
String convertToXpath = XmlMapUtil.convertToXpath(currentLocation.toString());
boolean findFromVar = false;
if (abstractTree instanceof OutputXmlTree) {
findFromVar = true;
}
AbstractNode sourceNode = findConnectionSource(mapperData, currentLocation, XmlMapUtil.getXPathLength(convertToXpath), findFromVar);
if (sourceNode != null) {
FilterConnection connection = null;
connection = XmlmapFactory.eINSTANCE.createFilterConnection();
sourceNode.getFilterOutGoingConnections().add(connection);
abstractTree.getFilterIncomingConnections().add(connection);
connection.setSource(sourceNode);
connection.setTarget(abstractTree);
mapperData.getConnections().add(connection);
usefullConnections.add(connection);
}
}
}
}
List<FilterConnection> copyOfConnections = new ArrayList<FilterConnection>(connections);
copyOfConnections.removeAll(usefullConnections);
for (FilterConnection connection : copyOfConnections) {
if (connection.getSource() != null) {
if (connection.getSource().getFilterOutGoingConnections().contains(connection)) {
connection.getSource().getFilterOutGoingConnections().remove(connection);
mapperData.getConnections().remove(connection);
}
}
}
abstractTree.getFilterIncomingConnections().removeAll(copyOfConnections);
} else if (!connections.isEmpty()) {
for (FilterConnection connection : connections) {
if (connection.getSource() != null) {
if (connection.getSource().getFilterOutGoingConnections().contains(connection)) {
connection.getSource().getFilterOutGoingConnections().remove(connection);
mapperData.getConnections().remove(connection);
}
}
}
abstractTree.getFilterIncomingConnections().removeAll(connections);
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class DeleteTreeNodeAction method calculateEnabled.
@Override
protected boolean calculateEnabled() {
// nodesNeedToChangeMainStatus.clear();
if (getSelectedObjects().isEmpty()) {
return false;
} else {
boolean enable = true;
Object s = getSelectedObjects().get(0);
if (s instanceof List && !((List) s).isEmpty()) {
List selectedarts = (List) s;
Object lastSelection = selectedarts.get(selectedarts.size() - 1);
if (!(lastSelection instanceof TreeNodeEditPart)) {
return false;
}
for (Object obj : selectedarts) {
if (obj instanceof TreeNodeEditPart) {
TreeNodeEditPart nodePart = (TreeNodeEditPart) obj;
TreeNode treeNode = (TreeNode) nodePart.getModel();
int xPathLength = XmlMapUtil.getXPathLength(treeNode.getXpath());
if (xPathLength <= 2) {
enable = false;
}
// can't delete root
if (treeNode.eContainer() instanceof TreeNode && XmlMapUtil.DOCUMENT.equals(((TreeNode) treeNode.eContainer()).getType())) {
enable = false;
}
}
if (!enable) {
return enable;
}
}
}
return enable;
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class DropContextAnalyzer method checkDropInputValid.
private boolean checkDropInputValid(Object target) {
if (objects.getType() == TransferdType.INPUT) {
for (Object obj : objects.getToTransfer()) {
TreeNodeEditPart part = (TreeNodeEditPart) obj;
AbstractInOutTree srouceTree = XmlMapUtil.getAbstractInOutTree((TreeNode) part.getModel());
AbstractInOutTree targetTree = null;
if (target instanceof InputXmlTree) {
targetTree = (InputXmlTree) target;
} else {
targetTree = XmlMapUtil.getAbstractInOutTree((TreeNode) target);
}
if (srouceTree == targetTree) {
return false;
}
if (srouceTree.eContainer() instanceof XmlMapData) {
XmlMapData mapdata = ((XmlMapData) srouceTree.eContainer());
int indexSource = mapdata.getInputTrees().indexOf(srouceTree);
int indexTarget = mapdata.getInputTrees().indexOf(targetTree);
if (indexTarget < indexSource) {
return false;
}
}
}
}
return true;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class AddChoiceAction method calculateEnabled.
@Override
protected boolean calculateEnabled() {
if (getSelectedObjects().isEmpty()) {
return false;
} else {
// get the last selection to run the action
Object s = getSelectedObjects().get(0);
if (s instanceof List && !((List) s).isEmpty()) {
List selectedarts = (List) s;
Object object = selectedarts.get(selectedarts.size() - 1);
if (object instanceof TreeNodeEditPart) {
TreeNodeEditPart nodePart = (TreeNodeEditPart) object;
this.parent = (TreeNode) nodePart.getModel();
if (parent.isChoice() || parent.isSubstitution()) {
return false;
}
// can't create two or more choice under a node
EList<TreeNode> children = parent.getChildren();
for (int i = 0; i < children.size(); i++) {
if (children.get(i).isChoice()) {
return false;
}
}
boolean isElement = NodeType.ELEMENT.equals(parent.getNodeType());
if (isElement && XmlMapUtil.getXPathLength(parent.getXpath()) > 2) {
return true;
}
}
}
}
return false;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class CreateElementAction method run.
@Override
public void run() {
TreeNode treeNode = null;
boolean needWarning = false;
if (input) {
treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
if (!parent.getOutgoingConnections().isEmpty()) {
needWarning = true;
}
} else {
treeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
OutputTreeNode outputTreeNode = (OutputTreeNode) treeNode;
EList<Connection> incomingConnections = parent.getIncomingConnections();
if (!incomingConnections.isEmpty()) {
needWarning = true;
}
}
boolean canContinue = true;
// Shell shell = this.part.getSite().getShell();
if (needWarning) {
canContinue = MessageDialog.openConfirm(null, "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element ?");
}
if (canContinue) {
// IInputValidator validataor = new IInputValidator() {
//
// public String isValid(String newText) {
// String xpath = XmlMapUtil.getXPath(parent.getXpath(), newText, NodeType.ELEMENT);
// EList<TreeNode> children = parent.getChildren();
// boolean exist = false;
// for (TreeNode child : children) {
// if (child.getXpath() != null && child.getXpath().equals(xpath)) {
// exist = true;
// break;
// }
// }
//
// if (exist) {
// return "Element '" + newText + "' already exist !";
// } else {
// return null;
// }
// }
//
// };
InputDialog dialog = new InputDialog(null, "Create New Element", "Input the new element's valid label", "", null);
int open = -1;
String label = "";
while (!StringUtil.validateLabelForXML(label)) {
open = dialog.open();
if (open == InputDialog.OK) {
label = dialog.getValue().trim();
}
if (open == InputDialog.CANCEL) {
return;
}
}
if (open == Window.OK) {
XmlMapUtil.detachNodeConnections(parent, mapperManager.getExternalData(), false);
treeNode.setName(label);
treeNode.setNodeType(NodeType.ELEMENT);
String parentXpath = parent.getXpath();
if (parent.isChoice() || parent.isSubstitution()) {
TreeNode realPrant = XmlMapUtil.getRealParentNode(parent);
if (realPrant != null) {
parentXpath = realPrant.getXpath();
}
}
treeNode.setXpath(XmlMapUtil.getXPath(parentXpath, treeNode.getName(), treeNode.getNodeType()));
treeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
parent.getChildren().add(treeNode);
parent.setExpression("");
if (!input) {
OutputTreeNode output = (OutputTreeNode) parent;
if (!XmlMapUtil.isExpressionEditable(output) && output.isAggregate()) {
output.setAggregate(false);
}
}
}
if (open == Window.OK && mapperManager != null) {
// if (input) {
// mapperManager.inputTreeSchemaBeanListModified();
// } else {
// mapperManager.outputTreeSchemaBeanListModified();
// }
Object object = graphicViewer.getEditPartRegistry().get(treeNode);
if (object instanceof TreeNodeEditPart) {
graphicViewer.select((TreeNodeEditPart) object);
}
}
}
}
Aggregations