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;
}
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("");
}
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);
// }
}
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);
}
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;
}
}
}
}
Aggregations