[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.gmf] Re: What is the right way to change the XXXDiagramEditPart IFigure?
|
- From: Vlad Ciubotariu <vcciubot@xxxxxxxxxxxx>
- Date: Tue, 16 Jan 2007 11:23:22 -0500
- Newsgroups: eclipse.modeling.gmf
- Organization: EclipseCorner
- User-agent: Pan/0.14.2.91 (As She Crawled Across the Table (Debian GNU/Linux))
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 },