|
|
@@ -21,6 +21,7 @@ import java.util.Stack; |
|
|
|
import com.google.gwt.core.client.GWT; |
|
|
|
import com.google.gwt.dom.client.Element; |
|
|
|
import com.google.gwt.user.client.Command; |
|
|
|
import com.google.gwt.user.client.Timer; |
|
|
|
import com.vaadin.client.ApplicationConnection; |
|
|
|
import com.vaadin.client.Paintable; |
|
|
|
import com.vaadin.client.TooltipInfo; |
|
|
@@ -46,7 +47,7 @@ public class MenuBarConnector extends AbstractComponentConnector |
|
|
|
* every time UI changes in the component are received from the server. |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { |
|
|
|
public void updateFromUIDL(final UIDL uidl, final ApplicationConnection client) { |
|
|
|
if (!isRealUpdate(uidl)) { |
|
|
|
return; |
|
|
|
} |
|
|
@@ -63,114 +64,120 @@ public class MenuBarConnector extends AbstractComponentConnector |
|
|
|
getWidget().client = client; |
|
|
|
getWidget().uidlId = uidl.getId(); |
|
|
|
|
|
|
|
// Empty the menu every time it receives new information |
|
|
|
if (!getWidget().getItems().isEmpty()) { |
|
|
|
getWidget().clearItems(); |
|
|
|
} |
|
|
|
Timer timer = new Timer() { |
|
|
|
|
|
|
|
UIDL options = uidl.getChildUIDL(0); |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
// Empty the menu every time it receives new information |
|
|
|
if (!getWidget().getItems().isEmpty()) { |
|
|
|
getWidget().clearItems(); |
|
|
|
} |
|
|
|
|
|
|
|
if (null != getState() |
|
|
|
&& !ComponentStateUtil.isUndefinedWidth(getState())) { |
|
|
|
UIDL moreItemUIDL = options.getChildUIDL(0); |
|
|
|
StringBuffer itemHTML = new StringBuffer(); |
|
|
|
UIDL options = uidl.getChildUIDL(0); |
|
|
|
|
|
|
|
if (moreItemUIDL.hasAttribute("icon")) { |
|
|
|
Icon icon = client |
|
|
|
.getIcon(moreItemUIDL.getStringAttribute("icon")); |
|
|
|
if (icon != null) { |
|
|
|
itemHTML.append(icon.getElement().getString()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (null != getState() && !ComponentStateUtil.isUndefinedWidth(getState())) { |
|
|
|
UIDL moreItemUIDL = options.getChildUIDL(0); |
|
|
|
StringBuffer itemHTML = new StringBuffer(); |
|
|
|
|
|
|
|
String moreItemText = moreItemUIDL.getStringAttribute("text"); |
|
|
|
if ("".equals(moreItemText)) { |
|
|
|
moreItemText = "►"; |
|
|
|
} |
|
|
|
itemHTML.append(moreItemText); |
|
|
|
if (moreItemUIDL.hasAttribute("icon")) { |
|
|
|
Icon icon = client.getIcon(moreItemUIDL.getStringAttribute("icon")); |
|
|
|
if (icon != null) { |
|
|
|
itemHTML.append(icon.getElement().getString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
getWidget().moreItem = GWT.create(VMenuBar.CustomMenuItem.class); |
|
|
|
getWidget().moreItem.setHTML(itemHTML.toString()); |
|
|
|
getWidget().moreItem.setCommand(VMenuBar.emptyCommand); |
|
|
|
String moreItemText = moreItemUIDL.getStringAttribute("text"); |
|
|
|
if ("".equals(moreItemText)) { |
|
|
|
moreItemText = "►"; |
|
|
|
} |
|
|
|
itemHTML.append(moreItemText); |
|
|
|
|
|
|
|
getWidget().collapsedRootItems = new VMenuBar(true, getWidget()); |
|
|
|
getWidget().moreItem.setSubMenu(getWidget().collapsedRootItems); |
|
|
|
getWidget().moreItem.addStyleName( |
|
|
|
getWidget().getStylePrimaryName() + "-more-menuitem"); |
|
|
|
} |
|
|
|
getWidget().moreItem = GWT.create(VMenuBar.CustomMenuItem.class); |
|
|
|
getWidget().moreItem.setHTML(itemHTML.toString()); |
|
|
|
getWidget().moreItem.setCommand(VMenuBar.emptyCommand); |
|
|
|
|
|
|
|
UIDL uidlItems = uidl.getChildUIDL(1); |
|
|
|
Iterator<Object> itr = uidlItems.getChildIterator(); |
|
|
|
Stack<Iterator<Object>> iteratorStack = new Stack<Iterator<Object>>(); |
|
|
|
Stack<VMenuBar> menuStack = new Stack<VMenuBar>(); |
|
|
|
VMenuBar currentMenu = getWidget(); |
|
|
|
|
|
|
|
while (itr.hasNext()) { |
|
|
|
UIDL item = (UIDL) itr.next(); |
|
|
|
VMenuBar.CustomMenuItem currentItem = null; |
|
|
|
|
|
|
|
final int itemId = item.getIntAttribute("id"); |
|
|
|
|
|
|
|
boolean itemHasCommand = item.hasAttribute("command"); |
|
|
|
boolean itemIsCheckable = item |
|
|
|
.hasAttribute(MenuBarConstants.ATTRIBUTE_CHECKED); |
|
|
|
|
|
|
|
String itemHTML = getWidget().buildItemHTML(item); |
|
|
|
|
|
|
|
Command cmd = null; |
|
|
|
if (!item.hasAttribute("separator")) { |
|
|
|
if (itemHasCommand || itemIsCheckable) { |
|
|
|
// Construct a command that fires onMenuClick(int) with the |
|
|
|
// item's id-number |
|
|
|
cmd = new Command() { |
|
|
|
@Override |
|
|
|
public void execute() { |
|
|
|
getWidget().hostReference.onMenuClick(itemId); |
|
|
|
} |
|
|
|
}; |
|
|
|
getWidget().collapsedRootItems = new VMenuBar(true, |
|
|
|
getWidget()); |
|
|
|
getWidget().moreItem.setSubMenu(getWidget().collapsedRootItems); |
|
|
|
getWidget().moreItem.addStyleName( |
|
|
|
getWidget().getStylePrimaryName() + "-more-menuitem"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
currentItem = currentMenu.addItem(itemHTML.toString(), cmd); |
|
|
|
currentItem.updateFromUIDL(item, client); |
|
|
|
|
|
|
|
if (item.getChildCount() > 0) { |
|
|
|
menuStack.push(currentMenu); |
|
|
|
iteratorStack.push(itr); |
|
|
|
itr = item.getChildIterator(); |
|
|
|
currentMenu = new VMenuBar(true, currentMenu); |
|
|
|
client.getVTooltip().connectHandlersToWidget(currentMenu); |
|
|
|
// this is the top-level style that also propagates to items - |
|
|
|
// any item specific styles are set above in |
|
|
|
// currentItem.updateFromUIDL(item, client) |
|
|
|
if (ComponentStateUtil.hasStyles(getState())) { |
|
|
|
for (String style : getState().styles) { |
|
|
|
currentMenu.addStyleDependentName(style); |
|
|
|
UIDL uidlItems = uidl.getChildUIDL(1); |
|
|
|
Iterator<Object> itr = uidlItems.getChildIterator(); |
|
|
|
Stack<Iterator<Object>> iteratorStack = new Stack<Iterator<Object>>(); |
|
|
|
Stack<VMenuBar> menuStack = new Stack<VMenuBar>(); |
|
|
|
VMenuBar currentMenu = getWidget(); |
|
|
|
|
|
|
|
while (itr.hasNext()) { |
|
|
|
UIDL item = (UIDL) itr.next(); |
|
|
|
VMenuBar.CustomMenuItem currentItem = null; |
|
|
|
|
|
|
|
final int itemId = item.getIntAttribute("id"); |
|
|
|
|
|
|
|
boolean itemHasCommand = item.hasAttribute("command"); |
|
|
|
boolean itemIsCheckable = item.hasAttribute(MenuBarConstants.ATTRIBUTE_CHECKED); |
|
|
|
|
|
|
|
String itemHTML = getWidget().buildItemHTML(item); |
|
|
|
|
|
|
|
Command cmd = null; |
|
|
|
if (!item.hasAttribute("separator")) { |
|
|
|
if (itemHasCommand || itemIsCheckable) { |
|
|
|
// Construct a command that fires onMenuClick(int) with the |
|
|
|
// item's id-number |
|
|
|
cmd = new Command() { |
|
|
|
@Override |
|
|
|
public void execute() { |
|
|
|
getWidget().hostReference.onMenuClick(itemId); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
currentItem.setSubMenu(currentMenu); |
|
|
|
} |
|
|
|
|
|
|
|
while (!itr.hasNext() && !iteratorStack.empty()) { |
|
|
|
boolean hasCheckableItem = false; |
|
|
|
for (VMenuBar.CustomMenuItem menuItem : currentMenu |
|
|
|
.getItems()) { |
|
|
|
hasCheckableItem = hasCheckableItem |
|
|
|
|| menuItem.isCheckable(); |
|
|
|
} |
|
|
|
if (hasCheckableItem) { |
|
|
|
currentMenu.addStyleDependentName("check-column"); |
|
|
|
} else { |
|
|
|
currentMenu.removeStyleDependentName("check-column"); |
|
|
|
} |
|
|
|
currentItem = currentMenu.addItem(itemHTML.toString(), cmd); |
|
|
|
currentItem.updateFromUIDL(item, client); |
|
|
|
|
|
|
|
if (item.getChildCount() > 0) { |
|
|
|
menuStack.push(currentMenu); |
|
|
|
iteratorStack.push(itr); |
|
|
|
itr = item.getChildIterator(); |
|
|
|
currentMenu = new VMenuBar(true, currentMenu); |
|
|
|
client.getVTooltip().connectHandlersToWidget(currentMenu); |
|
|
|
// this is the top-level style that also propagates to items - |
|
|
|
// any item specific styles are set above in |
|
|
|
// currentItem.updateFromUIDL(item, client) |
|
|
|
if (ComponentStateUtil.hasStyles(getState())) { |
|
|
|
for (String style : getState().styles) { |
|
|
|
currentMenu.addStyleDependentName(style); |
|
|
|
} |
|
|
|
} |
|
|
|
currentItem.setSubMenu(currentMenu); |
|
|
|
} |
|
|
|
|
|
|
|
itr = iteratorStack.pop(); |
|
|
|
currentMenu = menuStack.pop(); |
|
|
|
} |
|
|
|
} // while |
|
|
|
while (!itr.hasNext() && !iteratorStack.empty()) { |
|
|
|
boolean hasCheckableItem = false; |
|
|
|
for (VMenuBar.CustomMenuItem menuItem : currentMenu.getItems()) { |
|
|
|
hasCheckableItem = hasCheckableItem || menuItem.isCheckable(); |
|
|
|
} |
|
|
|
if (hasCheckableItem) { |
|
|
|
currentMenu.addStyleDependentName("check-column"); |
|
|
|
} else { |
|
|
|
currentMenu.removeStyleDependentName("check-column"); |
|
|
|
} |
|
|
|
|
|
|
|
itr = iteratorStack.pop(); |
|
|
|
currentMenu = menuStack.pop(); |
|
|
|
} |
|
|
|
} // while |
|
|
|
} |
|
|
|
}; |
|
|
|
getLayoutManager().setNeedsHorizontalLayout(this); |
|
|
|
|
|
|
|
if (getWidget().mouseDownPressed) { |
|
|
|
timer.schedule(getState().delayMs); |
|
|
|
getWidget().mouseDownPressed = false; |
|
|
|
} else { |
|
|
|
timer.run(); |
|
|
|
} |
|
|
|
}// updateFromUIDL |
|
|
|
|
|
|
|
@Override |