mirror of
https://gitee.com/jmix/cuba.git
synced 2024-11-30 18:27:56 +08:00
Cuba-id support for application menu #PL-3529
This commit is contained in:
parent
0406a16cec
commit
ad9ae740a2
@ -60,7 +60,7 @@ def webToolkitLegacyModule = project(':cuba-web6-toolkit')
|
||||
def webModuleThemes = project(':cuba-web-themes')
|
||||
def webLegacyModuleThemes = project(':cuba-web6-themes')
|
||||
|
||||
def vaadinVersion = '7.1.9.cuba.4'
|
||||
def vaadinVersion = '7.1.9.cuba.5'
|
||||
def vaadinLegacyVersion = '6.6.1.144'
|
||||
def springVersion = '3.1.3.RELEASE'
|
||||
|
||||
|
@ -10,6 +10,7 @@ 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;
|
||||
import com.vaadin.client.ui.VMenuBar;
|
||||
import com.vaadin.client.ui.menubar.MenuBarConnector;
|
||||
import com.vaadin.shared.ui.Connect;
|
||||
|
||||
@ -58,10 +59,17 @@ public class CubaMenuBarConnector extends MenuBarConnector {
|
||||
|
||||
@Override
|
||||
protected String getItemId(UIDL uidl) {
|
||||
if (uidl.hasAttribute("testId")) {
|
||||
return uidl.getStringAttribute("testId");
|
||||
if (uidl.hasAttribute("tid")) {
|
||||
return uidl.getStringAttribute("tid");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assignAdditionalAttributes(VMenuBar.CustomMenuItem currentItem, UIDL item) {
|
||||
if (item.hasAttribute("cid")) {
|
||||
currentItem.getElement().setAttribute("cuba-id", item.getStringAttribute("cid"));
|
||||
}
|
||||
}
|
||||
}
|
@ -173,9 +173,11 @@ public class MenuBuilder {
|
||||
TestIdManager testIdManager = appWindow.getAppUI().getTestIdManager();
|
||||
|
||||
String id = testIdManager.normalize(conf.getId());
|
||||
testIdManager.reserveId(id);
|
||||
String testId = menuBar.getId() + "_" + id;
|
||||
testIdManager.reserveId(testId);
|
||||
|
||||
menuBar.setTestId(menuItem, menuBar.getId() + "_" + id);
|
||||
menuBar.setTestId(menuItem, testId);
|
||||
menuBar.setCubaId(menuItem, id);
|
||||
}
|
||||
}
|
||||
}
|
@ -19,8 +19,9 @@ import java.util.Map;
|
||||
*/
|
||||
public class CubaMenuBar extends com.vaadin.ui.MenuBar {
|
||||
|
||||
protected final Map<MenuItem, String> shortcuts = new HashMap<>();
|
||||
protected final Map<MenuItem, String> testIds = new HashMap<>();
|
||||
protected Map<MenuItem, String> shortcuts = null;
|
||||
protected Map<MenuItem, String> testIds = null;
|
||||
protected Map<MenuItem, String> cubaIds = null;
|
||||
|
||||
@Override
|
||||
protected CubaMenuBarState getState() {
|
||||
@ -47,6 +48,10 @@ public class CubaMenuBar extends com.vaadin.ui.MenuBar {
|
||||
}
|
||||
|
||||
public void setShortcut(MenuItem item, String str) {
|
||||
if (shortcuts == null) {
|
||||
shortcuts = new HashMap<>();
|
||||
}
|
||||
|
||||
if (shortcuts.containsKey(item)) {
|
||||
shortcuts.remove(item);
|
||||
}
|
||||
@ -54,23 +59,38 @@ public class CubaMenuBar extends com.vaadin.ui.MenuBar {
|
||||
}
|
||||
|
||||
public void clearShortcut(MenuItem item) {
|
||||
shortcuts.remove(item);
|
||||
if (shortcuts != null) {
|
||||
shortcuts.remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTestId(MenuItem item, String id) {
|
||||
if (testIds == null) {
|
||||
testIds = new HashMap<>();
|
||||
}
|
||||
testIds.put(item, id);
|
||||
}
|
||||
|
||||
public void setCubaId(MenuItem item, String id) {
|
||||
if (cubaIds == null) {
|
||||
cubaIds = new HashMap<>();
|
||||
}
|
||||
cubaIds.put(item, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintAdditionalItemParams(PaintTarget target, MenuItem item) throws PaintException {
|
||||
if (shortcuts.containsKey(item)) {
|
||||
if (shortcuts != null && shortcuts.containsKey(item)) {
|
||||
String shortcut = shortcuts.get(item);
|
||||
if (shortcut != null) {
|
||||
target.addAttribute("shortcut", shortcut);
|
||||
}
|
||||
}
|
||||
if (testIds.containsKey(item)) {
|
||||
target.addAttribute("testId", testIds.get(item));
|
||||
if (testIds != null && testIds.containsKey(item)) {
|
||||
target.addAttribute("tid", testIds.get(item));
|
||||
}
|
||||
if (cubaIds != null && cubaIds.containsKey(item)) {
|
||||
target.addAttribute("cid", cubaIds.get(item));
|
||||
}
|
||||
}
|
||||
}
|
@ -249,7 +249,7 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable,
|
||||
|
||||
while (itr.hasNext()) {
|
||||
UIDL item = (UIDL) itr.next();
|
||||
CustomMenuItem currentItem = null;
|
||||
CustomMenuItem currentItem;
|
||||
|
||||
String itemText = item.getStringAttribute("text");
|
||||
final int itemId = item.getIntAttribute("id");
|
||||
@ -1109,6 +1109,13 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable,
|
||||
VMenuBar root = findRootMenu();
|
||||
client.registerTooltip(root, this, info);
|
||||
}
|
||||
|
||||
if (uidl.hasAttribute("debugId")) {
|
||||
getElement().setId(uidl.getStringAttribute("debugId"));
|
||||
}
|
||||
if (uidl.hasAttribute("cid")) {
|
||||
getElement().setAttribute("cuba-id", uidl.getStringAttribute("cid"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,6 +11,7 @@ import com.haulmont.cuba.gui.NoSuchScreenException;
|
||||
import com.haulmont.cuba.gui.TestIdManager;
|
||||
import com.haulmont.cuba.gui.config.*;
|
||||
import com.haulmont.cuba.security.global.UserSession;
|
||||
import com.haulmont.cuba.web.App;
|
||||
import com.haulmont.cuba.web.AppWindow;
|
||||
import com.haulmont.cuba.web.toolkit.MenuShortcutAction;
|
||||
import com.vaadin.ui.MenuBar;
|
||||
@ -169,5 +170,8 @@ public class MenuBuilder {
|
||||
if (menuBar.getDebugId() != null && !conf.isSeparator()) {
|
||||
menuBar.setDebugId(menuItem, testIdManager.normalize(menuBar.getDebugId() + "_" + conf.getId()));
|
||||
}
|
||||
if (App.getInstance().isTestMode() && !conf.isSeparator()) {
|
||||
menuBar.setCubaId(menuItem, conf.getId());
|
||||
}
|
||||
}
|
||||
}
|
@ -20,13 +20,13 @@ import java.util.Map;
|
||||
*/
|
||||
public class MenuBar extends com.vaadin.ui.MenuBar {
|
||||
|
||||
protected Map<MenuItem, String> shortcuts;
|
||||
protected boolean vertical;
|
||||
|
||||
protected Map<MenuItem, String> shortcuts;
|
||||
protected BiMap<MenuItem, String> debugIds;
|
||||
protected Map<MenuItem, String> cubaIds;
|
||||
|
||||
public MenuBar() {
|
||||
shortcuts = new HashMap<>();
|
||||
}
|
||||
|
||||
public void setShortcut(MenuItem item, KeyCombination shortcut) {
|
||||
@ -34,6 +34,10 @@ public class MenuBar extends com.vaadin.ui.MenuBar {
|
||||
}
|
||||
|
||||
public void setShortcut(MenuItem item, String str) {
|
||||
if (shortcuts == null) {
|
||||
shortcuts = new HashMap<>();
|
||||
}
|
||||
|
||||
if (shortcuts.containsKey(item)) {
|
||||
shortcuts.remove(item);
|
||||
}
|
||||
@ -41,7 +45,9 @@ public class MenuBar extends com.vaadin.ui.MenuBar {
|
||||
}
|
||||
|
||||
public void clearShortcut(MenuItem item) {
|
||||
shortcuts.remove(item);
|
||||
if (shortcuts != null) {
|
||||
shortcuts.remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDebugId(MenuItem item, String id) {
|
||||
@ -51,6 +57,13 @@ public class MenuBar extends com.vaadin.ui.MenuBar {
|
||||
debugIds.put(item, id);
|
||||
}
|
||||
|
||||
public void setCubaId(MenuItem item, String id) {
|
||||
if (cubaIds == null) {
|
||||
cubaIds = new HashMap<>();
|
||||
}
|
||||
cubaIds.put(item, id);
|
||||
}
|
||||
|
||||
public String getDebugId(MenuItem item) {
|
||||
if (debugIds != null) {
|
||||
return debugIds.get(item);
|
||||
@ -60,7 +73,6 @@ public class MenuBar extends com.vaadin.ui.MenuBar {
|
||||
|
||||
@Override
|
||||
public void changeVariables(Object source, Map<String, Object> variables) {
|
||||
|
||||
if (variables.containsKey("clickedDebugId")) {
|
||||
MenuItem clickedItem = debugIds.inverse().get(variables.get("clickedDebugId"));
|
||||
if (clickedItem != null && clickedItem.isEnabled()) {
|
||||
@ -140,7 +152,7 @@ public class MenuBar extends com.vaadin.ui.MenuBar {
|
||||
}
|
||||
|
||||
//***************************
|
||||
if (shortcuts.containsKey(item)) {
|
||||
if (shortcuts != null && shortcuts.containsKey(item)) {
|
||||
String shortcut = shortcuts.get(item);
|
||||
if (shortcut != null) {
|
||||
target.addAttribute("shortcut", shortcut);
|
||||
@ -152,12 +164,15 @@ public class MenuBar extends com.vaadin.ui.MenuBar {
|
||||
target.addAttribute("debugId", debugIds.get(item));
|
||||
}
|
||||
|
||||
if (cubaIds != null && cubaIds.containsKey(item)) {
|
||||
target.addAttribute("cid", cubaIds.get(item));
|
||||
}
|
||||
|
||||
if (item.hasChildren()) {
|
||||
for (com.vaadin.ui.MenuBar.MenuItem child : item.getChildren()) {
|
||||
paintItem(target, child);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
target.endTag("item");
|
||||
|
Loading…
Reference in New Issue
Block a user