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