3 * Copyright (C) 2007 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.
11 package eu
.etaxonomy
.taxeditor
.propertysheet
.description
;
13 import java
.util
.List
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.ui
.views
.properties
.ComboBoxPropertyDescriptor
;
18 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
19 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
20 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
21 import eu
.etaxonomy
.taxeditor
.store
.model
.LanguageUtil
;
28 public class CommonNamePropertySource
extends DescriptionElementPropertySource
{
29 private static final Logger logger
= Logger
30 .getLogger(CommonNamePropertySource
.class);
32 public static final String P_ID_LANGUAGE
= "language";
33 // public static final String P_LANGUAGE = "011:Language";
34 public static final String P_LANGUAGE
= "Language";
36 private CommonTaxonName commonName
;
38 private List
<Language
> languages
;
39 private String
[] languageStrings
;
40 private int selectedLanguageIndex
;
45 public CommonNamePropertySource(CommonTaxonName commonName
) {
48 this.commonName
= commonName
;
49 addDescriptor(P_ID_LANGUAGE
);
52 protected void addDescriptor(String id
) {
53 super.addDescriptor(id
);
55 if (id
.equals(P_ID_LANGUAGE
)) {
56 descriptors
.addElement(
57 new ComboBoxPropertyDescriptor(P_ID_LANGUAGE
, P_LANGUAGE
,
58 getLanguageStringArray()));
65 private String
[] getLanguageStringArray() {
66 if (languages
== null) {
67 languages
= CdmStore
.getLanguages();
70 languageStrings
= new String
[languages
.size()];
71 for (Language language
: languages
) {
72 languageStrings
[i
] = LanguageUtil
.getDescription(language
);
73 if (language
.equals(commonName
.getLanguage())) {
74 selectedLanguageIndex
= i
;
79 return languageStrings
;
82 public Object
getPropertyValue(Object id
) {
84 if (id
.equals(P_ID_LANGUAGE
)) {
85 return selectedLanguageIndex
;
88 return super.getPropertyValue(id
);
91 public void setPropertyValue(Object id
, Object value
) {
92 if (id
.equals(P_ID_LANGUAGE
)) {
93 selectedLanguageIndex
= ((Integer
) value
).intValue();
94 commonName
.setLanguage(languages
.get(selectedLanguageIndex
));
97 super.setPropertyValue(id
, value
);