use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree 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.OutputXmlTree in project tdi-studio-se by Talend.
the class MapperUI method prepareClosing.
public void prepareClosing(int response) {
List<IMetadataTable> newMetadatas = new ArrayList<IMetadataTable>();
EList<OutputXmlTree> outputTrees = null;
if (response == SWT.OK || response == SWT.APPLICATION_MODAL) {
// fix for bug TDI-18185
mapperManager.fireCurrentDirectEditApply();
// if press ok or apply , use copyOfMapData to check the metadata list
outputTrees = copyOfMapData.getOutputTrees();
} else {
// if press cancel , use the original mapData
outputTrees = ((XmlMapData) mapperComponent.getExternalEmfData()).getOutputTrees();
}
List<IMetadataTable> copyOfMetadata = new ArrayList<IMetadataTable>(mapperComponent.getMetadataList());
for (OutputXmlTree outputTree : outputTrees) {
IMetadataTable found = null;
for (IMetadataTable table : mapperComponent.getMetadataList()) {
if (outputTree.getName().equals(table.getTableName())) {
found = table;
}
}
if (found != null) {
newMetadatas.add(found);
} else {
// create a new metadata if needed
MetadataTable metadataTable = new MetadataTable();
metadataTable.setTableName(outputTree.getName());
mapperComponent.getProcess().addUniqueConnectionName(outputTree.getName());
List<IMetadataColumn> listColumns = new ArrayList<IMetadataColumn>();
for (OutputTreeNode treeNode : outputTree.getNodes()) {
MetadataColumn column = new MetadataColumn();
column.setLabel(treeNode.getName());
column.setKey(treeNode.isKey());
column.setTalendType(treeNode.getType());
column.setNullable(treeNode.isNullable());
column.setPattern(treeNode.getPattern());
listColumns.add(column);
}
metadataTable.setListColumns(listColumns);
newMetadatas.add(metadataTable);
}
}
mapperComponent.setMetadataList(newMetadatas);
copyOfMetadata.removeAll(newMetadatas);
List<IODataComponent> outputs = mapperComponent.getIODataComponents().getOuputs();
List<String> connectionNames = new ArrayList<String>();
for (IODataComponent output : outputs) {
connectionNames.add(output.getUniqueName());
}
for (IMetadataTable leftTree : copyOfMetadata) {
if (!connectionNames.contains(leftTree.getTableName())) {
mapperComponent.getProcess().removeUniqueConnectionName(leftTree.getTableName());
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.
the class ImportTreeFromXml method run.
@Override
public void run() {
List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
FileDialog f = new FileDialog(shell);
String file = f.open();
if (file != null) {
boolean clickOk = false;
TreeNode treeNodeRoot = null;
String detailedMessage = "";
try {
clickOk = TreeUtil.getFoxTreeNodesForXmlMap(file, shell, list);
if (!clickOk) {
return;
}
treeNodeRoot = XmlMapUtil.getTreeNodeRoot(parentNode);
XmlMapUtil.detachNodeConnections(treeNodeRoot, mapperManager.getExternalData(), true);
parentNode.getChildren().clear();
prepareEmfTreeNode(list, parentNode);
} catch (Exception e) {
ExceptionHandler.process(e);
StringBuffer sb = new StringBuffer();
sb.append(e.toString());
sb.append("\n");
if (e.getStackTrace() != null) {
for (StackTraceElement trace : e.getStackTrace()) {
sb.append(trace.toString());
sb.append("\n");
}
}
detailedMessage = sb.toString();
}
boolean childrenEmpty = false;
if (parentNode.getChildren().isEmpty()) {
childrenEmpty = true;
TreeNode rootNode = null;
if (input) {
rootNode = XmlmapFactory.eINSTANCE.createTreeNode();
} else {
rootNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
}
rootNode.setName("root");
rootNode.setNodeType(NodeType.ELEMENT);
rootNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
rootNode.setXpath(XmlMapUtil.getXPath(parentNode.getXpath(), "root", NodeType.ELEMENT));
parentNode.getChildren().add(rootNode);
}
// set a default loop
parentNode.getChildren().get(0).setLoop(true);
parentNode.getChildren().get(0).setMain(true);
if (childrenEmpty || (detailedMessage != null && !"".equals(detailedMessage))) {
showError(detailedMessage);
}
if (parentNode.eContainer() instanceof InputXmlTree) {
XmlMapConnectionBuilder connectionBuilder = new XmlMapConnectionBuilder();
connectionBuilder.setCheckRootNodePrefix(true);
connectionBuilder.rebuildLinks(parentNode, mapperManager.getExternalData());
mapperManager.refreshTreeSchemaEditor((InputXmlTree) parentNode.eContainer());
// mapperManager.inputTreeSchemaBeanListModified();
} else if (parentNode.eContainer() instanceof OutputXmlTree) {
mapperManager.refreshTreeSchemaEditor((OutputXmlTree) parentNode.eContainer());
// mapperManager.outputTreeSchemaBeanListModified();
}
if (treeNodeRoot != null && treeNodeRoot.eContainer() instanceof AbstractInOutTree) {
mapperManager.getProblemsAnalyser().checkProblems((AbstractInOutTree) treeNodeRoot.eContainer());
mapperManager.getMapperUI().updateStatusBar();
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.
the class SetLoopAction method addInputLoopNodesToOutput.
private void addInputLoopNodesToOutput(TreeNode loopNode, List<Connection> connections) {
for (Connection connection : connections) {
if (connection.getTarget() instanceof OutputTreeNode) {
OutputTreeNode loopParentNode = (OutputTreeNode) XmlMapUtil.getLoopParentNode((OutputTreeNode) connection.getTarget());
if (loopParentNode != null) {
if (loopParentNode.getInputLoopNodesTable() != null) {
loopParentNode.getInputLoopNodesTable().getInputloopnodes().add(loopNode);
}
} else {
OutputXmlTree abstractInOutTree = (OutputXmlTree) XmlMapUtil.getAbstractInOutTree((OutputTreeNode) connection.getTarget());
if (!XmlMapUtil.hasDocument(abstractInOutTree)) {
EList<InputLoopNodesTable> inputLoopNodesTables = abstractInOutTree.getInputLoopNodesTables();
if (inputLoopNodesTables.size() == 1) {
InputLoopNodesTable inputLoopNodesTable = inputLoopNodesTables.get(0);
inputLoopNodesTable.getInputloopnodes().add(loopNode);
}
}
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.
the class InsertNewColumnCommand method execute.
@Override
public void execute() {
if (rq == null || objects.getToTransfer() == null || targetEditPart == null || dropType == null) {
return;
}
Object targetModel = targetEditPart.getModel();
for (Object obj : objects.getToTransfer()) {
AbstractNode createdNode = rq.getNewObject();
// INPUT => OUTPUT INSERT
if (objects.getType() == TransferdType.INPUT) {
TreeNodeEditPart part = (TreeNodeEditPart) obj;
TreeNode sourceNode = (TreeNode) part.getModel();
String expression = XmlMapUtil.convertToExpression(sourceNode.getXpath());
switch(dropType) {
case DROP_INSERT_OUTPUT:
int index = -1;
OutputXmlTree outputTree = null;
if (targetModel instanceof OutputTreeNode) {
OutputTreeNode targetNode = (OutputTreeNode) targetModel;
if (targetNode.eContainer() instanceof OutputXmlTree) {
outputTree = (OutputXmlTree) targetNode.eContainer();
index = outputTree.getNodes().indexOf(targetNode);
}
} else if (targetModel instanceof OutputXmlTree) {
outputTree = (OutputXmlTree) targetModel;
}
if (outputTree != null) {
boolean fillNode = fillTreeNode(outputTree.getNodes(), sourceNode, outputTree.getName(), expression, (OutputTreeNode) createdNode);
if (!fillNode) {
return;
}
if (index != -1) {
outputTree.getNodes().add(index, (OutputTreeNode) createdNode);
} else {
outputTree.getNodes().add((OutputTreeNode) createdNode);
}
createConnection(sourceNode, createdNode);
AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(sourceNode);
createOutputMetadataColumn(abstractTree.getName(), outputTree.getName(), sourceNode, createdNode.getName(), index);
}
break;
case DROP_INSERT_VAR:
VarNode targetVar = (VarNode) targetModel;
VarNode varNode = (VarNode) createdNode;
if (targetVar.eContainer() instanceof VarTable) {
VarTable varTable = (VarTable) targetVar.eContainer();
String validSourceName = validSourceNodeName(varTable.getNodes(), sourceNode);
String name = getUniqueTableEntry(varTable.getNodes(), validSourceName);
varNode.setName(name);
varNode.setType(sourceNode.getType());
varNode.setExpression(expression);
varTable.getNodes().add(varTable.getNodes().indexOf(targetVar), varNode);
createConnection(sourceNode, createdNode);
}
break;
case DROP_INSERT_INPUT:
if (targetModel instanceof InputXmlTree) {
InputXmlTree inputTree = (InputXmlTree) targetModel;
boolean fillNode = fillTreeNode(inputTree.getNodes(), sourceNode, inputTree.getName(), expression, (TreeNode) createdNode);
if (!fillNode) {
return;
}
inputTree.getNodes().add((TreeNode) createdNode);
createLookupConnection(sourceNode, (TreeNode) createdNode);
AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(sourceNode);
createInputMetadataColumn(abstractTree.getName(), inputTree.getName(), sourceNode, createdNode.getName(), -1);
}
default:
break;
}
} else // VAR => OUTPUT INSERT
if (objects.getType() == TransferdType.VAR) {
VarNodeEditPart part = (VarNodeEditPart) obj;
VarNode sourceNode = (VarNode) part.getModel();
//$NON-NLS-1$
String tableName = "Var";
if (sourceNode.eContainer() instanceof VarTable) {
tableName = ((VarTable) sourceNode.eContainer()).getName();
}
//$NON-NLS-1$
String expression = tableName + "." + sourceNode.getName();
if (dropType == DropType.DROP_INSERT_OUTPUT) {
int index = -1;
OutputXmlTree outputTree = null;
if (targetModel instanceof OutputTreeNode) {
OutputTreeNode targetNode = (OutputTreeNode) targetModel;
if (targetNode.eContainer() instanceof OutputXmlTree) {
outputTree = (OutputXmlTree) targetNode.eContainer();
index = outputTree.getNodes().indexOf(targetNode);
}
} else if (targetModel instanceof OutputXmlTree) {
outputTree = (OutputXmlTree) targetModel;
}
if (outputTree != null) {
OutputTreeNode outputNode = (OutputTreeNode) createdNode;
String name = getUniqueTableEntry(outputTree.getNodes(), sourceNode.getName());
outputNode.setName(name);
outputNode.setType(sourceNode.getType());
outputNode.setExpression(expression);
outputNode.setXpath(XmlMapUtil.getXPath(outputTree.getName(), outputNode.getName(), outputNode.getNodeType()));
if (index != -1) {
outputTree.getNodes().add(index, (OutputTreeNode) createdNode);
} else {
outputTree.getNodes().add((OutputTreeNode) createdNode);
}
createConnection(sourceNode, createdNode);
createOutputMetadataColumn(null, outputTree.getName(), sourceNode, createdNode.getName(), index);
// List<IMetadataTable> metadataTargets = manager.getMapperComponent().getMetadataList();
// IMetadataTable metadataTarget = null;
// if (metadataTargets != null) {
// for (IMetadataTable target : metadataTargets) {
// if (target.getTableName().equals(outputTree.getName())) {
// metadataTarget = target;
// }
// }
// if (metadataTarget != null) {
// IMetadataColumn createNewColumn = new MetadataColumn();
// createNewColumn.setLabel(outputNode.getName());
// createNewColumn.setTalendType(outputNode.getType());
// createNewColumn.setNullable(true);
// metadataTarget.getListColumns().add(createNewColumn);
// }
// }
}
}
}
}
switch(dropType) {
case DROP_INSERT_OUTPUT:
manager.getMapperUI().getTabFolderEditors().getOutputMetaEditorView().getTableViewerCreator().refresh();
case DROP_INSERT_INPUT:
manager.getMapperUI().getTabFolderEditors().getOutputMetaEditorView().getTableViewerCreator().refresh();
}
}
Aggregations