Overriding standard ECore validation messages [message #901788] |
Tue, 14 August 2012 11:18  |
Eclipse User |
|
|
|
Hi,
What is the proper way to override the standard Ecore validation messages?
If part of my ecore model has a feature called Collections which must have at least 1 Item and in my instance of the model, I create a Collection which doesn't have any Items then Ecore gives me a message like this:-
"The feature 'items' of com.blah.blah.model.impl.CollectionImpl@<object ref> with 0 values must have at least 1 values"
This error message might not mean as much to the user as something like:-
"Collections must contain at least 1 Item"
so I'd like to override the way that the EMF error messages are created.
I've looked around a fair bit and the best I could come up with was to override getEResourceLocator in the EObjectValidator class like this:-
@Override
protected ResourceLocator getEcoreResourceLocator() {
return OIDKModel.INSTANCE.getPluginResourceLocator();
}
and use my own properties file to define the message keys.
But the message substitutions don't work so I get:-
"{0} must contain at least {1} item"
and it occurs to me that if I override that method, I should provide ALL of the EMF message keys in case they ever come up as I will be responsible for creating them all now.
So there must be another way to do this where I can override specific messages. But does anyone know how this should be done?
Thanks.
|
|
|
Re: Overriding standard ECore validation messages [message #901799 is a reply to message #901788] |
Tue, 14 August 2012 11:49   |
Eclipse User |
|
|
|
Simon,
That's really the only way and yes, you'll have to be careful to support
all the messages (or have your model's plugin delegate to the Ecore plugin).
On 14/08/2012 5:18 PM, Simon Barnett wrote:
> Hi,
>
> What is the proper way to override the standard Ecore validation
> messages?
>
> If part of my ecore model has a feature called Collections which must
> have at least 1 Item and in my instance of the model, I create a
> Collection which doesn't have any Items then Ecore gives me a message
> like this:-
>
> "The feature 'items' of
> com.blah.blah.model.impl.CollectionImpl@<object ref> with 0 values
> must have at least 1 values"
>
> This error message might not mean as much to the user as something like:-
>
> "Collections must contain at least 1 Item"
>
> so I'd like to override the way that the EMF error messages are created.
>
> I've looked around a fair bit and the best I could come up with was to
> override getEResourceLocator in the EObjectValidator class like this:-
>
> @Override
> protected ResourceLocator getEcoreResourceLocator() {
> return OIDKModel.INSTANCE.getPluginResourceLocator();
> }
>
> and use my own properties file to define the message keys.
>
> But the message substitutions don't work so I get:-
>
> "{0} must contain at least {1} item"
>
> and it occurs to me that if I override that method, I should provide
> ALL of the EMF message keys in case they ever come up as I will be
> responsible for creating them all now.
>
> So there must be another way to do this where I can override specific
> messages. But does anyone know how this should be done?
>
> Thanks.
* 2.44 How do I map between an EMF Resource and an Eclipse IFile?
<http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_map_between_an_EMF_Resource_and_an_Eclipse_IFile.3F>
From that IFile, you can get the containing folder and determine all
the other files in that folder.
On 14/08/2012 3:01 PM, Bastian Barton wrote:
> Hi xTexters,
>
> I have been searching for a pretty long time, but it shouldn't be that
> complicated:
>
> Having a Resource and therefore a platform URI, how can I get a list
> of all files in the same directory? I need it for an auto-import
> mechanism in the IScopeProvider.
>
> Thanks!
>
> BB
|
|
|
|
|
Re: Overriding standard ECore validation messages [message #901834 is a reply to message #901825] |
Tue, 14 August 2012 13:41   |
Eclipse User |
|
|
|
OK, I think I've sorted the delegation question using the following code in the validator:-
@Override
protected String getEcoreString(String key, Object[] substitutions) {
try {
return getString(getEcoreResourceLocator(), key, substitutions);
} catch (MissingResourceException ex) {
return getString(EcorePlugin.INSTANCE, key, substitutions);
}
}
private String getString(ResourceLocator resourceLocator, String key,
Object[] substitutions) {
return substitutions == null ? resourceLocator.getString(key)
: resourceLocator.getString(key, substitutions);
}
But I still don't get my substitutions in the message.
Any ideas on that one?
|
|
|
Re: Overriding standard ECore validation messages [message #901864 is a reply to message #901834] |
Tue, 14 August 2012 15:33   |
Eclipse User |
|
|
|
Simon,
In the constructor for your XyzPlugin, you can specify other resource
locators for it to delegate to in the call to super.
On 14/08/2012 7:41 PM, Simon Barnett wrote:
> OK, I think I've sorted the delegation question using the following
> code in the validator:-
>
> @Override
> protected String getEcoreString(String key, Object[] substitutions) {
> try {
> return getString(getEcoreResourceLocator(), key, substitutions);
> } catch (MissingResourceException ex) {
> return getString(EcorePlugin.INSTANCE, key, substitutions);
> }
> }
>
> private String getString(ResourceLocator resourceLocator, String key,
> Object[] substitutions) {
> return substitutions == null ? resourceLocator.getString(key)
> : resourceLocator.getString(key, substitutions);
> }
>
> But I still don't get my substitutions in the message.
> Any ideas on that one?
|
|
|
|
|
|
|
Re: Overriding standard ECore validation messages [message #901968 is a reply to message #901920] |
Wed, 15 August 2012 07:03  |
Eclipse User |
|
|
|
Ed Willink wrote on Wed, 15 August 2012 07:05Eclipse (and EMF) supports internationalization, so if you configure
your Eclipse to use Barnetese and provide the Barnetese
internationalization fragment for EMF, then every internationalized
message might use Barnetese as first choice and English as a fall-back.
That's the way we provide custom messages in German. You have to create a fragment for the host org.eclipse.emf.ecore.
I'm not sure, but imho it would be enough to provide a plugin_en.properties file for English. This should override the default plugin.properties in org.eclipse.emf.ecore.
Greetings
Christoph
|
|
|
Powered by
FUDForum. Page generated in 0.05758 seconds