03e13f8302471fca11d73c06dd7c14048deabd62
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / identifier / IdentifierDetailSection.java
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.identifier;
12
13 import java.util.Collection;
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 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
24 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
25 import eu.etaxonomy.cdm.model.common.Identifier;
26 import eu.etaxonomy.taxeditor.model.ImageResources;
27 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
28 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
29 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
30
31 /**
32 * <p>
33 * CollectingAreasDetailSection class.
34 * </p>
35 *
36 * @author n.hoffmann
37 * @created Oct 14, 2010
38 * @version 1.0
39 */
40 public class IdentifierDetailSection extends AbstractEntityCollectionSection<DerivedUnitFacade, Identifier> {
41
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 public IdentifierDetailSection(CdmFormFactory formFactory,
51 ConversationHolder conversation, ICdmFormElement parentElement, int style) {
52 super(formFactory, conversation, parentElement, "Identifiers", style);
53 }
54
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 /** {@inheritDoc} */
92 @Override
93 public Collection<Identifier> getCollection(DerivedUnitFacade entity) {
94 return entity.getIdentifiers();
95 }
96
97 /* (non-Javadoc)
98 * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#createNewElement()
99 */
100 /** {@inheritDoc} */
101 @Override
102 public Identifier createNewElement() {
103 return Identifier.NewInstance(getEntity().baseUnit(), null, null);
104 }
105
106 /* (non-Javadoc)
107 * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#addElement(eu.etaxonomy.cdm.model.common.IVersionableEntity)
108 */
109 /** {@inheritDoc} */
110 @Override
111 public void addElement(Identifier element) {
112 getEntity().addIdentifier(element);
113 }
114
115 /* (non-Javadoc)
116 * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#removeElement(eu.etaxonomy.cdm.model.common.IVersionableEntity)
117 */
118 /** {@inheritDoc} */
119 @Override
120 public void removeElement(Identifier element) {
121 getEntity().removeIdentifier(getEntity().getIdentifiers().get(0));
122 getConversationHolder().commit();
123 System.out.println();
124 }
125
126 /* (non-Javadoc)
127 * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getEmptyString()
128 */
129 /** {@inheritDoc} */
130 @Override
131 public String getEmptyString() {
132 return "No identifiers yet.";
133 }
134
135 /* (non-Javadoc)
136 * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getTooltipString()
137 */
138 /** {@inheritDoc} */
139 @Override
140 protected String getTooltipString() {
141 return "Add an identifier";
142 }
143
144 }