Revision 191f2328
Added by Patrick Plitzner over 8 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationPartElement.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
13 | 13 |
import java.net.URI; |
14 | 14 |
|
15 | 15 |
import org.apache.commons.io.FileUtils; |
16 |
import org.apache.commons.lang.StringUtils; |
|
17 | 16 |
import org.eclipse.swt.events.SelectionListener; |
18 | 17 |
|
19 | 18 |
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart; |
20 | 19 |
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection; |
21 | 20 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
22 | 21 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
23 |
import eu.etaxonomy.taxeditor.ui.element.LabelElement; |
|
24 | 22 |
import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement; |
25 |
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
|
23 |
import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
|
|
26 | 24 |
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement; |
27 | 25 |
|
28 | 26 |
/** |
... | ... | |
35 | 33 |
public class MediaRepresentationPartElement<T extends MediaRepresentationPart> extends |
36 | 34 |
AbstractEntityCollectionElement<T> { |
37 | 35 |
|
38 |
protected TextWithLabelElement text_uri;
|
|
36 |
protected UriWithLabelElement text_uri;
|
|
39 | 37 |
protected NumberWithLabelElement text_size; |
40 | 38 |
|
41 |
protected LabelElement element_messages; |
|
42 |
|
|
43 |
/** |
|
44 |
* <p>Constructor for AbstractMediaRepresentationPartElement.</p> |
|
45 |
* |
|
46 |
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object. |
|
47 |
* @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object. |
|
48 |
* @param element a T object. |
|
49 |
* @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object. |
|
50 |
* @param style a int. |
|
51 |
* @param <T> a T object. |
|
52 |
*/ |
|
53 | 39 |
public MediaRepresentationPartElement(CdmFormFactory formFactory, |
54 | 40 |
AbstractFormSection section, |
55 | 41 |
T element, SelectionListener removeListener, |
56 | 42 |
int style) { |
57 | 43 |
super(formFactory, section, element, removeListener, null, style); |
58 | 44 |
} |
59 |
|
|
45 |
|
|
60 | 46 |
/** {@inheritDoc} */ |
61 | 47 |
@Override |
62 | 48 |
public void createControls(ICdmFormElement element, int style) { |
63 |
text_uri = formFactory.createTextWithLabelElement(element, "URI", null, style);
|
|
49 |
text_uri = formFactory.createUriWithLabelElement(element, "URI", null, style);
|
|
64 | 50 |
text_size = formFactory.createNumberTextWithLabelElement(element, "Size", null, style); |
65 | 51 |
text_size.setEnabled(false); |
66 |
|
|
67 |
element_messages = formFactory.createLabel(element, ""); |
|
68 | 52 |
} |
69 | 53 |
|
70 | 54 |
@Override |
... | ... | |
76 | 60 |
if(entity.getUri() != null){ |
77 | 61 |
text_uri.setText(entity.getUri().toString()); |
78 | 62 |
} |
79 |
element_messages.setText("We currrently do not know how to display this generic MediaRepresentationPart to you."); |
|
80 | 63 |
} |
81 | 64 |
|
82 | 65 |
@Override |
83 | 66 |
public void handleEvent(Object eventSource) { |
84 | 67 |
if(eventSource == text_uri){ |
85 |
try { |
|
86 |
String uriString = text_uri.getText(); |
|
87 |
URI uri = StringUtils.isNotEmpty(uriString) ? new URI(uriString) : null; |
|
88 |
getEntity().setUri(uri); |
|
89 |
} catch (Exception e) { |
|
90 |
handleException(e); |
|
91 |
} finally { |
|
92 |
firePropertyChangeEvent(this); |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
protected void handleException(Exception e) { |
|
98 |
element_messages.setText(e.getMessage()); |
|
99 |
text_size.setText(""); |
|
68 |
URI uri = text_uri.getUri(); |
|
69 |
getEntity().setUri(uri); |
|
70 |
firePropertyChangeEvent(this); |
|
71 |
} |
|
100 | 72 |
} |
101 | 73 |
|
102 | 74 |
} |
Also available in: Unified diff
Show URI parsing exceptions below URI text field (fixes #5055, #5003, #4587)