Context menu not working in Windows

Hello,

This is my first post. First, Vaadin is turning out to be an excellent platform for building out our bioinformatics/data exploration platform. I’m currently deploying our app using Vaadin version 6.3.4 on GlassFish 3.0.1.

Now, on to the issue: I have a working application that implements context menus on tables that appear in various places based on user interaction. I do all of my work on Linux with Firefox and Chromium and things appear to be working as designed (e.g, user clicks on a table row/rows, appropriate context menu shows with right click in table). However, in Windows (on FF, IE, and Chrome) the context menu appears very briefly and then disappears. I can’t seem to figure this out, but it looks like it might be a bug.

The code below shows the table setup code, which creates a table in the first component of a SplitPanel.


public class SampleTable extends Table {

    private OceanExplorer app;

    public SampleTable(final OceanExplorer app) {
        this.app = app;
        addListener((Table.ValueChangeListener) app);
        setSizeFull();
        setSelectable(true);
        setImmediate(true);
        setMultiSelect(true);
        setColumnReorderingAllowed(true);
        setColumnCollapsingAllowed(true);

        addActionHandler(new Action.Handler() {

            private Set<Sample> sampleSet;
            private Action histogram = new Action("");
            public Action metadata = new Action(HelpMessages.SELECT_METADATA_SAMPLE);

            @Override
            public Action[] getActions(Object target, Object sender) {
                sampleSet = (Set<Sample>) getValue();
                if (sampleSet.isEmpty()) {
                    return new Action[]{new Action(HelpMessages.SELECT_ROW)};
                } else if (sampleSet.size() > 1) {
                    return new Action[]{metadata};
                }
                histogram.setCaption("Show histogram for " + sampleSet);
                return new Action[]{histogram, metadata};
            }

            @Override
            public void handleAction(Action action, Object sender, Object target) {
                if (action.equals(histogram)) {
                    SampleHistogramWindow hist = new SampleHistogramWindow(sampleSet, app);
                    hist.showWindow();
                } else if (action.equals(metadata)) {
                    MetadataWindow meta = new MetadataWindow(sampleSet, app, "sample");
                    meta.showWindow();
                }
            }
        });

        addListener(new ItemClickListener() {

            @Override
            public void itemClick(ItemClickEvent event) {
                requestRepaint();
            }
        });
    }

    public void addSamplesForRun(Run run) {
        setContainerDataSource(DBHelper.getSamplesForRun(run));
        setVisibleColumns(new Object[]{"runName", "name"});
        setColumnHeaders(new String[]{"Run Name", "Sample Name"});
    }

Your help is greatly appreciated.

Thanks!
Chris

You have an ItemClickListener that does nothing but cause the table to be repainted and probably close the contextmenu at the same time. Have you tried removing it?

Potentially, but there didn’t appear to be any other way to update the selection and enable context-senstivity for the selected rows/row. Maybe using a set that is updated using the ItemClickListener would be better? What’s the best way to do this sort of thing?

Here’s a brief
movie
showing working and non-working examples.

Thanks,
Chris

OK, I got this working. Seems I was missing something obvious in that I didn’t really need the ItemClickListener at all. I was able to solve this by implementing a ValueChangeListener on the table when it is created that does the refresh while the Action only listens (in the Table) for the current selected value/values.

Example below:

Creating the table:


public SampleTable getSampleTable() {
        if (sampleTable == null) {
            sampleTable = new SampleTable(this);
            sampleTable.addListener(new ValueChangeListener() {

                @Override
                public void valueChange(ValueChangeEvent event) {
                    sampleTable.requestRepaint();
                }
            });
        }
        return sampleTable;

Table action:


addActionHandler(new Action.Handler() {

            private Action histogram = new Action("");
            public Action metadata = new Action(HelpMessages.SELECT_METADATA_SAMPLE);
            private Set<Sample> selected;

            @Override
            public Action[] getActions(Object target, Object sender) {
                 selected = (Set<Sample>) getValue();
                if (selected.isEmpty()) {
                    return new Action[]{new Action(HelpMessages.SELECT_ROW)};
                } else if (selected.size() > 1) {
                    return new Action[]{metadata};
                }
                histogram.setCaption("Show histogram for " + selected);
                return new Action[]{histogram, metadata};
            }

            @Override
            public void handleAction(Action action, Object sender, Object target) {
                if (action.equals(histogram)) {
                    SampleHistogramWindow hist = new SampleHistogramWindow(selected, app);
                    hist.showWindow();
                } else if (action.equals(metadata)) {
                    MetadataWindow meta = new MetadataWindow(selected, app, "sample");
                    meta.showWindow();
                }
            }
        });

Thanks for a point in the right direction!
Chris