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