Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [platform-swt-dev] Overrriding default behaviors

I tried it, but it doesn't quite do the trick. AFTER I finish handling
the TrasverseEvent (positioning the combo in the item 0) it does the
default dehaviour, and the combo goes to the item 1.

Here's the code adapted from yours.

        combo.addTraverseListener(new TraverseListener() {
            public void keyTraversed(TraverseEvent e) {
                //if (mEditor.getEditor() instanceof CCombo) {
                    mCancelComboSelection = true;
                //}
                e.doit = false;
                System.out.println("OK");
                combo.select(0);
            }
        }
Even when I hard code the selection to the 1st item, it ends up in the
second item.

The combo was created like this

        this.combo = new GaiaCombo(composite, SWT.READ_ONLY);
        this.combo.add("Uno");
        this.combo.add("Dos");
        this.combo.add("Tres");
        this.combo.add("Cuatro");
        this.combo.select(0);

        this.setLayoutDataTo(this.combo, SWT.DEFAULT, SWT.DEFAULT, 10,
10);
        this.setVisible(true);

GaiaCombo is just a Combo subclass that just adds 2 methods to open
close and toggle the dropdown menu.

-----Original Message-----
From: Erik Poupaert [mailto:erik.poupaert@xxxxxxxxx] 
Sent: Jueves 20 de Febrero de 2003 11:41
To: platform-swt-dev@xxxxxxxxxxx
Subject: RE: [platform-swt-dev] Overrriding default behaviors



>>>>> We are trying to add editing capabilities to the Table widget. We
would
>>>>> like to simulate the Excel's cell behaviour, including the
"embeded
>>>>> combo" option. The problem is some keys already have behaviour
that we
>>>>> cannot override (la arrows chang the selection in the combo). We'd
like
>>>>> to allow the user to use the keys to navigate through the cells
but we
>>>>> cannt avoid the combo selection to change (in the case of the up
and
>>>>> down arrows).
>>>>> That default behaviour doesn't do any harm in the case of the Text
>>>>> widget, it just moves the cursor.
>>>>> So, is there any way, including subclassing or calling the OS, to
avoid
>>>>> the widget's default behavoiurs envolving the key events?

I've had the same problem, but I've fixed it with the following things:

	protected boolean mCancelComboSelection;
...
			combo.addTraverseListener(this);

			combo.addSelectionListener(new
SelectionAdapter()
			{
				public void
widgetSelected(SelectionEvent e)
				{
					if(mCancelComboSelection)
					{
						e.doit=false;
	
mCancelComboSelection=false;
					}
				}

	public void keyTraversed(TraverseEvent e)
	{
		if(mEditor.getEditor() instanceof CCombo)
		{
			mCancelComboSelection=true;
		}
		e.doit=false;
	}

The effect is that the combo doesn't open any longer on ARROW_UP or
ARROW_DOWN. Of course, you need to do something else instead. In my
case,
the cursor goes to the cell up or the cell down (if possible).


Back to the top