ItEr22S12CUVistaRecursosTempoPorProxectoItEr21S07: Enabling CustomMenuController to add new buttons dinamically
This commit is contained in:
parent
a039731707
commit
fa50126bdc
4 changed files with 77 additions and 9 deletions
|
|
@ -0,0 +1,9 @@
|
|||
package org.zkoss.ganttz.util;
|
||||
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
|
||||
public interface IMenuItemsRegister {
|
||||
|
||||
public void addMenuItem(String name, EventListener eventListener);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package org.zkoss.ganttz.util;
|
||||
|
||||
import org.zkoss.zk.ui.Desktop;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
|
||||
public class MenuItemsRegisterLocator {
|
||||
|
||||
private static final String MENU_ATTRIBUTE = MenuItemsRegisterLocator.class
|
||||
.getSimpleName()
|
||||
+ "_menu";
|
||||
|
||||
private MenuItemsRegisterLocator() {
|
||||
}
|
||||
|
||||
public static void store(IMenuItemsRegister register) {
|
||||
getDesktop().setAttribute(MENU_ATTRIBUTE, register);
|
||||
}
|
||||
|
||||
private static Desktop getDesktop() {
|
||||
return Executions.getCurrent().getDesktop();
|
||||
}
|
||||
|
||||
public static IMenuItemsRegister retrieve()
|
||||
throws IllegalStateException {
|
||||
Object result = getDesktop().getAttribute(MENU_ATTRIBUTE);
|
||||
if (result == null)
|
||||
throw new IllegalStateException("no "
|
||||
+ IMenuItemsRegister.class.getSimpleName() + " registered");
|
||||
return (IMenuItemsRegister) result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,14 +5,20 @@ import static org.navalplanner.web.I18nHelper._;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.ganttz.util.IMenuItemsRegister;
|
||||
import org.zkoss.ganttz.util.MenuItemsRegisterLocator;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
import org.zkoss.zul.Button;
|
||||
import org.zkoss.zul.Div;
|
||||
import org.zkoss.zul.Hbox;
|
||||
|
||||
/**
|
||||
* Controller for customMenu <br />
|
||||
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
|
||||
*/
|
||||
public class CustomMenuController extends Div {
|
||||
public class CustomMenuController extends Div implements IMenuItemsRegister {
|
||||
|
||||
private List<CustomMenuItem> firstLevel;
|
||||
|
||||
|
|
@ -64,6 +70,7 @@ public class CustomMenuController extends Div {
|
|||
|
||||
public CustomMenuController() {
|
||||
initializeMenu();
|
||||
MenuItemsRegisterLocator.store(this);
|
||||
}
|
||||
|
||||
public void initializeMenu() {
|
||||
|
|
@ -72,12 +79,6 @@ public class CustomMenuController extends Div {
|
|||
|
||||
ci = new CustomMenuItem(_("Planification"),
|
||||
"/navalplanner-webapp/planner/main.zul");
|
||||
ci.appendChildren(new CustomMenuItem(_("Planification"),
|
||||
"/navalplanner-webapp/planner/main.zul"));
|
||||
ci.appendChildren(new CustomMenuItem(_("Company overview"),
|
||||
"/navalplanner-webapp/planner/main.zul"));
|
||||
ci.appendChildren(new CustomMenuItem(_("Planifications list"),
|
||||
"/navalplanner-webapp/planner/main.zul"));
|
||||
l.add(ci);
|
||||
|
||||
ci = new CustomMenuItem(_("Resources"),
|
||||
|
|
@ -121,6 +122,10 @@ public class CustomMenuController extends Div {
|
|||
this.firstLevel = l;
|
||||
}
|
||||
|
||||
private Hbox getRegisteredItemsInsertionPoint() {
|
||||
return (Hbox) getFellow("registeredItemsInsertionPoint");
|
||||
}
|
||||
|
||||
public List<CustomMenuItem> getCustomMenuItems() {
|
||||
return this.firstLevel;
|
||||
}
|
||||
|
|
@ -136,4 +141,26 @@ public class CustomMenuController extends Div {
|
|||
return this.firstLevel.get(0).getChildren();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMenuItem(String name,
|
||||
org.zkoss.zk.ui.event.EventListener eventListener) {
|
||||
Hbox insertionPoint = getRegisteredItemsInsertionPoint();
|
||||
Button button = new Button();
|
||||
button.setLabel(_(name));
|
||||
button.addEventListener(Events.ON_CLICK, eventListener);
|
||||
insertionPoint.appendChild(button);
|
||||
insertionPoint.appendChild(separator());
|
||||
}
|
||||
|
||||
private Component separator() {
|
||||
Div div = new Div();
|
||||
div.setStyle("width: 14px; background: /" + getContextPath()
|
||||
+ "common/img/sub_separacion.gif");
|
||||
return div;
|
||||
}
|
||||
|
||||
public String getContextPath() {
|
||||
return Executions.getCurrent().getContextPath();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@
|
|||
<n:td forEach="${menuContainer.customMenuSecondaryItems}">
|
||||
<n:a href="${each.url}" class="sub_menu">${i18n:_(each.name)}</n:a>
|
||||
<n:td width="14"
|
||||
background="/navalplanner-webapp/common/img/sub_separacion.gif" />
|
||||
background="${menuContainer.contextPath}/common/img/sub_separacion.gif" />
|
||||
</n:td>
|
||||
<hbox id="registeredItemsInsertionPoint" />
|
||||
</n:tr>
|
||||
</n:table>
|
||||
|
||||
</n:td>
|
||||
</n:tr>
|
||||
</n:table>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue