Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 316498

Summary: [widgets] Keyboard navigation inside the DateTime SWT.CALENDAR widget does not work on Cocoa
Product: [Eclipse Project] Platform Reporter: Al B <Alfredo.Bencomo>
Component: SWTAssignee: Scott Kovatch <skovatch>
Status: RESOLVED WONTFIX QA Contact: Silenio Quarti <Silenio_Quarti>
Severity: normal    
Priority: P3 CC: skovatch
Version: 3.5.2   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:

Description Al B CLA 2010-06-10 13:27:31 EDT
Running the the snippet below on Windows or with Carbon, one can use the keyboard arrows to navigate inside the DateTime widget.  Also, the Page Up and Page Down keys change the month backwards and forwards.

However, these events are not triggered on Cocoa.


import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet250 {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new RowLayout());

		final DateTime calendar = new DateTime(shell, SWT.CALENDAR);
		calendar.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println ("Calendar date selected (MM/DD/YYYY) = " + (calendar.getMonth () + 1) + "/" + calendar.getDay () + "/" + calendar.getYear ());				
			}
		});
		
		calendar.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
					System.out.println("calendar date changed");
				}
			}
		});

		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}
Comment 1 Scott Kovatch CLA 2010-11-02 14:13:56 EDT
Unfortunately this is platform behavior. NSDatePicker doesn't support keyboard-based navigation. But, once bug 277638 is fixed you can make a DateTime with SWT.DATE and SWT.DROP_DOWN set and then use the keyboard to adjust the date elements. The calendar drop-down will update to match the textual date.