| 1 | 8 | |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
package org.eclipse.swtbot.swt.finder.widgets; |
| 12 | |
|
| 13 | |
import java.util.Calendar; |
| 14 | |
import java.util.Date; |
| 15 | |
|
| 16 | |
import org.eclipse.swt.SWT; |
| 17 | |
import org.eclipse.swt.widgets.DateTime; |
| 18 | |
import org.eclipse.swtbot.swt.finder.ReferenceBy; |
| 19 | |
import org.eclipse.swtbot.swt.finder.SWTBotWidget; |
| 20 | |
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; |
| 21 | |
import org.eclipse.swtbot.swt.finder.results.Result; |
| 22 | |
import org.eclipse.swtbot.swt.finder.results.VoidResult; |
| 23 | |
import org.eclipse.swtbot.swt.finder.utils.MessageFormat; |
| 24 | |
import org.hamcrest.SelfDescribing; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
@SWTBotWidget(clasz = DateTime.class, preferredName = "dateTime", referenceBy = { ReferenceBy.LABEL }) |
| 31 | |
public class SWTBotDateTime extends AbstractSWTBotControl<DateTime> { |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public SWTBotDateTime(DateTime w) throws WidgetNotFoundException { |
| 41 | 0 | this(w, null); |
| 42 | 0 | } |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
public SWTBotDateTime(DateTime w, SelfDescribing description) throws WidgetNotFoundException { |
| 53 | 5 | super(w, description); |
| 54 | 5 | } |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
public Date getDate() { |
| 62 | 4 | return syncExec(new Result<Date>() { |
| 63 | |
public Date run() { |
| 64 | 4 | int year = widget.getYear(); |
| 65 | 4 | int month = widget.getMonth(); |
| 66 | 4 | int day = widget.getDay(); |
| 67 | |
|
| 68 | 4 | int hours = widget.getHours(); |
| 69 | 4 | int minutes = widget.getMinutes(); |
| 70 | 4 | int seconds = widget.getSeconds(); |
| 71 | 4 | Calendar calendar = Calendar.getInstance(); |
| 72 | 4 | calendar.setTimeInMillis(0); |
| 73 | 4 | calendar.set(year, month, day, hours, minutes, seconds); |
| 74 | 4 | return calendar.getTime(); |
| 75 | |
} |
| 76 | |
|
| 77 | |
}); |
| 78 | |
} |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
public void setDate(final Date toSet) { |
| 86 | 4 | log.debug(MessageFormat.format("Setting date on control: {0} to {1}", this, toSet)); |
| 87 | 4 | waitForEnabled(); |
| 88 | 4 | syncExec(new VoidResult() { |
| 89 | |
@SuppressWarnings("deprecation") |
| 90 | |
public void run() { |
| 91 | 4 | widget.setYear(toSet.getYear() + 1900); |
| 92 | 4 | widget.setMonth(toSet.getMonth()); |
| 93 | 4 | widget.setDay(toSet.getDate()); |
| 94 | |
|
| 95 | 4 | widget.setHours(toSet.getHours()); |
| 96 | 4 | widget.setMinutes(toSet.getMinutes()); |
| 97 | 4 | widget.setSeconds(toSet.getSeconds()); |
| 98 | 4 | } |
| 99 | |
}); |
| 100 | 4 | notify(SWT.Selection); |
| 101 | 4 | } |
| 102 | |
} |