@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;
    }
Example #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;
  }