Project

General

Profile

Download (3.42 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.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.section.campanula.compatibility.ICdmFormElement;
29

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

    
38
	/**
39
	 * @param formFactory
40
	 * @param conversation
41
	 * @param parentElement
42
	 * @param style
43
	 */
44
	public CurrentDeterminationDetailSection(CdmFormFactory formFactory,
45
			ConversationHolder conversation, ICdmFormElement parentElement,
46
			int style) {
47
		super(formFactory, conversation, parentElement, "Current Determination", style);
48
	}
49
	
50
	@Override
51
	protected Control createToolbar() {
52
		ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
53
		
54
		Action addAction = new Action("add", Action.AS_PUSH_BUTTON){
55
			/* (non-Javadoc)
56
			 * @see org.eclipse.jface.action.Action#run()
57
			 */
58
			@Override
59
			public void run() {
60
				DeterminationEvent element = createNewElement();
61
				
62
				// set as preferred determination
63
				getEntity().setPreferredDetermination(element);
64
				
65
				if(element != null){
66
					if(! getSection().isExpanded())
67
						getSection().setExpanded(true);
68
					internalUpdateSection(true); 
69
				}
70
			}
71
		};
72
		addAction.setImageDescriptor(new ImageDescriptor() {
73
			
74
			@Override
75
			public ImageData getImageData() {
76
				return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
77
			}
78
		});
79
		addAction.setToolTipText(getTooltipString());
80
		
81
		toolBarManager.add(addAction);
82
		
83
		return toolBarManager.createControl(this);
84
	}
85
	
86
	@Override
87
	public void refresh() {
88
		internalUpdateSection(false);
89
	}
90

    
91
	/* (non-Javadoc)
92
	 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
93
	 */
94
	@Override
95
	public Collection<DeterminationEvent> getCollection(DerivedUnitFacade entity) {
96
		DeterminationEvent preferredDetermination = entity.getPreferredDetermination();
97
		return preferredDetermination != null ? Arrays.asList(new DeterminationEvent[]{preferredDetermination}) : null;
98
	}
99
	
100
	/* (non-Javadoc)
101
	 * @see eu.etaxonomy.taxeditor.ui.section.occurrence.AbstractDeterminationEventDetailSection#createNewElement()
102
	 */
103
	@Override
104
	public DeterminationEvent createNewElement() {
105
		DeterminationEvent newElement = super.createNewElement();
106
		newElement.setPreferredFlag(true);
107
		return newElement;
108
	}
109
	
110

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

    
120
}
(6-6/29)