Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Solution: alternative label attribute
Solution: alternative label attribute [message #550061] Thu, 29 July 2010 01:28 Go to next message
Pantelis Petridis is currently offline Pantelis PetridisFriend
Messages: 10
Registered: February 2010
Junior Member
A would just like to share a solution to a GMF problem I came across, in
case it helps someone.

In a GMF editor we have created, we needed to display a node's A
attribute in a label, and if that was unset or empty, we wanted to
display attribute B. There seemed to be no way to provide this "choice"
behavior. (Please do correct me if i am wrong, i would like to know if
there is a better solution than the one below). To achieve this, we have
added the "OR" keyword support to message_format parser.

In the "Visual representation" section of Feature label mapping, we
first set the "edit method" and "view method" attributes to
"message_format". We also set "view pattern" to "{0} OR {1}", where {0}
is the A attribute and {1} the B attribute respectively. We then
modified the MessageFormatParser.java class located in
xxx.diagram.parsers package as follows:

/**
* @generated NOT
*/
private MessageFormat[] viewProcessors;

/**
* @generated NOT
*/
public void setViewPattern(String viewPattern) {
super.setViewPattern(viewPattern);
viewProcessors = null;
}

/**
* @generated NOT
*/
protected MessageFormat[] getViewProcessor() {
if (viewProcessors == null) {
String[] viewPatterns = new String[1];
if (getViewPattern() == null) {
viewPatterns[0] = getDefaultPattern();
} else {
viewPatterns = getViewPattern().trim().split(" OR ");
}

viewProcessors = new MessageFormat[viewPatterns.length];
for (int i = 0; i < viewPatterns.length; i++) {
viewProcessors[i] = new MessageFormat(viewPatterns[i]);
}
}
return viewProcessors;
}

/**
* @generated NOT
*/
public String getPrintString(IAdaptable adapter, int flags) {
String ret = "";
EObject element = (EObject) adapter.getAdapter(EObject.class);
for (int i = 0; i < getViewProcessor().length; i++) {
ret = (getViewProcessor())[i].format(getValues(element),
new StringBuffer(), new FieldPosition(0)).toString();
if (ret != null && ret.length() != 0) {
break;
}
}
return ret;
}

Simple, but i hope it helps someone

Pantelis
Re: Solution: alternative label attribute [message #550167 is a reply to message #550061] Thu, 29 July 2010 12:44 Go to previous messageGo to next message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
Hi Pantelis,

this is a nice solution. Thanks for posting it! However, I think it would only work for alternative attributes within the same domain element, wouldn't it?

In case you need a more flexible approach, please check out this blog post I wrote.

Cheers
Rob
Re: Solution: alternative label attribute [message #550283 is a reply to message #550167] Thu, 29 July 2010 18:06 Go to previous message
Pantelis Petridis is currently offline Pantelis PetridisFriend
Messages: 10
Registered: February 2010
Junior Member
yes, this only works for a single domain element, which in my case is
what I needed! Thanks for the blog link! I have used your
sharedEditingDomain solution in the past and it works great!

Pantelis

On 29/7/2010 3:44 μμ, Robert Wloch wrote:
> Hi Pantelis,
>
> this is a nice solution. Thanks for posting it! However, I think it
> would only work for alternative attributes within the same domain
> element, wouldn't it?
>
> In case you need a more flexible approach, please check out
> http://blogs.itemis.de/wloch/?p=252 I wrote.
>
> Cheers
> Rob
Previous Topic:toggle (checkable) menu item from popup menu
Next Topic:Add link (contained by canvas element) between two nodes not contained by canvas element
Goto Forum:
  


Current Time: Wed May 22 05:16:28 GMT 2024

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

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

Back to the top