use of org.talend.designer.xmlmap.parts.VarNodeEditPart in project tdi-studio-se by Talend.
the class UpdateFilterExpressionCommand method execute.
@Override
public void execute() {
AbstractInOutTree targetTree = (AbstractInOutTree) targetEditPart.getModel();
String expression = targetTree.getExpressionFilter();
if (objects.getToTransfer() != null) {
for (Object obj : objects.getToTransfer()) {
AbstractNode sourceNode = null;
// INPUT == FILTER
if (objects.getType() == TransferdType.INPUT) {
TreeNodeEditPart part = (TreeNodeEditPart) obj;
sourceNode = (TreeNode) part.getModel();
if (expression == null) {
expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
} else {
expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
}
} else // VARE == FILTER
if (objects.getType() == TransferdType.VAR) {
String tableName = "Var";
VarNodeEditPart part = (VarNodeEditPart) obj;
sourceNode = (VarNode) part.getModel();
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 != null) {
targetTree.setExpressionFilter(expression);
FilterConnection connection = XmlmapFactory.eINSTANCE.createFilterConnection();
connection.setSource(sourceNode);
connection.setTarget(targetTree);
targetTree.getFilterIncomingConnections().add(connection);
sourceNode.getFilterOutGoingConnections().add(connection);
xmlMapData.getConnections().add(connection);
}
// check if need update outputTree InputLoopNodesTable
}
}
}
use of org.talend.designer.xmlmap.parts.VarNodeEditPart 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.VarNodeEditPart 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.VarNodeEditPart 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.VarNodeEditPart in project tdi-studio-se by Talend.
the class VarToolBarFigure method removeVar.
@Override
protected void removeVar() {
CommandStack commandStack = getTableManager().getGraphicalViewer().getEditDomain().getCommandStack();
commandStack.execute(new Command() {
@Override
public void execute() {
List selectedEditParts = getTableManager().getGraphicalViewer().getSelectedEditParts();
final List<VarNode> toRemove = new ArrayList<VarNode>();
int minIndex = parentTable.getNodes().size() - 1;
for (Object obj : selectedEditParts) {
if (obj instanceof VarNodeEditPart) {
VarNode model = (VarNode) ((VarNodeEditPart) obj).getModel();
toRemove.add(model);
XmlMapUtil.detachNodeConnections(model, (XmlMapData) parentTable.eContainer(), true);
int index = parentTable.getNodes().indexOf(model);
if (index < minIndex) {
minIndex = index;
}
}
}
parentTable.getNodes().removeAll(toRemove);
if (!tablePart.getChildren().isEmpty()) {
if (minIndex > tablePart.getChildren().size() - 1) {
minIndex = tablePart.getChildren().size() - 1;
}
tablePart.getViewer().select((EditPart) tablePart.getChildren().get(minIndex));
} else {
remove.setEnabled(false);
}
}
});
}
Aggregations