1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.ui.section.name;
|
12
|
|
13
|
import org.eclipse.jface.action.Action;
|
14
|
import org.eclipse.jface.action.IAction;
|
15
|
import org.eclipse.jface.action.ToolBarManager;
|
16
|
import org.eclipse.jface.viewers.ISelectionProvider;
|
17
|
import org.eclipse.swt.SWT;
|
18
|
import org.eclipse.swt.widgets.Control;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
21
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
22
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
23
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
24
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
25
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
|
27
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
28
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
|
29
|
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
|
30
|
import eu.etaxonomy.taxeditor.ui.section.campanula.compatibility.ICdmFormElement;
|
31
|
|
32
|
/**
|
33
|
* <p>NonViralNameDetailSection class.</p>
|
34
|
*
|
35
|
* @author n.hoffmann
|
36
|
* @created May 20, 2010
|
37
|
* @version 1.0
|
38
|
*/
|
39
|
public class NonViralNameDetailSection extends AbstractCdmDetailSection<NonViralName>
|
40
|
implements ITaxonBaseDetailSection {
|
41
|
|
42
|
private TaxonBase taxonBase;
|
43
|
|
44
|
/**
|
45
|
* <p>Constructor for NonViralNameDetailSection.</p>
|
46
|
*
|
47
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
48
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
49
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
50
|
* @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
|
51
|
* @param style a int.
|
52
|
*/
|
53
|
public NonViralNameDetailSection(CdmFormFactory formFactory, ConversationHolder conversation,
|
54
|
ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
|
55
|
super(formFactory, conversation, parentElement, selectionProvider, style);
|
56
|
}
|
57
|
|
58
|
/* (non-Javadoc)
|
59
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailSection#createToolbar()
|
60
|
*/
|
61
|
@Override
|
62
|
protected Control createToolbar() {
|
63
|
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
|
64
|
|
65
|
if(getEntity() != null && checkForMultipleNameUsages(getEntity())){
|
66
|
|
67
|
Action cloneAction = new Action("Clone", IAction.AS_PUSH_BUTTON){
|
68
|
@Override
|
69
|
public void run() {
|
70
|
boolean confirm = AbstractUtility.confirmDialog("Confirm cloning", "Do you really want to clone the name?");
|
71
|
|
72
|
if(confirm){
|
73
|
NonViralName clonedName;
|
74
|
clonedName = (NonViralName) getEntity().clone();
|
75
|
setEntity(clonedName);
|
76
|
taxonBase.setName(clonedName);
|
77
|
taxonBase.generateTitle();
|
78
|
// EditorUtil.getActiveMultiPageTaxonEditor().r
|
79
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(NonViralNameDetailSection.this, null));
|
80
|
}
|
81
|
|
82
|
};
|
83
|
};
|
84
|
|
85
|
cloneAction.setToolTipText("Clone the name if you do not want to edit the shared instance");
|
86
|
|
87
|
toolBarManager.add(cloneAction);
|
88
|
|
89
|
}
|
90
|
return toolBarManager.createControl(this);
|
91
|
}
|
92
|
|
93
|
|
94
|
/**
|
95
|
* @param nonViralName
|
96
|
*
|
97
|
*/
|
98
|
private boolean checkForMultipleNameUsages(NonViralName nonViralName) {
|
99
|
return nonViralName.getTaxonBases().size() != 1;
|
100
|
}
|
101
|
|
102
|
/* (non-Javadoc)
|
103
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailSection#getHeading()
|
104
|
*/
|
105
|
/** {@inheritDoc} */
|
106
|
@Override
|
107
|
public String getHeading() {
|
108
|
return "Name";
|
109
|
}
|
110
|
|
111
|
/* (non-Javadoc)
|
112
|
* @see eu.etaxonomy.taxeditor.section.ITaxonDetailSection#setTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)
|
113
|
*/
|
114
|
/** {@inheritDoc} */
|
115
|
@Override
|
116
|
public void setTaxonBase(TaxonBase taxon) {
|
117
|
taxonBase = taxon;
|
118
|
NonViralName name = (NonViralName) HibernateProxyHelper.deproxy(taxon.getName());
|
119
|
setEntity(name);
|
120
|
}
|
121
|
|
122
|
/* (non-Javadoc)
|
123
|
* @see eu.etaxonomy.taxeditor.section.ITaxonDetailSection#getTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)
|
124
|
*/
|
125
|
@Override
|
126
|
public TaxonBase getTaxonBase() {
|
127
|
return taxonBase;
|
128
|
}
|
129
|
|
130
|
/* (non-Javadoc)
|
131
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
|
132
|
*/
|
133
|
@Override
|
134
|
protected AbstractCdmDetailElement<NonViralName> createCdmDetailElement(AbstractCdmDetailSection<NonViralName> parentElement, int style) {
|
135
|
return formFactory.createNonViralNameDetailElement(parentElement);
|
136
|
}
|
137
|
}
|