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.api.service.IVocabularyService;
|
15
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
16
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
17
|
import eu.etaxonomy.cdm.model.common.Marker;
|
18
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
19
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
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;
|
24
|
|
25
|
/**
|
26
|
* @author l.morris
|
27
|
* @date 9 Jan 2012
|
28
|
*
|
29
|
*/
|
30
|
public class TermBasePropertyTester extends PropertyTester {
|
31
|
|
32
|
private static final String IS_MODIFIABLE = "isModifiable";
|
33
|
|
34
|
|
35
|
/* (non-Javadoc)
|
36
|
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
|
37
|
*/
|
38
|
@Override
|
39
|
public boolean test(Object receiver, String property, Object[] args,
|
40
|
Object expectedValue) {
|
41
|
|
42
|
IStructuredSelection selection = (IStructuredSelection) receiver;
|
43
|
Object selectedElement = selection.getFirstElement();
|
44
|
if (selectedElement != null && HibernateProxyHelper.isInstanceOf(selectedElement, TermBase.class)){
|
45
|
TermBase term = HibernateProxyHelper.deproxy(selectedElement, TermBase.class);
|
46
|
|
47
|
if(IS_MODIFIABLE.equals(property)){
|
48
|
return isModifiable(term);
|
49
|
}
|
50
|
}
|
51
|
|
52
|
return false;
|
53
|
}
|
54
|
|
55
|
|
56
|
/**
|
57
|
* Checks whether there is a {@link Marker} with the type {@link MarkerType#MODIFIABLE()} and if there is then return its value.
|
58
|
*
|
59
|
* @return The markers value if it exists
|
60
|
*/
|
61
|
public static boolean isModifiable(Object object) {
|
62
|
if (object == null){
|
63
|
return true;
|
64
|
}
|
65
|
|
66
|
TermVocabulary vocabulary = null;
|
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
|
|
78
|
if(vocabulary == null){
|
79
|
return true;
|
80
|
}
|
81
|
|
82
|
for(Marker vocabularyMarker : vocabulary.getMarkers()){
|
83
|
if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){
|
84
|
return vocabularyMarker.getValue();
|
85
|
}
|
86
|
}
|
87
|
|
88
|
return true;
|
89
|
}
|
90
|
|
91
|
}
|