2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.element
;
11 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
12 import org
.eclipse
.swt
.graphics
.Color
;
13 import org
.eclipse
.swt
.widgets
.Label
;
15 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
17 public abstract class TimePeriodElementBase
<T
extends TimePeriod
>
18 extends AbstractRelevanceFormElement
19 implements ISelectable
{
21 protected T timePeriod
;
22 protected Label label
;
23 protected DateDetailSection
<T
> section_dateDetails
;
26 * Constructor for TimePeriodElement.
28 public TimePeriodElementBase(CdmFormFactory formFactory
,
29 ICdmFormElement parentElement
, String labelString
,
30 T timePeriod
, final int style
) {
31 super(formFactory
, parentElement
);
32 label
= formFactory
.createLabel(getLayoutComposite(), labelString
);
36 section_dateDetails
= createDateDetailSection();
37 addControl(section_dateDetails
);
39 setTimePeriod(timePeriod
);
41 formFactory
.addPropertyChangeListener(this);
45 protected abstract DateDetailSection
<T
> createDateDetailSection();
47 public void setEntity(T timePeriod
) {
48 setTimePeriod(timePeriod
);
52 public void propertyChange(PropertyChangeEvent event
) {
56 Object eventSource
= event
.getSource();
58 if (getElements().contains(eventSource
)) {
59 handleEvent(eventSource
);
63 private void handleEvent(Object eventSource
) {
64 if (eventSource
== section_dateDetails
) {
65 timePeriod
= section_dateDetails
.getEntity();
66 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
70 public void setTimePeriod(T timePeriod
) {
71 this.timePeriod
= timePeriod
;
72 if (timePeriod
!= null) {
73 section_dateDetails
.setEntity(timePeriod
);
77 public T
getTimePeriod() {
82 public void setBackground(Color color
) {
83 label
.setBackground(color
);
84 section_dateDetails
.setBackground(color
);
88 public void setSelected(boolean selected
) {
89 setBackground(selected ? SELECTED
: getPersistentBackground());
92 public void setLabel(String string
) {
93 label
.setText(string
);
97 public void updateCacheRelevance() {
98 if (section_dateDetails
!= null){
99 section_dateDetails
.updateCacheRelevance();
104 public void addDependsOnCache(ToggleableTextElement cacheElement
) {
105 if (section_dateDetails
!= null){
106 section_dateDetails
.addDependsOnCache(cacheElement
);