From 382942782d2bfcbac01900acc18d4398e179bc96 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 28 Dec 2010 09:41:20 +0000 Subject: [PATCH] Context menu support svn changeset:16678/svn branch:6.5 --- .../select/AbstractSelectTestCase.java | 30 ++++++++++++++ .../vaadin/tests/components/table/Tables.java | 39 ++++++++++++++++++ .../vaadin/tests/components/tree/Trees.java | 40 ++++++++++++++++++- 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/tests/src/com/vaadin/tests/components/select/AbstractSelectTestCase.java b/tests/src/com/vaadin/tests/components/select/AbstractSelectTestCase.java index dda942eabd..43500e8947 100644 --- a/tests/src/com/vaadin/tests/components/select/AbstractSelectTestCase.java +++ b/tests/src/com/vaadin/tests/components/select/AbstractSelectTestCase.java @@ -1,13 +1,17 @@ package com.vaadin.tests.components.select; +import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.List; import com.vaadin.data.Container; import com.vaadin.data.Item; import com.vaadin.data.util.IndexedContainer; +import com.vaadin.event.Action; import com.vaadin.event.ItemClickEvent; import com.vaadin.event.ItemClickEvent.ItemClickListener; import com.vaadin.event.ItemClickEvent.ItemClickNotifier; +import com.vaadin.terminal.Resource; import com.vaadin.tests.components.abstractfield.AbstractFieldTest; import com.vaadin.ui.AbstractSelect; @@ -19,6 +23,32 @@ public abstract class AbstractSelectTestCase extends private int items = 0; private int properties = 0; + protected static class ContextMenu { + + private List items = new ArrayList(); + + public ContextMenu(String caption, Resource icon) { + addItem(caption, icon); + } + + public ContextMenu() { + } + + public void addItem(String caption, Resource icon) { + items.add(new Action(caption, icon)); + } + + public Action[] getActions() { + Action[] actions = new Action[items.size()]; + for (int i = 0; i < items.size(); i++) { + actions[i] = items.get(i); + } + + return actions; + } + + } + @Override protected void createActions() { super.createActions(); diff --git a/tests/src/com/vaadin/tests/components/table/Tables.java b/tests/src/com/vaadin/tests/components/table/Tables.java index 03858b0bf1..b07be85177 100644 --- a/tests/src/com/vaadin/tests/components/table/Tables.java +++ b/tests/src/com/vaadin/tests/components/table/Tables.java @@ -5,6 +5,8 @@ import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; +import com.vaadin.event.Action; +import com.vaadin.event.Action.Handler; import com.vaadin.event.ItemClickEvent.ItemClickListener; import com.vaadin.tests.components.select.AbstractSelectTestCase; import com.vaadin.ui.AbstractSelect.MultiSelectMode; @@ -118,6 +120,27 @@ public class Tables extends AbstractSelectTestCase implements } }; + private Command contextMenuCommand = new Command() { + + public void execute(Table c, final ContextMenu value, Object data) { + c.removeAllActionHandlers(); + if (value != null) { + c.addActionHandler(new Handler() { + + public void handleAction(Action action, Object sender, + Object target) { + log("Action " + action.getCaption() + " performed on " + + target); + } + + public Action[] getActions(Object target, Object sender) { + return value.getActions(); + } + }); + } + } + }; + /* COMMANDS END */ @Override @@ -145,9 +168,25 @@ public class Tables extends AbstractSelectTestCase
implements createColumnCollapsingAllowedCheckbox(CATEGORY_FEATURES); createVisibleColumnsMultiToggle(CATEGORY_VISIBLE_COLUMNS); + createContextMenuAction(CATEGORY_FEATURES); } + private void createContextMenuAction(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("None", null); + options.put("Item without icon", new ContextMenu("No icon", null)); + ContextMenu cm = new ContextMenu(); + cm.addItem("Caption only", null); + cm.addItem("Has icon", ICON_16_USER_PNG_UNCACHEABLE); + options.put("With and without icon", cm); + options.put("Only one large icon", new ContextMenu("Icon", + ICON_64_EMAIL_REPLY_PNG_UNCACHEABLE)); + + createSelectAction("Context menu", category, options, "None", + contextMenuCommand, true); + } + private void createColumnReorderingAllowedCheckbox(String category) { createBooleanAction("Column reordering allowed", category, true, new Command() { diff --git a/tests/src/com/vaadin/tests/components/tree/Trees.java b/tests/src/com/vaadin/tests/components/tree/Trees.java index 83457d3708..dbb340d0ef 100644 --- a/tests/src/com/vaadin/tests/components/tree/Trees.java +++ b/tests/src/com/vaadin/tests/components/tree/Trees.java @@ -8,6 +8,8 @@ import java.util.List; import com.vaadin.data.Container; import com.vaadin.data.Container.Hierarchical; import com.vaadin.data.util.HierarchicalContainer; +import com.vaadin.event.Action; +import com.vaadin.event.Action.Handler; import com.vaadin.tests.components.select.AbstractSelectTestCase; import com.vaadin.ui.AbstractSelect.MultiSelectMode; import com.vaadin.ui.Tree; @@ -76,6 +78,27 @@ public class Trees extends AbstractSelectTestCase implements }; + private Command contextMenuCommand = new Command() { + + public void execute(Tree c, final ContextMenu value, Object data) { + c.removeAllActionHandlers(); + if (value != null) { + c.addActionHandler(new Handler() { + + public void handleAction(Action action, Object sender, + Object target) { + log("Action " + action.getCaption() + " performed on " + + target); + } + + public Action[] getActions(Object target, Object sender) { + return value.getActions(); + } + }); + } + } + }; + @Override protected Class getTestClass() { return Tree.class; @@ -94,13 +117,28 @@ public class Trees extends AbstractSelectTestCase implements createListeners(CATEGORY_LISTENERS); createItemStyleGenerator(CATEGORY_FEATURES); - + createContextMenuAction(CATEGORY_FEATURES); // TODO: DropHandler // TODO: DragMode // TODO: ActionHandler } + private void createContextMenuAction(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("None", null); + options.put("Item without icon", new ContextMenu("No icon", null)); + ContextMenu cm = new ContextMenu(); + cm.addItem("Caption only", null); + cm.addItem("Has icon", ICON_16_USER_PNG_UNCACHEABLE); + options.put("With and without icon", cm); + options.put("Only one large icon", new ContextMenu("Icon", + ICON_64_EMAIL_REPLY_PNG_UNCACHEABLE)); + + createSelectAction("Context menu", category, options, "None", + contextMenuCommand, true); + } + private void createItemStyleGenerator(String category) { LinkedHashMap options = new LinkedHashMap(); -- 2.39.5