Revision 67f98be5
Added by Patrick Plitzner over 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermBasePropertyTester.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2009 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
11 | 11 |
import org.eclipse.core.expressions.PropertyTester; |
12 | 12 |
import org.eclipse.jface.viewers.IStructuredSelection; |
13 | 13 |
|
14 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
|
14 | 15 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
15 | 16 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
16 | 17 |
import eu.etaxonomy.cdm.model.common.Marker; |
17 | 18 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
18 | 19 |
import eu.etaxonomy.cdm.model.common.TermBase; |
19 | 20 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
21 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
|
22 |
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto; |
|
23 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
20 | 24 |
|
21 | 25 |
/** |
22 | 26 |
* @author l.morris |
... | ... | |
26 | 30 |
public class TermBasePropertyTester extends PropertyTester { |
27 | 31 |
|
28 | 32 |
private static final String IS_MODIFIABLE = "isModifiable"; |
29 |
|
|
33 |
|
|
30 | 34 |
|
31 | 35 |
/* (non-Javadoc) |
32 | 36 |
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object) |
... | ... | |
34 | 38 |
@Override |
35 | 39 |
public boolean test(Object receiver, String property, Object[] args, |
36 | 40 |
Object expectedValue) { |
37 |
|
|
41 |
|
|
38 | 42 |
IStructuredSelection selection = (IStructuredSelection) receiver; |
39 | 43 |
Object selectedElement = selection.getFirstElement(); |
40 | 44 |
if (selectedElement != null && HibernateProxyHelper.isInstanceOf(selectedElement, TermBase.class)){ |
... | ... | |
44 | 48 |
return isModifiable(term); |
45 | 49 |
} |
46 | 50 |
} |
47 |
|
|
51 |
|
|
48 | 52 |
return false; |
49 | 53 |
} |
50 | 54 |
|
51 | 55 |
|
52 | 56 |
/** |
53 | 57 |
* Checks whether there is a {@link Marker} with the type {@link MarkerType#MODIFIABLE()} and if there is then return its value. |
54 |
*
|
|
55 |
* @return The markers value if it exists
|
|
58 |
* |
|
59 |
* @return The markers value if it exists |
|
56 | 60 |
*/ |
57 |
public static boolean isModifiable(TermBase termBase) {
|
|
58 |
if (termBase == null){
|
|
61 |
public static boolean isModifiable(Object object) {
|
|
62 |
if (object == null){
|
|
59 | 63 |
return true; |
60 | 64 |
} |
61 |
|
|
65 |
|
|
62 | 66 |
TermVocabulary vocabulary = null; |
63 |
|
|
64 |
if(termBase instanceof DefinedTermBase){ |
|
65 |
vocabulary = ((DefinedTermBase) termBase).getVocabulary(); |
|
66 |
}else if(termBase instanceof TermVocabulary){ |
|
67 |
vocabulary = (TermVocabulary) termBase; |
|
68 |
} |
|
69 |
|
|
67 |
|
|
68 |
if(object instanceof DefinedTermBase){ |
|
69 |
vocabulary = ((DefinedTermBase) object).getVocabulary(); |
|
70 |
}else if(object instanceof TermVocabulary){ |
|
71 |
vocabulary = (TermVocabulary) object; |
|
72 |
}else if(object instanceof TermDto){ |
|
73 |
vocabulary = CdmStore.getService(IVocabularyService.class).load(((TermDto) object).getVocabularyUuid()); |
|
74 |
}else if(object instanceof TermVocabularyDto){ |
|
75 |
vocabulary = CdmStore.getService(IVocabularyService.class).load(((TermVocabularyDto) object).getUuid()); |
|
76 |
} |
|
77 |
|
|
70 | 78 |
if(vocabulary == null){ |
71 | 79 |
return true; |
72 | 80 |
} |
73 |
|
|
81 |
|
|
74 | 82 |
for(Marker vocabularyMarker : vocabulary.getMarkers()){ |
75 | 83 |
if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){ |
76 |
return vocabularyMarker.getValue();
|
|
84 |
return vocabularyMarker.getValue(); |
|
77 | 85 |
} |
78 | 86 |
} |
79 |
|
|
87 |
|
|
80 | 88 |
return true; |
81 | 89 |
} |
82 | 90 |
|
Also available in: Unified diff
ref #7887 Refactor isModifiable() property test