Project

General

Profile

Download (3.69 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.name;
11

    
12
import java.util.Collection;
13
import java.util.Comparator;
14

    
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.jface.wizard.WizardDialog;
17

    
18
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
20
import eu.etaxonomy.cdm.model.name.NameRelationship;
21
import eu.etaxonomy.cdm.model.name.TaxonName;
22
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
23
import eu.etaxonomy.taxeditor.store.StoreUtil;
24
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
27
import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
28
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
29

    
30
/**
31
 * <p>NameRelationshipDetailSection class.</p>
32
 *
33
 * @author n.hoffmann
34
 * @created Mar 18, 2010
35
 */
36
public class NameRelationshipDetailSection extends AbstractEntityCollectionSection<TaxonName, NameRelationship> implements ITaxonBaseDetailSection{
37

    
38
	private TaxonBase taxonBase;
39

    
40
	/**
41
	 * <p>Constructor for NameRelationshipDetailSection.</p>
42
	 *
43
	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
44
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
45
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
46
	 * @param style a int.
47
	 */
48
	public NameRelationshipDetailSection(CdmFormFactory formFactory, ConversationHolder conversation,
49
			ICdmFormElement parentElement, int style) {
50
		super(formFactory, conversation, parentElement, "Name Relationships", style);
51
	}
52

    
53
	/** {@inheritDoc} */
54
	@Override
55
	public void addElement(NameRelationship element) {
56
		//getEntity().addRelationship(element);
57
	}
58

    
59
	/** {@inheritDoc} */
60
	@Override
61
	public NameRelationship createNewElement() {
62

    
63
		NameRelationshipWizard wizard = new NameRelationshipWizard(this);
64
		WizardDialog dialog = new WizardDialog(StoreUtil.getShell(), wizard);
65
		int status = dialog.open();
66

    
67
		if(status == IStatus.OK) {
68

    
69
            return wizard.getNameRelationship();
70
        }
71

    
72
		return null;
73
	}
74

    
75
	/** {@inheritDoc} */
76
	@Override
77
	public Collection<NameRelationship> getCollection(TaxonName entity) {
78
		Collection<NameRelationship> allNameRelationships = entity.getRelationsFromThisName();
79
		allNameRelationships.addAll(entity.getRelationsToThisName());
80
		return allNameRelationships;
81
	}
82

    
83
	@Override
84
	public Comparator<NameRelationship> getComparator() {
85
        return new DefaultCdmBaseComparator<>();
86
	}
87

    
88
	/** {@inheritDoc} */
89
	@Override
90
	public String getEmptyString() {
91
		return "No name relationships yet.";
92
	}
93

    
94
	/** {@inheritDoc} */
95
	@Override
96
	protected String getTooltipString() {
97
		return "Add a new name relationship from this name.";
98
	}
99

    
100
	/** {@inheritDoc} */
101
	@Override
102
	public void removeElement(NameRelationship element) {
103
		getEntity().removeNameRelationship(element);
104
	}
105

    
106
	/** {@inheritDoc} */
107
	@Override
108
    public void setTaxonBase(TaxonBase entity) {
109
		this.taxonBase = entity;
110
		TaxonName name = HibernateProxyHelper.deproxy(entity.getName());
111
		setEntity(name);
112
	}
113

    
114
	@Override
115
	public TaxonBase getTaxonBase() {
116
		return taxonBase;
117
	}
118

    
119
    /**
120
     * {@inheritDoc}
121
     */
122
    @Override
123
    public NameRelationship addExisting() {
124
        return null;
125
    }
126

    
127
    /**
128
     * {@inheritDoc}
129
     */
130
    @Override
131
    public boolean allowAddExisting() {
132
        return false;
133
    }
134
}
(9-9/21)