IDEMPIERE-185 Zk6: Context menu not working after migration to Zk6

This commit is contained in:
Heng Sin Low 2012-03-07 15:44:07 +08:00
parent 2148f8bf55
commit 2e6f20aabd
19 changed files with 90 additions and 1247 deletions

View File

@ -54,6 +54,7 @@ import org.zkoss.zul.RendererCtrl;
import org.zkoss.zul.Row;
import org.zkoss.zul.RowRenderer;
import org.zkoss.zul.RowRendererExt;
import org.zkoss.zul.impl.XulElement;
import org.zkoss.zhtml.Label;
import org.zkoss.zhtml.Text;
@ -481,7 +482,7 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
org.zkoss.zul.Column column = (org.zkoss.zul.Column) columns.getChildren().get(colIndex);
if (column.isVisible()) {
Div div = (Div) currentRow.getChildren().get(colIndex);
div.getFirstChild().detach();
div.getChildren().clear();
WEditor editor = getEditorCell(gridField[i]);
div.appendChild(editor.getComponent());
WEditorPopupMenu popupMenu = editor.getPopupMenu();
@ -491,6 +492,7 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
popupMenu.addMenuListener((ContextMenuListener)editor);
div.appendChild(popupMenu);
}
popupMenu.addContextElement((XulElement) editor.getComponent());
//check context
if (!gridField[i].isDisplayed(true))

View File

@ -0,0 +1,79 @@
/******************************************************************************
* Copyright (C) 2012 Low Heng Sin *
* Copyright (C) 2012 www.idempiere.org *
* 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.component;
import java.util.ArrayList;
import java.util.List;
import org.zkoss.zk.ui.Page;
import org.zkoss.zul.impl.XulElement;
/**
*
* @author hengsin
*
*/
public class Menupopup extends org.zkoss.zul.Menupopup {
/**
* generated serial version id
*/
private static final long serialVersionUID = -4929397362586559388L;
/**
* listo of xulelement that use this as the context menu
*/
private List<XulElement> elementList = new ArrayList<XulElement>();
/**
* add xul element that want to use this as the context menu
* @param element
*/
public void addContextElement(XulElement element) {
elementList.add(element);
if (this.getPage() != null) {
element.setContext(this);
}
}
/**
* stop the xul element from using this as the context menu
* @param element
* @return true if exists and remove from the added xul element list
*/
public boolean removeContextElement(XulElement element) {
if (elementList.remove(element)) {
element.setContext((String)null);
return true;
} else {
return false;
}
}
@Override
public void onPageAttached(Page newpage, Page oldpage) {
super.onPageAttached(newpage, oldpage);
for(XulElement e : elementList) {
e.setContext(this);
}
}
@Override
public void onPageDetached(Page page) {
super.onPageDetached(page);
for(XulElement e : elementList) {
e.setContext((String)null);
}
}
}

View File

@ -58,7 +58,6 @@ public class WAccountEditor extends WEditor implements ContextMenuListener
popupMenu = new WEditorPopupMenu(false, false, true);
popupMenu.addMenuListener(this);
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getUuid());
}
@Override

View File

@ -49,7 +49,6 @@ public class WAssignmentEditor extends WEditor implements ContextMenuListener {
popupMenu = new WEditorPopupMenu(true, false, false);
popupMenu.addMenuListener(this);
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getId());
}

View File

@ -106,7 +106,6 @@ public class WDateEditor extends WEditor implements ContextMenuListener
popupMenu = new WEditorPopupMenu(false, false, isShowPreference());
popupMenu.addMenuListener(this);
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getUuid());
}

View File

@ -100,7 +100,6 @@ public class WDatetimeEditor extends WEditor implements ContextMenuListener
popupMenu = new WEditorPopupMenu(false, false, isShowPreference());
popupMenu.addMenuListener(this);
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getUuid());
}
public void onEvent(Event event)

View File

@ -19,6 +19,7 @@ package org.adempiere.webui.editor;
import java.util.ArrayList;
import org.adempiere.webui.component.Menupopup;
import org.adempiere.webui.event.ContextMenuEvent;
import org.adempiere.webui.event.ContextMenuListener;
import org.compiere.util.Env;
@ -28,7 +29,6 @@ import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Menuitem;
import org.zkoss.zul.Menupopup;
/**
*
@ -36,7 +36,7 @@ import org.zkoss.zul.Menupopup;
* @date Mar 25, 2007
* @version $Revision: 0.10 $
*/
public class WEditorPopupMenu extends Menupopup implements EventListener
public class WEditorPopupMenu extends Menupopup implements EventListener<Event>
{
/**
*

View File

@ -87,7 +87,6 @@ public class WLocationEditor extends WEditor implements EventListener<Event>, Pr
popupMenu = new WEditorPopupMenu(false, false, isShowPreference());
popupMenu.addMenuListener(this);
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getUuid());
}
@Override

View File

@ -114,7 +114,6 @@ public class WLocatorEditor extends WEditor implements EventListener<Event>, Pro
{
popupMenu = new WEditorPopupMenu(true, true, isShowPreference());
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getUuid());
}
}

View File

@ -122,7 +122,6 @@ public class WNumberEditor extends WEditor implements ContextMenuListener
popupMenu = new WEditorPopupMenu(false, false, isShowPreference());
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getUuid());
}
/**

View File

@ -73,7 +73,6 @@ public class WPAttributeEditor extends WEditor implements ContextMenuListener
// Popup
popupMenu = new WEditorPopupMenu(true, false, false);
getComponent().getTextbox().setContext(popupMenu.getUuid());
addChangeLogMenu(popupMenu);
getComponent().getTextbox().setReadonly(true);

View File

@ -162,7 +162,6 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
getComponent().setButtonImage("/images/PickOpen10.png");
}
getComponent().getTextbox().setContext(popupMenu.getUuid());
addChangeLogMenu(popupMenu);
return;

View File

@ -137,8 +137,6 @@ public class WStringEditor extends WEditor implements ContextMenuListener
addTextEditorMenu(popupMenu);
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getUuid());
if (gridField.isAutocomplete()) {
Combobox combo = (Combobox)getComponent();
combo.setAutodrop(true);

View File

@ -144,7 +144,6 @@ ContextMenuListener, IZoomableEditor
{
popupMenu = new WEditorPopupMenu(zoom, true, isShowPreference());
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getUuid());
}
}

View File

@ -101,7 +101,6 @@ public class WTimeEditor extends WEditor implements ContextMenuListener
popupMenu = new WEditorPopupMenu(false, false, isShowPreference());
popupMenu.addMenuListener(this);
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getUuid());
}
public void onEvent(Event event)

View File

@ -42,7 +42,6 @@ public class WUrlEditor extends WEditor implements ContextMenuListener
popupMenu = new WEditorPopupMenu(false, false, isShowPreference());
popupMenu.addMenuListener(this);
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getUuid());
}

View File

@ -76,7 +76,6 @@ public class WYesNoEditor extends WEditor implements ContextMenuListener
popupMenu = new WEditorPopupMenu(false, false, isShowPreference());
popupMenu.addMenuListener(this);
addChangeLogMenu(popupMenu);
getComponent().setContext(popupMenu.getUuid());
}
public void onEvent(Event event)

View File

@ -79,6 +79,7 @@ import org.zkoss.zul.DefaultTreeNode;
import org.zkoss.zul.Space;
import org.zkoss.zul.Treeitem;
import org.zkoss.zul.impl.InputElement;
import org.zkoss.zul.impl.XulElement;
/**
*
@ -488,7 +489,11 @@ DataStatusListener, IADTabpanel, VetoableChangeListener
label.addEventListener(Events.ON_CLICK, new ZoomListener((IZoomableEditor) editor));
}
label.setContext(popupMenu.getUuid());
popupMenu.addContextElement(label);
if (editor.getComponent() instanceof XulElement)
{
popupMenu.addContextElement((XulElement) editor.getComponent());
}
}
}
}