开发者

How do I change content of ComboFieldEditor?

开发者 https://www.devze.com 2022-12-27 14:18 出处:网络
I want to开发者_开发知识库 change the values on one ComboFieldEditor depending on another ComboFieldEditor in an eclipse plugin. E.g. if the user changes the package, different classes need to be popu

I want to开发者_开发知识库 change the values on one ComboFieldEditor depending on another ComboFieldEditor in an eclipse plugin. E.g. if the user changes the package, different classes need to be populated in the second ComboFieldEditor. The ComboFieldEditor class does not seem to to have a way to change the items on the fly.


I created a SmartComboFieldEditor class to allow me to elegantly get and set the value of a ComboFieldEditor using the backing data store behind the scenes.

package wat.core.plugin;

import org.eclipse.jface.preference.ComboFieldEditor;
import org.eclipse.swt.widgets.Composite;

public class SmartComboFieldEditor extends ComboFieldEditor {

    public SmartComboFieldEditor(String name, String labelText, String[][] entryNamesAndValues, Composite parent) {
        super(name, labelText, entryNamesAndValues, parent);
    }

    public String getSelectedValue()
    {
        doStore();
        return getPreferenceStore().getString(getPreferenceName());
    }

    public void setSelectedValue(String newValue)
    {
        getPreferenceStore().setValue(getPreferenceName(), newValue);
        doLoad();
    }
}

Then you can override the propertyChange and performOK methods like so:

public void propertyChange(PropertyChangeEvent event) {
  super.propertyChange(event);
  if (event.getSource() == combo1)
  {
    if (combo1.getSelectedValue().equals("Some Value"))
    {
      combo2.setSelectedValue("Some Other Value");
    }
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号