Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 85704 Details for
Bug 213623
DataBinding ViewersObservables should expose widget
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Adapts ValidationStatusMap for IMessageManagers
MessageManagerListener.java (text/plain), 3.94 KB, created by
Thomas Kratz
on 2007-12-21 03:51:07 EST
(
hide
)
Description:
Adapts ValidationStatusMap for IMessageManagers
Filename:
MIME Type:
Creator:
Thomas Kratz
Created:
2007-12-21 03:51:07 EST
Size:
3.94 KB
patch
obsolete
>package de.eiswind.paris.client.core.databinding; > >import java.util.HashMap; >import java.util.Map; > >import org.eclipse.core.databinding.Binding; >import org.eclipse.core.databinding.observable.IObservable; >import org.eclipse.core.databinding.observable.map.IMapChangeListener; >import org.eclipse.core.databinding.observable.map.MapChangeEvent; >import org.eclipse.core.databinding.observable.map.MapDiff; >import org.eclipse.core.runtime.IStatus; >import org.eclipse.jface.databinding.swt.ISWTObservable; >import org.eclipse.jface.databinding.viewers.IViewerObservableList; >import org.eclipse.jface.databinding.viewers.IViewerObservableValue; >import org.eclipse.jface.dialogs.IMessageProvider; >import org.eclipse.swt.widgets.Control; >import org.eclipse.swt.widgets.Widget; >import org.eclipse.ui.forms.IMessageManager; > >/** > * Converts the ISTatus objects from the status Map of a DataBindingContext to > * by handled by a UI Forms IMessageManager. > * > * @author Thomas > * > */ >public class MessageManagerListener implements IMapChangeListener { > > private IMessageManager mgr; > > private static final KeyMap keyMap = new KeyMap(); > > public MessageManagerListener(IMessageManager mgr) { > > this.mgr = mgr; > > } > > public void handleMapChange(MapChangeEvent event) { > MapDiff diff = event.diff; > for (Object o : diff.getAddedKeys()) { > changeMessage((Binding) o, (IStatus) diff.getNewValue(o)); > } > for (Object o : diff.getChangedKeys()) { > changeMessage((Binding) o, (IStatus) diff.getNewValue(o)); > } > for (Object o : diff.getRemovedKeys()) { > removeMessage((Binding) o); > } > > } > > protected void changeMessage(Binding binding, IStatus status) { > if (status.getSeverity() == IStatus.OK) { > removeMessage(binding); > return; > } > Control control = guessControl(binding); > if (control != null) { > mgr.addMessage(getKey(binding), status.getMessage(), null, keyMap.getMessageProviderKey(status > .getSeverity()), control); > > } else { > mgr.addMessage(getKey(binding), status.getMessage(), null, keyMap.getMessageProviderKey(status > .getSeverity())); > } > } > > protected void removeMessage(Binding binding) { > Control control = guessControl(binding); > if (control != null) { > mgr.removeMessage(getKey(binding), control); > } else { > mgr.removeMessage(getKey(binding)); > } > } > > protected Control guessControl(Binding b) { > Control control = guessControl(b.getModel()); > if (control != null) { > return control; > } > control = guessControl(b.getTarget()); > return control; > } > > /** if this observable is bound to a control it will be returned */ > protected Control guessControl(IObservable value) { > if (value instanceof ISWTObservable) { > Widget w = ((ISWTObservable) value).getWidget(); > if (w instanceof Control) { > return (Control) w; > } > } > if (value instanceof IViewerObservableValue) { > return ((IViewerObservableValue) value).getViewer().getControl(); > } > if (value instanceof IViewerObservableList) { > return ((IViewerObservableList) value).getViewer().getControl(); > } > return null; > } > > protected String getKey(Binding binding) { > System.out.println(binding.hashCode()); > return "Bridge:" + Integer.valueOf(binding.hashCode()).toString(); > } > > protected static class KeyMap { > private Map<Integer, Integer> keymap = new HashMap<Integer, Integer>(); > > protected KeyMap() { > keymap.put(Integer.valueOf(IStatus.ERROR), Integer.valueOf(IMessageProvider.ERROR)); > keymap.put(Integer.valueOf(IStatus.INFO), Integer.valueOf(IMessageProvider.WARNING)); > keymap.put(Integer.valueOf(IStatus.INFO), Integer.valueOf(IMessageProvider.INFORMATION)); > keymap.put(Integer.valueOf(IStatus.OK), Integer.valueOf(IMessageProvider.NONE)); > keymap.put(Integer.valueOf(IStatus.CANCEL), Integer.valueOf(IMessageProvider.INFORMATION)); > } > > protected int getMessageProviderKey(int iStatusKey) { > > return keymap.get(Integer.valueOf(iStatusKey)).intValue(); > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 213623
:
85682
| 85704