gpt4 book ai didi

java - 如何使用 Jface 同步两个 Eclipse 部件

转载 作者:行者123 更新时间:2023-12-01 04:23:26 25 4
gpt4 key购买 nike

我发现使用数据绑定(bind)同步两个 Eclipse 部件时出现问题,我在包含文本框的两个部件类之间使用了一个模型,并且两个类都与该模型绑定(bind)。

第一部分:

DataBindingContext databindingcontext = new DataBindingContext();
textLeft = new Text(parent, SWT.BORDER);
textLeft.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
IObservableValue iobservableModel = PojoProperties.value("name").observe(new Name());
IObservableValue observablevalueLeft = WidgetProperties.text (SWT.Modify).observe(textLeft);
databindingcontext.bindValue (observablevalueLeft,iobservableModel);

型号:

public class Name {
public static String static_strName;

public String getName() {
return static_strName;
}

public void setName(String name) {
static_strName = name;
}
}

第 2 部分:

DataBindingContext m_databindingcontext = new DataBindingContext();
textPart2 = new Text(parent, SWT.BORDER);
textPart2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
IObservableValue iobservableModel = PojoProperties.value("name").observe(new Name());
IObservableValue observablevaluePart2 = WidgetProperties.text (SWT.Modify).observe(textPart2);
m_databindingcontext.bindValue (observablevaluePart2,iobservableModel);

最佳答案

试试这个:您需要 PropertyChangeSupport

DataBindingContext bindingContext = new DataBindingContext();
textLeft = new Text(parent, SWT.BORDER);
textLeft.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
IObservableValue observablevalueLeft = SWTObservables.observeText(textLeft , SWT.Modify);
IObservableValue iobservableModel = BeansObservables.observeValue(modelChangeRegistry, "name");
bindingContext.bindValue(iobservableModel, iobservableModel , null, null);

public class Name extends AbstractPropertyRegistration {

public static String static_strName;
public String getName() {
return static_strName;
}
public void setName(String name) {
static_strName = name;
}
}

public abstract class AbstractPropertyRegistration {
private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(listener);
}
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(listener);
}

public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
}

protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
}

关于java - 如何使用 Jface 同步两个 Eclipse 部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18737415/

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