Revision 499e1f2b
Added by Andreas Müller over 9 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/AbstractMatchingPreferences.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
32 | 32 |
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy; |
33 | 33 |
import eu.etaxonomy.cdm.strategy.match.MatchException; |
34 | 34 |
import eu.etaxonomy.cdm.strategy.match.MatchMode; |
35 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
35 | 36 |
import eu.etaxonomy.taxeditor.parser.MatchStrategyConfigurator; |
36 |
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
|
37 |
import eu.etaxonomy.taxeditor.store.CdmStore;
|
|
37 | 38 |
|
38 | 39 |
/** |
39 | 40 |
* <p>Abstract AbstractMatchingPreferences class.</p> |
... | ... | |
52 | 53 |
"|parsingProblem|problemStarts|problemEnds|PROTECTED|NOT_PROTECTED|propertyChangeSupport"; |
53 | 54 |
|
54 | 55 |
protected IMatchStrategy matchStrategy; |
55 |
|
|
56 |
|
|
56 | 57 |
protected Class<T> clazz; |
57 | 58 |
|
58 | 59 |
private List<MatchMode> matchModeList; |
59 |
|
|
60 |
|
|
60 | 61 |
protected Map<String, Combo> matchModeCombos = new HashMap<String, Combo>(); |
61 |
|
|
62 |
|
|
62 | 63 |
/* (non-Javadoc) |
63 | 64 |
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) |
64 | 65 |
*/ |
... | ... | |
69 | 70 |
GridLayout gridLayout = new GridLayout(); |
70 | 71 |
gridLayout.numColumns = 2; |
71 | 72 |
composite.setLayout(gridLayout); |
72 |
|
|
73 |
|
|
74 |
for(String fieldName : getFieldNames()){ |
|
75 |
createFieldWidget(composite, fieldName); |
|
76 |
} |
|
77 |
|
|
73 |
|
|
74 |
if(!CdmStore.isActive()) { |
|
75 |
MessagingUtils.noDataSourceWarningDialog(null); |
|
76 |
}else{ |
|
77 |
for(String fieldName : getFieldNames()){ |
|
78 |
createFieldWidget(composite, fieldName); |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
78 | 82 |
return composite; |
79 | 83 |
} |
80 |
|
|
84 |
|
|
81 | 85 |
/** |
82 | 86 |
* Creates a widget for a field consisting of the label and a combo |
83 |
*
|
|
87 |
* |
|
84 | 88 |
* @see {@link #createMatchModeCombo(Composite, String, MatchMode)} |
85 | 89 |
* @param composite |
86 | 90 |
* @param fieldName |
87 | 91 |
*/ |
88 | 92 |
private void createFieldWidget(Composite parent, String fieldName) { |
89 |
CLabel label = new CLabel(parent, SWT.NONE); |
|
90 |
label.setText(fieldName); |
|
91 |
|
|
92 |
MatchMode matchMode = matchStrategy.getMatchMode(fieldName); |
|
93 |
|
|
94 |
createMatchModeCombo(parent, fieldName, matchMode); |
|
95 |
} |
|
96 |
|
|
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 |
|
|
97 | 100 |
/** |
98 | 101 |
* Creates a combo for a field with the currently selected match mode for that field preselected |
99 |
*
|
|
102 |
* |
|
100 | 103 |
* @param parent |
101 | 104 |
* @param matchMode |
102 | 105 |
*/ |
103 | 106 |
private void createMatchModeCombo(Composite parent, String fieldName, MatchMode selectedMatchMode) { |
104 | 107 |
Combo matchModeCombo = new Combo(parent, SWT.NULL); |
105 |
|
|
108 |
|
|
106 | 109 |
for (MatchMode matchMode : getMatchModeList()) { |
107 | 110 |
matchModeCombo.add(matchMode.name()); |
108 | 111 |
} |
109 |
|
|
112 |
|
|
110 | 113 |
int index = getMatchModeList().indexOf(selectedMatchMode); |
111 |
|
|
114 |
|
|
112 | 115 |
matchModeCombo.select(index); |
113 |
|
|
116 |
|
|
114 | 117 |
matchModeCombo.addSelectionListener(new MatchModeComboSelectionListener(matchModeCombo, fieldName)); |
115 |
|
|
118 |
|
|
116 | 119 |
matchModeCombos.put(fieldName, matchModeCombo); |
117 | 120 |
} |
118 |
|
|
121 |
|
|
119 | 122 |
/** |
120 | 123 |
* This listener updates the cache strategy when a value was changed in one of the combos |
121 |
*
|
|
124 |
* |
|
122 | 125 |
* @author n.hoffmann |
123 | 126 |
* @created Jan 28, 2010 |
124 | 127 |
* @version 1.0 |
125 | 128 |
*/ |
126 | 129 |
private class MatchModeComboSelectionListener extends SelectionAdapter{ |
127 |
|
|
128 |
private Combo matchModeCombo; |
|
129 |
private String fieldName; |
|
130 |
|
|
131 |
private final Combo matchModeCombo;
|
|
132 |
private final String fieldName;
|
|
130 | 133 |
|
131 | 134 |
MatchModeComboSelectionListener(Combo matchModeCombo, String fieldName){ |
132 | 135 |
this.matchModeCombo = matchModeCombo; |
133 | 136 |
this.fieldName = fieldName; |
134 | 137 |
} |
135 |
|
|
138 |
|
|
136 | 139 |
/* (non-Javadoc) |
137 | 140 |
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
138 | 141 |
*/ |
... | ... | |
143 | 146 |
try { |
144 | 147 |
matchStrategy.setMatchMode(fieldName, matchMode); |
145 | 148 |
} catch (MatchException e) { |
146 |
StoreUtil.error(this.getClass(), e);
|
|
149 |
MessagingUtils.error(this.getClass(), e);
|
|
147 | 150 |
throw new RuntimeException(e); |
148 | 151 |
} |
149 | 152 |
} |
... | ... | |
151 | 154 |
|
152 | 155 |
/** |
153 | 156 |
* Transforms the MatchMode enum into a list. |
154 |
*
|
|
157 |
* |
|
155 | 158 |
* @return |
156 | 159 |
*/ |
157 | 160 |
private List<MatchMode> getMatchModeList(){ |
... | ... | |
163 | 166 |
|
164 | 167 |
/** |
165 | 168 |
* Get names of all declared fields |
166 |
*
|
|
169 |
* |
|
167 | 170 |
* @return |
168 | 171 |
*/ |
169 |
private List<String> getFieldNames(){
|
|
172 |
private List<String> getFieldNames(){ |
|
170 | 173 |
List<Field> fields = new ArrayList<Field>(); |
171 |
|
|
174 |
|
|
172 | 175 |
fields = getAllFields(fields, clazz); |
173 | 176 |
List<String> fieldNames = new ArrayList<String>(); |
174 |
|
|
177 |
|
|
175 | 178 |
for(Field field : fields){ |
176 | 179 |
String fieldName = field.getName(); |
177 | 180 |
if(! fieldName.matches(ExcludePattern)){ |
178 | 181 |
fieldNames.add(fieldName); |
179 | 182 |
} |
180 | 183 |
} |
181 |
|
|
184 |
|
|
182 | 185 |
return fieldNames; |
183 | 186 |
} |
184 |
|
|
187 |
|
|
185 | 188 |
/** |
186 | 189 |
* Get all declared fields including fields of the superclasses. |
187 | 190 |
* |
... | ... | |
198 | 201 |
|
199 | 202 |
return fields; |
200 | 203 |
} |
201 |
|
|
204 |
|
|
202 | 205 |
/* (non-Javadoc) |
203 | 206 |
* @see org.eclipse.jface.preference.PreferencePage#performApply() |
204 | 207 |
*/ |
... | ... | |
208 | 211 |
MatchStrategyConfigurator.setMatchStrategy(matchStrategy); |
209 | 212 |
super.performApply(); |
210 | 213 |
} |
211 |
|
|
214 |
|
|
212 | 215 |
/* (non-Javadoc) |
213 | 216 |
* @see org.eclipse.jface.preference.PreferencePage#performDefaults() |
214 | 217 |
*/ |
... | ... | |
218 | 221 |
try { |
219 | 222 |
// set match strategy to default |
220 | 223 |
matchStrategy = getDefaultMatchStrategy(); |
221 |
|
|
224 |
|
|
222 | 225 |
// set combos to their default values |
223 | 226 |
for(String fieldName : matchModeCombos.keySet()){ |
224 | 227 |
Combo combo = matchModeCombos.get(fieldName); |
225 | 228 |
MatchMode matchMode = matchStrategy.getMatchMode(fieldName); |
226 | 229 |
combo.select(matchModeList.indexOf(matchMode)); |
227 | 230 |
} |
228 |
|
|
231 |
|
|
229 | 232 |
} catch (MatchException e) { |
230 |
StoreUtil.error(this.getClass(), e);
|
|
233 |
MessagingUtils.error(this.getClass(), e);
|
|
231 | 234 |
throw new RuntimeException(e); |
232 | 235 |
} |
233 | 236 |
super.performDefaults(); |
234 | 237 |
} |
235 |
|
|
238 |
|
|
236 | 239 |
/** |
237 | 240 |
* Returns the default match strategy for the respective class |
238 | 241 |
* |
Also available in: Unified diff
merge trunk to Validation Editor