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.ui.section.media;
|
12
|
|
13
|
import java.io.IOException;
|
14
|
import java.net.URI;
|
15
|
import java.util.Collection;
|
16
|
|
17
|
import org.apache.commons.lang.StringUtils;
|
18
|
import org.apache.http.HttpException;
|
19
|
import org.eclipse.swt.events.SelectionListener;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.service.IMediaService;
|
22
|
import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData;
|
23
|
import eu.etaxonomy.cdm.model.media.ImageFile;
|
24
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
25
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
28
|
import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
|
29
|
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
|
30
|
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EntityDetailType;
|
31
|
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
|
33
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
|
34
|
|
35
|
/**
|
36
|
* <p>MediaRepresentationElement class.</p>
|
37
|
*
|
38
|
* @author n.hoffmann
|
39
|
* @created Mar 24, 2010
|
40
|
* @version 1.0
|
41
|
*/
|
42
|
public class MediaRepresentationElement extends AbstractEntityCollectionElement<MediaRepresentation> {
|
43
|
|
44
|
private MediaRepresentationPartSection section_mediaRepresentationPart;
|
45
|
private TextWithLabelElement text_mimeType;
|
46
|
private TextWithLabelElement text_suffix;
|
47
|
|
48
|
/**
|
49
|
* <p>Constructor for MediaRepresentationElement.</p>
|
50
|
*
|
51
|
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
|
52
|
* @param section a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection} object.
|
53
|
* @param element a {@link eu.etaxonomy.cdm.model.media.MediaRepresentation} object.
|
54
|
* @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
|
55
|
* @param style a int.
|
56
|
*/
|
57
|
public MediaRepresentationElement(CdmFormFactory cdmFormFactory,
|
58
|
AbstractFormSection section,
|
59
|
MediaRepresentation element, SelectionListener removeListener,
|
60
|
int style) {
|
61
|
super(cdmFormFactory, section, element, removeListener, null, style);
|
62
|
}
|
63
|
|
64
|
/* (non-Javadoc)
|
65
|
* @see eu.etaxonomy.taxeditor.forms.section.AbstractEntityCollectionElement#createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, int)
|
66
|
*/
|
67
|
/** {@inheritDoc} */
|
68
|
@Override
|
69
|
public void createControls(ICdmFormElement element, int style) {
|
70
|
text_mimeType = formFactory.createTextWithLabelElement(element, "Mime Type", null, style);
|
71
|
text_suffix = formFactory.createTextWithLabelElement(element, "Suffix", null, style);
|
72
|
section_mediaRepresentationPart = (MediaRepresentationPartSection) formFactory.createEntityDetailSection(EntityDetailType.MEDIAREPRESENTATIONPART, getConversationHolder(), element, style);
|
73
|
section_mediaRepresentationPart.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY(2, 1));
|
74
|
}
|
75
|
|
76
|
/** {@inheritDoc} */
|
77
|
@Override
|
78
|
public void setEntity(MediaRepresentation element) {
|
79
|
this.entity = element;
|
80
|
section_mediaRepresentationPart.setEntity(element);
|
81
|
text_mimeType.setText(element.getMimeType());
|
82
|
text_suffix.setText(element.getSuffix());
|
83
|
}
|
84
|
|
85
|
/*
|
86
|
* (non-Javadoc)
|
87
|
* @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#handleEvent(java.lang.Object)
|
88
|
*/
|
89
|
/** {@inheritDoc} */
|
90
|
@Override
|
91
|
public void handleEvent(Object eventSource) {
|
92
|
if(eventSource == text_mimeType){
|
93
|
getEntity().setMimeType(text_mimeType.getText());
|
94
|
}
|
95
|
else if(eventSource == text_suffix){
|
96
|
getEntity().setSuffix(text_suffix.getText());
|
97
|
}
|
98
|
// FIXME HACK automatically set the mime type to the first mediaRepresentationPart's mimetype
|
99
|
else if(eventSource == section_mediaRepresentationPart){
|
100
|
Collection<MediaRepresentationPart> imageFileElements = section_mediaRepresentationPart.getCollection(section_mediaRepresentationPart.getEntity());
|
101
|
|
102
|
MediaRepresentationPart mediaRepresentationPart = imageFileElements.iterator().next();
|
103
|
if(mediaRepresentationPart == null || !(mediaRepresentationPart instanceof ImageFile)){
|
104
|
return;
|
105
|
}
|
106
|
ImageFile imageFile = (ImageFile) mediaRepresentationPart;
|
107
|
|
108
|
URI uri = imageFile.getUri();
|
109
|
if(uri == null){
|
110
|
return;
|
111
|
}
|
112
|
try {
|
113
|
ImageMetaData imageInfo = CdmStore.getService(IMediaService.class).getImageInfo(uri, 10000);
|
114
|
String mimeType = imageInfo.getMimeType();
|
115
|
text_mimeType.setText(mimeType);
|
116
|
|
117
|
|
118
|
} catch (IOException e) {
|
119
|
StoreUtil.error(getClass(), e);
|
120
|
} catch (HttpException e) {
|
121
|
StoreUtil.error(getClass(), e);
|
122
|
}
|
123
|
String path = uri.getPath();
|
124
|
|
125
|
String suffix = path.substring(StringUtils.lastIndexOf(path, '.')+1);
|
126
|
text_suffix.setText(suffix);
|
127
|
}
|
128
|
}
|
129
|
|
130
|
private String getMimeType(URI uri){
|
131
|
return null;
|
132
|
}
|
133
|
}
|