3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.forms
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.events
.SelectionEvent
;
15 import org
.eclipse
.swt
.events
.SelectionListener
;
16 import org
.eclipse
.swt
.graphics
.Color
;
17 import org
.eclipse
.swt
.widgets
.DateTime
;
18 import org
.eclipse
.swt
.widgets
.Label
;
19 import org
.joda
.time
.DateTimeFieldType
;
20 import org
.joda
.time
.Partial
;
22 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
25 * <p>PartialElement class.</p>
28 * @created Mar 31, 2010
31 public class PartialElement
extends AbstractCdmFormElement
implements SelectionListener
{
34 private Partial partial
;
35 private DateTime composite_date
;
38 * <p>Constructor for PartialElement.</p>
40 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
41 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
42 * @param labelString a {@link java.lang.String} object.
45 public PartialElement(CdmFormFactory formFactory
,
46 ICdmFormElement formElement
, String labelString
, int style
) {
47 super(formFactory
, formElement
);
49 formElement
.getLayoutComposite().setLayout(CdmFormFactory
.LAYOUT(7, false));
51 label
= formFactory
.createLabel(getLayoutComposite(), labelString
);
55 composite_date
= new DateTime(getLayoutComposite(), SWT
.BORDER
| SWT
.DATE
| SWT
.DROP_DOWN
);
56 addControl(composite_date
);
57 composite_date
.addSelectionListener(this);
59 formFactory
.addPropertyChangeListener(this);
63 * <p>Setter for the field <code>partial</code>.</p>
65 * @param partial a {@link org.joda.time.Partial} object.
67 public void setPartial(Partial partial
){
68 this.partial
= partial
;
75 year
= partial
.get(DateTimeFieldType
.year());
76 }catch(IllegalArgumentException e
){
80 month
= partial
.get(DateTimeFieldType
.monthOfYear());
81 }catch(IllegalArgumentException e
){
85 day
= partial
.get(DateTimeFieldType
.dayOfMonth());
86 }catch(IllegalArgumentException e
){
91 composite_date
.setDate(year
, month
, day
);
96 * <p>Getter for the field <code>partial</code>.</p>
98 * @return a {@link org.joda.time.Partial} object.
100 public Partial
getPartial(){
105 * @see eu.etaxonomy.taxeditor.forms.ISelectable#setSelected(boolean)
108 public void setSelected(boolean selected
) {
109 setBackground(getColor(selected
));
114 public void setBackground(Color color
) {
115 label
.setBackground(color
);
119 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
122 public void widgetSelected(SelectionEvent e
) {
123 partial
= new Partial()
124 .with(DateTimeFieldType
.year(), composite_date
.getYear())
125 .with(DateTimeFieldType
.monthOfYear(), composite_date
.getMonth())
126 .with(DateTimeFieldType
.dayOfMonth(), composite_date
.getDay());
128 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
132 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
135 public void widgetDefaultSelected(SelectionEvent e
) {}