Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse RedDeer » Graphiti - create connection using pad button
Graphiti - create connection using pad button [message #1819626] Sat, 18 January 2020 21:21 Go to next message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 92
Registered: April 2012
Member
Hi,
I would like to create a connection between two GraphitiEditParts. As a user I do it by ContextButton. However, I need to keep the click pushed until I move mouse over second object.
Thank you in advance for some hints or ideas?
Re: Graphiti - create connection using pad button [message #1819627 is a reply to message #1819626] Sat, 18 January 2020 23:34 Go to previous message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 92
Registered: April 2012
Member
As a workaround I create connection programatically by using the same ConnectionFeature as pad button:

public class CreateSimpleConnection {

  private IFeatureProvider featureProvider;
  private TransactionalEditingDomain editDomain;
  private CreateConnectionContext context;

  public CreateSimpleConnection(GEFEditor gefEditor, GraphitiEditPart sourceEp,
      GraphitiEditPart destinationEp) {
    RuminaqEditor ruminaqEditor = ((RuminaqEditor) gefEditor.getEditorPart());
    this.editDomain = ruminaqEditor.getDiagramBehavior().getEditingDomain();
    this.featureProvider = ruminaqEditor.getDiagramTypeProvider().getFeatureProvider();
    
    PictogramElement sourcePe = Optional.of(sourceEp)
        .map(GraphitiEditPart::getGEFEditPart)
        .filter(ContainerShapeEditPart.class::isInstance)
        .map(o -> (ContainerShapeEditPart) o)
        .map(ContainerShapeEditPart::getPictogramElement).get();
    PictogramElement destinationPe = Optional.of(destinationEp)
        .map(GraphitiEditPart::getGEFEditPart)
        .filter(ContainerShapeEditPart.class::isInstance)
        .map(o -> (ContainerShapeEditPart) o)
        .map(ContainerShapeEditPart::getPictogramElement).get();

    this.context = new CreateConnectionContext();
    context.setSourceAnchor(getAnchor(sourcePe));
    context.setTargetAnchor(getAnchor(destinationPe));
    context.setSourcePictogramElement(sourcePe);
    context.setTargetPictogramElement(destinationPe);
    context.setSourceLocation(null);
    context.setTargetLocation(null);
  }

  private Anchor getAnchor(PictogramElement pe) {
    Anchor ret = null;
    if (pe instanceof Anchor) {
      ret = (Anchor) pe;
    } else if (pe instanceof AnchorContainer) {
      ret = Graphiti.getPeService().getChopboxAnchor((AnchorContainer) pe);
    }
    return ret;
  }

  public void execute() {
    CreateSimpleConnectionFeature f = new CreateSimpleConnectionFeature(featureProvider);
    f.canCreate(context);
    ModelUtil.runModelChange(() -> f.create(context),
        editDomain,
        "Add connection");
  }
}
Previous Topic:Is there an example of using Red Deer with a (non Eclipse) E4 Application?
Goto Forum:
  


Current Time: Sun Feb 16 18:28:30 GMT 2020

Powered by FUDForum. Page generated in 0.02254 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top