Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Eclipse:尝试转换cmbo“;“显示”;对“的价值”;储存;价值_Java_Data Binding_Eclipse Plugin_Swt - Fatal编程技术网

Java Eclipse:尝试转换cmbo“;“显示”;对“的价值”;储存;价值

Java Eclipse:尝试转换cmbo“;“显示”;对“的价值”;储存;价值,java,data-binding,eclipse-plugin,swt,Java,Data Binding,Eclipse Plugin,Swt,我正在HeliosSR2中构建插件。支持伽利略会很好,但我现在并不过分担心。Windows 7:64位、64位JVM(1.6_21 IIRC) 我有一个swt.custom.CCombo框,其中包含条目列表的显示值。我有一张“显示值”->“存储值”的地图 我要存储存储值,并显示显示值。算了吧 我将数据绑定与BeanObservables、IObservables、数据绑定上下文等一起使用 我目前的方法(不起作用或者我不会要求)是使用自定义的IConverter创建我自己的UpdateValue

我正在HeliosSR2中构建插件。支持伽利略会很好,但我现在并不过分担心。Windows 7:64位、64位JVM(1.6_21 IIRC)


我有一个
swt.custom.CCombo
框,其中包含条目列表的显示值。我有一张“显示值”->“存储值”的地图

我要存储存储值,并显示显示值。算了吧

我将数据绑定与BeanObservables、IObservables、数据绑定上下文等一起使用

我目前的方法(不起作用或者我不会要求)是使用自定义的
IConverter
创建我自己的
UpdateValueStrategy
,它将在两者之间进行内部映射

我目前正在尝试扩展
org.eclipse.core.databinding.conversion.Converter
,因为IConverter被标记为
@noimplement
@noextend
@noimplement
声明客户端应该扩展
Converter
,而不是直接实现IConverter(即使Converter非常简单)

不幸的是,Eclipse的Java编译器告诉我这是一个禁忌:

访问限制:由于对所需库{install}\plugins\org.eclipse.core.databinding_1.3.100.I20100601-0800.jar的限制,无法访问类型转换器

在相关的“.api_说明”中,我看到了以下XML:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component name="org.eclipse.core.databinding_1.3.100.I20100601-0800" version="1.2">
    <plugin id="org.eclipse.core.databinding_1.3.100.I20100601-0800"/>
    <package name="org.eclipse.core.databinding" visibility="1">
        <type name="ObservablesManager" restrictions="2"/>
        <type name="UpdateListStrategy" restrictions="0">
            <method name="useMoveAndReplace" restrictions="8" signature="()Z"/>
        </type>
    </package>
    <package name="org.eclipse.core.databinding.conversion" visibility="1">
        <type name="IConverter" restrictions="3"/>
    </package>
</component>

多亏了谷歌代码,我发现visibility=“1”意味着一个公共API。好的,很好

restrictions=“3”
另一方面,表示@noextend@noimplement。听起来熟悉吗?好的,很好

但似乎对IConverter的限制正在影响转换器,使其无法使用。我不能扩展转换器,也不能从构造函数调用
super(废话,废话)
。有趣的是,编译器并没有抱怨我实现了
公共对象转换(Object fromObject)
,即使转换器没有自己的转换,所以人们可能会认为
IConverter
限制适用

显然不是

有人有吗

  • 完全不同的方法
  • 有些方法可以打破这种访问限制,让我屈服,最好是以一种本地的方式,这样我就不会在其他地方做傻事了
我找到了编译器的“受限访问”设置,并将其切换为“警告”而不是“错误”。然而,我希望我能做一些不那么全球化的事情。我会在这段时间继续,但另一种选择会很好。

真奇怪

好的,当我尝试使用自动更正“include org.eclipse.core.databinding_1.3…”时,什么都没有发生。我认为它是作为插件依赖项正确包含的,并且没有修复错误

在此期间,该插件的jar出现在我的插件项目的“插件依赖项”文件夹中,我可以查看其源代码。在这一点上,人们会认为插件正确地包含在plugin.xml中

一个是错误的

我手动添加了…core.databinding_1.3。。。到我的插件依赖项,错误消失了

因此,这似乎是自动更正中的错误,而不是API限制代码中的错误

啊!!我在导入的包列表中有org.eclipse.core.databinding。那一定是把东西扔了

现在你知道了。知道我们有战斗。加油


说到代码。以下是我正在做的(或多或少):

enum MapValueDirection{
值到键,
键到值
};
私有类映射转换器扩展转换器{
Map=null;
公共映射转换器(映射映射,映射值方向目录){
super(String.class,String.class);
if(dir==MapValueDirection.VALUE\u到\u键){
映射=反向映射(映射);
}否则{
map=map;
}
}
私有映射反向映射(映射映射){
Map reversedMap=newtreemap();
Set entries=map_u.entrySet();
对于(条目当前:条目){
reversedMap.put(curEnt.getValue(),curEnt.getKey());
}
返回反向映射;
}
/*(非Javadoc)
*@see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
*/
公共对象转换(对象来自对象){
if(map!=null&&fromObject!=null&&String.class.equals(fromObject.getClass())){
Object newVal=map.get(fromObject);
if(newVal==null){
newVal=fromObject;
}
返回newVal;
}
从对象返回;
}
}
/**
*这就是实际工作的完成情况。
*/
公共void bindBean(对象bean、PropertyDescriptor prop){
Control curControl=getControl(prop.getPropertyType());
IObservableValue uiElement=getObserver(prop,curControl);
IOvservableValue modelElement=BeanObservables.observValue(bean,prop.getName());
//“显示”=键,“存储”=值
Map profileFlds=getProfileFields();
UpdateValueStrategy toStorage=新的UpdateValueStrategy();
toStorage.setConverter(新的映射转换器(profileFlds,MapValueDirection.KEY_到_值));
UpdateValueStrategy toDisplay=新的UpdateValueStrategy();
toDisplay.setConverter(新的映射转换器(profileFlds,MapValueDirection.VALUE_到_键));
bindingContext.bindValue(uiElement、modelElement、toDisplay、toStorage);
}
我的实际代码比这要复杂一点,但你明白了。我怀疑它的效率不是很高,但从概念上讲(基于我公认的有限经验),它在整个数据绑定框架中工作得很好

制作MappingConverter的通用版本应该相当简单,但我将把它作为一个例子
enum MapValueDirection {
    VALUE_TO_KEY,
    KEY_TO_VALUE
};

private class MappingConverter extends Converter {
    Map<String, String> map = null;

    public MappingConverter( Map<String, String> map_, MapValueDirection dir) {
        super(String.class, String.class);
        if (dir == MapValueDirection.VALUE_TO_KEY) {
            map = reverseMap(map_);
        } else {
            map = map_;
        }
    }

    private Map<String, String> reverseMap(Map<String, String> map_) {
        Map<String, String> reversedMap = new TreeMap<String, String>();
        Set<Entry<String, String>> entries = map_.entrySet();
        for (Entry<String, String> 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 && fromObject != null && 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<String, String> 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);
}