Project

General

Profile

Download (3.68 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

    
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

    
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", IAction.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
                    }
69
					internalUpdateSection(true);
70
				}
71
			}
72
		};
73
		addAction.setImageDescriptor(new ImageDescriptor() {
74

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

    
82
		toolBarManager.add(addAction);
83

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

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

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

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

    
111

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

    
121
    /**
122
     * {@inheritDoc}
123
     */
124
    @Override
125
    public DeterminationEvent addExisting() {
126
        return null;
127
    }
128

    
129
    /**
130
     * {@inheritDoc}
131
     */
132
    @Override
133
    public boolean allowAddExisting() {
134
        return false;
135
    }
136

    
137
}
(7-7/37)