Project

General

Profile

Download (4.24 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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
package eu.etaxonomy.taxeditor.ui.section.taxon;
10

    
11
import org.apache.commons.lang.StringUtils;
12
import org.eclipse.jface.action.Action;
13
import org.eclipse.jface.action.IAction;
14
import org.eclipse.jface.action.ToolBarManager;
15
import org.eclipse.jface.viewers.ISelectionProvider;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.widgets.Control;
18

    
19
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
21
import eu.etaxonomy.cdm.model.name.TaxonName;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
24
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
25
import eu.etaxonomy.taxeditor.model.ImageResources;
26
import eu.etaxonomy.taxeditor.ui.dialog.selection.NameSelectionDialog;
27
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
28
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
29
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
30
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
31
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
32
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
33
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailSection;
34

    
35
/**
36
 * @author n.hoffmann
37
 * @date Dec 1, 2011
38
 *
39
 */
40
public class TaxonRelationshipDetailSection extends AbstractCdmDetailSection<TaxonRelationship> implements ITaxonBaseDetailSection {
41
	Taxon taxon;
42
	TaxonName name;
43
	boolean taxonChoosable = false;
44

    
45
	public TaxonRelationshipDetailSection(CdmFormFactory formFactory,
46
			ConversationHolder conversation, ICdmFormElement parentElement,
47
			ISelectionProvider selectionProvider, int style, boolean taxonChoosable) {
48
		super(formFactory, conversation, parentElement,  selectionProvider, style);
49
		this.taxonChoosable = taxonChoosable;
50
	}
51

    
52
	@Override
53
	public String getHeading() {
54
		
55
		return getEntity() != null ? StringUtils.replace( getEntity().getType().getLabel(), "for", ""): "Taxon Relation";
56
	}
57

    
58
	/* (non-Javadoc)
59
	 * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
60
	 */
61
	@Override
62
	protected AbstractCdmDetailElement<TaxonRelationship> createCdmDetailElement(AbstractCdmDetailSection<TaxonRelationship> parentElement, int style) {
63
	    return formFactory.createTaxonRelationshipDetailElement(parentElement);
64
	}
65

    
66
	/** {@inheritDoc} */
67
	@Override
68
    public void setTaxonBase(TaxonBase taxon) {
69
		this.taxon = (Taxon)taxon;
70
		TaxonName name = HibernateProxyHelper.deproxy(taxon.getName());
71
		setName(name);
72
	}
73

    
74
	@Override
75
	public TaxonBase getTaxonBase() {
76
		return taxon;
77
	}
78
	
79
	private void setName(TaxonName name){
80
		this.name = name;
81
	}
82
	
83
	@Override
84
	protected Control createToolbar() {
85
	        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
86

    
87
	        if(taxonChoosable){
88
	            //choose name
89
	            Action chooseTaxonAction = new Action("Choose Taxon", IAction.AS_PUSH_BUTTON){
90
	                @Override
91
	                public void run() {
92
	                    Taxon taxon = TaxonBaseSelectionDialog.selectTaxon(getShell(), getConversationHolder(), getEntity().getFromTaxon());
93
	                    if(taxon!=null){
94
                            taxon = HibernateProxyHelper.deproxy(taxon);
95
                            name = taxon.getName();
96
                            TaxonRelationship rel = getEntity();
97
                            rel.setFromTaxon(taxon);
98
                            setEntity(rel);
99
                            setTaxonBase(taxon);
100
                           
101
                            firePropertyChangeEvent(TaxonRelationshipDetailSection.this);
102
	                    }
103
	                }
104
	            };
105
	            chooseTaxonAction.setToolTipText("Choose taxon for this Relationship");
106
	            chooseTaxonAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.BROWSE_ICON));
107

    
108
	            toolBarManager.add(chooseTaxonAction);
109
	    }
110
	        return toolBarManager.createControl(this);
111
	}
112

    
113
}
(9-9/10)