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.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.NonViralName;
|
22
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
23
|
import eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade;
|
24
|
import eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade.DetailType;
|
25
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
26
|
import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
|
27
|
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
|
28
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
|
29
|
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
|
30
|
|
31
|
/**
|
32
|
* <p>NonViralNameDetailSection class.</p>
|
33
|
*
|
34
|
* @author n.hoffmann
|
35
|
* @created May 20, 2010
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
public class NonViralNameDetailSection extends AbstractCdmDetailSection<NonViralName>
|
39
|
implements ITaxonBaseDetailSection {
|
40
|
|
41
|
private TaxonBase taxonBase;
|
42
|
|
43
|
/**
|
44
|
* <p>Constructor for NonViralNameDetailSection.</p>
|
45
|
*
|
46
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade} object.
|
47
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
48
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
|
49
|
* @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
|
50
|
* @param style a int.
|
51
|
*/
|
52
|
public NonViralNameDetailSection(CdmFormFactoryFacade formFactory, ConversationHolder conversation,
|
53
|
ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
|
54
|
super(formFactory, conversation, parentElement, selectionProvider, style);
|
55
|
}
|
56
|
|
57
|
/* (non-Javadoc)
|
58
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailSection#createToolbar()
|
59
|
*/
|
60
|
@Override
|
61
|
protected Control createToolbar() {
|
62
|
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
|
63
|
|
64
|
if(getEntity() != null && checkForMultipleNameUsages(getEntity())){
|
65
|
|
66
|
Action cloneAction = new Action("Clone", Action.AS_PUSH_BUTTON){
|
67
|
public void run() {
|
68
|
boolean confirm = StoreUtil.confirmDialog("Confirm cloning", "Do you really want to clone the name?");
|
69
|
|
70
|
if(confirm){
|
71
|
NonViralName clonedName;
|
72
|
clonedName = (NonViralName) getEntity().clone();
|
73
|
setEntity(clonedName);
|
74
|
taxonBase.setName(clonedName);
|
75
|
taxonBase.generateTitle();
|
76
|
// EditorUtil.getActiveMultiPageTaxonEditor().r
|
77
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(NonViralNameDetailSection.this, null));
|
78
|
}
|
79
|
|
80
|
};
|
81
|
};
|
82
|
|
83
|
cloneAction.setToolTipText("Clone the name if you do not want to edit the shared instance");
|
84
|
|
85
|
toolBarManager.add(cloneAction);
|
86
|
|
87
|
}
|
88
|
return toolBarManager.createControl(this);
|
89
|
}
|
90
|
|
91
|
|
92
|
/**
|
93
|
* @param nonViralName
|
94
|
*
|
95
|
*/
|
96
|
private boolean checkForMultipleNameUsages(NonViralName nonViralName) {
|
97
|
return nonViralName.getTaxonBases().size() != 1;
|
98
|
}
|
99
|
|
100
|
/* (non-Javadoc)
|
101
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailSection#getDetailType()
|
102
|
*/
|
103
|
/** {@inheritDoc} */
|
104
|
@Override
|
105
|
protected DetailType getDetailType() {
|
106
|
return DetailType.NONVIRALNAME;
|
107
|
}
|
108
|
|
109
|
/* (non-Javadoc)
|
110
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailSection#getHeading()
|
111
|
*/
|
112
|
/** {@inheritDoc} */
|
113
|
@Override
|
114
|
public String getHeading() {
|
115
|
return "Name";
|
116
|
}
|
117
|
|
118
|
/* (non-Javadoc)
|
119
|
* @see eu.etaxonomy.taxeditor.section.ITaxonDetailSection#setTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)
|
120
|
*/
|
121
|
/** {@inheritDoc} */
|
122
|
public void setTaxonBase(TaxonBase taxon) {
|
123
|
taxonBase = taxon;
|
124
|
NonViralName name = (NonViralName) HibernateProxyHelper.deproxy(taxon.getName());
|
125
|
setEntity(name);
|
126
|
}
|
127
|
|
128
|
/* (non-Javadoc)
|
129
|
* @see eu.etaxonomy.taxeditor.section.ITaxonDetailSection#getTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)
|
130
|
*/
|
131
|
@Override
|
132
|
public TaxonBase getTaxonBase() {
|
133
|
return taxonBase;
|
134
|
}
|
135
|
}
|