Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Overlay icons for validation
Overlay icons for validation [message #423852] Wed, 08 October 2008 07:16 Go to next message
Kristian Sons is currently offline Kristian SonsFriend
Messages: 27
Registered: July 2009
Junior Member
Hello!

I would like to create overlay icons for the EMF providers that change
depending on the current validation status. To perform the validation in
ItemProviderAdapter.overlayImage(Object, Object) seems a little too
expensive. I don´t want to include the status in the model either.

Best way seems to extend the notifyChanged method and to store the
status in a map for singleton adapters.

Any other approaches?

Thanks,
Kristian
Re: Overlay icons for validation [message #423863 is a reply to message #423852] Wed, 08 October 2008 10:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Kristian,

Comments below.

Kristian Sons wrote:
> Hello!
>
> I would like to create overlay icons for the EMF providers that change
> depending on the current validation status. To perform the validation in
> ItemProviderAdapter.overlayImage(Object, Object) seems a little too
> expensive. I don´t want to include the status in the model either.
>
> Best way seems to extend the notifyChanged method and to store the
> status in a map for singleton adapters.
I imagine you could use a specialized AdapterFactoryLabelProvider that
specializes the getImage method to act as a decorator so that you can
inject the decoration for any model without changing the basic item
providers for it and just tell the view to completely refresh all labels
after a validation...
>
> Any other approaches?
>
> Thanks,
> Kristian


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Overlay icons for validation [message #423865 is a reply to message #423852] Wed, 08 October 2008 10:57 Go to previous messageGo to next message
Mario Winterer is currently offline Mario WintererFriend
Messages: 136
Registered: July 2009
Senior Member
Kristian Sons schrieb:
> Hello!
>
> I would like to create overlay icons for the EMF providers that change
> depending on the current validation status. To perform the validation in
> ItemProviderAdapter.overlayImage(Object, Object) seems a little too
> expensive. I don´t want to include the status in the model either.
>
> Best way seems to extend the notifyChanged method and to store the
> status in a map for singleton adapters.
>
> Any other approaches?
>
> Thanks,
> Kristian

Maybe I've got something wrong, but what about simply using a
DecoratingLabelProvider that wraps the orginal AdapterFactoryLabelProvider?
(If the validation status is not stored within your model, I think the
default eclipse decoration mechanism could be a good choice).

Mario
Re: Overlay icons for validation [message #424179 is a reply to message #423852] Mon, 20 October 2008 07:33 Go to previous messageGo to next message
Kristian Sons is currently offline Kristian SonsFriend
Messages: 27
Registered: July 2009
Junior Member
Thanks Mario and Ed for your advice!

Here some snippets for those who want to achieve the same (based on the
generated RCP):

Editor::createPages:
labelDecorator = new MyLabelDecorator();
viewer.setLabelProvider(new DecoratingLabelProvider(new
AdapterFactoryLabelProvider(adapterFactory), labelDecorator ));

Editor::updateProblemIndication:
labelDecorator.setDiagnostics(diagnostic);

In MyLabelDecorator (implements ILabelDecorator):

public void setDiagnostics(Diagnostic diagnostic)
{
Map<Object, Integer> oldSeverityMap = severityMap;
severityMap = new HashMap<Object, Integer>();
processDiagnostic(diagnostic, severityMap);
notifyViewer(oldSeverityMap, severityMap);
}

private void notifyViewer(Map<Object, Integer> oldSeverityMap,
Map<Object, Integer> newSeverityMap)
{
List<Object> changedObjects = new ArrayList<Object>();
changedObjects.addAll(oldSeverityMap.keySet());
changedObjects.addAll(newSeverityMap.keySet());
fireLabelEvent(new LabelProviderChangedEvent(this,
changedObjects.toArray()));
}

private ComposedImage decorateSeverity(Image image, Integer severity)
{
List<Object> images = new ArrayList<Object>(2);
images.add(image);
if (severity == Diagnostic.WARNING)

images.add(X3DModelEditPlugin.INSTANCE.getImage("full/ovr16/warning_co "));
else

images.add(X3DModelEditPlugin.INSTANCE.getImage("full/ovr16/error_co "));

ComposedImage ci = new ComposedImage(images){

@Override
public List<Point> getDrawPoints(Size size)
{
List<Point> results = new ArrayList<Point>();
results.add(new Point());
Point overlay = new Point();
overlay.x = 0;
overlay.y = 7;
results.add(overlay);
return results;
}};
return ci;
}


Have fun!
Kristian
Re: Overlay icons for validation [message #424181 is a reply to message #424179] Mon, 20 October 2008 07:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Kristian,

That's very cool. Maybe we should provide something like this directly
in the framework. If you open a bugzilla enhancement request with this
as the contribution, I'll definitely look into it. It would make my
demos better! Thanks for sharing!!


Kristian Sons wrote:
> Thanks Mario and Ed for your advice!
>
> Here some snippets for those who want to achieve the same (based on
> the generated RCP):
>
> Editor::createPages:
> labelDecorator = new MyLabelDecorator();
> viewer.setLabelProvider(new DecoratingLabelProvider(new
> AdapterFactoryLabelProvider(adapterFactory), labelDecorator ));
>
> Editor::updateProblemIndication:
> labelDecorator.setDiagnostics(diagnostic);
>
> In MyLabelDecorator (implements ILabelDecorator):
>
> public void setDiagnostics(Diagnostic diagnostic)
> {
> Map<Object, Integer> oldSeverityMap = severityMap;
> severityMap = new HashMap<Object, Integer>();
> processDiagnostic(diagnostic, severityMap);
> notifyViewer(oldSeverityMap, severityMap);
> }
>
> private void notifyViewer(Map<Object, Integer>
> oldSeverityMap, Map<Object, Integer> newSeverityMap)
> {
> List<Object> changedObjects = new ArrayList<Object>();
> changedObjects.addAll(oldSeverityMap.keySet());
> changedObjects.addAll(newSeverityMap.keySet());
> fireLabelEvent(new LabelProviderChangedEvent(this,
> changedObjects.toArray()));
> }
>
> private ComposedImage decorateSeverity(Image image, Integer severity)
> {
> List<Object> images = new ArrayList<Object>(2);
> images.add(image);
> if (severity == Diagnostic.WARNING)
>
> images.add(X3DModelEditPlugin.INSTANCE.getImage("full/ovr16/warning_co "));
>
> else
>
> images.add(X3DModelEditPlugin.INSTANCE.getImage("full/ovr16/error_co "));
>
> ComposedImage ci = new ComposedImage(images){
>
> @Override
> public List<Point> getDrawPoints(Size size)
> {
> List<Point> results = new ArrayList<Point>();
> results.add(new Point());
> Point overlay = new Point();
> overlay.x = 0;
> overlay.y = 7;
> results.add(overlay);
> return results;
> }};
> return ci;
> }
>
>
> Have fun!
> Kristian
>
>
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Overlay icons for validation [message #424224 is a reply to message #424181] Mon, 20 October 2008 22:09 Go to previous messageGo to next message
Cameron Bateman is currently offline Cameron BatemanFriend
Messages: 481
Registered: July 2009
Senior Member
> That's very cool. Maybe we should provide something like this directly
> in the framework. If you open a bugzilla enhancement request with this

Could you post the bug number for this? I'm also quite interested in
validation-based decoration in item providers.
Re: Overlay icons for validation [message #424226 is a reply to message #424224] Mon, 20 October 2008 22:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Cameron,

Feel free to open it yourself. I'd prefer someone in the community open
it...


Cameron Bateman wrote:
>> That's very cool. Maybe we should provide something like this
>> directly in the framework. If you open a bugzilla enhancement
>> request with this
>
> Could you post the bug number for this? I'm also quite interested in
> validation-based decoration in item providers.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Overlay icons for validation [message #424230 is a reply to message #424179] Tue, 21 October 2008 05:17 Go to previous messageGo to next message
Ben is currently offline BenFriend
Messages: 46
Registered: July 2009
Member
Hi, Kristian,

I'm also looking for similar approach so thanks for sharing!

BTW, would you mind also posting the code for the processDiagnostic and
fireLabelEvent methods?
Re: Overlay icons for validation [message #424255 is a reply to message #424181] Tue, 21 October 2008 16:52 Go to previous messageGo to next message
Kristian Sons is currently offline Kristian SonsFriend
Messages: 27
Registered: July 2009
Junior Member
Ed Merks schrieb:
> That's very cool. Maybe we should provide something like this directly
> in the framework. If you open a bugzilla enhancement request with this
> as the contribution, I'll definitely look into it. It would make my
> demos better! Thanks for sharing!!

Done. See https://bugs.eclipse.org/251565
Was unshure about the component so perhaps you have to move it.

Kristian
Re: Overlay icons for validation [message #424256 is a reply to message #424230] Tue, 21 October 2008 16:58 Go to previous messageGo to next message
Kristian Sons is currently offline Kristian SonsFriend
Messages: 27
Registered: July 2009
Junior Member
Ben schrieb:
> Hi, Kristian,
>
> I'm also looking for similar approach so thanks for sharing!
>
> BTW, would you mind also posting the code for the processDiagnostic and
> fireLabelEvent methods?
>
>
>


Here we go:

private void processDiagnostic(Diagnostic diagnostic, Map<Object,
Integer> severityMap)
{
List<?> dataEntries = diagnostic.getData();
for(Object obj : dataEntries)
{
if (obj instanceof EObject)
severityMap.put(obj, diagnostic.getSeverity());
}
for (Diagnostic childDiagnostic : diagnostic.getChildren())
{
processDiagnostic(childDiagnostic, severityMap);
}
}

private void fireLabelEvent(final LabelProviderChangedEvent event)
{
Object[] listeners = listenerList.getListeners();
for (int i = 0; i < listeners.length; ++i) {
((ILabelProviderListener)
listeners[i]).labelProviderChanged(event);
}
}

BTW, this approach displays only overlays for those Objects generating
the Diagnostic. This is just the way I want it. But if you want also the
parents labeld you have to do a little more work...
Re: Overlay icons for validation [message #424257 is a reply to message #424226] Tue, 21 October 2008 17:04 Go to previous messageGo to next message
Cameron Bateman is currently offline Cameron BatemanFriend
Messages: 481
Registered: July 2009
Senior Member
Ed Merks wrote:
> Cameron,
> Feel free to open it yourself. I'd prefer someone in the community open
> it...

Done. https://bugs.eclipse.org/bugs/show_bug.cgi?id=251566.
Re: Overlay icons for validation [message #424258 is a reply to message #424255] Tue, 21 October 2008 17:06 Go to previous message
Cameron Bateman is currently offline Cameron BatemanFriend
Messages: 481
Registered: July 2009
Senior Member
Kristian Sons wrote:

> Done. See https://bugs.eclipse.org/251565
> Was unshure about the component so perhaps you have to move it.

Too funny. Per Ed's request I opened the same request exactly one bug
number later. Oh well, dups are cheap in bugzilla... :)
Previous Topic:Ecore: Upper bound not recognised?
Next Topic:[CDO] Hierarchical resources
Goto Forum:
  


Current Time: Wed Sep 25 05:02:12 GMT 2024

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

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

Back to the top