Project

General

Profile

« Previous | Next » 

Revision 2bfe249f

Added by Patrick Plitzner over 9 years ago

  • added simple user interface to add media (#3339)

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/MediaDetailsSection.java
11 11
package eu.etaxonomy.taxeditor.ui.section.description;
12 12

  
13 13
import org.eclipse.jface.viewers.ISelectionProvider;
14
import org.eclipse.ui.forms.widgets.Section;
14
import org.eclipse.ui.forms.widgets.ExpandableComposite;
15 15
import org.eclipse.ui.forms.widgets.TableWrapLayout;
16 16

  
17 17
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
......
71 71
		if(element_media != null){
72 72
			this.removeElements();
73 73
		}
74
		element_media = (MediaElement) formFactory.createEntityCollectionElement(this, entity, null, null, Section.EXPANDED);
75
		formFactory.addPropertyChangeListener(element_media);
74
		element_media = (MediaElement) formFactory.createEntityCollectionElement(this, entity, null, null, ExpandableComposite.EXPANDED);
76 75
		super.setEntity(entity);
77 76
		setSectionTitle();
78 77
		layout();
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaElement.java
3 3
 */
4 4
package eu.etaxonomy.taxeditor.ui.section.media;
5 5

  
6
import java.net.URI;
7
import java.net.URISyntaxException;
8
import java.util.List;
9
import java.util.Set;
10

  
6 11
import org.eclipse.swt.events.SelectionListener;
7 12

  
8 13
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
......
10 15
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
11 16
import eu.etaxonomy.cdm.model.common.LanguageString;
12 17
import eu.etaxonomy.cdm.model.media.Media;
18
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
19
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
20
import eu.etaxonomy.taxeditor.preference.Resources;
13 21
import eu.etaxonomy.taxeditor.store.CdmStore;
14 22
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
15 23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
16 24
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
17 25
import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
18
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
26
import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
19 27
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
20 28
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
21 29
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
......
31 39
 */
32 40
public class MediaElement extends AbstractEntityCollectionElement<Media> {
33 41

  
34
	private MediaRepresentationSection section_mediaRepresentation;
35
	private EntitySelectionElement<AgentBase> selection_artist;
36
	private LanguageStringWithLabelElement text_description;
37
	private LanguageStringWithLabelElement text_title;
42
//    private MediaRepresentationSection section_mediaRepresentation;
43
    private EntitySelectionElement<AgentBase> selection_artist;
44
    private LanguageStringWithLabelElement text_description;
45
    private LanguageStringWithLabelElement text_title;
46
    private UriWithLabelElement textUri;
38 47

  
39
	/**
40
	 * <p>
41
	 * Constructor for MediaElement.
42
	 * </p>
43
	 *
44
	 * @param formElement
45
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
46
	 *            object.
47
	 * @param element
48
	 *            a {@link eu.etaxonomy.cdm.model.media.Media} object.
49
	 * @param removeListener
50
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
51
	 * @param style
52
	 *            a int.
53
	 * @param cdmFormFactory
54
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
55
	 *            object.
56
	 */
57
	public MediaElement(CdmFormFactory cdmFormFactory,
58
			AbstractFormSection formElement, Media element,
59
			SelectionListener removeListener, int style) {
60
		super(cdmFormFactory, formElement, element, removeListener, null, style);
61
	}
48
    /**
49
     * <p>
50
     * Constructor for MediaElement.
51
     * </p>
52
     *
53
     * @param formElement
54
     *            a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
55
     *            object.
56
     * @param element
57
     *            a {@link eu.etaxonomy.cdm.model.media.Media} object.
58
     * @param removeListener
59
     *            a {@link org.eclipse.swt.events.SelectionListener} object.
60
     * @param style
61
     *            a int.
62
     * @param cdmFormFactory
63
     *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
64
     *            object.
65
     */
66
    public MediaElement(CdmFormFactory cdmFormFactory,
67
            AbstractFormSection formElement, Media element,
68
            SelectionListener removeListener, int style) {
69
        super(cdmFormFactory, formElement, element, removeListener, null, style);
70
    }
62 71

  
63
	/*
64
	 * (non-Javadoc)
65
	 *
66
	 * @see
67
	 * eu.etaxonomy.taxeditor.forms.entitysections.AbstractEntitySetElementComposite
68
	 * #createControls(org.eclipse.swt.widgets.Composite, int)
69
	 */
70
	/** {@inheritDoc} */
72
    /*
73
     * (non-Javadoc)
74
     *
75
     * @see
76
     * eu.etaxonomy.taxeditor.forms.entitysections.AbstractEntitySetElementComposite
77
     * #createControls(org.eclipse.swt.widgets.Composite, int)
78
     */
79
    /** {@inheritDoc} */
71 80
    @Override
72 81
    public void createControls(ICdmFormElement element, int style) {
73 82
        text_title = formFactory.createLanguageStringWithLabelElement(element, "Title", null, style);
74 83
        selection_artist = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), element, "Artist", null, EntitySelectionElement.ALL, style);
75 84
        text_description = formFactory.createLanguageStringWithLabelElement(element, "Description", null, 100, style);
76
        section_mediaRepresentation = formFactory.createMediaRepresentationSection(getConversationHolder(), element, style);
77
        section_mediaRepresentation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
78
	}
85
        textUri = formFactory.createUriWithLabelElement(element, "Media URI", null, style);
86
        //        section_mediaRepresentation = formFactory.createMediaRepresentationSection(getConversationHolder(), element, style);
87
        //        section_mediaRepresentation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
88
    }
89

  
90
    private MediaRepresentationPart getFirstMediaRepresentationPart() {
91
        Set<MediaRepresentation> representations = entity.getRepresentations();
92
        if(representations.size()==1){
93
            List<MediaRepresentationPart> parts = representations.iterator().next().getParts();
94
            if(parts.size()==1){
95
                return parts.iterator().next();
96
            }
97
        }
98
        return null;
99
    }
79 100

  
80
	/** {@inheritDoc} */
81
	@Override
82
	public void setEntity(Media element) {
83
		this.entity = element;
84
		section_mediaRepresentation.setEntity(element);
85
		selection_artist.setEntity((TeamOrPersonBase) HibernateProxyHelper
86
				.deproxy(element.getArtist()));
101
    /** {@inheritDoc} */
102
    @Override
103
    public void setEntity(Media element) {
104
        this.entity = element;
105
//        section_mediaRepresentation.setEntity(element);
106
        selection_artist.setEntity((TeamOrPersonBase) HibernateProxyHelper
107
                .deproxy(element.getArtist()));
87 108

  
88
		text_description.setLanguageString(element.getDescription(CdmStore
89
				.getDefaultLanguage()));
109
        text_description.setLanguageString(element.getDescription(CdmStore
110
                .getDefaultLanguage()));
90 111

  
91
		LanguageString title = element.getTitle(CdmStore.getDefaultLanguage());
112
        LanguageString title = element.getTitle(CdmStore.getDefaultLanguage());
92 113

  
93
		if (title == null) {
94
			title = LanguageString.NewInstance("",
95
					CdmStore.getDefaultLanguage());
96
		}
114
        if (title == null) {
115
            title = LanguageString.NewInstance("",
116
                    CdmStore.getDefaultLanguage());
117
        }
97 118

  
98
		text_title.setLanguageString(title);
99
	}
119
        text_title.setLanguageString(title);
100 120

  
101
	/*
102
	 * (non-Javadoc)
103
	 *
104
	 * @see
105
	 * eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#handleEvent
106
	 * (java.lang.Object)
107
	 */
108
	/** {@inheritDoc} */
109
	@Override
110
	public void handleEvent(Object eventSource) {
111
		if (eventSource == selection_artist) {
112
			getEntity().setArtist(selection_artist.getSelection());
113
		} else if (eventSource == text_description) {
114
			getEntity().addDescription(text_description.getLanguageString());
115
		} else if (eventSource == text_title) {
116
			getEntity().putTitle(text_title.getLanguageString());
117
			if (getParentElement() instanceof AbstractCdmDetailSection) {
118
				((AbstractCdmDetailSection) getParentElement()).updateTitle();
119
			}
120
		}
121
		firePropertyChangeEvent(this);
122
	}
121
        MediaRepresentationPart firstMediaRepresentationPart = getFirstMediaRepresentationPart();
122
        if(firstMediaRepresentationPart!=null){
123
            textUri.setUri(firstMediaRepresentationPart.getUri());
124
        }
125
    }
126

  
127
    /*
128
     * (non-Javadoc)
129
     *
130
     * @see
131
     * eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#handleEvent
132
     * (java.lang.Object)
133
     */
134
    /** {@inheritDoc} */
135
    @Override
136
    public void handleEvent(Object eventSource) {
137
        if (eventSource == selection_artist) {
138
            getEntity().setArtist(selection_artist.getSelection());
139
        } else if (eventSource == text_description) {
140
            getEntity().addDescription(text_description.getLanguageString());
141
        } else if (eventSource == text_title) {
142
            getEntity().putTitle(text_title.getLanguageString());
143
            if (getParentElement() instanceof AbstractCdmDetailSection) {
144
                ((AbstractCdmDetailSection) getParentElement()).updateTitle();
145
            }
146
        }
147
        else if (eventSource == textUri){
148
            textUri.setBackground(getPersistentBackground());
149
            MediaRepresentationPart firstMediaRepresentationPart = getFirstMediaRepresentationPart();
150
            URI uri;
151
            try {
152
                uri = textUri.getUri();
153
                if(firstMediaRepresentationPart!=null){
154
                    firstMediaRepresentationPart.setUri(uri);
155
                }
156
                else{
157
                    Set<MediaRepresentation> representations = getEntity().getRepresentations();
158
                    if(representations.size()>=1){
159
                        representations.iterator().next().addRepresentationPart(MediaRepresentationPart.NewInstance(uri, null));
160
                    }
161
                    else{
162
                        MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance();
163
                        mediaRepresentation.addRepresentationPart(MediaRepresentationPart.NewInstance(uri, null));
164
                        getEntity().addRepresentation(mediaRepresentation);
165
                    }
166
                }
167
            } catch (URISyntaxException e) {
168
                textUri.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
169
            }
170
        }
171
    }
123 172
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/media/MediaSpecimenGeneralDetailElement.java
9 9
 */
10 10
package eu.etaxonomy.taxeditor.ui.section.occurrence.media;
11 11

  
12
import java.net.URISyntaxException;
13
import java.util.Set;
14

  
12 15
import org.eclipse.swt.widgets.Label;
13
import org.eclipse.ui.forms.widgets.ExpandableComposite;
14 16
import org.joda.time.DateTime;
15 17

  
16 18
import eu.etaxonomy.cdm.api.service.IVocabularyService;
......
22 24
import eu.etaxonomy.cdm.model.common.TermVocabulary;
23 25
import eu.etaxonomy.cdm.model.common.VocabularyEnum;
24 26
import eu.etaxonomy.cdm.model.media.Media;
27
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
28
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
25 29
import eu.etaxonomy.cdm.model.occurrence.Collection;
26 30
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
27 31
import eu.etaxonomy.cdm.model.reference.Reference;
32
import eu.etaxonomy.taxeditor.preference.Resources;
28 33
import eu.etaxonomy.taxeditor.store.CdmStore;
29 34
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
30 35
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
31 36
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
32 37
import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
33
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
34 38
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
39
import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
35 40
import eu.etaxonomy.taxeditor.ui.mvc.element.DateElement;
36 41
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
37
import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationSection;
38 42
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
39 43

  
40 44
/**
......
54 58
    private EntitySelectionElement<Collection> selection_collection;
55 59
    private TextWithLabelElement text_accessionNumber;
56 60
    private EntitySelectionElement<Reference> selection_publishedIn;
61
    private UriWithLabelElement textMediaUri;
62
    private MediaRepresentationPart mediaRepresentationPart;
57 63

  
58
    private MediaRepresentationSection mediaRepresentationSection;
64
//    private MediaRepresentationSection mediaRepresentationSection;
59 65
    /**
60 66
     * @param formFactory
61 67
     * @param formElement
......
102 108
                }
103 109
            }
104 110
            selection_publishedIn = formFactory.createSelectionElement(Reference.class, getConversationHolder(), formElement, "Published in", publishedIn, EntitySelectionElement.ALL, style);
111
            mediaRepresentationPart = getMediaRepresentationPart(media);
112
            textMediaUri = formFactory.createUriWithLabelElement(formElement, "Media URI", mediaRepresentationPart.getUri(), style);
105 113

  
106
            mediaRepresentationSection = formFactory.createMediaRepresentationSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
107
            mediaRepresentationSection.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
108
            mediaRepresentationSection.setEntity(media);
114
//            mediaRepresentationSection = formFactory.createMediaRepresentationSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
115
//            mediaRepresentationSection.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
116
//            mediaRepresentationSection.setEntity(media);
109 117
        }
110 118
    }
111 119

  
......
160 168
                primaryMediaSource.setCitation(selection_publishedIn.getSelection());
161 169
            }
162 170
        }
171
        else if(eventSource==textMediaUri){
172
            textMediaUri.setBackground(getPersistentBackground());
173
            try {
174
                mediaRepresentationPart.setUri(textMediaUri.getUri());
175
            } catch (URISyntaxException e) {
176
                textMediaUri.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
177
            }
178
        }
163 179
    }
180

  
181
    private MediaRepresentationPart getMediaRepresentationPart(Media media) {
182
        if(mediaRepresentationPart!=null){
183
            return mediaRepresentationPart;
184
        }
185
        else {
186
            MediaRepresentationPart part = MediaRepresentationPart.NewInstance(null, null);
187

  
188
            Set<MediaRepresentation> representations = media.getRepresentations();
189
            MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance();
190
            mediaRepresentation.addRepresentationPart(part);
191
            media.addRepresentation(mediaRepresentation);
192
            return part;
193
        }
194
    }
195

  
164 196
}

Also available in: Unified diff