use of org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart in project tdi-studio-se by Talend.
the class XmlDragSourceListener method getTemplate.
/**
*
* DOC talend Comment method "getTemplate".
*
* @param event
* @return the validate drag able node list
*/
@Override
protected Object getTemplate(DragSourceEvent event) {
final RootEditPart rootEditPart = getViewer().getRootEditPart();
if (rootEditPart instanceof AbstractGraphicalEditPart) {
AbstractGraphicalEditPart graphicPart = (AbstractGraphicalEditPart) rootEditPart;
final IFigure figure = graphicPart.getFigure();
final IFigure findFigureAt = figure.findFigureAt(new Point(event.x, event.y));
if (findFigureAt instanceof ISash) {
return findFigureAt;
}
}
List<EditPart> filtedSelection = new ArrayList<EditPart>();
for (Object part : getViewer().getSelectedEditParts()) {
if (part instanceof TreeNodeEditPart || part instanceof VarNodeEditPart) {
filtedSelection.add((EditPart) part);
}
}
if (filtedSelection == null || filtedSelection.isEmpty()) {
return null;
}
List toTransfer = new ArrayList();
TransferdType type = null;
List<TableEntityPart> partList = new ArrayList<TableEntityPart>();
EditPart lastSelection = filtedSelection.get(filtedSelection.size() - 1);
if (lastSelection instanceof TreeNodeEditPart && !(lastSelection instanceof OutputTreeNodeEditPart)) {
type = TransferdType.INPUT;
} else if (lastSelection instanceof VarNodeEditPart) {
type = TransferdType.VAR;
}
if (type != null) {
if (filtedSelection.size() > 1) {
partList.addAll(lastSelection.getParent().getChildren());
Map<EditPart, Integer> partAndIndex = new HashMap<EditPart, Integer>();
if (type == TransferdType.INPUT) {
for (EditPart treePart : filtedSelection) {
if (!XmlMapUtil.isDragable((TreeNode) treePart.getModel())) {
return null;
}
}
MapperTablePart abstractInOutTreePart = MapperUtils.getMapperTablePart((TableEntityPart) lastSelection);
if (abstractInOutTreePart != null) {
partList = MapperUtils.getFlatChildrenPartList(abstractInOutTreePart);
}
} else {
partList.addAll(lastSelection.getParent().getChildren());
}
for (EditPart selected : filtedSelection) {
int indexOf = partList.indexOf(selected);
if (indexOf != -1) {
partAndIndex.put(selected, indexOf);
int index = 0;
for (int i = 0; i < toTransfer.size(); i++) {
if (indexOf > partAndIndex.get(toTransfer.get(i))) {
index = i + 1;
}
}
toTransfer.add(index, selected);
}
}
} else {
if (lastSelection.getModel() instanceof TreeNode && !XmlMapUtil.isDragable((TreeNode) lastSelection.getModel())) {
return null;
}
toTransfer.add(lastSelection);
}
return new TransferedObject(toTransfer, type);
}
return null;
}
use of org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart 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();
}
use of org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart in project tdi-studio-se by Talend.
the class XmlMapEditor method buildContextMenu.
@Override
public void buildContextMenu(IMenuManager menu) {
// context menu should only display in the document tree
List selectedEditParts = getGraphicalViewer().getSelectedEditParts();
if (selectedEditParts != null && !selectedEditParts.isEmpty()) {
List output = new ArrayList();
List input = new ArrayList();
for (Object selected : selectedEditParts) {
if (selected instanceof OutputTreeNodeEditPart) {
output.add(selected);
} else if (selected instanceof TreeNodeEditPart) {
input.add(selected);
}
}
if (!output.isEmpty() && !input.isEmpty()) {
return;
}
boolean isInput = !input.isEmpty();
ImportTreeFromXml importAction = (ImportTreeFromXml) getActionRegistry().getAction(ImportTreeFromXml.ID);
importAction.update(selectedEditParts);
importAction.setInput(isInput);
if (importAction.isEnabled()) {
menu.add(importAction);
}
CreateElementAction createElement = (CreateElementAction) getActionRegistry().getAction(CreateElementAction.ID);
createElement.update(selectedEditParts);
createElement.setInput(isInput);
if (createElement.isEnabled()) {
menu.add(createElement);
}
CreateAttributeAction createAttribute = (CreateAttributeAction) getActionRegistry().getAction(CreateAttributeAction.ID);
createAttribute.update(selectedEditParts);
createAttribute.setInput(isInput);
if (createAttribute.isEnabled()) {
menu.add(createAttribute);
}
CreateNameSpaceAction createNameSpace = (CreateNameSpaceAction) getActionRegistry().getAction(CreateNameSpaceAction.ID);
createNameSpace.update(selectedEditParts);
createNameSpace.setInput(isInput);
if (createNameSpace.isEnabled()) {
menu.add(createNameSpace);
}
FixValueAction fixValueAction = (FixValueAction) getActionRegistry().getAction(FixValueAction.ID);
fixValueAction.update(selectedEditParts);
if (fixValueAction.isEnabled()) {
menu.add(fixValueAction);
}
AddChoiceAction addChoice = (AddChoiceAction) getActionRegistry().getAction(AddChoiceAction.ID);
addChoice.update(selectedEditParts);
addChoice.setInput(isInput);
if (addChoice.isEnabled()) {
menu.add(addChoice);
}
SetSubstitutionAction setSubs = (SetSubstitutionAction) getActionRegistry().getAction(SetSubstitutionAction.ID);
setSubs.update(selectedEditParts);
setSubs.setInput(isInput);
if (setSubs.isEnabled()) {
menu.add(setSubs);
}
SetLoopAction loopAction = (SetLoopAction) getActionRegistry().getAction(SetLoopAction.ID);
loopAction.update(selectedEditParts);
loopAction.setInput(isInput);
if (loopAction.isEnabled()) {
menu.add(loopAction);
}
SetLoopOptional loopOptinalAction = (SetLoopOptional) getActionRegistry().getAction(SetLoopOptional.ID);
loopOptinalAction.update(selectedEditParts);
if (loopOptinalAction.isEnabled()) {
menu.add(loopOptinalAction);
}
SetGroupAction grouptAction = (SetGroupAction) getActionRegistry().getAction(SetGroupAction.ID);
grouptAction.update(selectedEditParts);
if (grouptAction.isEnabled()) {
menu.add(grouptAction);
}
ImportTreeFromRepository importFromRepository = (ImportTreeFromRepository) getActionRegistry().getAction(ImportTreeFromRepository.ID);
importFromRepository.update(selectedEditParts);
importFromRepository.setInput(isInput);
if (importFromRepository.isEnabled()) {
menu.add(importFromRepository);
}
SetAggregateAction aggreateAction = (SetAggregateAction) getActionRegistry().getAction(SetAggregateAction.ID);
aggreateAction.update(selectedEditParts);
if (aggreateAction.isEnabled()) {
menu.add(aggreateAction);
}
RenameTreeNodeAction renameTreeNodeAction = (RenameTreeNodeAction) getActionRegistry().getAction(RenameTreeNodeAction.ID);
renameTreeNodeAction.update(selectedEditParts);
if (renameTreeNodeAction.isEnabled()) {
menu.add(renameTreeNodeAction);
}
DeleteTreeNodeAction action = (DeleteTreeNodeAction) getActionRegistry().getAction(DeleteTreeNodeAction.ID);
action.update(selectedEditParts);
action.setInput(isInput);
if (action.isEnabled()) {
menu.add(action);
}
}
}
use of org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart in project tdi-studio-se by Talend.
the class SearchZoneMapper method moveScrollBarZoneAtSelectedTableItem.
public void moveScrollBarZoneAtSelectedTableItem(Figure entry) {
if (entry != null) {
Rectangle bounds = entry.getBounds();
int selection = bounds.y - 100;
if (entry instanceof XmlmapTreeNodeFigure) {
XmlmapTreeNodeFigure xmlMapTreeNodeFigure = (XmlmapTreeNodeFigure) entry;
TreeNode treeNode = xmlMapTreeNodeFigure.getTreeNode();
if (treeNode != null) {
for (Adapter adapter : treeNode.eAdapters()) {
TreeNodeEditPart part = (TreeNodeEditPart) adapter;
XmlMapDataEditPart xmlMapDataEditPart = part.getMapDataEditPart();
if (adapter instanceof OutputTreeNodeEditPart) {
Viewport viewport = xmlMapDataEditPart.getOutputScroll().getViewport();
viewport.setViewLocation(viewport.getViewLocation().translate(bounds.x, selection));
} else if (adapter instanceof TreeNodeEditPart) {
Viewport viewport = xmlMapDataEditPart.getInputScroll().getViewport();
viewport.setViewLocation(viewport.getViewLocation().translate(bounds.x, selection));
}
}
}
} else if (entry instanceof VarNodeFigure) {
VarNodeFigure varNodeFigure = (VarNodeFigure) entry;
VarNode varNode = varNodeFigure.getVarNode();
if (varNode != null) {
for (Adapter adapter : varNode.eAdapters()) {
VarNodeEditPart part = (VarNodeEditPart) adapter;
XmlMapDataEditPart xmlMapDataEditPart = part.getMapDataEditPart();
Viewport viewport = xmlMapDataEditPart.getVarScroll().getViewport();
viewport.setViewLocation(viewport.getViewLocation().translate(bounds.x, selection));
}
}
}
}
}
use of org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart in project tdi-studio-se by Talend.
the class CreateNodeAndConnectionCommand method doUpdate.
// private void createInputLoopTable(TreeNode sourceNode, OutputTreeNode targetOutputNode) {
// EditPartViewer viewer = targetEditPart.getViewer();
// if (viewer instanceof XmlMapGraphicViewer) {
// InputLoopTableUtil.addSourceLoopToInputLoopTable(sourceNode, targetOutputNode, ((XmlMapGraphicViewer) viewer)
// .getMapperManager().getMainInputTree());
// }
// }
private void doUpdate(AbstractNode sourceNode) {
if (targetEditPart instanceof OutputTreeNodeEditPart) {
OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) targetEditPart).getModel();
String expression = targetOutputNode.getExpression();
if (sourceNode instanceof TreeNode) {
if (expression == null) {
expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
} else {
expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
}
} else if (sourceNode instanceof VarNode) {
String tableName = "Var";
if (sourceNode.eContainer() instanceof VarTable) {
tableName = ((VarTable) sourceNode.eContainer()).getName();
}
if (expression == null) {
expression = tableName + "." + sourceNode.getName();
} else {
expression = expression + " " + tableName + "." + sourceNode.getName();
}
}
// if (sourceNode instanceof TreeNode) {
// createInputLoopTable((TreeNode) sourceNode, targetOutputNode);
// }
targetOutputNode.setExpression(expression);
Connection conn = XmlmapFactory.eINSTANCE.createConnection();
conn.setSource(sourceNode);
conn.setTarget(targetOutputNode);
targetOutputNode.getIncomingConnections().add(conn);
sourceNode.getOutgoingConnections().add(conn);
if (xmlMapData != null) {
xmlMapData.getConnections().add(conn);
}
} else if (targetEditPart instanceof TreeNodeEditPart) {
/* for lookup connections */
if (sourceNode instanceof TreeNode) {
TreeNode targetTreeNode = (TreeNode) targetEditPart.getModel();
String expression = targetTreeNode.getExpression();
if (expression == null) {
expression = "";
}
expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
targetTreeNode.setExpression(expression);
LookupConnection conn = XmlmapFactory.eINSTANCE.createLookupConnection();
conn.setSource(sourceNode);
conn.setTarget(targetTreeNode);
targetTreeNode.getLookupIncomingConnections().add(conn);
((TreeNode) sourceNode).getLookupOutgoingConnections().add(conn);
if (xmlMapData != null) {
xmlMapData.getConnections().add(conn);
}
}
} else if (targetEditPart instanceof VarNodeEditPart) {
/* for varTable drag drop */
if (sourceNode instanceof TreeNode) {
VarNodeEditPart targetPart = (VarNodeEditPart) targetEditPart;
VarNode targetNode = (VarNode) targetPart.getModel();
String expression = targetNode.getExpression();
if (expression == null) {
expression = "";
}
expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
if (targetNode.getName() == null || "".equals(targetNode.getName())) {
String findUniqueVarColumnName = XmlMapUtil.findUniqueVarColumnName(sourceNode.getName(), xmlMapData.getVarTables().get(0));
targetNode.setName(findUniqueVarColumnName);
}
targetNode.setExpression(expression.trim());
targetNode.setType(sourceNode.getType());
Connection conn = XmlmapFactory.eINSTANCE.createConnection();
conn.setSource(sourceNode);
conn.setTarget(targetNode);
targetNode.getIncomingConnections().add(conn);
sourceNode.getOutgoingConnections().add(conn);
if (xmlMapData != null) {
xmlMapData.getConnections().add(conn);
}
}
} else if (targetEditPart instanceof InputXmlTreeEditPart || targetEditPart instanceof OutputXmlTreeEditPart) {
AbstractInOutTree treeModel = (AbstractInOutTree) targetEditPart.getModel();
String expression = treeModel.getExpressionFilter();
if (sourceNode instanceof TreeNode) {
if (expression == null) {
expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
} else {
expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
}
} else if (sourceNode instanceof VarNode) {
String tableName = "Var";
if (sourceNode.eContainer() instanceof VarTable) {
tableName = ((VarTable) sourceNode.eContainer()).getName();
}
if (expression == null) {
expression = tableName + "." + sourceNode.getName();
} else {
expression = expression + " " + tableName + "." + sourceNode.getName();
}
}
treeModel.setExpressionFilter(expression);
FilterConnection connection = XmlmapFactory.eINSTANCE.createFilterConnection();
connection.setSource(sourceNode);
connection.setTarget(treeModel);
treeModel.getFilterIncomingConnections().add(connection);
sourceNode.getFilterOutGoingConnections().add(connection);
xmlMapData.getConnections().add(connection);
}
}
Aggregations