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
            return wizard.getNameRelationship();
69
        }
70

    
71
		return null;
72
	}
73

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

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

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

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

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

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

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

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

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