protected B getTargetBo(ICreateConnectionContext context) { if (context.getTargetAnchor() != null) { return BusinessObjectUtil.getFirstElementOfType( context.getTargetAnchor().getParent(), getTargetClass()); } return null; }
// Checks if user can create relationship object in the target // business object @Override public boolean canCreate(ICreateConnectionContext context) { // return true if both anchors belong to a TNodeTemplate // and those TNodeTemplates are not identical TNodeTemplate source = getTNodeTemplate(context.getSourceAnchor()); TNodeTemplate target = getTNodeTemplate(context.getTargetAnchor()); if (source != null && target != null && source != target) { return true; } return false; }
/** 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) { // return true if start anchor belongs to a TNodeTemplate if (getTNodeTemplate(context.getSourceAnchor()) != null) { return true; } return false; }
@Override public Connection create(ICreateConnectionContext context) { try { A source = getSourceBo(context); B target = getTargetBo(context); ModelHandler mh = ModelHandler.getInstance(getDiagram()); AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor()); BaseElement flow = createFlow(mh, source, target); // flow.setId(EcoreUtil.generateUUID()); addContext.setNewObject(flow); Connection connection = (Connection) getFeatureProvider().addIfPossible(addContext); ModelUtil.setID(flow); return connection; } catch (IOException e) { Activator.logError(e); } return null; }
@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; }
// 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; }
@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; }