IDEMPIERE-662 Zk: Menu lookup improvement.

This commit is contained in:
Heng Sin Low 2013-02-25 19:38:23 +08:00
parent 30debbd3e1
commit e40910d646
6 changed files with 258 additions and 25 deletions

View File

@ -117,7 +117,7 @@ public class AutoComplete extends Combobox
/**
* Refresh comboitem based on the specified value.
*/
private void refresh(String val)
public void refresh(String val)
{
if (comboItems == null || val == null) {
super.getChildren().clear();

View File

@ -255,11 +255,11 @@ public abstract class AbstractMenuPanel extends Panel implements EventListener<E
String eventName = event.getName();
if (eventName.equals(Events.ON_CLICK))
{
doOnClick(comp);
doOnClick(comp, event.getData());
}
}
private void doOnClick(Component comp) {
private void doOnClick(Component comp, Object eventData) {
boolean newRecord = false;
if (comp instanceof A) {
comp = comp.getParent().getParent();
@ -267,6 +267,8 @@ public abstract class AbstractMenuPanel extends Panel implements EventListener<E
if (comp instanceof Toolbarbutton) {
comp = comp.getParent().getParent();
newRecord = true;
} else if (eventData != null && eventData instanceof Boolean) {
newRecord = (Boolean)eventData;
}
if (comp instanceof Treerow)
{

View File

@ -34,7 +34,7 @@ public class MenuSearchPanel extends AbstractMenuPanel
*/
private static final long serialVersionUID = 5308522340852904168L;
private TreeSearchPanel pnlSearch;
private MenuTreeSearchPanel pnlSearch;
public MenuSearchPanel(Component parent)
{
@ -74,7 +74,7 @@ public class MenuSearchPanel extends AbstractMenuPanel
toolbar.setMold("panel");
this.appendChild(toolbar);
pnlSearch = new TreeSearchPanel(getMenuTree());
pnlSearch = new MenuTreeSearchPanel(getMenuTree());
pnlSearch.setSclass("menu-search-panel");
toolbar.appendChild(pnlSearch);
}

View File

@ -0,0 +1,210 @@
/******************************************************************************
* Copyright (C) 2013 Heng Sin Low *
* Copyright (C) 2013 Trek Global *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.webui.panel;
import java.util.ArrayList;
import java.util.List;
import org.adempiere.webui.util.TreeItemAction;
import org.adempiere.webui.util.TreeNodeAction;
import org.adempiere.webui.util.TreeUtils;
import org.compiere.model.MTreeNode;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.A;
import org.zkoss.zul.DefaultTreeNode;
import org.zkoss.zul.Hlayout;
import org.zkoss.zul.Toolbarbutton;
import org.zkoss.zul.Tree;
import org.zkoss.zul.Treeitem;
/**
*
* @author hengsin
*
*/
public class MenuTreeSearchPanel extends TreeSearchPanel {
/**
* generated serial id
*/
private static final long serialVersionUID = 8785295166415073971L;
private Toolbarbutton newBtn;
private Toolbarbutton openBtn;
private boolean isNew = false;
public MenuTreeSearchPanel(Tree tree, String event, int windowno, int tabno) {
super(tree, event, windowno, tabno);
}
public MenuTreeSearchPanel(Tree tree, String event) {
super(tree, event);
}
public MenuTreeSearchPanel(Tree tree) {
super(tree);
}
@Override
protected void init() {
super.init();
layout.getFirstChild().detach();
Hlayout hlayout = new Hlayout();
hlayout.setValign("middle");
hlayout.setSpacing("0px");
hlayout.setSclass("menu-search-toggle-box");
newBtn = new Toolbarbutton();
newBtn.setImage("/images/New16.png");
newBtn.setSclass("menu-search-toggle-off");
newBtn.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
newBtn.setDisabled(true);
newBtn.setSclass("menu-search-toggle-on");
isNew = true;
openBtn.setDisabled(false);
openBtn.setSclass("menu-search-toggle-off");
refreshAutoComplete();
}
});
newBtn.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "New")));
openBtn = new Toolbarbutton();
openBtn.setImage("/images/Open16.png");
openBtn.setSclass("menu-search-toggle-on");
openBtn.setDisabled(true);
openBtn.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
openBtn.setDisabled(true);
openBtn.setSclass("menu-search-toggle-on");
isNew = false;
newBtn.setDisabled(false);
newBtn.setSclass("menu-search-toggle-off");
refreshAutoComplete();
}
});
openBtn.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Open")));
hlayout.appendChild(newBtn);
hlayout.appendChild(openBtn);
layout.insertBefore(hlayout, layout.getFirstChild());
}
@Override
public void refreshSearchList() {
treeNodeItemMap.clear();
if (tree.getModel() == null) {
TreeUtils.traverse(tree, new TreeItemAction() {
public void run(Treeitem treeItem) {
if (treeItem.isVisible())
addTreeItem(treeItem);
}
});
} else {
TreeUtils.traverse(tree.getModel(), new TreeNodeAction() {
public void run(DefaultTreeNode<?> treeNode) {
addTreeItem(treeNode);
}
});
}
refreshAutoComplete();
}
private void refreshAutoComplete() {
List<String> valueList = new ArrayList<String>();
List<String> descriptionList = new ArrayList<String>();
List<String> imageList = new ArrayList<String>();
for (Object value : treeNodeItemMap.values())
{
if (value instanceof Treeitem)
{
Treeitem treeItem = (Treeitem) value;
if (isFolder(treeItem))
continue;
if (isNew) {
if (!"window".equals(treeItem.getAttribute("menu.type"))) {
continue;
}
}
valueList.add(getLabel(treeItem));
descriptionList.add(treeItem.getTooltiptext());
String image = getImage(treeItem);
if (image == null || image.length() == 0)
{
image = "/images/Folder16.png";
}
imageList.add(image);
}
else if (value instanceof DefaultTreeNode)
{
DefaultTreeNode<?> sNode = (DefaultTreeNode<?>) value;
MTreeNode mNode = (MTreeNode) sNode.getData();
if (!mNode.isLeaf())
continue;
if (isNew) {
if (!mNode.isWindow()) {
continue;
}
}
valueList.add(mNode.getName());
descriptionList.add(mNode.getDescription());
imageList.add(mNode.getImagePath());
}
}
treeDescription = descriptionList.toArray(new String[0]);
treeValues = valueList.toArray(new String[0]);
treeImages = imageList.toArray(new String[0]);
cmbSearch.setDescription(treeDescription);
cmbSearch.setDict(treeValues);
cmbSearch.setImages(treeImages);
cmbSearch.refresh("");
}
@Override
protected void onPostSelectTreeitem() {
Clients.clearBusy();
Event event = null;
if (eventToFire.equals(Events.ON_CLICK))
{
if (tree.getSelectedItem().getTreerow().getFirstChild().getFirstChild() instanceof A)
{
event = new Event(Events.ON_CLICK, tree.getSelectedItem().getTreerow().getFirstChild().getFirstChild(), isNew);
}
else
{
event = new Event(Events.ON_CLICK, tree.getSelectedItem().getTreerow(), isNew);
}
}
else
event = new Event(eventToFire, tree, isNew);
Events.postEvent(event);
Events.echoEvent(ON_POST_FIRE_TREE_EVENT, this, null);
}
}

View File

@ -63,27 +63,28 @@ public class TreeSearchPanel extends Panel implements EventListener<Event>, Tree
{
private static final String ON_COMBO_SELECT_ECHO_EVENT = "onComboSelectEcho";
private static final String ON_POST_SELECT_TREEITEM_EVENT = "onPostSelectTreeitem";
private static final String ON_POST_FIRE_TREE_EVENT = "onPostFireTreeEvent";
protected static final String ON_POST_FIRE_TREE_EVENT = "onPostFireTreeEvent";
/**
*
*/
private static final long serialVersionUID = 3478451169922775667L;
private TreeMap<String, Object> treeNodeItemMap = new TreeMap<String, Object>();
private String[] treeValues;
private String[] treeDescription;
private String[] treeImages;
protected TreeMap<String, Object> treeNodeItemMap = new TreeMap<String, Object>();
protected String[] treeValues;
protected String[] treeDescription;
protected String[] treeImages;
private Label lblSearch;
protected AutoComplete cmbSearch;
private Tree tree;
protected Tree tree;
private String eventToFire;
protected String eventToFire;
@SuppressWarnings("unused")
private int m_windowno = 0;
@SuppressWarnings("unused")
private int m_tabno = 0;
private Treeitem selectedItem;
protected Hlayout layout;
private static final String PREFIX_DOCUMENT_SEARCH = "/";
@ -128,10 +129,10 @@ public class TreeSearchPanel extends Panel implements EventListener<Event>, Tree
+ "var evt = new zk.Event(panel, 'onComboSelectEcho', [comboitem.uuid, popupheight], {toServer: true});"
+ "zAu.send(evt);";
private void init()
protected void init()
{
Hlayout hLayout = new Hlayout();
hLayout.setValign("middle");
layout = new Hlayout();
layout.setValign("middle");
lblSearch = new Label();
lblSearch.setValue(Msg.getMsg(Env.getCtx(),"TreeSearch").replaceAll("&", "") + ":");
lblSearch.setTooltiptext(Msg.getMsg(Env.getCtx(),"TreeSearchText"));
@ -164,20 +165,20 @@ public class TreeSearchPanel extends Panel implements EventListener<Event>, Tree
cmbSearch.setWidth("200px");
}
hLayout.appendChild(lblSearch);
hLayout.appendChild(cmbSearch);
this.appendChild(hLayout);
layout.appendChild(lblSearch);
layout.appendChild(cmbSearch);
this.appendChild(layout);
addEventListener(ON_POST_FIRE_TREE_EVENT, this);
}
private void addTreeItem(Treeitem treeItem)
protected void addTreeItem(Treeitem treeItem)
{
String key = getLabel(treeItem);
treeNodeItemMap.put(key, treeItem);
}
private void addTreeItem(DefaultTreeNode<?> node) {
protected void addTreeItem(DefaultTreeNode<?> node) {
Object data = node.getData();
if (data instanceof MTreeNode) {
MTreeNode mNode = (MTreeNode) data;
@ -250,7 +251,7 @@ public class TreeSearchPanel extends Panel implements EventListener<Event>, Tree
cmbSearch.setImages(treeImages);
}
private boolean isFolder(Treeitem treeItem) {
protected boolean isFolder(Treeitem treeItem) {
List<Component> list = treeItem.getChildren();
for (Component c : list) {
if (c instanceof Treechildren && ((Treechildren)c).getChildren().size() > 1) {
@ -260,7 +261,7 @@ public class TreeSearchPanel extends Panel implements EventListener<Event>, Tree
return false;
}
private String getLabel(Treeitem treeItem) {
protected String getLabel(Treeitem treeItem) {
String label = treeItem.getLabel();
if (label == null || label.trim().length() == 0)
{
@ -274,7 +275,7 @@ public class TreeSearchPanel extends Panel implements EventListener<Event>, Tree
return label;
}
private String getImage(Treeitem treeItem) {
protected String getImage(Treeitem treeItem) {
String image = treeItem.getImage();
if (image == null || image.trim().length() == 0)
{
@ -378,7 +379,7 @@ public class TreeSearchPanel extends Panel implements EventListener<Event>, Tree
}
}
private void onPostSelectTreeitem() {
protected void onPostSelectTreeitem() {
Clients.clearBusy();
Event event = null;
if (eventToFire.equals(Events.ON_CLICK))

View File

@ -1220,4 +1220,24 @@ tbody.z-grid-empty-body td {
font-weight: normal;
}
.
.menu-search-toggle-box {
display: inline-block;
border: 1px solid #ababab;
}
.menu-search-toggle-box .z-toolbarbutton-over {
border: none;
}
.menu-search-toggle-off {
margin:0px;
padding: 1px 4px 1px 4px;
}
.menu-search-toggle-on {
background: #999999;
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3) inset;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3) inset;
margin:0px;
padding: 1px 4px 1px 4px;
}