Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » CanonicalConnectionEditPolicy.getSemanticChildrenList
CanonicalConnectionEditPolicy.getSemanticChildrenList [message #187453] Fri, 16 May 2008 11:12 Go to next message
Eclipse UserFriend
Originally posted by: Weitzel.B.gmx.net

Hi,

I want to use a CanonicalConnectionEditPolicy to ensure that changing my
semantic model reflects in the diagram.
Installing my new EditPolicy was no problem so far, but it does not work
properly. After investigating I found out that the commands generated by the
policy could not be executed.
This seems to be caused by getEdgeViewClass in the generated ViewProvider.

IElementType elementType = getSemanticElementType(semanticAdapter);

returns null because

private IElementType getSemanticElementType(IAdaptable semanticAdapter) {
if (semanticAdapter == null) {
return null;
}
return (IElementType) semanticAdapter.getAdapter(IElementType.class);
}

returns null because the semanticAdapter has no adapter for IElementType.

I hope this was not too confusing until now ;-)

All problems seem to origin from
MyCanonicalConnectionEditPolicy.getSemanticChildrenList which looks this
way:

@Override
protected List getSemanticConnectionsList() {
List<EObject> result = new ArrayList<EObject>();
MyNode node = (MyNode)getSemanticHost();
result.addAll(node.getMyEdges());
return result;
}

In other words: I return instances of my semantic model.
Is this intended by CanonicalConnectionEditPolicy.getSemanticChildrenList?
The documentation just says:

/**
* Return a list of semantic relationships contained inside this
* compartment.
* @return EObject list
*/
abstract protected List getSemanticConnectionsList();

Unfortunately I could not find any usage (expect returning an empty list).

Could someone please explain what I should return there? semantic model,
notation model, some specific emf-stuff?

Thanx for reading so far ;-)
Re: CanonicalConnectionEditPolicy.getSemanticChildrenList [message #187591 is a reply to message #187453] Sun, 18 May 2008 13:51 Go to previous message
Eclipse UserFriend
Originally posted by: Weitzel.B.gmx.net

A quick summary for my problem:
I want to synchronize my diagram with my business-model.
I use a subclass of CanonicalConnectionEditPolicy for this.
The CanonicalConnectionEditPolicy from GMF builds unexecutable commands.

Now the longer version:


I created a very easy example to understand this canonical behaviour:

In my example I have nodes (Mynode) and edges (Myedge), the edges have
source and target (Mynodes) and are contained in the sourcenode.
I want to change the businessmodell and reflect these changes via
CanonicalEditPolicies in the diagram. I turned synchronized on for the
diagram but this seems not to work for connections. So I have to use my
own CanonicalConnectionEditPolicy to reflect these changes. I build my
EditPolicyProvider, registered it and installed the policy below on all
Mynodes.



As far as I understood the CanonicalConnectionEditPolicy I should return
in getSemanticConnectionsList just the EObjects of my semantic links:


public class MynodeCanonicalEditPolicy extends
CanonicalConnectionEditPolicy {

@Override
protected List getSemanticConnectionsList() {
if (getSemanticHost() instanceof Mynode) {
Mynode mynode = (Mynode) getSemanticHost();
return mynode.getMyedges();
}
return Collections.EMPTY_LIST;
}

@Override
protected EObject getSourceElement(EObject relationship) {
if (relationship instanceof Myedge) {
Myedge myedge = (Myedge) relationship;
return myedge.getMysourcenode();
}
return null;
}

@Override
protected EObject getTargetElement(EObject relationship) {
if (relationship instanceof Myedge) {
Myedge myedge = (Myedge) relationship;
return myedge.getMytargetnode();
}
return null;
}

}

But this policy is not working, I think because of
CanonicalConnectionEditPolicy.createConnectionView(EObject connection, int
index) in the GMF-Framework. In this method is the creation of the request
for the new view and finally of the command.
This is done in these lines:

String factoryHint = getDefaultFactoryHint();
IAdaptable elementAdapter = new
CanonicalElementAdapter(connection,factoryHint);
CreateConnectionViewRequest ccr =
getCreateConnectionViewRequest(elementAdapter,
getFactoryHint(elementAdapter,factoryHint), index);

This CanonicalElementAdapter is an adapter just for Strings and EObjects:

/** Adds <code>String.class</tt> adaptablity to return a factory hint. */
protected static final class CanonicalElementAdapter extends
EObjectAdapter {
private String _hint;

/**
* constructor
* @param element
* @param hint
*/
public CanonicalElementAdapter( EObject element, String hint ) {
super(element);
_hint = hint;
}

/** Adds <code>String.class</tt> adaptablity. */
public Object getAdapter(Class adapter) {
if ( adapter.equals(String.class) ) {
return _hint;
}
return super.getAdapter(adapter);
}
}


When the CreateViewCommand from the CreateConnectionViewRequest is tested
for canExecute() the corresponding view class is searched in the generated
MymodelViewProvider. To do this the adapter is used in
getSemanticElementType:

/**
* @generated
*/
private IElementType getSemanticElementType(IAdaptable semanticAdapter) {
if (semanticAdapter == null) {
return null;
}
return (IElementType) semanticAdapter.getAdapter(IElementType.class);
}

This returns null because the CanonicalElementAdapter has no adapter for
IElementType. So no view can be found, the command is not executable, my
policy is not worling and the diagram will be out of sync.


Can someone please help me with this problem?
Is it really a problem in the CanonicalConnectionEditPolicy?
How can I find a workaround for this?

Greetings
Balthasar
Previous Topic:Retrieve the active diagram instance
Next Topic:Manage child of an element associated to connection
Goto Forum:
  


Current Time: Fri Mar 29 11:56:43 GMT 2024

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

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

Back to the top