package com.vaadin.tests.components.select;\r
\r
+import java.util.ArrayList;\r
import java.util.LinkedHashMap;\r
+import java.util.List;\r
\r
import com.vaadin.data.Container;\r
import com.vaadin.data.Item;\r
import com.vaadin.data.util.IndexedContainer;\r
+import com.vaadin.event.Action;\r
import com.vaadin.event.ItemClickEvent;\r
import com.vaadin.event.ItemClickEvent.ItemClickListener;\r
import com.vaadin.event.ItemClickEvent.ItemClickNotifier;\r
+import com.vaadin.terminal.Resource;\r
import com.vaadin.tests.components.abstractfield.AbstractFieldTest;\r
import com.vaadin.ui.AbstractSelect;\r
\r
private int items = 0;\r
private int properties = 0;\r
\r
+ protected static class ContextMenu {\r
+\r
+ private List<Action> items = new ArrayList<Action>();\r
+\r
+ public ContextMenu(String caption, Resource icon) {\r
+ addItem(caption, icon);\r
+ }\r
+\r
+ public ContextMenu() {\r
+ }\r
+\r
+ public void addItem(String caption, Resource icon) {\r
+ items.add(new Action(caption, icon));\r
+ }\r
+\r
+ public Action[] getActions() {\r
+ Action[] actions = new Action[items.size()];\r
+ for (int i = 0; i < items.size(); i++) {\r
+ actions[i] = items.get(i);\r
+ }\r
+\r
+ return actions;\r
+ }\r
+\r
+ }\r
+\r
@Override\r
protected void createActions() {\r
super.createActions();\r
import java.util.LinkedHashMap;\r
import java.util.List;\r
\r
+import com.vaadin.event.Action;\r
+import com.vaadin.event.Action.Handler;\r
import com.vaadin.event.ItemClickEvent.ItemClickListener;\r
import com.vaadin.tests.components.select.AbstractSelectTestCase;\r
import com.vaadin.ui.AbstractSelect.MultiSelectMode;\r
}\r
};\r
\r
+ private Command<Table, ContextMenu> contextMenuCommand = new Command<Table, ContextMenu>() {\r
+\r
+ public void execute(Table c, final ContextMenu value, Object data) {\r
+ c.removeAllActionHandlers();\r
+ if (value != null) {\r
+ c.addActionHandler(new Handler() {\r
+\r
+ public void handleAction(Action action, Object sender,\r
+ Object target) {\r
+ log("Action " + action.getCaption() + " performed on "\r
+ + target);\r
+ }\r
+\r
+ public Action[] getActions(Object target, Object sender) {\r
+ return value.getActions();\r
+ }\r
+ });\r
+ }\r
+ }\r
+ };\r
+\r
/* COMMANDS END */\r
\r
@Override\r
createColumnCollapsingAllowedCheckbox(CATEGORY_FEATURES);\r
\r
createVisibleColumnsMultiToggle(CATEGORY_VISIBLE_COLUMNS);\r
+ createContextMenuAction(CATEGORY_FEATURES);\r
\r
}\r
\r
+ private void createContextMenuAction(String category) {\r
+ LinkedHashMap<String, ContextMenu> options = new LinkedHashMap<String, ContextMenu>();\r
+ options.put("None", null);\r
+ options.put("Item without icon", new ContextMenu("No icon", null));\r
+ ContextMenu cm = new ContextMenu();\r
+ cm.addItem("Caption only", null);\r
+ cm.addItem("Has icon", ICON_16_USER_PNG_UNCACHEABLE);\r
+ options.put("With and without icon", cm);\r
+ options.put("Only one large icon", new ContextMenu("Icon",\r
+ ICON_64_EMAIL_REPLY_PNG_UNCACHEABLE));\r
+\r
+ createSelectAction("Context menu", category, options, "None",\r
+ contextMenuCommand, true);\r
+ }\r
+\r
private void createColumnReorderingAllowedCheckbox(String category) {\r
createBooleanAction("Column reordering allowed", category, true,\r
new Command<Table, Boolean>() {\r
import com.vaadin.data.Container;\r
import com.vaadin.data.Container.Hierarchical;\r
import com.vaadin.data.util.HierarchicalContainer;\r
+import com.vaadin.event.Action;\r
+import com.vaadin.event.Action.Handler;\r
import com.vaadin.tests.components.select.AbstractSelectTestCase;\r
import com.vaadin.ui.AbstractSelect.MultiSelectMode;\r
import com.vaadin.ui.Tree;\r
\r
};\r
\r
+ private Command<Tree, ContextMenu> contextMenuCommand = new Command<Tree, ContextMenu>() {\r
+\r
+ public void execute(Tree c, final ContextMenu value, Object data) {\r
+ c.removeAllActionHandlers();\r
+ if (value != null) {\r
+ c.addActionHandler(new Handler() {\r
+\r
+ public void handleAction(Action action, Object sender,\r
+ Object target) {\r
+ log("Action " + action.getCaption() + " performed on "\r
+ + target);\r
+ }\r
+\r
+ public Action[] getActions(Object target, Object sender) {\r
+ return value.getActions();\r
+ }\r
+ });\r
+ }\r
+ }\r
+ };\r
+\r
@Override\r
protected Class<Tree> getTestClass() {\r
return Tree.class;\r
\r
createListeners(CATEGORY_LISTENERS);\r
createItemStyleGenerator(CATEGORY_FEATURES);\r
-\r
+ createContextMenuAction(CATEGORY_FEATURES);\r
// TODO: DropHandler\r
// TODO: DragMode\r
// TODO: ActionHandler\r
\r
}\r
\r
+ private void createContextMenuAction(String category) {\r
+ LinkedHashMap<String, ContextMenu> options = new LinkedHashMap<String, ContextMenu>();\r
+ options.put("None", null);\r
+ options.put("Item without icon", new ContextMenu("No icon", null));\r
+ ContextMenu cm = new ContextMenu();\r
+ cm.addItem("Caption only", null);\r
+ cm.addItem("Has icon", ICON_16_USER_PNG_UNCACHEABLE);\r
+ options.put("With and without icon", cm);\r
+ options.put("Only one large icon", new ContextMenu("Icon",\r
+ ICON_64_EMAIL_REPLY_PNG_UNCACHEABLE));\r
+\r
+ createSelectAction("Context menu", category, options, "None",\r
+ contextMenuCommand, true);\r
+ }\r
+\r
private void createItemStyleGenerator(String category) {\r
\r
LinkedHashMap<String, com.vaadin.ui.Tree.ItemStyleGenerator> options = new LinkedHashMap<String, com.vaadin.ui.Tree.ItemStyleGenerator>();\r