Project

General

Profile

Download (3.45 KB) Statistics
| Branch: | Tag: | Revision:
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.occurrence;
12

    
13
import java.util.Arrays;
14
import java.util.Collection;
15

    
16
import org.eclipse.jface.action.Action;
17
import org.eclipse.jface.action.IAction;
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;
23

    
24
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
25
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
26
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
27
import eu.etaxonomy.taxeditor.model.ImageResources;
28
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
29
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
30

    
31
/**
32
 * @author n.hoffmann
33
 * @created May 11, 2011
34
 * @version 1.0
35
 */
36
public class CurrentDeterminationDetailSection extends
37
		AbstractDeterminationEventDetailSection {
38

    
39
	/**
40
	 * @param formFactory
41
	 * @param conversation
42
	 * @param parentElement
43
	 * @param style
44
	 */
45
	public CurrentDeterminationDetailSection(CdmFormFactory formFactory,
46
			ConversationHolder conversation, ICdmFormElement parentElement,
47
			int style) {
48
		super(formFactory, conversation, parentElement, "Current Determination", style);
49
	}
50

    
51
	@Override
52
	protected Control createToolbar() {
53
		ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
54

    
55
		Action addAction = new Action("add", IAction.AS_PUSH_BUTTON){
56
			/* (non-Javadoc)
57
			 * @see org.eclipse.jface.action.Action#run()
58
			 */
59
			@Override
60
			public void run() {
61
				DeterminationEvent element = createNewElement();
62

    
63
				// set as preferred determination
64
				getEntity().setPreferredDetermination(element);
65

    
66
				if(element != null){
67
					if(! getSection().isExpanded()) {
68
                        getSection().setExpanded(true);
69
                    }
70
					internalUpdateSection(true);
71
				}
72
			}
73
		};
74
		addAction.setImageDescriptor(new ImageDescriptor() {
75

    
76
			@Override
77
			public ImageData getImageData() {
78
				return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
79
			}
80
		});
81
		addAction.setToolTipText(getTooltipString());
82

    
83
		toolBarManager.add(addAction);
84

    
85
		return toolBarManager.createControl(this);
86
	}
87

    
88
	@Override
89
	public void refresh() {
90
		internalUpdateSection(false);
91
	}
92

    
93
	/* (non-Javadoc)
94
	 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
95
	 */
96
	@Override
97
	public Collection<DeterminationEvent> getCollection(DerivedUnitFacade entity) {
98
		DeterminationEvent preferredDetermination = entity.getPreferredDetermination();
99
		return preferredDetermination != null ? Arrays.asList(new DeterminationEvent[]{preferredDetermination}) : null;
100
	}
101

    
102
	/* (non-Javadoc)
103
	 * @see eu.etaxonomy.taxeditor.ui.section.occurrence.AbstractDeterminationEventDetailSection#createNewElement()
104
	 */
105
	@Override
106
	public DeterminationEvent createNewElement() {
107
		DeterminationEvent newElement = super.createNewElement();
108
		newElement.setPreferredFlag(true);
109
		return newElement;
110
	}
111

    
112

    
113
	/* (non-Javadoc)
114
	 * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getTooltipString()
115
	 */
116
	/** {@inheritDoc} */
117
	@Override
118
	protected String getTooltipString() {
119
		return "Create new current determination event";
120
	}
121

    
122
}
(6-6/36)