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 <carg67@gmail.com>
This commit is contained in:
Nicolas Micoud 2022-01-11 18:02:50 +01:00 committed by GitHub
parent 916a5a9233
commit a5b5494294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 15 deletions

View File

@ -117,6 +117,7 @@ public class WTreeMaintenance extends TreeMaintenance implements IFormController
// //
centerTree = new Tree(); centerTree = new Tree();
centerTree.addEventListener(Events.ON_SELECT, this); centerTree.addEventListener(Events.ON_SELECT, this);
centerTree.addEventListener(Events.ON_DOUBLE_CLICK, this);
} // preInit } // preInit
/** /**
@ -223,8 +224,18 @@ public class WTreeMaintenance extends TreeMaintenance implements IFormController
ZKUpdateUtil.setVflex(centerList, true); ZKUpdateUtil.setVflex(centerList, true);
centerList.setSizedByContent(false); centerList.setSizedByContent(false);
centerList.addEventListener(Events.ON_SELECT, this); centerList.addEventListener(Events.ON_SELECT, this);
centerList.addDoubleClickListener(centerListListener);
} // jbInit } // jbInit
EventListener<Event> centerListListener = new EventListener<Event>() {
public void onEvent(Event event) throws Exception {
if (Events.ON_DOUBLE_CLICK.equals(event.getName())) {
add();
bAdd.setDisabled(true);
}
}
};
/** /**
* Dispose * Dispose
*/ */
@ -247,6 +258,27 @@ public class WTreeMaintenance extends TreeMaintenance implements IFormController
action_treeAddAll(); action_treeAddAll();
else if (e.getTarget() == bAdd) else if (e.getTarget() == bAdd)
{ {
add();
}
else if (e.getTarget() == bDelete)
{
remove();
}
else if (e.getTarget() == bDeleteAll)
action_treeDeleteAll();
else if (e.getTarget() == centerList)
onListSelection(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(); SimpleListModel model = (SimpleListModel) centerList.getModel();
int i = centerList.getSelectedIndex(); int i = centerList.getSelectedIndex();
if (i >= 0) { if (i >= 0) {
@ -254,23 +286,17 @@ public class WTreeMaintenance extends TreeMaintenance implements IFormController
} }
} }
else if (e.getTarget() == bDelete) void remove() {
{
if (cbAllNodes.isChecked())
return;
SimpleListModel model = (SimpleListModel) centerList.getModel(); SimpleListModel model = (SimpleListModel) centerList.getModel();
int i = centerList.getSelectedIndex(); int i = centerList.getSelectedIndex();
if (i >= 0) { if (i >= 0) {
action_treeDelete((ListItem)model.getElementAt(i)); action_treeDelete((ListItem)model.getElementAt(i));
} }
} }
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() == searchBox.getButton() || e.getTarget() == searchBox.getTextbox())
searchElement();
} // actionPerformed
private void searchElement() { private void searchElement() {
String filter = searchBox.getText() == null ? "" : searchBox.getText(); String filter = searchBox.getText() == null ? "" : searchBox.getText();
@ -420,10 +446,11 @@ public class WTreeMaintenance extends TreeMaintenance implements IFormController
stn = new DefaultTreeNode<Object>(new MTreeNode(item.id, 0, item.name, item.description, 0, item.isSummary, stn = new DefaultTreeNode<Object>(new MTreeNode(item.id, 0, item.name, item.description, 0, item.isSummary,
item.imageIndicator, false, null), new ArrayList<TreeNode<Object>>()); item.imageIndicator, false, null), new ArrayList<TreeNode<Object>>());
model.addNode(stn); model.addNode(stn);
}
// May cause Error if in tree // May cause Error if in tree
addNode(item); addNode(item);
} }
}
} // action_treeAdd } // action_treeAdd
/** /**