Can't drag link to superclass of the destination [message #223943] |
Wed, 01 April 2009 17:30 |
Martin Mising name Messages: 32 Registered: July 2009 |
Member |
|
|
Hi,
I am trying to work out how to draw a link on the diagram to the
superclass of the destination. (i.e. drag the little square handle on the
source to the destination) .
This works fine when I specifically define the reference to be exactly the
destination class, but I want the reference definition to be the
superclass of the destination, if I do this dragging the link no longer
works.
I posted a message about this a few weeks ago and Alex Shatalin kindly
confirmed that this functionality should work and suggested some things
for me to try.
After a lot of work I have now found how to patch the diagram code
generated by gmf so that it works. This involves 4 methods in:
package: mathModel.diagram.providers
class: MathModelModelingAssistantProvider
The problem is that my real code is a lot more complicated than this and I
don't really want to do a major edit of the code. Also I find it hard to
believe that there is a bug this fundamental in the gmf code? I must be
doing something silly and I would appreciate some help to find out what it
is.
Below I have put my example and the the modification that I have to do to
the code to get it to work, also more info here:
http://www.euclideanspace.com/software/development/eclipse/g mf/linkTargetMapping/
Thanks,
Martin
------------------------------------------------------------ ---------------
skeleton example:
In order to test this out I have defined 4 very simple classes using the
annotated Interfaces below. I want to drag a link from a MSubNodeS
instance to a MSubNodeD instance and for this to put a reference to the
MSubNodeD into MSubNodeS.link.
This won't work as I have it defined below, but it will work if I change:
MSubNode getLink();
to
MSubNodeD getLink();
What I would like is if I drag a link from a MSubNodeS instance to a
MSubNodeD instance then it will set link to be a MSubNodeD reference and
if I drag a link from a MSubNodeS instance to another MSubNodeS instance
then it will set link to be a MSubNodeS reference.
Base class: /** @model */
public interface MNode extends EObject {
/** @model */
String getName();
/** @model containment="true" */
EList<MSubNodeS> getSubNodeS();
/** @model containment="true" */
EList<MSubNodeD> getSubNodeD();
}
Super Class: /** @model */
public interface MSubNode extends EObject {
/** @model */
String getName();
}
Destination Class: /** @model */
public interface MSubNodeD extends MSubNode {
}
Source Class: /** @model */
public interface MSubNodeS extends MSubNode {
/** @model */
MSubNode getLink();
}
-------------------------------------
patch to code generated:
package: mathModel.diagram.providers
class: MathModelModelingAssistantProvider
from: these are the 4 methods generated by gmf from the interfaces above,
with this code link drag does not work:
public List getRelTypesOnTarget(IAdaptable target) {
IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target
.getAdapter(IGraphicalEditPart.class);
return Collections.EMPTY_LIST;
}
public List getRelTypesOnSourceAndTarget(IAdaptable source,
IAdaptable target) {
IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source
.getAdapter(IGraphicalEditPart.class);
IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target
.getAdapter(IGraphicalEditPart.class);
if (sourceEditPart instanceof
mathModel.diagram.edit.parts.MSubNodeSEditPart) {
List types = new ArrayList();
return types;
}
return Collections.EMPTY_LIST;
}
public List getTypesForSource(IAdaptable target,
IElementType relationshipType) {
IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target
.getAdapter(IGraphicalEditPart.class);
return Collections.EMPTY_LIST;
}
public List getTypesForTarget(IAdaptable source,
IElementType relationshipType) {
IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source
.getAdapter(IGraphicalEditPart.class);
if (sourceEditPart instanceof
mathModel.diagram.edit.parts.MSubNodeSEditPart) {
List types = new ArrayList();
return types;
}
return Collections.EMPTY_LIST;
}
------------------------------------------------------------ ---------
to: this is how I have to edit the 4 methods to get link drag to work:
public List getRelTypesOnTarget(IAdaptable target) {
IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target
.getAdapter(IGraphicalEditPart.class);
if (targetEditPart instanceof
mathModel.diagram.edit.parts.MSubNodeDEditPart) {
List types = new ArrayList();
types.add(mathModel.diagram.providers.MathModelElementTypes. MSubNodeSLink_3001);
return types;
}
return Collections.EMPTY_LIST;
}
/**
* @generated
*/
public List getRelTypesOnSourceAndTarget(IAdaptable source,
IAdaptable target) {
IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source
.getAdapter(IGraphicalEditPart.class);
IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target
.getAdapter(IGraphicalEditPart.class);
if (sourceEditPart instanceof
mathModel.diagram.edit.parts.MSubNodeSEditPart) {
List types = new ArrayList();
if (targetEditPart instanceof
mathModel.diagram.edit.parts.MSubNodeDEditPart) {
types.add(mathModel.diagram.providers.MathModelElementTypes. MSubNodeSLink_3001);
}
return types;
}
return Collections.EMPTY_LIST;
}
/**
* @generated
*/
public List getTypesForSource(IAdaptable target,
IElementType relationshipType) {
IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target
.getAdapter(IGraphicalEditPart.class);
if (targetEditPart instanceof
mathModel.diagram.edit.parts.MSubNodeDEditPart) {
List types = new ArrayList();
if (relationshipType ==
mathModel.diagram.providers.MathModelElementTypes.MSubNodeSL ink_3001) {
types.add(mathModel.diagram.providers.MathModelElementTypes. MSubNodeS_1002);
}
return types;
}
return Collections.EMPTY_LIST;
}
/**
* @generated
*/
public List getTypesForTarget(IAdaptable source,
IElementType relationshipType) {
IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source
.getAdapter(IGraphicalEditPart.class);
if (sourceEditPart instanceof
mathModel.diagram.edit.parts.MSubNodeSEditPart) {
List types = new ArrayList();
if (relationshipType ==
mathModel.diagram.providers.MathModelElementTypes.MSubNodeSL ink_3001) {
types.add(mathModel.diagram.providers.MathModelElementTypes. MSubNodeD_1001);
}
return types;
}
return Collections.EMPTY_LIST;
}
|
|
|
Powered by
FUDForum. Page generated in 0.03063 seconds