Ejemplo n.º 1
0
    @Override
    public IContextButtonPadData getContextButtonPad(IPictogramElementContext context) {

      IContextButtonPadData data = super.getContextButtonPad(context);
      PictogramElement pe = context.getPictogramElement();

      CreateConnectionContext ccc = new CreateConnectionContext();
      ccc.setSourcePictogramElement(pe);
      Anchor anchor = null;
      if (pe instanceof AnchorContainer) {
        // our spp has four fixed point anchor - we choose the first one
        anchor = ((ContainerShape) pe).getAnchors().get(0);
      }
      ccc.setSourceAnchor(anchor);

      ContextButtonEntry button = new ContextButtonEntry(null, context);
      button.setText("Create Binding");
      button.setIconId(ImageProvider.IMG_BINDING);
      ICreateConnectionFeature[] features = getFeatureProvider().getCreateConnectionFeatures();
      for (ICreateConnectionFeature feature : features) {
        if (feature.isAvailable(ccc) && feature.canStartConnection(ccc))
          button.addDragAndDropFeature(feature);
      }

      if (button.getDragAndDropFeatures().size() > 0) {
        data.getDomainSpecificContextButtons().add(button);
      }

      return data;
    }
Ejemplo n.º 2
0
  @Override
  public IContextButtonPadData getContextButtonPad(IPictogramElementContext context) {
    IContextButtonPadData data = super.getContextButtonPad(context);
    PictogramElement pe = context.getPictogramElement();

    // 1. set the generic context buttons
    // note, that we do not add 'remove' (just as an example)
    setGenericContextButtons(data, pe, CONTEXT_BUTTON_DELETE | CONTEXT_BUTTON_UPDATE);

    // 2. set the collapse button
    // simply use a dummy custom feature (senseless example)
    CustomContext cc = new CustomContext(new PictogramElement[] {pe});
    ICustomFeature[] cf = getFeatureProvider().getCustomFeatures(cc);
    for (int i = 0; i < cf.length; i++) {
      ICustomFeature iCustomFeature = cf[i];
      if (iCustomFeature instanceof AcoreCollapseDummyFeature) {
        IContextButtonEntry collapseButton =
            ContextEntryHelper.createCollapseContextButton(true, iCustomFeature, cc);
        data.setCollapseContextButton(collapseButton);
        break;
      }
    }

    // 3. add one domain specific context-button, which offers all
    // available connection-features as drag&drop features...

    // 3.a. create new CreateConnectionContext
    CreateConnectionContext ccc = new CreateConnectionContext();
    ccc.setSourcePictogramElement(pe);
    Anchor anchor = null;
    if (pe instanceof Anchor) {
      anchor = (Anchor) pe;
    } else if (pe instanceof AnchorContainer) {
      // assume, that our shapes always have chopbox anchors
      anchor = Graphiti.getPeService().getChopboxAnchor((AnchorContainer) pe);
    }
    ccc.setSourceAnchor(anchor);

    // 3.b. create context button and add all applicable features
    ContextButtonEntry button = new ContextButtonEntry(null, context);
    button.setText("Create connection"); // $NON-NLS-1$
    button.setIconId(AcoreImageProvider.IMG_EREFERENCE);
    ICreateConnectionFeature[] features = getFeatureProvider().getCreateConnectionFeatures();
    for (ICreateConnectionFeature feature : features) {
      if (feature.isAvailable(ccc) && feature.canStartConnection(ccc)) {
        button.addDragAndDropFeature(feature);
      }
    }

    // 3.c. add context button, if it contains at least one feature
    if (button.getDragAndDropFeatures().size() > 0) {
      data.getDomainSpecificContextButtons().add(button);
    }

    return data;
  }
 private void addReferenceToDiagram(
     IFeatureProvider fp, Diagram diagram, String sourceClass, String targetClass) {
   ICreateConnectionFeature[] ccfs = fp.getCreateConnectionFeatures();
   if (ccfs != null) {
     Shape sourceShape = findShapeForEClass(diagram, sourceClass);
     Anchor sourceAnchor = getPeService().getChopboxAnchor(sourceShape);
     Shape targetShape = findShapeForEClass(diagram, targetClass);
     Anchor targetAnchor = getPeService().getChopboxAnchor(targetShape);
     CreateConnectionContext ccc = new CreateConnectionContext();
     ccc.setSourceAnchor(sourceAnchor);
     ccc.setTargetAnchor(targetAnchor);
     // question instantiate create feature directly?
     for (ICreateConnectionFeature ccf : ccfs) {
       if (ccf.canCreate(ccc)) {
         ccf.execute(ccc);
         break;
       }
     }
   }
 }
  protected Connection createNewConnection(
      ModelHandler mh, ContainerShape oldShape, ContainerShape newShape) {

    Anchor sourceAnchor = LayoutUtil.getCenterAnchor(oldShape);
    Anchor targetAnchor = LayoutUtil.getCenterAnchor(newShape);

    // TODO: Use create features to create connection
    CreateConnectionContext createConnectionContext = new CreateConnectionContext();
    createConnectionContext.setSourcePictogramElement(oldShape);
    createConnectionContext.setTargetPictogramElement(newShape);
    createConnectionContext.setSourceAnchor(sourceAnchor);
    createConnectionContext.setTargetAnchor(targetAnchor);

    FlowNode oldObject = BusinessObjectUtil.getFirstElementOfType(oldShape, FlowNode.class);
    FlowNode newObject = BusinessObjectUtil.getFirstElementOfType(newShape, FlowNode.class);

    AddConnectionContext acc = new AddConnectionContext(sourceAnchor, targetAnchor);
    SequenceFlow flow = mh.createSequenceFlow(oldObject, newObject);
    acc.setNewObject(flow);

    Connection connection = (Connection) getFeatureProvider().addIfPossible(acc);

    return connection;
  }