IDEMPIERE-2112 improve shortcuts for master detail data entry windows / WIP, enabled shortcut Shift+Alt+N for new detail button

This commit is contained in:
Carlos Ruiz 2014-08-15 08:57:05 +02:00
parent e8228d6fbe
commit 79f99b8d81
3 changed files with 78 additions and 25 deletions

View File

@ -76,7 +76,6 @@ public class BreadCrumb extends Div implements EventListener<Event> {
private int windowNo; private int windowNo;
private HashMap<String, ToolBarButton> buttons = new HashMap<String, ToolBarButton>(); private HashMap<String, ToolBarButton> buttons = new HashMap<String, ToolBarButton>();
private Map<Integer, ToolBarButton> altKeyMap = new HashMap<Integer, ToolBarButton>();
private DataStatusEvent m_dse; private DataStatusEvent m_dse;
@ -129,11 +128,6 @@ public class BreadCrumb extends Div implements EventListener<Event> {
btnLast.setTooltiptext(btnLast.getTooltiptext()+" Alt+End"); btnLast.setTooltiptext(btnLast.getTooltiptext()+" Alt+End");
toolbar.appendChild(btnLast); toolbar.appendChild(btnLast);
altKeyMap.put(KeyEvent.UP, btnPrevious);
altKeyMap.put(KeyEvent.DOWN, btnNext);
altKeyMap.put(KeyEvent.PAGE_UP, btnFirst);
altKeyMap.put(KeyEvent.PAGE_DOWN, btnLast);
toolbar.setStyle("background-image: none; background-color: transparent; border: none;"); toolbar.setStyle("background-image: none; background-color: transparent; border: none;");
setWidgetAttribute(AdempiereWebUI.WIDGET_INSTANCE_NAME, "breadcrumb"); setWidgetAttribute(AdempiereWebUI.WIDGET_INSTANCE_NAME, "breadcrumb");

View File

@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.component.ADTabListModel.ADTabLabel;
import org.adempiere.webui.component.Label; import org.adempiere.webui.component.Label;
import org.adempiere.webui.component.Panel; import org.adempiere.webui.component.Panel;
import org.adempiere.webui.component.Tab; import org.adempiere.webui.component.Tab;
@ -16,13 +17,13 @@ import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.component.ToolBar; import org.adempiere.webui.component.ToolBar;
import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.component.Window; import org.adempiere.webui.component.Window;
import org.adempiere.webui.component.ADTabListModel.ADTabLabel;
import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.theme.ThemeManager;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.compiere.util.Util; import org.compiere.util.Util;
import org.zkoss.zhtml.Text; import org.zkoss.zhtml.Text;
import org.zkoss.zk.au.out.AuScript;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Execution; import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
@ -31,6 +32,7 @@ import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.KeyEvent;
import org.zkoss.zk.ui.sys.ExecutionCtrl; import org.zkoss.zk.ui.sys.ExecutionCtrl;
import org.zkoss.zk.ui.util.Clients; import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Div; import org.zkoss.zul.Div;
@ -45,6 +47,10 @@ import org.zkoss.zul.Toolbar;
* *
*/ */
public class DetailPane extends Panel implements EventListener<Event>, IdSpace { public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
/**
*
*/
private static final long serialVersionUID = -5714780894880069158L;
private static final String BTN_PROCESS_ID = "BtnProcess"; private static final String BTN_PROCESS_ID = "BtnProcess";
@ -67,10 +73,9 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
private static final String NEW_IMAGE = "images/New16.png"; private static final String NEW_IMAGE = "images/New16.png";
private static final String PROCESS_IMAGE = "images/Process16.png"; private static final String PROCESS_IMAGE = "images/Process16.png";
/** private ToolBarButton btnNew;
* generated serial id private long prevKeyEventTime = 0;
*/ private KeyEvent prevKeyEvent;
private static final long serialVersionUID = -7914602940626352282L;
private Tabbox tabbox; private Tabbox tabbox;
@ -251,19 +256,19 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
tp.setSclass("adwindow-detailpane-tabpanel"); tp.setSclass("adwindow-detailpane-tabpanel");
ToolBar toolbar = new ToolBar(); ToolBar toolbar = new ToolBar();
tp.appendChild(toolbar); tp.appendChild(toolbar);
ToolBarButton button = new ToolBarButton(); btnNew = new ToolBarButton();
btnNew.setImage(ThemeManager.getThemeResource(NEW_IMAGE));
button = new ToolBarButton(); btnNew.setId(BTN_NEW_ID);
button.setImage(ThemeManager.getThemeResource(NEW_IMAGE)); toolbar.appendChild(btnNew);
button.setId(BTN_NEW_ID); btnNew.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
toolbar.appendChild(button);
button.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
@Override @Override
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
onNew(); onNew();
} }
}); });
button.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "New"))); btnNew.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "New")) + " Shift+Alt+N");
ToolBarButton button = new ToolBarButton();
button = new ToolBarButton(); button = new ToolBarButton();
button.setImage(ThemeManager.getThemeResource(EDIT_IMAGE)); button.setImage(ThemeManager.getThemeResource(EDIT_IMAGE));
@ -483,6 +488,24 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
return; return;
} }
LayoutUtils.redraw(this); LayoutUtils.redraw(this);
} else if (event.getName().equals(Events.ON_CTRL_KEY)) {
KeyEvent keyEvent = (KeyEvent) event;
if (LayoutUtils.isReallyVisible(this)) {
//filter same key event that is too close
//firefox fire key event twice when grid is visible
long time = System.currentTimeMillis();
if (prevKeyEvent != null && prevKeyEventTime > 0 &&
prevKeyEvent.getKeyCode() == keyEvent.getKeyCode() &&
prevKeyEvent.getTarget() == keyEvent.getTarget() &&
prevKeyEvent.isAltKey() == keyEvent.isAltKey() &&
prevKeyEvent.isCtrlKey() == keyEvent.isCtrlKey() &&
prevKeyEvent.isShiftKey() == keyEvent.isShiftKey()) {
if ((time - prevKeyEventTime) <= 300) {
return;
}
}
this.onCtrlKeyEvent(keyEvent);
}
} }
} }
@ -518,6 +541,17 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
super.onPageDetached(page); super.onPageDetached(page);
if (msgPopup != null) if (msgPopup != null)
msgPopup.detach(); msgPopup.detach();
try {
SessionManager.getSessionApplication().getKeylistener().removeEventListener(Events.ON_CTRL_KEY, this);
} catch (Exception e){}
}
@Override
public void onPageAttached(Page newpage, Page oldpage) {
super.onPageAttached(newpage, oldpage);
if (newpage != null) {
SessionManager.getSessionApplication().getKeylistener().addEventListener(Events.ON_CTRL_KEY, this);
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -715,4 +749,27 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
Event openEvent = new Event(ON_NEW_EVENT, DetailPane.this); Event openEvent = new Event(ON_NEW_EVENT, DetailPane.this);
eventListener.onEvent(openEvent); eventListener.onEvent(openEvent);
} }
public static final int VK_N = 0x4E;
private void onCtrlKeyEvent(KeyEvent keyEvent) {
ToolBarButton btn = null;
if (keyEvent.isAltKey() && !keyEvent.isCtrlKey() && keyEvent.isShiftKey()) { // Shift+Alt key
if (keyEvent.getKeyCode() == VK_N) { // Shift+Alt+N
btn = btnNew;
}
}
if (btn != null) {
prevKeyEventTime = System.currentTimeMillis();
prevKeyEvent = keyEvent;
keyEvent.stopPropagation();
if (!btn.isDisabled() && btn.isVisible()) {
Events.sendEvent(btn, new Event(Events.ON_CLICK, btn));
//client side script to close combobox popup
String script = "var w=zk.Widget.$('#" + btn.getUuid()+"'); " +
"zWatch.fire('onFloatUp', w);";
Clients.response(new AuScript(script));
}
}
}
} }

View File

@ -25,8 +25,10 @@ import org.adempiere.webui.LayoutUtils;
*/ */
public class ToolBarButton extends org.zkoss.zul.Toolbarbutton public class ToolBarButton extends org.zkoss.zul.Toolbarbutton
{ {
/**
private static final long serialVersionUID = 0L; *
*/
private static final long serialVersionUID = -1214319982911389339L;
private String name; private String name;