use of org.talend.designer.xmlmap.editor.XmlMapGraphicViewer in project tdi-studio-se by Talend.
the class DragAndDropEditPolicy method getCommand.
@Override
public Command getCommand(Request request) {
if (request instanceof CreateNodeConnectionRequest) {
CreateNodeConnectionRequest rq = (CreateNodeConnectionRequest) request;
EditPart targetEditPart = rq.getTargetEditPart();
Command command = null;
if (targetEditPart != null && TemplateTransfer.getInstance().getObject() instanceof TransferedObject) {
TransferedObject toDrop = (TransferedObject) TemplateTransfer.getInstance().getObject();
MapperManager manager = ((XmlMapGraphicViewer) targetEditPart.getViewer()).getMapperManager();
if (manager != null && manager.getExternalData() != null) {
DropType dropType = rq.getNewObjectType();
if (dropType != null) {
switch(dropType) {
case DROP_FILTER:
if (targetEditPart instanceof MapperTablePart) {
command = new UpdateFilterExpressionCommand(toDrop, (MapperTablePart) targetEditPart, manager.getExternalData());
}
break;
case DROP_EXPRESSION:
if (targetEditPart instanceof TableEntityPart) {
command = new UpdateExpressionCommand(toDrop, (TableEntityPart) targetEditPart, manager);
}
break;
case DROP_OUTPUT_DOC_CHILD:
if (targetEditPart instanceof OutputTreeNodeEditPart && rq.getNewObject() instanceof OutputTreeNode) {
command = new CreateDocChildrenCommand(toDrop, (OutputTreeNodeEditPart) targetEditPart, rq, manager);
}
break;
case DROP_INSERT_OUTPUT:
case DROP_INSERT_VAR:
case DROP_INSERT_INPUT:
command = new InsertNewColumnCommand(toDrop, targetEditPart, rq, manager, dropType);
default:
break;
}
}
}
}
if (command != null) {
return command;
}
// drop expression
// boolean update = rq.getDropType() == CreateNodeConnectionRequest.DROP_EXPRESSION ? true : false;
// return new CreateNodeAndConnectionCommand(rq.getNewObject(), rq.getTargetEditPart(), update);
}
return super.getCommand(request);
}
use of org.talend.designer.xmlmap.editor.XmlMapGraphicViewer in project tdi-studio-se by Talend.
the class StyledTextHandler method updateCellExpression.
private void updateCellExpression() {
if (selectedNode != null && styledText != null && !styledText.getText().equals(selectedNode.getExpression())) {
DirectEditCommand command = new DirectEditCommand(selectedNodePart, selectedNode, DirectEditType.EXPRESSION, styledText.getText());
((XmlMapGraphicViewer) selectedNodePart.getViewer()).getEditDomain().getCommandStack().execute(command);
}
}
use of org.talend.designer.xmlmap.editor.XmlMapGraphicViewer in project tdi-studio-se by Talend.
the class XmlMapOutputZoneToolBar method addTable.
/*
* (non-Javadoc)
*
* @see org.talend.designer.newabstractmap.figures.treetools.zone.OutputZoneToolBar#addTable()
*/
@Override
protected void addTable() {
final OutputXmlTree createOutputXmlTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
CommandStack commandStack = externalPart.getViewer().getEditDomain().getCommandStack();
commandStack.execute(new Command() {
@Override
public void execute() {
if (externalPart.getViewer() instanceof XmlMapGraphicViewer) {
XmlMapGraphicViewer viewer = (XmlMapGraphicViewer) externalPart.getViewer();
MapperManager manager = viewer.getMapperManager();
String outputName = manager.getMapperUI().openNewOutputCreationDialog();
if (outputName == null) {
return;
}
createOutputXmlTree.setName(outputName);
externalData.getOutputTrees().add(createOutputXmlTree);
MetadataTable metadataTable = new MetadataTable();
metadataTable.setLabel(outputName);
metadataTable.setTableName(outputName);
mapperComponent.getMetadataList().add(metadataTable);
mapperComponent.getProcess().addUniqueConnectionName(outputName);
int indexOf = externalPart.getModelChildren().indexOf(createOutputXmlTree);
if (indexOf != -1) {
externalPart.getViewer().select((EditPart) externalPart.getChildren().get(indexOf));
}
if (!min_size.isEnabled()) {
min_size.setEnabled(true);
}
// check problem for created output incase input main is multiloop
mapperManger.getProblemsAnalyser().checkProblems(createOutputXmlTree);
mapperManger.getMapperUI().updateStatusBar();
}
}
});
}
use of org.talend.designer.xmlmap.editor.XmlMapGraphicViewer 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.editor.XmlMapGraphicViewer in project tdi-studio-se by Talend.
the class InputXmlTreeEditPart method notifyChanged.
@Override
public void notifyChanged(Notification notification) {
int type = notification.getEventType();
int featureId = notification.getFeatureID(XmlmapPackage.class);
switch(type) {
case Notification.ADD:
case Notification.REMOVE:
case Notification.REMOVE_MANY:
switch(featureId) {
case XmlmapPackage.INPUT_XML_TREE__NODES:
case XmlmapPackage.INPUT_XML_TREE__GLOBAL_MAP_KEYS_VALUES:
refreshChildren();
break;
case XmlmapPackage.ABSTRACT_IN_OUT_TREE__FILTER_INCOMING_CONNECTIONS:
refreshTargetConnections();
break;
}
break;
case Notification.SET:
switch(featureId) {
case XmlmapPackage.INPUT_XML_TREE__NODES:
case XmlmapPackage.INPUT_XML_TREE__GLOBAL_MAP_KEYS_VALUES:
refreshChildren();
break;
case XmlmapPackage.INPUT_XML_TREE__ACTIVATE_CONDENSED_TOOL:
getFigure().validate();
break;
case XmlmapPackage.INPUT_XML_TREE__LOOKUP_MODE:
case XmlmapPackage.INPUT_XML_TREE__MATCHING_MODE:
case XmlmapPackage.INPUT_XML_TREE__INNER_JOIN:
case XmlmapPackage.INPUT_XML_TREE__PERSISTENT:
case XmlmapPackage.INPUT_XML_TREE__MINIMIZED:
case XmlmapPackage.INPUT_XML_TREE__EXPRESSION_FILTER:
((InputXmlTreeFigure) getFigure()).update(featureId);
break;
case XmlmapPackage.ABSTRACT_IN_OUT_TREE__MULTI_LOOPS:
if (getParent() instanceof XmlMapDataEditPart) {
List childPart = ((XmlMapDataEditPart) getParent()).getChildren();
for (Object o : childPart) {
if (o instanceof OutputXmlTreeEditPart) {
OutputXmlTreeEditPart outputPart = (OutputXmlTreeEditPart) o;
boolean hasDocument = XmlMapUtil.hasDocument((OutputXmlTree) outputPart.getModel());
if (!hasDocument) {
OutputXmlTreeFigure outputTreeFigure = (OutputXmlTreeFigure) outputPart.getFigure();
outputTreeFigure.update(XmlmapPackage.ABSTRACT_IN_OUT_TREE__MULTI_LOOPS);
} else {
List nodeChild = outputPart.getChildren();
for (Object nc : nodeChild) {
if (nc instanceof OutputTreeNodeEditPart) {
refreshOutputNodeLoopFunctionBtn((OutputTreeNodeEditPart) nc);
}
}
}
}
}
boolean changed = clearOutputAggregateIfNeeded();
if (changed) {
((XmlMapDataEditPart) getParent()).refresh();
}
((XmlMapGraphicViewer) getViewer()).getMapperManager().getProblemsAnalyser().checkProblems();
((XmlMapGraphicViewer) getViewer()).getMapperManager().getMapperUI().updateStatusBar();
}
}
}
}
Aggregations