Home » Eclipse Projects » Sirius » How to apply layout when creating new presentation(Need to apply an existed layout to new representation when creation)
How to apply layout when creating new presentation [message #1481733] |
Fri, 21 November 2014 07:17 |
Sann Tran Messages: 15 Registered: November 2014 |
Junior Member |
|
|
I already have representation R1 that represents for model A. I would like to create representation R2 for the same model A, and the layout of R1 is applied to R2 automatically after R2 is created.
In .odesign file, I use Root Expression (inside Advanced) of Diagram properties. I make the Root Expression call a service to to store layout of R1 then apply to R2.
I found that the service was called everytime I create new representation, and also when I open representation, and when I refresh the diagram editor;
My service work fine when I open representation R2 (it means R2 is existed, and I double click to R2 to open it, layout of R1 is applied to R2)
But if R2 is not existed, when I create new representation R2, the layout of R1 is not applied to R2 although the service is called.
The questions are:
1. Is my method correct? It means that am I correct when put my service to Root Expression to be called?
2. If my method is correct, It mean that there is something incorrect in my service, so please look at my service, and let me know where I should change
private static void copyLayout(final Session session, final DRepresentation sourceRepresentation,
final DRepresentation targetRepresentation) {
final Diagram sourceDiagram = SiriusGMFHelper.getGmfDiagram((DDiagram) sourceRepresentation);
final Diagram targetDiagram = SiriusGMFHelper.getGmfDiagram((DDiagram) targetRepresentation);
final DiagramEditPart sourceDiagramEditPart = createDiagramEditPart(sourceDiagram);
final SiriusLayoutDataManager layoutManager =
SiriusLayoutDataManagerForSemanticElementsFactory.getInstance().getSiriusLayoutDataManager();
layoutManager.storeLayoutData(sourceDiagramEditPart);
final DiagramEditPart targetDiagramEditPart = createDiagramEditPart(targetDiagram);
if ((sourceDiagramEditPart == null) || (targetDiagramEditPart == null)) {
return;
}
final RecordingCommand command = new RecordingCommand(targetDiagramEditPart.getEditingDomain()) {
@Override
protected void doExecute() {
layoutManager.applyLayout(targetDiagramEditPart);
}
};
targetDiagramEditPart.getEditingDomain().getCommandStack().execute(command);
}
3. If my method is incorrect, What should I do to copy layout of R1 to R2 when R2 is created?
Thank you very much!
|
|
|
Re: How to apply layout when creating new presentation [message #1485804 is a reply to message #1481733] |
Mon, 24 November 2014 15:03 |
|
Hi,
Le 21/11/2014 08:17, Sann Tran a écrit :
> I already have representation R1 that represents for model A. I would
> like to create representation R2 for the same model A, and the layout of
> R1 is applied to R2 automatically after R2 is created.
>
> In .odesign file, I use Root Expression (inside Advanced) of Diagram
> properties. I make the Root Expression call a service to to store layout
> of R1 then apply to R2.
>
> I found that the service was called everytime I create new
> representation, and also when I open representation, and when I refresh
> the diagram editor;
>
This is the expected behavior: as displayed in the tooltip of the
corresponding property section, the root expression can be used to
dynamically change the considered root for the diagram. The semantic
target of the diagram will be the semantic element on which by the user
created the diagram but the expression will be evaluated to find the
root of the diagram from which the semantic candidate of the top level
mappings will be evaluated.
> My service work fine when I open representation R2 (it means R2 is
> existed, and I double click to R2 to open it, layout of R1 is applied to
> R2)
In this case, when you open R2, it already contains element and your
service is able to find them and to apply the layout from R1, but it
will be done on each refresh.
>
> But if R2 is not existed, when I create new representation R2, the
> layout of R1 is not applied to R2 although the service is called.
When the root expression is evaluated, R2 is empty, there are no element
on which the layout values can be reported.
>
> The questions are:
> 1. Is my method correct? It means that am I correct when put my service
> to Root Expression to be called?
> 2. If my method is correct, It mean that there is something incorrect in
> my service, so please look at my service, and let me know where I should
> change
See my previous comments. The layout
>
> private static void copyLayout(final Session session, final
> DRepresentation sourceRepresentation,
> final DRepresentation targetRepresentation) {
>
> final Diagram sourceDiagram =
> SiriusGMFHelper.getGmfDiagram((DDiagram) sourceRepresentation);
> final Diagram targetDiagram =
> SiriusGMFHelper.getGmfDiagram((DDiagram) targetRepresentation);
>
> final DiagramEditPart sourceDiagramEditPart =
> createDiagramEditPart(sourceDiagram);
>
> final SiriusLayoutDataManager layoutManager =
>
> SiriusLayoutDataManagerForSemanticElementsFactory.getInstance().getSiriusLayoutDataManager();
>
> layoutManager.storeLayoutData(sourceDiagramEditPart);
>
> final DiagramEditPart targetDiagramEditPart =
> createDiagramEditPart(targetDiagram);
>
> if ((sourceDiagramEditPart == null) || (targetDiagramEditPart ==
> null)) {
> return;
> }
> final RecordingCommand command = new
> RecordingCommand(targetDiagramEditPart.getEditingDomain()) {
> @Override
> protected void doExecute() {
> layoutManager.applyLayout(targetDiagramEditPart);
> }
> };
>
> targetDiagramEditPart.getEditingDomain().getCommandStack().execute(command);
>
> }
>
>
> 3. If my method is incorrect, What should I do to copy layout of R1 to
> R2 when R2 is created?
I think you should try to define a DiagramCreationDescription, this
should automatically report the layout of the source diagram on the new
diagram (see
org.eclipse.sirius.diagram.ui.tools.internal.menu.SubDiagramMenu.createDetailsActions(DDiagramElement,
IMenuManager, TransactionalEditingDomain, IGraphicalEditPart) and
org.eclipse.sirius.diagram.ui.tools.internal.actions.CreateRepresentationFromRepresentationCreationDescription)
when you create a diagram from another one.
Could you give some information on your context ? When do you want to
copy/paste the layout ? How will your user create this new diagram ?
>
> Thank you very much!
>
>
Regards
--
Maxime - Obeo
Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Maxime Porhel - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
Re: How to apply layout when creating new presentation [message #1486420 is a reply to message #1485804] |
Tue, 25 November 2014 02:56 |
Huy Le Messages: 18 Registered: November 2014 |
Junior Member |
|
|
Hi Maxim,
Let me clarify the issue.
We would like to add a feature called "auto-sync layout of two diagrams programmatically. The source one is undirected graph, the target is directed graph (flow). Flow is defined by applying some calculations based on the source. They refer to different Domain Classes."
Auto sync layout includes 03 different scenarios:
1/ Layout sync when open existing directed graph (this feature worked fine for now)
2/ Layout sync when creating new representation of Flow
3/ Auto sync layout when any changes in the source diagram (after saved of courses)
At scenario (2), i do debug & see that, the layout is already copied by checking represenation.aird, but opened editor does not in-synced with it. The layout only synced after we close the editor and open it again.
Question: do we have any way to append our own action before editor loaded or after an editor opened? If YES, we can execute layout-sync in between.
At Scenarios (3), I have no clue/idea how to do, it would be great if you give us some clues.
Thank you,
Huy.
-
Attachment: flow.png
(Size: 9.95KB, Downloaded 894 times)
|
|
| |
Re: How to apply layout when creating new presentation [message #1494191 is a reply to message #1493906] |
Mon, 01 December 2014 08:54 |
|
Hi Huy,
Le 01/12/2014 04:25, Huy Le a écrit :
> I found solution.
>
> I base on ResourceSetListener & override transactionAboutToCommit method.
Note that you could also override the following methods:
. getFilter which provides a a notification filter to select which
notifications should be sent to your listener. (If you extend
ResourceSetListenerImpl, you can configure it from the constructor)
. isPrecommitOnly(), if your listener is intended to only deal with
pre-commit events, you should return true.
. isAggregatePrecommitListener() retrun false per default and "assume
that we want individual transaction pre-commit". I think that in your
case, you should return true to be invoked only for pre-commit of the
root transaction with all notifications from that transaction and any
nested transactions : then you will have the possibility to do only one
"layout sync" command per user action and not one per sub transaction
(it could occur for some tools).
The other solution, proposed by Florian on your other forum message, was
to use a ModelChangeTrigger and to install it on the SessionEventBroker,
this SessionEventBroker is a pre-commit only aggregate resource set
listener on which you can register a ModelChangeTrigger with a scope, a
priority. With a chosen priority you could be sure to make your layout
called after the Sirius canonical synchronizer or other model change
triggers. With you chosen solution, it will depend on the precommit
listeners installation orders: if your precommit listener is installed
after the Sirius ones, your listener will called after those other
listeners.
> Something as below code snipet
>
> @Override
> public Command transactionAboutToCommit(final ResourceSetChangeEvent
> event) throws RollbackException {
>
> final Notification notification = event.getNotifications().get(0);
> final Object element = notification.getNotifier();
>
> if ((element instanceof Bounds) || (element instanceof
> Bendpoints)) {
> final MySemanticObject object =
> getDiagramSemanticModel((EObject) element);
> return new MySyncLayoutCommand(....); }
> return null;
> }
> Regards,
>
> Huy
Regards,
--
Maxime - Obeo
Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Maxime Porhel - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
Goto Forum:
Current Time: Thu Sep 26 05:16:28 GMT 2024
Powered by FUDForum. Page generated in 0.06185 seconds
|