Refactored code to use a static method that creates the IAction object.
This can be added by the GUI element itself.
private final Composite container;
+ /**
+ * Composite "around" the actual content. Is used for control action like e.g. remove button
+ */
private final Composite box;
private Button btnRemove;
private Color backgroundColor;
- /**
- * <p>
- * Constructor for AbstractEntityCollectionElement.
- * </p>
- *
- * @param style
- * a int.
- * @param formFactory
- * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
- * object.
- * @param section
- * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
- * object.
- * @param entity
- * a ENTITY object.
- * @param removeListener
- * a {@link org.eclipse.swt.events.SelectionListener} object.
- * @param <ENTITY>
- * a ENTITY object.
- */
public AbstractEntityCollectionElement(CdmFormFactory formFactory,
AbstractFormSection section, ENTITY entity,
SelectionListener removeListener, Color backgroundColor, int style) {
box.setBackgroundMode(SWT.INHERIT_DEFAULT);
addControl(box);
- TableWrapLayout boxLayout = LayoutConstants.LAYOUT(3, false);
+ TableWrapLayout boxLayout = LayoutConstants.LAYOUT(4, false);
boxLayout.topMargin = 4;
boxLayout.bottomMargin = 4;
box.setLayout(boxLayout);
// default implementation is empty
}
- /**
- * <p>
- * Setter for the field <code>entity</code>.
- * </p>
- *
- * @param entity
- * a ENTITY object.
- */
public abstract void setEntity(ENTITY entity);
- /**
- * <p>
- * Getter for the field <code>entity</code>.
- * </p>
- *
- * @return a ENTITY object.
- */
@Override
public ENTITY getEntity() {
return entity;
return null;
}
- /**
- * <p>
- * createControls
- * </p>
- *
- * @param element
- * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
- * object.
- * @param style
- * a int.
- */
public abstract void createControls(ICdmFormElement element, int style);
/**
setBackground(selected ? SELECTED : getPersistentBackground());
}
- /*
- * (non-Javadoc)
- *
- * @see
- * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
- * .eclipse.jface.util.PropertyChangeEvent)
- */
/** {@inheritDoc} */
@Override
public void propertyChange(PropertyChangeEvent event) {
}
}
- /**
- * <p>
- * handleEvent
- * </p>
- *
- * @param eventSource
- * a {@link java.lang.Object} object.
- */
public abstract void handleEvent(Object eventSource);
/** {@inheritDoc} */
return container;
}
- /**
- * <p>
- * Getter for the field <code>backgroundColor</code>.
- * </p>
- *
- * @return the backgroundColor
- */
public Color getBackgroundColor() {
return backgroundColor;
}
- /**
- * <p>
- * getConversationHolder
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
- * object.
- */
+ public Composite getBox() {
+ return box;
+ }
+
@Override
public ConversationHolder getConversationHolder() {
if (getParentElement() instanceof IConversationEnabled) {
import java.util.Collection;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.ToolBarManager;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Control;
-
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
-import eu.etaxonomy.taxeditor.ui.section.media.ITogglableMediaElement;
/**
* <p>DescriptionElementMediaSection class.</p>
getEntity().removeMedia(element);
}
- @Override
- protected Control createToolbar() {
- ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
-
- final String label = "Change View Type";
-
- Action addAction = new Action(label, IAction.AS_PUSH_BUTTON) {
- @Override
- public void run() {
- if(isExpanded()){
- if(getEntityCollectionElement() instanceof ITogglableMediaElement){
- ((ITogglableMediaElement) getEntityCollectionElement()).toggleAdvancedMediaView();
- }
- }
- }
- };
- addAction.setToolTipText(label);
-
- toolBarManager.add(addAction);
-
- return toolBarManager.createControl(this);
- }
}
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.media.AbstractTogglableMediaDetailsSection;
import eu.etaxonomy.taxeditor.ui.section.media.MediaMetaElement;
/**
* @created Jun 15, 2010
* @version 1.0
*/
-public class MediaDetailsSection extends AbstractTogglableMediaDetailsSection<Media> {
+public class MediaDetailsSection extends AbstractCdmDetailSection<Media> {
+
+ private MediaMetaElement mediaMetaElement;
public MediaDetailsSection(CdmFormFactory formFactory, ConversationHolder conversation,
ICdmFormElement parentElement,
@Override
public void setEntity(Media entity) {
- if(getTogglableMediaElement() != null){
+ if(mediaMetaElement != null){
this.removeElements();
}
- setTogglableMediaElement((MediaMetaElement) formFactory.createEntityCollectionElement(this, entity, null, null, ExpandableComposite.EXPANDED));
+ mediaMetaElement = (MediaMetaElement) formFactory.createEntityCollectionElement(this, entity, null, null, ExpandableComposite.EXPANDED);
super.setEntity(entity);
setSectionTitle();
setTextClient(createToolbar());
+++ /dev/null
-// $Id$
-/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
-package eu.etaxonomy.taxeditor.ui.section.media;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.ToolBarManager;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Control;
-
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
-
-/**
- *
- * @author pplitzner
- * @date Jun 25, 2015
- *
- */
-public abstract class AbstractTogglableMediaDetailsSection<ENTITY> extends AbstractCdmDetailSection<ENTITY> {
-
- private ITogglableMediaElement togglableMediaElement;
-
- public AbstractTogglableMediaDetailsSection(CdmFormFactory formFactory, ConversationHolder conversation,
- ICdmFormElement parentElement,
- ISelectionProvider selectionProvider, int style) {
- super(formFactory, conversation, parentElement, selectionProvider, style);
- }
-
- @Override
- protected Control createToolbar() {
- ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
-
- final String label = "Change View Type";
-
- Action addAction = new Action(label, IAction.AS_PUSH_BUTTON) {
- @Override
- public void run() {
- if(togglableMediaElement!=null){
- togglableMediaElement.toggleAdvancedMediaView();
- }
- }
- };
- addAction.setToolTipText(label);
-
- toolBarManager.add(addAction);
-
- return toolBarManager.createControl(this);
- }
-
- public void setTogglableMediaElement(ITogglableMediaElement togglableMediaElement) {
- this.togglableMediaElement = togglableMediaElement;
- }
-
- public ITogglableMediaElement getTogglableMediaElement() {
- return togglableMediaElement;
- }
-
-}
*/
package eu.etaxonomy.taxeditor.ui.section.media;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Button;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.agent.AgentBase;
/** {@inheritDoc} */
@Override
public void createControls(ICdmFormElement element, int style) {
-
+ final IAction switchAction = MediaViewSwitch.createSwitch(MediaMetaElement.this);
+ Button btnToggleAdvancedMediaView = new Button(getBox(), style);
+ btnToggleAdvancedMediaView.setText(switchAction.getText());
+ btnToggleAdvancedMediaView.setToolTipText(switchAction.getText());
+ btnToggleAdvancedMediaView.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ switchAction.run();
+ }
+ });
text_title = formFactory.createLanguageStringWithLabelElement(element, "Title", null, style);
selection_artist = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), element, "Artist", null, EntitySelectionElement.ALL, style);
text_description = formFactory.createLanguageStringWithLabelElement(element, "Description", null, 100, true, style);
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.ui.section.media;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+
+/**
+ * Adds a switch to a section with an {@link ITogglableMediaElement}
+ * to allow switching between simple and advanced media view
+ * @author pplitzner
+ * @date Jun 29, 2015
+ *
+ */
+public class MediaViewSwitch {
+
+ /**
+ * Creates an {@link IAction} for the given {@link ITogglableMediaElement}
+ * that switches between the two states of the element.
+ */
+ public static IAction createSwitch(final ITogglableMediaElement togglableMediaElement) {
+ final String label = "Change View Type";
+
+ Action switchAction = new Action(label, IAction.AS_PUSH_BUTTON) {
+ @Override
+ public void run() {
+ if(togglableMediaElement!=null){
+ togglableMediaElement.toggleAdvancedMediaView();
+ }
+ }
+ };
+ switchAction.setToolTipText(label);
+
+ return switchAction;
+ }
+}
*/
package eu.etaxonomy.taxeditor.ui.section.occurrence.media;
+import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Control;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.media.AbstractTogglableMediaDetailsSection;
+import eu.etaxonomy.taxeditor.ui.section.media.ITogglableMediaElement;
+import eu.etaxonomy.taxeditor.ui.section.media.MediaViewSwitch;
/**
* @author pplitzner
* @date 12.12.2013
*
*/
-public class MediaSpecimenGeneralDetailSection extends AbstractTogglableMediaDetailsSection<MediaSpecimen> {
+public class MediaSpecimenGeneralDetailSection extends AbstractCdmDetailSection<MediaSpecimen> {
+
+ private ITogglableMediaElement togglableMediaElement;
public MediaSpecimenGeneralDetailSection(CdmFormFactory formFactory,
ConversationHolder conversation, ICdmFormElement parentElement,
@Override
protected AbstractCdmDetailElement<MediaSpecimen> createCdmDetailElement(AbstractCdmDetailSection<MediaSpecimen> parentElement, int style) {
MediaSpecimenGeneralDetailElement mediaSpecimenGeneralDetailElement = formFactory.createMediaSpecimenGeneralDetailElement(parentElement);
- setTogglableMediaElement(mediaSpecimenGeneralDetailElement);
+ togglableMediaElement = mediaSpecimenGeneralDetailElement;
return mediaSpecimenGeneralDetailElement;
}
+ @Override
+ protected Control createToolbar() {
+ ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
+ toolBarManager.add(MediaViewSwitch.createSwitch(togglableMediaElement));
+ return toolBarManager.createControl(this);
+ }
+
+
}