IDEMPIERE-4937 Refreshing the GridTab after moving a node in the Tree (#860)

* IDEMPIERE-4937 Refreshing the GridTab after moving a node in the Tree

* IDEMPIERE-4937 Refreshing the GridTab after moving a node in the Tree

Use Trx object instead of context for event changes indicator.
This commit is contained in:
hengsin 2021-09-04 20:16:14 +08:00 committed by GitHub
parent 69794ff936
commit f1c663e100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 4 deletions

View File

@ -112,6 +112,8 @@ public class Trx
protected Exception trace; protected Exception trace;
private String m_displayName; private String m_displayName;
private boolean m_changesMadeByEventListener = false;
public static void startTrxMonitor() public static void startTrxMonitor()
{ {
@ -274,6 +276,7 @@ public class Trx
} }
m_active = true; m_active = true;
m_startTime = System.currentTimeMillis(); m_startTime = System.currentTimeMillis();
m_changesMadeByEventListener = false;
return true; return true;
} // startTrx } // startTrx
@ -362,6 +365,7 @@ public class Trx
{ {
m_connection.rollback(savepoint); m_connection.rollback(savepoint);
if (log.isLoggable(Level.INFO)) log.info ("**** " + m_trxName); if (log.isLoggable(Level.INFO)) log.info ("**** " + m_trxName);
m_changesMadeByEventListener = false;
return true; return true;
} }
} }
@ -730,6 +734,24 @@ public class Trx
m_displayName = displayName; m_displayName = displayName;
} }
/**
* Indicate additional db changes have been made by event listener
* @param changesMade
*/
public void setChangesMadeByEventListener(boolean changesMade)
{
m_changesMadeByEventListener = changesMade;
}
/**
*
* @return true if event listener(s) has flag that additional db changes have been made
*/
public boolean hasChangesMadeByEventListener()
{
return m_changesMadeByEventListener;
}
static class TrxMonitor implements Runnable static class TrxMonitor implements Runnable
{ {

View File

@ -1479,9 +1479,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
} }
else if (ON_DEFER_SET_SELECTED_NODE.equals(event.getName())) { else if (ON_DEFER_SET_SELECTED_NODE.equals(event.getName())) {
removeAttribute(ON_DEFER_SET_SELECTED_NODE_ATTR); removeAttribute(ON_DEFER_SET_SELECTED_NODE_ATTR);
if (gridTab.getRecord_ID() >= 0 && gridTab.isTreeTab() && treePanel != null) { setSelectedNode();
setSelectedNode(gridTab.getRecord_ID());
}
} }
else if (WPaymentEditor.ON_SAVE_PAYMENT.equals(event.getName())) { else if (WPaymentEditor.ON_SAVE_PAYMENT.equals(event.getName())) {
windowPanel.onSavePayment(); windowPanel.onSavePayment();
@ -1528,6 +1526,15 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
} }
} }
/**
* set selected tree node for current row (if there's tree)
*/
public void setSelectedNode() {
if (gridTab.getRecord_ID() >= 0 && gridTab.isTreeTab() && treePanel != null) {
setSelectedNode(gridTab.getRecord_ID());
}
}
private void onSouthEvent(SouthEvent event) { private void onSouthEvent(SouthEvent event) {
if (event == SouthEvent.OPEN || event == SouthEvent.CLOSE) { if (event == SouthEvent.OPEN || event == SouthEvent.CLOSE) {
boolean open = event == SouthEvent.OPEN ? true : false; boolean open = event == SouthEvent.OPEN ? true : false;

View File

@ -290,7 +290,10 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
protected abstract void switchEditStatus(boolean editStatus); protected abstract void switchEditStatus(boolean editStatus);
private void focusToActivePanel() { /**
* set focus to active panel
*/
public void focusToActivePanel() {
IADTabpanel adTabPanel = adTabbox.getSelectedTabpanel(); IADTabpanel adTabPanel = adTabbox.getSelectedTabpanel();
focusToTabpanel(adTabPanel); focusToTabpanel(adTabPanel);
} }

View File

@ -14,6 +14,11 @@ package org.adempiere.webui.component;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.webui.adwindow.ADTabpanel;
import org.adempiere.webui.adwindow.ADWindow;
import org.adempiere.webui.adwindow.ADWindowContent;
import org.adempiere.webui.adwindow.IADTabpanel;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.util.TreeUtils; import org.adempiere.webui.util.TreeUtils;
import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.FDialog;
import org.compiere.model.MTree; import org.compiere.model.MTree;
@ -24,10 +29,13 @@ import org.compiere.util.CLogger;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.compiere.util.Trx; import org.compiere.util.Trx;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.DropEvent; import org.zkoss.zk.ui.event.DropEvent;
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.zul.DefaultTreeNode; import org.zkoss.zul.DefaultTreeNode;
import org.zkoss.zul.Menuitem; import org.zkoss.zul.Menuitem;
import org.zkoss.zul.Menupopup; import org.zkoss.zul.Menupopup;
@ -183,6 +191,25 @@ public class ADTreeOnDropListener implements EventListener<Event> {
} }
// COMMIT ********************* // COMMIT *********************
trx.commit(true); trx.commit(true);
Component c = SessionManager.getAppDesktop().getActiveWindow();
ADWindow adwindow = ADWindow.findADWindow(c);
if (adwindow != null) {
ADWindowContent adwindowContent = adwindow.getADWindowContent();
if (trx.hasChangesMadeByEventListener()) {
Clients.showBusy(null);
Executions.schedule(c.getDesktop(), e -> {
adwindowContent.onRefresh();
Executions.schedule(c.getDesktop(), e1 -> Clients.clearBusy(), new Event("onEchangeIndicatorchoClearBusy"));
}, new Event("onPostTreeOnDrop"));
} else {
adwindowContent.focusToActivePanel();
IADTabpanel selected = adwindowContent.getADTab().getSelectedTabpanel();
if (selected instanceof ADTabpanel) {
((ADTabpanel)selected).setSelectedNode();
}
}
}
} }
catch (Exception e) catch (Exception e)
{ {