- moved toggle button to the top-right corner of the Media(Specimen)Section (#3339)
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / MediaDetailsSection.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 org.eclipse.jface.action.Action;
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.action.ToolBarManager;
16 import org.eclipse.jface.viewers.ISelectionProvider;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.ui.forms.widgets.ExpandableComposite;
20 import org.eclipse.ui.forms.widgets.TableWrapLayout;
21
22 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
23 import eu.etaxonomy.cdm.model.media.Media;
24 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
27 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
28 import eu.etaxonomy.taxeditor.ui.section.media.MediaMetaElement;
29
30 /**
31 * <p>MediaDetailsSection class.</p>
32 *
33 * @author n.hoffmann
34 * @created Jun 15, 2010
35 * @version 1.0
36 */
37 public class MediaDetailsSection extends AbstractCdmDetailSection<Media> {
38
39 private MediaMetaElement element_media;
40
41 /**
42 * <p>Constructor for MediaDetailsSection.</p>
43 *
44 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
45 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
46 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
47 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
48 * @param style a int.
49 */
50 public MediaDetailsSection(CdmFormFactory formFactory, ConversationHolder conversation,
51 ICdmFormElement parentElement,
52 ISelectionProvider selectionProvider, int style) {
53 super(formFactory, conversation, parentElement, selectionProvider, style);
54 }
55
56 /** {@inheritDoc} */
57 @Override
58 protected void createControls(AbstractCdmDetailSection formElement,
59 int style) {
60 TableWrapLayout layout = (TableWrapLayout) getLayoutComposite().getLayout();
61 layout.topMargin = 10;
62 layout.numColumns = 2;
63
64 getLayoutComposite().setLayout(layout);
65
66
67 }
68
69 @Override
70 protected Control createToolbar() {
71 ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
72
73 final String label;
74 if(element_media.isAdvancedMediaView()){
75 label = "Use simple media view";
76 }
77 else{
78 label = "Use advanced media view";
79 }
80
81 Action addAction = new Action("Use advanced media view", IAction.AS_PUSH_BUTTON) {
82 /* (non-Javadoc)
83 * @see org.eclipse.jface.action.Action#run()
84 */
85 @Override
86 public void run() {
87 element_media.toggleAdvancedMediaView();
88 }
89 };
90 addAction.setToolTipText(label);
91
92 toolBarManager.add(addAction);
93
94 return toolBarManager.createControl(this);
95 }
96
97 /**
98 * <p>setEntity</p>
99 *
100 * @param entity a {@link eu.etaxonomy.cdm.model.media.Media} object.
101 */
102 @Override
103 public void setEntity(Media entity) {
104 if(element_media != null){
105 this.removeElements();
106 }
107 element_media = (MediaMetaElement) formFactory.createEntityCollectionElement(this, entity, null, null, ExpandableComposite.EXPANDED);
108 super.setEntity(entity);
109 setSectionTitle();
110 setTextClient(createToolbar());
111 layout();
112 }
113
114 /* (non-Javadoc)
115 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailSection#getHeading()
116 */
117 /** {@inheritDoc} */
118 @Override
119 public String getHeading() {
120 return "Image";
121 }
122
123 /* (non-Javadoc)
124 * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
125 */
126 @Override
127 protected AbstractCdmDetailElement<Media> createCdmDetailElement(AbstractCdmDetailSection<Media> parentElement, int style) {
128 return null;
129 }
130 }