IDEMPIERE-144 Performance: Reduce use of modal dialog
This commit is contained in:
parent
336fd52791
commit
44fecb0ca9
|
@ -58,8 +58,16 @@ import org.zkoss.zul.Html;
|
||||||
* @author arboleda - globalqss
|
* @author arboleda - globalqss
|
||||||
* - Implement ShowHelp option on processes and reports
|
* - Implement ShowHelp option on processes and reports
|
||||||
*/
|
*/
|
||||||
public class ProcessModalDialog extends Window implements EventListener, IProcessMonitor
|
public class ProcessModalDialog extends Window implements EventListener<Event>, IProcessMonitor
|
||||||
{
|
{
|
||||||
|
private static final String ON_STATUS_UPDATE = "onStatusUpdate";
|
||||||
|
private static final String ON_COMPLETE = "onComplete";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* on modal close event, use this for highlight mode modal dialog to perform action after the modal dialog closed.
|
||||||
|
*/
|
||||||
|
public final static String ON_MODAL_CLOSE = "onModalClose";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generated serial version ID
|
* generated serial version ID
|
||||||
*/
|
*/
|
||||||
|
@ -140,7 +148,7 @@ public class ProcessModalDialog extends Window implements EventListener, IProces
|
||||||
centerPanel = new Panel();
|
centerPanel = new Panel();
|
||||||
dialogBody.appendChild(centerPanel);
|
dialogBody.appendChild(centerPanel);
|
||||||
div = new Div();
|
div = new Div();
|
||||||
div.setAlign("right");
|
div.setStyle("text-align: right");
|
||||||
Hbox hbox = new Hbox();
|
Hbox hbox = new Hbox();
|
||||||
Button btn = new Button("Ok");
|
Button btn = new Button("Ok");
|
||||||
LayoutUtils.addSclass("action-text-button", btn);
|
LayoutUtils.addSclass("action-text-button", btn);
|
||||||
|
@ -167,6 +175,7 @@ public class ProcessModalDialog extends Window implements EventListener, IProces
|
||||||
private StringBuffer m_messageText = new StringBuffer();
|
private StringBuffer m_messageText = new StringBuffer();
|
||||||
private String m_ShowHelp = null; // Determine if a Help Process Window is shown
|
private String m_ShowHelp = null; // Determine if a Help Process Window is shown
|
||||||
private boolean m_valid = true;
|
private boolean m_valid = true;
|
||||||
|
private boolean m_cancel = false;
|
||||||
|
|
||||||
private Panel centerPanel = null;
|
private Panel centerPanel = null;
|
||||||
private Html message = null;
|
private Html message = null;
|
||||||
|
@ -181,7 +190,6 @@ public class ProcessModalDialog extends Window implements EventListener, IProces
|
||||||
private boolean isLocked = false;
|
private boolean isLocked = false;
|
||||||
private org.adempiere.webui.apps.ProcessModalDialog.ProcessDialogRunnable processDialogRunnable;
|
private org.adempiere.webui.apps.ProcessModalDialog.ProcessDialogRunnable processDialogRunnable;
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
private String statusUpdate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Visible
|
* Set Visible
|
||||||
|
@ -212,6 +220,14 @@ public class ProcessModalDialog extends Window implements EventListener, IProces
|
||||||
return m_valid;
|
return m_valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if user have press the cancel button to close the dialog
|
||||||
|
*/
|
||||||
|
public boolean isCancel()
|
||||||
|
{
|
||||||
|
return m_cancel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dynamic Init
|
* Dynamic Init
|
||||||
* @return true, if there is something to process (start from menu)
|
* @return true, if there is something to process (start from menu)
|
||||||
|
@ -351,37 +367,8 @@ public class ProcessModalDialog extends Window implements EventListener, IProces
|
||||||
processDialogRunnable = new ProcessDialogRunnable(p);
|
processDialogRunnable = new ProcessDialogRunnable(p);
|
||||||
thread = new Thread(processDialogRunnable);
|
thread = new Thread(processDialogRunnable);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
||||||
Clients.response(new AuEcho(this, "checkProgress", null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkProgress() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(500);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Thread.interrupted();
|
|
||||||
}
|
|
||||||
if (thread.isAlive()) {
|
|
||||||
synchronized(this) {
|
|
||||||
if (statusUpdate != null) {
|
|
||||||
if (progressWindow != null)
|
|
||||||
progressWindow.statusUpdate(statusUpdate);
|
|
||||||
statusUpdate = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Clients.response(new AuEcho(this, "checkProgress", null));
|
|
||||||
} else {
|
|
||||||
Env.getCtx().putAll(processDialogRunnable.getProperties());
|
|
||||||
thread = null;
|
|
||||||
processDialogRunnable = null;
|
|
||||||
dispose();
|
|
||||||
if (m_processMonitor != null) {
|
|
||||||
m_processMonitor.unlockUI(m_pi);
|
|
||||||
}
|
|
||||||
unlockUI(m_pi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void hideBusyDialog() {
|
private void hideBusyDialog() {
|
||||||
if (progressWindow != null) {
|
if (progressWindow != null) {
|
||||||
progressWindow.dispose();
|
progressWindow.dispose();
|
||||||
|
@ -392,18 +379,50 @@ public class ProcessModalDialog extends Window implements EventListener, IProces
|
||||||
/**
|
/**
|
||||||
* handle events
|
* handle events
|
||||||
*/
|
*/
|
||||||
public void onEvent(Event event) {
|
public void onEvent(Event event) {
|
||||||
Component component = event.getTarget();
|
Component component = event.getTarget();
|
||||||
if (component instanceof Button) {
|
if (component instanceof Button) {
|
||||||
Button element = (Button)component;
|
Button element = (Button)component;
|
||||||
if ("Ok".equalsIgnoreCase(element.getId())) {
|
if ("Ok".equalsIgnoreCase(element.getId())) {
|
||||||
this.startProcess();
|
onOK();
|
||||||
} else if ("Cancel".equalsIgnoreCase(element.getId())) {
|
} else if ("Cancel".equalsIgnoreCase(element.getId())) {
|
||||||
this.dispose();
|
onCancel();
|
||||||
}
|
}
|
||||||
|
} else if (event.getName().equals(ON_STATUS_UPDATE)) {
|
||||||
|
onStatusUpdate(event);
|
||||||
|
} else if (event.getName().equals(ON_COMPLETE)) {
|
||||||
|
onComplete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onOK() {
|
||||||
|
this.startProcess();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onCancel() {
|
||||||
|
m_cancel = true;
|
||||||
|
this.dispose();
|
||||||
|
Events.sendEvent(this, new Event(ON_MODAL_CLOSE, this, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onStatusUpdate(Event event) {
|
||||||
|
String message = (String) event.getData();
|
||||||
|
if (progressWindow != null)
|
||||||
|
progressWindow.statusUpdate(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onComplete() {
|
||||||
|
Env.getCtx().putAll(processDialogRunnable.getProperties());
|
||||||
|
thread = null;
|
||||||
|
processDialogRunnable = null;
|
||||||
|
dispose();
|
||||||
|
if (m_processMonitor != null) {
|
||||||
|
m_processMonitor.unlockUI(m_pi);
|
||||||
|
}
|
||||||
|
unlockUI(m_pi);
|
||||||
|
Events.sendEvent(this, new Event(ON_MODAL_CLOSE, this, null));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void lockUI(ProcessInfo pi) {
|
public void lockUI(ProcessInfo pi) {
|
||||||
if (isLocked || Executions.getCurrent() == null)
|
if (isLocked || Executions.getCurrent() == null)
|
||||||
|
@ -429,10 +448,18 @@ public class ProcessModalDialog extends Window implements EventListener, IProces
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void statusUpdate(String message) {
|
public void statusUpdate(String message) {
|
||||||
statusUpdate = message;
|
Executions.schedule(getDesktop(), this, new Event(ON_STATUS_UPDATE, this, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProcessDialogRunnable implements Runnable {
|
/**
|
||||||
|
*
|
||||||
|
* @return ProcessInfo
|
||||||
|
*/
|
||||||
|
public ProcessInfo getProcessInfo() {
|
||||||
|
return m_pi;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProcessDialogRunnable implements Runnable {
|
||||||
private Properties properties;
|
private Properties properties;
|
||||||
|
|
||||||
ProcessDialogRunnable(Properties properties) {
|
ProcessDialogRunnable(Properties properties) {
|
||||||
|
@ -446,6 +473,7 @@ public class ProcessModalDialog extends Window implements EventListener, IProces
|
||||||
WProcessCtl.process(ProcessModalDialog.this, m_WindowNo, parameterPanel, m_pi, null);
|
WProcessCtl.process(ProcessModalDialog.this, m_WindowNo, parameterPanel, m_pi, null);
|
||||||
} finally {
|
} finally {
|
||||||
ServerContext.dispose();
|
ServerContext.dispose();
|
||||||
|
Executions.schedule(getDesktop(), ProcessModalDialog.this, new Event(ON_COMPLETE, ProcessModalDialog.this, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ import org.zkoss.zul.Menupopup;
|
||||||
* https://sourceforge.net/tracker/?func=detail&aid=2985892&group_id=176962&atid=955896
|
* https://sourceforge.net/tracker/?func=detail&aid=2985892&group_id=176962&atid=955896
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractADWindowPanel extends AbstractUIPart implements ToolbarListener,
|
public abstract class AbstractADWindowPanel extends AbstractUIPart implements ToolbarListener,
|
||||||
EventListener, DataStatusListener, ActionListener, IProcessMonitor
|
EventListener<Event>, DataStatusListener, ActionListener, IProcessMonitor
|
||||||
{
|
{
|
||||||
private static final CLogger logger;
|
private static final CLogger logger;
|
||||||
|
|
||||||
|
@ -777,7 +777,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
||||||
|
|
||||||
m_lock = new Menuitem(Msg.translate(Env.getCtx(), "Lock"));
|
m_lock = new Menuitem(Msg.translate(Env.getCtx(), "Lock"));
|
||||||
m_popup.appendChild(m_lock);
|
m_popup.appendChild(m_lock);
|
||||||
m_lock.addEventListener(Events.ON_CLICK, new EventListener()
|
m_lock.addEventListener(Events.ON_CLICK, new EventListener<Event>()
|
||||||
{
|
{
|
||||||
public void onEvent(Event event) throws Exception
|
public void onEvent(Event event) throws Exception
|
||||||
{
|
{
|
||||||
|
@ -790,7 +790,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
||||||
|
|
||||||
m_access = new Menuitem(Msg.translate(Env.getCtx(), "RecordAccessDialog"));
|
m_access = new Menuitem(Msg.translate(Env.getCtx(), "RecordAccessDialog"));
|
||||||
m_popup.appendChild(m_access);
|
m_popup.appendChild(m_access);
|
||||||
m_access.addEventListener(Events.ON_CLICK, new EventListener()
|
m_access.addEventListener(Events.ON_CLICK, new EventListener<Event>()
|
||||||
{
|
{
|
||||||
public void onEvent(Event event) throws Exception
|
public void onEvent(Event event) throws Exception
|
||||||
{
|
{
|
||||||
|
@ -1760,7 +1760,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
||||||
messagePanel.appendChild(listbox);
|
messagePanel.appendChild(listbox);
|
||||||
|
|
||||||
Div div = new Div();
|
Div div = new Div();
|
||||||
div.setAlign("center");
|
div.setStyle("text-align: center");
|
||||||
messagePanel.appendChild(div);
|
messagePanel.appendChild(div);
|
||||||
|
|
||||||
Hbox hbox = new Hbox();
|
Hbox hbox = new Hbox();
|
||||||
|
@ -1769,9 +1769,8 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
||||||
Button btnOk = new Button();
|
Button btnOk = new Button();
|
||||||
btnOk.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "OK")));
|
btnOk.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "OK")));
|
||||||
btnOk.setImage("/images/Ok16.png");
|
btnOk.setImage("/images/Ok16.png");
|
||||||
btnOk.addEventListener(Events.ON_CLICK, new EventListener()
|
btnOk.addEventListener(Events.ON_CLICK, new EventListener<Event>()
|
||||||
{
|
{
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void onEvent(Event event) throws Exception
|
public void onEvent(Event event) throws Exception
|
||||||
{
|
{
|
||||||
if (FDialog.ask(curWindowNo, messagePanel, "DeleteSelection"))
|
if (FDialog.ask(curWindowNo, messagePanel, "DeleteSelection"))
|
||||||
|
@ -1812,7 +1811,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
||||||
Button btnCancel = new Button();
|
Button btnCancel = new Button();
|
||||||
btnCancel.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Cancel")));
|
btnCancel.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Cancel")));
|
||||||
btnCancel.setImage("/images/Cancel16.png");
|
btnCancel.setImage("/images/Cancel16.png");
|
||||||
btnCancel.addEventListener(Events.ON_CLICK, new EventListener()
|
btnCancel.addEventListener(Events.ON_CLICK, new EventListener<Event>()
|
||||||
{
|
{
|
||||||
public void onEvent(Event event) throws Exception
|
public void onEvent(Event event) throws Exception
|
||||||
{
|
{
|
||||||
|
@ -2247,9 +2246,19 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
||||||
dialog.setWidth("500px");
|
dialog.setWidth("500px");
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
dialog.setPosition("center");
|
dialog.setPosition("center");
|
||||||
|
dialog.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED);
|
||||||
|
dialog.addEventListener(ProcessModalDialog.ON_MODAL_CLOSE, new EventListener<Event>() {
|
||||||
|
@Override
|
||||||
|
public void onEvent(Event event) throws Exception {
|
||||||
|
onRefresh(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
AEnv.showWindow(dialog);
|
AEnv.showWindow(dialog);
|
||||||
}
|
}
|
||||||
onRefresh(false);
|
else
|
||||||
|
{
|
||||||
|
onRefresh(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // actionButton
|
} // actionButton
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue