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