Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to change source and target of a link in the generated code?
How to change source and target of a link in the generated code? [message #227791] Tue, 28 April 2009 03:49 Go to next message
Eclipse UserFriend
Hi everybody,
I want to create a component diagram with components diagrams and ports
like this:
_____________ ______________
| |___ _____| |
| Component1 |P1 |___Connector___|P2 |Component 2 |
| |___| |____| |
|____________| |______________|

P1,P2 ports

The problem is that in the UML model I don't have a direct connection
between port and connectors,
I have

SourcePort ---ConnectorEnd1--Connector---ConnectorEnd2------TargetPort

but I don't want to represent graphically the ConnectorEnd.

I try to modify the genererated code in order to solve this.I can save the
port and the connector with the good references between them,
but I don't have the ConnectorEnd in my xmi file but most of all the
connector figure does not appear in my diagram!

I try to follow the examples and the book Eclipse Modeling Project in
order to know where I can add modified code in order to make appear the
connector but I don't understand very well all the mechanisms used.

I use ConnectorEnd like source and target for connector link in the
gmfmap and
in the class ConnectorCreateCommand generated in edit.commands I have
changed doDefaultElementCreation() to this :

/**
* @generated NOT
*/
protected EObject doDefaultElementCreation() {
org.alkante.generic_editor.uml.Connector newElement =
org.alkante.generic_editor.uml.UmlFactory.eINSTANCE
.createConnector();

// Creation ConnectorEnd
ConnectorEnd ce1 = org.alkante.generic_editor.uml.UmlFactory.eINSTANCE
.createConnectorEnd();
ConnectorEnd ce2 = org.alkante.generic_editor.uml.UmlFactory.eINSTANCE
.createConnectorEnd();

// add connectorEnds to the connector
newElement.getOwnedElement().add(ce1);
newElement.getOwnedElement().add(ce2);

// Links between Ports and ConnectorEnd
ce1.setRole(getSource());
ce2.setRole(getTarget());

getSource().getEnd().add(ce1);
getTarget().getEnd().add(ce2);

// Links between Connector and ConnectorEnd
newElement.getEnd().add(ce1);
newElement.getEnd().add(ce2);

//ce1.setOwner(newElement);
//ce2.setOwner(newElement);

getContainer().getOwnedElement().add(newElement);
UmlElementTypes.init_Connector_4001(newElement);

return newElement;
}

Moreover,I change the references in ConnectorCreateCommand ,
ConnectorReorientCommand ,UmlBaseEditSemanticPolicy ,UmlDiagramUpdater
in order to match with that.

However, in generated method doExecuteWithResult() after the line
ICommand configureCommand = elementType.getEditCommand(configureRequest)
configureCommand stay at null whereas configureRequest isn't null.

So my questions are :
Where is the best location for adding code in order to make appear
the conector in the diagram?
What I have missed in my modifications?

Thank you in advance
Marie
Re: How to change source and target of a link in the generated code? [message #227882 is a reply to message #227791] Tue, 28 April 2009 07:42 Go to previous messageGo to next message
Eclipse UserFriend
Hello Marie,

> I try to modify the genererated code in order to solve this.I can save
> the port and the connector with the good references between them,
> but I don't have the ConnectorEnd in my xmi file but most of all the
I doubt you have no ConnectorEnd.. In this case you probbaly will not be
able to save model file.. AFAIU from the code you should be able to find
ConnectorEnd elements as a child elements of Connector – see:
> // add connectorEnds to the connector
> newElement.getOwnedElement().add(ce1);
> newElement.getOwnedElement().add(ce2);

(i suppose ownedElement is containment feature)

> connector figure does not appear in my diagram!
Is it removed by diagram update process? Try blocking ???CanonicalEditPolicy
generated for the diagram to prevent connections from being updated from
there.


-----------------
Alex Shatalin
Re: How to change source and target of a link in the generated code? [message #227944 is a reply to message #227882] Tue, 28 April 2009 08:39 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alex,
thank you very much for your answer , I have commented the method
refreshConnections() in my PackageCanonicalEditPolicy and I had
ce1.setOwner(newElement); in the method
doDefaultElementCreation() now it works fine.
ce2.setOwner(newElement);

However , I have another question: I want to add a window where user will
can choose an Property in a dynamical list and add it into a
PropertyCompartment inside my component. Which class can I use for my
window?

Moreover I don't understand precisely where I can add a command to do
this because there is two ways yo create a property : by the palette or
using the pop-up of the component.
I look at the sequence diagram of commands , is it between the
creationTool and the EditPart or between the EditPart and the
CreationEditPolicy?

Thank in advance
Marie
Re: How to change source and target of a link in the generated code? [message #227962 is a reply to message #227944] Tue, 28 April 2009 09:21 Go to previous messageGo to next message
Eclipse UserFriend
Hello Marie,

> thank you very much for your answer , I have commented the method
> refreshConnections() in my PackageCanonicalEditPolicy and I had
> ce1.setOwner(newElement); in the method
Well, you've switched off connection updating process. It's up to you, but
I recomment you try switching it back. In case you'll end up with loosing
newly created link i suggest you to modify diagram updater code called from
refreshConnections() to properly update this kind of connections.


> However , I have another question: I want to add a window where user
> will can choose an Property in a dynamical list and add it into a
> PropertyCompartment inside my component. Which class can I use for my
> window?
I suppose you have to imlement custom dialog + pup it up on pressing some
key compination or on any other event..

concerning new element creation - you can either use requests + EditPart
to get a command and execute it (like toolbar tool) or just create new commad
creating your element and corresponding notation model element using EMF API.

-----------------
Alex Shatalin
Re: How to change source and target of a link in the generated code? [message #228075 is a reply to message #227962] Tue, 28 April 2009 12:31 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alex,
Thank you for your answer.
I try to follow your advice, I try to add if for the command of the
component in the PackageItemSemanticEditPolicy.
I had a protected Command getCreateRelationshipCommand( CreateRelationShip
req) in the PackageItemSemanticEditPolicy
but the problem is that the commands are ever created in the port which
graphically are the end of the connection.
How can I manage this in order to arrange the method refreshConnection()
in the PackageCanonicalEditPart?

I have also another problem : I have two Connector, an Assembly Connector
and a Delegation Connector which are distinguished by the value of their
kind attribute. But the Delegation Connector does not appear in the
diagram and in the xmi file is kind is 'assembly'!Wheras, with comment
in refreshConnection() I don't have any problem with the Assembly
Connector.

Could you help me for these problems?

Thank you in advance
Marie
Re: How to change source and target of a link in the generated code? [message #228177 is a reply to message #228075] Wed, 29 April 2009 05:49 Go to previous messageGo to next message
Eclipse UserFriend
Hello Marie,

> I had a protected Command getCreateRelationshipCommand(
> CreateRelationShip req) in the PackageItemSemanticEditPolicy
> but the problem is that the commands are ever created in the port
> which graphically are the end of the connection.
Not sure I understand you correctly here.. I'm suggesting you to throw away
incorerctly generated logic collecting exisitng Connector links from the
domain model (probably not taking into account port elements) and replace
it with the proper one - see generated collectAllLinks() method. The rest
should be done for you by already generated code - proper links will be created
by createConnections() method based on linkDescriptors and domain2NotationMap.

> I have also another problem : I have two Connector, an Assembly
> Connector and a Delegation Connector which are distinguished by the
> value of their kind attribute. But the Delegation Connector does not
> appear in the diagram and in the xmi file is kind is
> 'assembly'!Wheras, with comment in refreshConnection() I don't have
> any problem with the Assembly Connector.
Again, not sure I completely undersnand you. Do you have two different link
mappings for Assembly Connector and Delegation Connector links?

-----------------
Alex Shatalin
Re: How to change source and target of a link in the generated code? [message #228350 is a reply to message #228177] Wed, 29 April 2009 09:37 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alex,
I don't understand very well all the changes I had to do, I add manually
code in my PortItemSemanticEditPolicy in order to begin a connection with
a port and I changed the container of my connector to a Package.

I have two differents links mapping for my two connector, I try to
distinguish them with their kind :
Constraint self.kind = ConnectorKind::assembly + the Figure Seq Initialier
( idem for the other connector), is there a problem with the
initialization of the constraints?

Could you help me?
Thank you in advance
Marie
Re: How to change source and target of a link in the generated code? [message #228399 is a reply to message #228350] Wed, 29 April 2009 10:48 Go to previous messageGo to next message
Eclipse UserFriend
Hello Marie,

> code in my PortItemSemanticEditPolicy in order to begin a connection
> with a port and I changed the container of my connector to a Package.
So, these modifications should be reflected in DiagramUpdated - otherwise
generated code still suppose your connectino to begin with original source
and be contained in an origical container.. Try checking updater code 0 it
is rather straightforward. Idea is to collect all the connection existing
in cuddent state of domain model and update diagram in accordance (remove
diagram links wich was removed from the domain model and add links wich were
added).

> I have two differents links mapping for my two connector, I try to
> distinguish them with their kind : Constraint self.kind =
> ConnectorKind::assembly + the Figure Seq Initialier ( idem for the
> other connector), is there a problem with the initialization of the
> constraints?
If you have properly specified constraints/Feature Seq. Initializers then
it should work.

-----------------
Alex Shatalin
Re: How to change source and target of a link in the generated code? [message #228439 is a reply to message #228399] Wed, 29 April 2009 12:46 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alex,
Thank you very much for your answer.
The constraints of the Connectors does not seem to be well.
I add a constraint self.kind := ConnectorKind::ASSEMBLY but I think it
does not works and it keep the default value of the kind which is Assembly.
Could you help me for this problem?
Thank you in advance.
Marie
Re: How to change source and target of a link in the generated code? [message #228493 is a reply to message #228439] Thu, 30 April 2009 06:58 Go to previous messageGo to next message
Eclipse UserFriend
Hello Marie,

Try:
self.kind = <package>::ConnectorKind::ASSEMBLY

+ feature sequence initializer: <package>::ConnectorKind::ASSEMBLY (associated
with appropriate feature - "kind"

-----------------
Alex Shatalin
Re: How to change source and target of a link in the generated code? [message #228509 is a reply to message #228493] Thu, 30 April 2009 08:43 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alex,
I try the modifications but I always have only an assembly connector even
if I try to create an delegation connector.
Could you help me again for this problem?
Thank you in advance
Marie
Re: How to change source and target of a link in the generated code? [message #228517 is a reply to message #228509] Thu, 30 April 2009 09:21 Go to previous messageGo to next message
Eclipse UserFriend
Hello Marie,

Put a breakpoint into ???ElementTypes.init_??????() to check if the expression
was executed and what was the result of execution.

-----------------
Alex Shatalin
Re: How to change source and target of a link in the generated code? [message #228579 is a reply to message #228517] Thu, 30 April 2009 12:29 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alex,
The OCL seems to be nice, I can add inthe xmi file a connector with
kind="delegation", the problem is that I have a problem when I try to
create a delegation connector AssertionFailedException. I wonder if the
two connectors are well distinguished between its?
Could you help me for these problem?
Thanks in advance
Marie
Re: How to change source and target of a link in the generated code? [message #229352 is a reply to message #228579] Mon, 11 May 2009 10:11 Go to previous messageGo to next message
Eclipse UserFriend
Hello Marie,

>>Put a breakpoint into ???ElementTypes.init_??????() to check if the expression
was executed and what was the result of execution.
> The OCL seems to be nice, I can add inthe xmi file a connector with
If OCL is fine then why corresponding value was not used in init_???() method?
Can you check generated code as I suggested?
Here is an example of init_??() method generated for Ecore diagram example:

public static void init_EReference_4002(EReference instance) {
try {
Object value_0 = EcoreOCLFactory.getExpression("false", EcorePackage.eINSTANCE.getEReference()).evaluate(instance);
instance.setContainment(((Boolean) value_0).booleanValue());
} catch (RuntimeException e) {
EcoreDiagramEditorPlugin.getInstance().logError("Element initialization
failed", e); //$NON-NLS-1$
}
}

As you can see OCL expression "false" was first evaluated there and then
used as an initial value for "containment" property. Similar code should
be generated for your diagram, so if OCL expression is working well then
appropriate value should be used to initialize specified feature/attribute...

> kind="delegation", the problem is that I have a problem when I try to
> create a delegation connector AssertionFailedException. I wonder if
> the two connectors are well distinguished between its?
Are you sure you've created not only constraint but proper Feature Seq. Initializer
for this element in .gmfmap model?

-----------------
Alex Shatalin
Re: How to change source and target of a link in the generated code? [message #229491 is a reply to message #229352] Tue, 12 May 2009 05:23 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alex,
The OCL contraints seems to be take in account at the initialization.In my
model the kind ConnectorKind::ASSEMBLY is the default value. When I try to
change the kind of my first connector to ConnectorKind::DELEGATION the
image of the connector change in my diagram and in the xmi file the kind
of this connector is "delegation" However,this initialization not seem to
distinguish the two connectors because in fact it have exactly the same
kind.I believe only one connector is take into account.
For initialization my code is :
try {
Object value_0 = editor.diagram.expressions.UmlOCLFactory.getExpression(
"self.kind = ConnectorKind::delegation",
editor.XXXPackage.eINSTANCE
.getConnector()).evaluate(instance);

value_0 = editor.diagram.expressions.UmlAbstractExpression
.performCast(value_0,
editor.XXXPackage.eINSTANCE
.getConnectorKind());
instance
.setKind(editor.ConnectorKind.DELEGATION) ;
} catch (RuntimeException e) {


What can I add in order to distinguish these two connectors?

Thank you in advance
Marie
Re: How to change source and target of a link in the generated code? [message #229760 is a reply to message #229491] Tue, 12 May 2009 11:39 Go to previous messageGo to next message
Eclipse UserFriend
Hello Marie,

> of this connector is "delegation" However,this initialization not seem
> to distinguish the two connectors because in fact it have exactly the
> same kind.
Sorry, I do not understand you. Do you mean the following code will be executed
successfully, but the connection Kind will stay "ASSEMBLY"?..

> Object value_0 = editor.diagram.expressions.UmlOCLFactory.getExpression("self.kind
= ConnectorKind::delegation", editor.XXXPackage.eINSTANCE.getConnector()).evaluate(instanc e);
> value_0 = editor.diagram.expressions.UmlAbstractExpression.performCast (value_0,
editor.XXXPackage.eINSTANCE.getConnectorKind());
> instance.setKind(editor.ConnectorKind.DELEGATION) ;

-----------------
Alex Shatalin
Re: How to change source and target of a link in the generated code? [message #229806 is a reply to message #229760] Tue, 12 May 2009 11:59 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alex,
In fact I have two connectors that are initialized like this:


/**
* @generated
*/
public static void init_Connector_4001(
editor.Connector instance) {
try {
Object value_0 = editor.diagram.expressions.XXXOCLFactory
.getExpression("ConnectorKind::delegation")
editor.XXXPackage.eINSTANCE
.getConnector()).evaluate(instance);

value_0 = editor.diagram.expressions.UmlAbstractExpression
.performCast(value_0,
editor.XXXPackage.eINSTANCE
.getConnectorKind());
instance
.setKind((editor.ConnectorKind) value_0);
} catch (RuntimeException e) {
editor.diagram.part.XXXDiagramEditorPlugin
.getInstance().logError("Element initialization failed", e);
//$NON-NLS-1$
}
}

/**
* @generated
*/
public static void init_Connector_4002(
editor.Connector instance) {
try {
Object value_0 = editor.diagram.expressions.XXXOCLFactory
.getExpression(
"ConnectorKind::assembly",
editor.XXXPackage.eINSTANCE
.getConnector()).evaluate(instance);

value_0 = editor.diagram.expressions.XXXAbstractExpression
.performCast(value_0,
editor.XXXPackage.eINSTANCE
.getConnectorKind());
instance
.setKind((editor.ConnectorKind) value_0);
} catch (RuntimeException e) {
editor.diagram.part.XXXDiagramEditorPlugin
.getInstance().logError("Element initialization failed", e);
//$NON-NLS-1$
}
}

Then I try to create a connection with each connector.However when I open
the xmi file there is two connector like this:
<ownedElement xsi:type="uml:Connector" kind="delegation">
<ownedElement xsi:type="uml:ConnectorEnd"
role="//@ownedElement.0/@ownedElement.0"/>
<ownedElement xsi:type="uml:ConnectorEnd"
role="//@ownedElement.1/@ownedElement.0"/>
</ownedElement>
<ownedElement xsi:type="uml:Connector" kind="delegation">
<ownedElement xsi:type="uml:ConnectorEnd"
role="//@ownedElement.0/@ownedElement.0"/>
<ownedElement xsi:type="uml:ConnectorEnd"
role="//@ownedElement.1/@ownedElement.0"/>
</ownedElement>

Normally it should not have the same kind.
Could you help me for this problem?
Thank you in advance
Marie
Re: How to change source and target of a link in the generated code? [message #229814 is a reply to message #229806] Tue, 12 May 2009 12:05 Go to previous messageGo to next message
Eclipse UserFriend
Hello Marie,

Then try to debug this method:

> /**
> * @generated
> */
> public static void init_Connector_4002(editor.Connector instance) {
....

to check if appropriate kind was successfully set to the connection or not.
In case the kind was set then you have to check where this kind was reset
for just created connection.

-----------------
Alex Shatalin
Re: How to change source and target of a link in the generated code? [message #229830 is a reply to message #229814] Tue, 12 May 2009 12:29 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alex,
I cannot debug the init_Connector_4002 because I have the exception

org.eclipse.core.commands.ExecutionException: While executing the
operation, an exception occurred
at
org.eclipse.core.commands.operations.DefaultOperationHistory .execute(DefaultOperationHistory.java:519)
at
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack .execute(DiagramCommandStack.java:205)
at
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack .execute(DiagramCommandStack.java:168)
at
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack .execute(DiagramCommandStack.java:155)
at
org.eclipse.gef.tools.AbstractTool.executeCommand(AbstractTo ol.java:399)
at
org.eclipse.gef.tools.AbstractTool.executeCurrentCommand(Abs tractTool.java:411)
at
org.eclipse.gmf.runtime.diagram.ui.tools.ConnectionCreationT ool.handleCreateConnection(ConnectionCreationTool.java:341)
at
org.eclipse.gmf.runtime.diagram.ui.tools.ConnectionCreationT ool.handleButtonUp(ConnectionCreationTool.java:181)
at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java :1064)
at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:263)
at
org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMouse Released(DomainEventDispatcher.java:374)
at
org.eclipse.draw2d.LightweightSystem$EventHandler.mouseUp(Li ghtweightSystem.java:538)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:207)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3401)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3033)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2384)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2348)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:22 00)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:495)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:490)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:113)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:193)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:386)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Caused by: org.eclipse.core.runtime.AssertionFailedException: null
argument:failed to create a view
at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:86)
at
org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand.do ExecuteWithResult(CreateCommand.java:99)
at
org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTr ansactionalCommand.doExecute(AbstractTransactionalCommand.ja va:247)
at
org.eclipse.emf.workspace.AbstractEMFOperation.execute(Abstr actEMFOperation.java:169)
at
org.eclipse.gmf.runtime.common.core.command.CompositeCommand .doExecuteWithResult(CompositeCommand.java:403)
at
org.eclipse.gmf.runtime.common.core.command.AbstractCommand. execute(AbstractCommand.java:135)
at
org.eclipse.gmf.runtime.common.core.command.CompositeCommand .doExecuteWithResult(CompositeCommand.java:403)
at
org.eclipse.gmf.runtime.common.core.command.AbstractCommand. execute(AbstractCommand.java:135)
at
org.eclipse.gmf.runtime.common.core.command.CompositeCommand .doExecuteWithResult(CompositeCommand.java:403)
at
org.eclipse.gmf.runtime.common.core.command.AbstractCommand. execute(AbstractCommand.java:135)
at
org.eclipse.core.commands.operations.DefaultOperationHistory .execute(DefaultOperationHistory.java:511)

I believe this exception is due to it cannot distinguish the two
connectors.
Could you help me for this problem?
Thank you in advance.
Marie
Re: How to change source and target of a link in the generated code? [message #229962 is a reply to message #229830] Wed, 13 May 2009 06:43 Go to previous messageGo to next message
Eclipse UserFriend
Hello Marie,

Looks like a view was not created.. Try to debug generated XXXViewProvider.createEdge()
method to See why corresponding View was not created.

> I believe this exception is due to it cannot distinguish the two
> connectors.
Yes, i think this is a reason for having incorrecty working code.

-----------------
Alex Shatalin
Re: How to change source and target of a link in the generated code? [message #230392 is a reply to message #229962] Fri, 15 May 2009 02:59 Go to previous message
Eclipse UserFriend
Hello ALex,
Thank you for all the answer and your time.
Regards,
Marie
Previous Topic:position of second image figure on NodeFigure
Next Topic:Display wizard when creating new node
Goto Forum:
  


Current Time: Fri Jul 18 15:51:17 EDT 2025

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

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

Back to the top