1d71189e3eb07d1da69b4da3a78637565c008332
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / propertysheet / reference / SingleRefTypePropertySource.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.propertysheet.reference;
11
12 import org.apache.log4j.Logger;
13 import org.eclipse.jface.viewers.ILabelProvider;
14 import org.eclipse.ui.views.properties.PropertyDescriptor;
15
16 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
17
18 /**
19 * This subclass is for cases where only one subclass of <code>ReferenceBase</code>
20 * can be edited in the property source.
21 * <p>
22 * For instance, if the user is editing an
23 * <code>Article</code>, one of its fields would be a
24 * <code>SingleRefTypePropertySource</code> restricted to a <code>Journal</code>,
25 * and the reference type drop-down would be replaced by the non-editable
26 * value "Journal".
27 *
28 * @author p.ciardelli
29 * @created 19.11.2008
30 * @version 1.0
31 */
32 public class SingleRefTypePropertySource extends ReferencePropertySource {
33 private static final Logger logger = Logger
34 .getLogger(SingleRefTypePropertySource.class);
35
36 public static final String BOOK = "Book";
37 public static final String JOURNAL = "Journal";
38
39 private String referenceType;
40
41 public SingleRefTypePropertySource(ReferenceBase reference, String referenceType) {
42 super(reference);
43
44 this.referenceType = referenceType;
45 }
46
47 protected PropertyDescriptor createReferenceTypeDescriptor() {
48 return new PropertyDescriptor(P_ID_REFERENCETYPE, P_REFERENCETYPE) {
49 public ILabelProvider getLabelProvider() {
50 return super.getLabelProvider();
51 }
52 };
53 }
54
55 public Object getPropertyValue(Object id) {
56
57 // Reference Type: show non-editable reference type in property value
58 if (id.equals(P_ID_REFERENCETYPE)) {
59 return referenceType;
60 }
61
62 return super.getPropertyValue(id);
63 }
64 }