Project

General

Profile

Download (3.43 KB) Statistics
| Branch: | Tag: | Revision:
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

    
10
package eu.etaxonomy.taxeditor.ui.section.occurrence;
11

    
12
import java.util.Arrays;
13
import java.util.Collection;
14
import java.util.Comparator;
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
import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
31

    
32
/**
33
 * @author n.hoffmann
34
 * @created May 11, 2011
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
			@Override
57
			public void run() {
58
				DeterminationEvent element = createNewElement();
59

    
60
				// set as preferred determination
61
				getEntity().setPreferredDetermination(element);
62

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

    
73
			@Override
74
			public ImageData getImageData() {
75
				return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
76
			}
77
		});
78
		addAction.setToolTipText(getTooltipString());
79

    
80
		toolBarManager.add(addAction);
81

    
82
		return toolBarManager.createControl(this);
83
	}
84

    
85
	@Override
86
	public void refresh() {
87
		internalUpdateSection(false);
88
	}
89

    
90
	@Override
91
	public Collection<DeterminationEvent> getCollection(DerivedUnitFacade entity) {
92
		DeterminationEvent preferredDetermination = entity.getPreferredDetermination();
93
		return preferredDetermination != null ? Arrays.asList(new DeterminationEvent[]{preferredDetermination}) : null;
94
	}
95

    
96
	@Override
97
	public Comparator<DeterminationEvent> getComparator() {
98
        return new DefaultCdmBaseComparator<>();
99
	}
100

    
101
	@Override
102
	public DeterminationEvent createNewElement() {
103
		DeterminationEvent newElement = super.createNewElement();
104
		newElement.setPreferredFlag(true);
105
		return newElement;
106
	}
107

    
108
	/** {@inheritDoc} */
109
	@Override
110
	protected String getTooltipString() {
111
		return "Create new current determination event";
112
	}
113

    
114
    /**
115
     * {@inheritDoc}
116
     */
117
    @Override
118
    public DeterminationEvent addExisting() {
119
        return null;
120
    }
121

    
122
    /**
123
     * {@inheritDoc}
124
     */
125
    @Override
126
    public boolean allowAddExisting() {
127
        return false;
128
    }
129

    
130
}
(8-8/35)