Revision a8124871
Added by Patrick Plitzner over 8 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/AbstractMatchingPreferences.java | ||
---|---|---|
17 | 17 |
import java.util.List; |
18 | 18 |
import java.util.Map; |
19 | 19 |
|
20 |
import org.eclipse.jface.preference.PreferencePage; |
|
21 |
import org.eclipse.swt.SWT; |
|
22 |
import org.eclipse.swt.custom.CLabel; |
|
23 |
import org.eclipse.swt.events.SelectionAdapter; |
|
24 |
import org.eclipse.swt.events.SelectionEvent; |
|
25 |
import org.eclipse.swt.layout.GridLayout; |
|
20 |
import org.eclipse.jface.preference.ComboFieldEditor; |
|
21 |
import org.eclipse.jface.preference.FieldEditorPreferencePage; |
|
26 | 22 |
import org.eclipse.swt.widgets.Combo; |
27 |
import org.eclipse.swt.widgets.Composite; |
|
28 |
import org.eclipse.swt.widgets.Control; |
|
23 |
import org.eclipse.ui.IWorkbench; |
|
29 | 24 |
import org.eclipse.ui.IWorkbenchPreferencePage; |
30 | 25 |
|
31 | 26 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
... | ... | |
37 | 32 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
38 | 33 |
|
39 | 34 |
/** |
40 |
* <p>Abstract AbstractMatchingPreferences class.</p> |
|
41 |
* |
|
42 | 35 |
* @author n.hoffmann |
43 | 36 |
* @created Jan 22, 2010 |
44 | 37 |
* @version 1.0 |
45 | 38 |
*/ |
46 |
public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity> extends PreferencePage implements |
|
39 |
public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity> extends FieldEditorPreferencePage implements
|
|
47 | 40 |
IWorkbenchPreferencePage { |
48 | 41 |
|
49 | 42 |
/** |
... | ... | |
60 | 53 |
|
61 | 54 |
protected Map<String, Combo> matchModeCombos = new HashMap<String, Combo>(); |
62 | 55 |
|
63 |
/* (non-Javadoc) |
|
64 |
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) |
|
56 |
@Override |
|
57 |
public void init(IWorkbench workbench) { |
|
58 |
setPreferenceStore(PreferencesUtil.getPreferenceStore()); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* {@inheritDoc} |
|
65 | 63 |
*/ |
66 |
/** {@inheritDoc} */ |
|
67 | 64 |
@Override |
68 |
protected Control createContents(Composite parent) { |
|
69 |
final Composite composite = new Composite(parent, SWT.NULL); |
|
70 |
GridLayout gridLayout = new GridLayout(); |
|
71 |
gridLayout.numColumns = 2; |
|
72 |
composite.setLayout(gridLayout); |
|
73 |
|
|
74 |
if(!CdmStore.isActive()) { |
|
65 |
protected void createFieldEditors() { |
|
66 |
if(!CdmStore.isActive()) { |
|
75 | 67 |
MessagingUtils.noDataSourceWarningDialog(null); |
76 | 68 |
}else{ |
77 | 69 |
for(String fieldName : getFieldNames()){ |
78 |
createFieldWidget(composite, fieldName); |
|
70 |
String[][] comboValues = new String[getMatchModeList().size()][2]; |
|
71 |
for (int i=0;i<getMatchModeList().size();i++) { |
|
72 |
comboValues[i][0] = getMatchModeList().get(i).name(); |
|
73 |
comboValues[i][1] = getMatchModeList().get(i).name(); |
|
74 |
} |
|
75 |
addField(new ComboFieldEditor(this.getClass().getCanonicalName()+fieldName, |
|
76 |
fieldName, comboValues, |
|
77 |
getFieldEditorParent())); |
|
79 | 78 |
} |
80 | 79 |
} |
81 |
|
|
82 |
return composite; |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* Creates a widget for a field consisting of the label and a combo |
|
87 |
* |
|
88 |
* @see {@link #createMatchModeCombo(Composite, String, MatchMode)} |
|
89 |
* @param composite |
|
90 |
* @param fieldName |
|
91 |
*/ |
|
92 |
private void createFieldWidget(Composite parent, String fieldName) { |
|
93 |
CLabel label = new CLabel(parent, SWT.NONE); |
|
94 |
label.setText(fieldName); |
|
95 |
MatchMode matchMode = matchStrategy.getMatchMode(fieldName); |
|
96 |
|
|
97 |
createMatchModeCombo(parent, fieldName, matchMode); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Creates a combo for a field with the currently selected match mode for that field preselected |
|
102 |
* |
|
103 |
* @param parent |
|
104 |
* @param matchMode |
|
105 |
*/ |
|
106 |
private void createMatchModeCombo(Composite parent, String fieldName, MatchMode selectedMatchMode) { |
|
107 |
Combo matchModeCombo = new Combo(parent, SWT.NULL); |
|
108 |
|
|
109 |
for (MatchMode matchMode : getMatchModeList()) { |
|
110 |
matchModeCombo.add(matchMode.name()); |
|
111 |
} |
|
112 |
|
|
113 |
int index = getMatchModeList().indexOf(selectedMatchMode); |
|
114 |
|
|
115 |
matchModeCombo.select(index); |
|
116 |
|
|
117 |
matchModeCombo.addSelectionListener(new MatchModeComboSelectionListener(matchModeCombo, fieldName)); |
|
118 |
|
|
119 |
matchModeCombos.put(fieldName, matchModeCombo); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* This listener updates the cache strategy when a value was changed in one of the combos |
|
124 |
* |
|
125 |
* @author n.hoffmann |
|
126 |
* @created Jan 28, 2010 |
|
127 |
* @version 1.0 |
|
128 |
*/ |
|
129 |
private class MatchModeComboSelectionListener extends SelectionAdapter{ |
|
130 |
|
|
131 |
private final Combo matchModeCombo; |
|
132 |
private final String fieldName; |
|
133 |
|
|
134 |
MatchModeComboSelectionListener(Combo matchModeCombo, String fieldName){ |
|
135 |
this.matchModeCombo = matchModeCombo; |
|
136 |
this.fieldName = fieldName; |
|
137 |
} |
|
138 |
|
|
139 |
/* (non-Javadoc) |
|
140 |
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
|
141 |
*/ |
|
142 |
@Override |
|
143 |
public void widgetSelected(SelectionEvent event) { |
|
144 |
super.widgetSelected(event); |
|
145 |
MatchMode matchMode = getMatchModeList().get(matchModeCombo.getSelectionIndex()); |
|
146 |
try { |
|
147 |
matchStrategy.setMatchMode(fieldName, matchMode); |
|
148 |
} catch (MatchException e) { |
|
149 |
MessagingUtils.error(this.getClass(), e); |
|
150 |
throw new RuntimeException(e); |
|
151 |
} |
|
152 |
} |
|
153 | 80 |
} |
154 | 81 |
|
155 | 82 |
/** |
... | ... | |
202 | 129 |
return fields; |
203 | 130 |
} |
204 | 131 |
|
205 |
/* (non-Javadoc) |
|
206 |
* @see org.eclipse.jface.preference.PreferencePage#performApply() |
|
207 |
*/ |
|
208 |
/** {@inheritDoc} */ |
|
209 |
@Override |
|
210 |
protected void performApply() { |
|
211 |
PreferencesUtil.setMatchStrategy(matchStrategy); |
|
212 |
super.performApply(); |
|
213 |
} |
|
214 |
|
|
215 |
/* (non-Javadoc) |
|
216 |
* @see org.eclipse.jface.preference.PreferencePage#performDefaults() |
|
217 |
*/ |
|
218 |
/** {@inheritDoc} */ |
|
219 |
@Override |
|
220 |
protected void performDefaults() { |
|
221 |
try { |
|
222 |
// set match strategy to default |
|
223 |
matchStrategy = getDefaultMatchStrategy(); |
|
224 |
|
|
225 |
// set combos to their default values |
|
226 |
for(String fieldName : matchModeCombos.keySet()){ |
|
227 |
Combo combo = matchModeCombos.get(fieldName); |
|
228 |
MatchMode matchMode = matchStrategy.getMatchMode(fieldName); |
|
229 |
combo.select(matchModeList.indexOf(matchMode)); |
|
230 |
} |
|
231 |
|
|
232 |
} catch (MatchException e) { |
|
233 |
MessagingUtils.error(this.getClass(), e); |
|
234 |
throw new RuntimeException(e); |
|
235 |
} |
|
236 |
super.performDefaults(); |
|
237 |
} |
|
238 |
|
|
239 | 132 |
/** |
240 | 133 |
* Returns the default match strategy for the respective class |
241 | 134 |
* |
Also available in: Unified diff
Fixed persistency of Matching preferences #5337