p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / 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.io.IOException;
14 import java.net.MalformedURLException;
15 import java.net.URL;
16 import java.util.Vector;
17
18 import org.apache.log4j.Logger;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.widgets.Display;
21 import org.eclipse.ui.views.properties.IPropertyDescriptor;
22 import org.eclipse.ui.views.properties.IPropertySource;
23 import org.eclipse.ui.views.properties.PropertyDescriptor;
24 import org.eclipse.ui.views.properties.TextPropertyDescriptor;
25
26 import eu.etaxonomy.cdm.model.taxon.Taxon;
27 import eu.etaxonomy.taxeditor.editor.images.ImagesController;
28 import eu.etaxonomy.taxeditor.editor.images.TaxonImagesEditor;
29
30 /**
31 * @author p.ciardelli
32 * @created 30.03.2009
33 * @version 1.0
34 */
35 public class ImagePropertySource implements IPropertySource {
36 private static final Logger logger = Logger
37 .getLogger(ImagePropertySource.class);
38
39 private URL url;
40
41 private Taxon taxon;
42
43 // Property unique keys
44 public static final String P_ID_URL = "url";
45
46 // Property display keys
47 // Note: for an explanation of the sorting prefixes ("04:"),
48 // @see eu.etaxonomy.taxeditor.propertysheet.CustomSortPropertySheetEntry
49 public static final String P_URL = "00:URL";
50
51 /**
52 * @param url
53 */
54 public ImagePropertySource(Taxon taxon, URL url) {
55 this.taxon = taxon;
56 this.url = url;
57
58 addDescriptor(P_ID_URL);
59 }
60
61 protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();
62
63 protected void addDescriptor(String id) {
64 if (id.equals(P_ID_URL)) {
65 descriptors.addElement(
66 new TextPropertyDescriptor(P_ID_URL, P_URL));
67 }
68 }
69
70 /* (non-Javadoc)
71 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
72 */
73 public Object getEditableValue() {
74 return this;
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
79 */
80 public IPropertyDescriptor[] getPropertyDescriptors() {
81 return (IPropertyDescriptor[]) descriptors.toArray(
82 new IPropertyDescriptor[descriptors.size()]);
83 }
84
85 /* (non-Javadoc)
86 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
87 */
88 public Object getPropertyValue(Object id) {
89 if (id.equals(P_ID_URL)) {
90 return url.toString();
91 }
92 return null;
93 }
94
95 /* (non-Javadoc)
96 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
97 */
98 public boolean isPropertySet(Object id) {
99 return false;
100 }
101
102 /* (non-Javadoc)
103 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
104 */
105 public void resetPropertyValue(Object id) {}
106
107 /* (non-Javadoc)
108 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
109 */
110 public void setPropertyValue(Object id, Object value) {
111 if (id.equals(P_ID_URL)) {
112
113 try {
114
115 // TODO put this in an operation to allow undo
116 URL newUrl = new URL((String) value);
117
118 ImagesController.removeTaxonImageUrl(taxon, url);
119 ImagesController.addTaxonImageUrl(taxon, newUrl);
120
121 url = newUrl;
122 } catch (MalformedURLException e) {
123 // Do nothing if URL is malformed
124 } catch (IOException e) {
125 // Do nothing if URL causes an IO Exception
126 }
127 }
128 }
129 }