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.editor.images;
|
12
|
|
13
|
import java.util.HashSet;
|
14
|
import java.util.Set;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.eclipse.swt.widgets.Composite;
|
18
|
import org.eclipse.ui.IEditorInput;
|
19
|
import org.eclipse.ui.IEditorSite;
|
20
|
import org.eclipse.ui.PartInitException;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
23
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
24
|
import eu.etaxonomy.cdm.model.media.ImageFile;
|
25
|
import eu.etaxonomy.taxeditor.editor.AbstractTaxonEditor;
|
26
|
import eu.etaxonomy.taxeditor.editor.FreeTextElementFactory;
|
27
|
import eu.etaxonomy.taxeditor.editor.GroupComposite;
|
28
|
import eu.etaxonomy.taxeditor.editor.GroupedComposite;
|
29
|
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
|
30
|
import eu.etaxonomy.taxeditor.store.model.ImagesUtil;
|
31
|
|
32
|
/**
|
33
|
* @author p.ciardelli
|
34
|
* @author n.hoffmann
|
35
|
* @created 30.03.2009
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
public class TaxonImageEditor extends AbstractTaxonEditor {
|
39
|
private static final Logger logger = Logger
|
40
|
.getLogger(TaxonImageEditor.class);
|
41
|
|
42
|
private static final String ID = "eu.etaxonomy.taxeditor.taxonImageEditor";
|
43
|
|
44
|
private TaxonDescription emptyGallery;
|
45
|
|
46
|
public TaxonImageEditor(MultiPageTaxonEditor editor){
|
47
|
super(editor);
|
48
|
}
|
49
|
|
50
|
public void init(IEditorSite site, IEditorInput input)
|
51
|
throws PartInitException {
|
52
|
|
53
|
super.init(site, input);
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
protected void createManagedForm(Composite composite) {
|
58
|
|
59
|
super.createManagedForm(composite);
|
60
|
|
61
|
Set<TaxonDescription> descriptions = taxon.getDescriptions();
|
62
|
Set<DescriptionBase> imageGalleries = new HashSet<DescriptionBase>();
|
63
|
|
64
|
for(TaxonDescription description : descriptions){
|
65
|
if(description.isImageGallery()){
|
66
|
imageGalleries.add(description);
|
67
|
}
|
68
|
}
|
69
|
|
70
|
|
71
|
if(imageGalleries.size() == 0){
|
72
|
emptyGallery = TaxonDescription.NewInstance();
|
73
|
emptyGallery.setImageGallery(true);
|
74
|
emptyGallery.setTitleCache("");
|
75
|
descriptions.add(emptyGallery);
|
76
|
|
77
|
|
78
|
taxon.addDescription(emptyGallery);
|
79
|
}
|
80
|
|
81
|
firstGroupedComposite = null;
|
82
|
|
83
|
for(DescriptionBase description : descriptions){
|
84
|
if(description.isImageGallery()){
|
85
|
// Draw gallery label
|
86
|
Composite labelComposite =
|
87
|
FreeTextElementFactory.getDefault().createGalleryLabel(this, (TaxonDescription) description);
|
88
|
|
89
|
// Note whether this is the first label drawn
|
90
|
if (firstGroupedComposite == null) {
|
91
|
firstGroupedComposite = (GroupedComposite) labelComposite;
|
92
|
}
|
93
|
|
94
|
Set<ImageFile> imageFiles = ImagesUtil.getImages((TaxonDescription) description);
|
95
|
|
96
|
for(ImageFile imageFile : imageFiles){
|
97
|
FreeTextElementFactory.getDefault().createImageElement(this, imageFile);
|
98
|
}
|
99
|
}
|
100
|
}
|
101
|
|
102
|
// Redraw composite
|
103
|
composite.layout();
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* @return
|
108
|
*/
|
109
|
public GroupComposite getImageGroup() {
|
110
|
for(Composite c : getAllComposites()){
|
111
|
if(c instanceof ImagesGroupComposite){
|
112
|
return (GroupComposite) c;
|
113
|
}
|
114
|
}
|
115
|
return null;
|
116
|
}
|
117
|
|
118
|
/* (non-Javadoc)
|
119
|
* @see eu.etaxonomy.taxeditor.editor.AbstractTaxonEditor#getID()
|
120
|
*/
|
121
|
@Override
|
122
|
public String getID() {
|
123
|
return TaxonImageEditor.ID;
|
124
|
}
|
125
|
}
|