Search in sources :

Example 6 with AbstractNode

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

the class XmlMapConnectionBuilder method hasMaptchedLocation.

private boolean hasMaptchedLocation(XmlMapExpressionManager expressionManager, TableEntryLocation sourceLocation, EObject targetNodeOrTree, ExpressionType type) {
    String targetExpression = null;
    AbstractNode targetNode = null;
    AbstractInOutTree targetTree = null;
    switch(type) {
        case EXPRESSION:
            targetNode = (AbstractNode) targetNodeOrTree;
            targetExpression = targetNode.getExpression();
            break;
        case EXPRESSION_FILTER:
            targetTree = (AbstractInOutTree) targetNodeOrTree;
            targetExpression = targetTree.getExpressionFilter();
        default:
            break;
    }
    if (!"".equals(targetExpression) && targetExpression != null) {
        List<TableEntryLocation> targetLocations = expressionManager.parseTableEntryLocation(targetExpression);
        for (TableEntryLocation target : targetLocations) {
            if (sourceLocation.equals(target)) {
                return true;
            } else if (checkRootNodePrefix && !cancelForAll) {
                StringBuffer bf = new StringBuffer();
                String prefix = null;
                String nodeName = null;
                final String[] split = sourceLocation.toString().split("/");
                if (split.length > 2) {
                    for (int i = 0; i < split.length; i++) {
                        String value = split[i];
                        if (i == 1) {
                            int indexOf = split[1].indexOf(":");
                            if (indexOf != -1) {
                                prefix = split[1].substring(0, indexOf);
                                nodeName = split[1].substring(indexOf + 1, split[1].length());
                                value = nodeName;
                            } else {
                                break;
                            }
                        }
                        bf.append(value);
                        if (i < split.length - 1) {
                            bf.append("/");
                        }
                    }
                }
                if (bf.toString().equals(targetExpression)) {
                    if (applyForAll) {
                        // reset the target expression with prefix
                        if (targetNode != null) {
                            targetNode.setExpression(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                        }
                        if (targetTree != null) {
                            targetTree.setExpressionFilter(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                        }
                        return true;
                    } else {
                        PrefixChangeDialog dialog = new PrefixChangeDialog(new Shell());
                        dialog.setPrefix(prefix);
                        dialog.setRootNodeName(nodeName);
                        dialog.setSourceExpression(sourceLocation.toString());
                        dialog.setTargetExpression(target.toString());
                        if (dialog.open() == Window.OK) {
                            applyForAll = dialog.isApplyAll();
                            cancelForAll = dialog.isCancelAll();
                            if (cancelForAll) {
                                return false;
                            }
                            // reset the target expression with prefix
                            if (targetNode != null) {
                                targetNode.setExpression(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                            }
                            if (targetTree != null) {
                                targetTree.setExpressionFilter(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                            }
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) TableEntryLocation(org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) PrefixChangeDialog(org.talend.designer.xmlmap.ui.dialog.PrefixChangeDialog)

Example 7 with AbstractNode

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

the class XmlMapUtil method detachConnectionsSouce.

public static void detachConnectionsSouce(AbstractNode treeNode, XmlMapData mapData, boolean detachChildren) {
    for (Connection connection : treeNode.getIncomingConnections()) {
        AbstractNode source = connection.getSource();
        if (source.getOutgoingConnections().contains(connection)) {
            source.getOutgoingConnections().remove(connection);
            mapData.getConnections().remove(connection);
        }
    }
    treeNode.getIncomingConnections().clear();
    if (treeNode instanceof OutputTreeNode) {
        OutputTreeNode outputTreeNode = (OutputTreeNode) treeNode;
        if (!XmlMapUtil.isExpressionEditable(outputTreeNode) && outputTreeNode.isAggregate()) {
            outputTreeNode.setAggregate(false);
        }
        if (detachChildren && !outputTreeNode.getChildren().isEmpty()) {
            for (int i = 0; i < outputTreeNode.getChildren().size(); i++) {
                TreeNode child = outputTreeNode.getChildren().get(i);
                detachConnectionsSouce(child, mapData);
            }
        }
    }
    treeNode.setExpression("");
}
Also used : AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) INodeConnection(org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection) IConnection(org.talend.designer.xmlmap.model.emf.xmlmap.IConnection) 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)

Example 8 with AbstractNode

use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode 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 AbstractNode

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

the class MapperManager method refreshStyledTextEditor.

public void refreshStyledTextEditor(TableEntityPart nodePart) {
    if (nodePart == null) {
        mapperUI.getTabFolderEditors().getStyledTextHandler().setTextWithoutNotifyListeners("");
        mapperUI.getTabFolderEditors().getStyledTextHandler().getStyledText().setEnabled(false);
        mapperUI.getTabFolderEditors().getStyledTextHandler().getStyledText().setEditable(false);
        return;
    }
    AbstractNode node = (AbstractNode) nodePart.getModel();
    if (node instanceof TreeNode) {
        if (!((TreeNode) node).getChildren().isEmpty()) {
            mapperUI.getTabFolderEditors().getStyledTextHandler().setTextWithoutNotifyListeners("");
            mapperUI.getTabFolderEditors().getStyledTextHandler().getStyledText().setEnabled(false);
            mapperUI.getTabFolderEditors().getStyledTextHandler().getStyledText().setEditable(false);
            return;
        }
    }
    String expression = node.getExpression();
    if (expression == null) {
        expression = "";
    }
    mapperUI.getTabFolderEditors().getStyledTextHandler().setTextWithoutNotifyListeners(expression);
    mapperUI.getTabFolderEditors().getStyledTextHandler().getStyledText().setEnabled(true);
    mapperUI.getTabFolderEditors().getStyledTextHandler().getStyledText().setEditable(true);
    mapperUI.getTabFolderEditors().getStyledTextHandler().setSelectedNodePart(nodePart);
}
Also used : AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)

Example 10 with AbstractNode

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

the class XmlMapNodeDirectEditManager method initCellEditor.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.tools.DirectEditManager#initCellEditor()
     */
@Override
protected void initCellEditor() {
    DirectEditType directEditType = cellAndType.get(getCellEditor());
    if (model instanceof AbstractNode) {
        final AbstractNode abstractNode = (AbstractNode) model;
        if (directEditType != null) {
            switch(directEditType) {
                case EXPRESSION:
                    String expression = abstractNode.getExpression() == null ? "" : abstractNode.getExpression();
                    getCellEditor().setValue(expression);
                    Text text = ((ExtendedTextCellEditor) getCellEditor()).getTextControl();
                    text.selectAll();
                    break;
                case NODE_NAME:
                    String variable = abstractNode.getName();
                    if (variable == null) {
                        variable = "";
                    }
                    getCellEditor().setValue(variable);
                    final Text nametext = (Text) ((TextCellEditor) getCellEditor()).getControl();
                    nametext.selectAll();
                    if (model instanceof VarNode) {
                        nametext.addModifyListener(new ModifyListener() {

                            @Override
                            public void modifyText(ModifyEvent e) {
                                List<VarNode> children = new ArrayList<VarNode>();
                                children.addAll(((VarTable) abstractNode.eContainer()).getNodes());
                                children.remove(model);
                                String message = XmlMapUtil.isValidColumnName(children, ((Text) e.widget).getText());
                                if (message != null) {
                                    nametext.setBackground(ColorConstants.red);
                                } else {
                                    nametext.setBackground(ColorConstants.white);
                                }
                            }
                        });
                    }
                    break;
                case VAR_NODE_TYPE:
                    if (getCellEditor() instanceof ComboBoxCellEditor) {
                        CCombo combo = (CCombo) getCellEditor().getControl();
                        combo.setText(getTypeDisplayValue((VarNode) abstractNode));
                    }
                    break;
            }
        }
    } else if (model instanceof InputXmlTree) {
        InputXmlTree inputxmlTree = (InputXmlTree) model;
        if (directEditType != null) {
            switch(directEditType) {
                case EXPRESSION_FILTER:
                    String expressionFilter = inputxmlTree.getExpressionFilter();
                    if (expressionFilter == null) {
                        expressionFilter = "";
                    }
                    getCellEditor().setValue(expressionFilter);
                    Text textarea = ((ExtendedTextCellEditor) getCellEditor()).getTextControl();
                    textarea.selectAll();
                    break;
                case LOOKUP_MODEL:
                    if (getCellEditor() instanceof ComboBoxCellEditor) {
                        CCombo combo = (CCombo) getCellEditor().getControl();
                        combo.setText(getLookupDisplayName(inputxmlTree.getLookupMode()));
                    }
                    break;
                case MATCH_MODEL:
                    if (getCellEditor() instanceof ComboBoxCellEditor) {
                        CCombo combo = (CCombo) getCellEditor().getControl();
                        combo.setText(getMatchModelDisplayName(inputxmlTree.getMatchingMode()));
                    }
                    break;
                case JOIN_MODEL:
                    if (getCellEditor() instanceof ComboBoxCellEditor) {
                        CCombo combo = (CCombo) getCellEditor().getControl();
                        String join = "";
                        if (inputxmlTree.isInnerJoin()) {
                            join = joinModel[0];
                        } else {
                            join = joinModel[1];
                        }
                        combo.setText(join);
                    }
                    break;
                case PERSISTENT_MODEL:
                    if (getCellEditor() instanceof ComboBoxCellEditor) {
                        CCombo combo = (CCombo) getCellEditor().getControl();
                        combo.setText(String.valueOf(inputxmlTree.isPersistent()));
                    }
                    break;
            }
        }
    } else if (model instanceof OutputXmlTree) {
        OutputXmlTree outputTree = (OutputXmlTree) model;
        if (directEditType != null) {
            switch(directEditType) {
                case EXPRESSION_FILTER:
                    String expressionFilter = outputTree.getExpressionFilter();
                    if (expressionFilter == null) {
                        expressionFilter = "";
                    }
                    getCellEditor().setValue(expressionFilter);
                    Text textarea = ((ExtendedTextCellEditor) getCellEditor()).getTextControl();
                    textarea.selectAll();
                    break;
                case OUTPUT_REJECT:
                    if (getCellEditor() instanceof ComboBoxCellEditor) {
                        CCombo combo = (CCombo) getCellEditor().getControl();
                        combo.setText(String.valueOf(outputTree.isReject()));
                    }
                    break;
                case LOOK_UP_INNER_JOIN_REJECT:
                    if (getCellEditor() instanceof ComboBoxCellEditor) {
                        CCombo combo = (CCombo) getCellEditor().getControl();
                        combo.setText(String.valueOf(outputTree.isRejectInnerJoin()));
                    }
                    break;
                case ALL_IN_ONE:
                    if (getCellEditor() instanceof ComboBoxCellEditor) {
                        CCombo combo = (CCombo) getCellEditor().getControl();
                        combo.setText(String.valueOf(outputTree.isAllInOne()));
                    }
                    break;
                case ENABLE_EMPTY_ELEMENT:
                    if (getCellEditor() instanceof ComboBoxCellEditor) {
                        CCombo combo = (CCombo) getCellEditor().getControl();
                        combo.setText(String.valueOf(outputTree.isEnableEmptyElement()));
                    }
            }
        }
    } else if (model instanceof XmlMapData) {
        XmlMapData xmlMapData = (XmlMapData) model;
        if (directEditType != null) {
            switch(directEditType) {
                case SERACH:
                    Text text = (Text) getCellEditor().getControl();
                    text.selectAll();
                    break;
            }
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) ModifyListener(org.eclipse.swt.events.ModifyListener) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Text(org.eclipse.swt.widgets.Text) ExtendedTextCellEditor(org.talend.commons.ui.runtime.swt.tableviewer.celleditor.ExtendedTextCellEditor) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) ModifyEvent(org.eclipse.swt.events.ModifyEvent) DirectEditType(org.talend.designer.gefabstractmap.part.directedit.DirectEditType) CCombo(org.eclipse.swt.custom.CCombo) List(java.util.List) ArrayList(java.util.ArrayList) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Aggregations

AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)24 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)13 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)12 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)9 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)7 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)7 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)6 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)5 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)5 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)5 INodeConnection (org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection)5 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)5 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)5 ArrayList (java.util.ArrayList)4 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)4 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)4 VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)4 TableEntryLocation (org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation)4 List (java.util.List)3 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)3