PopupMenu issue

1 view
Skip to first unread message

Alejandro D. Garin

unread,
Dec 30, 2008, 12:22:51 PM12/30/08
to gwt-m...@googlegroups.com
Hi George,

I have noted a minor issue with the PopupMenu. I'm using it to display a context menu over a scrolltable to make some actions. If the PopupMenu has a nested MenuBar then when the mouse pointer left the menubar item the popup is closed.
You can use the demo attached to see the problem. Try the right click, goto the New item (this open a MenuBar with two items) and then go down with the mouse pointer to "Delete" item, then the popup closes.

It's not a big problem but will be nice if the popup still open until a mouse click.
Tested with IE, Firefox, Chrome.

Thanks.


import org.gwt.mosaic.ui.client.PopupMenu;
import org.gwt.mosaic.ui.client.infopanel.TrayInfoPanelNotifier;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;

public class PopupMenuDemo implements EntryPoint {

  private static Command cmd = new Command() {
    public void execute() {
      TrayInfoPanelNotifier.notifyTrayEvent("Menu", "Clicked!");
    }
  };   
  public void onModuleLoad() {
   
    HTML html = new HTML("Right Click over the text please!"){
      @Override
      public void onBrowserEvent(final Event event) {
        super.onBrowserEvent(event);
        switch (DOM.eventGetType(event)) {   
        case Event.ONCONTEXTMENU: {
            DOM.eventPreventDefault(event);
            final PopupMenu contextMenu = new PopupMenu();
            final MenuBar newMenu = new MenuBar(true);

            newMenu.setAutoOpen(true);
            newMenu.setAnimationEnabled(true);
            newMenu.addItem("New Appointment",cmd);
            newMenu.addItem("New Block",cmd);

            contextMenu.addItem("New", newMenu);
            contextMenu.addItem("Delete", cmd);
            contextMenu.addSeparator();
            contextMenu.addItem("Accept", cmd);
            contextMenu.addItem("Reject", cmd);
             
            contextMenu.setPopupPositionAndShow(new PositionCallback() {
              public void setPosition(int offsetWidth, int offsetHeight) {
                contextMenu.setPopupPosition(event.getClientX(), event.getClientY());
              }
            });
          break;
        }
        }   
      }};
    html.sinkEvents(Event.ONCONTEXTMENU);
    DOM.setStyleAttribute(html.getElement(), "color", "red");
    RootPanel.get().add(html);
  }

}

Alejandro D. Garin

unread,
Jan 2, 2009, 10:08:37 AM1/2/09
to gwt-m...@googlegroups.com
Hi George

Just to know if this could be added as an issue or should I found a workaround?

Thanks and happy new year!

G. Georgopoulos

unread,
Jan 2, 2009, 10:52:15 AM1/2/09
to gwt-m...@googlegroups.com
Hi Alejandro,

I will try to fix that today (I am planing to make a release on Saturday
with the new Actions API, that has also the disabled MenuItem you asked
for, so I hope to include a fix for that issue too.

If you find something or even a workaround let me know.

Thanks,
George.

> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google
> Groups "gwt-mosaic" group.
> To post to this group, send email to gwt-m...@googlegroups.com
> To unsubscribe from this group, send email to
> gwt-mosaic+...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/gwt-mosaic?hl=en
> -~----------~----~----~----~------~----~------~--~---
>

Alejandro D. Garin

unread,
Jan 2, 2009, 6:37:19 PM1/2/09
to gwt-m...@googlegroups.com
Thanks George.

I have a question regarding to GridLayouData. I was reading the
javadoc for BorderLayout and I found a very nice feature for
BorderLayoutData: the posibility to change the region dimension by the
user with an split bar. Is it posible to add this feature to
GridLayouData ?

Thanks.

G. Georgopoulos

unread,
Jan 2, 2009, 7:00:53 PM1/2/09
to gwt-m...@googlegroups.com
The GridLayout has support for colspan and rowspan and using split bars
is too complicated. In BorderLayout adding split bars was very easy.
Maybe nested BorderLayouts can mimic a GridLayout. Can you send me in a
simple drawing the layout you want to do?

Alejandro D. Garin

unread,
Jan 3, 2009, 9:36:43 AM1/3/09
to gwt-m...@googlegroups.com
Hi George,

I'm sending below a demo code using GridLayout. Will be very usefull
if I could change to BorderLayout to use the split the panels in all
regions.

Thanks!

import org.gwt.mosaic.ui.client.ToolBar;
import org.gwt.mosaic.ui.client.ToolButton;
import org.gwt.mosaic.ui.client.WindowPanel;
import org.gwt.mosaic.ui.client.layout.BoxLayout;
import org.gwt.mosaic.ui.client.layout.BoxLayoutData;
import org.gwt.mosaic.ui.client.layout.GridLayout;
import org.gwt.mosaic.ui.client.layout.GridLayoutData;
import org.gwt.mosaic.ui.client.layout.LayoutPanel;
import org.gwt.mosaic.ui.client.layout.BoxLayout.Orientation;
import org.gwt.mosaic.ui.client.layout.BoxLayoutData.FillStyle;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.gen2.table.client.FixedWidthFlexTable;
import com.google.gwt.gen2.table.client.FixedWidthGrid;
import com.google.gwt.gen2.table.client.ScrollTable;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class George implements EntryPoint {

/**
* This is the entry point method.
*/
public void onModuleLoad() {
final WindowPanel w = new WindowPanel("WindowPanel");
w.setSize("512px", "384px");
w.setAnimationEnabled(true);
w.setWidget(createContent());

Button b = new Button("Show WindowPanel");
b.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
w.center();
}
});

RootPanel.get().add(b);
}

private Widget createContent() {
final LayoutPanel vbox = new LayoutPanel(new
BoxLayout(Orientation.VERTICAL));
vbox.setPadding(0);
vbox.setWidgetSpacing(0);

final ToolBar toolBar = new ToolBar();
vbox.add(toolBar, new BoxLayoutData(FillStyle.HORIZONTAL));

toolBar.add(new ToolButton("Button 1"));
toolBar.add(new ToolButton("Button 2"));
toolBar.addSeparator();
toolBar.add(new ToolButton("Button 3"));

final LayoutPanel grid = new LayoutPanel(new GridLayout(3, 3));
vbox.add(grid, new BoxLayoutData(FillStyle.BOTH));

grid.add(newScrollTable1(), new GridLayoutData(3, 1, true));
grid.add(newScrollTable1(), new GridLayoutData(1, 2, true));
grid.add(newScrollTable1(), new GridLayoutData(2, 1, true));
grid.add(newScrollTable1(), new GridLayoutData(2, 1, true));

return vbox;
}

private Widget newScrollTable1() {
final FixedWidthFlexTable headerTable = new FixedWidthFlexTable();
final FixedWidthGrid dataTable = new FixedWidthGrid();

final ScrollTable scrollTable = new ScrollTable(dataTable, headerTable);
scrollTable.setCellPadding(3);
scrollTable.setCellSpacing(1);
scrollTable.setResizePolicy(ScrollTable.ResizePolicy.FILL_WIDTH);

headerTable.setText(0, 0, "NAME");
headerTable.setText(0, 1, "VALUE");

// Redraw the scroll table
scrollTable.redraw();

dataTable.resize(0, 2);

// Just adding some trivial data
for (int i = 0; i < 15; i++) {
dataTable.insertRow(i);
dataTable.setHTML(i, 1, "task " + i);
}

return scrollTable;
}

}

G. Georgopoulos

unread,
Jan 3, 2009, 10:32:31 AM1/3/09
to gwt-m...@googlegroups.com
Hi Alejandro,

try this:

import org.gwt.mosaic.ui.client.ToolBar;
import org.gwt.mosaic.ui.client.ToolButton;
import org.gwt.mosaic.ui.client.WindowPanel;

import org.gwt.mosaic.ui.client.layout.BorderLayout;
import org.gwt.mosaic.ui.client.layout.BorderLayoutData;
import org.gwt.mosaic.ui.client.layout.BoxLayout;
import org.gwt.mosaic.ui.client.layout.BoxLayoutData;
import org.gwt.mosaic.ui.client.layout.LayoutPanel;
import org.gwt.mosaic.ui.client.layout.BorderLayout.Region;
import org.gwt.mosaic.ui.client.layout.BoxLayout.Orientation;
import org.gwt.mosaic.ui.client.layout.BoxLayoutData.FillStyle;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.gen2.table.client.FixedWidthFlexTable;
import com.google.gwt.gen2.table.client.FixedWidthGrid;
import com.google.gwt.gen2.table.client.ScrollTable;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/

public class Main implements EntryPoint {

/**
* This is the entry point method.
*/
public void onModuleLoad() {
final WindowPanel w = new WindowPanel("WindowPanel");
w.setSize("512px", "384px");
w.setAnimationEnabled(true);
w.setWidget(createContent());

Button b = new Button("Show WindowPanel");
b.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
w.center();
}
});

RootPanel.get().add(b);
}

private Widget createContent() {
final LayoutPanel vbox = new LayoutPanel(

new BoxLayout(Orientation.VERTICAL));
vbox.setPadding(0);
vbox.setWidgetSpacing(0);

final ToolBar toolBar = new ToolBar();
vbox.add(toolBar, new BoxLayoutData(FillStyle.HORIZONTAL));

toolBar.add(new ToolButton("Button 1"));
toolBar.add(new ToolButton("Button 2"));
toolBar.addSeparator();
toolBar.add(new ToolButton("Button 3"));

final LayoutPanel b1 = new LayoutPanel(new BorderLayout());
vbox.add(b1, new BoxLayoutData(FillStyle.BOTH));

final LayoutPanel b2 = new LayoutPanel(new BorderLayout());
b2.setPadding(0);

b1.add(newScrollTable1(), new BorderLayoutData(Region.NORTH, .3, 10,
300, true));
b1.add(newScrollTable1(), new BorderLayoutData(Region.WEST, .3, 10,
300, true));
b1.add(b2);

b2.add(newScrollTable1(), new BorderLayoutData(Region.NORTH, .4, 10,
300, true));
b2.add(newScrollTable1(), new BorderLayoutData(true));

return vbox;
}

private Widget newScrollTable1() {
final FixedWidthFlexTable headerTable = new FixedWidthFlexTable();
final FixedWidthGrid dataTable = new FixedWidthGrid();

final ScrollTable scrollTable = new ScrollTable(dataTable, headerTable);
scrollTable.setCellPadding(3);
scrollTable.setCellSpacing(1);
scrollTable.setResizePolicy(ScrollTable.ResizePolicy.FILL_WIDTH);

headerTable.setText(0, 0, "NAME");
headerTable.setText(0, 1, "VALUE");

// Redraw the scroll table
scrollTable.redraw();

dataTable.resize(0, 2);

// Just adding some trivial data
for (int i = 0; i < 15; i++) {
dataTable.insertRow(i);
dataTable.setHTML(i, 1, "task " + i);
}

return scrollTable;
}

}

Kind Regards,
George.

Alejandro D. Garin

unread,
Jan 3, 2009, 11:07:21 AM1/3/09
to gwt-m...@googlegroups.com
Perfect!!

Thank you George.

G. Georgopoulos

unread,
Jan 5, 2009, 9:49:44 PM1/5/09
to gwt-m...@googlegroups.com
Hi Alejandro,

the issue is fixed in SVN:
http://code.google.com/p/gwt-mosaic/source/detail?r=511

Thanks,
George.

Alejandro D. Garin

unread,
Jan 6, 2009, 10:31:47 AM1/6/09
to gwt-m...@googlegroups.com
Thank you George, the fix is working.
Reply all
Reply to author
Forward
0 new messages