Web Menu shortucts #PL-2327

This commit is contained in:
Yuriy Artamonov 2013-08-01 07:36:14 +00:00
parent 5aa3a39d88
commit 5879fea1ed
6 changed files with 162 additions and 14 deletions

View File

@ -59,7 +59,7 @@ def webModule = project(':cuba-web')
def desktopModule = project(':cuba-desktop')
def portalModule = project(':cuba-portal')
def vaadinVersion = '7.1.1.h.M5'
def vaadinVersion = '7.1.1.h.M6'
def servletApi = [group: 'org.apache.tomcat', name: 'servlet-api', version: '6.0.20']
def groovyArtifact = [group: 'org.codehaus.groovy', name: 'groovy', version: '1.7.10']

View File

@ -6,6 +6,8 @@
package com.haulmont.cuba.web.toolkit.ui.client.menubar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.haulmont.cuba.web.toolkit.ui.CubaMenuBar;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.UIDL;
@ -29,6 +31,16 @@ public class CubaMenuBarConnector extends MenuBarConnector {
return (CubaMenuBarState) super.getState();
}
@Override
public CubaMenuBarWidget getWidget() {
return (CubaMenuBarWidget) super.getWidget();
}
@Override
protected Widget createWidget() {
return GWT.create(CubaMenuBarWidget.class);
}
@Override
public void layout() {
super.layout();

View File

@ -0,0 +1,68 @@
/*
* Copyright (c) 2013 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
*/
package com.haulmont.cuba.web.toolkit.ui.client.menubar;
import com.vaadin.client.UIDL;
import com.vaadin.client.Util;
import com.vaadin.client.ui.Icon;
import com.vaadin.client.ui.VMenuBar;
/**
* @author artamonov
* @version $Id$
*/
public class CubaMenuBarWidget extends VMenuBar {
@Override
public String buildItemHTML(UIDL item) {
// Construct html from the text and the optional icon
// Haulmont API : Added support for shortcuts
StringBuilder itemHTML = new StringBuilder();
if (item.hasAttribute("separator")) {
itemHTML.append("<span>---</span><span>---</span>");
} else {
itemHTML.append("<span class=\"")
.append(getStylePrimaryName())
.append("-menuitem-caption\">");
if (item.hasAttribute("icon")) {
itemHTML.append("<img src=\"")
.append(Util.escapeAttribute(client.translateVaadinUri(item.getStringAttribute("icon"))))
.append("\" class=\"")
.append(Icon.CLASSNAME).append("\" alt=\"\" />");
}
String itemText = item.getStringAttribute("text");
if (!htmlContentAllowed) {
itemText = Util.escapeHTML(itemText);
}
itemHTML.append(itemText);
itemHTML.append("</span>");
// Add submenu indicator
if (item.getChildCount() > 0) {
String bgStyle = "";
itemHTML.append("<span class=\"")
.append(getStylePrimaryName())
.append("-submenu-indicator\"")
.append(bgStyle)
.append(">&#x25BA;</span>");
} else {
String shortcut = "";
if (item.hasAttribute("shortcut")) {
shortcut = item.getStringAttribute("shortcut");
}
itemHTML.append("<span class=\"")
.append(getStylePrimaryName())
.append("-menuitem-shortcut\">")
.append(shortcut)
.append("</span");
}
}
return itemHTML.toString();
}
}

View File

@ -674,7 +674,7 @@ public class AppWindow extends UIView implements UserSubstitutionListener {
if (item.getShortcut() != null) {
MenuShortcutAction shortcut = new MenuShortcutAction(menuItem, "shortcut_" + item.getId(), item.getShortcut());
this.addAction(shortcut);
// menuBar.setShortcut(menuItem, item.getShortcut());
menuBar.setShortcut(menuItem, item.getShortcut());
}
}

View File

@ -6,7 +6,15 @@
package com.haulmont.cuba.web.toolkit.ui;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.gui.components.ShortcutAction;
import com.haulmont.cuba.web.toolkit.ui.client.menubar.CubaMenuBarState;
import com.vaadin.server.PaintException;
import com.vaadin.server.PaintTarget;
import java.util.HashMap;
import java.util.Map;
/**
* @author artamonov
@ -14,6 +22,8 @@ import com.haulmont.cuba.web.toolkit.ui.client.menubar.CubaMenuBarState;
*/
public class CubaMenuBar extends com.vaadin.ui.MenuBar {
protected final Map<MenuItem, String> shortcuts = new HashMap<>();
@Override
protected CubaMenuBarState getState() {
return (CubaMenuBarState) super.getState();
@ -33,4 +43,43 @@ public class CubaMenuBar extends com.vaadin.ui.MenuBar {
getState().vertical = useMoreMenuItem;
}
}
public void setShortcut(MenuItem item, ShortcutAction.KeyCombination shortcut) {
setShortcut(item, makeCaption(shortcut));
}
private String makeCaption(ShortcutAction.KeyCombination shortcut) {
Messages messages = AppBeans.get(Messages.class);
StringBuilder sb = new StringBuilder();
if (shortcut.getModifiers() != null) {
for (ShortcutAction.Modifier mod : shortcut.getModifiers()) {
sb.append(messages.getMessage(getClass(), "shortcut." + mod.name()))
.append("+");
}
}
sb.append(messages.getMessage(getClass(), "shortcut." + shortcut.getKey().name()));
return sb.toString();
}
public void setShortcut(MenuItem item, String str) {
if (shortcuts.containsKey(item)) {
shortcuts.remove(item);
}
shortcuts.put(item, str);
}
public void clearShortcut(MenuItem item) {
shortcuts.remove(item);
}
@Override
protected void paintAdditionalItemParams(PaintTarget target, MenuItem item) throws PaintException {
if (shortcuts.containsKey(item)) {
String shortcut = shortcuts.get(item);
if (shortcut != null) {
target.addAttribute("shortcut", shortcut);
}
}
}
}

View File

@ -31,6 +31,8 @@
text-shadow: black 1px 1px;
.#{$primaryStyleName}-menuitem-caption {
display: table-cell;
.v-icon {
margin-right: 3px;
}
@ -85,6 +87,7 @@
}
.#{$primaryStyleName}-submenu {
display: table;
overflow: hidden;
white-space: nowrap;
border: 0;
@ -97,7 +100,7 @@
.#{$primaryStyleName}-menuitem {
line-height: 16px;
padding: 1px 26px 1px 10px;
display: block;
display: table-row;
padding-right: 1.5em;
position: relative;
cursor: pointer;
@ -108,8 +111,9 @@
.#{$primaryStyleName}-menuitem-caption {
color: #fff;
display: inline-block;
display: table-cell;
padding-right: 4px;
border-left: 3px solid transparent;
.v-icon {
vertical-align: middle;
@ -117,20 +121,34 @@
margin-right: 3px;
}
}
.#{$primaryStyleName}-menuitem-shortcut {
display: table-cell;
border-left: 3px solid transparent;
border-right: 3px solid transparent;
padding: 0;
color: #c0c0c0;
}
}
.#{$primaryStyleName}-menuitem-selected,
.#{$primaryStyleName}-menuitem-shortcut-selected {
$menuSeparatorMargin: 3px;
.#{$primaryStyleName}-separator {
display: table-row;
height: 7px;
span {
display: table-cell;
background: white;
border-top: $menuSeparatorMargin solid $theme_appSubmenuBackgroundColor;
border-bottom: $menuSeparatorMargin solid $theme_appSubmenuBackgroundColor;
}
}
.#{$primaryStyleName}-menuitem-selected {
background-color: $theme_appMenuHighlightColor;
}
.#{$primaryStyleName}-menuitem-shortcut,
.#{$primaryStyleName}-menuitem-shortcut-selected {
padding: 0;
color: #c0c0c0;
display: inline-block;
}
.#{$primaryStyleName}-menuitem-selected div {
color: #fff;
}
@ -143,8 +161,9 @@
height: 16px;
text-indent: -9999px;
width: 16px;
display: inline-block;
display: table-cell;
min-width: 10px;
position: relative;
}
.#{$primaryStyleName}-submenu-indicator + .#{$primaryStyleName}-menuitem-caption {