Global and dynamic context menu - vaadin

I have an application which uses a lot (~1000) little components which all have a context menu associated running on Vaadin 23.
This creates a huge amount of data transfered from the server to the client (each right click is a javascript instruction, encapsulated into the json, etc).
I would like to reduce this amount of data, and create :
Only one global context menu listener (maybe on the parent component).
A dynamic menu items, depending on which subcomponent I right click, it should show different items.
I try a few options, using the addOpenedChangeListener or addAttachListener, but none of these method are able to dynamically create items in the context menu.
Is there a way to achieve the dynamic creation of menu items and identification of clicked item ?

Related

Umbraco, how to add onChange functionality on dropdown content backoffice?

I am having one document type which contains a dropdown list, I need to add a couple of things in it:
I need to display the Database table names in drop-down dynamically.
On the change of dropdown option, i need to display the selected table columns names in another drop-down.
Are above things possible by using only existing data types or it will require creating a custom template using razor syntaxes (if it is so then how the template will display directly in the back office content node?)
Can you please provide your views and any links for code/tutorials?
screen shot of content form
If this is for the back office, you will need to do it in HTML and Angular, with an API controller to handle the DB lookup stuff.
As far as I'm aware, there's nothing built in to do dropdowns that depend on each other, so you'd have to create a new DataType to do it.
The process is to long to detail here, but here are some useful links on creating custom DocTypes in Umbraco 7.
https://our.umbraco.org/documentation/tutorials/Creating-a-Property-Editor/
http://velstand.info/tips/umbraco/to-create-a-datatype-by-using-external-data-sources/
https://24days.in/umbraco-cms/2016/custom-property-editor-tutorial/

Vaadin: How to remove item from DB container grid

How do I remove a row from a container/item/grid/db/entity/bean/class/object/ID?
Also, what's the difference between all these?
Everyone seems to say these as if they were interchangeable.
Can I get a simple explanation of how these all work together?
I've been through dozens of youtube videos and tutorials, but I still can't see the big picture.
Simple task: Delete one row from a grid.
But then it starts getting bigger and more complex with nested beanitem container property field entities and I just can't make sense of it.
Thank you for all of your help in advance!
The Grid, Table or any other Vaadin Component used to present set of data use some implementation of the Container to store your data. A Component is a part of your User Interface, the <div> in your DOM which is seen by your end user. The Vaadin Containers contains your objects. The most widely used containers are:
IndexedContainer - default container for Grid and Table. You usually add items by calling addItem method on either container or related component. The disadvantage of using this type of container is that you are usually obligated to set appropriate properties (think of columns) on both items and the container itself,
BeanContainer - is able to receive Java objects that follows JavaBean convention. Thus it is able to automatically infer properties of your component,
SQLContainer - contains data stored in database. Constructed using SQL query. Can be setup to automatically update your database based on changes made by user in UI.
Items and IDs
Adding single items to some containers may look a bit complicated. There are a few ways to do this. They are described very well on a Vaadin website. Basically the ID is an unique object that you use to access corresponding Item. The Item is represents the single row in your component. Every Item have properties. You can access and make changes to your items in container using their IDs i.e.
table.getItem("uniqueId");
Usually, you don't operate directly on containers. The components expose basic Container interface methods via their API. In example implementation of AbstractSelect.getItem() component currently (Vaadin 7.5.9):
protected Container items;
public Item getItem(Object itemId) {
return items.getItem(itemId);
}
(AbstractSelect is a super class of other Vaadin components like Table and Grid)
It gets more complicated with properties of the items. Every Item have some properties (columns). And every Property has its corresponding ID. Using property ID you can access the value of the item in the specific column. The following code presents above - it adds one item with one property and sets its value:
Table table = new Table();
table.addContainerProperty("column1", String.class, "defaultValue");
Item item = table.addItem("uniqueId");
item.getItemProperty("column1").setValue("Black Friday");
Notice that it is perfectly safe to use String literals as IDs since underneath they are compared using equals()

Rendering subcategories on click in asp.net mvc3

I am new to mvc3, developing my first project in mvc3. I have left side bar filled with top categories. On click of top category, I want to display sub categories under clicked category.
Subcategories can be at any no of level.
How to go for it?
Should I use partial views?
On click of category, first I have to check if it has a subcategory, if yes then render sub categories.
I think your best option here is to use AJAX and dynamic load of data.
On your javascript code bind the click event of your first level nodes to an AJAX call to a method on the server.
This method should: check if the node has children, if it has then return the list of children associated to it, if it hasn't it should return some info adverting your client code about it.
Your AJAX call on success should check if receive a list of subnodes or a message adverting that there's no subnodes. If it has the subnodes just append them to your html structure, if it hasn't do nothing (or whatever you want to do when clicking on a top node without children).
From here you can make your system grow in complexity as much as you want, using different methods for different node levels and behaviours, etc...

MVC selectable GridView

I am designing a webpage using MVC. One of the pages has the following controls and functions:
Controls:
2 GridViews (gvItems, gvSelectedItems)
3 buttons (btnTransferSingle, btnTransferAll, submit)
Functions
gvItems will be populated with a set of items that contains: Name, points
gvSelectedItems will contain items that is transferred from gvItems. Hence it will also contain: Name, points
both GirdViews supports multiple selection
btnTransferSingle will transfer all selected items from gvItems to gvSelectedItems.
btnTransferAll will transfer all remaining items from gvItems to gvSelectedItems.
btnSubmit will send all the items from gvSelectedItems to the Controller.
I am not sure how to the following:
1) How to create a gridview that supports multiselection and displaying of multiple model attribute.
2) How to transfer the items from one gridview (gvItems) to another (gvSelectedItems)?
3) How to pass back all the items from gvSelectedItems to the controller?
I am able to do the stuff that was mentioned using listBox but listBox only allows displaying of only one attribute and doesn't have a header.
I used Matt Kruse Javascript's Toolbox to aid the moving of items between listboxes.
Any help is appreciated. Thanks.
I think that listboxes are the correct approach here.
If you want to display both attributes try to concatenate them when loading the data.
Headers can be somewhat added with html/css

XUL: Multiple reuse of an overlay in same file?

I'm developing a Firefox extension. There is a menu X which I need to show in both Tools menu and Context menu. Tools menu item and Context menu item are defined in same file but menu X in another file.
As I'm reusing menu X by id only last use of it is effective. How can I reuse it multiple time in same file without redundancy?
It can be done using XBL.
I haven't found a good solution either. The approach is rather to define the menu in the overlay only once and then clone it in your "load" event handler. You can then insert the clone at the second location. You have to be careful because ID attributes have to stay unique - so if your menu uses ID attributes you will have to additionally rewrite them. Ugly, I know.
IDs are, per definitionem, unique. That means you can't share the menuitem but you can share the code that gets executed when the action is invoked. One way to achieve this is to use commands.

Resources