Is it passable to add Shortcut Action Handler to Table?

I have vaadin application with the split panel at main window. As a first component of the first component - there is ComboBoxs (I use them as a filters for table ) and as a second - table. I need support for actions ShortcutAction.KeyCode.ARROW_DOWN and ShortcutAction.KeyCode.ARROW_UP (to scroll values in table by setCurrentPageFirstItemIndex) , but I can`t find the way to add special handler for Table (it could not be even focused ) - I can add them as an action handler for application main window, but in this case the table scroll each time i use arrow up/down in ComboBox.
What should be done to enable shortcut support only for Table ?

Please Help! :frowning:
Thank you.

I share your pain. :frowning:

With TubeTunes (
http://tubetunes.appspot.com/
) I wanted to apply same kind of pattern, but it is unfortunately not currently supported. Table allows you to attach hander for ShortcutActions, but it simply creates a popup menu of these. Not exactly what I wanted. Also, the event overlap with ComboBox made me finally to disable keyboard actions for the Window altogether.

I did create a ticket for this:
http://dev.vaadin.com/ticket/3738

my current design is to use Page up/down and scroll by sum numbers of rows… but it is not exactly what i want it to be :frowning:
Such functionality must be in Table…

Here’s the ticket for keyboard navigation on Table:
#2390
. Go vote for it on
Vaadin UserVoice
!

As a workaround, you could try and enclose the Table inside a Panel (light style, no borders), and add the shortcut actions inside the Panel (both Window and Panel are valid action containers for shortcut keys).

Thank you!

vote

i’m confused now… so is there a way to navigate in a table with arrow keys or not? :confused: if yes, could anyone explain how? Thanks

Yes it is. You just have to attach the key event listeners (shortcut actions) to the Window the Table is in, or wrap the Table with a Panel (Panel.STYLE_LIGHT maybe?) and add the actions to the Panel.

My Example (you just need to use different keys) :



Handler handler = new ScrollUpDownHandler();

//add ActionHandler to some panel, or to root window where is our table placed. 
mainPanel.addActionHandler(handler);

//---
class ScrollUpDownHandler implements Handler {

		/**
		 * 
		 */
		private static final long serialVersionUID = -2629242368773216799L;

		Action action_up = new ShortcutAction("Up", ShortcutAction.KeyCode.PAGE_UP, null);

		Action action_down = new ShortcutAction("Down", ShortcutAction.KeyCode.PAGE_DOWN, null);

		/*
		 * (non-Javadoc)
		 * 
		 * @see com.vaadin.event.Action.Handler#getActions(java.lang.Object,
		 * java.lang.Object)
		 */
		@Override
		public Action[] getActions(Object target, Object sender) {
			return new Action[] { action_up, action_down };
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see
		 * com.vaadin.event.Action.Handler#handleAction(com.vaadin.event.Action,
		 * java.lang.Object, java.lang.Object)
		 */
		@Override
		public void handleAction(Action action, Object sender, Object target) {
			if (action == action_up) {
				table.setCurrentPageFirstItemIndex(table.getCurrentPageFirstItemIndex() - 5);
				TrochiliformesApplication.getRootWindow().showNotification("Scroll Up");
			}
			if (action == action_down) {
				TrochiliformesApplication.getRootWindow().showNotification("Scroll down");
				table.setCurrentPageFirstItemIndex(table.getCurrentPageFirstItemIndex() + 5);
			}

		}

	}
//-------

Hi guys,

I see that this issue is still unfixed.
Shall we use this workaround stated in this post of using a Window or a Panel ?
Or is there maybe a plan to fixe it ?

I don’t see any milestone on this ticket : http://dev.vaadin.com/ticket/3738

Thx a lots :slight_smile:

Hi Jouni.

The workaround with the panel works, but then my tabel lies within a scrollable area.
Is it impossible to turn of the scrolling within a panel?

/Michael

I think I found out how to use the panel as work around without the scrolable area.

Its all about controlling the container in the panel fx by setting it explicitly.


VerticalLayout layout = new VerticalLayout();
Panel panel = new Panel(layout);
layout.setSizefull();

Or a complete example:


public class MyVaadinApplication extends Application {

    private Table table = new Table();
    private final VerticalLayout layout = new VerticalLayout();
    private final Panel panel = new Panel(layout);
    

    @Override
    public void init() {
        layout.setSizeFull();
        table.setSizeFull();
        table.addContainerProperty("test", TextField.class, null);

        Window mainWindow = new Window();
        setMainWindow(mainWindow);

        mainWindow.addComponent(panel);
        panel.addComponent(table);
        panel.setHeight("300px");
        panel.addActionHandler(new Action.Handler() {
            public void handleAction(Action action, Object sender, Object target) {
                getMainWindow().showNotification(action.toString());
            }

            public Action[] getActions(Object target, Object sender) {
                return new Action[]{
                            new ShortcutAction("Default key",
                            ShortcutAction.KeyCode.ENTER, null)
                        };
            }
        });

        for (int i = 0; i < 100; i++) {
            TextField field = new TextField();
            field.setImmediate(true);
            table.addItem(new Object[]{field}, i);
        }
    }
}