Skip to main content



      Home
Home » Eclipse Projects » Sirius » Trigger Arrange All of a Diagram programmatically
Trigger Arrange All of a Diagram programmatically [message #1627735] Sat, 21 February 2015 13:46 Go to next message
Eclipse UserFriend
Hi,

i want to trigger an 'Arrange All' of a Diagram from an External Java Action (org.eclipse.sirius.tools.api.ui.IExternalJavaAction) or from the VSM itself (after the External Java Action is finished).

The two util classes org.eclipse.sirius.diagram.ui.tools.internal.layout.LayoutUtil and org.eclipse.sirius.diagram.ui.tools.api.layout.LayoutUtils sound promising. However, i can not use them directly within an IExternalJavaAction.

Could you tell me what is the best way to trigger an 'Arrange All'?
Re: Trigger Arrange All of a Diagram programmatically [message #1652176 is a reply to message #1627735] Thu, 05 March 2015 13:54 Go to previous messageGo to next message
Eclipse UserFriend
A little update: I figure out how to trigger an 'Arrange All' Action from an IExternalJavaAction. The problem now is, that the code works fine when I trigger it from a stand-alone operation (Tool Arrange All) but it did not work when I trigger it in a squence of commands (Tool Up in Sequence):

https://dl.dropboxusercontent.com/u/4062763/arrangeAllInOdesign.png


The "Up in Sequence"-Action has the goal to move an element up in an ordered list by changing its index. Afterwards, an "ArrangeAll"-Action is triggered to arrange the graphical elements accordingly to the order of the list. See:

https://dl.dropboxusercontent.com/u/4062763/upBefore.png

https://dl.dropboxusercontent.com/u/4062763/upAfter.png

https://dl.dropboxusercontent.com/u/4062763/upWantedResult.png


The goal is of course to have 'Up in Sequence' and 'Arrange All' in one single step...
Here is the related ArrangeAllAction (IExternalJavaAction ):

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.gmf.runtime.diagram.ui.requests.ArrangeRequest;
import org.eclipse.sirius.business.api.action.AbstractExternalJavaAction;
import org.eclipse.sirius.viewpoint.SiriusPlugin;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;

public class ArrangeAllAction extends AbstractExternalJavaAction {
	@Override
	public void execute(Collection<? extends EObject> selections, Map<String, Object> parameters) {
		try {
			// trigger 'Arrange All' on the whole diagram
			DiagramEditPart diagramEditPart = null;
			IEditorPart editor = PlatformUI.getWorkbench()
					.getActiveWorkbenchWindow().getActivePage()
					.getActiveEditor();

			if (editor instanceof DiagramEditor) {
				DiagramEditor diagramEditor = (DiagramEditor) editor;
				diagramEditPart = diagramEditor.getDiagramEditPart();
			}

			ArrangeRequest arrangeRequest = new ArrangeRequest(ActionIds.ACTION_ARRANGE_ALL);
			List<Object> partsToArrange = new ArrayList<Object>(1);
			partsToArrange.add(diagramEditPart);
			arrangeRequest.setPartsToArrange(partsToArrange);
			diagramEditPart.performRequest(arrangeRequest);

		} catch (Exception e) {
			SiriusPlugin.getDefault().error("Error while arrange elements", e);
		}

	}

	@Override
	public boolean canExecute(Collection<? extends EObject> selections) {
		return true;
	}

}
Re: Trigger Arrange All of a Diagram programmatically [message #1653561 is a reply to message #1652176] Fri, 06 March 2015 04:23 Go to previous messageGo to next message
Eclipse UserFriend
Hi Studs,

Could you provide a minimal example to reproduce?

Best Regards.

Le 05/03/2015 19:54, Studs Terkel a écrit :
> A little update: I figure out how to trigger an 'Arrange All' Action
> from an IExternalJavaAction. The problem now is, that the code works
> fine when I trigger it from a stand-alone operation (Tool Arrange All)
> but it did not work when I trigger it in a squence of commands (Tool Up
> in Sequence):
>
>
>
>
> The "Up in Sequence"-Action has the goal to move an element up in an
> ordered list by changing its index. Afterwards, an "ArrangeAll"-Action
> is triggered to arrange the graphical elements accordingly to the order
> of the list. See:
>
>
>
>
>
>
>
>
> The goal is of course to have 'Up in Sequence' and 'Arrange All' in one
> single step...
> Here is the related ArrangeAllAction (IExternalJavaAction ):
>
>
> import java.util.ArrayList;
> import java.util.Collection;
> import java.util.List;
> import java.util.Map;
>
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
> import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
> import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
> import org.eclipse.gmf.runtime.diagram.ui.requests.ArrangeRequest;
> import org.eclipse.sirius.business.api.action.AbstractExternalJavaAction;
> import org.eclipse.sirius.viewpoint.SiriusPlugin;
> import org.eclipse.ui.IEditorPart;
> import org.eclipse.ui.PlatformUI;
>
> public class ArrangeAllAction extends AbstractExternalJavaAction {
> @Override
> public void execute(Collection<? extends EObject> selections,
> Map<String, Object> parameters) {
> try {
> // trigger 'Arrange All' on the whole diagram
> DiagramEditPart diagramEditPart = null;
> IEditorPart editor = PlatformUI.getWorkbench()
> .getActiveWorkbenchWindow().getActivePage()
> .getActiveEditor();
>
> if (editor instanceof DiagramEditor) {
> DiagramEditor diagramEditor = (DiagramEditor) editor;
> diagramEditPart = diagramEditor.getDiagramEditPart();
> }
>
> ArrangeRequest arrangeRequest = new
> ArrangeRequest(ActionIds.ACTION_ARRANGE_ALL);
> List<Object> partsToArrange = new ArrayList<Object>(1);
> partsToArrange.add(diagramEditPart);
> arrangeRequest.setPartsToArrange(partsToArrange);
> diagramEditPart.performRequest(arrangeRequest);
>
> } catch (Exception e) {
> SiriusPlugin.getDefault().error("Error while arrange
> elements", e);
> }
>
> }
>
> @Override
> public boolean canExecute(Collection<? extends EObject> selections) {
> return true;
> }
>
> }
>



--
Esteban Dugueperoux - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Trigger Arrange All of a Diagram programmatically [message #1654104 is a reply to message #1653561] Fri, 06 March 2015 09:37 Go to previous messageGo to next message
Eclipse UserFriend
What exactly do you need?
Re: Trigger Arrange All of a Diagram programmatically [message #1654179 is a reply to message #1654104] Fri, 06 March 2015 10:17 Go to previous messageGo to next message
Eclipse UserFriend
Le 06/03/2015 15:37, Studs Terkel a écrit :
> What exactly do you need?

One Eclipse project example which show your working use case and another
one which show your non working use case.


--
Esteban Dugueperoux - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Trigger Arrange All of a Diagram programmatically [message #1660860 is a reply to message #1654179] Mon, 09 March 2015 07:17 Go to previous messageGo to next message
Eclipse UserFriend
I created a small example based on the Emf extended library example:

https://dl.dropboxusercontent.com/u/4062763/triggerArrangeAllExampleProjects.zip

The zip contains 4 plugins (org.eclipse.emf.examples.library.*) and 2 runtime projects. The related Actions are located in org.eclipse.emf.examples.library.sirius. The eclipse runtime should look like this:

https://dl.dropboxusercontent.com/u/4062763/extLibExample.png

Like described in the previous posts, the goal is to move a Writer up in the writers [0...*] List of Library and subsequently trigger an Arrange All to maintain the nice structure. In that regard, the Tool MovePlusArrangeAll is not working as i expected.
Re: Trigger Arrange All of a Diagram programmatically [message #1691910 is a reply to message #1660860] Fri, 10 April 2015 08:29 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Sorry for the delay of the response. This post was missed.

Le 09/03/2015 12:17, Studs Terkel a écrit :
> I created a small example based on the Emf extended library example:
>
> https://dl.dropboxusercontent.com/u/4062763/triggerArrangeAllExampleProjects.zip
>
>
> The zip contains 4 plugins (org.eclipse.emf.examples.library.*) and 2
> runtime projects. The related Actions are located in
> org.eclipse.emf.examples.library.sirius. The eclipse runtime should look
> like this:
>
>
>
> Like described in the previous posts, the goal is to move a Writer up in
> the writers [0...*] List of Library and subsequently trigger an Arrange
> All to maintain the nice structure. In that regard, the Tool
> MovePlusArrangeAll is not working as i expected.

I tried your sample. The arrange all external java action is launched
but before the diagram has been refreshed. So the graphical relations
between each writers have not been yet updated according to the semantic
changes. And as you said, the arrange all has not the expected result.

I see no way to do what you want.

This looks like an interesting feature to explore: We could imagine a
check box in the tool, as "Force Refresh" one , to launch an arrange all
(and another one to launch an arrange selection). You can create a
feature for that [1]. But we have no plans to work on it in the
following weeks.

[1] https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Sirius

Best regards,

--
Laurent Redor - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Trigger Arrange All of a Diagram programmatically [message #1692093 is a reply to message #1691910] Mon, 13 April 2015 07:54 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

thx for the reply. I think a feature like a triggerable auto-arrangement of your graphical objects is a really important... Who likes to babysit the arrangement of nodes and connections? Smile

For now: Is there a hotkey for "Arrange All" or is it possible to set a hotkey for this operation?
Re: Trigger Arrange All of a Diagram programmatically [message #1692188 is a reply to message #1692093] Tue, 14 April 2015 04:39 Go to previous messageGo to next message
Eclipse UserFriend
Le 13/04/2015 13:54, Studs Terkel a écrit :
> Hello,
>
Hi

> thx for the reply. I think a feature like a triggerable auto-arrangement
> of your graphical objects is a really important... Who likes to babysit
> the arrangement of nodes and connections? :)
>
> For now: Is there a hotkey for "Arrange All" or is it possible to set a
> hotkey for this operation?

There is currently no shortcut associated to "Arrange All" action
(inherited from GMF). You can use "Alt+D / R / A" or "Alt+D / R / S":

* Alt+D : Open the menu "Diagram"
* R : Open the sub-menu "aRrange"
* A : Launch the action "All"
or
* S : Launch the action "Selection"

Best regards,

--
Laurent Redor - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Trigger Arrange All of a Diagram programmatically [message #1731134 is a reply to message #1692188] Tue, 03 May 2016 02:36 Go to previous message
Eclipse UserFriend
Hello guys,
I'm not able to access triggerArrangeAllExampleProjects.zip file.
Can I get that zip file.
Previous Topic:Example not working
Next Topic:How to Create a View without a reference to the model
Goto Forum:
  


Current Time: Sun Mar 16 09:14:31 EDT 2025

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

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

Back to the top