Project

General

Profile

« Previous | Next » 

Revision 291c69d6

Added by Andreas Müller almost 6 years ago

ref #7421 merged DateDetailSection and VerbatimDateDetailSection and moved verbatim field up

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
1364 1364
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.DateDetailSection}
1365 1365
     *         object.
1366 1366
     */
1367
    public DateDetailSection createDateDetailSection(ICdmFormElement parentElement, int style) {
1368
        DateDetailSection section = new DateDetailSection(this, parentElement, style);
1367
    public DateDetailSection<TimePeriod> createDateDetailSection(ICdmFormElement parentElement, int style) {
1368
        DateDetailSection<TimePeriod> section = new DateDetailSection<TimePeriod>(this, parentElement, false, style);
1369 1369
        parentElement.addElement(section);
1370 1370
        adapt(section);
1371 1371
        return section;
......
1384 1384
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.VerbatimDateDetailSection}
1385 1385
     *         object.
1386 1386
     */
1387
    public VerbatimDateDetailSection createVerbatimDateDetailSection(ICdmFormElement parentElement, int style) {
1388
        VerbatimDateDetailSection section = new VerbatimDateDetailSection(this, parentElement, style);
1387
    public DateDetailSection<VerbatimTimePeriod> createVerbatimDateDetailSection(ICdmFormElement parentElement, int style) {
1388
        DateDetailSection<VerbatimTimePeriod> section 
1389
        	= new DateDetailSection<VerbatimTimePeriod>(this, parentElement, true, style);
1389 1390
        parentElement.addElement(section);
1390 1391
        adapt(section);
1391 1392
        return section;
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/DateDetailSection.java
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.element;
11

  
12
import eu.etaxonomy.cdm.model.common.TimePeriod;
13
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
14

  
15
/**
16
 * <p>
17
 * DateDetailSection class.
18
 * </p>
19
 *
20
 * @author n.hoffmann
21
 * @created Mar 31, 2010
22
 */
23
public class DateDetailSection extends DateDetailSectionBase<TimePeriod> {
24

  
25
	protected DateDetailSection(CdmFormFactory formFactory, 
26
			ICdmFormElement parentElement, int style) {
27
		super(formFactory, parentElement, style);
28
	}
29

  
30
	protected TimePeriod newInstance(){
31
		return TimePeriod.NewInstance();
32
	}
33
	
34
	protected TimePeriod parseNewInstance() {
35
		TimePeriod result = TimePeriodParser.parseString(getText_parseText().getText());
36
		return result;
37
	}
38

  
39
}
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.model.common.VerbatimTimePeriod;
10
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
11

  
12
public class DateDetailSection<T extends TimePeriod> 
13
		extends AbstractFormSection<T> {
14
	protected TextWithLabelElement text_freeText;
15
	private PartialElement partialElement_start;
16
	private PartialElement partialElement_end;
17
	private TextWithLabelElement text_parseText;
18
    private TextWithLabelElement text_VerbatimDate = null;
19
	private int cursorPosition;
20
	private boolean includeVerbatim;
21

  
22
	public int getCursorPosition() {
23
        return cursorPosition;
24
    }
25

  
26
    public void setCursorPosition(int cursorPosition) {
27
        this.cursorPosition = cursorPosition;
28
    }
29

  
30
    /**
31
	 * <p>
32
	 * Constructor for DateDetailSection.
33
	 * </p>
34
	 *
35
	 * @param formFactory
36
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
37
	 *            object.
38
	 * @param parentElement
39
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
40
	 *            object.
41
	 * @param style
42
	 *            a int.
43
	 */
44
	protected DateDetailSection(CdmFormFactory formFactory,
45
			ICdmFormElement parentElement, boolean includeVerbatim, int style) {
46
		super(formFactory, parentElement, style);
47

  
48
		this.includeVerbatim = includeVerbatim;
49
		partialElement_start = formFactory.createPartialElement(this,
50
				"Start ", null, style);
51
		partialElement_end = formFactory.createPartialElement(this, "End ",
52
				null, style);
53
		if (includeVerbatim){
54
	        text_VerbatimDate = formFactory.createTextWithLabelElement(this,
55
	                "Verbatim Date", null, style);
56

  
57
	        text_VerbatimDate.getMainControl().setLayoutData(
58
	                LayoutConstants.FILL_HORIZONTALLY(6, 1));
59
		}
60

  
61
		setText_parseText(formFactory.createTextWithLabelElement(this, "Parse",
62
				null, style));
63
		getText_parseText().getMainControl().setLayoutData(
64
				LayoutConstants.FILL_HORIZONTALLY(6, 1));
65

  
66
		text_freeText = formFactory.createTextWithLabelElement(this,
67
				"Freetext", null, style);
68
		text_freeText.getMainControl().setLayoutData(
69
				LayoutConstants.FILL_HORIZONTALLY(6, 1));
70

  
71

  
72
		formFactory.addPropertyChangeListener(this);
73
	}
74

  
75
	@Override
76
	public final T getEntity() {
77
		if(super.getEntity() == null){
78
			T newInstance = newInstance();
79
			this.setEntity(newInstance);
80
		}
81
		return super.getEntity();
82
	}
83
	
84
	@SuppressWarnings("unchecked")
85
	protected T newInstance(){
86
		if (includeVerbatim){
87
			return (T)VerbatimTimePeriod.NewVerbatimInstance();
88
		}else{
89
			return (T)TimePeriod.NewInstance();
90
		}
91
	}
92
    
93
	@SuppressWarnings("unchecked")
94
	protected T parseNewInstance() {
95
		if (includeVerbatim){
96
			T result = (T)TimePeriodParser.parseStringVerbatim(getText_parseText().getText());
97
			return result;
98
		}else{
99
			T result = (T)TimePeriodParser.parseString(getText_parseText().getText());
100
			return result;
101
		}
102
	}
103
	
104
	
105
	/**
106
	 * <p>
107
	 * Setter for the field <code>timePeriod</code>.
108
	 * </p>
109
	 *
110
	 * @param timePeriod
111
	 *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
112
	 */
113
	@Override
114
	public void setEntity(T timePeriod) {
115
		setEntityInternally(timePeriod);
116
		updateTitle();
117
		getText_parseText().setText(timePeriod.toString());
118
	}
119

  
120
	/**
121
	 * When setting the entity through parsing we do not want to alter the parse field
122
	 * @param timePeriod
123
	 */
124
	protected void setEntityInternally(T timePeriod){
125
		Partial start = timePeriod.getStart();
126
		partialElement_start.setPartial(start);
127
		Partial end = timePeriod.getEnd();
128
		partialElement_end.setPartial(end);
129

  
130
		((Text) getText_parseText().getMainControl()).setSelection(cursorPosition);
131
		text_freeText.setText(timePeriod.getFreeText());
132
		if (includeVerbatim){
133
	        ((Text) text_VerbatimDate.getMainControl()).setSelection(cursorPosition);
134
	        text_VerbatimDate.setText(((VerbatimTimePeriod)timePeriod).getVerbatimDate());
135
		}
136

  
137
		super.setEntity(timePeriod);
138
	}
139

  
140
	/** {@inheritDoc} */
141
	@Override
142
	public void propertyChange(PropertyChangeEvent event) {
143
		if (event == null) {
144
			return;
145
		}
146
		Object eventSource = event.getSource();
147

  
148
		if (getElements().contains(eventSource)) {
149
			if (event instanceof CdmPropertyChangeEvent) {
150
				if (((CdmPropertyChangeEvent) event).hasException()) {
151
					handleException((CdmPropertyChangeEvent) event);
152
					return;
153
				}
154
			}
155
			handleEvent(eventSource);
156
		}
157
	}
158

  
159
	/**
160
	 * @param event
161
	 */
162
	private void handleException(CdmPropertyChangeEvent event) {
163
		firePropertyChangeEvent(new CdmPropertyChangeEvent(this,
164
				event.getException()));
165
	}
166

  
167
	protected void handleEvent(Object eventSource) {
168
		if (eventSource == partialElement_start) {
169
			Partial start = partialElement_start.getPartial();
170
			getEntity().setStart(start);
171
		} else if (eventSource == partialElement_end) {
172
			Partial end = partialElement_end.getPartial();
173
			getEntity().setEnd(end);
174
		} else if (eventSource == getText_parseText()) {
175
			cursorPosition = ((Text) getText_parseText().getMainControl())
176
					.getCaretPosition();
177
			T newInstance = parseNewInstance();
178
			setEntityInternally(newInstance);
179
		} else if (eventSource == text_freeText) {
180
			getEntity().setFreeText(text_freeText.getText());
181
		}else if (eventSource == text_VerbatimDate) {
182
            VerbatimTimePeriod entity = (VerbatimTimePeriod)getEntity();
183
            entity.setVerbatimDate(text_VerbatimDate.getText());
184
        }
185
		updateTitle();
186
		firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
187
	}
188

  
189
//	protected abstract T parseNewInstance() ;
190

  
191
	protected void updateTitle(){
192
		String title = CdmUtils.Nz(getEntity().toString());
193
		this.setText(title);
194
		layout();
195
	}
196

  
197
	/** {@inheritDoc} */
198
	@Override
199
	public void dispose() {
200
		formFactory.removePropertyChangeListener(this);
201
		super.dispose();
202
	}
203

  
204
    public TextWithLabelElement getText_parseText() {
205
        return text_parseText;
206
    }
207

  
208
    public void setText_parseText(TextWithLabelElement text_parseText) {
209
        this.text_parseText = text_parseText;
210
    }
211
}
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 abstract T parseNewInstance() ;
153

  
154
	protected void updateTitle(){
155
		String title = CdmUtils.Nz(getEntity().toString());
156
		this.setText(title);
157
		layout();
158
	}
159

  
160
	/** {@inheritDoc} */
161
	@Override
162
	public void dispose() {
163
		formFactory.removePropertyChangeListener(this);
164
		super.dispose();
165
	}
166

  
167
    public TextWithLabelElement getText_parseText() {
168
        return text_parseText;
169
    }
170

  
171
    public void setText_parseText(TextWithLabelElement text_parseText) {
172
        this.text_parseText = text_parseText;
173
    }
174
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TimePeriodElement.java
31 31
	}
32 32

  
33 33
	@Override
34
	protected DateDetailSectionBase<TimePeriod> createDateDetailSection() {
34
	protected DateDetailSection<TimePeriod> createDateDetailSection() {
35 35
		return formFactory.createDateDetailSection(this,
36 36
				Section.TWISTIE);
37 37
	}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TimePeriodElementBase.java
10 10
public abstract class TimePeriodElementBase<T extends TimePeriod> 
11 11
		extends AbstractCdmFormElement 
12 12
		implements ISelectable {
13

  
14 13
	
15 14
	/**
16 15
	 * <p>
......
34 33
			ICdmFormElement parentElement, String labelString,
35 34
			T timePeriod, final int style) {
36 35
		super(formFactory, parentElement);
37

  
38 36
		label = formFactory.createLabel(getLayoutComposite(), labelString);
39 37

  
40 38
		addControl(label);
......
47 45
		formFactory.addPropertyChangeListener(this);
48 46
	}
49 47

  
50
	protected abstract DateDetailSectionBase<T> createDateDetailSection();
48
	protected abstract DateDetailSection<T> createDateDetailSection();
51 49

  
52 50
	protected T timePeriod;
53 51
	protected Label label;
54
	protected DateDetailSectionBase<T> section_dateDetails;
52
	protected DateDetailSection<T> section_dateDetails;
55 53

  
56 54

  
57 55
	/**
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/VerbatimDateDetailSection.java
1
/**
2
* Copyright (C) 2018 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
package eu.etaxonomy.taxeditor.ui.element;
10

  
11
import org.eclipse.swt.widgets.Text;
12

  
13
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
14
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
15

  
16
/**
17
 * @author k.luther
18
 * @since 15.05.2018
19
 *
20
 */
21
public class VerbatimDateDetailSection extends DateDetailSectionBase<VerbatimTimePeriod> {
22

  
23

  
24
    private final TextWithLabelElement text_VerbatimDate;
25

  
26
    /**
27
     * <p>
28
     * Constructor for DateDetailSection.
29
     * </p>
30
     *
31
     * @param formFactory
32
     *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
33
     *            object.
34
     * @param parentElement
35
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
36
     *            object.
37
     * @param style
38
     *            a int.
39
     */
40
    protected VerbatimDateDetailSection(CdmFormFactory formFactory,
41
            ICdmFormElement parentElement, int style) {
42
        super(formFactory, parentElement, style);
43

  
44
        text_VerbatimDate = formFactory.createTextWithLabelElement(this,
45
                "Verbatim Date", null, style);
46

  
47
        text_VerbatimDate.getMainControl().setLayoutData(
48
                LayoutConstants.FILL_HORIZONTALLY(6, 1));
49

  
50

  
51
        formFactory.addPropertyChangeListener(this);
52
    }
53
    
54
    @Override
55
	protected VerbatimTimePeriod newInstance(){
56
		return VerbatimTimePeriod.NewVerbatimInstance();
57
	}
58
    
59
	protected VerbatimTimePeriod parseNewInstance() {
60
		VerbatimTimePeriod result = TimePeriodParser.parseStringVerbatim(getText_parseText().getText());
61
		return result;
62
	}
63

  
64
    
65
    @Override
66
    protected void handleEvent(Object eventSource) {
67

  
68
        if (eventSource == text_VerbatimDate) {
69
            VerbatimTimePeriod entity = getEntity();
70
            entity.setVerbatimDate(text_VerbatimDate.getText());
71
        }
72
        super.handleEvent(eventSource);
73

  
74
    }
75

  
76
    /**
77
     * When setting the entity through parsing we do not want to alter the parse field
78
     * @param timePeriod
79
     */
80
    @Override
81
    protected void setEntityInternally(VerbatimTimePeriod timePeriod){
82
        super.setEntityInternally(timePeriod);
83
        ((Text) text_VerbatimDate.getMainControl()).setSelection(super.getCursorPosition());
84
        text_VerbatimDate.setText(timePeriod.getVerbatimDate());
85
    }
86

  
87
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/VerbatimTimePeriodElement.java
27 27
	}
28 28

  
29 29
	@Override
30
	protected DateDetailSectionBase<VerbatimTimePeriod> createDateDetailSection() {
30
	protected DateDetailSection<VerbatimTimePeriod> createDateDetailSection() {
31 31
		return formFactory.createVerbatimDateDetailSection(this,
32 32
				Section.TWISTIE);
33 33
	}

Also available in: Unified diff