1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.taxeditor.ui.section.name;
|
11
|
|
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.INonViralName;
|
22
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
23
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
24
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
25
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
26
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.NameSelectionDialog;
|
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
|
* @created May 20, 2010
|
37
|
*/
|
38
|
public class NonViralNameDetailSection extends AbstractCdmDetailSection<TaxonName>
|
39
|
implements ITaxonBaseDetailSection {
|
40
|
|
41
|
private TaxonBase taxonBase;
|
42
|
boolean nameChoosable = false;
|
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 nameChoosable if <code>true</code> adds a button to choose the displayed name
|
52
|
* @param style a int.
|
53
|
*/
|
54
|
public NonViralNameDetailSection(CdmFormFactory formFactory, ConversationHolder conversation,
|
55
|
ICdmFormElement parentElement, ISelectionProvider selectionProvider, boolean nameChoosable, int style) {
|
56
|
super(formFactory, conversation, parentElement, selectionProvider, style);
|
57
|
this.nameChoosable = nameChoosable;
|
58
|
}
|
59
|
|
60
|
@Override
|
61
|
protected Control createToolbar() {
|
62
|
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
|
63
|
|
64
|
if(nameChoosable ){
|
65
|
//choose name
|
66
|
Action chooseNameAction = new Action("Choose Name", IAction.AS_PUSH_BUTTON){
|
67
|
@Override
|
68
|
public void run() {
|
69
|
TaxonName taxonName = NameSelectionDialog.select(getShell(), //getConversationHolder(),
|
70
|
getEntity());
|
71
|
if(taxonName!=null){
|
72
|
TaxonName nonViralName = HibernateProxyHelper.deproxy(taxonName);
|
73
|
taxonBase.setName(nonViralName);
|
74
|
// taxonBase.getTitleCache();
|
75
|
setEntity(nonViralName);
|
76
|
firePropertyChangeEvent(NonViralNameDetailSection.this);
|
77
|
}
|
78
|
}
|
79
|
};
|
80
|
chooseNameAction.setToolTipText("Choose name for this taxon");
|
81
|
chooseNameAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.BROWSE_ICON));
|
82
|
|
83
|
toolBarManager.add(chooseNameAction);
|
84
|
}
|
85
|
|
86
|
//clone
|
87
|
if(getEntity() != null && checkForMultipleNameUsages(getEntity())){
|
88
|
|
89
|
Action cloneAction = new Action("Clone", IAction.AS_PUSH_BUTTON){
|
90
|
@Override
|
91
|
public void run() {
|
92
|
boolean confirm = MessagingUtils.confirmDialog("Confirm cloning", "Do you really want to clone the name?");
|
93
|
|
94
|
if(confirm){
|
95
|
TaxonName clonedName;
|
96
|
clonedName = (TaxonName) getEntity().clone();
|
97
|
setEntity(clonedName);
|
98
|
taxonBase.setName(clonedName);
|
99
|
taxonBase.generateTitle();
|
100
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(NonViralNameDetailSection.this, null));
|
101
|
}
|
102
|
|
103
|
};
|
104
|
};
|
105
|
|
106
|
cloneAction.setToolTipText("Clone the name if you do not want to edit the shared instance");
|
107
|
|
108
|
toolBarManager.add(cloneAction);
|
109
|
|
110
|
}
|
111
|
return toolBarManager.createControl(this);
|
112
|
}
|
113
|
|
114
|
|
115
|
private boolean checkForMultipleNameUsages(INonViralName nonViralName) {
|
116
|
return nonViralName.getTaxonBases().size() != 1;
|
117
|
}
|
118
|
|
119
|
/** {@inheritDoc} */
|
120
|
@Override
|
121
|
public String getHeading() {
|
122
|
return "Name";
|
123
|
}
|
124
|
|
125
|
/** {@inheritDoc} */
|
126
|
@Override
|
127
|
public void setTaxonBase(TaxonBase taxon) {
|
128
|
taxonBase = taxon;
|
129
|
TaxonName name = HibernateProxyHelper.deproxy(taxon.getName());
|
130
|
setEntity(name);
|
131
|
}
|
132
|
|
133
|
@Override
|
134
|
public TaxonBase getTaxonBase() {
|
135
|
return taxonBase;
|
136
|
}
|
137
|
|
138
|
@Override
|
139
|
protected AbstractCdmDetailElement<TaxonName> createCdmDetailElement(
|
140
|
AbstractCdmDetailSection<TaxonName> parentElement, int style) {
|
141
|
return formFactory.createNonViralNameDetailElement(parentElement);
|
142
|
}
|
143
|
}
|