Search in sources :

Example 6 with NodeType

use of org.talend.designer.xmlmap.model.emf.xmlmap.NodeType in project tdi-studio-se by Talend.

the class XmlDropTargetListener method handleDrop.

@Override
protected void handleDrop() {
    final Object object = TemplateTransfer.getInstance().getObject();
    if (object == null || !(object instanceof TransferedObject)) {
        return;
    }
    updateTargetRequest();
    updateTargetEditPart();
    DropContextAnalyzer analyzer = new DropContextAnalyzer((TransferedObject) object, (AbstractGraphicalEditPart) getTargetEditPart(), getDropLocation());
    if (analyzer.isDropValid()) {
        NodeType selectedNodeType = NodeType.ELEMENT;
        DropType dropType = analyzer.getDropType();
        if (dropType == DropType.DROP_OUTPUT_DOC_CHILD && getTargetEditPart() instanceof OutputTreeNodeEditPart) {
            OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) getTargetEditPart()).getModel();
            Shell shell = 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 : ((TransferedObject) object).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())) {
                        dropType = DropType.DROP_EXPRESSION;
                    }
                } else {
                    return;
                }
            }
            if (dropType != DropType.DROP_EXPRESSION) {
                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) {
                        MapperManager mapperManager = ((XmlMapGraphicViewer) getViewer()).getMapperManager();
                        if (mapperManager != null && mapperManager.getExternalData() != null) {
                            XmlMapUtil.detachNodeConnections(targetOutputNode, mapperManager.getExternalData(), false);
                        }
                    } else {
                        return;
                    }
                }
            }
        }
        NewNodeCreationFactory factory = new NewNodeCreationFactory(dropType, selectedNodeType);
        getCreateRequest().setFactory(factory);
    }
    if (getTargetEditPart() != null) {
        Command command = getCommand();
        if (command != null && command.canExecute()) {
            getViewer().getEditDomain().getCommandStack().execute(command);
        } else {
            getCurrentEvent().detail = DND.DROP_NONE;
        }
    } else {
        getCurrentEvent().detail = DND.DROP_NONE;
    }
    selectAddedObject();
}
Also used : VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) MapperManager(org.talend.designer.xmlmap.ui.tabs.MapperManager) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) Point(org.eclipse.draw2d.geometry.Point) Shell(org.eclipse.swt.widgets.Shell) Command(org.eclipse.gef.commands.Command) 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) XmlMapGraphicViewer(org.talend.designer.xmlmap.editor.XmlMapGraphicViewer)

Aggregations

NodeType (org.talend.designer.xmlmap.model.emf.xmlmap.NodeType)6 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)3 Shell (org.eclipse.swt.widgets.Shell)2 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)2 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)2 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)2 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)2 VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)2 Point (org.eclipse.draw2d.geometry.Point)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 Command (org.eclipse.gef.commands.Command)1 Test (org.junit.Test)1 TableEntityPart (org.talend.designer.gefabstractmap.part.TableEntityPart)1 DragAndDrogDialog (org.talend.designer.xmlmap.dnd.DragAndDrogDialog)1 XmlMapGraphicViewer (org.talend.designer.xmlmap.editor.XmlMapGraphicViewer)1 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)1 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)1 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)1 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)1 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)1