Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » How traverse on composite Nebula widget DateChooserCombo
icon8.gif  How traverse on composite Nebula widget DateChooserCombo [message #731677] Sun, 02 October 2011 12:32 Go to next message
Mariusz P. is currently offline Mariusz P.Friend
Messages: 85
Registered: February 2010
Member
Hello Razz

I have code:

DateChooserCombo dateChooserCombo = new DateChooserCombo(shell, SWT.NONE);
Control[] control = dateChooserCombo.getChildren();
Control textInDateChooserCombo = control[0];
Control buttonInDateChooserCombo = control[1];


How to go key arrow down at the same time by textInDateChooserCombo and buttonInDateChooserCombo at once? How implements TraverseListener?

[Updated on: Wed, 29 February 2012 01:11]

Report message to a moderator

Re: How traverse on composite Nebula widget DateChooserCombo [message #801059 is a reply to message #731677] Fri, 17 February 2012 21:42 Go to previous messageGo to next message
Mariusz P. is currently offline Mariusz P.Friend
Messages: 85
Registered: February 2010
Member
Help Smile
Re: How traverse on composite Nebula widget DateChooserCombo [message #809319 is a reply to message #731677] Tue, 28 February 2012 18:38 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 298
Registered: July 2009
Senior Member

Hello Mariusz,

It is unclear what the problem is and what you want to achieve. We cannot help you without a detailed description.

Best regards,

Wim
Re: How traverse on composite Nebula widget DateChooserCombo [message #809442 is a reply to message #809319] Tue, 28 February 2012 22:04 Go to previous messageGo to next message
Mariusz P. is currently offline Mariusz P.Friend
Messages: 85
Registered: February 2010
Member
OK. Example:

1. I have three widgets: Button, DateChooserCombo, Text.
2. Default traversing TAB key is: Button -> text widget in widget DateChooserCombo -> button in widget DateChooserCombo -> Text.
3. I want change the default traverse key from TAB to ARROW DOWN.
4. How to get traversing: Button -> DateChooserCombo -> Text (only three steps).

[Updated on: Tue, 28 February 2012 23:22]

Report message to a moderator

Re: How traverse on composite Nebula widget DateChooserCombo [message #809453 is a reply to message #809442] Tue, 28 February 2012 22:24 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 298
Registered: July 2009
Senior Member

I see. Can you post a working snippet that shows how you have solved this so far?

Regards,

Wim
Re: How traverse on composite Nebula widget DateChooserCombo [message #809482 is a reply to message #809453] Tue, 28 February 2012 23:20 Go to previous messageGo to next message
Mariusz P. is currently offline Mariusz P.Friend
Messages: 85
Registered: February 2010
Member
package datechoosercomboexample;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.nebula.widgets.datechooser.DateChooserCombo;

public class DateChooserComboExample {

	protected Shell shell;
	private Text text;
	private Text text_1;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			DateChooserComboExample window = new DateChooserComboExample();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(493, 459);
		shell.setText("SWT Application");

		Group grpTabTraversal = new Group(shell, SWT.NONE);
		grpTabTraversal.setText("TAB TRAVERSAL");
		grpTabTraversal.setBounds(10, 10, 443, 125);

		Button btnButton = new Button(grpTabTraversal, SWT.NONE);
		btnButton.setBounds(41, 60, 75, 25);
		btnButton.setText("Button");

		DateChooserCombo dateChooserCombo = new DateChooserCombo(grpTabTraversal, SWT.NONE);
		dateChooserCombo.setBounds(157, 68, 86, 17);

		text = new Text(grpTabTraversal, SWT.BORDER);
		text.setBounds(280, 64, 76, 21);

		Group grpArrowDownTraversal = new Group(shell, SWT.NONE);
		grpArrowDownTraversal.setText("ARROW DOWN TRAVERSAL");
		grpArrowDownTraversal.setBounds(10, 152, 443, 266);

		Button btnButton_1 = new Button(grpArrowDownTraversal, SWT.NONE);
		btnButton_1.setBounds(39, 80, 75, 25);
		btnButton_1.setText("Button");
		btnButton_1.addTraverseListener(new TraverseListener() {
			@Override
			public void keyTraversed(TraverseEvent e) {

				if (e.detail == SWT.TRAVERSE_RETURN || e.keyCode == SWT.ARROW_DOWN) {
					e.detail = SWT.TRAVERSE_TAB_NEXT;
				} else if (e.keyCode == SWT.ARROW_UP) {
					e.detail = SWT.TRAVERSE_TAB_PREVIOUS;
				}
				e.doit = true;
			}
		});

		DateChooserCombo dateChooserCombo_1 = new DateChooserCombo(grpArrowDownTraversal, SWT.NONE);
		dateChooserCombo_1.setBounds(162, 88, 86, 17);
		dateChooserCombo_1.addTraverseListener(new TraverseListener() {
			@Override
			public void keyTraversed(TraverseEvent e) {

				if (e.detail == SWT.TRAVERSE_RETURN || e.keyCode == SWT.ARROW_DOWN) {
					e.detail = SWT.TRAVERSE_TAB_NEXT;
				} else if (e.keyCode == SWT.ARROW_UP) {
					e.detail = SWT.TRAVERSE_TAB_PREVIOUS;
				}
				e.doit = true;
			}
		});

		text_1 = new Text(grpArrowDownTraversal, SWT.BORDER);
		text_1.setBounds(280, 84, 76, 21);
		text_1.addTraverseListener(new TraverseListener() {
			@Override
			public void keyTraversed(TraverseEvent e) {

				if (e.detail == SWT.TRAVERSE_RETURN || e.keyCode == SWT.ARROW_DOWN) {
					e.detail = SWT.TRAVERSE_TAB_NEXT;
				} else if (e.keyCode == SWT.ARROW_UP) {
					e.detail = SWT.TRAVERSE_TAB_PREVIOUS;
				}
				e.doit = true;
			}
		});

	}
}


Problem is it in group "ARROW DOWN TRAVERSAL". ARROW DOWN key is stopped on button in widget DateChooserCombo. I would like to have also traversing: Button -> DateChooserCombo -> Text (text widget in widget DateChooserCombo and button in widget DateChooserCombo as one step).

[Updated on: Wed, 29 February 2012 00:17]

Report message to a moderator

Re: How traverse on composite Nebula widget DateChooserCombo [message #809513 is a reply to message #809482] Wed, 29 February 2012 00:25 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 298
Registered: July 2009
Senior Member

Ah yes. The DateChooserCombo is a composite widget. The trick is to expose the button on the control.

You can subclass DateChooserCombo and expose the button:

package datechoosercombo;

import org.eclipse.nebula.widgets.datechooser.DateChooserCombo;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

public class MyCombo extends DateChooserCombo {

	private Button buttonControl;

	public MyCombo(Composite parent, int style) {
		super(parent, style);
	}

	@Override
	protected Button createButtonControl(int style) {
		buttonControl = super.createButtonControl(style);
		return getButtonControl();
	}

	public Button getButtonControl() {
		return buttonControl;
	}

}


Then add the traverse listener to the button like this:

		dateChooserCombo_1.getButtonControl().addTraverseListener(new TraverseListener() {
			@Override
			public void keyTraversed(TraverseEvent e) {
				
				if (e.detail == SWT.TRAVERSE_RETURN || e.keyCode == SWT.ARROW_DOWN) {
					e.detail = SWT.TRAVERSE_TAB_NEXT;
				} else if (e.keyCode == SWT.ARROW_UP) {
					e.detail = SWT.TRAVERSE_TAB_PREVIOUS;
				}
				e.doit = true;
			}
		});


works like a charm
Re: How traverse on composite Nebula widget DateChooserCombo [message #809523 is a reply to message #809513] Wed, 29 February 2012 00:43 Go to previous message
Mariusz P. is currently offline Mariusz P.Friend
Messages: 85
Registered: February 2010
Member
This it's the same:

DateChooserCombo dateChooserCombo = new DateChooserCombo(shell, SWT.NONE);
Control[] control = dateChooserCombo.getChildren();
Control textInDateChooserCombo = control[0];
Control buttonInDateChooserCombo = control[1];
buttonInDateChooserCombo.addTraverseListener(new TraverseListener() {
	@Override
	public void keyTraversed(TraverseEvent e) {

		if (e.detail == SWT.TRAVERSE_RETURN || e.keyCode == SWT.ARROW_DOWN) {
			e.detail = SWT.TRAVERSE_TAB_NEXT;
		} else if (e.keyCode == SWT.ARROW_UP) {
			e.detail = SWT.TRAVERSE_TAB_PREVIOUS;
		}
		e.doit = true;
	}
});


Question is: "How in one step (one key pressing) traversing all widget DateChooserCombo ("text field & button together in DateChooserCombo)?

[Updated on: Wed, 29 February 2012 00:47]

Report message to a moderator

Previous Topic:Binding Long-Values in FormattedText (DateTimeFormatter)
Next Topic:1 problem, 1 question on GridViewer
Goto Forum:
  


Current Time: Fri Dec 19 00:44:52 GMT 2014

Powered by FUDForum. Page generated in 0.01703 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software