return link;
}
});
Menu menu1 = new Menu(new Model<String>("Pages"), itemsForMenu1);
/* End of menu 1 */
/* Menu 2 with some AJAX links for drag/drop and resize control */
final Menu menu2 = new Menu(new Model<String>("Ajax Control"));
// Enable/disable dragging
menu2.addMenuItem(new IMenuLink() {
private static final long serialVersionUID = 1L;
private boolean isEnabled = true;
private Model<String> labelModel = new Model<String>("disable drag");
@Override
public Component getDisplayComponent(String id) {
return new Label(id, labelModel);
}
@Override
public AbstractLink getLink(String id) {
return new AjaxFallbackLink<Void>(id) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
if (isEnabled) {
isEnabled = false;
labelModel.setObject("enable drag");
draggable1.disable(target);
draggable2.disable(target);
draggableDroppable1.disableDraggable(target);
draggableDroppable2.disableDraggable(target);
draggableAndResizable1.disableDraggable(target);
}
else {
isEnabled = true;
labelModel.setObject("disable drag");
draggable1.enable(target);
draggable2.enable(target);
draggableDroppable1.enableDraggable(target);
draggableDroppable2.enableDraggable(target);
draggableAndResizable1.enableDraggable(target);
}
// Redraw menu
menu2.redraw(target);
}
};
}
});
// Enable/disable dropping
menu2.addMenuItem(new IMenuLink() {
private static final long serialVersionUID = 1L;
private boolean isEnabled = true;
private Model<String> labelModel = new Model<String>("disable drop");
@Override
public Component getDisplayComponent(String id) {
return new Label(id, labelModel);
}
@Override
public AbstractLink getLink(String id) {
return new AjaxFallbackLink<Void>(id) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
if (isEnabled) {
isEnabled = false;
labelModel.setObject("enable drop");
droppable1.disable(target);
droppable2.disable(target);
draggableDroppable1.disableDroppable(target);
draggableDroppable2.disableDroppable(target);
}
else {
isEnabled = true;
labelModel.setObject("disable drop");
droppable1.enable(target);
droppable2.enable(target);
draggableDroppable1.enableDroppable(target);
draggableDroppable2.enableDroppable(target);
}
// Redraw menu
menu2.redraw(target);
}
};
}
});
// Enable/disable resize
menu2.addMenuItem(new IMenuLink() {
private static final long serialVersionUID = 1L;
private boolean isEnabled = true;
private Model<String> labelModel = new Model<String>("disable resize");
@Override
public Component getDisplayComponent(String id) {
return new Label(id, labelModel);
}
@Override
public AbstractLink getLink(String id) {
return new AjaxFallbackLink<Void>(id) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
if (isEnabled) {
isEnabled = false;
labelModel.setObject("enable resize");
resizable1.disable(target);
draggableAndResizable1.disableResizable(target);
}
else {
isEnabled = true;
labelModel.setObject("disable resize");
resizable1.enable(target);
draggableAndResizable1.enableResizable(target);
}
// Redraw menu
menu2.redraw(target);
}
};
}
});
// Enable/disable resize
menu2.addMenuItem(new IMenuLink() {
private static final long serialVersionUID = 1L;
private Model<String> labelModel = new Model<String>("show animations");
@Override
public Component getDisplayComponent(String id) {
return new Label(id, labelModel);
}
@Override
public AbstractLink getLink(String id) {
return new AjaxFallbackLink<Void>(id) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
// Redraw menu
menu2.redraw(target);
// Show the effects
explode.fire(target, postEffects, draggable1);
puff.fire(target, postEffects2, draggable2);
}