1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2014 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
|
package eu.etaxonomy.taxeditor.ui.section.media;
|
11
|
|
12
|
import java.net.URISyntaxException;
|
13
|
import java.util.List;
|
14
|
import java.util.Set;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.media.Media;
|
17
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
18
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
19
|
import eu.etaxonomy.cdm.model.media.MediaUtils;
|
20
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
21
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
22
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
25
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
28
|
|
29
|
/**
|
30
|
* @author pplitzner
|
31
|
* @date 25.08.2014
|
32
|
*
|
33
|
*/
|
34
|
public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
|
35
|
|
36
|
private UriWithLabelElement textUri;
|
37
|
private MediaRepresentationSection section_mediaRepresentation;
|
38
|
|
39
|
private boolean isAdvancedMediaView;
|
40
|
private MediaRepresentationPart singleMediaRepresentationPart;
|
41
|
private ICdmFormElement parentFormElement;
|
42
|
private int style;
|
43
|
|
44
|
/**
|
45
|
* @param formFactory
|
46
|
* @param formElement
|
47
|
*/
|
48
|
public MediaDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
|
49
|
super(formFactory, formElement);
|
50
|
}
|
51
|
|
52
|
/* (non-Javadoc)
|
53
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.ui.element.ICdmFormElement, java.lang.Object, int)
|
54
|
*/
|
55
|
@Override
|
56
|
protected void createControls(ICdmFormElement formElement, Media entity, int style) {
|
57
|
this.parentFormElement = formElement;
|
58
|
this.style = style;
|
59
|
}
|
60
|
|
61
|
/* (non-Javadoc)
|
62
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement#setEntity(java.lang.Object)
|
63
|
*/
|
64
|
@Override
|
65
|
public void setEntity(Media entity) {
|
66
|
super.setEntity(entity);
|
67
|
if(singleMediaRepresentationPart==null){
|
68
|
singleMediaRepresentationPart = MediaUtils.initFirstMediaRepresentationPart(entity);
|
69
|
}
|
70
|
initIsAdvancedMediaView();
|
71
|
showAdvancedView();
|
72
|
|
73
|
}
|
74
|
|
75
|
/* (non-Javadoc)
|
76
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
|
77
|
*/
|
78
|
@Override
|
79
|
public void handleEvent(Object eventSource) {
|
80
|
if(eventSource==textUri){
|
81
|
textUri.setBackground(getPersistentBackground());
|
82
|
try {
|
83
|
singleMediaRepresentationPart.setUri(textUri.getUri());
|
84
|
} catch (URISyntaxException e) {
|
85
|
textUri.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
|
86
|
}
|
87
|
}
|
88
|
}
|
89
|
|
90
|
public void toggleAdvancedMediaView(){
|
91
|
isAdvancedMediaView = !isAdvancedMediaView;
|
92
|
showAdvancedView();
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* @param showAdvancedView
|
97
|
*/
|
98
|
private void showAdvancedView() {
|
99
|
if(isAdvancedMediaView){
|
100
|
if(textUri!=null){
|
101
|
removeElementsAndControls(textUri);
|
102
|
}
|
103
|
section_mediaRepresentation = formFactory.createMediaRepresentationSection(getConversationHolder(), parentFormElement, style);
|
104
|
section_mediaRepresentation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
105
|
section_mediaRepresentation.setEntity(getEntity());
|
106
|
}
|
107
|
else{
|
108
|
if(section_mediaRepresentation!=null){
|
109
|
removeElementsAndControls(section_mediaRepresentation);
|
110
|
}
|
111
|
textUri = formFactory.createUriWithLabelElement(parentFormElement, "Media URI", null, style);
|
112
|
textUri.setUri(singleMediaRepresentationPart.getUri());
|
113
|
textUri.getLayoutComposite().layout();
|
114
|
}
|
115
|
}
|
116
|
|
117
|
private void initIsAdvancedMediaView(){
|
118
|
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ADVANCED_MEDIA_SECTION)){
|
119
|
isAdvancedMediaView = true;
|
120
|
return;
|
121
|
}
|
122
|
Set<MediaRepresentation> representations = getEntity().getRepresentations();
|
123
|
if(representations.size()>1){
|
124
|
isAdvancedMediaView = true;
|
125
|
return;
|
126
|
}
|
127
|
if(representations.size()==1){
|
128
|
List<MediaRepresentationPart> parts = representations.iterator().next().getParts();
|
129
|
if(parts.size()>1){
|
130
|
isAdvancedMediaView = true;
|
131
|
return;
|
132
|
}
|
133
|
}
|
134
|
isAdvancedMediaView = false;
|
135
|
}
|
136
|
|
137
|
/**
|
138
|
* @return
|
139
|
*/
|
140
|
public boolean isAdvancedMediaView() {
|
141
|
return isAdvancedMediaView;
|
142
|
}
|
143
|
|
144
|
}
|