Search in sources :

Example 1 with XmlMapGraphicViewer

use of org.talend.designer.xmlmap.editor.XmlMapGraphicViewer 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 2 with XmlMapGraphicViewer

use of org.talend.designer.xmlmap.editor.XmlMapGraphicViewer in project tdi-studio-se by Talend.

the class StyledTextHandler method updateCellExpression.

private void updateCellExpression() {
    if (selectedNode != null && styledText != null && !styledText.getText().equals(selectedNode.getExpression())) {
        DirectEditCommand command = new DirectEditCommand(selectedNodePart, selectedNode, DirectEditType.EXPRESSION, styledText.getText());
        ((XmlMapGraphicViewer) selectedNodePart.getViewer()).getEditDomain().getCommandStack().execute(command);
    }
}
Also used : DirectEditCommand(org.talend.designer.xmlmap.commands.DirectEditCommand) XmlMapGraphicViewer(org.talend.designer.xmlmap.editor.XmlMapGraphicViewer)

Example 3 with XmlMapGraphicViewer

use of org.talend.designer.xmlmap.editor.XmlMapGraphicViewer in project tdi-studio-se by Talend.

the class XmlMapOutputZoneToolBar method addTable.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.newabstractmap.figures.treetools.zone.OutputZoneToolBar#addTable()
     */
@Override
protected void addTable() {
    final OutputXmlTree createOutputXmlTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
    CommandStack commandStack = externalPart.getViewer().getEditDomain().getCommandStack();
    commandStack.execute(new Command() {

        @Override
        public void execute() {
            if (externalPart.getViewer() instanceof XmlMapGraphicViewer) {
                XmlMapGraphicViewer viewer = (XmlMapGraphicViewer) externalPart.getViewer();
                MapperManager manager = viewer.getMapperManager();
                String outputName = manager.getMapperUI().openNewOutputCreationDialog();
                if (outputName == null) {
                    return;
                }
                createOutputXmlTree.setName(outputName);
                externalData.getOutputTrees().add(createOutputXmlTree);
                MetadataTable metadataTable = new MetadataTable();
                metadataTable.setLabel(outputName);
                metadataTable.setTableName(outputName);
                mapperComponent.getMetadataList().add(metadataTable);
                mapperComponent.getProcess().addUniqueConnectionName(outputName);
                int indexOf = externalPart.getModelChildren().indexOf(createOutputXmlTree);
                if (indexOf != -1) {
                    externalPart.getViewer().select((EditPart) externalPart.getChildren().get(indexOf));
                }
                if (!min_size.isEnabled()) {
                    min_size.setEnabled(true);
                }
                // check problem for created output incase input main is multiloop
                mapperManger.getProblemsAnalyser().checkProblems(createOutputXmlTree);
                mapperManger.getMapperUI().updateStatusBar();
            }
        }
    });
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) MapperManager(org.talend.designer.xmlmap.ui.tabs.MapperManager) Command(org.eclipse.gef.commands.Command) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) OutputXmlTreeEditPart(org.talend.designer.xmlmap.parts.OutputXmlTreeEditPart) XmlMapDataEditPart(org.talend.designer.xmlmap.parts.XmlMapDataEditPart) EditPart(org.eclipse.gef.EditPart) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapGraphicViewer(org.talend.designer.xmlmap.editor.XmlMapGraphicViewer)

Example 4 with XmlMapGraphicViewer

use of org.talend.designer.xmlmap.editor.XmlMapGraphicViewer 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)

Example 5 with XmlMapGraphicViewer

use of org.talend.designer.xmlmap.editor.XmlMapGraphicViewer in project tdi-studio-se by Talend.

the class InputXmlTreeEditPart method notifyChanged.

@Override
public void notifyChanged(Notification notification) {
    int type = notification.getEventType();
    int featureId = notification.getFeatureID(XmlmapPackage.class);
    switch(type) {
        case Notification.ADD:
        case Notification.REMOVE:
        case Notification.REMOVE_MANY:
            switch(featureId) {
                case XmlmapPackage.INPUT_XML_TREE__NODES:
                case XmlmapPackage.INPUT_XML_TREE__GLOBAL_MAP_KEYS_VALUES:
                    refreshChildren();
                    break;
                case XmlmapPackage.ABSTRACT_IN_OUT_TREE__FILTER_INCOMING_CONNECTIONS:
                    refreshTargetConnections();
                    break;
            }
            break;
        case Notification.SET:
            switch(featureId) {
                case XmlmapPackage.INPUT_XML_TREE__NODES:
                case XmlmapPackage.INPUT_XML_TREE__GLOBAL_MAP_KEYS_VALUES:
                    refreshChildren();
                    break;
                case XmlmapPackage.INPUT_XML_TREE__ACTIVATE_CONDENSED_TOOL:
                    getFigure().validate();
                    break;
                case XmlmapPackage.INPUT_XML_TREE__LOOKUP_MODE:
                case XmlmapPackage.INPUT_XML_TREE__MATCHING_MODE:
                case XmlmapPackage.INPUT_XML_TREE__INNER_JOIN:
                case XmlmapPackage.INPUT_XML_TREE__PERSISTENT:
                case XmlmapPackage.INPUT_XML_TREE__MINIMIZED:
                case XmlmapPackage.INPUT_XML_TREE__EXPRESSION_FILTER:
                    ((InputXmlTreeFigure) getFigure()).update(featureId);
                    break;
                case XmlmapPackage.ABSTRACT_IN_OUT_TREE__MULTI_LOOPS:
                    if (getParent() instanceof XmlMapDataEditPart) {
                        List childPart = ((XmlMapDataEditPart) getParent()).getChildren();
                        for (Object o : childPart) {
                            if (o instanceof OutputXmlTreeEditPart) {
                                OutputXmlTreeEditPart outputPart = (OutputXmlTreeEditPart) o;
                                boolean hasDocument = XmlMapUtil.hasDocument((OutputXmlTree) outputPart.getModel());
                                if (!hasDocument) {
                                    OutputXmlTreeFigure outputTreeFigure = (OutputXmlTreeFigure) outputPart.getFigure();
                                    outputTreeFigure.update(XmlmapPackage.ABSTRACT_IN_OUT_TREE__MULTI_LOOPS);
                                } else {
                                    List nodeChild = outputPart.getChildren();
                                    for (Object nc : nodeChild) {
                                        if (nc instanceof OutputTreeNodeEditPart) {
                                            refreshOutputNodeLoopFunctionBtn((OutputTreeNodeEditPart) nc);
                                        }
                                    }
                                }
                            }
                        }
                        boolean changed = clearOutputAggregateIfNeeded();
                        if (changed) {
                            ((XmlMapDataEditPart) getParent()).refresh();
                        }
                        ((XmlMapGraphicViewer) getViewer()).getMapperManager().getProblemsAnalyser().checkProblems();
                        ((XmlMapGraphicViewer) getViewer()).getMapperManager().getMapperUI().updateStatusBar();
                    }
            }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) OutputXmlTreeFigure(org.talend.designer.xmlmap.figures.OutputXmlTreeFigure) InputXmlTreeFigure(org.talend.designer.xmlmap.figures.InputXmlTreeFigure) XmlMapGraphicViewer(org.talend.designer.xmlmap.editor.XmlMapGraphicViewer) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

XmlMapGraphicViewer (org.talend.designer.xmlmap.editor.XmlMapGraphicViewer)6 Command (org.eclipse.gef.commands.Command)3 MapperManager (org.talend.designer.xmlmap.ui.tabs.MapperManager)3 Point (org.eclipse.draw2d.geometry.Point)2 EditPart (org.eclipse.gef.EditPart)2 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)2 MapperTablePart (org.talend.designer.gefabstractmap.part.MapperTablePart)2 OutputXmlTreeFigure (org.talend.designer.xmlmap.figures.OutputXmlTreeFigure)2 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)2 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)1 Shell (org.eclipse.swt.widgets.Shell)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 MetadataTable (org.talend.core.model.metadata.MetadataTable)1 TableEntityPart (org.talend.designer.gefabstractmap.part.TableEntityPart)1 CreateDocChildrenCommand (org.talend.designer.xmlmap.commands.CreateDocChildrenCommand)1 DirectEditCommand (org.talend.designer.xmlmap.commands.DirectEditCommand)1