@Override public Connection create(ICreateConnectionContext context) { Connection newConnection = null; // get EClasses which should be connected StandardNode source = getStandardNode(context.getSourcePictogramElement()); StandardNode target = getStandardNode(context.getTargetPictogramElement()); if (source != null && target != null && target != source) { // create new business object Link l = createLink(source, target); if (l == null) { return null; } // add connection for business object AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor()); addContext.setNewObject(l); newConnection = (Connection) getFeatureProvider().addIfPossible(addContext); PictogramElement pes = context.getSourcePictogramElement(); PictogramElement pet = context.getTargetPictogramElement(); if (source.getEdge().getChildNode().size() == 0) { pet.getGraphicsAlgorithm().setX(pes.getGraphicsAlgorithm().getX()); pet.getGraphicsAlgorithm() .setY(pes.getGraphicsAlgorithm().getY() + pes.getGraphicsAlgorithm().getHeight() + 45); } } return newConnection; }
/** Criteria that a node can be created - the target */ @Override public boolean canCreate(ICreateConnectionContext context) { PictogramElement pe = context.getSourcePictogramElement(); PictogramElement peS = context.getTargetPictogramElement(); if (this.getBusinessObjectForPictogramElement(pe) != null) { if (this.getBusinessObjectForPictogramElement(pe) instanceof StandardNode) { // StandardNode ss = (StandardNode)this.getBusinessObjectForPictogramElement(peS); return true; } } return false; }
@Override public boolean canStartConnection(ICreateConnectionContext context) { PictogramElement pe = context.getSourcePictogramElement(); if (this.getBusinessObjectForPictogramElement(pe) != null) { if (this.getBusinessObjectForPictogramElement(pe) instanceof StandardNode) { StandardNode st = (StandardNode) this.getBusinessObjectForPictogramElement(pe); if (st.getEdge() == null || (st.getEdge() != null && st.getEdge().getComposition().getValue() != Composition.ATOMIC_VALUE)) { return true; } } } return false; }
// Creates the business object for the relationship @Override public Connection create(ICreateConnectionContext context) { Connection newConnection = null; // get TNodeTemplates which should be connected TNodeTemplate source = getTNodeTemplate(context.getSourceAnchor()); TNodeTemplate target = getTNodeTemplate(context.getTargetAnchor()); if (source != null && target != null) { // create new business object TRelationshipTemplate newClass = ToscaFactory.eINSTANCE.createTRelationshipTemplate(); newClass.setName("Relation"); newClass.setId(("R" + (Integer) newClass.hashCode()).toString()); newClass.setType(new QName("Bidirected")); // newClass.setType( new QName("Peer - Peer") ); SourceElementType se = ToscaFactory.eINSTANCE.createSourceElementType(); se.setRef(source.getId()); newClass.setSourceElement(se); TargetElementType te = ToscaFactory.eINSTANCE.createTargetElementType(); te.setRef(target.getId()); newClass.setTargetElement(te); ContainerShape sourceContainer = (ContainerShape) context.getSourcePictogramElement(); Object parentObject = getFeatureProvider().getBusinessObjectForPictogramElement(sourceContainer.getContainer()); TServiceTemplate serviceTemplate = null; if (parentObject == null) return null; if (parentObject instanceof TServiceTemplate) { serviceTemplate = (TServiceTemplate) parentObject; } TTopologyTemplate topology = null; topology = serviceTemplate.getTopologyTemplate(); topology.getRelationshipTemplate().add(newClass); // add connection for business object AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor()); addContext.setNewObject(newClass); newConnection = (Connection) getFeatureProvider().addIfPossible(addContext); } return newConnection; }