1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.ui.section.occurrence;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
import java.util.Collection;
|
13
|
import java.util.Comparator;
|
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.jface.resource.ImageDescriptor;
|
19
|
import org.eclipse.swt.SWT;
|
20
|
import org.eclipse.swt.graphics.ImageData;
|
21
|
import org.eclipse.swt.widgets.Control;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
24
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
25
|
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
|
26
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
|
30
|
|
31
|
/**
|
32
|
* @author n.hoffmann
|
33
|
* @created May 11, 2011
|
34
|
*/
|
35
|
public class CurrentDeterminationDetailSection extends
|
36
|
AbstractDeterminationEventDetailSection {
|
37
|
|
38
|
public CurrentDeterminationDetailSection(CdmFormFactory formFactory,
|
39
|
ConversationHolder conversation, ICdmFormElement parentElement,
|
40
|
int style) {
|
41
|
super(formFactory, conversation, parentElement, "Current Determination", style);
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
protected Control createToolbar() {
|
46
|
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
|
47
|
|
48
|
Action addAction = new Action("add", IAction.AS_PUSH_BUTTON){
|
49
|
@Override
|
50
|
public void run() {
|
51
|
DeterminationEvent element = createNewElement();
|
52
|
|
53
|
// set as preferred determination
|
54
|
getEntity().setPreferredDetermination(element);
|
55
|
|
56
|
if(element != null){
|
57
|
if(! getSection().isExpanded()) {
|
58
|
getSection().setExpanded(true);
|
59
|
}
|
60
|
internalUpdateSection(true);
|
61
|
}
|
62
|
}
|
63
|
};
|
64
|
addAction.setImageDescriptor(new ImageDescriptor() {
|
65
|
|
66
|
@Override
|
67
|
public ImageData getImageData() {
|
68
|
return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
|
69
|
}
|
70
|
});
|
71
|
addAction.setToolTipText(getTooltipString());
|
72
|
|
73
|
toolBarManager.add(addAction);
|
74
|
|
75
|
return toolBarManager.createControl(this);
|
76
|
}
|
77
|
|
78
|
@Override
|
79
|
public void refresh() {
|
80
|
internalUpdateSection(false);
|
81
|
}
|
82
|
|
83
|
@Override
|
84
|
public Collection<DeterminationEvent> getCollection(DerivedUnitFacade entity) {
|
85
|
DeterminationEvent preferredDetermination = entity.getPreferredDetermination();
|
86
|
return preferredDetermination != null ? Arrays.asList(new DeterminationEvent[]{preferredDetermination}) : null;
|
87
|
}
|
88
|
|
89
|
@Override
|
90
|
public Comparator<DeterminationEvent> getComparator() {
|
91
|
return new DefaultCdmBaseComparator<>();
|
92
|
}
|
93
|
|
94
|
@Override
|
95
|
public DeterminationEvent createNewElement() {
|
96
|
DeterminationEvent newElement = super.createNewElement();
|
97
|
newElement.setPreferredFlag(true);
|
98
|
return newElement;
|
99
|
}
|
100
|
|
101
|
@Override
|
102
|
protected String getTooltipString() {
|
103
|
return "Create new current determination event";
|
104
|
}
|
105
|
|
106
|
@Override
|
107
|
public DeterminationEvent addExisting() {
|
108
|
return null;
|
109
|
}
|
110
|
|
111
|
@Override
|
112
|
public boolean allowAddExisting() {
|
113
|
return false;
|
114
|
}
|
115
|
}
|