|
Re: Pulling attribute from a referenced object [message #58243 is a reply to message #57900] |
Mon, 02 October 2006 13:43 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: vcciubot.uwaterloo.ca
Assuming you already show some attribute in your diagram and you want this
attribute edit part to `point' somewhere else:
You should override resolveSemanticElement() of your attribute edit part
to return the referenced object (look to in GraphicalEditPart to see how
it's done).
This method in the attribute editPart passes the referenced
object to the parser:
public String getEditText() {
EObject element = resolveSemanticElement();
return (element == null) ? "" //$NON-NLS-1$
: getParser().getEditString(
new EObjectAdapter(element),
getParserOptions().intValue());
}
The parser is set by this other method:
public IParser getParser() {
if (parser == null) {
String parserHint = ((View)getModel()).getType();
EObject element = resolveSemanticElement();
if (element != null) {
ParserHintAdapter hintAdapter =
new ParserHintAdapter(element, parserHint);
parser = ParserService.getInstance().getParser(hintAdapter);
}
}
return parser;
}
It calls the ParserService which in turn calls your ParserProvider. So you
might have to extend the generated Provider to handle this attribute, but
it's very easy.
This other method, keeps synchs with the model:
protected void addSemanticListeners() {
if (getParser() instanceof ISemanticParser) {
EObject semanticElement = resolveSemanticElement();
parserElements =
((ISemanticParser) getParser()).getSemanticElementsBeingParsed(semanticElement) ;
for (int i = 0; i < parserElements.size(); i++)
addListenerFilter("SemanticModel" + i, this,(EObject)parserElements.get(i)); //$NON-NLS-1$
} else
super.addSemanticListeners();
}
On Sat, 30 Sep 2006 19:58:02 -0400, John wrote:
> Hello all, I have a question about how to pull the contents of an attribute
> from a referenced object into a label. I've looked around the web and this
> group and haven't seen anything yet. Here's the scoop:
>
> I have the following classes modeled in EMF:
>
> Person
> lastName String
> firstName String
>
> Commander
> startPeriod Date
> endPeriod Date
> kind String
> person (single reference to Person)
>
> Command
> startDate Date
> commanders (List of Commanders)
>
> I've started modeling this in GMF, and so far have been able to model a
> figure based on Command with a fixed title "Command" at the top, followed by
> a compartment listing "kind" for each Commander in the Command object. This
> was pretty simple to do following along with the GMF tutorial.
>
> What I'd really like to be able to do is have the list in that compartment
> display the lastName of each Person via the person reference in Commander
> rather than the simple attribute "kind", but I'm not seeing how something
> like that is done. Can anyone give me some guidance?
>
> Thanks!!!
|
|
|
Powered by
FUDForum. Page generated in 0.03262 seconds