IDEMPIERE-3851 Filtering list box (AP2-671 TrekGlobal) - integrate development from Elaine Tan

This commit is contained in:
Carlos Ruiz 2018-12-18 17:28:24 +01:00
parent 1fd56b7609
commit 83f8ea2253
4 changed files with 189 additions and 17 deletions

View File

@ -0,0 +1,10 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Oct 11, 2018 5:49:00 PM SGT
-- AP2-671 Make a filtering list box
UPDATE AD_Field SET DisplayLogic='@AD_Reference_ID@=10 | @AD_Reference_ID@=17 | @AD_Reference_ID@=18 | @AD_Reference_ID@=19', AD_Val_Rule_ID=NULL, AD_Reference_Value_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2018-10-11 17:49:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=56279
;
SELECT register_migration_script('201810122100_Ticket_AP2-671.sql') FROM dual
;

View File

@ -0,0 +1,7 @@
-- Oct 11, 2018 5:49:00 PM SGT
-- AP2-671 Make a filtering list box
UPDATE AD_Field SET DisplayLogic='@AD_Reference_ID@=10 | @AD_Reference_ID@=17 | @AD_Reference_ID@=18 | @AD_Reference_ID@=19', AD_Val_Rule_ID=NULL, AD_Reference_Value_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2018-10-11 17:49:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=56279
;
SELECT register_migration_script('201810122100_Ticket_AP2-671.sql') FROM dual
;

View File

@ -17,6 +17,7 @@
package org.adempiere.webui.component;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
@ -36,7 +37,7 @@ public class AutoComplete extends Combobox
/**
*
*/
private static final long serialVersionUID = 8350448733668388572L;
private static final long serialVersionUID = 7437206681528058083L;
/** comboItems All menu labels */
private String[] comboItems;
@ -47,6 +48,8 @@ public class AutoComplete extends Combobox
private String[] images;
private String[] contents;
private Object[] values;
private HashMap<Comboitem, String> mapItems = new HashMap<Comboitem, String>();
@ -57,8 +60,18 @@ public class AutoComplete extends Combobox
*/
public void setDict(String[] vals)
{
setDict(vals, true);
}
public void setDict(String[] vals, boolean sort)
{
comboItems = vals;
if (comboItems != null && sort)
{
Arrays.sort(comboItems);
}
}
/**
@ -88,6 +101,11 @@ public class AutoComplete extends Combobox
this.images = images;
}
public void setValues(Object[] values)
{
this.values = values;
}
/**
* Constructor
*/
@ -161,6 +179,8 @@ public class AutoComplete extends Combobox
}
comboitem.setLabel(comboItems[i]);
if (values != null)
comboitem.setValue(values[i]);
comboitem.setDescription(strDescription[i]);
if (images != null && i < images.length && images[i] != null && images[i].trim().length() > 0)

View File

@ -27,6 +27,7 @@ import javax.swing.event.ListDataListener;
import org.adempiere.webui.ValuePreference;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.AutoComplete;
import org.adempiere.webui.component.Combobox;
import org.adempiere.webui.event.ContextMenuEvent;
import org.adempiere.webui.event.ContextMenuListener;
@ -53,6 +54,7 @@ import org.compiere.util.Msg;
import org.compiere.util.NamePair;
import org.compiere.util.Util;
import org.compiere.util.ValueNamePair;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
@ -96,8 +98,13 @@ ContextMenuListener, IZoomableEditor
public WTableDirEditor(GridField gridField)
{
super(new EditorCombobox(), gridField);
((EditorCombobox)getComponent()).editor = this;
this(gridField.isAutocomplete() ? new EditorAutoComplete() : new EditorCombobox(), gridField);
}
private WTableDirEditor(Component comp, GridField gridField)
{
super(comp, gridField);
((ITableDirEditor)getComponent()).setEditor(this);
lookup = gridField.getLookup();
init();
}
@ -114,8 +121,18 @@ ContextMenuListener, IZoomableEditor
*/
public WTableDirEditor(Lookup lookup, String label, String description, boolean mandatory, boolean readonly, boolean updateable)
{
super(new EditorCombobox(), label, description, mandatory, readonly, updateable);
((EditorCombobox)getComponent()).editor = this;
this(lookup, label, description, mandatory, readonly, updateable, false);
}
public WTableDirEditor(Lookup lookup, String label, String description, boolean mandatory, boolean readonly, boolean updateable, boolean autocomplete)
{
this(autocomplete ? new EditorAutoComplete() : new EditorCombobox(), lookup, label, description, mandatory, readonly, updateable);
}
private WTableDirEditor(Component comp, Lookup lookup, String label, String description, boolean mandatory, boolean readonly, boolean updateable)
{
super(comp, label, description, mandatory, readonly, updateable);
((ITableDirEditor)getComponent()).setEditor(this);
if (lookup == null)
{
@ -135,11 +152,20 @@ ContextMenuListener, IZoomableEditor
* @param isUpdateable
* @param lookup
*/
public WTableDirEditor(String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable,
Lookup lookup)
public WTableDirEditor(String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, Lookup lookup)
{
super(new EditorCombobox(), columnName, null, null, mandatory, isReadOnly, isUpdateable);
((EditorCombobox)getComponent()).editor = this;
this(columnName, mandatory, isReadOnly, isUpdateable, lookup, false);
}
public WTableDirEditor(String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, Lookup lookup, boolean autocomplete)
{
this(autocomplete ? new EditorAutoComplete() : new EditorCombobox(), columnName, mandatory, isReadOnly, isUpdateable, lookup);
}
private WTableDirEditor(Component comp, String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, Lookup lookup)
{
super(comp, columnName, null, null, mandatory, isReadOnly, isUpdateable);
((ITableDirEditor)getComponent()).setEditor(this);
if (lookup == null)
{
throw new IllegalArgumentException("Lookup cannot be null");
@ -153,10 +179,12 @@ ContextMenuListener, IZoomableEditor
ZKUpdateUtil.setWidth(getComponent(), "200px");
getComponent().setAutocomplete(true);
getComponent().setAutodrop(true);
getComponent().addEventListener(Events.ON_BLUR, this);
getComponent().addEventListener(Events.ON_CHANGING, this);
getComponent().addEventListener(Events.ON_OPEN, this);
getComponent().addEventListener("onPostSelect", this);
getComponent().addEventListener(Events.ON_BLUR, this);
if (getComponent() instanceof EditorAutoComplete) {
;
} else {
getComponent().addEventListener(Events.ON_CHANGING, this);
}
boolean zoom= false;
if (lookup != null)
@ -309,6 +337,9 @@ ContextMenuListener, IZoomableEditor
getComponent().setValue(null);
getComponent().setSelectedItem(null);
oldValue = value;
if (getComponent() instanceof EditorAutoComplete)
updateStyle();
}
}
@ -394,6 +425,26 @@ ContextMenuListener, IZoomableEditor
}
}
}
if (getComponent() instanceof EditorAutoComplete) {
EditorAutoComplete editor = (EditorAutoComplete) getComponent();
editor.setDict(null);
editor.setValues(null);
editor.setDescription(null);
String[] dict = new String[getComponent().getItemCount()];
Object[] values = new Object[getComponent().getItemCount()];
String[] description = new String[getComponent().getItemCount()];
for (int i = 0; i < dict.length; i++) {
Comboitem item = getComponent().getItemAtIndex(i);
dict[i] = item.getLabel();
values[i] = item.getValue();
}
editor.setDict(dict, false);
editor.setDescription(description);
editor.setValues(values);
}
getComponent().setValue(oldValue);
}
@ -673,15 +724,27 @@ ContextMenuListener, IZoomableEditor
super.dynamicDisplay(ctx);
}
private static class EditorCombobox extends Combobox {
private interface ITableDirEditor {
public void setEditor(WTableDirEditor editor);
}
private static class EditorCombobox extends Combobox implements ITableDirEditor {
/**
* generated serial id
*/
private static final long serialVersionUID = 4540856986889452983L;
protected WTableDirEditor editor;
private static final long serialVersionUID = 9087317631313577239L;
private WTableDirEditor editor;
private DesktopCleanup listener = null;
protected EditorCombobox() {
}
@Override
public void setPage(Page page) {
super.setPage(page);
}
@Override
public void onPageAttached(Page newpage, Page oldpage) {
super.onPageAttached(newpage, oldpage);
@ -716,6 +779,78 @@ ContextMenuListener, IZoomableEditor
editor.tableCacheListener = null;
}
}
@Override
public void setEditor(WTableDirEditor editor) {
this.editor = editor;
}
}
private static class EditorAutoComplete extends AutoComplete implements ITableDirEditor {
/**
* generated serial id
*/
private static final long serialVersionUID = 8435677226644775152L;
protected WTableDirEditor editor;
private DesktopCleanup listener = null;
protected EditorAutoComplete() {
}
@Override
public void setPage(Page page) {
super.setPage(page);
}
@Override
public void onPageAttached(Page newpage, Page oldpage) {
super.onPageAttached(newpage, oldpage);
if (editor.tableCacheListener == null) {
editor.createCacheListener();
if (listener == null) {
listener = new DesktopCleanup() {
@Override
public void cleanup(Desktop desktop) throws Exception {
EditorAutoComplete.this.cleanup();
}
};
newpage.getDesktop().addListener(listener);
}
}
}
@Override
public void onPageDetached(Page page) {
super.onPageDetached(page);
if (listener != null && page.getDesktop() != null)
page.getDesktop().removeListener(listener);
cleanup();
}
/**
*
*/
protected void cleanup() {
if (editor.tableCacheListener != null) {
CacheMgt.get().unregister(editor.tableCacheListener);
editor.tableCacheListener = null;
}
}
@Override
public void setEditor(WTableDirEditor editor) {
this.editor = editor;
}
@Override
public void setValue(String value)
{
setText(value);
if (Util.isEmpty(value)) {
refresh("");
}
}
}
private static class CCacheListener extends CCache<String, Object> {