3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
;
12 import org
.eclipse
.core
.expressions
.PropertyTester
;
13 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
15 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
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
;
27 public class TermBasePropertyTester
extends PropertyTester
{
29 private static final String IS_MODIFIABLE
= "isModifiable";
33 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
36 public boolean test(Object receiver
, String property
, Object
[] args
,
37 Object expectedValue
) {
39 IStructuredSelection selection
= (IStructuredSelection
) receiver
;
40 CdmBase selectedElement
= (CdmBase
)selection
.getFirstElement();
41 if (selectedElement
.isInstanceOf(TermBase
.class)){
42 TermBase term
= CdmBase
.deproxy(selectedElement
, TermBase
.class);
44 if(IS_MODIFIABLE
.equals(property
)){
45 return isModifiable(term
);
54 * Checks whether there is a {@link Marker} with the type {@link MarkerType#MODIFIABLE()} and if there is then return its value.
56 * @return The markers value if it exists
58 public static boolean isModifiable(TermBase termBase
) {
59 if (termBase
== null){
63 TermVocabulary vocabulary
= null;
65 if(termBase
instanceof DefinedTermBase
){
66 vocabulary
= ((DefinedTermBase
) termBase
).getVocabulary();
67 }else if(termBase
instanceof TermVocabulary
){
68 vocabulary
= (TermVocabulary
) termBase
;
71 if(vocabulary
== null){
75 for(Marker vocabularyMarker
: vocabulary
.getMarkers()){
76 if(vocabularyMarker
.getMarkerType().equals(MarkerType
.MODIFIABLE())){
77 return vocabularyMarker
.getValue();