|
Re: Overriding standard ECore validation messages [message #901799 is a reply to message #901788] |
Tue, 14 August 2012 15:49 |
Ed Merks Messages: 33113 Registered: July 2009 |
Senior Member |
|
|
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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
Re: Overriding standard ECore validation messages [message #901834 is a reply to message #901825] |
Tue, 14 August 2012 17:41 |
Simon Barnett Messages: 28 Registered: July 2012 |
Junior Member |
|
|
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 19:33 |
Ed Merks Messages: 33113 Registered: July 2009 |
Senior Member |
|
|
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?
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03958 seconds