Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How Strange.</p> <p>Okay, when I tried to use the auto-correct "include org.eclipse.core.databinding_1.3..." nothing happened. I ass-u-me'd that it was correctly included as a plugin dependency and didn't fix the error.</p> <p>During this time, that plugin's jar appeared in my plugin project's "Plug-in Dependencies" folder, and I was able to view its source. One would think at that point that the plugin was correctly included in the plugin.xml</p> <p>One would be wrong.</p> <p>I manually added ...core.databinding_1.3... to my plugin dependencies and the errors Went Away.</p> <p>So it seems this is a bug in the autocorrect rather than in the API restriction code.</p> <p>AH! I had org.eclipse.core.databinding in my Imported Packages list. That must have thrown things off.</p> <p>So now you know. And knowing's have the battle. GO CODE!</p> <hr> <p>And speaking of code. Here's what I'm doing (more or less):</p> <pre><code>enum MapValueDirection { VALUE_TO_KEY, KEY_TO_VALUE }; private class MappingConverter extends Converter { Map&lt;String, String&gt; map = null; public MappingConverter( Map&lt;String, String&gt; map_, MapValueDirection dir) { super(String.class, String.class); if (dir == MapValueDirection.VALUE_TO_KEY) { map = reverseMap(map_); } else { map = map_; } } private Map&lt;String, String&gt; reverseMap(Map&lt;String, String&gt; map_) { Map&lt;String, String&gt; reversedMap = new TreeMap&lt;String, String&gt;(); Set&lt;Entry&lt;String, String&gt;&gt; entries = map_.entrySet(); for (Entry&lt;String, String&gt; curEnt : entries) { reversedMap.put(curEnt.getValue(), curEnt.getKey()); } return reversedMap; } /* (non-Javadoc) * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) */ public Object convert(Object fromObject) { if (map != null &amp;&amp; fromObject != null &amp;&amp; String.class.equals(fromObject.getClass())) { Object newVal = map.get(fromObject); if (newVal == null) { newVal = fromObject; } return newVal; } return fromObject; } } /** * And this is were the actual work gets done. */ public void bindBean(Object bean, PropertyDescriptor prop) { Control curControl = getControl(prop.getPropertyType()); IObservableValue uiElement = getObserver(prop, curControl); IOvservableValue modelElement = BeanObservables.observValue(bean, prop.getName()); // "display" = key, "storage" = value Map&lt;String, String&gt; profileFlds = getProfileFields(); UpdateValueStrategy toStorage = new UpdateValueStrategy(); toStorage.setConverter( new MappingConverter( profileFlds, MapValueDirection.KEY_TO_VALUE)); UpdateValueStrategy toDisplay = new UpdateValueStrategy(); toDisplay .setConverter( new MappingConverter( profileFlds, MapValueDirection.VALUE_TO_KEY)); m_bindingContext.bindValue( uiElement, modelElement, toDisplay , toStorage); } </code></pre> <p>My actual code is a bit more complex than that, but you get the idea. I suspect it's not terribly efficient, but it works well within the whole data binding framework, conceptually speaking (based on my admittedly limited experience).</p> <p>It should be fairly trivial to make a Generic version of MappingConverter, but I'll leave that as an Exercise For the Reader.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload