Skip to main content



      Home
Home » Modeling » EMF » Overlay icons for validation
Overlay icons for validation [message #423852] Wed, 08 October 2008 03:16 Go to next message
Eclipse UserFriend
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 06:23 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Overlay icons for validation [message #423865 is a reply to message #423852] Wed, 08 October 2008 06:57 Go to previous messageGo to next message
Eclipse UserFriend
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 03:33 Go to previous messageGo to next message
Eclipse UserFriend
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 03:51 Go to previous messageGo to next message
Eclipse UserFriend
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
>
>
>
>
>
>
Re: Overlay icons for validation [message #424224 is a reply to message #424181] Mon, 20 October 2008 18:09 Go to previous messageGo to next message
Eclipse UserFriend
> 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 18:11 Go to previous messageGo to next message
Eclipse UserFriend
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.
>
Re: Overlay icons for validation [message #424230 is a reply to message #424179] Tue, 21 October 2008 01:17 Go to previous messageGo to next message
Eclipse UserFriend
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 12:52 Go to previous messageGo to next message
Eclipse UserFriend
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 12:58 Go to previous messageGo to next message
Eclipse UserFriend
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 13:04 Go to previous messageGo to next message
Eclipse UserFriend
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 13:06 Go to previous message
Eclipse UserFriend
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: Fri Jul 04 08:13:34 EDT 2025

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

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

Back to the top