Search in sources :

Example 1 with MapperManager

use of org.talend.designer.xmlmap.ui.tabs.MapperManager 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 MapperManager

use of org.talend.designer.xmlmap.ui.tabs.MapperManager in project tdi-studio-se by Talend.

the class XmlMapFilterContainer method addButtonListener.

@Override
protected void addButtonListener() {
    IService expressionBuilderDialogService = GlobalServiceRegister.getDefault().getService(IExpressionBuilderDialogService.class);
    final IExpressionBuilderDialogController dialog = ((IExpressionBuilderDialogService) expressionBuilderDialogService).getExpressionBuilderInstance(parent, null, null);
    button.addMouseListener(new MouseListener() {

        @Override
        public void mousePressed(MouseEvent me) {
            if (dialog instanceof TrayDialog) {
                TrayDialog parentDialog = (TrayDialog) dialog;
                // if press the button ,should apply ExpressionCellEditor value
                MapperManager mapperManger = (MapperManager) tableManager.getMapperManger();
                mapperManger.fireCurrentDirectEditApply();
                dialog.setDefaultExpression(tableManager.getExpressionFilter());
                if (Window.OK == parentDialog.open()) {
                    String expressionForTable = dialog.getExpressionForTable();
                    tableManager.setExpressionFilter(expressionForTable);
                    tableManager.getEditPart().getViewer().getEditDomain().getCommandStack().execute(getFilterChangeCommand(tableManager.getModel(), expressionForTable));
                }
            }
        }

        @Override
        public void mouseReleased(MouseEvent me) {
        // TODO Auto-generated method stub
        }

        @Override
        public void mouseDoubleClicked(MouseEvent me) {
        // TODO Auto-generated method stub
        }
    });
}
Also used : IExpressionBuilderDialogService(org.talend.core.runtime.services.IExpressionBuilderDialogService) MouseListener(org.eclipse.draw2d.MouseListener) MouseEvent(org.eclipse.draw2d.MouseEvent) MapperManager(org.talend.designer.xmlmap.ui.tabs.MapperManager) IExpressionBuilderDialogController(org.talend.commons.ui.runtime.expressionbuilder.IExpressionBuilderDialogController) TrayDialog(org.eclipse.jface.dialogs.TrayDialog) IService(org.talend.core.IService)

Example 3 with MapperManager

use of org.talend.designer.xmlmap.ui.tabs.MapperManager 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 MapperManager

use of org.talend.designer.xmlmap.ui.tabs.MapperManager 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

MapperManager (org.talend.designer.xmlmap.ui.tabs.MapperManager)4 Command (org.eclipse.gef.commands.Command)3 XmlMapGraphicViewer (org.talend.designer.xmlmap.editor.XmlMapGraphicViewer)3 EditPart (org.eclipse.gef.EditPart)2 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)2 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)2 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)2 MouseEvent (org.eclipse.draw2d.MouseEvent)1 MouseListener (org.eclipse.draw2d.MouseListener)1 Point (org.eclipse.draw2d.geometry.Point)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)1 TrayDialog (org.eclipse.jface.dialogs.TrayDialog)1 Shell (org.eclipse.swt.widgets.Shell)1 IExpressionBuilderDialogController (org.talend.commons.ui.runtime.expressionbuilder.IExpressionBuilderDialogController)1 IService (org.talend.core.IService)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 MetadataTable (org.talend.core.model.metadata.MetadataTable)1 IExpressionBuilderDialogService (org.talend.core.runtime.services.IExpressionBuilderDialogService)1 MapperTablePart (org.talend.designer.gefabstractmap.part.MapperTablePart)1