1
|
/**
|
2
|
* Copyright (C) 2009 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.editor.definedterm;
|
10
|
|
11
|
import org.eclipse.core.expressions.PropertyTester;
|
12
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
13
|
|
14
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
15
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
16
|
import eu.etaxonomy.cdm.model.common.Marker;
|
17
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
18
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
19
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
20
|
|
21
|
/**
|
22
|
* @author l.morris
|
23
|
* @date 9 Jan 2012
|
24
|
*
|
25
|
*/
|
26
|
public class TermBasePropertyTester extends PropertyTester {
|
27
|
|
28
|
private static final String IS_MODIFIABLE = "isModifiable";
|
29
|
|
30
|
|
31
|
/* (non-Javadoc)
|
32
|
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
|
33
|
*/
|
34
|
@Override
|
35
|
public boolean test(Object receiver, String property, Object[] args,
|
36
|
Object expectedValue) {
|
37
|
|
38
|
IStructuredSelection selection = (IStructuredSelection) receiver;
|
39
|
Object selectedElement = selection.getFirstElement();
|
40
|
if (selectedElement != null && HibernateProxyHelper.isInstanceOf(selectedElement, TermBase.class)){
|
41
|
TermBase term = HibernateProxyHelper.deproxy(selectedElement, TermBase.class);
|
42
|
|
43
|
if(IS_MODIFIABLE.equals(property)){
|
44
|
return isModifiable(term);
|
45
|
}
|
46
|
}
|
47
|
|
48
|
return false;
|
49
|
}
|
50
|
|
51
|
|
52
|
/**
|
53
|
* 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
|
56
|
*/
|
57
|
public static boolean isModifiable(TermBase termBase) {
|
58
|
if (termBase == null){
|
59
|
return true;
|
60
|
}
|
61
|
|
62
|
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
|
|
70
|
if(vocabulary == null){
|
71
|
return true;
|
72
|
}
|
73
|
|
74
|
for(Marker vocabularyMarker : vocabulary.getMarkers()){
|
75
|
if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){
|
76
|
return vocabularyMarker.getValue();
|
77
|
}
|
78
|
}
|
79
|
|
80
|
return true;
|
81
|
}
|
82
|
|
83
|
}
|