Improved PrintPublisher Wizard; Integrated SpecimenCdmExcel import
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / supplemental / VersionElement.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.supplemental;
12
13 import org.eclipse.swt.widgets.Label;
14 import org.joda.time.DateTime;
15
16 import eu.etaxonomy.cdm.common.CdmUtils;
17 import eu.etaxonomy.cdm.model.common.User;
18 import eu.etaxonomy.cdm.model.common.VersionableEntity;
19 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20 import eu.etaxonomy.taxeditor.ui.forms.AbstractCdmFormElement;
21 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
22 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
23 import eu.etaxonomy.taxeditor.ui.forms.IEntityElement;
24 import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
25
26 /**
27 * <p>VersionElement class.</p>
28 *
29 * @author n.hoffmann
30 * @created Nov 5, 2009
31 * @version 1.0
32 */
33 public class VersionElement extends AbstractCdmFormElement implements IEntityElement<VersionableEntity> {
34
35 private Label label_created;
36 private Label label_updated;
37
38 private TextWithLabelElement text_uuid;
39 private TextWithLabelElement text_objectId;
40 private VersionableEntity entity;
41 private boolean showDebug;
42
43 /**
44 * <p>Constructor for VersionElement.</p>
45 *
46 * @param style a int.
47 * @param toolkit a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
48 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
49 * @param entity a {@link eu.etaxonomy.cdm.model.common.VersionableEntity} object.
50 */
51 public VersionElement(CdmFormFactory toolkit, ICdmFormElement parentElement, VersionableEntity entity, int style) {
52 super(toolkit, parentElement);
53
54 showDebug = PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.SHOW_DEBUG_INFORMATION);
55
56 label_created = toolkit.createLabel(getLayoutComposite(), null);
57 label_created.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY());
58
59 label_updated = toolkit.createLabel(getLayoutComposite(), null);
60 label_updated.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY());
61
62 if(showDebug){
63 text_uuid = toolkit.createTextWithLabelElement(parentElement, "UUID", null, style);
64
65 text_objectId = toolkit.createTextWithLabelElement(parentElement, "Object ID", null, style);
66 }
67 }
68
69 /**
70 * <p>Setter for the field <code>entity</code>.</p>
71 *
72 * @param entity a {@link eu.etaxonomy.cdm.model.common.VersionableEntity} object.
73 */
74 public void setEntity(VersionableEntity entity){
75
76 this.entity = entity;
77
78 String createdString = "Created "
79 + dateFormat(entity.getCreated())
80 + " by " + userFormat(entity.getCreatedBy());
81 label_created.setText(createdString);
82
83 String updatedString = "Updated "
84 + dateFormat(entity.getUpdated())
85 + " by " + userFormat(entity.getUpdatedBy());
86 label_updated.setText(updatedString);
87
88
89
90 if(showDebug){
91 text_uuid.setText(entity.getUuid().toString());
92
93 text_objectId.setText(entity.getId()+"");
94 }
95
96 }
97
98 private String dateFormat(DateTime dateTime){
99 if(dateTime == null){
100 return "";
101 }
102 return CdmUtils.Nz(dateTime.toString(PreferencesUtil.getDateFormatPattern()));
103 }
104
105 private String userFormat(User user){
106 if(user == null){
107 return "";
108 }
109 // TODO agree on what to display username or real name or even more from shibboleth
110 return CdmUtils.Nz(user.getUsername());
111 }
112
113 /**
114 * <p>Getter for the field <code>entity</code>.</p>
115 *
116 * @return a {@link eu.etaxonomy.cdm.model.common.VersionableEntity} object.
117 */
118 public VersionableEntity getEntity() {
119 return entity;
120 }
121
122 /** {@inheritDoc} */
123 public void setSelected(boolean selected) {
124 // will not likely be selected
125 }
126 }