gpt4 book ai didi

java - SWT 组合中的空条目

转载 作者:行者123 更新时间:2023-12-01 10:45:46 27 4
gpt4 key购买 nike

我有一个 SWT 组合,其中有一个空条目和一些值。当我选择空条目时,它不会触发任何事件。但我需要触发更新事件。如果我确实调用 firePropertyChange() 方法,我总是会在控制台中收到以下异常。

在 importMap 中,它具有以下值 - { ,1,2,3,4} 。第一个值是空字符串。

我正在数据绑定(bind)上下文中绑定(bind)组合值

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;
}

这是每当我在组合框中选择一个项目时遇到的以下异常

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$4.run(ValueBinding.java:197)
at org.eclipse.core.databinding.observable.Realm$1.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$3.run(ValueBinding.java:188)
at org.eclipse.core.databinding.observable.Realm$1.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$4(ValueBinding.java:140)
at org.eclipse.core.databinding.ValueBinding$1.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$1.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$1(SimplePropertyObservableValue.java:112)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue$2.run(SimplePropertyObservableValue.java:66)
at org.eclipse.core.databinding.observable.Realm$1.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$1.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$4(Workbench.java:2427)
at org.eclipse.ui.internal.Workbench$7.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 中。

关于java - SWT 组合中的空条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34182634/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com