IDEMPIERE-1657: common show window with mask
cover below case + refactor * 1. show a dialog => show mask * 2. process a event * 2.1. show other dialog => show mask * 2.1. hidden dialog in step 1 => hidden mask * 3. result dialog show without mask
This commit is contained in:
parent
72ae1269d1
commit
220d14a3d1
|
@ -20,17 +20,35 @@ import org.zkoss.zk.ui.Component;
|
|||
/**
|
||||
* interface for any component want support show other window over it with a
|
||||
* mask. object manage component as AbstractUIPart also implement this interface
|
||||
* consider below case.
|
||||
* 1. show a dialog => show mask
|
||||
* 2. process a event
|
||||
* 2.1. show other dialog => show mask
|
||||
* 2.1. hidden dialog in step 1 => hidden mask
|
||||
* 3. result dialog show without mask
|
||||
* to void this case process as below
|
||||
* in {@link #showMask()} set a flag to request scope by call: {@link Component#setAttribute(String, Object, int)}
|
||||
* key is {@link #READY_SHOW_MASK_FLAG} value is Integer(1) and scope is {@link Component#REQUEST_SCOPE}
|
||||
* in {@link #hideMask()} check flag before hidden mask. when has flag, don't hidden mask
|
||||
*
|
||||
* component want support show mask can implement this interface or use support class {@link ShowMaskWrapper} as composite object
|
||||
*/
|
||||
public interface ISupportMask {
|
||||
public static String READY_SHOW_MASK_FLAG = "ISupportMask_READY_SHOW_MASK_FLAG";
|
||||
/**
|
||||
* show mask over this component
|
||||
* when override, remember call {@link Component#setAttribute(String, Object, int)} with
|
||||
* key is {@link #READY_SHOW_MASK_FLAG} value is Integer(1) and scope is {@link Component#REQUEST_SCOPE}
|
||||
* by call {@link LayoutUtils#setFlagShowMask(Component)}
|
||||
*/
|
||||
public void showMask();
|
||||
|
||||
/**
|
||||
* Hide mask. at code call showMask will hand reference to this object. and
|
||||
* call this function in handle close event of window
|
||||
* when override, remember check exists of key {@link #READY_SHOW_MASK_FLAG} at scope {@link Component#REQUEST_SCOPE} in attribute
|
||||
* by call {@link LayoutUtils#hasFlagShowMask(Component)}
|
||||
* if exists flag, don't hidden mask
|
||||
*/
|
||||
public void hideMask();
|
||||
|
||||
|
@ -46,4 +64,4 @@ public interface ISupportMask {
|
|||
* @return
|
||||
*/
|
||||
public Component getMaskComponent();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) 2015 iDempiere *
|
||||
* Product: iDempiere ERP & CRM Smart Business Solution *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*****************************************************************************/
|
||||
|
||||
package org.adempiere.webui;
|
||||
|
||||
import org.adempiere.webui.component.Mask;
|
||||
import org.adempiere.webui.part.UIPart;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
|
||||
/**
|
||||
* Helper class for any component want implement {@link ISupportMask}
|
||||
* Just make a instance of this class and let it do everything
|
||||
* @author hieplq
|
||||
*
|
||||
*/
|
||||
public class ShowMaskWrapper implements ISupportMask {
|
||||
|
||||
/**
|
||||
* component will implement ISupportMask;
|
||||
*/
|
||||
private Component comp;
|
||||
|
||||
/**
|
||||
* cache {@link Mask} Object
|
||||
*/
|
||||
private Mask maskObj;
|
||||
|
||||
/**
|
||||
* comp is component want implement this interface
|
||||
* @param comp
|
||||
*/
|
||||
public ShowMaskWrapper (Component comp){
|
||||
this.comp = comp;
|
||||
}
|
||||
|
||||
/**
|
||||
* this mask will show over component from {@link UIPart#getComponent()}
|
||||
* @param uiPart
|
||||
*/
|
||||
public ShowMaskWrapper (UIPart uiPart){
|
||||
this.comp = uiPart.getComponent();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void showMask() {
|
||||
maskObj = getMaskObj ();
|
||||
if (maskObj.getParent() == null){
|
||||
comp.appendChild(maskObj);
|
||||
}
|
||||
ShowMaskWrapper.setFlagShowMask(comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void hideMask() {
|
||||
if (maskObj != null || maskObj.getParent() != null){
|
||||
// in same request, not yet call to show mask
|
||||
if (!ShowMaskWrapper.hasFlagShowMask(comp)){
|
||||
maskObj.detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* return new {@link Mask} when mask is not yet create
|
||||
*/
|
||||
@Override
|
||||
public Mask getMaskObj() {
|
||||
if (maskObj == null)
|
||||
maskObj = new Mask();
|
||||
|
||||
return maskObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Component getMaskComponent() {
|
||||
return comp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flag {@link ISupportMask#READY_SHOW_MASK_FLAG} to Component.REQUEST_SCOPE
|
||||
* @param comp
|
||||
*/
|
||||
public static void setFlagShowMask (Component comp){
|
||||
comp.setAttribute(ISupportMask.READY_SHOW_MASK_FLAG, new Integer(1), Component.REQUEST_SCOPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* check flag {@link ISupportMask#READY_SHOW_MASK_FLAG} ready in scope Component.REQUEST_SCOPE
|
||||
* @param comp
|
||||
* @return
|
||||
*/
|
||||
public static boolean hasFlagShowMask (Component comp){
|
||||
return (comp.getAttribute(ISupportMask.READY_SHOW_MASK_FLAG, Component.REQUEST_SCOPE) != null);
|
||||
}
|
||||
}
|
|
@ -17,7 +17,8 @@
|
|||
|
||||
package org.adempiere.webui.component;
|
||||
|
||||
import org.adempiere.webui.ISupportMask;
|
||||
import org.adempiere.webui.ISupportMask;
|
||||
import org.adempiere.webui.ShowMaskWrapper;
|
||||
import org.adempiere.webui.panel.ITabOnCloseHandler;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.IdSpace;
|
||||
|
@ -42,6 +43,8 @@ public class Tabpanel extends org.zkoss.zul.Tabpanel implements IdSpace, ISuppor
|
|||
|
||||
private int tabLevel;
|
||||
|
||||
protected ShowMaskWrapper showMaskWrapper = new ShowMaskWrapper(this);
|
||||
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return enabled;
|
||||
|
@ -88,21 +91,12 @@ public class Tabpanel extends org.zkoss.zul.Tabpanel implements IdSpace, ISuppor
|
|||
this.onCloseHandler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* cache {@link Mask} Object
|
||||
*/
|
||||
private Mask maskObj;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void showMask() {
|
||||
maskObj = getMaskObj ();
|
||||
if (maskObj.getParent() == null){
|
||||
this.appendChild(maskObj);
|
||||
}
|
||||
|
||||
showMaskWrapper.showMask();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,10 +104,7 @@ public class Tabpanel extends org.zkoss.zul.Tabpanel implements IdSpace, ISuppor
|
|||
*/
|
||||
@Override
|
||||
public void hideMask() {
|
||||
if (maskObj != null || maskObj.getParent() != null){
|
||||
maskObj.detach();
|
||||
}
|
||||
|
||||
showMaskWrapper.hideMask();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,10 +112,7 @@ public class Tabpanel extends org.zkoss.zul.Tabpanel implements IdSpace, ISuppor
|
|||
*/
|
||||
@Override
|
||||
public Mask getMaskObj() {
|
||||
if (maskObj == null)
|
||||
maskObj = new Mask();
|
||||
|
||||
return maskObj;
|
||||
return showMaskWrapper.getMaskObj();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,6 +120,6 @@ public class Tabpanel extends org.zkoss.zul.Tabpanel implements IdSpace, ISuppor
|
|||
*/
|
||||
@Override
|
||||
public Component getMaskComponent() {
|
||||
return this;
|
||||
return showMaskWrapper.getMaskComponent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package org.adempiere.webui.component;
|
||||
|
||||
import org.adempiere.webui.ISupportMask;
|
||||
import org.adempiere.webui.ShowMaskWrapper;
|
||||
import org.adempiere.webui.event.DialogEvents;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
|
@ -38,6 +39,7 @@ public class Window extends org.zkoss.zul.Window implements ISupportMask
|
|||
*/
|
||||
private static final long serialVersionUID = -8249071775776387012L;
|
||||
|
||||
protected ShowMaskWrapper showMaskWrapper = new ShowMaskWrapper(this);
|
||||
/*** Show as modal window ***/
|
||||
public static final String MODE_MODAL = "modal";
|
||||
/*** Show as popup window ***/
|
||||
|
@ -109,21 +111,13 @@ public class Window extends org.zkoss.zul.Window implements ISupportMask
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cache {@link Mask} Object
|
||||
*/
|
||||
private Mask maskObj;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void showMask() {
|
||||
maskObj = getMaskObj ();
|
||||
if (maskObj.getParent() == null){
|
||||
this.appendChild(maskObj);
|
||||
}
|
||||
|
||||
showMaskWrapper.showMask();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,9 +125,7 @@ public class Window extends org.zkoss.zul.Window implements ISupportMask
|
|||
*/
|
||||
@Override
|
||||
public void hideMask() {
|
||||
if (maskObj != null || maskObj.getParent() != null){
|
||||
maskObj.detach();
|
||||
}
|
||||
showMaskWrapper.hideMask();
|
||||
|
||||
}
|
||||
|
||||
|
@ -142,10 +134,7 @@ public class Window extends org.zkoss.zul.Window implements ISupportMask
|
|||
*/
|
||||
@Override
|
||||
public Mask getMaskObj() {
|
||||
if (maskObj == null)
|
||||
maskObj = new Mask();
|
||||
|
||||
return maskObj;
|
||||
return showMaskWrapper.getMaskObj();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,6 +142,6 @@ public class Window extends org.zkoss.zul.Window implements ISupportMask
|
|||
*/
|
||||
@Override
|
||||
public Component getMaskComponent() {
|
||||
return this;
|
||||
return showMaskWrapper.getMaskComponent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.adempiere.webui.part;
|
|||
import java.awt.BorderLayout;
|
||||
|
||||
import org.adempiere.webui.ISupportMask;
|
||||
import org.adempiere.webui.ShowMaskWrapper;
|
||||
import org.adempiere.webui.component.Mask;
|
||||
import org.adempiere.webui.desktop.IDesktop;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
|
@ -30,6 +31,8 @@ public abstract class AbstractUIPart implements UIPart, ISupportMask {
|
|||
|
||||
protected Page page = null;
|
||||
|
||||
protected ShowMaskWrapper showMaskWrapper = new ShowMaskWrapper(this);
|
||||
|
||||
public Component createPart(Object parent) {
|
||||
if (parent == null)
|
||||
throw new IllegalArgumentException("Null parent.");
|
||||
|
@ -49,19 +52,11 @@ public abstract class AbstractUIPart implements UIPart, ISupportMask {
|
|||
|
||||
protected abstract Component doCreatePart(Component parent);
|
||||
|
||||
/**
|
||||
* cache {@link Mask} Object
|
||||
*/
|
||||
private Mask maskObj;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override public void showMask() {
|
||||
maskObj = getMaskObj ();
|
||||
if (maskObj.getParent() == null){
|
||||
this.getMaskComponent().appendChild(maskObj);
|
||||
}
|
||||
showMaskWrapper.showMask();
|
||||
|
||||
}
|
||||
|
||||
|
@ -70,9 +65,7 @@ public abstract class AbstractUIPart implements UIPart, ISupportMask {
|
|||
*/
|
||||
@Override
|
||||
public void hideMask() {
|
||||
if (maskObj != null || maskObj.getParent() != null){
|
||||
maskObj.detach();
|
||||
}
|
||||
showMaskWrapper.hideMask();
|
||||
|
||||
}
|
||||
|
||||
|
@ -81,10 +74,7 @@ public abstract class AbstractUIPart implements UIPart, ISupportMask {
|
|||
*/
|
||||
@Override
|
||||
public Mask getMaskObj() {
|
||||
if (maskObj == null)
|
||||
maskObj = new Mask();
|
||||
|
||||
return maskObj;
|
||||
return showMaskWrapper.getMaskObj();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue