3c2ac1f1700f4ab484c8912a6678d01cbebea0a9
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / propertysheet / description / CommonNamePropertySource.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.propertysheet.description;
12
13 import java.util.List;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
17
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;
22
23 /**
24 * @author p.ciardelli
25 * @created 02.04.2009
26 * @version 1.0
27 */
28 public class CommonNamePropertySource extends DescriptionElementPropertySource {
29 private static final Logger logger = Logger
30 .getLogger(CommonNamePropertySource.class);
31
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";
35
36 private CommonTaxonName commonName;
37
38 private List<Language> languages;
39 private String[] languageStrings;
40 private int selectedLanguageIndex;
41
42 /**
43 * @param element
44 */
45 public CommonNamePropertySource(CommonTaxonName commonName) {
46 super(commonName);
47
48 this.commonName = commonName;
49 addDescriptor(P_ID_LANGUAGE);
50 }
51
52 protected void addDescriptor(String id) {
53 super.addDescriptor(id);
54
55 if (id.equals(P_ID_LANGUAGE)) {
56 descriptors.addElement(
57 new ComboBoxPropertyDescriptor(P_ID_LANGUAGE, P_LANGUAGE,
58 getLanguageStringArray()));
59 }
60 }
61
62 /**
63 * @return
64 */
65 private String[] getLanguageStringArray() {
66 if (languages == null) {
67 languages = CdmStore.getLanguages();
68
69 int i = 0;
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;
75 }
76 i++;
77 }
78 }
79 return languageStrings;
80 }
81
82 public Object getPropertyValue(Object id) {
83
84 if (id.equals(P_ID_LANGUAGE)) {
85 return selectedLanguageIndex;
86 }
87
88 return super.getPropertyValue(id);
89 }
90
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));
95 }
96
97 super.setPropertyValue(id, value);
98 }
99 }