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.event.EventUtility;
|
26
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
27
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
28
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
|
31
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
33
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
|
34
|
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
|
35
|
|
36
|
/**
|
37
|
* @author n.hoffmann
|
38
|
* @date Dec 1, 2011
|
39
|
*
|
40
|
*/
|
41
|
public class TaxonRelationshipDetailSection extends AbstractCdmDetailSection<TaxonRelationship> implements ITaxonBaseDetailSection {
|
42
|
Taxon taxon;
|
43
|
TaxonName name;
|
44
|
boolean taxonChoosable = false;
|
45
|
|
46
|
public TaxonRelationshipDetailSection(CdmFormFactory formFactory,
|
47
|
ConversationHolder conversation, ICdmFormElement parentElement,
|
48
|
ISelectionProvider selectionProvider, int style, boolean taxonChoosable) {
|
49
|
super(formFactory, conversation, parentElement, selectionProvider, style);
|
50
|
this.taxonChoosable = taxonChoosable;
|
51
|
}
|
52
|
|
53
|
@Override
|
54
|
public String getHeading() {
|
55
|
|
56
|
return getEntity() != null ? StringUtils.replace( getEntity().getType().getLabel(), "for", ""): "Taxon Relation";
|
57
|
}
|
58
|
|
59
|
/* (non-Javadoc)
|
60
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
|
61
|
*/
|
62
|
@Override
|
63
|
protected AbstractCdmDetailElement<TaxonRelationship> createCdmDetailElement(AbstractCdmDetailSection<TaxonRelationship> parentElement, int style) {
|
64
|
return formFactory.createTaxonRelationshipDetailElement(parentElement);
|
65
|
}
|
66
|
|
67
|
/** {@inheritDoc} */
|
68
|
@Override
|
69
|
public void setTaxonBase(TaxonBase taxon) {
|
70
|
this.taxon = (Taxon)taxon;
|
71
|
TaxonName name = HibernateProxyHelper.deproxy(taxon.getName());
|
72
|
setName(name);
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public TaxonBase getTaxonBase() {
|
77
|
return taxon;
|
78
|
}
|
79
|
|
80
|
private void setName(TaxonName name){
|
81
|
this.name = name;
|
82
|
}
|
83
|
|
84
|
@Override
|
85
|
protected Control createToolbar() {
|
86
|
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
|
87
|
|
88
|
if(taxonChoosable){
|
89
|
//choose name
|
90
|
Action chooseTaxonAction = new Action("Choose Taxon", IAction.AS_PUSH_BUTTON){
|
91
|
@Override
|
92
|
public void run() {
|
93
|
Taxon taxon = TaxonBaseSelectionDialog.selectTaxon(getShell(), //getConversationHolder(),
|
94
|
getEntity().getFromTaxon());
|
95
|
if(taxon!=null){
|
96
|
taxon = HibernateProxyHelper.deproxy(taxon);
|
97
|
name = taxon.getName();
|
98
|
TaxonRelationship rel = getEntity();
|
99
|
rel.setFromTaxon(taxon);
|
100
|
setEntity(rel);
|
101
|
setTaxonBase(taxon);
|
102
|
// firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
|
103
|
detailElement.firePropertyChangeEvent(new CdmPropertyChangeEvent(detailElement, null));
|
104
|
EventUtility.postEvent(WorkbenchEventConstants.REFRESH_TAXON_DETAILS, true);
|
105
|
EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, true);
|
106
|
((TaxonRelationshipDetailElement)detailElement).getTaxonElement().setSelected(true);
|
107
|
// EventUtility.postEvent(WorkbenchEventConstants.REFRESH_SUPPLEMENTAL, true);
|
108
|
}
|
109
|
}
|
110
|
};
|
111
|
chooseTaxonAction.setToolTipText("Choose taxon for this Relationship");
|
112
|
chooseTaxonAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.BROWSE_ICON));
|
113
|
|
114
|
toolBarManager.add(chooseTaxonAction);
|
115
|
}
|
116
|
return toolBarManager.createControl(this);
|
117
|
}
|
118
|
|
119
|
|
120
|
|
121
|
}
|