use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class ImportTreeFromRepository method createDefaultTreeNode.
private TreeNode createDefaultTreeNode(TreeNode parentNode, String name) {
TreeNode createTreeNode = createModel();
createTreeNode.setName(name);
createTreeNode.setNodeType(NodeType.ELEMENT);
createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
createTreeNode.setXpath(XmlMapUtil.getXPath(parentNode.getXpath(), createTreeNode.getName(), createTreeNode.getNodeType()));
parentNode.getChildren().add(createTreeNode);
return createTreeNode;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class RenameTreeNodeAction method run.
@Override
public void run() {
if (selectedNode != null) {
// validataor
IInputValidator validataor = new IInputValidator() {
public String isValid(String newText) {
String xpath = XmlMapUtil.getXPath(((TreeNode) selectedNode.eContainer()).getXpath(), newText, selectedNode.getNodeType());
EList<TreeNode> children = ((TreeNode) selectedNode.eContainer()).getChildren();
boolean exist = false;
for (TreeNode child : children) {
if (child.getNodeType().equals(selectedNode.getNodeType())) {
if (child.getXpath() != null && child.getXpath().equals(xpath) && !child.equals(selectedNode)) {
exist = true;
break;
}
}
}
if (exist) {
if (selectedNode.getNodeType().equals(NodeType.ATTRIBUT)) {
return "Atribute '" + newText + "' already exist !";
} else if (selectedNode.getNodeType().equals(NodeType.ELEMENT)) {
return "Element '" + newText + "' already exist !";
}
}
return null;
}
};
String name = selectedNode.getName();
if (selectedNode.isSubstitution()) {
name = name.substring(0, name.lastIndexOf(XSDPopulationUtil2.SUBS));
}
InputDialog dialog = new InputDialog(null, "Rename Tree Node", "", name, validataor);
if (dialog.open() == Window.OK) {
if (selectedNode.isSubstitution()) {
selectedNode.setName(dialog.getValue() + XSDPopulationUtil2.SUBS);
} else {
selectedNode.setName(dialog.getValue());
}
// refresh
if (selectedNode.isSubstitution()) {
TreeNode realParent = XmlMapUtil.getRealParentNode(selectedNode);
if (realParent != null) {
selectedNode.setXpath(XmlMapUtil.getXPath(realParent.getXpath(), selectedNode.getName(), selectedNode.getNodeType()));
}
} else {
XmlMapData externalEmfData = (XmlMapData) mapperManager.getExternalData();
XmlMapUtil.updateXPathAndExpression(externalEmfData, mapperManager.getMapperComponent().getExpressionManager(), selectedNode, dialog.getValue(), XmlMapUtil.getXPathLength(selectedNode.getXpath()), true);
}
TabFolderEditors tabFolderEditors = mapperManager.getMapperUI().getTabFolderEditors();
if (tabFolderEditors != null) {
if (selectedNode instanceof OutputTreeNode) {
tabFolderEditors.getOutputTreeSchemaEditor().refresh();
} else if (selectedNode instanceof TreeNode) {
tabFolderEditors.getInputTreeSchemaEditor().refresh();
}
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class InsertNewColumnCommand method validSourceNodeName.
private String validSourceNodeName(final List<? extends AbstractNode> validationList, TreeNode sourceNode) {
String sourceName = sourceNode.getName();
boolean isValidate = MetadataToolHelper.isValidColumnName(sourceName);
boolean fixing = false;
if (!isValidate) {
if (sourceName.contains(":")) {
//$NON-NLS-1$
if (sourceNode.eContainer() instanceof TreeNode) {
TreeNode parent = (TreeNode) sourceNode.eContainer();
for (TreeNode child : parent.getChildren()) {
if (child.getNodeType() == NodeType.NAME_SPACE) {
if (sourceName.startsWith(child.getName() + ":")) {
//$NON-NLS-1$
sourceName = sourceName.substring(child.getName().length() + 1, sourceName.length());
fixing = true;
}
}
}
if (!fixing) {
//$NON-NLS-1$
sourceName = sourceName.substring(sourceName.indexOf(":"), sourceName.length());
fixing = true;
}
}
}
if (!fixing || !MetadataToolHelper.isValidColumnName(sourceName)) {
IInputValidator validataor = new IInputValidator() {
@Override
public String isValid(String newText) {
return XmlMapUtil.isValidColumnName(validationList, newText);
}
};
InputDialog dialog = new InputDialog(null, Messages.getString("InsertNewColumnCommand_createNew"), Messages.getString("InsertNewColumnCommand_message"), sourceName, //$NON-NLS-1$ //$NON-NLS-2$
validataor);
int open = dialog.open();
if (open == Window.CANCEL) {
return null;
} else {
sourceName = dialog.getValue();
}
}
}
return sourceName;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode 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);
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class CreateAttributeAction method run.
@Override
public void run() {
TreeNode treeNode = null;
if (input) {
treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
} else {
treeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
}
// IInputValidator validataor = new IInputValidator() {
//
// public String isValid(String newText) {
// String xpath = XmlMapUtil.getXPath(parent.getXpath(), newText, NodeType.ATTRIBUT);
// 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 "Atribute '" + newText + "' already exist !";
// } else {
// return null;
// }
// }
//
// };
String label = "";
InputDialog dialog = new InputDialog(null, "Create New Attribute", "Input the new attribute's valid label", "", null);
int open = -1;
while (!StringUtil.validateLabelForXML(label)) {
open = dialog.open();
if (open == InputDialog.OK) {
label = dialog.getValue().trim();
}
if (open == InputDialog.CANCEL) {
return;
}
}
if (open == Window.OK) {
treeNode.setName(label);
treeNode.setNodeType(NodeType.ATTRIBUT);
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);
final EList<TreeNode> children = parent.getChildren();
int index = 0;
for (int i = 0; i < children.size(); i++) {
final TreeNode child = children.get(i);
if (child.getNodeType() == NodeType.NAME_SPACE || child.getNodeType() == NodeType.ATTRIBUT) {
if (i == children.size() - 1) {
index = children.size();
}
continue;
} else {
index = i;
break;
}
}
children.add(index, treeNode);
}
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