use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode in project tdi-studio-se by Talend.
the class XmlMapUtil method detachConnectionsTarget.
public static void detachConnectionsTarget(AbstractNode treeNode, XmlMapData mapData, boolean detachChildren) {
for (Connection connection : treeNode.getOutgoingConnections()) {
AbstractNode target = connection.getTarget();
if (target.getIncomingConnections().contains(connection)) {
target.getIncomingConnections().remove(connection);
mapData.getConnections().remove(connection);
}
}
treeNode.getOutgoingConnections().clear();
// TreeNode detach children's connections
if (treeNode instanceof TreeNode) {
TreeNode inputTreeNode = (TreeNode) treeNode;
if (detachChildren && !inputTreeNode.getChildren().isEmpty()) {
for (int i = 0; i < inputTreeNode.getChildren().size(); i++) {
TreeNode child = inputTreeNode.getChildren().get(i);
detachConnectionsTarget(child, mapData);
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode in project tdi-studio-se by Talend.
the class XmlMapUtil method updateTargetExpression.
public static void updateTargetExpression(AbstractNode renamedNode, String oldExpression, String newExpression, XmlMapExpressionManager expressionManager) {
TableEntryLocation previousLocation = expressionManager.parseTableEntryLocation(oldExpression).get(0);
TableEntryLocation newLocation = expressionManager.parseTableEntryLocation(newExpression).get(0);
List<INodeConnection> connections = new ArrayList<INodeConnection>();
connections.addAll(renamedNode.getOutgoingConnections());
if (renamedNode instanceof TreeNode) {
connections.addAll(((TreeNode) renamedNode).getLookupOutgoingConnections());
}
for (INodeConnection connection : connections) {
AbstractNode target = connection.getTarget();
List<TableEntryLocation> targetLocaitons = expressionManager.parseTableEntryLocation(target.getExpression());
for (TableEntryLocation current : targetLocaitons) {
if (current.equals(previousLocation)) {
String replaced = expressionManager.replaceExpression(target.getExpression(), current, newLocation);
target.setExpression(replaced);
}
}
}
for (FilterConnection connection : renamedNode.getFilterOutGoingConnections()) {
AbstractInOutTree target = connection.getTarget();
List<TableEntryLocation> targetLocaitons = expressionManager.parseTableEntryLocation(target.getExpressionFilter());
for (TableEntryLocation current : targetLocaitons) {
if (current.equals(previousLocation)) {
String replaced = expressionManager.replaceExpression(target.getExpressionFilter(), current, newLocation);
target.setExpressionFilter(replaced);
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode in project tdi-studio-se by Talend.
the class XmlMapNodeDirectEditManager method createCellEditorOn.
@Override
protected CellEditor createCellEditorOn(Composite composite) {
Composite parent = (Composite) source.getViewer().getControl();
CellEditor cellEditor = null;
Figure figure = null;
if (this.locator instanceof XmlMapNodeCellEditorLocator) {
XmlMapNodeCellEditorLocator lo = (XmlMapNodeCellEditorLocator) locator;
figure = lo.getFigure();
}
if (figure instanceof IComboCell) {
try {
// tree setting can be edit or not
if (source instanceof InputXmlTreeEditPart) {
InputXmlTree inputTree = (InputXmlTree) ((InputXmlTreeEditPart) source).getModel();
if (DirectEditType.JOIN_MODEL.equals(((IComboCell) figure).getDirectEditType())) {
if (!XmlMapUtil.hasAtLeastOneHashKey(inputTree)) {
return null;
}
}
if (DirectEditType.PERSISTENT_MODEL.equals(((IComboCell) figure).getDirectEditType())) {
if (LOOKUP_MODE.CACHE_OR_RELOAD.toString().equals(inputTree.getLookupMode())) {
return null;
}
}
}
if (source instanceof OutputXmlTreeEditPart) {
OutputXmlTree outputTree = (OutputXmlTree) ((OutputXmlTreeEditPart) source).getModel();
if (DirectEditType.ALL_IN_ONE.equals(((IComboCell) figure).getDirectEditType())) {
if (!XmlMapUtil.hasDocument(outputTree)) {
return null;
}
boolean hasAggregate = false;
for (int i = 0; i < outputTree.getNodes().size(); i++) {
OutputTreeNode outputTreeNode = outputTree.getNodes().get(i);
hasAggregate = hasAggreage(outputTreeNode);
if (hasAggregate) {
break;
}
}
if (hasAggregate) {
return null;
}
} else if (DirectEditType.ENABLE_EMPTY_ELEMENT.equals(((IComboCell) figure).getDirectEditType())) {
if (!XmlMapUtil.hasDocument(outputTree)) {
return null;
}
}
}
cellEditor = new XmlComboCellEditor();
cellEditor.create(composite);
((XmlComboCellEditor) cellEditor).setItems(getComboItemsByType(((IComboCell) figure).getDirectEditType()));
cellAndType.put(cellEditor, ((IComboCell) figure).getDirectEditType());
} catch (Exception e) {
return null;
}
} else if (figure instanceof ITextCell) {
// this one is created for direct doc child name , no use anymore...
cellEditor = new TextCellEditor(composite);
cellAndType.put(cellEditor, ((ITextCell) figure).getDirectEditType());
// for the search
XmlMapNodeCellEditorLocator lo = (XmlMapNodeCellEditorLocator) locator;
if (lo.getFigure() != null && lo.getFigure() instanceof VarNodeTextLabel) {
figure = (VarNodeTextLabel) lo.getFigure();
if (figure.getParent() != null && figure.getParent() instanceof XmlMapSearchZoneToolBar) {
XmlMapSearchZoneToolBar searchZone = (XmlMapSearchZoneToolBar) figure.getParent();
if (searchZone.getSearchMaps().size() > 0) {
searchZone.getSearchZoneMapper().hightlightAll(searchZone.getSearchMaps(), false);
searchZone.getSearchZoneMapper().setHightlightAll(false);
searchZone.getSearchMaps().clear();
searchZone.hightLightAll.setSelected(false);
}
}
}
} else if (figure instanceof IExpressionBuilderCell && model instanceof AbstractNode) {
IService expressionBuilderDialogService = GlobalServiceRegister.getDefault().getService(IExpressionBuilderDialogService.class);
CellEditorDialogBehavior behavior = new CellEditorDialogBehavior();
cellEditor = new ExpressionCellEditor(composite, behavior, source, DirectEditType.EXPRESSION);
((ExpressionCellEditor) cellEditor).setOwnerId(((AbstractNode) model).getExpression());
IExpressionBuilderDialogController dialog = ((IExpressionBuilderDialogService) expressionBuilderDialogService).getExpressionBuilderInstance(parent, (ExpressionCellEditor) cellEditor, null);
cellAndType.put(cellEditor, DirectEditType.EXPRESSION);
behavior.setCellEditorDialog(dialog);
} else if (figure instanceof ITextAreaCell) {
TextAreaBehavior behavior = new TextAreaBehavior();
cellEditor = new ExpressionCellEditor(composite, behavior, source, DirectEditType.EXPRESSION_FILTER);
cellAndType.put(cellEditor, DirectEditType.EXPRESSION_FILTER);
} else if (figure instanceof IExpressionBuilderCell && model instanceof InputXmlTree) {
IService expressionBuilderDialogService = GlobalServiceRegister.getDefault().getService(IExpressionBuilderDialogService.class);
CellEditorDialogBehavior behavior = new CellEditorDialogBehavior();
cellEditor = new ExpressionCellEditor(composite, behavior, source, DirectEditType.EXPRESSION);
((ExpressionCellEditor) cellEditor).setOwnerId(((InputXmlTree) model).getLookupMode());
IExpressionBuilderDialogController dialog = ((IExpressionBuilderDialogService) expressionBuilderDialogService).getExpressionBuilderInstance(parent, (ExpressionCellEditor) cellEditor, null);
cellAndType.put(cellEditor, DirectEditType.EXPRESSION);
behavior.setCellEditorDialog(dialog);
}
// }
return cellEditor;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode in project tdi-studio-se by Talend.
the class XmlDirectEditPolicy method getDirectEditCommand.
@Override
protected Command getDirectEditCommand(DirectEditRequest request) {
Command command = null;
CellEditor editor = request.getCellEditor();
Object directEditFeature = request.getDirectEditFeature();
if (directEditFeature instanceof DirectEditType) {
DirectEditType type = (DirectEditType) directEditFeature;
if (getHost().getModel() instanceof AbstractNode) {
AbstractNode model = (AbstractNode) getHost().getModel();
switch(type) {
case EXPRESSION:
case NODE_NAME:
command = new DirectEditCommand(getHost(), model, type, request.getCellEditor().getValue());
break;
case VAR_NODE_TYPE:
if (editor instanceof ComboBoxCellEditor) {
ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
int selectIndex = (Integer) combo.getValue();
command = new DirectEditCommand(getHost(), model, type, combo.getItems()[selectIndex]);
}
break;
case LOOKUP_MODEL:
case MATCH_MODEL:
case JOIN_MODEL:
case PERSISTENT_MODEL:
case OUTPUT_REJECT:
case LOOK_UP_INNER_JOIN_REJECT:
if (editor instanceof ComboBoxCellEditor) {
ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
int selectIndex = (Integer) combo.getValue();
command = new TreeSettingDirectEditCommand(model, type, combo.getItems()[selectIndex]);
}
break;
case EXPRESSION_FILTER:
if (editor instanceof TextCellEditor) {
command = new TreeSettingDirectEditCommand(model, type, request.getCellEditor().getValue());
}
default:
break;
}
} else {
switch(type) {
case LOOKUP_MODEL:
case MATCH_MODEL:
case JOIN_MODEL:
case PERSISTENT_MODEL:
case OUTPUT_REJECT:
case LOOK_UP_INNER_JOIN_REJECT:
case ALL_IN_ONE:
case ENABLE_EMPTY_ELEMENT:
if ((editor instanceof ComboBoxCellEditor)) {
ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
int selectIndex = (Integer) combo.getValue();
command = new TreeSettingDirectEditCommand(getHost().getModel(), type, combo.getItems()[selectIndex]);
}
break;
case EXPRESSION_FILTER:
command = new TreeSettingDirectEditCommand(getHost().getModel(), type, request.getCellEditor().getValue());
}
}
}
return command;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode in project tdi-studio-se by Talend.
the class DirectEditCommand method execute.
@Override
public void execute() {
try {
if (model != null) {
if (DirectEditType.EXPRESSION.equals(type)) {
List<TableEntryLocation> matchedLocations = expressionManager.parseTableEntryLocation((String) newValue);
EList<? extends INodeConnection> connections = null;
if (model instanceof OutputTreeNode || model instanceof VarNode) {
connections = model.getIncomingConnections();
} else if (model instanceof TreeNode) {
connections = ((TreeNode) model).getLookupIncomingConnections();
}
List usefullConnections = new ArrayList();
mapperData = XmlMapUtil.getXmlMapData(model);
if (!matchedLocations.isEmpty()) {
for (int i = 0; i < matchedLocations.size(); i++) {
TableEntryLocation currentLocation = matchedLocations.get(i);
boolean found = false;
for (INodeConnection conn : connections) {
TableEntryLocation sourceLocation = null;
if (conn.getSource() instanceof TreeNode) {
sourceLocation = expressionManager.parseTableEntryLocation(XmlMapUtil.convertToExpression(((TreeNode) conn.getSource()).getXpath())).get(0);
} else if (conn.getSource() instanceof VarNode) {
VarNode varNode = (VarNode) conn.getSource();
sourceLocation = new TableEntryLocation(((VarTable) varNode.eContainer()).getName(), varNode.getName());
}
if (currentLocation.equals(sourceLocation)) {
found = true;
usefullConnections.add(conn);
break;
}
}
if (!found) {
if (mapperData != null) {
String convertToXpath = XmlMapUtil.convertToXpath(currentLocation.toString());
boolean findFromVar = false;
if (model instanceof OutputTreeNode) {
findFromVar = true;
}
AbstractNode sourceNode = findConnectionSource(mapperData, currentLocation, XmlMapUtil.getXPathLength(convertToXpath), findFromVar);
if (sourceNode != null) {
INodeConnection connection = null;
if (model instanceof OutputTreeNode || model instanceof VarNode) {
connection = XmlmapFactory.eINSTANCE.createConnection();
sourceNode.getOutgoingConnections().add((Connection) connection);
model.getIncomingConnections().add((Connection) connection);
} else if (model instanceof TreeNode && sourceNode instanceof TreeNode) {
TreeNode source = (TreeNode) sourceNode;
connection = XmlmapFactory.eINSTANCE.createLookupConnection();
source.getLookupOutgoingConnections().add((LookupConnection) connection);
((TreeNode) model).getLookupIncomingConnections().add((LookupConnection) connection);
}
//
// if (model instanceof OutputTreeNode && sourceNode instanceof TreeNode) {
// createInputLoopTable((TreeNode) sourceNode, (OutputTreeNode) model);
// }
connection.setSource(sourceNode);
connection.setTarget(model);
mapperData.getConnections().add(connection);
usefullConnections.add(connection);
}
}
}
}
} else {
if (!connections.isEmpty()) {
if (model instanceof OutputTreeNode || model instanceof VarNode) {
XmlMapUtil.detachConnectionsSouce(model, mapperData, false);
model.getIncomingConnections().clear();
} else if (model instanceof TreeNode) {
XmlMapUtil.detachLookupSource((TreeNode) model, mapperData);
((TreeNode) model).getLookupIncomingConnections().clear();
}
}
}
List<INodeConnection> copyOfConnections = new ArrayList<INodeConnection>(connections);
copyOfConnections.removeAll(usefullConnections);
if (model instanceof OutputTreeNode || model instanceof VarNode) {
for (INodeConnection connection : copyOfConnections) {
if (connection.getSource() != null) {
if (connection.getSource().getOutgoingConnections().contains(connection)) {
connection.getSource().getOutgoingConnections().remove(connection);
mapperData.getConnections().remove(connection);
}
}
}
model.getIncomingConnections().removeAll(copyOfConnections);
} else if (model instanceof TreeNode) {
for (INodeConnection connection : copyOfConnections) {
if (connection.getSource() != null) {
if (((TreeNode) connection.getSource()).getLookupOutgoingConnections().contains(connection)) {
((TreeNode) connection.getSource()).getLookupOutgoingConnections().remove(connection);
mapperData.getConnections().remove(connection);
}
}
}
((TreeNode) model).getLookupIncomingConnections().removeAll(copyOfConnections);
}
if (model instanceof OutputTreeNode) {
OutputTreeNode outModel = (OutputTreeNode) model;
if (NodeType.NAME_SPACE.equals(outModel.getNodeType()) && outModel.getExpression() != null && !"".equals(model.getExpression())) {
outModel.setDefaultValue("");
}
}
model.setExpression((String) newValue);
} else if (DirectEditType.VAR_NODE_TYPE.equals(type)) {
VarNode varModel = (VarNode) model;
JavaType javaTypeFromLabel = JavaTypesManager.getJavaTypeFromLabel((String) newValue);
if (javaTypeFromLabel == null) {
javaTypeFromLabel = JavaTypesManager.getDefaultJavaType();
}
varModel.setType(javaTypeFromLabel.getId());
} else if (DirectEditType.NODE_NAME.equals(type)) {
if (model instanceof VarNode) {
List<VarNode> children = new ArrayList<VarNode>();
children.addAll(((VarTable) model.eContainer()).getNodes());
children.remove(model);
String message = XmlMapUtil.isValidColumnName(children, (String) newValue);
if (message != null) {
MessageDialog.openError(null, "Error", message);
return;
}
String oldName = model.getName();
String oldExpression = XmlMapUtil.VAR_TABLE_NAME + XmlMapUtil.EXPRESSION_SEPARATOR + oldName;
model.setName((String) newValue);
String newExpression = XmlMapUtil.VAR_TABLE_NAME + XmlMapUtil.EXPRESSION_SEPARATOR + model.getName();
XmlMapUtil.updateTargetExpression(model, oldExpression, newExpression, expressionManager);
} else if (model instanceof GlobalMapNode) {
model.setName((String) newValue);
}
}
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
}
Aggregations