Revision 85ad5f88
Added by Katja Luther over 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/InverseTermWrapper.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.ui.combo; |
|
10 |
|
|
11 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
|
12 |
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; |
|
13 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
14 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
15 |
|
|
16 |
/** |
|
17 |
* @author k.luther |
|
18 |
* @since 15.10.2018 |
|
19 |
* |
|
20 |
*/ |
|
21 |
public class InverseTermWrapper { |
|
22 |
String label; |
|
23 |
NameRelationshipType term; |
|
24 |
boolean isInverse; |
|
25 |
|
|
26 |
|
|
27 |
boolean useAbbrevLabel; |
|
28 |
|
|
29 |
InverseTermWrapper(NameRelationshipType term, boolean isInverse, boolean useAbbrevLabel){ |
|
30 |
this.term = term; |
|
31 |
this.isInverse = isInverse; |
|
32 |
this.useAbbrevLabel = useAbbrevLabel; |
|
33 |
if (isInverse){ |
|
34 |
this.label = getInverseLabel(term); |
|
35 |
}else{ |
|
36 |
this.label = getLabel( term); |
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
|
|
41 |
public NameRelationshipType getTerm() { |
|
42 |
return term; |
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
public void setTerm(NameRelationshipType term) { |
|
47 |
this.term = term; |
|
48 |
} |
|
49 |
|
|
50 |
|
|
51 |
public String getLabel() { |
|
52 |
return label; |
|
53 |
} |
|
54 |
|
|
55 |
|
|
56 |
public void setLabel(String label) { |
|
57 |
this.label = label; |
|
58 |
} |
|
59 |
|
|
60 |
public boolean isInverse() { |
|
61 |
return isInverse; |
|
62 |
} |
|
63 |
|
|
64 |
|
|
65 |
public void setInverse(boolean isInverse) { |
|
66 |
this.isInverse = isInverse; |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* @param term |
|
71 |
* @return |
|
72 |
*/ |
|
73 |
private String getInverseLabel(NameRelationshipType term) { |
|
74 |
if (term == null){ |
|
75 |
return ""; |
|
76 |
}else{ |
|
77 |
String termLabel = null; |
|
78 |
if (useAbbrevLabel){ |
|
79 |
termLabel = term.getInverseSymbol(); |
|
80 |
}else{ |
|
81 |
termLabel = term.getInverseLabel(CdmStore.getDefaultLanguage()); |
|
82 |
} |
|
83 |
if (termLabel == null){ |
|
84 |
termLabel = term.getInverseLabel(); |
|
85 |
} |
|
86 |
|
|
87 |
return termLabel; |
|
88 |
} |
|
89 |
|
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* May be overridden by derived classes if the desired label string does not |
|
94 |
* reside in term.getLabel(); |
|
95 |
* |
|
96 |
* @param term |
|
97 |
* a T object. |
|
98 |
* @return a {@link java.lang.String} object. |
|
99 |
*/ |
|
100 |
protected String getLabel(NameRelationshipType term) { |
|
101 |
if (term == null){ |
|
102 |
return ""; |
|
103 |
}else{ |
|
104 |
String termLabel = null; |
|
105 |
if (useAbbrevLabel){ |
|
106 |
termLabel = term.getIdInVocabulary(); |
|
107 |
}else{ |
|
108 |
termLabel = term.getLabel(CdmStore.getDefaultLanguage()); |
|
109 |
} |
|
110 |
if (termLabel == null){ |
|
111 |
termLabel = term.getLabel(); |
|
112 |
} |
|
113 |
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_VOCABULARY_ID_FOR_TERM_LABELS) |
|
114 |
&& term.getVocabulary()!=null){ |
|
115 |
String vocLabel = term.getVocabulary().getLabel(CdmStore.getDefaultLanguage()); |
|
116 |
if (vocLabel == null){ |
|
117 |
vocLabel = term.getVocabulary().getLabel(); |
|
118 |
} |
|
119 |
termLabel += " ["+vocLabel+"]"; |
|
120 |
} |
|
121 |
return termLabel; |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/NameRelationshipTypeCombo.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.ui.combo; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Comparator; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
import org.eclipse.jface.util.PropertyChangeEvent; |
|
16 |
import org.eclipse.swt.events.SelectionEvent; |
|
17 |
|
|
18 |
import eu.etaxonomy.cdm.model.common.TermType; |
|
19 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
|
20 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
21 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
22 |
import eu.etaxonomy.taxeditor.store.TermManager; |
|
23 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
|
24 |
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent; |
|
25 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
|
26 |
|
|
27 |
/** |
|
28 |
* @author k.luther |
|
29 |
* @since 08.10.2018 |
|
30 |
* |
|
31 |
*/ |
|
32 |
public class NameRelationshipTypeCombo<T extends InverseTermWrapper> extends AbstractComboElement<T> { |
|
33 |
|
|
34 |
|
|
35 |
List<InverseTermWrapper> wrapperList = new ArrayList<>(); |
|
36 |
T wrapperSelection; |
|
37 |
List<NameRelationshipType> terms = new ArrayList(); |
|
38 |
boolean useAbbrevLabel; |
|
39 |
|
|
40 |
|
|
41 |
/** |
|
42 |
* @param cdmFormFactory |
|
43 |
* @param parentElement |
|
44 |
* @param termType |
|
45 |
* @param labelString |
|
46 |
* @param selection |
|
47 |
* @param addEmptyElement |
|
48 |
* @param style |
|
49 |
* @param useAbbrevLabel |
|
50 |
* @param comparator |
|
51 |
*/ |
|
52 |
public NameRelationshipTypeCombo(CdmFormFactory cdmFormFactory, ICdmFormElement parentElement, |
|
53 |
String labelString, boolean addEmptyElement, int style, boolean useAbbrevLabel, |
|
54 |
Comparator<T> comparator) { |
|
55 |
super(cdmFormFactory, parentElement); |
|
56 |
// labelString, selection, addEmptyElement, style, comparator |
|
57 |
terms = getTermManager().getPreferredTerms(TermType.NameRelationshipType); |
|
58 |
this.useAbbrevLabel = useAbbrevLabel; |
|
59 |
populateTerms(); |
|
60 |
|
|
61 |
combo.addSelectionListener(this); |
|
62 |
combo.addDisposeListener(this); |
|
63 |
PreferencesUtil.getPreferenceStore().addPropertyChangeListener(this); |
|
64 |
|
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Fills the combo with elements and sets up the convenience functions |
|
70 |
* for selection index |
|
71 |
* |
|
72 |
* @param preferredTerms |
|
73 |
*/ |
|
74 |
|
|
75 |
protected void populateTerms() { |
|
76 |
|
|
77 |
combo.removeAll(); |
|
78 |
|
|
79 |
|
|
80 |
fillInverseTermWrapperList(); |
|
81 |
|
|
82 |
int i = 1; |
|
83 |
|
|
84 |
for (InverseTermWrapper termWrapper : wrapperList) { |
|
85 |
String label = termWrapper.getLabel(); |
|
86 |
combo.add(label); |
|
87 |
i++; |
|
88 |
|
|
89 |
} |
|
90 |
|
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* |
|
95 |
*/ |
|
96 |
private void fillInverseTermWrapperList() { |
|
97 |
for (NameRelationshipType term: terms){ |
|
98 |
if (term.getInverseLabel(CdmStore.getDefaultLanguage()) != null && !term.getInverseLabel(CdmStore.getDefaultLanguage()).equals(term.getLabel(CdmStore.getDefaultLanguage()))){ |
|
99 |
wrapperList.add(new InverseTermWrapper(term, true, useAbbrevLabel)); |
|
100 |
} |
|
101 |
wrapperList.add(new InverseTermWrapper(term, false, useAbbrevLabel)); |
|
102 |
} |
|
103 |
|
|
104 |
} |
|
105 |
|
|
106 |
|
|
107 |
/** {@inheritDoc} */ |
|
108 |
@Override |
|
109 |
public void widgetSelected(SelectionEvent e) { |
|
110 |
wrapperSelection = (T) wrapperList.get(combo.getSelectionIndex()); |
|
111 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e)); |
|
112 |
} |
|
113 |
|
|
114 |
/** {@inheritDoc} */ |
|
115 |
@Override |
|
116 |
public void propertyChange(PropertyChangeEvent event) { |
|
117 |
super.propertyChange(event); |
|
118 |
if (event != null |
|
119 |
&& PreferencesUtil.PREFERRED_TERMS_CHANGE.equals(event |
|
120 |
.getProperty())) { |
|
121 |
populateTerms(); |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
@Override |
|
127 |
public T getSelection() { |
|
128 |
return wrapperSelection; |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* {@inheritDoc} |
|
133 |
*/ |
|
134 |
@Override |
|
135 |
public void setSelection(T selection) { |
|
136 |
// TODO Auto-generated method stub |
|
137 |
|
|
138 |
} |
|
139 |
protected TermManager getTermManager() { |
|
140 |
return CdmStore.getTermManager(); |
|
141 |
} |
|
142 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java | ||
---|---|---|
104 | 104 |
import eu.etaxonomy.cdm.model.media.Rights; |
105 | 105 |
import eu.etaxonomy.cdm.model.molecular.DnaSample; |
106 | 106 |
import eu.etaxonomy.cdm.model.name.NameRelationship; |
107 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
|
107 | 108 |
import eu.etaxonomy.cdm.model.name.NameTypeDesignation; |
108 | 109 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus; |
109 | 110 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
... | ... | |
117 | 118 |
import eu.etaxonomy.cdm.strategy.parser.ParserProblem; |
118 | 119 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
119 | 120 |
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement; |
121 |
import eu.etaxonomy.taxeditor.ui.combo.InverseTermWrapper; |
|
120 | 122 |
import eu.etaxonomy.taxeditor.ui.combo.MisappliedRelationshipComboElement; |
123 |
import eu.etaxonomy.taxeditor.ui.combo.NameRelationshipTypeCombo; |
|
121 | 124 |
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement; |
122 | 125 |
import eu.etaxonomy.taxeditor.ui.combo.VocabularyComboElement; |
123 | 126 |
import eu.etaxonomy.taxeditor.ui.dialog.CloneClassificationDetailElement; |
... | ... | |
1014 | 1017 |
parentElement.addElement(element); |
1015 | 1018 |
return element; |
1016 | 1019 |
} |
1017 |
else{ |
|
1020 |
else {
|
|
1018 | 1021 |
//this should never happen |
1019 | 1022 |
return null; |
1020 | 1023 |
} |
1021 | 1024 |
} |
1025 |
|
|
1026 |
public NameRelationshipTypeCombo createNameRelationshipTypeCombo(ICdmFormElement parentElement, |
|
1027 |
String labelString, |
|
1028 |
int style, |
|
1029 |
boolean useAbbrevLabel, |
|
1030 |
Comparator<NameRelationshipType> comparator) { |
|
1031 |
|
|
1032 |
NameRelationshipTypeCombo<InverseTermWrapper> element = new NameRelationshipTypeCombo(this, parentElement, labelString, true, style, useAbbrevLabel, comparator); |
|
1033 |
adapt(element); |
|
1034 |
parentElement.addElement(element); |
|
1035 |
return element; |
|
1036 |
} |
|
1037 |
|
|
1022 | 1038 |
public MisappliedRelationshipComboElement createMisappliedRelationshipComboElement( |
1023 | 1039 |
ICdmFormElement parentElement, |
1024 | 1040 |
String labelString, |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameRelationshipWizardPage.java | ||
---|---|---|
14 | 14 |
import org.eclipse.swt.SWT; |
15 | 15 |
import org.eclipse.swt.widgets.Composite; |
16 | 16 |
|
17 |
import eu.etaxonomy.cdm.model.common.TermType; |
|
18 | 17 |
import eu.etaxonomy.cdm.model.name.NameRelationship; |
19 | 18 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
20 | 19 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
21 | 20 |
import eu.etaxonomy.taxeditor.ui.AbstractEntityCollectionElementWizardPage; |
22 |
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
|
|
21 |
import eu.etaxonomy.taxeditor.ui.combo.NameRelationshipTypeCombo;
|
|
23 | 22 |
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement; |
24 | 23 |
|
25 | 24 |
/** |
... | ... | |
36 | 35 |
|
37 | 36 |
private EntitySelectionElement<TaxonName> selection_relatedTo; |
38 | 37 |
|
39 |
private TermComboElement<NameRelationshipType> combo_relationshipType;
|
|
38 |
private NameRelationshipTypeCombo combo_relationshipType;
|
|
40 | 39 |
|
41 | 40 |
private final TaxonName entity; |
42 | 41 |
|
43 | 42 |
private NameRelationshipType type; |
44 | 43 |
|
45 |
private TaxonName toName; |
|
44 |
private TaxonName relatedName; |
|
45 |
boolean inverse; |
|
46 | 46 |
|
47 | 47 |
/** |
48 | 48 |
* <p> |
... | ... | |
77 | 77 |
public void createControl(Composite parent) { |
78 | 78 |
super.createControl(parent); |
79 | 79 |
|
80 |
combo_relationshipType = formFactory.createDefinedTermComboElement(TermType.NameRelationshipType, |
|
81 |
rootElement, "Name Relationship Type", null, SWT.NULL); |
|
80 |
combo_relationshipType = formFactory.createNameRelationshipTypeCombo(rootElement, |
|
81 |
"Type", SWT.NULL, false,null); |
|
82 |
|
|
82 | 83 |
|
83 | 84 |
selection_relatedTo = formFactory |
84 | 85 |
.createSelectionElement(TaxonName.class, |
... | ... | |
97 | 98 |
* @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object. |
98 | 99 |
*/ |
99 | 100 |
public NameRelationship getNameRelationship() { |
100 |
return entity.addRelationshipToName(toName, type, null, null, null); |
|
101 |
NameRelationship rel; |
|
102 |
if (inverse){ |
|
103 |
rel = entity.addRelationshipFromName(relatedName, type, null, null, null); |
|
104 |
}else{ |
|
105 |
rel = entity.addRelationshipToName(relatedName, type, null, null, null); |
|
106 |
} |
|
107 |
return rel; |
|
101 | 108 |
} |
102 | 109 |
|
103 | 110 |
/** {@inheritDoc} */ |
... | ... | |
108 | 115 |
} |
109 | 116 |
Object eventSource = event.getSource(); |
110 | 117 |
if (eventSource == combo_relationshipType) { |
111 |
type = combo_relationshipType.getSelection(); |
|
118 |
type = combo_relationshipType.getSelection().getTerm(); |
|
119 |
this.inverse = combo_relationshipType.getSelection().isInverse(); |
|
112 | 120 |
} else if (eventSource == selection_relatedTo) { |
113 |
toName = selection_relatedTo.getEntity();
|
|
121 |
relatedName = selection_relatedTo.getEntity();
|
|
114 | 122 |
} |
115 | 123 |
|
116 |
boolean complete = type != null && toName != null;
|
|
124 |
boolean complete = type != null && relatedName != null;
|
|
117 | 125 |
setPageComplete(complete); |
118 | 126 |
} |
119 | 127 |
|
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java | ||
---|---|---|
225 | 225 |
|
226 | 226 |
} |
227 | 227 |
} |
228 |
if (element instanceof Distribution && part instanceof IDistributionEditor){ |
|
228 |
if (element instanceof Distribution && part instanceof IDistributionEditor && viewer instanceof DetailsViewerE4){ |
|
229 |
|
|
229 | 230 |
((DetailsViewerE4)viewer).setInput(element, part); |
230 | 231 |
}else{ |
231 | 232 |
viewer.setInput(element); |
Also available in: Unified diff
ref #7809: namerelationshiptypes should be shown in both directions