Project

General

Profile

Download (4.27 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.CdmPropertyChangeEvent;
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

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

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

    
51
	@Override
52
	public String getHeading() {
53

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

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

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

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

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

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

    
86
	        if(taxonChoosable){
87
	            //choose name
88
	            Action chooseTaxonAction = new Action("Choose Taxon", IAction.AS_PUSH_BUTTON){
89
	                @Override
90
	                public void run() {
91
	                    Taxon taxon = TaxonBaseSelectionDialog.selectTaxon(getShell(), //getConversationHolder(),
92
	                            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
                            detailElement.firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
100
                            setTaxonBase(taxon);
101

    
102

    
103
                            firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
104
	                    }
105
	                }
106
	            };
107
	            chooseTaxonAction.setToolTipText("Choose taxon for this Relationship");
108
	            chooseTaxonAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.BROWSE_ICON));
109

    
110
	            toolBarManager.add(chooseTaxonAction);
111
	    }
112
	        return toolBarManager.createControl(this);
113
	}
114

    
115
}
(9-9/10)