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.element.AbstractCdmFormElement;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
24
|
import eu.etaxonomy.taxeditor.ui.section.campanula.compatibility.ICdmFormElement;
|
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
|
|
39
|
private VersionableEntity entity;
|
40
|
|
41
|
/**
|
42
|
* <p>Constructor for VersionElement.</p>
|
43
|
*
|
44
|
* @param style a int.
|
45
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
46
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
47
|
* @param entity a {@link eu.etaxonomy.cdm.model.common.VersionableEntity} object.
|
48
|
*/
|
49
|
public VersionElement(CdmFormFactory formFactory, ICdmFormElement parentElement, VersionableEntity entity, int style) {
|
50
|
super(formFactory, parentElement);
|
51
|
|
52
|
label_created = formFactory.createLabel(getLayoutComposite(), null, style);
|
53
|
label_created.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
|
54
|
|
55
|
label_updated = formFactory.createLabel(getLayoutComposite(), null, style);
|
56
|
label_updated.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
|
57
|
|
58
|
|
59
|
setEntity(entity);
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* <p>Setter for the field <code>entity</code>.</p>
|
64
|
*
|
65
|
* @param entity a {@link eu.etaxonomy.cdm.model.common.VersionableEntity} object.
|
66
|
*/
|
67
|
public void setEntity(VersionableEntity entity){
|
68
|
|
69
|
this.entity = entity;
|
70
|
|
71
|
String createdString = "";
|
72
|
String updatedString = "";
|
73
|
|
74
|
if(entity != null){
|
75
|
createdString = "Created "
|
76
|
+ dateFormat(entity.getCreated())
|
77
|
+ " by " + userFormat(entity.getCreatedBy());
|
78
|
updatedString = "Updated "
|
79
|
+ dateFormat(entity.getUpdated())
|
80
|
+ " by " + userFormat(entity.getUpdatedBy());
|
81
|
}
|
82
|
|
83
|
label_created.setText(createdString);
|
84
|
label_updated.setText(updatedString);
|
85
|
}
|
86
|
|
87
|
private String dateFormat(DateTime dateTime){
|
88
|
if(dateTime == null){
|
89
|
return "";
|
90
|
}
|
91
|
return CdmUtils.Nz(dateTime.toString(PreferencesUtil.getDateFormatPattern()));
|
92
|
}
|
93
|
|
94
|
private String userFormat(User user){
|
95
|
if(user == null){
|
96
|
return "";
|
97
|
}
|
98
|
// TODO agree on what to display username or real name or even more from shibboleth
|
99
|
return CdmUtils.Nz(user.getUsername());
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* <p>Getter for the field <code>entity</code>.</p>
|
104
|
*
|
105
|
* @return a {@link eu.etaxonomy.cdm.model.common.VersionableEntity} object.
|
106
|
*/
|
107
|
public VersionableEntity getEntity() {
|
108
|
return entity;
|
109
|
}
|
110
|
|
111
|
@Override
|
112
|
public void setSelected(boolean selected) {
|
113
|
// this entity element is not likely to get selected
|
114
|
}
|
115
|
}
|