Revision 7e65b368
Added by Patrick Plitzner almost 8 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/identifier/IdentifierDetailSection.java | ||
---|---|---|
12 | 12 |
|
13 | 13 |
import java.util.Collection; |
14 | 14 |
|
15 |
import org.eclipse.jface.action.Action; |
|
16 |
import org.eclipse.jface.action.IAction; |
|
17 |
import org.eclipse.jface.action.ToolBarManager; |
|
18 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
19 |
import org.eclipse.swt.SWT; |
|
20 |
import org.eclipse.swt.graphics.ImageData; |
|
21 |
import org.eclipse.swt.widgets.Control; |
|
22 |
|
|
23 | 15 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
24 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
|
16 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
|
25 | 17 |
import eu.etaxonomy.cdm.model.common.Identifier; |
26 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
|
27 | 18 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
28 | 19 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
29 | 20 |
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection; |
30 | 21 |
|
31 | 22 |
/** |
32 |
* <p> |
|
33 |
* CollectingAreasDetailSection class. |
|
34 |
* </p> |
|
23 |
* |
|
24 |
* @author pplitzner |
|
35 | 25 |
* |
36 |
* @author n.hoffmann |
|
37 |
* @created Oct 14, 2010 |
|
38 |
* @version 1.0 |
|
39 | 26 |
*/ |
40 |
public class IdentifierDetailSection extends AbstractEntityCollectionSection<DerivedUnitFacade, Identifier> {
|
|
27 |
public class IdentifierDetailSection extends AbstractEntityCollectionSection<IdentifiableEntity, Identifier> {
|
|
41 | 28 |
|
42 |
/** |
|
43 |
* <p>Constructor for CollectingAreasDetailSection.</p> |
|
44 |
* |
|
45 |
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object. |
|
46 |
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
|
47 |
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object. |
|
48 |
* @param style a int. |
|
49 |
*/ |
|
50 | 29 |
public IdentifierDetailSection(CdmFormFactory formFactory, |
51 | 30 |
ConversationHolder conversation, ICdmFormElement parentElement, int style) { |
52 | 31 |
super(formFactory, conversation, parentElement, "Identifiers", style); |
53 | 32 |
} |
54 | 33 |
|
55 |
@Override |
|
56 |
protected Control createToolbar() { |
|
57 |
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); |
|
58 |
|
|
59 |
Action addAction = new Action("add", IAction.AS_PUSH_BUTTON){ |
|
60 |
/* (non-Javadoc) |
|
61 |
* @see org.eclipse.jface.action.Action#run() |
|
62 |
*/ |
|
63 |
@Override |
|
64 |
public void run() { |
|
65 |
Identifier element = createNewElement(); |
|
66 |
if(element != null){ |
|
67 |
if(! getSection().isExpanded()) { |
|
68 |
getSection().setExpanded(true); |
|
69 |
} |
|
70 |
internalUpdateSection(true); |
|
71 |
} |
|
72 |
} |
|
73 |
}; |
|
74 |
addAction.setImageDescriptor(new ImageDescriptor() { |
|
75 |
|
|
76 |
@Override |
|
77 |
public ImageData getImageData() { |
|
78 |
return ImageResources.getImage(ImageResources.ADD_ICON).getImageData(); |
|
79 |
} |
|
80 |
}); |
|
81 |
addAction.setToolTipText(getTooltipString()); |
|
82 |
|
|
83 |
toolBarManager.add(addAction); |
|
84 |
|
|
85 |
return toolBarManager.createControl(this); |
|
86 |
} |
|
87 |
|
|
88 |
/* (non-Javadoc) |
|
89 |
* @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getCollection(java.lang.Object) |
|
90 |
*/ |
|
91 | 34 |
/** {@inheritDoc} */ |
92 | 35 |
@Override |
93 |
public Collection<Identifier> getCollection(DerivedUnitFacade entity) {
|
|
36 |
public Collection<Identifier> getCollection(IdentifiableEntity entity) {
|
|
94 | 37 |
return entity.getIdentifiers(); |
95 | 38 |
} |
96 | 39 |
|
97 |
/* (non-Javadoc) |
|
98 |
* @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#createNewElement() |
|
99 |
*/ |
|
100 | 40 |
/** {@inheritDoc} */ |
101 | 41 |
@Override |
102 | 42 |
public Identifier createNewElement() { |
103 |
return Identifier.NewInstance(getEntity().baseUnit(), null, null);
|
|
43 |
return Identifier.NewInstance(null, null); |
|
104 | 44 |
} |
105 | 45 |
|
106 |
/* (non-Javadoc) |
|
107 |
* @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#addElement(eu.etaxonomy.cdm.model.common.IVersionableEntity) |
|
108 |
*/ |
|
109 | 46 |
/** {@inheritDoc} */ |
110 | 47 |
@Override |
111 | 48 |
public void addElement(Identifier element) { |
112 | 49 |
getEntity().addIdentifier(element); |
113 | 50 |
} |
114 | 51 |
|
115 |
/* (non-Javadoc) |
|
116 |
* @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#removeElement(eu.etaxonomy.cdm.model.common.IVersionableEntity) |
|
117 |
*/ |
|
118 | 52 |
/** {@inheritDoc} */ |
119 | 53 |
@Override |
120 | 54 |
public void removeElement(Identifier element) { |
121 |
getEntity().removeIdentifier(getEntity().getIdentifiers().get(0));
|
|
55 |
getEntity().removeIdentifier(element);
|
|
122 | 56 |
getConversationHolder().commit(); |
123 | 57 |
} |
124 | 58 |
|
125 |
/* (non-Javadoc) |
|
126 |
* @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getEmptyString() |
|
127 |
*/ |
|
128 | 59 |
/** {@inheritDoc} */ |
129 | 60 |
@Override |
130 | 61 |
public String getEmptyString() { |
131 | 62 |
return "No identifiers yet."; |
132 | 63 |
} |
133 | 64 |
|
134 |
/* (non-Javadoc) |
|
135 |
* @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getTooltipString() |
|
136 |
*/ |
|
137 | 65 |
/** {@inheritDoc} */ |
138 | 66 |
@Override |
139 | 67 |
protected String getTooltipString() { |
Also available in: Unified diff
Add identifer section to supplemental data view #5898