3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.propertysheet
.images
;
13 import java
.io
.IOException
;
14 import java
.net
.MalformedURLException
;
16 import java
.util
.Vector
;
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
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.taxeditor
.editor
.images
.ImagesController
;
28 import eu
.etaxonomy
.taxeditor
.editor
.images
.TaxonImagesEditor
;
35 public class ImagePropertySource
implements IPropertySource
{
36 private static final Logger logger
= Logger
37 .getLogger(ImagePropertySource
.class);
43 // Property unique keys
44 public static final String P_ID_URL
= "url";
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";
54 public ImagePropertySource(Taxon taxon
, URL url
) {
58 addDescriptor(P_ID_URL
);
61 protected Vector
<PropertyDescriptor
> descriptors
= new Vector
<PropertyDescriptor
>();
63 protected void addDescriptor(String id
) {
64 if (id
.equals(P_ID_URL
)) {
65 descriptors
.addElement(
66 new TextPropertyDescriptor(P_ID_URL
, P_URL
));
71 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
73 public Object
getEditableValue() {
78 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
80 public IPropertyDescriptor
[] getPropertyDescriptors() {
81 return (IPropertyDescriptor
[]) descriptors
.toArray(
82 new IPropertyDescriptor
[descriptors
.size()]);
86 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
88 public Object
getPropertyValue(Object id
) {
89 if (id
.equals(P_ID_URL
)) {
90 return url
.toString();
96 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
98 public boolean isPropertySet(Object id
) {
103 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
105 public void resetPropertyValue(Object id
) {}
108 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
110 public void setPropertyValue(Object id
, Object value
) {
111 if (id
.equals(P_ID_URL
)) {
115 // TODO put this in an operation to allow undo
116 URL newUrl
= new URL((String
) value
);
118 ImagesController
.removeTaxonImageUrl(taxon
, url
);
119 ImagesController
.addTaxonImageUrl(taxon
, 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