2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
;
11 import org
.eclipse
.core
.expressions
.PropertyTester
;
12 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
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
;
26 public class TermBasePropertyTester
extends PropertyTester
{
28 private static final String IS_MODIFIABLE
= "isModifiable";
32 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
35 public boolean test(Object receiver
, String property
, Object
[] args
,
36 Object expectedValue
) {
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);
43 if(IS_MODIFIABLE
.equals(property
)){
44 return isModifiable(term
);
53 * Checks whether there is a {@link Marker} with the type {@link MarkerType#MODIFIABLE()} and if there is then return its value.
55 * @return The markers value if it exists
57 public static boolean isModifiable(TermBase termBase
) {
58 if (termBase
== null){
62 TermVocabulary vocabulary
= null;
64 if(termBase
instanceof DefinedTermBase
){
65 vocabulary
= ((DefinedTermBase
) termBase
).getVocabulary();
66 }else if(termBase
instanceof TermVocabulary
){
67 vocabulary
= (TermVocabulary
) termBase
;
70 if(vocabulary
== null){
74 for(Marker vocabularyMarker
: vocabulary
.getMarkers()){
75 if(vocabularyMarker
.getMarkerType().equals(MarkerType
.MODIFIABLE())){
76 return vocabularyMarker
.getValue();