Giter Site home page Giter Site logo

context-menu's Introduction

Published on Vaadin  Directory Stars on Vaadin Directory

Vaadin ContextMenu Add-on

Vaadin ContextMenu is an UI component add-on for Vaadin Framework.

Online demo

Try the add-on demo at https://demo.vaadin.com/sampler/#addons/contextmenu

Download release

Official releases of this add-on are available at Vaadin Directory. For Maven instructions, download and reviews, go to https://vaadin.com/addon/vaadin-contextmenu

Building and running demo

git clone https://github.com/vaadin/context-menu.git
cd context-menu
mvn install
cd vaadin-context-menu-demo
mvn jetty:run

To see the demo, navigate to http://localhost:8080/

Release notes

Version 3.1.0 - Latest version for Vaadin Framework 8

  • Change to use SerializableEventListener

Version 3.0.0 - Rewritten for Vaadin Framework 8

The context menu was rewritten from scratch, but API was kept compatible with version 2.x. Required Framework version is 8.6+. Key improvements are:

  • Tree context click support
  • BrowserWindowOpener support for menu items, i.e. now it's possible to open new browser instances by clicking menu items
  • FileDownloader support for menu items, i.e. now it's possible to download files by clicking menu items
  • HTML format for items is implemented
  • Numerous bugfixes

Version 2.1.0 - Context Menu for Vaadin Framework 8

  • Bugfixes
  • HTML tooltips support

Version 0.7.5 - Latest version for Vaadin Framework 7

  • Basic support for component context menu everywhere
  • Basic code examples
  • Use ContextClickEvent API introduced in Vaadin 7.6

Version 2.0.0 - Context Menu for Vaadin Framework 8

  • Support for Vaadin Framework 8
  • Renamed the groupId to com.vaadin from `com.vaadin.addon
  • Renamed the packaging to com.vaadin.contextmenu from com.vaadin.addon.contextmenu
  • Renamed widgetset to com.vaadin.contextmenu.WidgetSet from com.vaadin.addon.contextmenu.WidgetSet

Issue tracking

The issues for this add-on are tracked on its github.com page. All bug reports and feature requests are appreciated.

Contributions

Contributions are welcome, but there are no guarantees that they are accepted as such. Please contact [email protected]

License & Author

Add-on is distributed under Apache License 2.0. For license terms, see LICENSE.

ContextMenu is written by Vaadin Ltd.

Developer Guide

Getting started

Check a demo application included.

context-menu's People

Contributors

alvarezguille avatar ansku avatar artur- avatar binbalenci avatar hesara avatar juergenkoras avatar legioth avatar maxschuster avatar mtzukanov avatar mvysny avatar philippberger avatar pleku avatar samie avatar tatulund avatar tfyre avatar tsuoanttila avatar zhesun88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

context-menu's Issues

Allow buttons to be placed inside menu

It would be great if Context Menu allow the placement of buttons as menu elements. This is allowed in MenuBar and there are certain situations where this is needed in order to perform certain actions. For instance, opening new browser windows / tabs does need to .extend(someComponent), but MenuItems are not Components, so it's impossible to open a new browser window / tab from Context Menu.

My assumption is that it wouldn't be that difficult to add this functionality...

TreeGrid support

Is there any support for TreeGrid planned ? Can we move to Vaadin 8.1 ? I tried with the GridContextMenu, but the context menu does not close after left-clicking a menu item and the menu action is called multiple times (I supposed once for every predecessor of the tree node that the menu was opened on).

Add the possibility to hide the menu

There should be an option to hide the menu completely if some items don't match some cases. This is very important for a GridContextMenu. I want to show only menu items on special items not for all. For the moment this is not possible, because you can't hide the menu. removing all items from the menu returns a black line (the menu without any items).

context menu does not release resources

class ContextMenuConnector registers a native preview event handler (in method #init), but never releases it. This is both a problem of memory (widget never get released, including all stuff hanging on those objects) and of performance (more and more handlers have to be invoked with every native event)

Menu should be opened inside visible area

Menu is always opened with its upper left corner at the mouse pointer.
If the mouse pointer is in the lower part of the screen this means that the bottom of the menu can be outside the visible area.

The menu should be moved up (and to the left) until it is inside visible area, but not so far that the top is clipped.
Ideally, if the menu is too high for the screen, it should have some sort of scroll.

Same problem for submenus.

Arrow keys stop working after opening context menu

After opening the context menu, the up/down cursors don't work anymore.

Steps to reproduce:

  1. right click on an item in the grid
  2. click somewhere to close the context menu
  3. try using up/down key inside the grid
@Theme("mytheme")
public class TestUI extends UI {

    @WebServlet(urlPatterns = "/*", name = "TestUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = TestUI.class, productionMode = false)
    public static class TestUIServlet extends VaadinServlet {
    }

    public class TestBean {
        private String name = "name";
        private String value = "value";

        public String getName() {
            return name;
        }

        public void setName(String inName) {
            name = inName;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String inValue) {
            value = inValue;
        }

    }

    private Grid<TestBean> grid = new Grid<TestBean>(TestBean.class);
    private GridContextMenu<TestBean> contextMenu = new GridContextMenu<>(grid);
    private ArrayList<TestBean> items = new ArrayList<>();

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        setContent(layout);
        
        items.add(new TestBean());

        grid.setDataProvider(new ListDataProvider<>(items));
        grid.setWidth("100%");
        grid.setHeight("400px");

        layout.addComponent(grid);

        contextMenu.addContextMenuOpenListener(event -> handleOpen(event));
    }

    private void handleOpen(ContextMenuOpenEvent inEvent) {
        contextMenu.removeItems();
        contextMenu.addItem("test1", event -> System.out.println("clicked 1"));
        contextMenu.addItem("test2", event -> System.out.println("clicked 2"));
    }

}

Should be possible to close menu with Escape

Currently, the only way to close the menu is to click outside it.
Looking at regular menus in Windows, it seems that it is standard to also close on Escape.
It would be nice if the Vaadin ContextMenu also supported this.

Please remember to allow Escape to propagate to other components if the menu is not open.

css filename error in log

Contextmenu gwt.xml file has this

    <!-- Widget styles in public -directory -->
    <stylesheet src="context-menu/styles.css"/>

And in the log file, I get these warnings?

2015-12-01 14:50:14.630  INFO 7380 --- [ XNIO-1 task-16] com.vaadin.server.VaadinServlet          : Requested resource [/VAADIN/widgetsets/com.globalbilisim.nostro.WidgetSet/context-menu/styles.css] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.
2015-12-01 14:50:17.555  INFO 7380 --- [ XNIO-1 task-23] com.vaadin.server.VaadinServlet          : Requested resource [/VAADIN/widgetsets/com.globalbilisim.nostro.WidgetSet/context-menu/styles.css] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.
2015-12-01 14:50:19.290  INFO 7380 --- [ XNIO-1 task-33] ContextMenu                              : beforeClientResponse
2015-12-01 14:50:19.291  INFO 7380 --- [ XNIO-1 task-33] ContextMenu                              : beforeClientResponse
2015-12-01 14:51:16.574  INFO 7380 --- [ XNIO-1 task-45] ContextMenu                              : Context click listener

css file is under context-menu2 folder and seems working but this is logged. Also everytime I click the contect menu, it logs above.

Clicking on a menu item that has submenus should not close the popup menu

This is important for our automation testing procedures.
For example, on a menu bar menu item you can click on a menu item in order to select it (instead of hovering), and that gets the submenu to popup.
In this tool the whole popup menu closes on clicking an entry, even if the entry is just the parent ofr submenus.

After adding Gridcontextmenu everywhere visible

After adding the GridContextmenu to a Grid or Treegrid the menu ist already visible (only a short black line, because not items are added yet). I haven't added any header, body or footer listener yet. Should this be the case?
I would expect, that a menu is only visible after adding a menu to header, body or footer.
Furthermore after adding only a "addGridBodyContextMenuListener" the same menu appears in the header. I think this isn't correct yet.

Not compatible with java 1.7

I see its compiled with java 1.8 but I want to use it with 1.7. I tried to compile it by my own but has some compilation issues as below

[ERROR] Project/context-menu/vaadin-context-menu-addon/src/main/java/com/vaadin/addon/contextmenu/GridContextMenu.java:[24,71] local variable section is accessed from within inner class; needs to be declared final
[ERROR] Project/context-menu/vaadin-context-menu-addon/src/main/java/com/vaadin/addon/contextmenu/GridContextMenu.java:[25,49] local variable listener is accessed from within inner class; needs to be declared final

I don't want to maintain this by changing the code. How should I go about this?

Error: Grid motion cursors stop responding

Grid motion cursors stop responding. It happens when using the ContextMenu in a Grid. I press right click and it shows me the menu. Then, I press left-click outside the menu and from that moment the movement cursors (up, down to the sides) stop responding in the Grid.
It also happens in online examples, for example, at https://demo.vaadin.com/sampler/#addons/contextmenu
It occurs both in the version of Vaadin 8 and 7.

Description (Tooltip) ond menu item does not work

Hi,

I can't get a tooltip to show on menu items.

Reproduce:

  1. Go to http://demo.vaadin.com/context-menu-demo/
  2. Right-click on button to open the context-menu
  3. Hover over "Icon + Description + <b>HTML</b>"

According to the source there should be a tooltip on this menu item. It does not show when i do it. Tested with firefox and chromium on linux.
For my project i use contex-menu with vaadin 7 and it does not show the tooltip too.

btw. I'm not sure if this <b>HTML</b> is a bug as well

Thanks, raffael

Widget is detached before executing the command

#24 broke context menu for me. @mletenay already has investigated this issue.

@mletenay said:

When I mouseclick on the menu item, the standard Vaadin's (7.6.4) VMenuBar#itemClick is invoked:

hideParents(true);
menuVisible = false;
Scheduler.get().scheduleDeferred(item.getCommand());
The menu is hidden / detached and when the scheduled command is invoked it is ignored.
Am I doing something wrong or is this a bug ? What's actually meaning of that isAttached() check ?

ContextMenu is invisible

From @tkvtkv on April 18, 2017 11:51

I created a ContextMenu (vaadin-context-menu-0.7.4).

 ContextMenu contextMenu = new ContextMenu(this, false);
        contextMenu.setAsContextMenuOf(butTest);

        contextMenu.addContextMenuOpenListener(new ContextMenu.ContextMenuOpenListener() {
            public void onContextMenuOpen(ContextMenu.ContextMenuOpenListener.ContextMenuOpenEvent event) {
                Notification.show("Context menu on "
                        + event.getSourceComponent().getCaption());
            }
        });

        MenuItem basic = contextMenu.addItem("Basic Item", new ContextMenu.Command() {
            public void menuSelected(com.vaadin.addon.contextmenu.MenuItem selectedItem) {
                //main.addWindow(getAboutDialog());
                labAction.setValue("ContextMenu item 'Basic Item' selected " );
            }
        });

        MenuItem second = contextMenu.addItem("Second Item", new Menu.Command() {
            public void menuSelected(com.vaadin.addon.contextmenu.MenuItem menuItem) {
                labAction.setValue("ContextMenu item 'Second Item' selected " );
            }
        });

When I right mouse click on butTest I see a notification "Context menu on ..." only. But the Context menu is invisible.
contextmenu_notification

What I missed?
Please help me to understand what need to do to show a context menu.

Copied from original issue: vaadin/vaadin-core#102

ERROR] Line 15: The constructor VOverlay(boolean, boolean, boolean) is undefined

With following version:

<!-- https://mvnrepository.com/artifact/com.vaadin.addon/vaadin-context-menu -->
		<dependency>
			<groupId>com.vaadin.addon</groupId>
			<artifactId>vaadin-context-menu</artifactId>
			<version>0.7.5</version>
		</dependency>

I experience on latest Vaadin release:

INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ archive-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 133 source files to /home/zangetsu/proj/coreso/integration/commons/archive-service/target/classes
[WARNING] /home/zangetsu/proj/coreso/integration/commons/archive-service/src/main/java/org/archenroot/integration/commons/archive_service/backend/domain/entity/StringToEnumFactory.java: /home/zangetsu/proj/coreso/integration/commons/archive-service/src/main/java/org/archenroot/integration/commons/archive_service/backend/domain/entity/StringToEnumFactory.java uses unchecked or unsafe operations.
[WARNING] /home/zangetsu/proj/coreso/integration/commons/archive-service/src/main/java/org/archenroot/integration/commons/archive_service/backend/domain/entity/StringToEnumFactory.java: Recompile with -Xlint:unchecked for details.
[INFO] 
[INFO] --- vaadin-maven-plugin:8.1.3:compile (default) @ archive-service ---
[INFO] auto discovered modules [AppWidgetset]
[INFO] Using com.vaadin:vaadin-client version 8.1.3
[INFO] Using com.vaadin:vaadin-client-compiler version 8.1.3
[INFO] Compiling module AppWidgetset
[INFO]    Tracing compile failure path for type 'com.vaadin.addon.contextmenu.client.MyVOverlay'
[INFO]       [ERROR] Errors in 'jar:file:/home/zangetsu/.m2/repository/com/vaadin/addon/vaadin-context-menu/0.7.5/vaadin-context-menu-0.7.5.jar!/com/vaadin/addon/contextmenu/client/MyVOverlay.java'
[INFO]          [ERROR] Line 15: The constructor VOverlay(boolean, boolean, boolean) is undefined
[INFO]    [ERROR] Aborting compile due to errors in some input files

Doesn't work in combination with ItemClickListener

Code to reproduce, either listener works on its own but not together:

@SuppressWarnings("unchecked")
private TreeTable createTreeTable() {
    TreeTable table = new TreeTable();
    table.addContainerProperty("id", Integer.class, null);
    for (int i = 0; i < 10; ++i) {
        Item item = table.addItem(i);
        item.getItemProperty("id").setValue(i);
    }
    addItemClickListener(table);
    addContextMenu(table);
    return table;
}

private void addContextMenu(TreeTable table) {
    final ContextMenu menu = new ContextMenu(table, true);

    menu.addContextMenuOpenListener(event -> {
        System.out.println("context menu open!");
    });
}

private void addItemClickListener(TreeTable table) {
    table.addItemClickListener(event -> {
        if (event.isDoubleClick()) {
            System.out.println("double-click!");
        }
    });
}

css filename error in log - reopen

After some test, I confrim that this still continue. I believe it's due to gwt.xml:

Contextmenu gwt.xml file has this

<!-- Widget styles in public -directory -->
<stylesheet src="context-menu/styles.css"/>

info message:

2015-12-09 12:08:09.016  INFO 6700 --- [  XNIO-1 task-9] com.vaadin.server.VaadinServlet          : Requested resource [/VAADIN/widgetsets/vwscdn2b36d3d30e1dfdb8ec1f8cae96e8e870/context-menu/styles.css] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.

There's too much INFO logging going on

Seems to me to be "debug" type stuff that has been left behind.
As in ContextMenu.java:

logger.info("Context click listener");

Such should be removed or changed to another logging level.

Old version in pom

According to the Vaadin Directory the current version of this add-on is 0.7.2. But all pom.xml files of this project state the version as 0.7. The version number should be updated before every release. And after the release it should be changed to a SNAPSHOT release (e.g. 0.7.3-SNAPSHOT).

Receive focus on context click ?

Why is that a context-click (aka right-click) doesn't fire a focus event?
I'm just asking because I'm not fully aware how the same situation is in other frameworks, such a Swing.

To me there should be a least be an option for a context-click to also trigger a focus event. Not sure if such functionality belongs in the add-on or in the framework.

The consequence of not having the focus change on context-click is that the user gets very confused. "Which row did I actually click?" (surely not the one with the focus border).

On Grid I've currently semi-solved the problem by turning off completely the visual indicator for focus on cells. This I've done via CSS. For reference this works for me:

  // Turn off focus visual indication for grid cells
  .v-grid:focus .v-grid-cell-focused:before {
      display: none;
  }

However this will not solve the problem for those who still (for one reason or another) require the visual indicator for focus.

To solve this usability issue I still believe the best option is to have a context-click trigger a focus event as well.

Bug with reopening context menu

Hi, i find possible bug.

Problem occures when context menu was opened and i try to reopen it with right click.
In some cases when i trying to reopen menu, i saw rapidly animation of opening/closing and menu stays closed.

I tried to fix it by my own.
In class Overlay, method
hide(final boolean autoClosed, final boolean animateIn, final boolean animateOut)
i find this:

Overlay.this.setPreviewingAllNativeEvents(false);

As i can see, this line prevents opening of new menu, when closing animation still in process.
And closing animation action was hardcoded, when you call hide method.

In my case i fix this with overriding call of hide method in MyVOverlay clsss, and set animation false.

@Override public void hide(boolean autoClosed) { super.hide(autoClosed, false, false); }

ContextMenu not opening

Using versions:
Spring Boot,
Vaadin 8.1.2,
ContextMenu 2.0.0

I can't seem to get the ContextMenu to open. I can debug through the right click event until I get to 'GridContextMenu.open(int x, int y). The call in to the proxy to 'showContextMenu' doesn't seem to do anything.

    public void open(int x, int y) {
        getRpcProxy(ContextMenuClientRpc.class).showContextMenu(x, y);
    }

I have the same issue on the demo project and can't get contextmenus to open on any component. I'm not clear if I've missed out on some resource file configuration or if the code below should be enough.

GridContextMenu<FIXMessageEntry> gridMenu = new GridContextMenu<>(grid);
gridMenu.addItem("Say Hi", e -> Notification.show("Hi"));

Cannot be used with Vaadin Framework 8.1 Tree

Using ContextMenu with Vaadin Framework 8.1 Tree is a bit awkward. The Tree does not extend directly from Grid, but uses the new Composite concept to re-package TreeGrid in to a new component. The internal TreeGrid is not available for the user of Tree as it's a private field.

This is the first workaround for the issue I came up with:
Wnt/vaadin-fiddle@6df5870#diff-9678f070438ec4e39925356f264887b1R288
using reflection to get hold of the internal TreeGrid to be able to add the context menu to the Tree.

Second workaround uses a class that extends Tree to be able to call Composite's getCompositionRoot, casts the returned component and finally adds API for adding a context menu:

Wnt/vaadin-fiddle@4806d41#diff-2a47376b01da011f7fe17f8d4818266bR7

By using either workaround the ContextMenu works as expected, but there are some warnings in the server console:
WARNING: Ignoring RPC call to com.vaadin.shared.ContextClickRpc.contextClick in connector com.vaadin.ui.Tree(158) as no RPC implementation is registered

or in the 2nd version:
WARNING: Ignoring RPC call to com.vaadin.shared.ContextClickRpc.contextClick in connector org.vaadin.vaadinfiddle.vaadinfiddleprototype.components.TreeWithContextMenu(15) as no RPC implementation is registered

The ContextMenu class is not serializable

Hi, thank you for this awesome extension. Just a minor thing: the ContextMenu class is not serializable: the Logger logger is not serializable and the serialization fails:

Caused by: java.io.NotSerializableException: java.util.logging.Logger
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)

Perhaps the logger field should be static.

Nested ContextMenuItems not work properly

When I add MenuItem to existing MenuItem as sub menu items, I can only trigger parents items by ContextClickEvent. When I trigger ClickEvent (left mouse button), the submenu will show for a second and turn off all the ContextMenu item. Please explain why you implement it that way.

Grid tooltip overlaps with menu

If the grid-row where I right-click has a tooltip, the tooltip is opened on top of the menu.
To get rid of the tooltip I have to move the mouse out of the menu, move it around a bit and then back.

It seems the menu has z-index 20000, and the tooltip has 20001

MenuItem should implement EventTrigger

With the latest version of vaadin there is a support for extending MenuBar.MenuItem by a FileDownloader. This is possible because MenuBar.MenuItem is implementing the new interface EventTrigger.

This should be also supported by the MenuItems of a contextmenu.

Ignoring RPC to TreeServerRpc.contextClick as no RPC implementation is registered

This is a really weird issue. I have two Trees on the application. One is defined in the UI class and one in a custom component. When I click on the first Tree I get the context menus, but I get this warning when I try the same on the tree in the custom component:

WARNING: Ignoring RPC call to com.vaadin.shared.ui.tree.TreeServerRpc.contextClick in connector com.vaadin.ui.Tree(99) as no RPC implementation is registered

Any idea?

The sources are here. The custom component is here.

This is on version 0.7.5 since I'm using Vaadin 7.7.10.

Context Menu on tablets

Is there a way how to simulate right click on tablets? (iOS, Android) Any idea how to make context menu available on touch devices?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.