Skip to main content



      Home
Home » Modeling » EMF » Decorate EMF editor icons
Decorate EMF editor icons [message #411802] Mon, 06 August 2007 10:10 Go to next message
Eclipse UserFriend
Hello !

I wish to decorate elements in all kind of EMF editors. Is it possible ?

I have found org.eclipse.ui.decorators extension point to decorate
IResource in the package explorer (but it works only on package explorer ?).
I have alse found org.eclipse.ui.startup extension point but I have to
list the editors packages in the "earlyStartup" method and I can't list
all the editors I want.

public class Startup implements IStartup {

/**
* Initializes me.
*/
public Startup() {
super();
}

/**
* Install the validator.
*/
public void earlyStartup() {
EValidator.Registry.INSTANCE.put(FooPackage.eINSTANCE,
new EValidatorAdapter());
EValidator.Registry.INSTANCE.put(Foo2Package.eINSTANCE,
new EValidatorAdapter());
...
}
}

Thanks.

Nathalie Lépine, Obeo.
Re: Decorate EMF editor icons [message #411804 is a reply to message #411802] Mon, 06 August 2007 10:21 Go to previous messageGo to next message
Eclipse UserFriend
This is a multi-part message in MIME format.
--------------000305090800000808030006
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Nathalie,

We've not provided integration with Eclipse's decorator APIs. You can
accomplish decoration quite easily by augmenting the icons returned by a
standard item provider using
org.eclipse.emf.edit.provider.ComposedImage. Here's an example from
EStructuralFeatureItemProvider which is called for the images of an
EReference and an EAttribute:

public Object getComposedImage(Object object, Object imageToCompose)
{
EStructuralFeature eStructuralFeature = (EStructuralFeature)object;
Collection<Object> images = new ArrayList<Object>();
images.add(imageToCompose);
String imageName = "full/obj16/EOccurrence";
int minOccurs = eStructuralFeature.getLowerBound();
int maxOccurs = eStructuralFeature.getUpperBound();
if (minOccurs >= 0 && (minOccurs <= maxOccurs || maxOccurs == -1))
{
switch (minOccurs)
{
case 0:
{
imageName += "Zero";
break;
}
case 1:
{
imageName += "One";
break;
}
default:
{
imageName += "N";
break;
}
}

if (minOccurs != maxOccurs)
{
switch (maxOccurs)
{
case -1:
{
imageName += "ToUnbounded";
break;
}
case 0:
{
break;
}
case 1:
{
imageName += "ToOne";
break;
}
default:
{
imageName += minOccurs <= 1 ? "ToN" : "ToM";
break;
}
}
}
}
else
{
imageName += "NToM";
}

if (!imageName.equals("full/obj16/EOccurrenceZeroToOne"))
{
images.add(EcoreEditPlugin.INSTANCE.getImage(imageName));
}

return
new ComposedImage(images)
{
@Override
public List<ComposedImage.Point> getDrawPoints(Size size)
{
List<ComposedImage.Point> result = super.getDrawPoints(size);
if (result.size() > 1)
{
result.get(0).y = -2;
}
return result;
}
};
}


Nathalie L
Re: Decorate EMF editor icons [message #411805 is a reply to message #411804] Mon, 06 August 2007 10:39 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, but I need a generic decoration.

Ed Merks a écrit :
> Nathalie,
>
> We've not provided integration with Eclipse's decorator APIs. You can
> accomplish decoration quite easily by augmenting the icons returned by a
> standard item provider using
> org.eclipse.emf.edit.provider.ComposedImage. Here's an example from
> EStructuralFeatureItemProvider which is called for the images of an
> EReference and an EAttribute:
>
> public Object getComposedImage(Object object, Object imageToCompose)
> {
> EStructuralFeature eStructuralFeature = (EStructuralFeature)object;
> Collection<Object> images = new ArrayList<Object>();
> images.add(imageToCompose);
> String imageName = "full/obj16/EOccurrence";
> int minOccurs = eStructuralFeature.getLowerBound();
> int maxOccurs = eStructuralFeature.getUpperBound();
> if (minOccurs >= 0 && (minOccurs <= maxOccurs || maxOccurs == -1))
> {
> switch (minOccurs)
> {
> case 0:
> {
> imageName += "Zero";
> break;
> }
> case 1:
> {
> imageName += "One";
> break;
> }
> default:
> {
> imageName += "N";
> break;
> }
> }
>
> if (minOccurs != maxOccurs)
> {
> switch (maxOccurs)
> {
> case -1:
> {
> imageName += "ToUnbounded";
> break;
> }
> case 0:
> {
> break;
> }
> case 1:
> {
> imageName += "ToOne";
> break;
> }
> default:
> {
> imageName += minOccurs <= 1 ? "ToN" : "ToM";
> break;
> }
> }
> }
> }
> else
> {
> imageName += "NToM";
> }
>
> if (!imageName.equals("full/obj16/EOccurrenceZeroToOne"))
> {
> images.add(EcoreEditPlugin.INSTANCE.getImage(imageName));
> }
>
> return
> new ComposedImage(images)
> {
> @Override
> public List<ComposedImage.Point> getDrawPoints(Size size)
> {
> List<ComposedImage.Point> result = super.getDrawPoints(size);
> if (result.size() > 1)
> {
> result.get(0).y = -2;
> }
> return result;
> }
> };
> }
>
>
> Nathalie Lépine wrote:
>> Hello !
>>
>> I wish to decorate elements in all kind of EMF editors. Is it possible ?
>>
>> I have found org.eclipse.ui.decorators extension point to decorate
>> IResource in the package explorer (but it works only on package
>> explorer ?).
>> I have alse found org.eclipse.ui.startup extension point but I have to
>> list the editors packages in the "earlyStartup" method and I can't
>> list all the editors I want.
>>
>> public class Startup implements IStartup {
>>
>> /**
>> * Initializes me.
>> */
>> public Startup() {
>> super();
>> }
>>
>> /**
>> * Install the validator.
>> */
>> public void earlyStartup() {
>> EValidator.Registry.INSTANCE.put(FooPackage.eINSTANCE,
>> new EValidatorAdapter());
>> EValidator.Registry.INSTANCE.put(Foo2Package.eINSTANCE,
>> new EValidatorAdapter());
>> ...
>> }
>> }
>>
>> Thanks.
>>
>> Nathalie Lépine, Obeo.
>
Re: Decorate EMF editor icons [message #411807 is a reply to message #411805] Mon, 06 August 2007 11:37 Go to previous message
Eclipse UserFriend
Nathalie,

I'm not sure what that means exactly, but note that decoration could
happen directly via a specialized AdapterFactoryLabelProvider that
decorates the normal results you'd get from the item provider. I.e.,
it's not necessary to modify the item providers themselves to use this
technique. And of course the AdapterFactoryLabelProvider constructed
using a ComposedAdapterFactory that in turn is constructed with
ComposedAdapterFactory.Registry.INSTANCE could be used to produce labels
for any model that has registered its item providers...


Nathalie Lépine wrote:
> Thanks, but I need a generic decoration.
>
> Ed Merks a écrit :
>> Nathalie,
>>
>> We've not provided integration with Eclipse's decorator APIs. You
>> can accomplish decoration quite easily by augmenting the icons
>> returned by a standard item provider using
>> org.eclipse.emf.edit.provider.ComposedImage. Here's an example from
>> EStructuralFeatureItemProvider which is called for the images of an
>> EReference and an EAttribute:
>>
>> public Object getComposedImage(Object object, Object
>> imageToCompose)
>> {
>> EStructuralFeature eStructuralFeature =
>> (EStructuralFeature)object;
>> Collection<Object> images = new ArrayList<Object>();
>> images.add(imageToCompose);
>> String imageName = "full/obj16/EOccurrence";
>> int minOccurs = eStructuralFeature.getLowerBound();
>> int maxOccurs = eStructuralFeature.getUpperBound();
>> if (minOccurs >= 0 && (minOccurs <= maxOccurs || maxOccurs ==
>> -1))
>> {
>> switch (minOccurs)
>> {
>> case 0:
>> {
>> imageName += "Zero";
>> break;
>> }
>> case 1:
>> {
>> imageName += "One";
>> break;
>> }
>> default:
>> {
>> imageName += "N";
>> break;
>> }
>> }
>>
>> if (minOccurs != maxOccurs)
>> {
>> switch (maxOccurs)
>> {
>> case -1:
>> {
>> imageName += "ToUnbounded";
>> break;
>> }
>> case 0:
>> {
>> break;
>> }
>> case 1:
>> {
>> imageName += "ToOne";
>> break;
>> }
>> default:
>> {
>> imageName += minOccurs <= 1 ? "ToN" : "ToM";
>> break;
>> }
>> }
>> }
>> }
>> else
>> {
>> imageName += "NToM";
>> }
>>
>> if (!imageName.equals("full/obj16/EOccurrenceZeroToOne"))
>> {
>> images.add(EcoreEditPlugin.INSTANCE.getImage(imageName));
>> }
>>
>> return
>> new ComposedImage(images)
>> {
>> @Override
>> public List<ComposedImage.Point> getDrawPoints(Size size)
>> {
>> List<ComposedImage.Point> result =
>> super.getDrawPoints(size);
>> if (result.size() > 1)
>> {
>> result.get(0).y = -2;
>> }
>> return result;
>> }
>> };
>> }
>>
>>
>> Nathalie Lépine wrote:
>>> Hello !
>>>
>>> I wish to decorate elements in all kind of EMF editors. Is it
>>> possible ?
>>>
>>> I have found org.eclipse.ui.decorators extension point to decorate
>>> IResource in the package explorer (but it works only on package
>>> explorer ?).
>>> I have alse found org.eclipse.ui.startup extension point but I have
>>> to list the editors packages in the "earlyStartup" method and I
>>> can't list all the editors I want.
>>>
>>> public class Startup implements IStartup {
>>>
>>> /**
>>> * Initializes me.
>>> */
>>> public Startup() {
>>> super();
>>> }
>>>
>>> /**
>>> * Install the validator.
>>> */
>>> public void earlyStartup() {
>>> EValidator.Registry.INSTANCE.put(FooPackage.eINSTANCE,
>>> new EValidatorAdapter());
>>> EValidator.Registry.INSTANCE.put(Foo2Package.eINSTANCE,
>>> new EValidatorAdapter());
>>> ...
>>> }
>>> }
>>>
>>> Thanks.
>>>
>>> Nathalie Lépine, Obeo.
>>
Previous Topic:Error occurred when open the Ecore.mdl in Rose!
Next Topic:Changing status line text for selection in the property view
Goto Forum:
  


Current Time: Mon Sep 22 11:51:35 EDT 2025

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

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

Back to the top