Search in sources :

Example 6 with TableEntityPart

use of org.talend.designer.gefabstractmap.part.TableEntityPart 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);
            }
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) TableEntityPart(org.talend.designer.gefabstractmap.part.TableEntityPart) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) DragAndDrogDialog(org.talend.designer.xmlmap.dnd.DragAndDrogDialog) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) Shell(org.eclipse.swt.widgets.Shell) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) NodeType(org.talend.designer.xmlmap.model.emf.xmlmap.NodeType) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)

Example 7 with TableEntityPart

use of org.talend.designer.gefabstractmap.part.TableEntityPart 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);
}
Also used : MapperManager(org.talend.designer.xmlmap.ui.tabs.MapperManager) TableEntityPart(org.talend.designer.gefabstractmap.part.TableEntityPart) CreateDocChildrenCommand(org.talend.designer.xmlmap.commands.CreateDocChildrenCommand) AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) EditPart(org.eclipse.gef.EditPart) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) MapperTablePart(org.talend.designer.gefabstractmap.part.MapperTablePart) UpdateExpressionCommand(org.talend.designer.xmlmap.commands.UpdateExpressionCommand) Command(org.eclipse.gef.commands.Command) InsertNewColumnCommand(org.talend.designer.xmlmap.commands.InsertNewColumnCommand) UpdateFilterExpressionCommand(org.talend.designer.xmlmap.commands.UpdateFilterExpressionCommand) CreateDocChildrenCommand(org.talend.designer.xmlmap.commands.CreateDocChildrenCommand) UpdateExpressionCommand(org.talend.designer.xmlmap.commands.UpdateExpressionCommand) CreateNodeConnectionRequest(org.talend.designer.xmlmap.dnd.CreateNodeConnectionRequest) UpdateFilterExpressionCommand(org.talend.designer.xmlmap.commands.UpdateFilterExpressionCommand) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) DropType(org.talend.designer.xmlmap.dnd.DropType) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) InsertNewColumnCommand(org.talend.designer.xmlmap.commands.InsertNewColumnCommand) XmlMapGraphicViewer(org.talend.designer.xmlmap.editor.XmlMapGraphicViewer)

Example 8 with TableEntityPart

use of org.talend.designer.gefabstractmap.part.TableEntityPart in project tdi-studio-se by Talend.

the class MapperManager method selectionChanged.

@Override
public void selectionChanged(SelectionChangedEvent event) {
    if (!event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection) {
        Iterator iterator = ((IStructuredSelection) event.getSelection()).iterator();
        while (iterator.hasNext()) {
            Object firstElement = iterator.next();
            if (firstElement instanceof TableEntityPart) {
                AbstractNode model = (AbstractNode) ((TableEntityPart) firstElement).getModel();
                boolean isInputMain = false;
                if (model instanceof OutputTreeNode) {
                    OutputTreeNode outputTreeNodeRoot = (OutputTreeNode) XmlMapUtil.getTreeNodeRoot((OutputTreeNode) model);
                    if (outputTreeNodeRoot != null && outputTreeNodeRoot.eContainer() instanceof OutputXmlTree) {
                        selectOutputXmlTree((OutputXmlTree) outputTreeNodeRoot.eContainer());
                        onEntitySelection((IStructuredSelection) event.getSelection(), selectedOutputTree);
                    }
                } else if (model instanceof TreeNode) {
                    TreeNode inputTreeNodeRoot = XmlMapUtil.getTreeNodeRoot((TreeNode) model);
                    if (inputTreeNodeRoot != null && inputTreeNodeRoot.eContainer() instanceof InputXmlTree) {
                        selectInputXmlTree((InputXmlTree) inputTreeNodeRoot.eContainer());
                        isInputMain = !((InputXmlTree) inputTreeNodeRoot.eContainer()).isLookup();
                        onEntitySelection((IStructuredSelection) event.getSelection(), selectedInputTree);
                    }
                }
                if (!isInputMain) {
                    refreshStyledTextEditor((TableEntityPart) firstElement);
                } else {
                    refreshStyledTextEditor(null);
                }
                selectedFigure = ((TableEntityPart) firstElement).getFigure();
            } else if (firstElement instanceof InputXmlTreeEditPart) {
                selectInputXmlTree((InputXmlTree) ((InputXmlTreeEditPart) firstElement).getModel());
                refreshStyledTextEditor(null);
            } else if (firstElement instanceof OutputXmlTreeEditPart) {
                selectOutputXmlTree((OutputXmlTree) ((OutputXmlTreeEditPart) firstElement).getModel());
                refreshStyledTextEditor(null);
            }
        }
    }
// else {
// ExtendedTableModel<TreeSchemaTableEntry> oldModel = mapperUI.getTabFolderEditors().getInputTreeSchemaEditor()
// .getExtendedTableModel();
// if (oldModel != null && oldModel.getBeanCount() != 0) {
// List<TreeSchemaTableEntry> treeSchemaEntrys = new ArrayList<TreeSchemaTableEntry>();
// mapperUI.getTabFolderEditors().getInputTreeSchemaEditor()
// .setExtendedControlModel(new ExtendedTableModel<TreeSchemaTableEntry>("Tree Schema", treeSchemaEntrys));
// mapperUI.getTabFolderEditors().getInputTreeSchemaEditor().getTableViewerCreator().refresh();
// }
// refreshStyledTextEditor(null);
// }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) TableEntityPart(org.talend.designer.gefabstractmap.part.TableEntityPart) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) InputXmlTreeEditPart(org.talend.designer.xmlmap.parts.InputXmlTreeEditPart) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) OutputXmlTreeEditPart(org.talend.designer.xmlmap.parts.OutputXmlTreeEditPart)

Example 9 with TableEntityPart

use of org.talend.designer.gefabstractmap.part.TableEntityPart in project tdi-studio-se by Talend.

the class SearchZoneMapper method getMatcherNodeFigure.

private Map<Integer, Figure> getMatcherNodeFigure(AbstractNode node) {
    Map<Integer, Figure> map = new HashMap<Integer, Figure>();
    int i = -1;
    TableEntityFigure figure = null;
    if (node != null) {
        EList<Adapter> adapter = node.eAdapters();
        if (adapter.size() > 0) {
            if (adapter.get(0) instanceof TableEntityPart) {
                TableEntityPart tableEntityPart = (TableEntityPart) adapter.get(0);
                if (tableEntityPart != null && tableEntityPart.getFigure() != null && tableEntityPart.getFigure() instanceof TableEntityFigure) {
                    figure = (TableEntityFigure) tableEntityPart.getFigure();
                }
            }
        }
        if (node.getExpression() != null && matcher.matches(node.getExpression())) {
            i++;
            map.put(i, figure);
        } else if (node.getName() != null && matcher.matches(node.getName())) {
            i++;
            map.put(i, figure);
        }
    }
    return map;
}
Also used : TableEntityPart(org.talend.designer.gefabstractmap.part.TableEntityPart) HashMap(java.util.HashMap) Adapter(org.eclipse.emf.common.notify.Adapter) TableEntityFigure(org.talend.designer.gefabstractmap.figures.table.entity.TableEntityFigure) IFigure(org.eclipse.draw2d.IFigure) OutputXmlTreeFigure(org.talend.designer.xmlmap.figures.OutputXmlTreeFigure) TableEntityFigure(org.talend.designer.gefabstractmap.figures.table.entity.TableEntityFigure) XmlmapTreeNodeFigure(org.talend.designer.xmlmap.figures.treeNode.XmlmapTreeNodeFigure) VarNodeFigure(org.talend.designer.xmlmap.figures.varnode.VarNodeFigure) InputXmlTreeFigure(org.talend.designer.xmlmap.figures.InputXmlTreeFigure) VarEntityFigure(org.talend.designer.gefabstractmap.figures.var.VarEntityFigure) Figure(org.eclipse.draw2d.Figure)

Example 10 with TableEntityPart

use of org.talend.designer.gefabstractmap.part.TableEntityPart in project tdi-studio-se by Talend.

the class MapperGraphicalViewer method primDeselectAll.

/*
     * if partToAppend is inputTree , don't clean all outputTree in selection list , leave the first one by default . if
     * partToAppend is outputTree , do the same for inputTree selections
     */
private void primDeselectAll(EditPart eidtPart) {
    EditPart partToAppend = eidtPart;
    List list = primGetSelectedEditParts();
    if (partToAppend instanceof TableEntityPart) {
        partToAppend = MapperUtils.getMapperTablePart((TableEntityPart) partToAppend);
    }
    EditPart part;
    MapperTablePart abstractTreePart = null;
    for (int i = 0; i < list.size(); i++) {
        part = (EditPart) list.get(i);
        if (partToAppend instanceof InputTablePart) {
            if (abstractTreePart == null && part instanceof OutputTablePart) {
                abstractTreePart = (MapperTablePart) part;
                continue;
            }
        } else if (partToAppend instanceof OutputTablePart) {
            if (abstractTreePart == null && part instanceof InputTablePart) {
                abstractTreePart = (MapperTablePart) part;
                continue;
            }
        }
        part.setSelected(EditPart.SELECTED_NONE);
    }
    list.clear();
    if (abstractTreePart != null) {
        list.add(abstractTreePart);
    }
}
Also used : OutputTablePart(org.talend.designer.gefabstractmap.part.OutputTablePart) TableEntityPart(org.talend.designer.gefabstractmap.part.TableEntityPart) MapperRootEditPart(org.talend.designer.gefabstractmap.part.MapperRootEditPart) EditPart(org.eclipse.gef.EditPart) List(java.util.List) MapperTablePart(org.talend.designer.gefabstractmap.part.MapperTablePart) InputTablePart(org.talend.designer.gefabstractmap.part.InputTablePart)

Aggregations

TableEntityPart (org.talend.designer.gefabstractmap.part.TableEntityPart)15 List (java.util.List)8 ArrayList (java.util.ArrayList)7 MapperTablePart (org.talend.designer.gefabstractmap.part.MapperTablePart)7 EditPart (org.eclipse.gef.EditPart)5 IFigure (org.eclipse.draw2d.IFigure)3 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)3 TableEntityFigure (org.talend.designer.gefabstractmap.figures.table.entity.TableEntityFigure)3 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)3 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)3 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)3 HashMap (java.util.HashMap)2 Figure (org.eclipse.draw2d.Figure)2 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)2 ExpandCollapseFigure (org.talend.designer.gefabstractmap.figures.table.entity.ExpandCollapseFigure)2 TableTreeEntityFigure (org.talend.designer.gefabstractmap.figures.table.entity.TableTreeEntityFigure)2 VarEntityFigure (org.talend.designer.gefabstractmap.figures.var.VarEntityFigure)2 InputTablePart (org.talend.designer.gefabstractmap.part.InputTablePart)2 OutputTablePart (org.talend.designer.gefabstractmap.part.OutputTablePart)2 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)2