Home » Modeling » GMF (Graphical Modeling Framework) » What is the right way to change the XXXDiagramEditPart IFigure?
What is the right way to change the XXXDiagramEditPart IFigure? [message #93273] |
Tue, 16 January 2007 15:12 |
Eclipse User |
|
|
|
Originally posted by: NOSAPM.xyz.com
A straightforward brute force approach is to override its createFigure(...),
and that the way I would do it in GEF, but maybe GMF offers a more
elegant workaround.
And does changing the IFigure necessarily require changing the View model
element as well?
Thanks,
Theo
|
|
|
Re: What is the right way to change the XXXDiagramEditPart IFigure? [message #93289 is a reply to message #93273] |
Tue, 16 January 2007 16:01 |
Eclipse User |
|
|
|
Originally posted by: 5d5.mail.ru
FigureViewmap allows you to specify custom figure in gmfgen model. Just
use it instead of default InnerClassViewmap.
Theo wrote:
> A straightforward brute force approach is to override its createFigure(...),
> and that the way I would do it in GEF, but maybe GMF offers a more
> elegant workaround.
> And does changing the IFigure necessarily require changing the View model
> element as well?
> Thanks,
> Theo
>
>
|
|
|
Re: What is the right way to change the XXXDiagramEditPart IFigure? [message #93335 is a reply to message #93273] |
Tue, 16 January 2007 16:23 |
Eclipse User |
|
|
|
Originally posted by: vcciubot.uwaterloo.ca
On Tue, 16 Jan 2007 10:12:26 -0500, Theo wrote:
> A straightforward brute force approach is to override its createFigure(...),
> and that the way I would do it in GEF, but maybe GMF offers a more
> elegant workaround.
For ShapeNodeEditParts you should override createNodeFigure(). For
AbstractBorderedShapeEditParts the method is createMainFigure().
> And does changing the IFigure necessarily require changing the View
> model element as well?
The model-view-controller paradigm ensures the view is independent of the
figure you use. However, if you have a compartment view it will probably
be more useful to have a compartment editpart and so on a compartment
figure.
The information flow is as follows:
(1) SemanticHint (viewID or ElementType) -> ViewProvider -> ViewFactory
-> View
(2) View -> EditPartFactory to return an EditPart
Your viewProvider has to deal with two types of hints:
(a) ElementTypes - this is the case when you use a tool or when a view is
created by a canonical policy
(b) view types, which are strings, when you create views from a view
factory
ElementTypes have semantic hint in plugin.xml (a string). So you can map
from an ElementType to a string hint.
I've found it's easier to have the following structure for the code:
ViewProvider:
protected Class getViewClass(IAdaptable semanticAdapter, String semanticHint) {
Class clazz = null;
Map viewMap = Bluenose2GMFMapping.getViewMap();
String viewType = semanticHint;
if (viewType != null && viewType.equals("") == false) {
clazz = (Class) viewMap.get(viewType);
}
// this case is possible when created by a canonical policy
if (clazz == null) {
viewType = Bluenose2VisualIDHelper.getSemanticHint(semanticAdapter);
clazz = (Class) viewMap.get(viewType);
}
VisualIDHelper:
public static String getSemanticHint(IAdaptable semanticAdapter) {
EClass semanticType = getSemanticEClass(semanticAdapter);
EObject semanticElement = getSemanticElement(semanticAdapter);
if (semanticElement == null)
return Bluenose2VisualIDs.UNKNOWN_VISUAL_ID;
IHintedType elementType = (IHintedType) ElementTypeRegistry.getInstance()
.getElementType(
semanticType,
ClientContextManager.getInstance().getClientContextFor(
semanticElement));
return elementType.getSemanticHint();
}
Mapping:
static {
Object[][] _map = {
/* diagram */
{ DIAGRAM_VISUAL_ID, Bluenose2DiagramViewFactory.class,
Bluenose2DiagramEditPart.class },
/* blocks */
{ ARBITER_VISUAL_ID, BlockViewFactory.class,
BlockEditPart.class },
{ MK_RA_VISUAL_ID, BlockViewFactory.class, BlockEditPart.class },
{ DATAPATH_VISUAL_ID, BlockViewFactory.class,
BlockEditPart.class },
{ INTERFACE_NEXT_VISUAL_ID, BlockViewFactory.class,
BlockEditPart.class },
{ INTERFACE_NEXT_REQ_ACC_VISUAL_ID, BlockViewFactory.class,
BlockEditPart.class },
|
|
|
Re: What is the right way to change the XXXDiagramEditPart IFigure? [message #93402 is a reply to message #93289] |
Tue, 16 January 2007 18:35 |
Eclipse User |
|
|
|
Originally posted by: NOSAPM.xyz.com
Hi Dmitry,
I tried this trick with "Gen Diagram XXXEditPart" / "Figure Viewmap ..."
Unfortunately, no matter what you enter as Diagram Figure in the .gmfgen
the generated editor is the same file by file, char by char.
So, I guess tampering with the Diagram Figure simply isn't implemented yet
in codegen
I tried it also with label mapping "Gen Node Label XXXEditPart" / "Parent
Assigned Viewmap".
I changed the default
org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel
to a plain
org.eclipse.draw2d.Label
In this case the new figure type is correctly used in setLabel() of the
child label's EditPart, that is,
public void setLabel(WrapLabel figure)
became
public void setLabel(Label figure) ...
, but the parent's EditPart, which is supposed to provide the figure
instance through
"Access to parent figure's child", still uses WrapLabel = = errors.
I think that this approach for now would only work with nodes ->
"GenTop Level Node ..." / "Inner Class Viewmap ..." / "Class Body"
since it is just a string pasted mot-a-mot by the generator.
Good luck,
Theo
"Dmitry Stadnik" <5d5@mail.ru> wrote in message
news:eoistm$oel$1@utils.eclipse.org...
> FigureViewmap allows you to specify custom figure in gmfgen model. Just
> use it instead of default InnerClassViewmap.
>
> Theo wrote:
>> A straightforward brute force approach is to override its
>> createFigure(...),
>> and that the way I would do it in GEF, but maybe GMF offers a more
>> elegant workaround.
>> And does changing the IFigure necessarily require changing the View model
>> element as well?
>> Thanks,
>> Theo
|
|
|
Re: What is the right way to change the XXXDiagramEditPart IFigure? [message #93428 is a reply to message #93335] |
Tue, 16 January 2007 19:19 |
Eclipse User |
|
|
|
Originally posted by: NOSAPM.xyz.com
Thanks Vlad. The flow control snippet is pretty neat
"Vlad Ciubotariu" <vcciubot@uwaterloo.ca> wrote in message
news:pan.2007.01.16.16.23.22.57774@uwaterloo.ca...
> On Tue, 16 Jan 2007 10:12:26 -0500, Theo wrote:
>
>> A straightforward brute force approach is to override its
>> createFigure(...),
>> and that the way I would do it in GEF, but maybe GMF offers a more
>> elegant workaround.
>
> For ShapeNodeEditParts you should override createNodeFigure(). For
> AbstractBorderedShapeEditParts the method is createMainFigure().
>
>
>> And does changing the IFigure necessarily require changing the View
>> model element as well?
>
> The model-view-controller paradigm ensures the view is independent of the
> figure you use. However, if you have a compartment view it will probably
> be more useful to have a compartment editpart and so on a compartment
> figure.
>
> The information flow is as follows:
>
> (1) SemanticHint (viewID or ElementType) -> ViewProvider -> ViewFactory
> -> View
>
> (2) View -> EditPartFactory to return an EditPart
>
> Your viewProvider has to deal with two types of hints:
> (a) ElementTypes - this is the case when you use a tool or when a view is
> created by a canonical policy
>
> (b) view types, which are strings, when you create views from a view
> factory
>
> ElementTypes have semantic hint in plugin.xml (a string). So you can map
> from an ElementType to a string hint.
>
> I've found it's easier to have the following structure for the code:
> ViewProvider:
>
> protected Class getViewClass(IAdaptable semanticAdapter, String
> semanticHint) {
> Class clazz = null;
> Map viewMap = Bluenose2GMFMapping.getViewMap();
>
> String viewType = semanticHint;
>
> if (viewType != null && viewType.equals("") == false) {
> clazz = (Class) viewMap.get(viewType);
> }
> // this case is possible when created by a canonical policy
> if (clazz == null) {
> viewType = Bluenose2VisualIDHelper.getSemanticHint(semanticAdapter);
> clazz = (Class) viewMap.get(viewType);
> }
>
> VisualIDHelper:
>
> public static String getSemanticHint(IAdaptable semanticAdapter) {
> EClass semanticType = getSemanticEClass(semanticAdapter);
> EObject semanticElement = getSemanticElement(semanticAdapter);
> if (semanticElement == null)
> return Bluenose2VisualIDs.UNKNOWN_VISUAL_ID;
>
> IHintedType elementType = (IHintedType) ElementTypeRegistry.getInstance()
> .getElementType(
> semanticType,
> ClientContextManager.getInstance().getClientContextFor(
> semanticElement));
>
> return elementType.getSemanticHint();
> }
>
> Mapping:
> static {
>
> Object[][] _map = {
> /* diagram */
> { DIAGRAM_VISUAL_ID, Bluenose2DiagramViewFactory.class,
> Bluenose2DiagramEditPart.class },
>
> /* blocks */
> { ARBITER_VISUAL_ID, BlockViewFactory.class,
> BlockEditPart.class },
>
> { MK_RA_VISUAL_ID, BlockViewFactory.class, BlockEditPart.class },
>
> { DATAPATH_VISUAL_ID, BlockViewFactory.class,
> BlockEditPart.class },
>
> { INTERFACE_NEXT_VISUAL_ID, BlockViewFactory.class,
> BlockEditPart.class },
>
> { INTERFACE_NEXT_REQ_ACC_VISUAL_ID, BlockViewFactory.class,
> BlockEditPart.class },
>
>
>
>
|
|
|
Goto Forum:
Current Time: Fri Nov 08 23:16:29 GMT 2024
Powered by FUDForum. Page generated in 0.03623 seconds
|