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