How to change the contents of a ComboFieldEditor?

I want to change the values ​​to one ComboFieldEditor depending on another ComboFieldEditor in the eclipse plugin. For instance. if the user changes the value of package , in the second ComboFieldEditor it is necessary to fill in different classes. The ComboFieldEditor class does not seem to be able to modify elements on the fly.

+2
source share
1 answer

I created the SmartComboFieldEditor class to allow me to elegantly get and set the ComboFieldEditor value using the backup 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 as follows:

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

Source: https://habr.com/ru/post/1393329/


All Articles