Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Programmatically call Arrange Selection
Programmatically call Arrange Selection [message #1775130] Wed, 25 October 2017 06:48 Go to next message
Martin Jedlicka is currently offline Martin JedlickaFriend
Messages: 121
Registered: January 2016
Senior Member
Hi,

I have a question on the call Arrange Selection.

I have an Arrange All code that works correctly:

// Arrange All - OK
IEditorPart editor = EclipseUIUtil.getActiveEditor();
List<Object> partsToArrange = new ArrayList<>(1);

if (editor instanceof DiagramEditor) {
  DiagramEditor diagramEditor = (DiagramEditor) editor;
  DiagramEditPart diagramEditPart = diagramEditor.getDiagramEditPart();
  
  ArrangeRequest arrangeRequest = new ArrangeRequest(ActionIds.ACTION_ARRANGE_ALL);
  partsToArrange.add(diagramEditPart);
  arrangeRequest.setPartsToArrange(partsToArrange);
  diagramEditPart.performRequest(arrangeRequest);
}


And now I would need to call the Arrange Selection programmatically. I have this code:

// I want Arrange Selection but call Arrange All - BAD
IEditorPart editor = EclipseUIUtil.getActiveEditor();
List<Object> partsToArrange = new ArrayList<>();

if (editor instanceof DiagramEditor) {
  DiagramEditor diagramEditor = (DiagramEditor) editor;
  DiagramEditPart diagramEditPart = diagramEditor.getDiagramEditPart();
  
  List<?> children = diagramEditPart.getChildren();
  for (Object child : children) {
    if (child instanceof DNodeEditPart) {
      DNodeEditPart editPart = (DNodeEditPart) child;
      Object model = editPart.getModel();
      if (model instanceof Node) {
        Node node = (Node) model;
        if (node.getElement().equals(dNodeSource) || node.getElement().equals(dNodeTarget)) {
          partsToArrange.add(editPart);
        }
      }
    }
  }
  
  ArrangeRequest arrangeRequest = new ArrangeRequest(ActionIds.ACTION_ARRANGE_SELECTION);
  partsToArrange.add(diagramEditPart);
  arrangeRequest.setPartsToArrange(partsToArrange);
  //diagramEditPart.performRequest(arrangeRequest);
  
  Command command = partsToArrange.get(0).getCommand(arrangeRequest);
  if (command != null) {
    command.execute();
  }
}


but it's still called Arrange All instead of Arrange Selection.

Do not you know where I'm making a mistake?

Thanks.

Martin
Re: Programmatically call Arrange Selection [message #1775146 is a reply to message #1775130] Wed, 25 October 2017 09:58 Go to previous message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
Hi,

Why do you add diagramEditPart to the arrange parts?
Except that I don't see the problem.

Regards,

Pierre


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Wed, 25 October 2017 10:00]

Report message to a moderator

Previous Topic:Container Drop -> Create Edge View
Next Topic:Select Model Element Variable
Goto Forum:
  


Current Time: Mon Mar 30 18:29:09 GMT 2020

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

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

Back to the top