SWT 组合中的空条目
Empty entry in the SWT combo
我有一个 SWT 组合,它有一个空条目和一些值。当我 select 空条目时,它不会触发任何事件。但我需要触发更新事件。如果我调用 firePropertyChange() 方法,我总是会在控制台中收到以下异常。
在 importMap 中,它具有以下值 - { ,1,2,3,4} 。第一个值是一个空字符串。
我在数据绑定上下文中绑定组合值
IObservableValue observeSelectionCImportObserveWidget = WidgetProperties.selection().observe(cImport);
IObservableValue importModelObserveValue = BeanProperties.value("import").observe(model);
bindingContext.bindValue(observeSelectionCImportObserveWidget, importModelObserveValue, null, new UpdateValueStrategy(UpdateValueStrategy.POLICY_ON_REQUEST));
IObservableValue observeSingleSelectionIndexCImportObserveWidget = WidgetProperties.singleSelectionIndex().observe(cImport);
IObservableValue importIndexModelObserveValue = BeanProperties.value("importIndex").observe(model);
bindingContext.bindValue(observeSingleSelectionIndexCImportObserveWidget, importIndexModelObserveValue, null, null);
IObservableList itemsCImportObserveWidget = WidgetProperties.items().observe(cImport);
IObservableList importComboModelObserveList = BeanProperties.list("importCombo").observe(model);
bindingContext.bindList(itemsCImportObserveWidget, importComboModelObserveList, null, null);
public void setImport(String value){
if(value.equals(""))
return;
long index = 0;
for (Entry<Long, String> entry : importmap.entrySet()) {
if (entry.getValue().equals(value)) {
index = entry.getKey();
break;
}
}
if(ag.getImport() == index) return; // ag is a class which has getters and setters for Import.
ag.setImport(index);
setPriority(); // this method gets the value ag.getImport() and does some operation and updates the values in a text field
IsDirty();
}
public String getImport(){
if(ag.getImport() < 1)
return "";
return importMap.get(ag.getImport());
}
public int getImportIndex(){
if(ag.getImport() < 1)
return -1;
long index = 0;
for (Entry<Long, String> entry : importmap.entrySet()) {
if (entry.getKey() == ag.getImport()) {
return (int) index;
}
index++;
}
return -1;
}
public List<String> getImportCombo(){
List<String> importValues = new ArrayList<String>();
if(importMap != null && importmap.size() > 0)
importtValues.addAll(importmap.values());
return importValues;
}
这是我在 select 组合框中的一个项目时得到的以下异常
WARN : 16:12:49,983 - TcLogger$IC_PrintStream.log:?
java.lang.NullPointerException
at org.eclipse.core.internal.databinding.beans.BeanPropertyHelper.writeProperty(BeanPropertyHelper.java:51)
at org.eclipse.core.internal.databinding.beans.BeanValueProperty.doSetValue(BeanValueProperty.java:51)
at org.eclipse.core.databinding.property.value.ValueProperty.setValue(ValueProperty.java:67)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.doSetValue(SimplePropertyObservableValue.java:104)
at org.eclipse.core.databinding.observable.value.AbstractObservableValue.setValue(AbstractObservableValue.java:55)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.setValue(DecoratingObservableValue.java:103)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.setValue(DecoratingObservableValue.java:103)
at org.eclipse.core.databinding.UpdateValueStrategy.doSet(UpdateValueStrategy.java:486)
at org.eclipse.core.databinding.ValueBinding.run(ValueBinding.java:197)
at org.eclipse.core.databinding.observable.Realm.run(Realm.java:148)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:152)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:170)
at org.eclipse.core.databinding.ValueBinding.run(ValueBinding.java:188)
at org.eclipse.core.databinding.observable.Realm.run(Realm.java:148)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:152)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:170)
at org.eclipse.core.databinding.ValueBinding.doUpdate(ValueBinding.java:151)
at org.eclipse.core.databinding.ValueBinding.access(ValueBinding.java:140)
at org.eclipse.core.databinding.ValueBinding.handleValueChange(ValueBinding.java:45)
at org.eclipse.core.databinding.observable.value.ValueChangeEvent.dispatch(ValueChangeEvent.java:62)
at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:119)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.fireValueChange(DecoratingObservableValue.java:55)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.handleValueChange(DecoratingObservableValue.java:93)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.handleValueChange(DecoratingObservableValue.java:67)
at org.eclipse.core.databinding.observable.value.ValueChangeEvent.dispatch(ValueChangeEvent.java:62)
at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:119)
at org.eclipse.core.databinding.observable.value.AbstractObservableValue.fireValueChange(AbstractObservableValue.java:71)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.notifyIfChanged(SimplePropertyObservableValue.java:120)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.access(SimplePropertyObservableValue.java:112)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.run(SimplePropertyObservableValue.java:66)
at org.eclipse.core.databinding.observable.Realm.run(Realm.java:148)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:152)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:170)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.handleEvent(SimplePropertyObservableValue.java:63)
at org.eclipse.core.databinding.property.NativePropertyListener.fireChange(NativePropertyListener.java:63)
at org.eclipse.jface.internal.databinding.swt.WidgetListener.handleEvent(WidgetListener.java:55)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access(Workbench.java:2427)
at org.eclipse.ui.internal.Workbench.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at com.teamcenter.rac.aifrcp.Application.runApplication(Unknown Source)
at com.teamcenter.rac.aifrcp.Application.start(Unknown Source)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
如果您正在使用 'importIndex',您需要有一个 'setImportIndex' 方法,以便可以将更改的值保存在 bean 中。
我有一个 SWT 组合,它有一个空条目和一些值。当我 select 空条目时,它不会触发任何事件。但我需要触发更新事件。如果我调用 firePropertyChange() 方法,我总是会在控制台中收到以下异常。
在 importMap 中,它具有以下值 - { ,1,2,3,4} 。第一个值是一个空字符串。
我在数据绑定上下文中绑定组合值
IObservableValue observeSelectionCImportObserveWidget = WidgetProperties.selection().observe(cImport);
IObservableValue importModelObserveValue = BeanProperties.value("import").observe(model);
bindingContext.bindValue(observeSelectionCImportObserveWidget, importModelObserveValue, null, new UpdateValueStrategy(UpdateValueStrategy.POLICY_ON_REQUEST));
IObservableValue observeSingleSelectionIndexCImportObserveWidget = WidgetProperties.singleSelectionIndex().observe(cImport);
IObservableValue importIndexModelObserveValue = BeanProperties.value("importIndex").observe(model);
bindingContext.bindValue(observeSingleSelectionIndexCImportObserveWidget, importIndexModelObserveValue, null, null);
IObservableList itemsCImportObserveWidget = WidgetProperties.items().observe(cImport);
IObservableList importComboModelObserveList = BeanProperties.list("importCombo").observe(model);
bindingContext.bindList(itemsCImportObserveWidget, importComboModelObserveList, null, null);
public void setImport(String value){
if(value.equals(""))
return;
long index = 0;
for (Entry<Long, String> entry : importmap.entrySet()) {
if (entry.getValue().equals(value)) {
index = entry.getKey();
break;
}
}
if(ag.getImport() == index) return; // ag is a class which has getters and setters for Import.
ag.setImport(index);
setPriority(); // this method gets the value ag.getImport() and does some operation and updates the values in a text field
IsDirty();
}
public String getImport(){
if(ag.getImport() < 1)
return "";
return importMap.get(ag.getImport());
}
public int getImportIndex(){
if(ag.getImport() < 1)
return -1;
long index = 0;
for (Entry<Long, String> entry : importmap.entrySet()) {
if (entry.getKey() == ag.getImport()) {
return (int) index;
}
index++;
}
return -1;
}
public List<String> getImportCombo(){
List<String> importValues = new ArrayList<String>();
if(importMap != null && importmap.size() > 0)
importtValues.addAll(importmap.values());
return importValues;
}
这是我在 select 组合框中的一个项目时得到的以下异常
WARN : 16:12:49,983 - TcLogger$IC_PrintStream.log:?
java.lang.NullPointerException
at org.eclipse.core.internal.databinding.beans.BeanPropertyHelper.writeProperty(BeanPropertyHelper.java:51)
at org.eclipse.core.internal.databinding.beans.BeanValueProperty.doSetValue(BeanValueProperty.java:51)
at org.eclipse.core.databinding.property.value.ValueProperty.setValue(ValueProperty.java:67)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.doSetValue(SimplePropertyObservableValue.java:104)
at org.eclipse.core.databinding.observable.value.AbstractObservableValue.setValue(AbstractObservableValue.java:55)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.setValue(DecoratingObservableValue.java:103)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.setValue(DecoratingObservableValue.java:103)
at org.eclipse.core.databinding.UpdateValueStrategy.doSet(UpdateValueStrategy.java:486)
at org.eclipse.core.databinding.ValueBinding.run(ValueBinding.java:197)
at org.eclipse.core.databinding.observable.Realm.run(Realm.java:148)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:152)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:170)
at org.eclipse.core.databinding.ValueBinding.run(ValueBinding.java:188)
at org.eclipse.core.databinding.observable.Realm.run(Realm.java:148)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:152)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:170)
at org.eclipse.core.databinding.ValueBinding.doUpdate(ValueBinding.java:151)
at org.eclipse.core.databinding.ValueBinding.access(ValueBinding.java:140)
at org.eclipse.core.databinding.ValueBinding.handleValueChange(ValueBinding.java:45)
at org.eclipse.core.databinding.observable.value.ValueChangeEvent.dispatch(ValueChangeEvent.java:62)
at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:119)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.fireValueChange(DecoratingObservableValue.java:55)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.handleValueChange(DecoratingObservableValue.java:93)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.handleValueChange(DecoratingObservableValue.java:67)
at org.eclipse.core.databinding.observable.value.ValueChangeEvent.dispatch(ValueChangeEvent.java:62)
at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:119)
at org.eclipse.core.databinding.observable.value.AbstractObservableValue.fireValueChange(AbstractObservableValue.java:71)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.notifyIfChanged(SimplePropertyObservableValue.java:120)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.access(SimplePropertyObservableValue.java:112)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.run(SimplePropertyObservableValue.java:66)
at org.eclipse.core.databinding.observable.Realm.run(Realm.java:148)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:152)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:170)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.handleEvent(SimplePropertyObservableValue.java:63)
at org.eclipse.core.databinding.property.NativePropertyListener.fireChange(NativePropertyListener.java:63)
at org.eclipse.jface.internal.databinding.swt.WidgetListener.handleEvent(WidgetListener.java:55)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access(Workbench.java:2427)
at org.eclipse.ui.internal.Workbench.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at com.teamcenter.rac.aifrcp.Application.runApplication(Unknown Source)
at com.teamcenter.rac.aifrcp.Application.start(Unknown Source)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
如果您正在使用 'importIndex',您需要有一个 'setImportIndex' 方法,以便可以将更改的值保存在 bean 中。