IDEMPIERE-5898 Implementation of the assistant to type search and table in multi-selection fields (#2079)
* IDEMPIERE-5898 Implementation of the assistant to type search and table in multi-selection fields * IDEMPIERE-5898 Implementation of the assistant to type search and table in multi-selection fields
This commit is contained in:
parent
72c00ff0d6
commit
3560493f25
|
@ -31,7 +31,6 @@ import org.adempiere.webui.component.ListHead;
|
|||
import org.adempiere.webui.component.ListHeader;
|
||||
import org.adempiere.webui.component.ListItem;
|
||||
import org.adempiere.webui.component.Listbox;
|
||||
import org.adempiere.webui.component.Panel;
|
||||
import org.adempiere.webui.component.SimpleListModel;
|
||||
import org.adempiere.webui.component.Window;
|
||||
import org.adempiere.webui.event.ContextMenuEvent;
|
||||
|
@ -285,18 +284,18 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
|
|||
{
|
||||
popupMenu = new WEditorPopupMenu(false, true, isShowPreference(), false, false, false, lookup);
|
||||
addChangeLogMenu(popupMenu);
|
||||
popupMenu.removeNewUpdateMenu();
|
||||
|
||||
if (gridField.getDisplayType() == DisplayType.ChosenMultipleSelectionList) { // The Assistant must be shown for MultipleSelectionList only (not for MultipleSelectionTable editors)
|
||||
Menuitem editor = new Menuitem();
|
||||
editor.setAttribute("EVENT", WEditorPopupMenu.ASSISTANT_EVENT);
|
||||
editor.setLabel(Msg.getMsg(Env.getCtx(), "Assistant"));
|
||||
if (ThemeManager.isUseFontIconForImage())
|
||||
editor.setIconSclass("z-icon-Wizard");
|
||||
else
|
||||
editor.setImage(ThemeManager.getThemeResource("images/Wizard16.png"));
|
||||
editor.addEventListener(Events.ON_CLICK, popupMenu);
|
||||
popupMenu.appendChild(editor);
|
||||
}
|
||||
Menuitem editor = new Menuitem();
|
||||
editor.setAttribute("EVENT", WEditorPopupMenu.ASSISTANT_EVENT);
|
||||
editor.setLabel(Msg.getMsg(Env.getCtx(), "Assistant"));
|
||||
if (ThemeManager.isUseFontIconForImage())
|
||||
editor.setIconSclass("z-icon-Wizard");
|
||||
else
|
||||
editor.setImage(ThemeManager.getThemeResource("images/Wizard16.png"));
|
||||
editor.addEventListener(Events.ON_CLICK, popupMenu);
|
||||
popupMenu.appendChild(editor);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -742,7 +741,7 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
|
|||
private Listbox availableList = new Listbox();
|
||||
private Listbox selectedList = new Listbox();
|
||||
private Hlayout hlayout;
|
||||
private Button bOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK, false, true);
|
||||
private Button bOk, bCancel, bRemoveAll;
|
||||
private int refID = 0;
|
||||
private String m_newValue = "";
|
||||
|
||||
|
@ -787,47 +786,69 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
|
|||
center.setAutoscroll(true);
|
||||
|
||||
//Listener for add and remove button
|
||||
EventListener<Event> actionListener = new EventListener<Event>() {
|
||||
EventListener<Event> actionListenerAddRemove = new EventListener<Event>() {
|
||||
public void onEvent(Event event) throws Exception {
|
||||
migrateValueAcrossLists(event);
|
||||
}
|
||||
};
|
||||
|
||||
//Listener for up and down button
|
||||
EventListener<Event> actionListener2 = new EventListener<Event>() {
|
||||
EventListener<Event> actionListenerUpDown = new EventListener<Event>() {
|
||||
public void onEvent(Event event) throws Exception {
|
||||
migrateValueWithinSelectedList(event);
|
||||
}
|
||||
};
|
||||
|
||||
//Listener for remove all button
|
||||
EventListener<Event> actionListenerRemoveAll = new EventListener<Event>() {
|
||||
public void onEvent(Event event) throws Exception {
|
||||
deleteAllValuesList(event);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
EventListener<Event> mouseListener = new EventListener<Event>() {
|
||||
public void onEvent(Event event) throws Exception {
|
||||
if (Events.ON_DOUBLE_CLICK.equals(event.getName())) {
|
||||
migrateValueAcrossLists(event);
|
||||
if (gridField.getDisplayType() != DisplayType.ChosenMultipleSelectionList) {
|
||||
deleteValueList(event);
|
||||
}else {
|
||||
migrateValueAcrossLists(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
EventListener<Event> crossListMouseListener = new DragListener();
|
||||
|
||||
bUp = createButton("MoveUp16", actionListener2);
|
||||
bDown = createButton("MoveDown16", actionListener2);
|
||||
bAdd = createButton("MoveRight16", actionListener);
|
||||
bRemove = createButton("MoveLeft16", actionListener);
|
||||
bOk.addEventListener(Events.ON_CLICK, this);
|
||||
bUp = createButton("MoveUp16", actionListenerUpDown);
|
||||
bDown = createButton("MoveDown16", actionListenerUpDown);
|
||||
bAdd = createButton("MoveRight16", actionListenerAddRemove);
|
||||
bRemove = createButton("MoveLeft16", actionListenerAddRemove);
|
||||
|
||||
Hlayout yesButtonLayout;
|
||||
yesButtonLayout = createHlayoutBtn(new Button[] {bUp, bDown});
|
||||
|
||||
Hlayout yesButtonLayout = createHlayoutBtn(new Button[] {bUp, bDown});
|
||||
Hlayout noButtonLayout = createHlayoutBtn(new Button[] {bRemove, bAdd});
|
||||
|
||||
initListboxAndModel(selectedList, selectedModel, mouseListener, crossListMouseListener, true, Msg.getMsg(Env.getCtx(), "SelectedItems"), yesButtonLayout);
|
||||
initListboxAndModel(availableList, availableModel, mouseListener, crossListMouseListener, true, Msg.getMsg(Env.getCtx(), "Available"), noButtonLayout);
|
||||
|
||||
hlayout = createHlayoutLine(new Component[] {availableList, selectedList});
|
||||
if (gridField.getDisplayType() == DisplayType.ChosenMultipleSelectionList) {
|
||||
initListboxAndModel(availableList, availableModel, mouseListener, crossListMouseListener, true, Msg.getMsg(Env.getCtx(), "Available"), noButtonLayout);
|
||||
hlayout = createHlayoutLine(new Component[] {availableList, selectedList});
|
||||
} else {
|
||||
hlayout = createHlayoutLine(new Component[] {selectedList});
|
||||
}
|
||||
|
||||
center.appendChild(hlayout);
|
||||
|
||||
Panel confirmPanel = new Panel();
|
||||
confirmPanel.setSclass("confirm-panel-right");
|
||||
confirmPanel.appendChild(bOk);
|
||||
ConfirmPanel confirmPanel = new ConfirmPanel(true, false, true, false, false, false);
|
||||
bOk = confirmPanel.getOKButton();
|
||||
bOk.addEventListener(Events.ON_CLICK, this);
|
||||
bCancel = confirmPanel.getButton(ConfirmPanel.A_CANCEL);
|
||||
bCancel.addEventListener(Events.ON_CLICK, this);
|
||||
bRemoveAll = confirmPanel.getButton(ConfirmPanel.A_RESET);
|
||||
bRemoveAll.addEventListener(Events.ON_CLICK, actionListenerRemoveAll);
|
||||
|
||||
South south = new South();
|
||||
south.setSclass("dialog-footer");
|
||||
|
@ -837,35 +858,42 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
|
|||
|
||||
private void load() {
|
||||
selectedModel.removeAllElements();
|
||||
availableModel.removeAllElements();
|
||||
if (gridField.getDisplayType() != DisplayType.ChosenMultipleSelectionList)
|
||||
availableModel.removeAllElements();
|
||||
|
||||
// selected
|
||||
Object values = getValue();
|
||||
ArrayList<String> listSelected = new ArrayList<String>();
|
||||
if (values != null && !Util.isEmpty((String) values)) {
|
||||
for (String value : ((String) values).split(",")) {
|
||||
selectedModel.addElement(new ValueNamePair (value, MRefList.getListName(Env.getCtx(), refID, value)));
|
||||
if (gridField.getDisplayType() == DisplayType.ChosenMultipleSelectionList) {
|
||||
selectedModel.addElement(new ValueNamePair (value, MRefList.getListName(Env.getCtx(), refID, value)));
|
||||
} else {
|
||||
String name = lookup.getDisplay(value);
|
||||
selectedModel.addElement(new ValueNamePair(value, name));
|
||||
}
|
||||
listSelected.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
// available (data - available)
|
||||
String validationCode = gridField.getVO().ValidationCode;
|
||||
if (!Util.isEmpty(validationCode)) {
|
||||
validationCode = Env.parseContext(Env.getCtx(), gridField.getWindowNo(), gridField.getVO().TabNo, validationCode, false);
|
||||
if (Util.isEmpty(validationCode, true)) {
|
||||
//not validated, ensure list is empty
|
||||
validationCode = "1=2";
|
||||
if (gridField.getDisplayType() == DisplayType.ChosenMultipleSelectionList) {
|
||||
// available (data - available)
|
||||
String validationCode = gridField.getVO().ValidationCode;
|
||||
if (!Util.isEmpty(validationCode)) {
|
||||
validationCode = Env.parseContext(Env.getCtx(), gridField.getWindowNo(), gridField.getVO().TabNo, validationCode, false);
|
||||
if (Util.isEmpty(validationCode, true)) {
|
||||
//not validated, ensure list is empty
|
||||
validationCode = "1=2";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ValueNamePair vnp : MRefList.getList(Env.getCtx(), refID, false, validationCode, "")) {
|
||||
for (ValueNamePair vnp : MRefList.getList(Env.getCtx(), refID, false, validationCode, "")) {
|
||||
|
||||
if (listSelected.contains(vnp.getValue()))
|
||||
continue;
|
||||
if (listSelected.contains(vnp.getValue()))
|
||||
continue;
|
||||
|
||||
availableModel.addElement(new ValueNamePair (vnp.getValue(), MRefList.getListName(Env.getCtx(), refID, vnp.getValue())));
|
||||
listSelected.add(vnp.getValue());
|
||||
availableModel.addElement(new ValueNamePair (vnp.getValue(), MRefList.getListName(Env.getCtx(), refID, vnp.getValue())));
|
||||
listSelected.add(vnp.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -885,6 +913,45 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
|
|||
value = value.deleteCharAt(value.length() - 1);
|
||||
m_newValue = value.toString();
|
||||
this.detach();
|
||||
} else if (event.getTarget() == bCancel) {
|
||||
this.detach();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete All Values from List
|
||||
* @param event
|
||||
*/
|
||||
private void deleteAllValuesList(Event event) {
|
||||
if (gridField.getDisplayType() == DisplayType.ChosenMultipleSelectionList) {
|
||||
selectedModel.removeAllElements();
|
||||
availableModel.removeAllElements();
|
||||
String validationCode = gridField.getVO().ValidationCode;
|
||||
if (!Util.isEmpty(validationCode)) {
|
||||
validationCode = Env.parseContext(Env.getCtx(), gridField.getWindowNo(), gridField.getVO().TabNo, validationCode, false);
|
||||
if (Util.isEmpty(validationCode, true)) {
|
||||
//not validated, ensure list is empty
|
||||
validationCode = "1=2";
|
||||
}
|
||||
}
|
||||
for (ValueNamePair vnp : MRefList.getList(Env.getCtx(), refID, false, validationCode, "")) {
|
||||
availableModel.addElement(new ValueNamePair (vnp.getValue(), MRefList.getListName(Env.getCtx(), refID, vnp.getValue())));
|
||||
}
|
||||
} else {
|
||||
selectedModel.removeAllElements();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove selected item
|
||||
* @param event
|
||||
*/
|
||||
private void deleteValueList (Event event) {
|
||||
Object source = event.getTarget();
|
||||
if (source instanceof ListItem listItem) {
|
||||
int index = listItem.getIndex();
|
||||
selectedModel.removeElement(selectedModel.getElementAt(index));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,24 +13,39 @@
|
|||
*****************************************************************************/
|
||||
package org.adempiere.webui.editor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.webui.LayoutUtils;
|
||||
import org.adempiere.webui.ValuePreference;
|
||||
import org.adempiere.webui.apps.AEnv;
|
||||
import org.adempiere.webui.component.Button;
|
||||
import org.adempiere.webui.component.ChosenSearchBox;
|
||||
import org.adempiere.webui.component.ConfirmPanel;
|
||||
import org.adempiere.webui.component.Label;
|
||||
import org.adempiere.webui.component.ListHead;
|
||||
import org.adempiere.webui.component.ListHeader;
|
||||
import org.adempiere.webui.component.ListItem;
|
||||
import org.adempiere.webui.component.Listbox;
|
||||
import org.adempiere.webui.component.SimpleListModel;
|
||||
import org.adempiere.webui.component.Window;
|
||||
import org.adempiere.webui.event.ContextMenuEvent;
|
||||
import org.adempiere.webui.event.ContextMenuListener;
|
||||
import org.adempiere.webui.event.DialogEvents;
|
||||
import org.adempiere.webui.event.ValueChangeEvent;
|
||||
import org.adempiere.webui.factory.ButtonFactory;
|
||||
import org.adempiere.webui.factory.InfoManager;
|
||||
import org.adempiere.webui.panel.IHelpContext;
|
||||
import org.adempiere.webui.panel.InfoPanel;
|
||||
import org.adempiere.webui.part.WindowContainer;
|
||||
import org.adempiere.webui.session.SessionManager;
|
||||
import org.adempiere.webui.theme.ThemeManager;
|
||||
import org.adempiere.webui.util.ZKUpdateUtil;
|
||||
import org.adempiere.webui.window.WFieldRecordInfo;
|
||||
import org.compiere.model.GridField;
|
||||
import org.compiere.model.Lookup;
|
||||
|
@ -42,16 +57,26 @@ import org.compiere.model.X_AD_CtxHelp;
|
|||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Util;
|
||||
import org.compiere.util.ValueNamePair;
|
||||
import org.zkoss.addon.chosenbox.Chosenbox;
|
||||
import org.zkoss.zk.au.out.AuFocus;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.event.DropEvent;
|
||||
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.Borderlayout;
|
||||
import org.zkoss.zul.Center;
|
||||
import org.zkoss.zul.Hlayout;
|
||||
import org.zkoss.zul.ListModel;
|
||||
import org.zkoss.zul.ListModelList;
|
||||
import org.zkoss.zul.ListSubModel;
|
||||
import org.zkoss.zul.Listitem;
|
||||
import org.zkoss.zul.Menuitem;
|
||||
import org.zkoss.zul.South;
|
||||
|
||||
/**
|
||||
* Default editor for {@link DisplayType#ChosenMultipleSelectionSearch}.
|
||||
|
@ -204,6 +229,18 @@ public class WChosenboxSearchEditor extends WEditor implements ContextMenuListen
|
|||
}
|
||||
}
|
||||
popupMenu = new WEditorPopupMenu(false, true, isShowPreference(), false, false, false, lookup);
|
||||
popupMenu.removeNewUpdateMenu();
|
||||
|
||||
Menuitem editor = new Menuitem();
|
||||
editor.setAttribute("EVENT", WEditorPopupMenu.ASSISTANT_EVENT);
|
||||
editor.setLabel(Msg.getMsg(Env.getCtx(), "Assistant"));
|
||||
if (ThemeManager.isUseFontIconForImage())
|
||||
editor.setIconSclass("z-icon-Wizard");
|
||||
else
|
||||
editor.setImage(ThemeManager.getThemeResource("images/Wizard16.png"));
|
||||
editor.addEventListener(Events.ON_CLICK, popupMenu);
|
||||
popupMenu.appendChild(editor);
|
||||
|
||||
if (ThemeManager.isUseFontIconForImage())
|
||||
getComponent().getButton().setIconSclass(imageUrl);
|
||||
else
|
||||
|
@ -363,6 +400,41 @@ public class WChosenboxSearchEditor extends WEditor implements ContextMenuListen
|
|||
else if (WEditorPopupMenu.CHANGE_LOG_EVENT.equals(evt.getContextEvent()))
|
||||
{
|
||||
WFieldRecordInfo.start(gridField);
|
||||
} else if (WEditorPopupMenu.ASSISTANT_EVENT.equals(evt.getContextEvent())) {
|
||||
final WChosenboxSearchAssistant wdc = new WChosenboxSearchAssistant();
|
||||
wdc.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener<Event>() {
|
||||
public void onEvent(Event event) throws Exception {
|
||||
Object newValue = wdc.getNewValue();
|
||||
updateValue(newValue);
|
||||
setValue(newValue.toString());
|
||||
}
|
||||
});
|
||||
AEnv.showWindow(wdc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ON_SELECT event
|
||||
* @param newValue
|
||||
*/
|
||||
private void updateValue(Object newValue) {
|
||||
try {
|
||||
onselecting = true;
|
||||
|
||||
if (isValueChange(newValue)) {
|
||||
try {
|
||||
if (gridField != null)
|
||||
gridField.setLookupEditorSettingValue(true);
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), "", newValue);
|
||||
super.fireValueChange(changeEvent);
|
||||
this.value = newValue.toString();
|
||||
} finally {
|
||||
if (gridField != null)
|
||||
gridField.setLookupEditorSettingValue(false);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
onselecting = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,6 +488,8 @@ public class WChosenboxSearchEditor extends WEditor implements ContextMenuListen
|
|||
{
|
||||
if (obj != null)
|
||||
{
|
||||
if (newValue.contains(obj.toString()))
|
||||
continue;
|
||||
if (builder.length() > 0)
|
||||
builder.append(",");
|
||||
builder.append(obj.toString());
|
||||
|
@ -426,7 +500,8 @@ public class WChosenboxSearchEditor extends WEditor implements ContextMenuListen
|
|||
}
|
||||
else
|
||||
{
|
||||
newValue = newValue + "," + value.toString();
|
||||
if (!newValue.contains(value.toString()))
|
||||
newValue = newValue + "," + value.toString();
|
||||
}
|
||||
}
|
||||
fireValueChangeEvent(newValue);
|
||||
|
@ -623,6 +698,357 @@ public class WChosenboxSearchEditor extends WEditor implements ContextMenuListen
|
|||
super.dynamicDisplay(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assistant dialog to manage selection of items and to change ordering of selected items.
|
||||
*/
|
||||
private class WChosenboxSearchAssistant extends Window implements EventListener<Event> {
|
||||
private static final long serialVersionUID = 1043859495570181469L;
|
||||
private Button bRemoveAll, bUp, bDown;
|
||||
private SimpleListModel selectedModel = new SimpleListModel();
|
||||
private Listbox selectedList = new Listbox();
|
||||
private Hlayout hlayout;
|
||||
private Button bOk, bCancel;
|
||||
private String m_newValue = "";
|
||||
|
||||
public WChosenboxSearchAssistant() {
|
||||
super();
|
||||
setTitle(gridField.getHeader() + " " + Msg.getMsg(Env.getCtx(), "Assistant"));
|
||||
init();
|
||||
load();
|
||||
setClosable(true);
|
||||
setBorder("normal");
|
||||
setShadow(true);
|
||||
setMaximizable(true);
|
||||
setSizable(true);
|
||||
|
||||
if (!ThemeManager.isUseCSSForWindowSize()) {
|
||||
ZKUpdateUtil.setWindowHeightX(this, 600);
|
||||
ZKUpdateUtil.setWindowWidthX(this, 700);
|
||||
}
|
||||
else
|
||||
{
|
||||
addCallback(AFTER_PAGE_ATTACHED, t -> {
|
||||
ZKUpdateUtil.setCSSHeight(this);
|
||||
ZKUpdateUtil.setCSSWidth(this);
|
||||
});
|
||||
}
|
||||
setSclass("chosenbox-assistant-dialog");
|
||||
|
||||
addCallback(AFTER_PAGE_DETACHED, t -> {
|
||||
WChosenboxSearchEditor.this.getComponent().getChosenbox().focus();
|
||||
});
|
||||
}
|
||||
|
||||
private void init() {
|
||||
m_newValue = getValue() != null ? getValue().toString() : "";
|
||||
|
||||
Borderlayout mainLayout = new Borderlayout();
|
||||
appendChild(mainLayout);
|
||||
|
||||
Center center = new Center();
|
||||
mainLayout.appendChild(center);
|
||||
center.setAutoscroll(true);
|
||||
|
||||
|
||||
|
||||
//Listener for up and down button
|
||||
EventListener<Event> actionListenerUpDown = new EventListener<Event>() {
|
||||
public void onEvent(Event event) throws Exception {
|
||||
migrateValueWithinSelectedList(event);
|
||||
}
|
||||
};
|
||||
//Listener for up and down button
|
||||
EventListener<Event> actionListenerRemoveAll = new EventListener<Event>() {
|
||||
public void onEvent(Event event) throws Exception {
|
||||
deleteAllValuesList(event);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
EventListener<Event> mouseListener = new EventListener<Event>() {
|
||||
public void onEvent(Event event) throws Exception {
|
||||
if (Events.ON_DOUBLE_CLICK.equals(event.getName())) {
|
||||
deleteValueList(event);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
EventListener<Event> crossListMouseListener = new DragListener();
|
||||
|
||||
bUp = createButton("MoveUp16", actionListenerUpDown);
|
||||
bDown = createButton("MoveDown16", actionListenerUpDown);
|
||||
|
||||
Hlayout yesButtonLayout = createHlayoutBtn(new Button[] {bUp, bDown});
|
||||
|
||||
initListboxAndModel(selectedList, selectedModel, mouseListener, crossListMouseListener, true, Msg.getMsg(Env.getCtx(), "SelectedItems"), yesButtonLayout);
|
||||
|
||||
hlayout = createHlayoutLine(new Component[] {selectedList});
|
||||
center.appendChild(hlayout);
|
||||
|
||||
ConfirmPanel confirmPanel = new ConfirmPanel(true, false, true, false, false, false);
|
||||
bOk = confirmPanel.getOKButton();
|
||||
bOk.addEventListener(Events.ON_CLICK, this);
|
||||
bCancel = confirmPanel.getButton(ConfirmPanel.A_CANCEL);
|
||||
bCancel.addEventListener(Events.ON_CLICK, this);
|
||||
bRemoveAll = confirmPanel.getButton(ConfirmPanel.A_RESET);
|
||||
bRemoveAll.addEventListener(Events.ON_CLICK, actionListenerRemoveAll);
|
||||
|
||||
South south = new South();
|
||||
south.setSclass("dialog-footer");
|
||||
mainLayout.appendChild(south);
|
||||
south.appendChild(confirmPanel);
|
||||
}
|
||||
|
||||
private void load() {
|
||||
selectedModel.removeAllElements();
|
||||
|
||||
// selected
|
||||
Object values = getValue();
|
||||
ArrayList<String> listSelected = new ArrayList<String>();
|
||||
if (values != null && !Util.isEmpty((String) values)) {
|
||||
for (String value : ((String) values).split(",")) {
|
||||
|
||||
String name = lookup.getDisplay(value);
|
||||
selectedModel.addElement(new ValueNamePair(value, name));
|
||||
listSelected.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
if (event.getTarget() == bOk) {
|
||||
|
||||
StringBuilder value = new StringBuilder("");
|
||||
|
||||
for (Listitem le : selectedList.getItems()) {
|
||||
int index = selectedList.getIndexOfItem(le);
|
||||
ValueNamePair selObject = (ValueNamePair ) selectedModel.getElementAt(index);
|
||||
value.append(selObject.getID()).append(",");
|
||||
}
|
||||
|
||||
if (value.length() > 0)
|
||||
value = value.deleteCharAt(value.length() - 1);
|
||||
m_newValue = value.toString();
|
||||
this.detach();
|
||||
} else if (event.getTarget() == bCancel) {
|
||||
this.detach();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete All Values from List
|
||||
* @param event
|
||||
*/
|
||||
private void deleteAllValuesList(Event event) {
|
||||
selectedModel.removeAllElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove selected item
|
||||
* @param event
|
||||
*/
|
||||
private void deleteValueList (Event event) {
|
||||
Object source = event.getTarget();
|
||||
if (source instanceof ListItem listItem) {
|
||||
int index = listItem.getIndex();
|
||||
selectedModel.removeElement(selectedModel.getElementAt(index));
|
||||
}
|
||||
}
|
||||
|
||||
private Button createButton(String image, EventListener<Event> actionListener) {
|
||||
Button btn = ButtonFactory.createButton(null, ThemeManager.getThemeResource("images/" + image + ".png"), null);
|
||||
LayoutUtils.addSclass("btn-small", btn);
|
||||
LayoutUtils.addSclass("btn-sorttab small-img-btn", btn);
|
||||
if(actionListener != null)
|
||||
btn.addEventListener(Events.ON_CLICK, actionListener);
|
||||
return btn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lb
|
||||
* @param model
|
||||
* @param mouseListener
|
||||
* @param crossListMouseListener
|
||||
* @param isItemDraggable
|
||||
* @param headerLabel
|
||||
* @param buttonsLayout
|
||||
*/
|
||||
private void initListboxAndModel(Listbox lb, SimpleListModel model, EventListener<Event> mouseListener, EventListener<Event> crossListMouseListener, boolean isItemDraggable, String headerLabel, Hlayout buttonsLayout) {
|
||||
lb.addEventListener(Events.ON_RIGHT_CLICK, this);
|
||||
ZKUpdateUtil.setHflex(lb, "1");
|
||||
ZKUpdateUtil.setVflex(lb, true);
|
||||
|
||||
if (mouseListener != null)
|
||||
lb.addDoubleClickListener(mouseListener);
|
||||
if (crossListMouseListener != null)
|
||||
lb.addOnDropListener(crossListMouseListener);
|
||||
lb.setItemDraggable(isItemDraggable);
|
||||
lb.setItemRenderer(model);
|
||||
lb.setModel(model);
|
||||
model.setMultiple(true);
|
||||
ListHead listHead = new ListHead();
|
||||
listHead.setParent(lb);
|
||||
ListHeader listHeader = new ListHeader();
|
||||
listHeader.appendChild(new Label(headerLabel));
|
||||
listHeader.setParent(listHead);
|
||||
listHeader.appendChild(buttonsLayout);
|
||||
}
|
||||
|
||||
private Hlayout createHlayoutBtn(Button[] btns) {
|
||||
Hlayout hl = new Hlayout();
|
||||
for (Button btn : btns)
|
||||
hl.appendChild(btn);
|
||||
hl.setStyle("display: inline-block; float: right;");
|
||||
return hl;
|
||||
}
|
||||
|
||||
private Hlayout createHlayoutLine(Component[] comps) {
|
||||
|
||||
Hlayout hl = new Hlayout();
|
||||
hl.setValign("middle");
|
||||
for (Component comp : comps)
|
||||
hl.appendChild(comp);
|
||||
hl.setVflex("1");
|
||||
hl.setStyle("margin-bottom: 5px;");
|
||||
return hl;
|
||||
}
|
||||
|
||||
private SimpleListModel getModel(Listbox listbox) {
|
||||
|
||||
SimpleListModel retValue = null;
|
||||
|
||||
if (listbox == selectedList)
|
||||
retValue = selectedModel;
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for DropEvent
|
||||
*/
|
||||
private class DragListener implements EventListener<Event> {
|
||||
public DragListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
if (event instanceof DropEvent) {
|
||||
int endIndex = 0;
|
||||
DropEvent me = (DropEvent) event;
|
||||
ListItem endItem = (ListItem) me.getTarget();
|
||||
ListItem startItem = (ListItem) me.getDragged();
|
||||
|
||||
if (!startItem.isSelected())
|
||||
startItem.setSelected(true);
|
||||
|
||||
Listbox selListbox = selectedList;
|
||||
SimpleListModel selModel = getModel(selListbox);
|
||||
|
||||
if (startItem.getListbox() == endItem.getListbox() && startItem.getListbox() == selListbox) {
|
||||
List<ValueNamePair > selObjects = new ArrayList<ValueNamePair >();
|
||||
endIndex = selListbox.getIndexOfItem(endItem);
|
||||
for (Object obj : selListbox.getSelectedItems()) {
|
||||
ListItem listItem = (ListItem) obj;
|
||||
int index = selListbox.getIndexOfItem(listItem);
|
||||
ValueNamePair selObject = (ValueNamePair ) selModel.getElementAt(index);
|
||||
selObjects.add(selObject);
|
||||
}
|
||||
migrateValueWithinSelectedList (selModel, selListbox, endIndex, selObjects);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move selected items to endIndex
|
||||
* @param selModel
|
||||
* @param selListbox
|
||||
* @param endIndex
|
||||
* @param selObjects
|
||||
*/
|
||||
private void migrateValueWithinSelectedList (SimpleListModel selModel, Listbox selListbox, int endIndex, List<ValueNamePair > selObjects) {
|
||||
int iniIndex =0;
|
||||
Arrays.sort(selObjects.toArray());
|
||||
ValueNamePair selObject= null;
|
||||
ValueNamePair endObject = (ValueNamePair ) selModel.getElementAt(endIndex);
|
||||
for (ValueNamePair selected : selObjects) {
|
||||
iniIndex = selModel.indexOf(selected);
|
||||
selObject = (ValueNamePair ) selModel.getElementAt(iniIndex);
|
||||
selModel.removeElement(selObject);
|
||||
endIndex = selModel.indexOf(endObject);
|
||||
selModel.add(endIndex, selObject);
|
||||
}
|
||||
|
||||
selListbox.removeAllItems();
|
||||
for(int i=0 ; i<selModel.getSize(); i++) {
|
||||
ValueNamePair pp = (ValueNamePair ) selModel.getElementAt(i);
|
||||
selListbox.addItem(new ValueNamePair(pp.getID(), pp.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle event from up and down button. <br/>
|
||||
* Move selected items up/down within {@link #selectedList}.
|
||||
* @param event
|
||||
*/
|
||||
private void migrateValueWithinSelectedList (Event event) {
|
||||
Object[] selObjects = selectedList.getSelectedItems().toArray();
|
||||
if (selObjects == null)
|
||||
return;
|
||||
int length = selObjects.length;
|
||||
if (length == 0)
|
||||
return;
|
||||
//
|
||||
int[] indices = selectedList.getSelectedIndices();
|
||||
//
|
||||
boolean change = false;
|
||||
//
|
||||
Object source = event.getTarget();
|
||||
if (source == bUp) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
int index = indices[i];
|
||||
if (index == 0)
|
||||
break;
|
||||
ValueNamePair selObject = (ValueNamePair ) selectedModel.getElementAt(index);
|
||||
ValueNamePair newObject = (ValueNamePair ) selectedModel.getElementAt(index - 1);
|
||||
selectedModel.setElementAt(newObject, index);
|
||||
selectedModel.setElementAt(selObject, index - 1);
|
||||
indices[i] = index - 1;
|
||||
change = true;
|
||||
}
|
||||
} // up
|
||||
|
||||
else if (source == bDown) {
|
||||
for (int i = length - 1; i >= 0; i--) {
|
||||
int index = indices[i];
|
||||
if (index >= selectedModel.getSize() - 1)
|
||||
break;
|
||||
ValueNamePair selObject = (ValueNamePair ) selectedModel.getElementAt(index);
|
||||
ValueNamePair newObject = (ValueNamePair ) selectedModel.getElementAt(index + 1);
|
||||
selectedModel.setElementAt(newObject, index);
|
||||
selectedModel.setElementAt(selObject, index + 1);
|
||||
selectedList.setSelectedIndex(index + 1);
|
||||
indices[i] = index + 1;
|
||||
change = true;
|
||||
}
|
||||
} // down
|
||||
|
||||
//
|
||||
if (change) {
|
||||
selectedList.setSelectedIndices(indices);
|
||||
if ( selectedList.getSelectedItem() != null) {
|
||||
AuFocus focus = new AuFocus(selectedList.getSelectedItem());
|
||||
Clients.response(focus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getNewValue() {
|
||||
return m_newValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ListSubModel} for {@link Chosenbox} auto complete
|
||||
*/
|
||||
|
|
|
@ -51,7 +51,7 @@ public class WEditorPopupMenu extends Menupopup implements EventListener<Event>
|
|||
/**
|
||||
* generated serial id
|
||||
*/
|
||||
private static final long serialVersionUID = 6190279880520042885L;
|
||||
private static final long serialVersionUID = 4574171758155591250L;
|
||||
|
||||
/** Menu item attribute to store context menu event name (zoom, requery, etc) */
|
||||
public static final String EVENT_ATTRIBUTE = "EVENT";
|
||||
|
@ -371,5 +371,15 @@ public class WEditorPopupMenu extends Menupopup implements EventListener<Event>
|
|||
});
|
||||
appendChild(editor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the new and update items from the menu - for ChosenList
|
||||
*/
|
||||
public void removeNewUpdateMenu() {
|
||||
if (newItem != null)
|
||||
removeChild(newItem);
|
||||
if (updateItem != null)
|
||||
removeChild(updateItem);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue