Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Modify labels for an element
Modify labels for an element [message #420464] Tue, 01 July 2008 11:17 Go to next message
nospam is currently offline nospamFriend
Messages: 21
Registered: July 2009
Junior Member
I'm using GMF to generate an editor. I have some references to
org.eclipse.uml2.uml.Property in the domain model that I'm using.

In the Properties View I have a drop-down list of Properties. Their labels
consist of:
<Property> propertyName : propertyType
I would like to add the name of the Class that contains the Property to
the label, e.g.:
<Property> propertyName : propertyType <className>

Is there an easy way to do this?
Re: Modify labels for an element [message #420469 is a reply to message #420464] Tue, 01 July 2008 11:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
W.F.

I sounds like you'd want to specialize the getText method of the
PropertyItemProvider. You'd then need a specialized
UMLItemProviderAdapterFactory and take steps to ensure that one is used
instead of the one provided directly by the UML2 project.


W.F. wrote:
> I'm using GMF to generate an editor. I have some references to
> org.eclipse.uml2.uml.Property in the domain model that I'm using.
>
> In the Properties View I have a drop-down list of Properties. Their
> labels consist of:
> <Property> propertyName : propertyType
> I would like to add the name of the Class that contains the Property
> to the label, e.g.:
> <Property> propertyName : propertyType <className>
>
> Is there an easy way to do this?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Modify labels for an element [message #420473 is a reply to message #420469] Tue, 01 July 2008 12:23 Go to previous messageGo to next message
nospam is currently offline nospamFriend
Messages: 21
Registered: July 2009
Junior Member
Ed Merks wrote:

> W.F.

> I sounds like you'd want to specialize the getText method of the
> PropertyItemProvider. You'd then need a specialized
> UMLItemProviderAdapterFactory and take steps to ensure that one is used
> instead of the one provided directly by the UML2 project.


OK, it's all clear until:
"take steps to ensure that one is used instead of the one provided
directly by the UML2 project"

Here's what I have in the .edit project generated by GMF:

protected void addXXXPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
getResourceLocator(),
getString("..."),
getString("...", "...", "..."),
XXXPackage.Literals.XXX,
true,
false,
false,
ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
null,
null));
}

I guess this is the part that sets which Adapter Factory is used:
((ComposeableAdapterFactory)adapterFactory).getRootAdapterFa ctory()

Should I just create my specialized Adapter Factory and pass it instead of
the one returned by getRootAdapterFactory()?
Re: Modify labels for an element [message #420475 is a reply to message #420473] Tue, 01 July 2008 12:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
W.F.,

You could extend UMLs item provider adapter factory and change the
create adapter method for Property to use your own. You're showing a
specific property descriptor and it's certainly possible to modify the
label provider for a given property descriptor to show labels in a
specific way, but I didn't think that was your original question.


W.F. wrote:
> Ed Merks wrote:
>
>> W.F.
>
>> I sounds like you'd want to specialize the getText method of the
>> PropertyItemProvider. You'd then need a specialized
>> UMLItemProviderAdapterFactory and take steps to ensure that one is
>> used instead of the one provided directly by the UML2 project.
>
>
> OK, it's all clear until:
> "take steps to ensure that one is used instead of the one provided
> directly by the UML2 project"
>
> Here's what I have in the .edit project generated by GMF:
>
> protected void addXXXPropertyDescriptor(Object object) {
> itemPropertyDescriptors.add
> (createItemPropertyDescriptor
>
> (((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
> getResourceLocator(),
> getString("..."),
> getString("...", "...", "..."),
> XXXPackage.Literals.XXX,
> true,
> false,
> false,
> ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
> null,
> null));
> }
>
> I guess this is the part that sets which Adapter Factory is used:
> ((ComposeableAdapterFactory)adapterFactory).getRootAdapterFa ctory()
>
> Should I just create my specialized Adapter Factory and pass it
> instead of the one returned by getRootAdapterFactory()?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Modify labels for an element [message #420478 is a reply to message #420475] Tue, 01 July 2008 12:52 Go to previous messageGo to next message
nospam is currently offline nospamFriend
Messages: 21
Registered: July 2009
Junior Member
Yes, that's what I want to do: I have a specific drop-down list which
contains the Property elements and I want to change their labels there.

So is this a good way to do this:

protected void addXXXPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(new ComposedAdapterFactory(new MyOwnUMLItemProviderAdapterFactory),
getResourceLocator(),
getString("..."),
getString("...", "...", "..."),
XXXPackage.Literals.XXX,
true,
false,
false,
ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
null,
null));
}


I would have:
new ComposedAdapterFactory(new MyOwnUMLItemProviderAdapterFactory)

Or is there an easier way to change the labels?

I still have two problems:
- where to put the implementations of the specialized UML AdapterFactory
and specialized UML PropertyItemProvider in the GMF project structure?
- is it ok that I create a new AdapterFactory instance every time
addXXXPropertyDescriptor(Object object) is called? I think it's called
whenever the drop-down list is accessed.



Ed Merks wrote:

> W.F.,

> You could extend UMLs item provider adapter factory and change the
> create adapter method for Property to use your own. You're showing a
> specific property descriptor and it's certainly possible to modify the
> label provider for a given property descriptor to show labels in a
> specific way, but I didn't think that was your original question.


> W.F. wrote:
>> Ed Merks wrote:
>>
>>> W.F.
>>
>>> I sounds like you'd want to specialize the getText method of the
>>> PropertyItemProvider. You'd then need a specialized
>>> UMLItemProviderAdapterFactory and take steps to ensure that one is
>>> used instead of the one provided directly by the UML2 project.
>>
>>
>> OK, it's all clear until:
>> "take steps to ensure that one is used instead of the one provided
>> directly by the UML2 project"
>>
>> Here's what I have in the .edit project generated by GMF:
>>
>> protected void addXXXPropertyDescriptor(Object object) {
>> itemPropertyDescriptors.add
>> (createItemPropertyDescriptor
>>
>> (((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
>> getResourceLocator(),
>> getString("..."),
>> getString("...", "...", "..."),
>> XXXPackage.Literals.XXX,
>> true,
>> false,
>> false,
>> ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
>> null,
>> null));
>> }
>>
>> I guess this is the part that sets which Adapter Factory is used:
>> ((ComposeableAdapterFactory)adapterFactory).getRootAdapterFa ctory()
>>
>> Should I just create my specialized Adapter Factory and pass it
>> instead of the one returned by getRootAdapterFactory()?
>>
Re: Modify labels for an element [message #420487 is a reply to message #420478] Tue, 01 July 2008 14:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000702000003010409080300
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

WF,

Perhaps having a look at how ETypedElementItemProvider does something
similar will help so how to specialize just the label provider for a
given property.

protected void addETypePropertyDescriptor(Object object)
{
itemPropertyDescriptors.add
(new *ItemPropertyDescriptorWithUniqueChoiceOfValueLabels*

(((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
getResourceLocator(),



W.F. wrote:
> Yes, that's what I want to do: I have a specific drop-down list which
> contains the Property elements and I want to change their labels there.
>
> So is this a good way to do this:
>
> protected void addXXXPropertyDescriptor(Object object) {
> itemPropertyDescriptors.add
> (createItemPropertyDescriptor
> (new ComposedAdapterFactory(new
> MyOwnUMLItemProviderAdapterFactory),
> getResourceLocator(),
> getString("..."),
> getString("...", "...", "..."),
> XXXPackage.Literals.XXX,
> true,
> false,
> false,
> ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
> null,
> null));
> }
>
>
> I would have:
> new ComposedAdapterFactory(new MyOwnUMLItemProviderAdapterFactory)
>
> Or is there an easier way to change the labels?
>
> I still have two problems:
> - where to put the implementations of the specialized UML
> AdapterFactory and specialized UML PropertyItemProvider in the GMF
> project structure?
> - is it ok that I create a new AdapterFactory instance every time
> addXXXPropertyDescriptor(Object object) is called? I think it's called
> whenever the drop-down list is accessed.
>
>
>
> Ed Merks wrote:
>
>> W.F.,
>
>> You could extend UMLs item provider adapter factory and change the
>> create adapter method for Property to use your own. You're showing
>> a specific property descriptor and it's certainly possible to modify
>> the label provider for a given property descriptor to show labels in
>> a specific way, but I didn't think that was your original question.
>
>
>> W.F. wrote:
>>> Ed Merks wrote:
>>>
>>>> W.F.
>>>
>>>> I sounds like you'd want to specialize the getText method of the
>>>> PropertyItemProvider. You'd then need a specialized
>>>> UMLItemProviderAdapterFactory and take steps to ensure that one is
>>>> used instead of the one provided directly by the UML2 project.
>>>
>>>
>>> OK, it's all clear until:
>>> "take steps to ensure that one is used instead of the one provided
>>> directly by the UML2 project"
>>>
>>> Here's what I have in the .edit project generated by GMF:
>>>
>>> protected void addXXXPropertyDescriptor(Object object) {
>>> itemPropertyDescriptors.add
>>> (createItemPropertyDescriptor
>>>
>>> (((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
>>> getResourceLocator(),
>>> getString("..."),
>>> getString("...", "...", "..."),
>>> XXXPackage.Literals.XXX,
>>> true,
>>> false,
>>> false,
>>> ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
>>> null,
>>> null));
>>> }
>>>
>>> I guess this is the part that sets which Adapter Factory is used:
>>> ((ComposeableAdapterFactory)adapterFactory).getRootAdapterFa ctory()
>>>
>>> Should I just create my specialized Adapter Factory and pass it
>>> instead of the one returned by getRootAdapterFactory()?
>>>
>
>

--------------000702000003010409080300
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
WF,<br>
<br>
Perhaps having a look at how ETypedElementItemProvider does something
similar will help so how to specialize just the label provider for a
given property.<br>
<blockquote><tt>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Modify labels for an element [message #420498 is a reply to message #420487] Tue, 01 July 2008 15:26 Go to previous messageGo to next message
nospam is currently offline nospamFriend
Messages: 21
Registered: July 2009
Junior Member
Thanks for your help!

That's a very compact solution:

protected void addXXXPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(new ItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
getResourceLocator(),
getString("..."),
getString("...", "...", "..."),
XXXPackage.Literals.XXX,
true,
false,
false,
null,
null,
null) {
@Override
public IItemLabelProvider getLabelProvider(Object object) {
return new ItemDelegator(adapterFactory, resourceLocator) {
@Override
public String getText(Object object) {
if (object instanceof Property) {
return super.getText(object) + ((Property)
object).getClass_().getLabel();
} else {
return super.getText(object);
}
}
};
}
});
}
Re: Modify labels for an element [message #420508 is a reply to message #420498] Tue, 01 July 2008 16:26 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
W.F.,

Pretty cool hey. There's almost always a nice elegant solution, if only
it were easier to find.


W.F. wrote:
> Thanks for your help!
>
> That's a very compact solution:
>
> protected void addXXXPropertyDescriptor(Object object) {
> itemPropertyDescriptors.add
> (new ItemPropertyDescriptor
>
> (((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
> getResourceLocator(),
> getString("..."),
> getString("...", "...", "..."),
> XXXPackage.Literals.XXX,
> true,
> false,
> false,
> null,
> null,
> null) {
> @Override
> public IItemLabelProvider getLabelProvider(Object object) {
> return new ItemDelegator(adapterFactory, resourceLocator) {
> @Override
> public String getText(Object object) {
> if (object instanceof Property) {
> return super.getText(object) + ((Property)
> object).getClass_().getLabel();
> } else {
> return super.getText(object);
> }
> }
> };
> }
> });
> }
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:ItemPropertyDescriptors: Viewer not updated
Next Topic:Choosing between SDO/CDO/Teneo/EclipseLink etc.
Goto Forum:
  


Current Time: Sat Apr 27 03:57:58 GMT 2024

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

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

Back to the top