3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
;
13 import java
.util
.Arrays
;
14 import java
.util
.Collection
;
17 import org
.eclipse
.jface
.action
.Action
;
18 import org
.eclipse
.jface
.action
.ToolBarManager
;
19 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swt
.graphics
.ImageData
;
22 import org
.eclipse
.swt
.widgets
.Control
;
24 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
25 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
26 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
27 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
28 import eu
.etaxonomy
.taxeditor
.ui
.campanula
.compatibility
.ICdmFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
33 * @created May 11, 2011
36 public class PreservedSpecimenCurrentDeterminationDetailSection
extends
37 PreservedSpecimenAbstractDeterminationEventDetailSection
{
42 * @param parentElement
45 public PreservedSpecimenCurrentDeterminationDetailSection(CdmFormFactory formFactory
,
46 ConversationHolder conversation
, ICdmFormElement parentElement
,
48 super(formFactory
, conversation
, parentElement
, "Current Determination", style
);
52 protected Control
createToolbar() {
53 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
55 Action addAction
= new Action("add", Action
.AS_PUSH_BUTTON
){
57 * @see org.eclipse.jface.action.Action#run()
61 DeterminationEvent element
= createNewElement();
63 // set as preferred determination
64 Set
<DeterminationEvent
> events
= getEntity().getDeterminations();
65 for (DeterminationEvent event
: events
){
66 if (event
.getPreferredFlag() == true){
67 event
.setPreferredFlag(false);
70 element
.setPreferredFlag(true);
74 if(! getSection().isExpanded()) {
75 getSection().setExpanded(true);
77 internalUpdateSection(true);
81 addAction
.setImageDescriptor(new ImageDescriptor() {
84 public ImageData
getImageData() {
85 return ImageResources
.getImage(ImageResources
.ADD_ICON
).getImageData();
88 addAction
.setToolTipText(getTooltipString());
90 toolBarManager
.add(addAction
);
92 return toolBarManager
.createControl(this);
96 public void refresh() {
97 internalUpdateSection(false);
101 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
104 public Collection
<DeterminationEvent
> getCollection(DerivedUnit entity
) {
105 DeterminationEvent preferredDetermination
= null;
106 Set
<DeterminationEvent
> events
= entity
.getDeterminations();
107 for (DeterminationEvent event
: events
){
108 if (event
.getPreferredFlag() == true){
109 preferredDetermination
= event
;
112 return preferredDetermination
!= null ? Arrays
.asList(new DeterminationEvent
[]{preferredDetermination
}) : null;
116 * @see eu.etaxonomy.taxeditor.ui.section.occurrence.AbstractDeterminationEventDetailSection#createNewElement()
119 public DeterminationEvent
createNewElement() {
120 DeterminationEvent newElement
= super.createNewElement();
121 newElement
.setPreferredFlag(true);
127 * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getTooltipString()
131 protected String
getTooltipString() {
132 return "Create new current determination event";