vaadin 7 layout click doesn't work

610 views Asked by At

I've created MainGameTab which extends TabSheet.

In constructor I create layouts and add them as tabs. I wanted to add right click event to the layout

mainLayout.addLayoutClickListener(new LayoutClickListener() {

    private static final long serialVersionUID = 1871942396979048283L;

    @Override
    public void layoutClick(LayoutClickEvent event) {
        if (event.getButton() == MouseButton.RIGHT) {
            TextQuestUi.getCurrent().addWindow(new CharacterSheet(c));
        }
    }

});
this.addTab(mainLayout, "Game");

CharacterSheet is a class, that extends Window

public class CharacterSheet extends Window {

But when I click on tab - I've got basic right click items for browser instead of new window.

What's the problem?

My MainGameTab looks like this

public MainGameTab() {
    final Player c = new Player();
    c.setName("Hero");
    c.setLevel(100);

    Skill skill = new Skill();
    skill.setName("Help from heaven");
    skill.setEffect("Full recover health");
    c.addSkill(skill);

    Stat stat = new Stat();
    stat.setName("Attack");
    stat.setValue(50);
    c.addStat(stat);

    HorizontalLayout mainLayout = new HorizontalLayout();
    mainLayout.addLayoutClickListener(new LayoutClickListener() {

        private static final long serialVersionUID = 1871942396979048283L;

        @Override
        public void layoutClick(LayoutClickEvent event) {
            if (event.getButton() == MouseButton.RIGHT) {
                TextQuestUi.getCurrent().addWindow(new CharacterSheet(c));
            }
        }

    });
    this.addTab(mainLayout, "Game");

    HorizontalLayout logLayout = new HorizontalLayout();
    this.addTab(logLayout, "Log");
}

And I add it in UI

@Override
protected void init(VaadinRequest request) {
   this.setContent(new MainGameTab());   
}
1

There are 1 answers

0
UnP On

I'll suggest you to use one of the existing Vaadin addons. See here

Or, I am assuming that you're probably looking for getButton() in ItemClickEvent - something like this:

t.addListener(new ItemClickListener() {
  public void itemClick(ItemClickEvent event) {
    if (event.getButton()==ItemClickEvent.BUTTON_RIGHT) {
       // Right mouse button clicked, do greatThings!
    }
  }
});