IDEMPIERE-231 Zk6: Improve the tablet experience. Fixed tree search broken by earlier revision for this ticket. Added support to show image in the combo items.
This commit is contained in:
parent
aab1a1c4d8
commit
ed3021b966
|
@ -44,6 +44,8 @@ public class AutoComplete extends Combobox
|
||||||
/** strDescription Description of menu items */
|
/** strDescription Description of menu items */
|
||||||
private String[] strDescription;
|
private String[] strDescription;
|
||||||
|
|
||||||
|
private String[] images;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set menu labels
|
* Set menu labels
|
||||||
*
|
*
|
||||||
|
@ -71,6 +73,11 @@ public class AutoComplete extends Combobox
|
||||||
strDescription = vals;
|
strDescription = vals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setImages(String[] images)
|
||||||
|
{
|
||||||
|
this.images = images;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
@ -144,6 +151,10 @@ public class AutoComplete extends Combobox
|
||||||
|
|
||||||
comboitem.setLabel(comboItems[i]);
|
comboitem.setLabel(comboItems[i]);
|
||||||
comboitem.setDescription(strDescription[i]);
|
comboitem.setDescription(strDescription[i]);
|
||||||
|
if (images != null && i < images.length && images[i] != null && images[i].trim().length() > 0)
|
||||||
|
{
|
||||||
|
comboitem.setImage(images[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (it != null && it.hasNext()) {
|
while (it != null && it.hasNext()) {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package org.adempiere.webui.panel;
|
package org.adempiere.webui.panel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.adempiere.webui.AdempiereIdGenerator;
|
import org.adempiere.webui.AdempiereIdGenerator;
|
||||||
|
@ -31,17 +32,21 @@ import org.adempiere.webui.util.TreeUtils;
|
||||||
import org.compiere.model.MTreeNode;
|
import org.compiere.model.MTreeNode;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.Msg;
|
import org.compiere.util.Msg;
|
||||||
|
import org.zkoss.zk.ui.Component;
|
||||||
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.util.Clients;
|
import org.zkoss.zk.ui.util.Clients;
|
||||||
import org.zkoss.zul.Div;
|
import org.zkoss.zul.A;
|
||||||
import org.zkoss.zul.DefaultTreeNode;
|
import org.zkoss.zul.DefaultTreeNode;
|
||||||
import org.zkoss.zul.Hlayout;
|
import org.zkoss.zul.Hlayout;
|
||||||
import org.zkoss.zul.Tree;
|
import org.zkoss.zul.Tree;
|
||||||
|
import org.zkoss.zul.Treechildren;
|
||||||
import org.zkoss.zul.Treeitem;
|
import org.zkoss.zul.Treeitem;
|
||||||
import org.zkoss.zul.event.TreeDataEvent;
|
import org.zkoss.zul.event.TreeDataEvent;
|
||||||
import org.zkoss.zul.event.TreeDataListener;
|
import org.zkoss.zul.event.TreeDataListener;
|
||||||
|
import org.zkoss.zul.impl.LabelElement;
|
||||||
|
import org.zkoss.zul.impl.LabelImageElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -49,7 +54,7 @@ import org.zkoss.zul.event.TreeDataListener;
|
||||||
* @date Mar 3, 2007
|
* @date Mar 3, 2007
|
||||||
* @version $Revision: 0.10 $
|
* @version $Revision: 0.10 $
|
||||||
*/
|
*/
|
||||||
public class TreeSearchPanel extends Panel implements EventListener, TreeDataListener
|
public class TreeSearchPanel extends Panel implements EventListener<Event>, TreeDataListener
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -58,6 +63,7 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis
|
||||||
private TreeMap<String, Object> treeNodeItemMap = new TreeMap<String, Object>();
|
private TreeMap<String, Object> treeNodeItemMap = new TreeMap<String, Object>();
|
||||||
private String[] treeValues;
|
private String[] treeValues;
|
||||||
private String[] treeDescription;
|
private String[] treeDescription;
|
||||||
|
private String[] treeImages;
|
||||||
|
|
||||||
private Label lblSearch;
|
private Label lblSearch;
|
||||||
private AutoComplete cmbSearch;
|
private AutoComplete cmbSearch;
|
||||||
|
@ -130,7 +136,7 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis
|
||||||
|
|
||||||
private void addTreeItem(Treeitem treeItem)
|
private void addTreeItem(Treeitem treeItem)
|
||||||
{
|
{
|
||||||
String key = treeItem.getLabel();
|
String key = getLabel(treeItem);
|
||||||
treeNodeItemMap.put(key, treeItem);
|
treeNodeItemMap.put(key, treeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +180,7 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis
|
||||||
|
|
||||||
treeValues = new String[treeNodeItemMap.size()];
|
treeValues = new String[treeNodeItemMap.size()];
|
||||||
treeDescription = new String[treeNodeItemMap.size()];
|
treeDescription = new String[treeNodeItemMap.size()];
|
||||||
|
treeImages = new String[treeNodeItemMap.size()];
|
||||||
|
|
||||||
int i = -1;
|
int i = -1;
|
||||||
|
|
||||||
|
@ -183,8 +190,13 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis
|
||||||
if (value instanceof Treeitem)
|
if (value instanceof Treeitem)
|
||||||
{
|
{
|
||||||
Treeitem treeItem = (Treeitem) value;
|
Treeitem treeItem = (Treeitem) value;
|
||||||
treeValues[i] = treeItem.getLabel();
|
treeValues[i] = getLabel(treeItem);
|
||||||
treeDescription[i] = treeItem.getTooltiptext();
|
treeDescription[i] = treeItem.getTooltiptext();
|
||||||
|
treeImages[i] = getImage(treeItem);
|
||||||
|
if ((treeImages[i] == null || treeImages[i].trim().length() == 0) && isFolder(treeItem))
|
||||||
|
{
|
||||||
|
treeImages[i] = "/images/Folder16.png";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (value instanceof DefaultTreeNode)
|
else if (value instanceof DefaultTreeNode)
|
||||||
{
|
{
|
||||||
|
@ -192,11 +204,51 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis
|
||||||
MTreeNode mNode = (MTreeNode) sNode.getData();
|
MTreeNode mNode = (MTreeNode) sNode.getData();
|
||||||
treeValues[i] = mNode.getName();
|
treeValues[i] = mNode.getName();
|
||||||
treeDescription[i] = mNode.getDescription();
|
treeDescription[i] = mNode.getDescription();
|
||||||
|
treeImages[i] = mNode.getImageIndiactor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmbSearch.setDescription(treeDescription);
|
cmbSearch.setDescription(treeDescription);
|
||||||
cmbSearch.setDict(treeValues);
|
cmbSearch.setDict(treeValues);
|
||||||
|
cmbSearch.setImages(treeImages);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isFolder(Treeitem treeItem) {
|
||||||
|
List<Component> list = treeItem.getChildren();
|
||||||
|
for (Component c : list) {
|
||||||
|
if (c instanceof Treechildren && ((Treechildren)c).getChildren().size() > 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLabel(Treeitem treeItem) {
|
||||||
|
String label = treeItem.getLabel();
|
||||||
|
if (label == null || label.trim().length() == 0)
|
||||||
|
{
|
||||||
|
if (treeItem.getTreerow().getFirstChild().getFirstChild() != null &&
|
||||||
|
treeItem.getTreerow().getFirstChild().getFirstChild() instanceof LabelElement)
|
||||||
|
{
|
||||||
|
LabelElement element = (LabelElement) treeItem.getTreerow().getFirstChild().getFirstChild();
|
||||||
|
label = element.getLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getImage(Treeitem treeItem) {
|
||||||
|
String image = treeItem.getImage();
|
||||||
|
if (image == null || image.trim().length() == 0)
|
||||||
|
{
|
||||||
|
if (treeItem.getTreerow().getFirstChild().getFirstChild() != null &&
|
||||||
|
treeItem.getTreerow().getFirstChild().getFirstChild() instanceof LabelImageElement)
|
||||||
|
{
|
||||||
|
LabelImageElement element = (LabelImageElement) treeItem.getTreerow().getFirstChild().getFirstChild();
|
||||||
|
image = element.getImage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -246,7 +298,16 @@ public class TreeSearchPanel extends Panel implements EventListener, TreeDataLis
|
||||||
Clients.clearBusy();
|
Clients.clearBusy();
|
||||||
Event event = null;
|
Event event = null;
|
||||||
if (eventToFire.equals(Events.ON_CLICK))
|
if (eventToFire.equals(Events.ON_CLICK))
|
||||||
event = new Event(Events.ON_CLICK, tree.getSelectedItem().getTreerow());
|
{
|
||||||
|
if (tree.getSelectedItem().getTreerow().getFirstChild().getFirstChild() instanceof A)
|
||||||
|
{
|
||||||
|
event = new Event(Events.ON_CLICK, tree.getSelectedItem().getTreerow().getFirstChild().getFirstChild());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
event = new Event(Events.ON_CLICK, tree.getSelectedItem().getTreerow());
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
event = new Event(eventToFire, tree);
|
event = new Event(eventToFire, tree);
|
||||||
Events.postEvent(event);
|
Events.postEvent(event);
|
||||||
|
|
Loading…
Reference in New Issue