import java.util.List;
import java.util.Map;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.jface.preference.ComboFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
- * <p>Abstract AbstractMatchingPreferences class.</p>
- *
* @author n.hoffmann
* @created Jan 22, 2010
* @version 1.0
*/
-public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity> extends PreferencePage implements
+public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity> extends FieldEditorPreferencePage implements
IWorkbenchPreferencePage {
/**
protected Map<String, Combo> matchModeCombos = new HashMap<String, Combo>();
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+ @Override
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(PreferencesUtil.getPreferenceStore());
+ }
+
+ /**
+ * {@inheritDoc}
*/
- /** {@inheritDoc} */
@Override
- protected Control createContents(Composite parent) {
- final Composite composite = new Composite(parent, SWT.NULL);
- GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 2;
- composite.setLayout(gridLayout);
-
- if(!CdmStore.isActive()) {
+ protected void createFieldEditors() {
+ if(!CdmStore.isActive()) {
MessagingUtils.noDataSourceWarningDialog(null);
}else{
for(String fieldName : getFieldNames()){
- createFieldWidget(composite, fieldName);
+ String[][] comboValues = new String[getMatchModeList().size()][2];
+ for (int i=0;i<getMatchModeList().size();i++) {
+ comboValues[i][0] = getMatchModeList().get(i).name();
+ comboValues[i][1] = getMatchModeList().get(i).name();
+ }
+ addField(new ComboFieldEditor(this.getClass().getCanonicalName()+fieldName,
+ fieldName, comboValues,
+ getFieldEditorParent()));
}
}
-
- return composite;
- }
-
- /**
- * Creates a widget for a field consisting of the label and a combo
- *
- * @see {@link #createMatchModeCombo(Composite, String, MatchMode)}
- * @param composite
- * @param fieldName
- */
- private void createFieldWidget(Composite parent, String fieldName) {
- CLabel label = new CLabel(parent, SWT.NONE);
- label.setText(fieldName);
- MatchMode matchMode = matchStrategy.getMatchMode(fieldName);
-
- createMatchModeCombo(parent, fieldName, matchMode);
- }
-
- /**
- * Creates a combo for a field with the currently selected match mode for that field preselected
- *
- * @param parent
- * @param matchMode
- */
- private void createMatchModeCombo(Composite parent, String fieldName, MatchMode selectedMatchMode) {
- Combo matchModeCombo = new Combo(parent, SWT.NULL);
-
- for (MatchMode matchMode : getMatchModeList()) {
- matchModeCombo.add(matchMode.name());
- }
-
- int index = getMatchModeList().indexOf(selectedMatchMode);
-
- matchModeCombo.select(index);
-
- matchModeCombo.addSelectionListener(new MatchModeComboSelectionListener(matchModeCombo, fieldName));
-
- matchModeCombos.put(fieldName, matchModeCombo);
- }
-
- /**
- * This listener updates the cache strategy when a value was changed in one of the combos
- *
- * @author n.hoffmann
- * @created Jan 28, 2010
- * @version 1.0
- */
- private class MatchModeComboSelectionListener extends SelectionAdapter{
-
- private final Combo matchModeCombo;
- private final String fieldName;
-
- MatchModeComboSelectionListener(Combo matchModeCombo, String fieldName){
- this.matchModeCombo = matchModeCombo;
- this.fieldName = fieldName;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetSelected(SelectionEvent event) {
- super.widgetSelected(event);
- MatchMode matchMode = getMatchModeList().get(matchModeCombo.getSelectionIndex());
- try {
- matchStrategy.setMatchMode(fieldName, matchMode);
- } catch (MatchException e) {
- MessagingUtils.error(this.getClass(), e);
- throw new RuntimeException(e);
- }
- }
}
/**
return fields;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#performApply()
- */
- /** {@inheritDoc} */
- @Override
- protected void performApply() {
- PreferencesUtil.setMatchStrategy(matchStrategy);
- super.performApply();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
- */
- /** {@inheritDoc} */
- @Override
- protected void performDefaults() {
- try {
- // set match strategy to default
- matchStrategy = getDefaultMatchStrategy();
-
- // set combos to their default values
- for(String fieldName : matchModeCombos.keySet()){
- Combo combo = matchModeCombos.get(fieldName);
- MatchMode matchMode = matchStrategy.getMatchMode(fieldName);
- combo.select(matchModeList.indexOf(matchMode));
- }
-
- } catch (MatchException e) {
- MessagingUtils.error(this.getClass(), e);
- throw new RuntimeException(e);
- }
- super.performDefaults();
- }
-
/**
* Returns the default match strategy for the respective class
*