Revision 943d4d5e
Added by Andreas Müller almost 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java | ||
---|---|---|
1247 | 1247 |
* @return a {@link eu.etaxonomy.taxeditor.ui.element.TimePeriodElement} |
1248 | 1248 |
* object. |
1249 | 1249 |
*/ |
1250 |
public TimePeriodElement createTimePeriodElement(ICdmFormElement parentElement, String labelString, |
|
1250 |
public TimePeriodElement<TimePeriod> createTimePeriodElement(ICdmFormElement parentElement, String labelString,
|
|
1251 | 1251 |
TimePeriod timePeriod, int style) { |
1252 |
TimePeriodElement element = new TimePeriodElement(this, parentElement, labelString, timePeriod, style);
|
|
1252 |
TimePeriodElement<TimePeriod> element = new TimePeriodElement<TimePeriod>(this, parentElement, labelString, timePeriod, style);
|
|
1253 | 1253 |
adapt(element); |
1254 | 1254 |
parentElement.addElement(element); |
1255 | 1255 |
return element; |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/DateDetailSection.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.ui.element; |
11 | 11 |
|
12 |
import org.eclipse.jface.util.PropertyChangeEvent; |
|
13 |
import org.eclipse.swt.widgets.Text; |
|
14 |
import org.joda.time.Partial; |
|
15 |
|
|
16 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
17 | 12 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
18 |
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser; |
|
19 | 13 |
|
20 | 14 |
/** |
21 | 15 |
* <p> |
... | ... | |
24 | 18 |
* |
25 | 19 |
* @author n.hoffmann |
26 | 20 |
* @created Mar 31, 2010 |
27 |
* @version 1.0 |
|
28 | 21 |
*/ |
29 |
public class DateDetailSection extends AbstractFormSection<TimePeriod> { |
|
30 |
|
|
31 |
protected TextWithLabelElement text_freeText; |
|
32 |
private PartialElement partialElement_start; |
|
33 |
private PartialElement partialElement_end; |
|
34 |
private TextWithLabelElement text_parseText; |
|
35 |
private int cursorPosition; |
|
36 |
|
|
37 |
public int getCursorPosition() { |
|
38 |
return cursorPosition; |
|
39 |
} |
|
40 |
|
|
41 |
public void setCursorPosition(int cursorPosition) { |
|
42 |
this.cursorPosition = cursorPosition; |
|
43 |
} |
|
22 |
public class DateDetailSection extends DateDetailSectionBase<TimePeriod> { |
|
44 | 23 |
|
45 |
/** |
|
46 |
* <p> |
|
47 |
* Constructor for DateDetailSection. |
|
48 |
* </p> |
|
49 |
* |
|
50 |
* @param formFactory |
|
51 |
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} |
|
52 |
* object. |
|
53 |
* @param parentElement |
|
54 |
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} |
|
55 |
* object. |
|
56 |
* @param style |
|
57 |
* a int. |
|
58 |
*/ |
|
59 |
protected DateDetailSection(CdmFormFactory formFactory, |
|
24 |
protected DateDetailSection(CdmFormFactory formFactory, |
|
60 | 25 |
ICdmFormElement parentElement, int style) { |
61 | 26 |
super(formFactory, parentElement, style); |
62 |
|
|
63 |
partialElement_start = formFactory.createPartialElement(this, |
|
64 |
"Start ", null, style); |
|
65 |
partialElement_end = formFactory.createPartialElement(this, "End ", |
|
66 |
null, style); |
|
67 |
|
|
68 |
setText_parseText(formFactory.createTextWithLabelElement(this, "Parse", |
|
69 |
null, style)); |
|
70 |
getText_parseText().getMainControl().setLayoutData( |
|
71 |
LayoutConstants.FILL_HORIZONTALLY(6, 1)); |
|
72 |
|
|
73 |
text_freeText = formFactory.createTextWithLabelElement(this, |
|
74 |
"Freetext", null, style); |
|
75 |
text_freeText.getMainControl().setLayoutData( |
|
76 |
LayoutConstants.FILL_HORIZONTALLY(6, 1)); |
|
77 |
|
|
78 |
|
|
79 |
formFactory.addPropertyChangeListener(this); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public TimePeriod getEntity() { |
|
84 |
if(super.getEntity() == null){ |
|
85 |
setEntity(TimePeriod.NewInstance()); |
|
86 |
} |
|
87 |
return super.getEntity(); |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* <p> |
|
92 |
* Setter for the field <code>timePeriod</code>. |
|
93 |
* </p> |
|
94 |
* |
|
95 |
* @param timePeriod |
|
96 |
* a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object. |
|
97 |
*/ |
|
98 |
@Override |
|
99 |
public void setEntity(TimePeriod timePeriod) { |
|
100 |
setEntityInternally(timePeriod); |
|
101 |
updateTitle(); |
|
102 |
getText_parseText().setText(timePeriod.toString()); |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* When setting the entity through parsing we do not want to alter the parse field |
|
107 |
* @param timePeriod |
|
108 |
*/ |
|
109 |
protected void setEntityInternally(TimePeriod timePeriod){ |
|
110 |
Partial start = timePeriod.getStart(); |
|
111 |
partialElement_start.setPartial(start); |
|
112 |
Partial end = timePeriod.getEnd(); |
|
113 |
partialElement_end.setPartial(end); |
|
114 |
|
|
115 |
((Text) getText_parseText().getMainControl()).setSelection(cursorPosition); |
|
116 |
text_freeText.setText(timePeriod.getFreeText()); |
|
117 |
|
|
118 |
super.setEntity(timePeriod); |
|
119 |
} |
|
120 |
|
|
121 |
/** {@inheritDoc} */ |
|
122 |
@Override |
|
123 |
public void propertyChange(PropertyChangeEvent event) { |
|
124 |
if (event == null) { |
|
125 |
return; |
|
126 |
} |
|
127 |
Object eventSource = event.getSource(); |
|
128 |
|
|
129 |
if (getElements().contains(eventSource)) { |
|
130 |
if (event instanceof CdmPropertyChangeEvent) { |
|
131 |
if (((CdmPropertyChangeEvent) event).hasException()) { |
|
132 |
handleException((CdmPropertyChangeEvent) event); |
|
133 |
return; |
|
134 |
} |
|
135 |
} |
|
136 |
handleEvent(eventSource); |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* @param event |
|
142 |
*/ |
|
143 |
private void handleException(CdmPropertyChangeEvent event) { |
|
144 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, |
|
145 |
event.getException())); |
|
146 |
} |
|
147 |
|
|
148 |
protected void handleEvent(Object eventSource) { |
|
149 |
if (eventSource == partialElement_start) { |
|
150 |
Partial start = partialElement_start.getPartial(); |
|
151 |
getEntity().setStart(start); |
|
152 |
} else if (eventSource == partialElement_end) { |
|
153 |
Partial end = partialElement_end.getPartial(); |
|
154 |
getEntity().setEnd(end); |
|
155 |
} else if (eventSource == getText_parseText()) { |
|
156 |
cursorPosition = ((Text) getText_parseText().getMainControl()) |
|
157 |
.getCaretPosition(); |
|
158 |
setEntityInternally(TimePeriodParser.parseString(getText_parseText().getText())); |
|
159 |
} else if (eventSource == text_freeText) { |
|
160 |
getEntity().setFreeText(text_freeText.getText()); |
|
161 |
} |
|
162 |
updateTitle(); |
|
163 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null)); |
|
164 | 27 |
} |
165 | 28 |
|
166 |
protected void updateTitle(){ |
|
167 |
String title = CdmUtils.Nz(getEntity().toString()); |
|
168 |
this.setText(title); |
|
169 |
layout(); |
|
29 |
protected TimePeriod newInstance(){ |
|
30 |
return TimePeriod.NewInstance(); |
|
170 | 31 |
} |
171 | 32 |
|
172 |
/* |
|
173 |
* (non-Javadoc) |
|
174 |
* |
|
175 |
* @see eu.etaxonomy.taxeditor.forms.AbstractFormSection#dispose() |
|
176 |
*/ |
|
177 |
/** {@inheritDoc} */ |
|
178 |
@Override |
|
179 |
public void dispose() { |
|
180 |
formFactory.removePropertyChangeListener(this); |
|
181 |
super.dispose(); |
|
182 |
} |
|
183 |
|
|
184 |
public TextWithLabelElement getText_parseText() { |
|
185 |
return text_parseText; |
|
186 |
} |
|
187 |
|
|
188 |
public void setText_parseText(TextWithLabelElement text_parseText) { |
|
189 |
this.text_parseText = text_parseText; |
|
190 |
} |
|
191 |
|
|
192 | 33 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/DateDetailSectionBase.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.ui.element; |
|
2 |
|
|
3 |
import org.eclipse.jface.util.PropertyChangeEvent; |
|
4 |
import org.eclipse.swt.widgets.Text; |
|
5 |
import org.joda.time.Partial; |
|
6 |
|
|
7 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
8 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
|
9 |
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser; |
|
10 |
|
|
11 |
public abstract class DateDetailSectionBase<T extends TimePeriod> |
|
12 |
extends AbstractFormSection<T> { |
|
13 |
protected TextWithLabelElement text_freeText; |
|
14 |
private PartialElement partialElement_start; |
|
15 |
private PartialElement partialElement_end; |
|
16 |
private TextWithLabelElement text_parseText; |
|
17 |
private int cursorPosition; |
|
18 |
|
|
19 |
public int getCursorPosition() { |
|
20 |
return cursorPosition; |
|
21 |
} |
|
22 |
|
|
23 |
public void setCursorPosition(int cursorPosition) { |
|
24 |
this.cursorPosition = cursorPosition; |
|
25 |
} |
|
26 |
|
|
27 |
/** |
|
28 |
* <p> |
|
29 |
* Constructor for DateDetailSection. |
|
30 |
* </p> |
|
31 |
* |
|
32 |
* @param formFactory |
|
33 |
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} |
|
34 |
* object. |
|
35 |
* @param parentElement |
|
36 |
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} |
|
37 |
* object. |
|
38 |
* @param style |
|
39 |
* a int. |
|
40 |
*/ |
|
41 |
protected DateDetailSectionBase(CdmFormFactory formFactory, |
|
42 |
ICdmFormElement parentElement, int style) { |
|
43 |
super(formFactory, parentElement, style); |
|
44 |
|
|
45 |
partialElement_start = formFactory.createPartialElement(this, |
|
46 |
"Start ", null, style); |
|
47 |
partialElement_end = formFactory.createPartialElement(this, "End ", |
|
48 |
null, style); |
|
49 |
|
|
50 |
setText_parseText(formFactory.createTextWithLabelElement(this, "Parse", |
|
51 |
null, style)); |
|
52 |
getText_parseText().getMainControl().setLayoutData( |
|
53 |
LayoutConstants.FILL_HORIZONTALLY(6, 1)); |
|
54 |
|
|
55 |
text_freeText = formFactory.createTextWithLabelElement(this, |
|
56 |
"Freetext", null, style); |
|
57 |
text_freeText.getMainControl().setLayoutData( |
|
58 |
LayoutConstants.FILL_HORIZONTALLY(6, 1)); |
|
59 |
|
|
60 |
|
|
61 |
formFactory.addPropertyChangeListener(this); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public final T getEntity() { |
|
66 |
if(super.getEntity() == null){ |
|
67 |
T newInstance = newInstance(); |
|
68 |
this.setEntity(newInstance); |
|
69 |
} |
|
70 |
return super.getEntity(); |
|
71 |
} |
|
72 |
|
|
73 |
protected abstract T newInstance(); |
|
74 |
|
|
75 |
/** |
|
76 |
* <p> |
|
77 |
* Setter for the field <code>timePeriod</code>. |
|
78 |
* </p> |
|
79 |
* |
|
80 |
* @param timePeriod |
|
81 |
* a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object. |
|
82 |
*/ |
|
83 |
@Override |
|
84 |
public void setEntity(T timePeriod) { |
|
85 |
setEntityInternally(timePeriod); |
|
86 |
updateTitle(); |
|
87 |
getText_parseText().setText(timePeriod.toString()); |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* When setting the entity through parsing we do not want to alter the parse field |
|
92 |
* @param timePeriod |
|
93 |
*/ |
|
94 |
protected void setEntityInternally(T timePeriod){ |
|
95 |
Partial start = timePeriod.getStart(); |
|
96 |
partialElement_start.setPartial(start); |
|
97 |
Partial end = timePeriod.getEnd(); |
|
98 |
partialElement_end.setPartial(end); |
|
99 |
|
|
100 |
((Text) getText_parseText().getMainControl()).setSelection(cursorPosition); |
|
101 |
text_freeText.setText(timePeriod.getFreeText()); |
|
102 |
|
|
103 |
super.setEntity(timePeriod); |
|
104 |
} |
|
105 |
|
|
106 |
/** {@inheritDoc} */ |
|
107 |
@Override |
|
108 |
public void propertyChange(PropertyChangeEvent event) { |
|
109 |
if (event == null) { |
|
110 |
return; |
|
111 |
} |
|
112 |
Object eventSource = event.getSource(); |
|
113 |
|
|
114 |
if (getElements().contains(eventSource)) { |
|
115 |
if (event instanceof CdmPropertyChangeEvent) { |
|
116 |
if (((CdmPropertyChangeEvent) event).hasException()) { |
|
117 |
handleException((CdmPropertyChangeEvent) event); |
|
118 |
return; |
|
119 |
} |
|
120 |
} |
|
121 |
handleEvent(eventSource); |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* @param event |
|
127 |
*/ |
|
128 |
private void handleException(CdmPropertyChangeEvent event) { |
|
129 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, |
|
130 |
event.getException())); |
|
131 |
} |
|
132 |
|
|
133 |
protected void handleEvent(Object eventSource) { |
|
134 |
if (eventSource == partialElement_start) { |
|
135 |
Partial start = partialElement_start.getPartial(); |
|
136 |
getEntity().setStart(start); |
|
137 |
} else if (eventSource == partialElement_end) { |
|
138 |
Partial end = partialElement_end.getPartial(); |
|
139 |
getEntity().setEnd(end); |
|
140 |
} else if (eventSource == getText_parseText()) { |
|
141 |
cursorPosition = ((Text) getText_parseText().getMainControl()) |
|
142 |
.getCaretPosition(); |
|
143 |
T newInstance = parseNewInstance(); |
|
144 |
setEntityInternally(newInstance); |
|
145 |
} else if (eventSource == text_freeText) { |
|
146 |
getEntity().setFreeText(text_freeText.getText()); |
|
147 |
} |
|
148 |
updateTitle(); |
|
149 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null)); |
|
150 |
} |
|
151 |
|
|
152 |
protected T parseNewInstance() { |
|
153 |
@SuppressWarnings("unchecked") |
|
154 |
T result = (T)TimePeriodParser.parseString(getText_parseText().getText()); |
|
155 |
return result; |
|
156 |
} |
|
157 |
|
|
158 |
protected void updateTitle(){ |
|
159 |
String title = CdmUtils.Nz(getEntity().toString()); |
|
160 |
this.setText(title); |
|
161 |
layout(); |
|
162 |
} |
|
163 |
|
|
164 |
/** {@inheritDoc} */ |
|
165 |
@Override |
|
166 |
public void dispose() { |
|
167 |
formFactory.removePropertyChangeListener(this); |
|
168 |
super.dispose(); |
|
169 |
} |
|
170 |
|
|
171 |
public TextWithLabelElement getText_parseText() { |
|
172 |
return text_parseText; |
|
173 |
} |
|
174 |
|
|
175 |
public void setText_parseText(TextWithLabelElement text_parseText) { |
|
176 |
this.text_parseText = text_parseText; |
|
177 |
} |
|
178 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TimePeriodElement.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.ui.element; |
11 | 11 |
|
12 |
import org.eclipse.jface.util.PropertyChangeEvent; |
|
13 |
import org.eclipse.swt.graphics.Color; |
|
14 |
import org.eclipse.swt.widgets.Label; |
|
15 | 12 |
import org.eclipse.ui.forms.widgets.Section; |
16 | 13 |
|
17 | 14 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
... | ... | |
23 | 20 |
* |
24 | 21 |
* @author n.hoffmann |
25 | 22 |
* @created Nov 17, 2009 |
26 |
* @version 1.0 |
|
27 | 23 |
*/ |
28 |
public class TimePeriodElement extends AbstractCdmFormElement implements ISelectable { |
|
24 |
public class TimePeriodElement<T extends TimePeriod> |
|
25 |
extends TimePeriodElementBase<TimePeriod> { |
|
29 | 26 |
|
30 |
protected TimePeriod timePeriod; |
|
31 |
protected Label label; |
|
32 |
protected DateDetailSection section_dateDetails; |
|
33 |
|
|
34 |
/** |
|
35 |
* <p> |
|
36 |
* Constructor for TimePeriodElement. |
|
37 |
* </p> |
|
38 |
* |
|
39 |
* @param style |
|
40 |
* a int. |
|
41 |
* @param formFactory |
|
42 |
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} |
|
43 |
* object. |
|
44 |
* @param parentElement |
|
45 |
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} |
|
46 |
* object. |
|
47 |
* @param labelString |
|
48 |
* a {@link java.lang.String} object. |
|
49 |
* @param timePeriod |
|
50 |
* a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object. |
|
51 |
*/ |
|
52 |
public TimePeriodElement(CdmFormFactory formFactory, |
|
53 |
ICdmFormElement parentElement, String labelString, |
|
54 |
TimePeriod timePeriod, final int style) { |
|
55 |
super(formFactory, parentElement); |
|
56 |
|
|
57 |
label = formFactory.createLabel(getLayoutComposite(), labelString); |
|
58 |
|
|
59 |
addControl(label); |
|
60 |
|
|
61 |
section_dateDetails = formFactory.createDateDetailSection(this, |
|
62 |
Section.TWISTIE); |
|
63 |
addControl(section_dateDetails); |
|
64 |
|
|
65 |
setTimePeriod(timePeriod); |
|
66 |
|
|
67 |
formFactory.addPropertyChangeListener(this); |
|
27 |
|
|
28 |
public TimePeriodElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString, |
|
29 |
TimePeriod timePeriod, int style) { |
|
30 |
super(formFactory, parentElement, labelString, timePeriod, style); |
|
68 | 31 |
} |
69 | 32 |
|
70 |
/** |
|
71 |
* <p> |
|
72 |
* Constructor for TimePeriodElement. |
|
73 |
* </p> |
|
74 |
* |
|
75 |
* @param formFactory |
|
76 |
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} |
|
77 |
* object. |
|
78 |
* @param parentElement |
|
79 |
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} |
|
80 |
* object. |
|
81 |
*/ |
|
82 |
public TimePeriodElement(CdmFormFactory formFactory, |
|
83 |
ICdmFormElement parentElement) { |
|
84 |
super(formFactory, parentElement); |
|
85 |
} |
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
/** |
|
91 |
* <p> |
|
92 |
* setEntity |
|
93 |
* </p> |
|
94 |
* |
|
95 |
* @param timePeriod |
|
96 |
* a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object. |
|
97 |
*/ |
|
98 |
public void setEntity(TimePeriod timePeriod) { |
|
99 |
setTimePeriod(timePeriod); |
|
100 |
} |
|
101 |
|
|
102 |
/** {@inheritDoc} */ |
|
103 | 33 |
@Override |
104 |
public void propertyChange(PropertyChangeEvent event) { |
|
105 |
if (event == null) { |
|
106 |
return; |
|
107 |
} |
|
108 |
Object eventSource = event.getSource(); |
|
109 |
|
|
110 |
if (getElements().contains(eventSource)) { |
|
111 |
handleEvent(eventSource); |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
private void handleEvent(Object eventSource) { |
|
116 |
if (eventSource == section_dateDetails) { |
|
117 |
timePeriod = section_dateDetails.getEntity(); |
|
118 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null)); |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* <p> |
|
124 |
* Setter for the field <code>timePeriod</code>. |
|
125 |
* </p> |
|
126 |
* |
|
127 |
* @param timePeriod |
|
128 |
* the timePeriod to set |
|
129 |
*/ |
|
130 |
public void setTimePeriod(TimePeriod timePeriod) { |
|
131 |
this.timePeriod = timePeriod; |
|
132 |
if (timePeriod != null) { |
|
133 |
section_dateDetails.setEntity(timePeriod); |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* <p> |
|
139 |
* Getter for the field <code>timePeriod</code>. |
|
140 |
* </p> |
|
141 |
* |
|
142 |
* @return the timePeriod |
|
143 |
*/ |
|
144 |
public TimePeriod getTimePeriod() { |
|
145 |
return timePeriod; |
|
146 |
} |
|
147 |
|
|
148 |
/** {@inheritDoc} */ |
|
149 |
@Override |
|
150 |
public void setBackground(Color color) { |
|
151 |
label.setBackground(color); |
|
152 |
section_dateDetails.setBackground(color); |
|
34 |
protected DateDetailSectionBase<TimePeriod> createDateDetailSection() { |
|
35 |
return formFactory.createDateDetailSection(this, |
|
36 |
Section.TWISTIE); |
|
153 | 37 |
} |
154 | 38 |
|
155 |
@Override |
|
156 |
public void setSelected(boolean selected) { |
|
157 |
setBackground(selected ? SELECTED : getPersistentBackground()); |
|
158 |
} |
|
159 | 39 |
|
160 |
public void setLabel(String string) { |
|
161 |
label.setText(string); |
|
162 |
} |
|
163 | 40 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TimePeriodElementBase.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.ui.element; |
|
2 |
|
|
3 |
import org.eclipse.jface.util.PropertyChangeEvent; |
|
4 |
import org.eclipse.swt.graphics.Color; |
|
5 |
import org.eclipse.swt.widgets.Label; |
|
6 |
|
|
7 |
|
|
8 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
|
9 |
|
|
10 |
public abstract class TimePeriodElementBase<T extends TimePeriod> |
|
11 |
extends AbstractCdmFormElement |
|
12 |
implements ISelectable { |
|
13 |
|
|
14 |
|
|
15 |
/** |
|
16 |
* <p> |
|
17 |
* Constructor for TimePeriodElement. |
|
18 |
* </p> |
|
19 |
* |
|
20 |
* @param style |
|
21 |
* a int. |
|
22 |
* @param formFactory |
|
23 |
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} |
|
24 |
* object. |
|
25 |
* @param parentElement |
|
26 |
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} |
|
27 |
* object. |
|
28 |
* @param labelString |
|
29 |
* a {@link java.lang.String} object. |
|
30 |
* @param timePeriod |
|
31 |
* a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object. |
|
32 |
*/ |
|
33 |
public TimePeriodElementBase(CdmFormFactory formFactory, |
|
34 |
ICdmFormElement parentElement, String labelString, |
|
35 |
T timePeriod, final int style) { |
|
36 |
super(formFactory, parentElement); |
|
37 |
|
|
38 |
label = formFactory.createLabel(getLayoutComposite(), labelString); |
|
39 |
|
|
40 |
addControl(label); |
|
41 |
|
|
42 |
section_dateDetails = createDateDetailSection(); |
|
43 |
addControl(section_dateDetails); |
|
44 |
|
|
45 |
setTimePeriod(timePeriod); |
|
46 |
|
|
47 |
formFactory.addPropertyChangeListener(this); |
|
48 |
} |
|
49 |
|
|
50 |
protected abstract DateDetailSectionBase<T> createDateDetailSection(); |
|
51 |
|
|
52 |
protected T timePeriod; |
|
53 |
protected Label label; |
|
54 |
protected DateDetailSectionBase<T> section_dateDetails; |
|
55 |
|
|
56 |
|
|
57 |
/** |
|
58 |
* <p> |
|
59 |
* setEntity |
|
60 |
* </p> |
|
61 |
* |
|
62 |
* @param timePeriod |
|
63 |
* a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object. |
|
64 |
*/ |
|
65 |
public void setEntity(T timePeriod) { |
|
66 |
setTimePeriod(timePeriod); |
|
67 |
} |
|
68 |
|
|
69 |
/** {@inheritDoc} */ |
|
70 |
@Override |
|
71 |
public void propertyChange(PropertyChangeEvent event) { |
|
72 |
if (event == null) { |
|
73 |
return; |
|
74 |
} |
|
75 |
Object eventSource = event.getSource(); |
|
76 |
|
|
77 |
if (getElements().contains(eventSource)) { |
|
78 |
handleEvent(eventSource); |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
private void handleEvent(Object eventSource) { |
|
83 |
if (eventSource == section_dateDetails) { |
|
84 |
timePeriod = section_dateDetails.getEntity(); |
|
85 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null)); |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* <p> |
|
91 |
* Setter for the field <code>timePeriod</code>. |
|
92 |
* </p> |
|
93 |
* |
|
94 |
* @param timePeriod |
|
95 |
* the timePeriod to set |
|
96 |
*/ |
|
97 |
public void setTimePeriod(T timePeriod) { |
|
98 |
this.timePeriod = timePeriod; |
|
99 |
if (timePeriod != null) { |
|
100 |
section_dateDetails.setEntity(timePeriod); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* <p> |
|
106 |
* Getter for the field <code>timePeriod</code>. |
|
107 |
* </p> |
|
108 |
* |
|
109 |
* @return the timePeriod |
|
110 |
*/ |
|
111 |
public T getTimePeriod() { |
|
112 |
return timePeriod; |
|
113 |
} |
|
114 |
|
|
115 |
/** {@inheritDoc} */ |
|
116 |
@Override |
|
117 |
public void setBackground(Color color) { |
|
118 |
label.setBackground(color); |
|
119 |
section_dateDetails.setBackground(color); |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public void setSelected(boolean selected) { |
|
124 |
setBackground(selected ? SELECTED : getPersistentBackground()); |
|
125 |
} |
|
126 |
|
|
127 |
public void setLabel(String string) { |
|
128 |
label.setText(string); |
|
129 |
} |
|
130 |
|
|
131 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/VerbatimDateDetailSection.java | ||
---|---|---|
18 | 18 |
* @since 15.05.2018 |
19 | 19 |
* |
20 | 20 |
*/ |
21 |
public class VerbatimDateDetailSection extends DateDetailSection { |
|
21 |
public class VerbatimDateDetailSection extends DateDetailSectionBase<VerbatimTimePeriod> {
|
|
22 | 22 |
|
23 | 23 |
|
24 | 24 |
private final TextWithLabelElement text_VerbatimDate; |
... | ... | |
50 | 50 |
|
51 | 51 |
formFactory.addPropertyChangeListener(this); |
52 | 52 |
} |
53 |
|
|
54 |
@Override |
|
55 |
protected VerbatimTimePeriod newInstance(){ |
|
56 |
return VerbatimTimePeriod.NewVerbatimInstance(); |
|
57 |
} |
|
53 | 58 |
|
54 | 59 |
|
55 | 60 |
/** |
... | ... | |
67 | 72 |
getText_parseText().setText(timePeriod.toString()); |
68 | 73 |
|
69 | 74 |
} |
75 |
|
|
70 | 76 |
@Override |
71 | 77 |
protected void handleEvent(Object eventSource) { |
72 | 78 |
|
... | ... | |
81 | 87 |
newEntity.setFreeText(entity.getFreeText()); |
82 | 88 |
newEntity.setVerbatimDate(text_VerbatimDate.getText()); |
83 | 89 |
setEntity(newEntity); |
84 |
|
|
85 | 90 |
} |
86 | 91 |
} |
87 | 92 |
super.handleEvent(eventSource); |
88 | 93 |
|
89 | 94 |
} |
90 | 95 |
|
91 |
@Override |
|
92 |
public TimePeriod getEntity() { |
|
93 |
if(super.getEntity() == null){ |
|
94 |
setEntity(VerbatimTimePeriod.NewVerbatimInstance()); |
|
95 |
} |
|
96 |
return super.getEntity(); |
|
97 |
} |
|
98 |
|
|
99 | 96 |
/** |
100 | 97 |
* When setting the entity through parsing we do not want to alter the parse field |
101 | 98 |
* @param timePeriod |
102 | 99 |
*/ |
103 |
|
|
104 |
private void setEntityInternally(VerbatimTimePeriod timePeriod){
|
|
100 |
@Override |
|
101 |
protected void setEntityInternally(VerbatimTimePeriod timePeriod){
|
|
105 | 102 |
super.setEntityInternally(timePeriod); |
106 | 103 |
((Text) text_VerbatimDate.getMainControl()).setSelection(super.getCursorPosition()); |
107 | 104 |
text_VerbatimDate.setText(timePeriod.getVerbatimDate()); |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/VerbatimTimePeriodElement.java | ||
---|---|---|
18 | 18 |
* @since 15.05.2018 |
19 | 19 |
* |
20 | 20 |
*/ |
21 |
public class VerbatimTimePeriodElement extends TimePeriodElement { |
|
21 |
public class VerbatimTimePeriodElement |
|
22 |
extends TimePeriodElementBase<VerbatimTimePeriod> { |
|
22 | 23 |
|
24 |
|
|
25 |
public VerbatimTimePeriodElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString, |
|
26 |
VerbatimTimePeriod timePeriod, int style) { |
|
27 |
super(formFactory, parentElement, labelString, timePeriod, style); |
|
28 |
} |
|
23 | 29 |
|
24 |
|
|
25 |
/** |
|
26 |
* <p> |
|
27 |
* Constructor for TimePeriodElement. |
|
28 |
* </p> |
|
29 |
* |
|
30 |
* @param style |
|
31 |
* a int. |
|
32 |
* @param formFactory |
|
33 |
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} |
|
34 |
* object. |
|
35 |
* @param parentElement |
|
36 |
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} |
|
37 |
* object. |
|
38 |
* @param labelString |
|
39 |
* a {@link java.lang.String} object. |
|
40 |
* @param timePeriod |
|
41 |
* a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object. |
|
42 |
*/ |
|
43 |
public VerbatimTimePeriodElement(CdmFormFactory formFactory, |
|
44 |
ICdmFormElement parentElement, String labelString, |
|
45 |
VerbatimTimePeriod timePeriod, final int style) { |
|
46 |
super(formFactory, parentElement); |
|
47 |
|
|
48 |
label = formFactory.createLabel(getLayoutComposite(), labelString); |
|
49 |
|
|
50 |
addControl(label); |
|
51 |
|
|
52 |
section_dateDetails = formFactory.createVerbatimDateDetailSection(this, |
|
53 |
Section.TWISTIE); |
|
54 |
addControl(section_dateDetails); |
|
55 |
|
|
56 |
setTimePeriod(timePeriod); |
|
57 |
|
|
58 |
formFactory.addPropertyChangeListener(this); |
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
} |
|
30 |
@Override |
|
31 |
protected DateDetailSectionBase<VerbatimTimePeriod> createDateDetailSection() { |
|
32 |
return formFactory.createVerbatimDateDetailSection(this, |
|
33 |
Section.TWISTIE); |
|
34 |
} |
|
63 | 35 |
|
64 | 36 |
/** |
65 | 37 |
* <p> |
... | ... | |
70 | 42 |
* the timePeriod to set |
71 | 43 |
*/ |
72 | 44 |
@Override |
73 |
public void setTimePeriod(TimePeriod timePeriod) { |
|
45 |
public void setTimePeriod(VerbatimTimePeriod timePeriod) {
|
|
74 | 46 |
super.setTimePeriod(timePeriod); |
75 |
|
|
76 | 47 |
} |
77 | 48 |
|
78 | 49 |
|
Also available in: Unified diff
ref #7421 refactor verbatim date sections and elements