Project

General

Profile

Download (3.97 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.derivedUnit;
12

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

    
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;
23

    
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.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 PreservedSpecimenCurrentDeterminationDetailSection extends
37
    PreservedSpecimenAbstractDeterminationEventDetailSection {
38

    
39
	/**
40
	 * @param formFactory
41
	 * @param conversation
42
	 * @param parentElement
43
	 * @param style
44
	 */
45
	public PreservedSpecimenCurrentDeterminationDetailSection(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", Action.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
		        Set<DeterminationEvent> events = getEntity().getDeterminations();
65
		        for (DeterminationEvent event : events){
66
		            if (event.getPreferredFlag() == true){
67
		                event.setPreferredFlag(false);
68
		            }
69
		        }
70
		        element.setPreferredFlag(true);
71
		        events.add(element);
72

    
73
				if(element != null){
74
					if(! getSection().isExpanded()) {
75
                        getSection().setExpanded(true);
76
                    }
77
					internalUpdateSection(true);
78
				}
79
			}
80
		};
81
		addAction.setImageDescriptor(new ImageDescriptor() {
82

    
83
			@Override
84
			public ImageData getImageData() {
85
				return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
86
			}
87
		});
88
		addAction.setToolTipText(getTooltipString());
89

    
90
		toolBarManager.add(addAction);
91

    
92
		return toolBarManager.createControl(this);
93
	}
94

    
95
	@Override
96
	public void refresh() {
97
		internalUpdateSection(false);
98
	}
99

    
100
	/* (non-Javadoc)
101
	 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
102
	 */
103
	@Override
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;
110
	            }
111
	        }
112
		return preferredDetermination != null ? Arrays.asList(new DeterminationEvent[]{preferredDetermination}) : null;
113
	}
114

    
115
	/* (non-Javadoc)
116
	 * @see eu.etaxonomy.taxeditor.ui.section.occurrence.AbstractDeterminationEventDetailSection#createNewElement()
117
	 */
118
	@Override
119
	public DeterminationEvent createNewElement() {
120
		DeterminationEvent newElement = super.createNewElement();
121
		newElement.setPreferredFlag(true);
122
		return newElement;
123
	}
124

    
125

    
126
	/* (non-Javadoc)
127
	 * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getTooltipString()
128
	 */
129
	/** {@inheritDoc} */
130
	@Override
131
	protected String getTooltipString() {
132
		return "Create new current determination event";
133
	}
134

    
135
}
(2-2/10)