9b79702d042f645758f13ac1c5b994279abb2431
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / propertysheet / images / ImagePropertySource.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.images;
12
13 import java.util.Vector;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.ui.views.properties.IPropertyDescriptor;
17 import org.eclipse.ui.views.properties.IPropertySource;
18 import org.eclipse.ui.views.properties.PropertyDescriptor;
19
20 import eu.etaxonomy.cdm.model.media.ImageFile;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22
23 /**
24 * @author p.ciardelli
25 * @created 30.03.2009
26 * @version 1.0
27 */
28 public class ImagePropertySource implements IPropertySource {
29 private static final Logger logger = Logger
30 .getLogger(ImagePropertySource.class);
31
32 private ImageFile imageFile;
33
34 private Taxon taxon;
35
36 // Property unique keys
37 public static final String P_ID_IMAGE = "image";
38
39 // Property display keys
40 public static final String P_IMAGE = "Image URI";
41
42 /**
43 * @param url
44 */
45 public ImagePropertySource(Taxon taxon, ImageFile imageFile) {
46 this.setTaxon(taxon);
47 this.imageFile = imageFile;
48
49 addDescriptor(P_ID_IMAGE);
50 }
51
52 protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();
53
54 protected void addDescriptor(String id) {
55 if (id.equals(P_ID_IMAGE)) {
56 descriptors.addElement(
57 new PropertyDescriptor(P_ID_IMAGE, P_IMAGE));
58 }
59 }
60
61 /* (non-Javadoc)
62 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
63 */
64 public Object getEditableValue() {
65 return this;
66 }
67
68 /* (non-Javadoc)
69 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
70 */
71 public IPropertyDescriptor[] getPropertyDescriptors() {
72 return (IPropertyDescriptor[]) descriptors.toArray(
73 new IPropertyDescriptor[descriptors.size()]);
74 }
75
76 /* (non-Javadoc)
77 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
78 */
79 public Object getPropertyValue(Object id) {
80 if (id.equals(P_ID_IMAGE)) {
81 return imageFile.getUri();
82 }
83 return null;
84 }
85
86 /* (non-Javadoc)
87 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
88 */
89 public boolean isPropertySet(Object id) {
90 return false;
91 }
92
93 /* (non-Javadoc)
94 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
95 */
96 public void resetPropertyValue(Object id) {}
97
98 /* (non-Javadoc)
99 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
100 */
101 public void setPropertyValue(Object id, Object value) {
102
103 logger.error("Not yet implemented.");
104
105 // if (id.equals(P_ID_IMAGE)) {
106 //
107 // // TODO put this in an operation to allow undo
108 // ImageFile imageFile = ImageFile.NewInstance((String) value, null);
109 //
110 // ImagesUtil.removeTaxonImage(taxon, imageFile);
111 // ImagesUtil.addTaxonImage(taxon, imageFile);
112 //
113 // this.imageFile = imageFile;
114 //
115 // }
116 }
117
118 public ImageFile getImageFile(){
119 return imageFile;
120 }
121
122 /**
123 * @param taxon the taxon to set
124 */
125 public void setTaxon(Taxon taxon) {
126 this.taxon = taxon;
127 }
128
129 /**
130 * @return the taxon
131 */
132 public Taxon getTaxon() {
133 return taxon;
134 }
135 }