Revision 6a534f27
Added by Katja Luther over 5 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditingSupportE4.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.ArrayList; |
4 | 4 |
import java.util.Arrays; |
5 |
import java.util.Collection; |
|
6 |
import java.util.Comparator; |
|
5 | 7 |
import java.util.List; |
8 |
import java.util.Map; |
|
6 | 9 |
import java.util.Set; |
7 | 10 |
import java.util.SortedSet; |
11 |
import java.util.UUID; |
|
8 | 12 |
|
9 | 13 |
import javax.inject.Inject; |
10 | 14 |
|
... | ... | |
15 | 19 |
import org.eclipse.jface.viewers.CellEditor; |
16 | 20 |
import org.eclipse.jface.viewers.ComboBoxViewerCellEditor; |
17 | 21 |
import org.eclipse.jface.viewers.EditingSupport; |
22 |
import org.eclipse.jface.viewers.ICellEditorListener; |
|
18 | 23 |
import org.eclipse.jface.viewers.ISelection; |
19 | 24 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
20 | 25 |
import org.eclipse.jface.viewers.LabelProvider; |
... | ... | |
25 | 30 |
import org.eclipse.swt.widgets.TableColumn; |
26 | 31 |
|
27 | 32 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
33 |
import eu.etaxonomy.cdm.model.common.OrderedTermComparator; |
|
34 |
import eu.etaxonomy.cdm.model.common.Representation; |
|
28 | 35 |
import eu.etaxonomy.cdm.model.common.TermType; |
29 | 36 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
37 |
import eu.etaxonomy.cdm.model.description.DescriptionElementSource; |
|
30 | 38 |
import eu.etaxonomy.cdm.model.description.Distribution; |
31 | 39 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
32 | 40 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
... | ... | |
63 | 71 |
public String getText(Object element) { |
64 | 72 |
if (element instanceof PresenceAbsenceTerm) { |
65 | 73 |
PresenceAbsenceTerm status = (PresenceAbsenceTerm)element; |
74 |
Representation rep = status.getPreferredRepresentation(CdmStore.getDefaultLanguage()); |
|
75 |
String label = null; |
|
76 |
if (rep != null){ |
|
77 |
label = rep.getAbbreviatedLabel(); |
|
78 |
if (label == null){ |
|
79 |
label = rep.getLabel(); |
|
80 |
} |
|
81 |
}else{ |
|
82 |
label = status.getTitleCache(); |
|
83 |
} |
|
66 | 84 |
String result = null; |
67 | 85 |
if (PreferencesUtil.isShowSymbolInChecklistEditor() && !StringUtils.isBlank(status.getSymbol())){ |
68 |
result = status.getTitleCache() + "("+ status.getSymbol()+")";
|
|
86 |
result = label + "("+ status.getSymbol()+")";
|
|
69 | 87 |
}else{ |
70 |
result = status.getTitleCache();
|
|
88 |
result = label;
|
|
71 | 89 |
} |
72 | 90 |
return result; |
73 | 91 |
} |
... | ... | |
78 | 96 |
cellEditor.setContentProvider(new ArrayContentProvider()); |
79 | 97 |
|
80 | 98 |
|
81 |
List<DefinedTermBase<?>> inputAll = new ArrayList<>();
|
|
99 |
List<DefinedTermBase> inputAll = new ArrayList<>(); |
|
82 | 100 |
PresenceAbsenceTerm noneTerm = PresenceAbsenceTerm.NewInstance(); |
83 | 101 |
noneTerm.setTitleCache(" ", true); |
84 | 102 |
inputAll.add(noneTerm); |
85 |
List<DefinedTermBase<?>> input = CdmStore.getTermManager().getPreferredTerms(TermType.PresenceAbsenceTerm); |
|
86 |
inputAll.addAll(1, input); |
|
103 |
Collection<DefinedTermBase> input = CdmStore.getTermManager().getPreferredTerms(TermType.PresenceAbsenceTerm); |
|
104 |
List<DefinedTermBase> inputList = new ArrayList(input); |
|
105 |
Comparator<DefinedTermBase> comp = new OrderedTermComparator<>(); |
|
106 |
// Collections.sort(inputList, comp); |
|
107 |
inputAll.addAll(1,inputList); |
|
108 |
|
|
109 |
|
|
87 | 110 |
cellEditor.setInput(inputAll); |
111 |
cellEditor.addListener(new ICellEditorListener() { |
|
112 |
|
|
113 |
@Override |
|
114 |
public void applyEditorValue() { |
|
115 |
// TODO Auto-generated method stub |
|
116 |
|
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public void cancelEditor() { |
|
121 |
// TODO Auto-generated method stub |
|
122 |
|
|
123 |
} |
|
124 |
|
|
125 |
@Override |
|
126 |
public void editorValueChanged(boolean oldValidState, boolean newValidState) { |
|
127 |
fireStateChanged(cellEditor.getValue()); |
|
128 |
|
|
129 |
} |
|
130 |
|
|
131 |
}); |
|
88 | 132 |
|
89 | 133 |
|
90 | 134 |
} |
... | ... | |
100 | 144 |
} |
101 | 145 |
|
102 | 146 |
@Override |
103 |
protected Object getValue(Object element) {
|
|
147 |
protected PresenceAbsenceTerm getValue(Object element) {
|
|
104 | 148 |
if (element instanceof Taxon) { |
105 | 149 |
Taxon taxon = (Taxon) element; |
106 | 150 |
String result = null; |
... | ... | |
113 | 157 |
} |
114 | 158 |
|
115 | 159 |
//fireStateChanged(distributionForColumn); |
116 |
return result;
|
|
160 |
return null;
|
|
117 | 161 |
} |
118 | 162 |
return null; |
119 | 163 |
} |
120 | 164 |
|
121 |
protected void fireStateChanged(Distribution dist) { |
|
165 |
|
|
166 |
|
|
167 |
protected void fireStateChanged(Object dist) { |
|
122 | 168 |
if (dist!= null){ |
123 | 169 |
ISelection selection = new StructuredSelection(dist); |
124 |
// selService.setSelection(selection);
|
|
170 |
selService.setSelection(selection); |
|
125 | 171 |
} |
126 | 172 |
} |
127 | 173 |
|
... | ... | |
171 | 217 |
for (DescriptionElementBase deb : td.getElements()) { |
172 | 218 |
if (deb instanceof Distribution) { |
173 | 219 |
Distribution distribution = (Distribution) deb; |
220 |
UUID areaUuid = null; |
|
221 |
for (Map.Entry<UUID,Integer> entry: editor.getAreaPosition().entrySet()){ |
|
222 |
if (entry.getValue().intValue()== columnIndex){ |
|
223 |
areaUuid = entry.getKey(); |
|
224 |
break; |
|
225 |
} |
|
226 |
} |
|
174 | 227 |
if (distribution.getArea() != null){ |
175 |
if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){ |
|
176 |
if (column.getText().equalsIgnoreCase(distribution.getArea().getIdInVocabulary())) { |
|
177 |
return distribution; |
|
178 |
} |
|
179 |
}else{ |
|
180 |
if (column.getText().equalsIgnoreCase(distribution.getArea().getTitleCache())) { |
|
181 |
return distribution; |
|
182 |
} |
|
228 |
if (distribution.getArea().getUuid().equals(areaUuid)){ |
|
229 |
return distribution; |
|
230 |
|
|
183 | 231 |
} |
184 | 232 |
} |
185 | 233 |
} |
... | ... | |
200 | 248 |
if (areaIndex == columnIndex){ |
201 | 249 |
NamedArea area = (NamedArea) term; |
202 | 250 |
Distribution distribution = Distribution.NewInstance(area, occurenceStatus); |
251 |
if (editor.getDefaultSource() != null){ |
|
252 |
DescriptionElementSource source = DescriptionElementSource.NewPrimarySourceInstance(editor.getDefaultSource(), ""); |
|
253 |
distribution.addSource(source); |
|
254 |
} |
|
203 | 255 |
Set<TaxonDescription> descriptions = taxon.getDescriptions(); |
204 | 256 |
if (!descriptions.isEmpty()) { |
205 | 257 |
for (TaxonDescription desc : descriptions) { |
Also available in: Unified diff
add button to select default source in distribution editor