Project

General

Profile

Download (4.1 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.TaxonBaseSelectionDialog;
27
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
28
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
29
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
30
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
31
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
32

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

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

    
50
	@Override
51
	public String getHeading() {
52

    
53
		return getEntity() != null ? StringUtils.replace( getEntity().getType().getLabel(), "for", ""): "Taxon Relation";
54
	}
55

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

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

    
72
	@Override
73
	public TaxonBase getTaxonBase() {
74
		return taxon;
75
	}
76

    
77
	private void setName(TaxonName name){
78
		this.name = name;
79
	}
80

    
81
	@Override
82
	protected Control createToolbar() {
83
	        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
84

    
85
	        if(taxonChoosable){
86
	            //choose name
87
	            Action chooseTaxonAction = new Action("Choose Taxon", IAction.AS_PUSH_BUTTON){
88
	                @Override
89
	                public void run() {
90
	                    Taxon taxon = TaxonBaseSelectionDialog.selectTaxon(getShell(), //getConversationHolder(),
91
	                            getEntity().getFromTaxon());
92
	                    if(taxon!=null){
93
                            taxon = HibernateProxyHelper.deproxy(taxon);
94
                            name = taxon.getName();
95
                            TaxonRelationship rel = getEntity();
96
                            rel.setFromTaxon(taxon);
97
                            setEntity(rel);
98
                            setTaxonBase(taxon);
99

    
100
                            firePropertyChangeEvent(TaxonRelationshipDetailSection.this);
101
	                    }
102
	                }
103
	            };
104
	            chooseTaxonAction.setToolTipText("Choose taxon for this Relationship");
105
	            chooseTaxonAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.BROWSE_ICON));
106

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

    
112
}
(9-9/10)