1

How to create dynamic context popup menu?

asked 2007-11-18 08:44:46 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4629538

By: flyisland

Hi all,

I want to show up different context menu items based on the selected item of a tree component, how to do that?

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2007-11-20 05:31:06 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4633032

By: flyisland

thank you oberinspector, it works now

link publish delete flag offensive edit

answered 2007-11-19 15:00:21 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4631240

By: oberinspector

ConcurrentModificationException comes when you modify the list of children direkt...
means: you iterate over the list of children and start to remove the children (listelements), but removeChild() also modifies the list or set you use to iterate.
That causes the error. You first have to make a copy of the List and use the copy to iterate and remove... i often use a conversion routine to array or to other iteratable type to get a copy.

Good Luck!

link publish delete flag offensive edit

answered 2007-11-19 11:59:20 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4630955

By: flyisland

I tried to 1)remove all children of the context menu; 2)create appropriate child menu item of the context menu; but got "ConcurrentModificationException".

After checked the dev-guide, I found "OpenEvent" is just a "notification", that means the context menu has already popuped before I received the "OpenEvent".
I guess that why I got the "ConcurrentModificationException"

link publish delete flag offensive edit

answered 2007-11-19 07:32:46 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4630613

By: oberinspector

propably you can translate my code to zul... you have to write an onOpen eventhandler for the menupopup in zscript like my one:

<menupopup id="myContextMenu" onOpen="onOpen();" ...
...
<zscript>
...
public void onOpen(OpenEvent event){
if(event.getReference() != null)
init((EntityIF)event.getReference().getAttribute("ENTITY"));
}

The init() has to remove existing children and has to create the context menu on demand...
And in the list box you have to provide the attribute items "ForEach" Listitem and set the context menu.
...
<listitem context="myContextMenu" ...
...

link publish delete flag offensive edit

answered 2007-11-19 02:57:50 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4630395

By: flyisland

Hi oberinspector, thanks for the reply.

But I do not what to do that by using java.

It'll be better if menuitem had a "disable" attribute and ZK would re-render the menuitems based on it's attribute items each time when the context menu is opened.

link publish delete flag offensive edit

answered 2007-11-18 11:50:01 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4629652

By: oberinspector

I have done this with java. A window with one instance of my EntityContextMenu and a listbox inside. init() creates the listbox dynamically and each listitem gets InstanceListContextMenu as context and the entity which is represented by the listitem as attribute:

public class InstanceList extends Window implements ApplicationIF{
String typeName = "";
Criteria criteria;
Listbox listbox;


public InstanceList(String typeName) {
super();
this.typeName = typeName;
this.setWidth("100%");

EntityContextMenu ecm = new EntityContextMenu();
ecm.setId("InstanceListContextMenu");
this.appendChild(ecm);

init(null);
}
...
private void createListcells(List <EntityIF> resultList){
for (EntityIF entity : resultList) {
Listitem item = new Listitem();
item.setContext("InstanceListContextMenu");
item.setAttribute("ENTITY", entity); ...

Here is the code of my dynamic EntityContextMenu menupopup class. The init function is called from the onOpen event:

...
public class EntityContextMenu extends Menupopup{
EntityIF _entity;
LabelFactory lf = new LabelFactory(this.getClass());


public EntityContextMenu() {
super();
}
public EntityContextMenu(EntityIF entity) {
super();
init(entity);
}


public void init(EntityIF entity){

HibUtil.currentSession().update(entity);

this._entity = entity;

this.getChildren().clear();

byte access = LoginManager.evaluateAccess(_entity);

if((_entity instanceof EbtEntityType) && AF.testFlagsOR(access, (byte)( AF.USE
| AF.ADM))){
Menuitem newInstanceMenuItem = new Menuitem(lf.label("New Instance"));
newInstanceMenuItem.setTooltiptext(lf.tooltiptext("New Instance"));
newInstanceMenuItem.setImage(StaticRessources.HOME + "/icon/16x16/actions/New.png");
newInstanceMenuItem.addForward("onClick", this, "onNew");
this.appendChild(newInstanceMenuItem);
}

if((_entity instanceof EbtEntityType)){
Menuitem instanceListMenuitem = new Menuitem(lf.label("Instance List"));
instanceListMenuitem.setTooltiptext(lf.tooltiptext("Instance List"));
instanceListMenuitem.setImage(StaticRessources.HOME + "/icon/16x16/actions/List.png");
instanceListMenuitem.addForward("onClick", this, "onList");
this.appendChild(instanceListMenuitem);
this.appendChild(new Menuseparator());
this.appendChild(new Menuseparator());
}


if(AF.testFlagsOR(access, (byte)(AF.PRV | AF.RD | AF.WR | AF.ADM))){
Menuitem previewMenuItem = new Menuitem(lf.label("Preview"));
previewMenuItem.setTooltiptext(lf.tooltiptext("Preview"));
previewMenuItem.setImage(StaticRessources.HOME + "/icon/16x16/actions/Preview.png");
previewMenuItem.addForward("onClick", this, "onPreview");
this.appendChild(previewMenuItem);
}

if(AF.testFlagsOR(access, (byte)(AF.RD | AF.WR | AF.ADM))){
Menuitem viewMenuItem = new Menuitem(lf.label("View"));
viewMenuItem.setTooltiptext(lf.tooltiptext("View"));
viewMenuItem.setImage(StaticRessources.HOME
+ "/icon/16x16/actions/View.png");
viewMenuItem.addForward("onClick", this, "onView");
this.appendChild(viewMenuItem);
}

if(AF.testFlagsOR(access, (byte)( AF.WR | AF.ADM))){
Menuitem editMenuItem = new Menuitem(lf.label("Edit"));
editMenuItem.setTooltiptext(lf.tooltiptext("Edit"));
editMenuItem.setImage(StaticRessources.HOME
+ "/icon/16x16/actions/Edit.png");
editMenuItem.addForward("onClick", this, "onEdit");
this.appendChild(editMenuItem);
}

if(AF.testFlagsOR(access, (byte)( AF.USE | AF.ADM))){
this.appendChild(new Menuseparator());
Menuitem copyMenuItem = new Menuitem(lf.label("Copy"));
copyMenuItem.setTooltiptext(lf.tooltiptext("Copy"));
copyMenuItem.setImage(StaticRessources.HOME
+ "/icon/16x16/actions/Copy.png");
copyMenuItem.addForward("onClick", this, "onCopy");

Menuitem xCopyMenuItem = new Menuitem(lf.label("XCopy"));
xCopyMenuItem.setTooltiptext(lf.tooltiptext("XCopy"));
xCopyMenuItem.setImage(StaticRessources.HOME
+ "/icon/16x16/actions/XCopy.png");
xCopyMenuItem.addForward("onClick", this, "onXCopy");

this.appendChild(copyMenuItem);
this.appendChild(xCopyMenuItem);
}

if(AF.testFlagsOR(access, (byte)( AF.DEL | AF.ADM))){
this.appendChild(new Menuseparator());
Menuitem deleteMenuItem = new Menuitem(lf.label("Delete"));
deleteMenuItem.setTooltiptext(lf.tooltiptext("Delete"));
deleteMenuItem.setImage(StaticRessources.HOME + "/icon/16x16/actions/Delete.png");
deleteMenuItem.addForward("onClick", this, "onDelete");
this.appendChild(deleteMenuItem);
}

}

public void onOpen(OpenEvent event){
if(event.getReference() != null)
init((EntityIF)event.getReference().getAttribute("ENTITY"));
}

public void onList(){
((ApplicationContainerIF)this.getDesktop().getAttribute("APPLICATION_CONTAINER
"))
.addSelectAreaApp(new InstanceList(((EbtEntityType)_entity).getName()));
}

public void onNew(){
try {
EntityIF newEntity = ((EbtEntityType)_entity).newInstance();

((ApplicationContainerIF)this.getDesktop().getAttribute("APPLICATION_CONTAINE
R"))
.addContentAreaApp(new EntityExplorer(newEntity));

} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void onEdit(){
((ApplicationContainerIF)this.getDesktop().getAttribute("APPLICATION_CONTAINER
"))
.addContentAreaApp(new EntityExplorer(_entity));
}

public void onCopy(){
ClipBoardManager.setClipBoard(_entity);
}

public void onXCopy(){
ClipBoardManager.addToXClipboard(_entity);
}

}

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2007-11-18 08:44:46 +0800

Seen: 1,430 times

Last updated: Nov 20 '07

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More