summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/ui
diff options
context:
space:
mode:
authorJouni Koivuviita <jouni.koivuviita@itmill.com>2009-11-11 08:05:38 +0000
committerJouni Koivuviita <jouni.koivuviita@itmill.com>2009-11-11 08:05:38 +0000
commitc73e3e3a8ba21df09967896ad6b238c098809b47 (patch)
treeb11a4e321b7f0f93ae348dd0a6aa1525b3a7af5a /src/com/vaadin/ui
parentaee045e3d09ef620743f5d0bc6e66065d9ea9b28 (diff)
downloadvaadin-framework-c73e3e3a8ba21df09967896ad6b238c098809b47.tar.gz
vaadin-framework-c73e3e3a8ba21df09967896ad6b238c098809b47.zip
MenuBar fixes (again)
* Fix submenu indicators for IE * Fixes #3678: enhancement: MenuBar needs a separator item svn changeset:9722/svn branch:6.2
Diffstat (limited to 'src/com/vaadin/ui')
-rw-r--r--src/com/vaadin/ui/MenuBar.java95
1 files changed, 67 insertions, 28 deletions
diff --git a/src/com/vaadin/ui/MenuBar.java b/src/com/vaadin/ui/MenuBar.java
index 77523f9680..286da7a4ff 100644
--- a/src/com/vaadin/ui/MenuBar.java
+++ b/src/com/vaadin/ui/MenuBar.java
@@ -79,35 +79,39 @@ public class MenuBar extends AbstractComponent {
while (itr.hasNext()) {
MenuItem item = itr.next();
-
target.startTag("item");
-
- target.addAttribute("text", item.getText());
target.addAttribute("id", item.getId());
- Command command = item.getCommand();
- if (command != null) {
- target.addAttribute("command", true);
+ if (item.isSeparator()) {
+ target.addAttribute("separator", true);
+ target.endTag("item");
} else {
- target.addAttribute("command", false);
- }
+ target.addAttribute("text", item.getText());
- Resource icon = item.getIcon();
- if (icon != null) {
- target.addAttribute("icon", icon);
- }
+ Command command = item.getCommand();
+ if (command != null) {
+ target.addAttribute("command", true);
+ }
- if (!item.isEnabled()) {
- target.addAttribute("disabled", true);
- }
+ Resource icon = item.getIcon();
+ if (icon != null) {
+ target.addAttribute("icon", icon);
+ }
- if (item.hasChildren()) {
- iteratorStack.push(itr); // For later use
+ if (!item.isEnabled()) {
+ target.addAttribute("disabled", true);
+ }
+
+ if (item.hasChildren()) {
+ iteratorStack.push(itr); // For later use
+
+ // Go through the children
+ itr = item.getChildren().iterator();
+ } else {
+ target.endTag("item"); // Item had no children, end
+ // description
+ }
- // Go through the children
- itr = item.getChildren().iterator();
- } else {
- target.endTag("item"); // Item had no children, end description
}
// The end submenu. More than one submenu may end at once.
@@ -115,7 +119,6 @@ public class MenuBar extends AbstractComponent {
itr = iteratorStack.pop();
target.endTag("item");
}
-
}
target.endTag("items");
@@ -382,6 +385,7 @@ public class MenuBar extends AbstractComponent {
private Resource itsIcon;
private MenuItem itsParent;
private boolean enabled = true;
+ private boolean isSeparator = false;
/**
* Constructs a new menu item that can optionally have an icon and a
@@ -410,7 +414,27 @@ public class MenuBar extends AbstractComponent {
* @return True if this item has children
*/
public boolean hasChildren() {
- return itsChildren != null;
+ return !isSeparator() && itsChildren != null;
+ }
+
+ /**
+ * Adds a separator to this menu. A separator is a way to visually group
+ * items in a menu, to make it easier for users to find what they are
+ * looking for in the menu.
+ *
+ * @author Jouni Koivuviita / IT Mill Ltd.
+ * @since 6.2.0
+ */
+ public MenuBar.MenuItem addSeparator() {
+ MenuItem item = addItem("", null, null);
+ item.setSeparator(true);
+ return item;
+ }
+
+ public MenuBar.MenuItem addSeparatorBefore(MenuItem itemToAddBefore) {
+ MenuItem item = addItemBefore("", null, null, itemToAddBefore);
+ item.setSeparator(true);
+ return item;
}
/**
@@ -439,8 +463,12 @@ public class MenuBar extends AbstractComponent {
*/
public MenuBar.MenuItem addItem(String caption, Resource icon,
MenuBar.Command command) {
+ if (isSeparator()) {
+ throw new UnsupportedOperationException(
+ "Cannot add items to a separator");
+ }
if (caption == null) {
- throw new IllegalArgumentException("caption cannot be null");
+ throw new IllegalArgumentException("Caption cannot be null");
}
if (itsChildren == null) {
@@ -483,7 +511,6 @@ public class MenuBar extends AbstractComponent {
newItem = new MenuItem(caption, icon, command);
newItem.setParent(this);
itsChildren.add(index, newItem);
-
} else {
newItem = addItem(caption, icon, command);
}
@@ -546,7 +573,10 @@ public class MenuBar extends AbstractComponent {
* @return The number of child items
*/
public int getSize() {
- return itsChildren.size();
+ if (itsChildren != null) {
+ return itsChildren.size();
+ }
+ return -1;
}
/**
@@ -604,8 +634,8 @@ public class MenuBar extends AbstractComponent {
if (itsChildren.isEmpty()) {
itsChildren = null;
}
+ requestRepaint();
}
- requestRepaint();
}
/**
@@ -615,8 +645,8 @@ public class MenuBar extends AbstractComponent {
if (itsChildren != null) {
itsChildren.clear();
itsChildren = null;
+ requestRepaint();
}
- requestRepaint();
}
/**
@@ -638,6 +668,15 @@ public class MenuBar extends AbstractComponent {
return enabled;
}
+ private void setSeparator(boolean isSeparator) {
+ this.isSeparator = isSeparator;
+ requestRepaint();
+ }
+
+ public boolean isSeparator() {
+ return isSeparator;
+ }
+
}// class MenuItem
}// class MenuBar