From a5b5494294896a25a5eb346df7cf24e33c4b75bb Mon Sep 17 00:00:00 2001 From: Nicolas Micoud <58596990+nmicoud@users.noreply.github.com> Date: Tue, 11 Jan 2022 18:02:50 +0100 Subject: [PATCH] IDEMPIERE-4903 : Add double click events on WTreeMaintenance (#1122) * IDEMPIERE-4903 : Add double click events on WTreeMaintenance * IDEMPIERE-4903 : Add double click events on WTreeMaintenance Fix errors, detail in ticket * peer review and tests Co-authored-by: Carlos Ruiz --- .../webui/apps/form/WTreeMaintenance.java | 57 ++++++++++++++----- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WTreeMaintenance.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WTreeMaintenance.java index 07955dd2a3..9eba7fb128 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WTreeMaintenance.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WTreeMaintenance.java @@ -117,6 +117,7 @@ public class WTreeMaintenance extends TreeMaintenance implements IFormController // centerTree = new Tree(); centerTree.addEventListener(Events.ON_SELECT, this); + centerTree.addEventListener(Events.ON_DOUBLE_CLICK, this); } // preInit /** @@ -223,7 +224,17 @@ public class WTreeMaintenance extends TreeMaintenance implements IFormController ZKUpdateUtil.setVflex(centerList, true); centerList.setSizedByContent(false); centerList.addEventListener(Events.ON_SELECT, this); + centerList.addDoubleClickListener(centerListListener); } // jbInit + + EventListener centerListListener = new EventListener() { + public void onEvent(Event event) throws Exception { + if (Events.ON_DOUBLE_CLICK.equals(event.getName())) { + add(); + bAdd.setDisabled(true); + } + } + }; /** * Dispose @@ -247,31 +258,46 @@ public class WTreeMaintenance extends TreeMaintenance implements IFormController action_treeAddAll(); else if (e.getTarget() == bAdd) { - SimpleListModel model = (SimpleListModel) centerList.getModel(); - int i = centerList.getSelectedIndex(); - if (i >= 0) { - action_treeAdd((ListItem)model.getElementAt(i)); - } + add(); } - else if (e.getTarget() == bDelete) { - SimpleListModel model = (SimpleListModel) centerList.getModel(); - int i = centerList.getSelectedIndex(); - if (i >= 0) { - action_treeDelete((ListItem)model.getElementAt(i)); - } + remove(); } else if (e.getTarget() == bDeleteAll) action_treeDeleteAll(); else if (e.getTarget() == centerList) onListSelection(e); - else if (e.getTarget() == centerTree) - onTreeSelection(e); + else if (e.getTarget() == centerTree) { + if (e.getName().equals(Events.ON_DOUBLE_CLICK)) + remove(); + else + onTreeSelection(e); + } else if (e.getTarget() == searchBox.getButton() || e.getTarget() == searchBox.getTextbox()) searchElement(); } // actionPerformed + void add() { + SimpleListModel model = (SimpleListModel) centerList.getModel(); + int i = centerList.getSelectedIndex(); + if (i >= 0) { + action_treeAdd((ListItem)model.getElementAt(i)); + } + } + + void remove() { + + if (cbAllNodes.isChecked()) + return; + + SimpleListModel model = (SimpleListModel) centerList.getModel(); + int i = centerList.getSelectedIndex(); + if (i >= 0) { + action_treeDelete((ListItem)model.getElementAt(i)); + } + } + private void searchElement() { String filter = searchBox.getText() == null ? "" : searchBox.getText(); filter = Util.deleteAccents(filter.trim().toUpperCase()); @@ -420,9 +446,10 @@ public class WTreeMaintenance extends TreeMaintenance implements IFormController stn = new DefaultTreeNode(new MTreeNode(item.id, 0, item.name, item.description, 0, item.isSummary, item.imageIndicator, false, null), new ArrayList>()); model.addNode(stn); + // May cause Error if in tree + addNode(item); } - // May cause Error if in tree - addNode(item); + } } // action_treeAdd