]> source.dussan.org Git - vaadin-framework.git/commitdiff
Context menu support
authorArtur Signell <artur.signell@itmill.com>
Tue, 28 Dec 2010 09:41:20 +0000 (09:41 +0000)
committerArtur Signell <artur.signell@itmill.com>
Tue, 28 Dec 2010 09:41:20 +0000 (09:41 +0000)
svn changeset:16678/svn branch:6.5

tests/src/com/vaadin/tests/components/select/AbstractSelectTestCase.java
tests/src/com/vaadin/tests/components/table/Tables.java
tests/src/com/vaadin/tests/components/tree/Trees.java

index dda942eabd09e8653baad4c3bdb06938790b83ab..43500e8947fe33a5782cf6402e6a85500ccdd590 100644 (file)
@@ -1,13 +1,17 @@
 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
@@ -19,6 +23,32 @@ public abstract class AbstractSelectTestCase<T extends AbstractSelect> extends
     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
index 03858b0bf11715dd8a9c670f87975ffc1f59cf54..b07be85177aef9c7f79eedcb96be2ff608cbadb0 100644 (file)
@@ -5,6 +5,8 @@ import java.util.Arrays;
 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
@@ -118,6 +120,27 @@ public class Tables extends AbstractSelectTestCase<Table> implements
         }\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
@@ -145,9 +168,25 @@ public class Tables extends AbstractSelectTestCase<Table> implements
         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
index 83457d370899dddafb8a7b1367f7f9ed383972d9..dbb340d0efb04d8b16473278090d2614b41f441f 100644 (file)
@@ -8,6 +8,8 @@ import java.util.List;
 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
@@ -76,6 +78,27 @@ public class Trees extends AbstractSelectTestCase<Tree> implements
 \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
@@ -94,13 +117,28 @@ public class Trees extends AbstractSelectTestCase<Tree> implements
 \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