use of org.talend.designer.xmlmap.parts.TreeNodeEditPart in project tdi-studio-se by Talend.
the class DeleteTreeNodeAction method run.
@Override
public void run() {
try {
TreeNode docRoot = null;
Object s = getSelectedObjects().get(0);
if (s instanceof List && !((List) s).isEmpty()) {
List selectedarts = new ArrayList((List) s);
Iterator iter = selectedarts.iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof TreeNodeEditPart) {
TreeNodeEditPart nodePart = (TreeNodeEditPart) obj;
TreeNode treeNode = (TreeNode) nodePart.getModel();
if (treeNode.eContainer() instanceof TreeNode) {
TreeNode parent = (TreeNode) treeNode.eContainer();
if (docRoot == null) {
docRoot = XmlMapUtil.getTreeNodeRoot(parent);
}
XmlMapUtil.detachNodeConnections(treeNode, mapperManager.getExternalData(), true);
// if delete loop , clean group and main
if (treeNode.isLoop()) {
if (treeNode instanceof OutputTreeNode && XmlMapUtil.findUpGroupNode((OutputTreeNode) treeNode) != null) {
XmlMapUtil.cleanSubGroup(docRoot);
}
XmlMapUtil.clearMainNode(docRoot);
}
parent.getChildren().remove(treeNode);
// check if tree is multiloop
if (docRoot != null && docRoot.eContainer() instanceof AbstractInOutTree) {
AbstractInOutTree tree = (AbstractInOutTree) docRoot.eContainer();
tree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(tree));
}
if (input) {
// remove delete loops in InputLoopTable for outputs
List<TreeNode> subNodes = new ArrayList<TreeNode>();
checkSubElementIsLoop(treeNode, subNodes);
XmlMapUtil.removeloopInOutputTree(mapperManager, subNodes);
}
}
}
}
}
if (mapperManager != null) {
mapperManager.beanListModified(input);
// }
if (docRoot != null && docRoot.eContainer() instanceof AbstractInOutTree) {
mapperManager.getProblemsAnalyser().checkProblems((AbstractInOutTree) docRoot.eContainer());
mapperManager.getMapperUI().updateStatusBar();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.talend.designer.xmlmap.parts.TreeNodeEditPart in project tdi-studio-se by Talend.
the class FixValueAction 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.selectedNode = (TreeNode) nodePart.getModel();
boolean isNameSpace = NodeType.NAME_SPACE.equals(selectedNode.getNodeType());
if (isNameSpace && (selectedNode.getExpression() == null || "".equals(selectedNode.getExpression()))) {
return true;
}
}
}
}
return false;
}
use of org.talend.designer.xmlmap.parts.TreeNodeEditPart in project tdi-studio-se by Talend.
the class ImportTreeFromXml 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 parentPart = (TreeNodeEditPart) object;
parentNode = (TreeNode) parentPart.getModel();
if (parentNode.eContainer() instanceof AbstractInOutTree && XmlMapUtil.DOCUMENT.equals(parentNode.getType())) {
return true;
}
}
}
}
return false;
}
use of org.talend.designer.xmlmap.parts.TreeNodeEditPart in project tdi-studio-se by Talend.
the class RenameTreeNodeAction method calculateEnabled.
@Override
protected boolean calculateEnabled() {
if (getSelectedObjects().isEmpty()) {
return false;
} else {
boolean enable = true;
// 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 obj = selectedarts.get(selectedarts.size() - 1);
if (obj instanceof TreeNodeEditPart) {
TreeNodeEditPart nodePart = (TreeNodeEditPart) obj;
this.selectedNode = (TreeNode) nodePart.getModel();
if (NodeType.NAME_SPACE.equals(selectedNode.getNodeType()) || selectedNode.isChoice()) {
return false;
}
int xPathLength = XmlMapUtil.getXPathLength(selectedNode.getXpath());
if (xPathLength <= 2) {
enable = false;
}
} else {
enable = false;
}
}
return enable;
}
}
use of org.talend.designer.xmlmap.parts.TreeNodeEditPart in project tdi-studio-se by Talend.
the class AddChoiceAction 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();
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 a choice for the selected element ?");
}
if (canContinue) {
XmlMapUtil.detachNodeConnections(parent, mapperManager.getExternalData(), false);
treeNode.setName(parent.getName() + XSDPopulationUtil2.CHOICE);
treeNode.setNodeType(NodeType.ELEMENT);
treeNode.setXpath(XmlMapUtil.getXPath(this.parent.getXpath(), treeNode.getName(), treeNode.getNodeType()));
treeNode.setChoice(true);
parent.getChildren().add(treeNode);
if (!input) {
OutputTreeNode output = (OutputTreeNode) parent;
if (!XmlMapUtil.isExpressionEditable(output) && output.isAggregate()) {
output.setAggregate(false);
}
}
Object object = graphicViewer.getEditPartRegistry().get(treeNode);
if (object instanceof TreeNodeEditPart) {
graphicViewer.select((TreeNodeEditPart) object);
}
}
}
Aggregations