2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
;
11 import java
.util
.Arrays
;
12 import java
.util
.Collection
;
13 import java
.util
.Comparator
;
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
.jface
.resource
.ImageDescriptor
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.graphics
.ImageData
;
21 import org
.eclipse
.swt
.widgets
.Control
;
23 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
24 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
25 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.section
.DefaultCdmBaseComparator
;
32 * @created May 11, 2011
34 public class CurrentDeterminationDetailSection
extends
35 AbstractDeterminationEventDetailSection
{
37 public CurrentDeterminationDetailSection(CdmFormFactory formFactory
,
38 ICdmFormElement parentElement
,
40 super(formFactory
, parentElement
, "Current Determination", style
);
44 protected Control
createToolbar() {
45 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
47 Action addAction
= new Action("add", IAction
.AS_PUSH_BUTTON
){
50 DeterminationEvent element
= createNewElement();
52 // set as preferred determination
53 getEntity().setPreferredDetermination(element
);
56 if(! getSection().isExpanded()) {
57 getSection().setExpanded(true);
59 internalUpdateSection(true);
63 addAction
.setImageDescriptor(new ImageDescriptor() {
66 public ImageData
getImageData() {
67 return ImageResources
.getImage(ImageResources
.ADD_ICON
).getImageData();
70 addAction
.setToolTipText(getTooltipString());
72 toolBarManager
.add(addAction
);
74 return toolBarManager
.createControl(this);
78 public void refresh() {
79 internalUpdateSection(false);
83 public Collection
<DeterminationEvent
> getCollection(SpecimenOrObservationBase entity
) {
84 DeterminationEvent preferredDetermination
= entity
.getPreferredDetermination();
85 return preferredDetermination
!= null ? Arrays
.asList(new DeterminationEvent
[]{preferredDetermination
}) : null;
89 public Comparator
<DeterminationEvent
> getComparator() {
90 return new DefaultCdmBaseComparator
<>();
94 public DeterminationEvent
createNewElement() {
95 DeterminationEvent newElement
= super.createNewElement();
96 newElement
.setPreferredFlag(true);
101 protected String
getTooltipString() {
102 return "Create new current determination event";
106 public DeterminationEvent
addExisting() {
111 public boolean allowAddExisting() {