1 package com.vaadin.contextmenu; 2 3 import java.io.Serializable; 4 import java.util.List; 5 6 import com.vaadin.server.Resource; 7 8 public interface Menu extends Serializable { 9 10 /** 11 * This interface contains the layer for menu commands of the 12 * {@link com.vaadin.ui.MenuBar} class. It's method will fire when the user 13 * clicks on the containing {@link MenuItem}. The selected item is given as 14 * an argument. 15 */ 16 public interface Command extends Serializable { 17 public void menuSelected(MenuItem selectedItem); 18 } 19 20 /** 21 * Add a new item to the menu bar. Command can be null, but a caption must 22 * be given. 23 * 24 * @param caption 25 * the text for the menu item 26 * @param command 27 * the command for the menu item 28 * @throws IllegalArgumentException 29 */ 30 public abstract MenuItem addItem(String caption, Command command); 31 32 /** 33 * Add a new item to the menu bar. Icon and command can be null, but a 34 * caption must be given. 35 * 36 * @param caption 37 * the text for the menu item 38 * @param icon 39 * the icon for the menu item 40 * @param command 41 * the command for the menu item 42 * @throws IllegalArgumentException 43 */ 44 public abstract MenuItem addItem(String caption, Resource icon, 45 Command command); 46 47 /** 48 * Add an item before some item. If the given item does not exist the item 49 * is added at the end of the menu. Icon and command can be null, but a 50 * caption must be given. 51 * 52 * @param caption 53 * the text for the menu item 54 * @param icon 55 * the icon for the menu item 56 * @param command 57 * the command for the menu item 58 * @param itemToAddBefore 59 * the item that will be after the new item 60 * @throws IllegalArgumentException 61 */ 62 public abstract MenuItem addItemBefore(String caption, Resource icon, 63 Command command, MenuItem itemToAddBefore); 64 65 /** 66 * Returns a list with all the MenuItem objects in the menu bar 67 * 68 * @return a list containing the MenuItem objects in the menu bar 69 */ 70 public abstract List<MenuItem> getItems(); 71 72 /** 73 * Remove first occurrence the specified item from the main menu 74 * 75 * @param item 76 * The item to be removed 77 */ 78 public abstract void removeItem(MenuItem item); 79 80 /** 81 * Empty the menu bar 82 */ 83 public abstract void removeItems(); 84 85 /** 86 * Returns the size of the menu. 87 * 88 * @return The size of the menu 89 */ 90 public abstract int getSize(); 91 92 /** 93 * Sets whether html is allowed in the item captions. If set to true, the 94 * captions are passed to the browser as html and the developer is 95 * responsible for ensuring no harmful html is used. If set to false, the 96 * content is passed to the browser as plain text. 97 * 98 * @param htmlContentAllowed 99 * true if the captions are used as html, false if used as plain 100 * text 101 */ 102 public abstract void setHtmlContentAllowed(boolean htmlContentAllowed); 103 104 /** 105 * Checks whether item captions are interpreted as html or plain text. 106 * 107 * @return true if the captions are used as html, false if used as plain 108 * text 109 * @see #setHtmlContentAllowed(boolean) 110 */ 111 public abstract boolean isHtmlContentAllowed(); 112 113 }