コード例 #1
0
 protected B getTargetBo(ICreateConnectionContext context) {
   if (context.getTargetAnchor() != null) {
     return BusinessObjectUtil.getFirstElementOfType(
         context.getTargetAnchor().getParent(), getTargetClass());
   }
   return null;
 }
コード例 #2
0
  @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;
  }
コード例 #3
0
 // 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;
 }
コード例 #4
0
  // 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;
  }
コード例 #5
0
 @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;
 }