Add button for advanced media view to media attached to desccriptions
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / DescriptionElementMediaSection.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.ui.section.description;
12
13 import java.util.Collection;
14
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.action.ToolBarManager;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.widgets.Control;
20
21 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
22 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
23 import eu.etaxonomy.cdm.model.description.Feature;
24 import eu.etaxonomy.cdm.model.media.Media;
25 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
27 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
28 import eu.etaxonomy.taxeditor.ui.section.media.ITogglableMediaElement;
29
30 /**
31 * <p>DescriptionElementMediaSection class.</p>
32 *
33 * @author n.hoffmann
34 * @created Mar 18, 2010
35 * @version 1.0
36 */
37 public class DescriptionElementMediaSection extends
38 AbstractEntityCollectionSection<DescriptionElementBase, Media> {
39
40 public DescriptionElementMediaSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation,
41 ICdmFormElement parentElement, int style) {
42 super(cdmFormFactory, conversation, parentElement, "Media", style);
43 }
44
45 /** {@inheritDoc} */
46 @Override
47 public void setEntity(DescriptionElementBase entity) {
48 if(entity.getFeature().equals(Feature.IMAGE())){
49 this.setVisible(false);
50 }
51 super.setEntity(entity);
52 }
53
54 /** {@inheritDoc} */
55 @Override
56 public void addElement(Media element) {
57 getEntity().addMedia(element);
58 }
59
60 /** {@inheritDoc} */
61 @Override
62 public Media createNewElement() {
63 return Media.NewInstance();
64 }
65
66 /** {@inheritDoc} */
67 @Override
68 public Collection<Media> getCollection(DescriptionElementBase entity) {
69 return entity.getMedia();
70 }
71
72 /** {@inheritDoc} */
73 @Override
74 public String getEmptyString() {
75 return "No media yet.";
76 }
77
78 /** {@inheritDoc} */
79 @Override
80 protected String getTooltipString() {
81 return "Create new media";
82 }
83
84 /** {@inheritDoc} */
85 @Override
86 public void removeElement(Media element) {
87 getEntity().removeMedia(element);
88 }
89
90 @Override
91 protected Control createToolbar() {
92 ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
93
94 final String label = "Change View Type";
95
96 Action addAction = new Action(label, IAction.AS_PUSH_BUTTON) {
97 @Override
98 public void run() {
99 if(isExpanded()){
100 if(getEntityCollectionElement() instanceof ITogglableMediaElement){
101 ((ITogglableMediaElement) getEntityCollectionElement()).toggleAdvancedMediaView();
102 }
103 }
104 }
105 };
106 addAction.setToolTipText(label);
107
108 toolBarManager.add(addAction);
109
110 return toolBarManager.createControl(this);
111 }
112
113 }