Revision 97623d1d
Added by Katja Luther almost 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java | ||
---|---|---|
40 | 40 |
import org.eclipse.ui.forms.widgets.ExpandableComposite; |
41 | 41 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
42 | 42 |
import org.eclipse.ui.forms.widgets.Section; |
43 |
import org.eclipse.ui.forms.widgets.TableWrapData; |
|
43 | 44 |
import org.eclipse.ui.internal.forms.widgets.FormFonts; |
44 | 45 |
import org.joda.time.DateTime; |
45 | 46 |
import org.joda.time.Partial; |
... | ... | |
2892 | 2893 |
// return dateElement; |
2893 | 2894 |
// } |
2894 | 2895 |
|
2895 |
public DateElement createDateElement(ICdmFormElement formElement, String labelText, DateTime dateTime, int style){ |
|
2896 |
public DateElement createDateElement(ICdmFormElement formElement, String labelText, DateTime dateTime, int style, boolean editableText){
|
|
2896 | 2897 |
Label label = new Label(formElement.getLayoutComposite(), style); |
2897 |
label.setText(labelText+" (yyyy-MM-dd)"); |
|
2898 |
DateElement dateElement = new DateElement(formElement.getLayoutComposite(), dateTime, style); |
|
2898 |
label.setText(labelText); |
|
2899 |
label.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE, 1, 1)); |
|
2900 |
DateElement dateElement = new DateElement(formElement.getLayoutComposite(), dateTime, style, editableText); |
|
2899 | 2901 |
dateElement.initController(this, formElement); |
2900 | 2902 |
return dateElement; |
2901 | 2903 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/element/DateElement.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.taxeditor.ui.mvc.element; |
10 | 10 |
|
11 | 11 |
|
12 |
import java.awt.FontMetrics; |
|
12 | 13 |
import java.util.Calendar; |
13 | 14 |
import java.util.ConcurrentModificationException; |
14 | 15 |
import java.util.List; |
15 | 16 |
|
16 | 17 |
import org.eclipse.core.runtime.Assert; |
17 | 18 |
import org.eclipse.jface.util.IPropertyChangeListener; |
19 |
import org.eclipse.jface.viewers.CellEditor.LayoutData; |
|
18 | 20 |
import org.eclipse.swt.SWT; |
19 | 21 |
import org.eclipse.swt.events.DisposeEvent; |
20 | 22 |
import org.eclipse.swt.events.DisposeListener; |
21 | 23 |
import org.eclipse.swt.events.SelectionAdapter; |
22 | 24 |
import org.eclipse.swt.events.SelectionEvent; |
25 |
import org.eclipse.swt.graphics.GC; |
|
23 | 26 |
import org.eclipse.swt.graphics.Image; |
24 | 27 |
import org.eclipse.swt.layout.GridData; |
25 | 28 |
import org.eclipse.swt.layout.GridLayout; |
... | ... | |
35 | 38 |
import org.eclipse.ui.forms.widgets.TableWrapLayout; |
36 | 39 |
//import org.joda.time.DateTime; |
37 | 40 |
|
41 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
|
38 | 42 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
39 | 43 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
40 | 44 |
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent; |
... | ... | |
52 | 56 |
private final FormToolkit toolkit = new FormToolkit(Display.getCurrent()); |
53 | 57 |
private org.joda.time.DateTime initialDateTime; |
54 | 58 |
private Text textDate; |
55 |
// private final Button openDateDialog; |
|
59 |
private final Button openDateDialog; |
|
60 |
|
|
61 |
private static final String pattern = "yyyy-MM-dd HH:mm:ss"; |
|
56 | 62 |
|
57 | 63 |
|
58 | 64 |
/** |
... | ... | |
60 | 66 |
* @param parent |
61 | 67 |
* @param style |
62 | 68 |
*/ |
63 |
public DateElement(Composite parent, org.joda.time.DateTime initialDateTime, int style) { |
|
69 |
public DateElement(Composite parent, org.joda.time.DateTime initialDateTime, int style, boolean editableText) {
|
|
64 | 70 |
super(parent, style); |
65 | 71 |
this.initialDateTime = initialDateTime; |
66 | 72 |
addDisposeListener(new DisposeListener() { |
... | ... | |
81 | 87 |
tableWrapLayout.bottomMargin = 0; |
82 | 88 |
setLayout(tableWrapLayout); |
83 | 89 |
} |
90 |
|
|
91 |
Composite composite = new Composite (this, SWT.NONE); |
|
92 |
GridLayout layout = new GridLayout (); |
|
93 |
|
|
94 |
layout.numColumns = 2; |
|
95 |
|
|
96 |
composite.setLayout(layout); |
|
97 |
composite.setSize(400, composite.getSize().y); |
|
98 |
int width = composite.getSize().x; |
|
99 |
|
|
100 |
// textDate = new Text(composite, SWT.BORDER|SWT.FILL); |
|
101 |
textDate = toolkit.createText(composite, "yyyy-mm-dd HH:mm:ss", style); |
|
102 |
textDate.setEditable(editableText); |
|
103 |
|
|
104 |
GridData gridData = new GridData(); |
|
105 |
gridData.minimumWidth = 200; |
|
106 |
|
|
107 |
|
|
108 |
textDate.setLayoutData(gridData); |
|
109 |
openDateDialog = new Button (composite, SWT.PUSH); |
|
110 |
Image image = ImageResources.getImage(ImageResources.DATE); |
|
111 |
// openDateDialog.setText ("Open Date Dialog"); |
|
112 |
openDateDialog.setImage(image); |
|
113 |
|
|
114 |
openDateDialog.addSelectionListener (new SelectionAdapter() { |
|
115 |
@Override |
|
116 |
public void widgetSelected(SelectionEvent e){ |
|
117 |
final Shell dialog = new Shell (parent.getShell(), SWT.DIALOG_TRIM); |
|
118 |
|
|
119 |
dialog.setLayout (new GridLayout (3, false)); |
|
120 |
|
|
121 |
final DateTime calendar = new DateTime (dialog, SWT.CALENDAR | SWT.BORDER); |
|
122 |
final DateTime time = new DateTime (dialog, SWT.TIME | SWT.SHORT); |
|
84 | 123 |
|
85 |
textDate = new Text(this, SWT.BORDER | SWT.WRAP); |
|
86 |
textDate.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1)); |
|
87 |
|
|
88 |
// openDateDialog = new Button (this, SWT.PUSH); |
|
89 |
// Image image = getDisplay().getSystemImage(SWT.DATE); |
|
90 |
// openDateDialog.setText ("Open Date Dialog"); |
|
91 |
// openDateDialog.addSelectionListener (new SelectionAdapter() { |
|
92 |
// @Override |
|
93 |
// public void widgetSelected(SelectionEvent e){ |
|
94 |
// final Shell dialog = new Shell (parent.getShell(), SWT.DIALOG_TRIM); |
|
95 |
// |
|
96 |
// dialog.setLayout (new GridLayout (3, false)); |
|
97 |
// |
|
98 |
// final DateTime calendar = new DateTime (dialog, SWT.CALENDAR | SWT.BORDER); |
|
99 |
// //final DateTime time = new DateTime (dialog, SWT.TIME | SWT.SHORT); |
|
100 |
// |
|
101 |
// new Label (dialog, SWT.NONE); |
|
102 |
// new Label (dialog, SWT.NONE); |
|
103 |
// Button ok = new Button (dialog, SWT.PUSH); |
|
104 |
// ok.setText ("OK"); |
|
105 |
// ok.setLayoutData(new GridData (SWT.FILL, SWT.CENTER, false, false)); |
|
106 |
// ok.addSelectionListener (new SelectionAdapter() { |
|
107 |
// @Override |
|
108 |
// public void widgetSelected(SelectionEvent e){ |
|
109 |
// setData(makeJodaFromSWT(calendar)); |
|
110 |
// setTextDate((calendar.getMonth () + 1) + "/" + calendar.getDay () + "/" + calendar.getYear ()); |
|
111 |
// System.out.println ("Calendar date selected (MM/DD/YYYY) = " + (calendar.getMonth () + 1) + "/" + calendar.getDay () + "/" + calendar.getYear ()); |
|
112 |
// // System.out.println ("Time selected (HH:MM) = " + time.getHours () + ":" + (time.getMinutes () < 10 ? "0" : "") + time.getMinutes ()); |
|
113 |
// dialog.close (); |
|
114 |
// } |
|
115 |
// }); |
|
116 |
// dialog.setDefaultButton (ok); |
|
117 |
// dialog.pack (); |
|
118 |
// dialog.open (); |
|
119 |
// } |
|
120 |
// }); |
|
124 |
new Label (dialog, SWT.NONE); |
|
125 |
new Label (dialog, SWT.NONE); |
|
126 |
Button ok = new Button (dialog, SWT.PUSH); |
|
127 |
ok.setText ("OK"); |
|
128 |
ok.setLayoutData(new GridData (SWT.FILL, SWT.CENTER, false, false)); |
|
129 |
ok.addSelectionListener (new SelectionAdapter() { |
|
130 |
@Override |
|
131 |
public void widgetSelected(SelectionEvent e){ |
|
132 |
setData(makeJodaFromSWT(calendar, time)); |
|
133 |
dialog.close (); |
|
134 |
} |
|
135 |
}); |
|
136 |
dialog.setDefaultButton (ok); |
|
137 |
dialog.pack (); |
|
138 |
dialog.open (); |
|
139 |
} |
|
140 |
}); |
|
121 | 141 |
|
122 | 142 |
toolkit.adapt(textDate, true, true); |
123 | 143 |
} |
... | ... | |
134 | 154 |
return textDate; |
135 | 155 |
} |
136 | 156 |
|
137 |
// public void setTextDate(String text){ |
|
138 |
// textDate.setText(text); |
|
139 |
// } |
|
140 |
// /** |
|
141 |
// * <p> |
|
142 |
// * Setter for the field <code>entity</code>. |
|
143 |
// * </p> |
|
144 |
// * |
|
145 |
// * @param selection |
|
146 |
// * a T object. |
|
147 |
// */ |
|
148 |
// public void setEntity(org.joda.time.DateTime time) { |
|
149 |
// this.initialDateTime = time; |
|
150 |
// |
|
151 |
// } |
|
152 |
// |
|
153 |
// |
|
154 |
// public static org.joda.time.DateTime makeJodaFromSWT( |
|
155 |
// org.eclipse.swt.widgets.DateTime widget) { |
|
156 |
// return new org.joda.time.DateTime(widget.getYear(), |
|
157 |
// widget.getMonth(), |
|
158 |
// widget.getDay(), |
|
159 |
// widget.getHours(), |
|
160 |
// widget.getMinutes(), |
|
161 |
// widget.getSeconds()); |
|
162 |
// } |
|
163 |
// |
|
164 |
// public static void updateSWTwithJoda( |
|
165 |
// org.eclipse.swt.widgets.DateTime widget, |
|
166 |
// org.joda.time.DateTime dateTime) { |
|
167 |
// widget.setYear(dateTime.getYear()); |
|
168 |
// widget.setMonth(dateTime.getMonthOfYear()); |
|
169 |
// widget.setDay(dateTime.getDayOfMonth()); |
|
170 |
// widget.setHours(dateTime.getHourOfDay()); |
|
171 |
// widget.setMinutes(dateTime.getMinuteOfHour()); |
|
172 |
// widget.setSeconds(dateTime.getSecondOfMinute()); |
|
173 |
// } |
|
174 |
// |
|
175 |
// public void setData (org.joda.time.DateTime data) { |
|
176 |
// this.initialDateTime = data; |
|
177 |
// |
|
178 |
// } |
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
public static org.joda.time.DateTime makeJodaFromSWT( |
|
161 |
org.eclipse.swt.widgets.DateTime widget, org.eclipse.swt.widgets.DateTime dateTime) { |
|
162 |
return new org.joda.time.DateTime(widget.getYear(), |
|
163 |
widget.getMonth(), |
|
164 |
widget.getDay(), |
|
165 |
dateTime.getHours(), |
|
166 |
dateTime.getMinutes(), |
|
167 |
dateTime.getSeconds()); |
|
168 |
} |
|
169 |
|
|
170 |
public static void updateSWTwithJoda( |
|
171 |
org.eclipse.swt.widgets.DateTime widget, |
|
172 |
org.joda.time.DateTime dateTime) { |
|
173 |
widget.setYear(dateTime.getYear()); |
|
174 |
widget.setMonth(dateTime.getMonthOfYear()); |
|
175 |
widget.setDay(dateTime.getDayOfMonth()); |
|
176 |
widget.setHours(dateTime.getHourOfDay()); |
|
177 |
widget.setMinutes(dateTime.getMinuteOfHour()); |
|
178 |
widget.setSeconds(dateTime.getSecondOfMinute()); |
|
179 |
} |
|
180 |
|
|
181 |
public void setData (org.joda.time.DateTime data) { |
|
182 |
this.initialDateTime = data; |
|
183 |
this.controller.setDateTime(data); |
|
184 |
this.textDate.setText(initialDateTime.toString(pattern)); |
|
185 |
|
|
186 |
} |
|
179 | 187 |
|
180 | 188 |
|
181 | 189 |
|
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/element/DateElementController.java | ||
---|---|---|
42 | 42 |
public DateElementController(DateElement dateTimeElement, CdmFormFactory formFactory, ICdmFormElement parentElement, DateTime initialDateTime) { |
43 | 43 |
super(formFactory, parentElement); |
44 | 44 |
this.textDate = dateTimeElement.getTextDate(); |
45 |
this.textDate.setText(initialDateTime!=null?initialDateTime.toString("yyyy-MM-dd"):"");
|
|
45 |
this.textDate.setText(initialDateTime!=null?initialDateTime.toString("yyyy-MM-dd HH:mm:ss"):"yyyy-mm-dd HH:mm:ss");
|
|
46 | 46 |
addControl(textDate); |
47 |
dateTime = initialDateTime; |
|
47 | 48 |
textDate.addModifyListener(this); |
48 | 49 |
} |
49 | 50 |
|
... | ... | |
61 | 62 |
@Override |
62 | 63 |
public void modifyText(ModifyEvent e) { |
63 | 64 |
try { |
64 |
String text = textDate.getText(); |
|
65 |
DateTime parsedDateTime = DateTime.parse(text); |
|
66 |
this.dateTime = parsedDateTime; |
|
65 |
// String text = textDate.getText();
|
|
66 |
// DateTime parsedDateTime = DateTime.parse(text);
|
|
67 |
// this.dateTime = parsedDateTime;
|
|
67 | 68 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e)); |
68 | 69 |
} catch (IllegalArgumentException iae) { |
69 | 70 |
System.err.println(iae.getMessage()); |
70 | 71 |
} |
71 | 72 |
} |
72 | 73 |
|
73 |
public DateTime getDateTime(){
|
|
74 |
public DateTime getDateTime(){ |
|
74 | 75 |
return dateTime; |
75 |
} |
|
76 |
} |
|
77 |
public void setDateTime(DateTime date){ |
|
78 |
dateTime = date; |
|
79 |
} |
|
76 | 80 |
|
77 | 81 |
/* (non-Javadoc) |
78 | 82 |
* @see eu.etaxonomy.taxeditor.ui.element.IRelevantFormElement#setIrrelevant(boolean) |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaMetaElement.java | ||
---|---|---|
74 | 74 |
text_title = formFactory.createLanguageStringWithLabelElement(element, "Title", null, style); |
75 | 75 |
selection_artist = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), element, "Artist", null, EntitySelectionElement.ALL, style); |
76 | 76 |
addElement(selection_artist); |
77 |
mediaCreated = formFactory.createDateElement(element, "Media Created", getEntity().getMediaCreated(), style); |
|
77 |
mediaCreated = formFactory.createDateElement(element, "Media Created", getEntity().getMediaCreated(), style, false);
|
|
78 | 78 |
addElement(mediaCreated.getController()); |
79 | 79 |
text_description = formFactory.createLanguageStringWithLabelElement(element, "Description", null, 100, true, style); |
80 | 80 |
|
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/DnaQualityDetailElement.java | ||
---|---|---|
68 | 68 |
numberRatioOfAbsorbance260_230 = formFactory.createNumberTextWithLabelElement(formElement, "Ratio of absorbance 260-230", ratioOfAbsorbance260_230, style); |
69 | 69 |
numberConcentration = formFactory.createNumberTextWithLabelElement(formElement, "Concentration", concentration, style); |
70 | 70 |
comboQualityTerm = formFactory.createDefinedTermComboElement(TermType.DnaQualityType, formElement, "Quality Term", qualityTerm, style); |
71 |
dateQualityCheck = formFactory.createDateElement(formElement, "Quality Check", dnaQuality.getQualityCheckDate(), style); |
|
71 |
dateQualityCheck = formFactory.createDateElement(formElement, "Quality Check", dnaQuality.getQualityCheckDate(), style, true);
|
|
72 | 72 |
} |
73 | 73 |
|
74 | 74 |
/* |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/media/MediaSpecimenGeneralDetailElement.java | ||
---|---|---|
73 | 73 |
comboKindOfUnit = formFactory.createDefinedTermComboElement(mediaSpecimenVocabulary, formElement, "Kind of Media", entity.getKindOfUnit(), style); |
74 | 74 |
textTitleLanguageString = formFactory.createLanguageStringWithLabelElement(formElement, "Motif", media.getTitle(), style); |
75 | 75 |
selectionArtist = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), formElement, "Prepared by", media.getArtist(), EntitySelectionElement.ALL, style); |
76 |
date = formFactory.createDateElement(formElement, "Preparation Date", entity.getMediaSpecimen().getMediaCreated(), style); |
|
76 |
date = formFactory.createDateElement(formElement, "Preparation Date", entity.getMediaSpecimen().getMediaCreated(), style, true);
|
|
77 | 77 |
textMethodLanguageString = formFactory.createLanguageStringWithLabelElement(formElement, "Method", media.getDescription(Language.getDefaultLanguage()), style); |
78 | 78 |
selection_collection = formFactory.createSelectionElement(Collection.class, getConversationHolder(), formElement, "Collection", entity.getCollection(), EntitySelectionElement.ALL, style); |
79 | 79 |
text_accessionNumber = formFactory.createTextWithLabelElement(formElement, "Accession Number", entity.getAccessionNumber(), style); |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/reference/ReferenceDetailElement.java | ||
---|---|---|
186 | 186 |
} |
187 | 187 |
|
188 | 188 |
private void createWebPageControls(ReferenceDetailElement referenceDetailElement, Reference reference, int style) { |
189 |
text_accessed = formFactory.createDateElement(referenceDetailElement, "Accessed", reference.getAccessed(), style); |
|
189 |
text_accessed = formFactory.createDateElement(referenceDetailElement, "Accessed", reference.getAccessed(), style, false);
|
|
190 | 190 |
|
191 | 191 |
} |
192 | 192 |
|
Also available in: Unified diff
ref #6658: add calendar widget to dateElement