use of org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart 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.parts.OutputTreeNodeEditPart 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.parts.OutputTreeNodeEditPart in project tdi-studio-se by Talend.
the class CreateNodeAndConnectionCommand method execute.
@Override
public void execute() {
if (targetEditPart == null) {
return;
}
xmlMapData = getXmlMapData(targetEditPart.getModel());
if (xmlMapData == null) {
return;
}
if (newObjects instanceof TransferedObject) {
TransferedObject tranceferedObj = (TransferedObject) newObjects;
// this node type is only used when drag leaf element or attribute or varnode to create output node
NodeType selectedNodeType = NodeType.ELEMENT;
if (!update && targetEditPart instanceof OutputTreeNodeEditPart) {
OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) targetEditPart).getModel();
Shell shell = targetEditPart.getViewer().getControl().getShell();
// if allNamespace , create output as namespace , if allsubTree , create output subtree , no need prompt
boolean needPrompt = false;
boolean hasSubTree = false;
for (Object o : tranceferedObj.getToTransfer()) {
if (o instanceof VarNodeEditPart) {
needPrompt = true;
} else if (o instanceof TreeNodeEditPart) {
TreeNode treeNode = (TreeNode) ((TreeNodeEditPart) o).getModel();
if (NodeType.ATTRIBUT.equals(treeNode.getNodeType())) {
needPrompt = true;
}
if (NodeType.ELEMENT.equals(treeNode.getNodeType())) {
if (treeNode.getChildren().isEmpty()) {
needPrompt = true;
} else {
hasSubTree = true;
}
}
}
}
if (needPrompt) {
DragAndDrogDialog selectDialog = new DragAndDrogDialog(shell, !targetOutputNode.getChildren().isEmpty());
int open = selectDialog.open();
if (open == Window.OK) {
if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
selectedNodeType = NodeType.ELEMENT;
} else if (DragAndDrogDialog.CREATE_AS_ATTRIBUTE.equals(selectDialog.getSelectValue())) {
selectedNodeType = NodeType.ATTRIBUT;
} else if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
selectedNodeType = NodeType.NAME_SPACE;
} else if (DragAndDrogDialog.CREATE_AS_TEXT.equals(selectDialog.getSelectValue())) {
update = true;
}
} else {
return;
}
}
if (!update) {
if (!targetOutputNode.getIncomingConnections().isEmpty() && ((selectedNodeType != NodeType.ATTRIBUT && selectedNodeType != NodeType.NAME_SPACE) || hasSubTree)) {
boolean 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) {
XmlMapUtil.detachNodeConnections(targetOutputNode, xmlMapData, false);
} else {
return;
}
}
}
}
for (Object o : (tranceferedObj.getToTransfer())) {
if (!(o instanceof TableEntityPart)) {
continue;
}
AbstractNode sourceNode = (AbstractNode) ((TableEntityPart) o).getModel();
if (update) {
doUpdate(sourceNode);
} else {
// only drop output can create a new node now
if (targetEditPart instanceof OutputTreeNodeEditPart) {
OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) targetEditPart).getModel();
OutputTreeNode targetNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
targetNode.setName(sourceNode.getName());
targetNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
if (sourceNode instanceof TreeNode) {
NodeType nodeType = selectedNodeType;
if (NodeType.NAME_SPACE.equals(((TreeNode) sourceNode).getNodeType())) {
// namespace and only be droped as namespace
nodeType = NodeType.NAME_SPACE;
targetNode.setDefaultValue(((TreeNode) sourceNode).getDefaultValue());
} else if (!((TreeNode) sourceNode).getChildren().isEmpty()) {
nodeType = ((TreeNode) sourceNode).getNodeType();
}
targetNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), targetNode.getName(), nodeType));
targetNode.setNodeType(nodeType);
targetNode.setExpression(XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath()));
EList<TreeNode> sourceChildren = ((TreeNode) sourceNode).getChildren();
if (!sourceChildren.isEmpty()) {
// children must be attribute or namespace
for (TreeNode child : sourceChildren) {
OutputTreeNode childTarget = XmlmapFactory.eINSTANCE.createOutputTreeNode();
childTarget.setName(child.getName());
childTarget.setType(child.getType());
childTarget.setNodeType(child.getNodeType());
childTarget.setXpath(XmlMapUtil.getXPath(targetNode.getXpath(), childTarget.getName(), childTarget.getNodeType()));
targetNode.getChildren().add(childTarget);
if (NodeType.NAME_SPACE.equals(child.getNodeType())) {
childTarget.setDefaultValue(child.getDefaultValue());
// default value is already set as from source , no need the expression to get
// default value
childTarget.setExpression("");
} else {
childTarget.setExpression(XmlMapUtil.convertToExpression(child.getXpath()));
Connection conn = XmlmapFactory.eINSTANCE.createConnection();
conn.setSource(child);
conn.setTarget(childTarget);
// attach source and target
childTarget.getIncomingConnections().add(conn);
child.getOutgoingConnections().add(conn);
if (xmlMapData != null) {
xmlMapData.getConnections().add(conn);
}
}
}
}
} else if (sourceNode instanceof VarNode) {
String variable = sourceNode.getName();
targetNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), targetNode.getName(), selectedNodeType));
targetNode.setNodeType(selectedNodeType);
if (sourceNode.eContainer() instanceof VarTable) {
VarTable container = (VarTable) sourceNode.eContainer();
variable = container.getName() + TalendTextUtils.JAVA_END_STRING + variable;
}
targetNode.setExpression(variable);
}
targetOutputNode.getChildren().add(targetNode);
// add connection
Connection conn = XmlmapFactory.eINSTANCE.createConnection();
conn.setSource(sourceNode);
conn.setTarget(targetNode);
// attach source and target
targetNode.getIncomingConnections().add(conn);
sourceNode.getOutgoingConnections().add(conn);
if (xmlMapData != null) {
xmlMapData.getConnections().add(conn);
}
// if (sourceNode instanceof TreeNode) {
// createInputLoopTable((TreeNode) sourceNode, targetNode);
// }
}
}
}
}
if (targetEditPart instanceof OutputTreeNodeEditPart) {
OutputTreeNode model = (OutputTreeNode) targetEditPart.getModel();
if (NodeType.NAME_SPACE.equals(model.getNodeType()) && model.getExpression() != null && !"".equals(model.getExpression())) {
model.setDefaultValue("");
}
if (!XmlMapUtil.isExpressionEditable(model)) {
model.setExpression("");
if (model.isAggregate()) {
model.setAggregate(false);
}
}
}
}
use of org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart in project tdi-studio-se by Talend.
the class XmlMapUtil method getParentLoopNodeEditPart.
public static OutputTreeNodeEditPart getParentLoopNodeEditPart(OutputTreeNodeEditPart nodePart) {
if (nodePart != null && nodePart instanceof OutputTreeNodeEditPart) {
OutputTreeNodeEditPart nodePartTemp = nodePart;
TreeNode model = (TreeNode) nodePartTemp.getModel();
if (model.isLoop()) {
return nodePartTemp;
} else {
if (nodePartTemp.getParent() != null && nodePartTemp.getParent() instanceof OutputTreeNodeEditPart) {
return getParentLoopNodeEditPart((OutputTreeNodeEditPart) nodePartTemp.getParent());
}
}
}
return null;
}
use of org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart in project tdi-studio-se by Talend.
the class DragAndDropEditPolicy method getCommand.
@Override
public Command getCommand(Request request) {
if (request instanceof CreateNodeConnectionRequest) {
CreateNodeConnectionRequest rq = (CreateNodeConnectionRequest) request;
EditPart targetEditPart = rq.getTargetEditPart();
Command command = null;
if (targetEditPart != null && TemplateTransfer.getInstance().getObject() instanceof TransferedObject) {
TransferedObject toDrop = (TransferedObject) TemplateTransfer.getInstance().getObject();
MapperManager manager = ((XmlMapGraphicViewer) targetEditPart.getViewer()).getMapperManager();
if (manager != null && manager.getExternalData() != null) {
DropType dropType = rq.getNewObjectType();
if (dropType != null) {
switch(dropType) {
case DROP_FILTER:
if (targetEditPart instanceof MapperTablePart) {
command = new UpdateFilterExpressionCommand(toDrop, (MapperTablePart) targetEditPart, manager.getExternalData());
}
break;
case DROP_EXPRESSION:
if (targetEditPart instanceof TableEntityPart) {
command = new UpdateExpressionCommand(toDrop, (TableEntityPart) targetEditPart, manager);
}
break;
case DROP_OUTPUT_DOC_CHILD:
if (targetEditPart instanceof OutputTreeNodeEditPart && rq.getNewObject() instanceof OutputTreeNode) {
command = new CreateDocChildrenCommand(toDrop, (OutputTreeNodeEditPart) targetEditPart, rq, manager);
}
break;
case DROP_INSERT_OUTPUT:
case DROP_INSERT_VAR:
case DROP_INSERT_INPUT:
command = new InsertNewColumnCommand(toDrop, targetEditPart, rq, manager, dropType);
default:
break;
}
}
}
}
if (command != null) {
return command;
}
// drop expression
// boolean update = rq.getDropType() == CreateNodeConnectionRequest.DROP_EXPRESSION ? true : false;
// return new CreateNodeAndConnectionCommand(rq.getNewObject(), rq.getTargetEditPart(), update);
}
return super.getCommand(request);
}
Aggregations