public ContextMenu doContextMenu(StaplerRequest request, StaplerResponse response) throws IOException, JellyException { ContextMenu menu = new ContextMenu().from(this, request, response); for (MenuItem i : menu.items) { if (i.url.equals(request.getContextPath() + "/manage")) { // add "Manage Jenkins" subitems i.subMenu = new ContextMenu().from(this, request, response, "manage"); } } return menu; }
/** * @see ContextMenuVisibility */ public ContextMenu add(Action a) { if (!Functions.isContextMenuVisible(a)) { return this; } StaplerRequest req = Stapler.getCurrentRequest(); String text = a.getDisplayName(); String base = Functions.getIconFilePath(a); if (base==null) return this; String icon = Stapler.getCurrentRequest().getContextPath()+(base.startsWith("images/")?Functions.getResourcePath():"")+'/'+base; String url = Functions.getActionUrl(req.findAncestor(ModelObject.class).getUrl(),a); return add(url,icon,text); }
public ContextMenu from(ModelObjectWithContextMenu self, StaplerRequest request, StaplerResponse response, String view) throws JellyException, IOException { WebApp webApp = WebApp.getCurrent(); final Script s = webApp.getMetaClass(self).getTearOff(JellyClassTearOff.class).findScript(view); if (s!=null) { JellyFacet facet = webApp.getFacet(JellyFacet.class); request.setAttribute("taskTags",this); // <l:task> will look for this variable and populate us request.setAttribute("mode","side-panel"); // run sidepanel but ignore generated HTML facet.scriptInvoker.invokeScript(request,response,new Script() { public Script compile() throws JellyException { return this; } public void run(JellyContext context, XMLOutput output) throws JellyTagException { Functions.initPageVariables(context); s.run(context,output); } },self,new XMLOutput(new DefaultHandler())); } else if (self instanceof Actionable) { // fallback this.addAll(((Actionable)self).getAllActions()); } return this; } }
public ContextMenu getContextMenu(String prefix) { if (getStore().hasPermission(UPDATE) || getStore().hasPermission(DELETE)) { ContextMenu result = new ContextMenu(); if (getStore().hasPermission(UPDATE)) { result.add(new MenuItem( ContextMenuIconUtils.buildUrl(prefix, "update"), getMenuItemIconUrlByClassSpec("icon-setting icon-md"), result.add(new MenuItem(ContextMenuIconUtils.buildUrl(prefix, "delete"), getMenuItemIconUrlByClassSpec("icon-edit-delete icon-md"), Messages.CredentialsStoreAction_DeleteCredentialAction() )); result.add(new MenuItem(ContextMenuIconUtils.buildUrl(prefix, "move"), getMenuItemIconUrlByClassSpec("icon-credentials-move icon-md"), Messages.CredentialsStoreAction_MoveCredentialAction()
public ContextMenu getContextMenu(String prefix) { if (getStore().hasPermission(CREATE) || (getStore().hasPermission(MANAGE_DOMAINS) && !domain.isGlobal())) { ContextMenu result = new ContextMenu(); if (getStore().hasPermission(CREATE)) { result.add(new MenuItem( ContextMenuIconUtils.buildUrl(prefix, "newCredentials"), getMenuItemIconUrlByClassSpec("icon-credentials-new-credential icon-md"), result.add(new MenuItem(ContextMenuIconUtils.buildUrl(prefix, "configure"), getMenuItemIconUrlByClassSpec("icon-setting icon-md"), Messages.CredentialsStoreAction_ConfigureDomainAction() )); result.add(new MenuItem(ContextMenuIconUtils.buildUrl(prefix, "delete"), getMenuItemIconUrlByClassSpec("icon-edit-delete icon-md"), Messages.CredentialsStoreAction_DeleteDomainAction()
public ContextMenu getContextMenu(String prefix) { if (getStore().hasPermission(UPDATE) || getStore().hasPermission(DELETE)) { ContextMenu result = new ContextMenu(); if (getStore().hasPermission(UPDATE)) { result.add(new MenuItem( ContextMenuIconUtils.buildUrl(prefix, "update"), getMenuItemIconUrlByClassSpec("icon-setting icon-md"), result.add(new MenuItem(ContextMenuIconUtils.buildUrl(prefix, "delete"), getMenuItemIconUrlByClassSpec("icon-edit-delete icon-md"), Messages.CredentialsStoreAction_DeleteCredentialAction() )); result.add(new MenuItem(ContextMenuIconUtils.buildUrl(prefix, "move"), getMenuItemIconUrlByClassSpec("icon-credentials-move icon-md"), Messages.CredentialsStoreAction_MoveCredentialAction()
public ContextMenu getContextMenu(String prefix) { if (getStore().hasPermission(CREATE) || (getStore().hasPermission(MANAGE_DOMAINS) && !domain.isGlobal())) { ContextMenu result = new ContextMenu(); if (getStore().hasPermission(CREATE)) { result.add(new MenuItem( ContextMenuIconUtils.buildUrl(prefix, "newCredentials"), getMenuItemIconUrlByClassSpec("icon-credentials-new-credential icon-md"), result.add(new MenuItem(ContextMenuIconUtils.buildUrl(prefix, "configure"), getMenuItemIconUrlByClassSpec("icon-setting icon-md"), Messages.CredentialsStoreAction_ConfigureDomainAction() )); result.add(new MenuItem(ContextMenuIconUtils.buildUrl(prefix, "delete"), getMenuItemIconUrlByClassSpec("icon-edit-delete icon-md"), Messages.CredentialsStoreAction_DeleteDomainAction()
/** * Helper method to produce the breadcrumb context menu. * * @param context the url prefix to put on all urls. * @return the selectable reports. * @see #doChildrenContextMenu(StaplerRequest, StaplerResponse) * @see com.sonyericsson.hudson.plugins.gerrit.trigger.GerritManagement#doContextMenu(StaplerRequest, StaplerResponse) */ @Restricted(NoExternalUse.class) public ContextMenu getContextMenu(String context) { ContextMenu menu = new ContextMenu(); String url = makeRelativeUrl(context, "buildMemory"); menu.add(new MenuItem() .withUrl(url) .withStockIcon("clipboard.png") .withDisplayName(Messages.BuildMemoryReport_DisplayName())); url = makeRelativeUrl(context, "eventListeners"); menu.add(new MenuItem() .withUrl(url) .withStockIcon("clipboard.png") .withDisplayName(Messages.EventListenersReport_DisplayName())); if (isDebugMode()) { menu.add("triggerDebugEvent", "warning.png", "Trigger Debug", false, true); } return menu; }
/** * Adds a menu item for the specified action with the supplied prefix offset and optional sub menu. * * @param menu the menu to add to. * @param prefix the prefix offset of the action urls. * @param action the action. * @param subMenu the sub menu. */ public static void addMenuItem(@NonNull ModelObjectWithContextMenu.ContextMenu menu, @CheckForNull String prefix, @NonNull Action action, @CheckForNull ModelObjectWithContextMenu.ContextMenu subMenu) { if (isContextMenuVisible(action) && action.getIconFileName() != null) { Icon icon = action instanceof IconSpec ? ContextMenuIconUtils.getIcon(action) : null; String base = icon != null ? ContextMenuIconUtils.getQualifiedUrl(icon) : Functions.getIconFilePath(action); ModelObjectWithContextMenu.MenuItem item = new ModelObjectWithContextMenu.MenuItem( ContextMenuIconUtils.buildUrl(prefix, action.getUrlName()), ContextMenuIconUtils.getMenuItemIconUrl(base), action.getDisplayName() ); item.subMenu = subMenu; menu.add(item); } } /** TODO copied from {@link Functions} but currently restricted */
/** * Creates the children context menu with the supplied prefix to all URLs. * * @param prefix the prefix to prepend to relative urls. * @return the {@link ContextMenu} or {@code null} * @since 2.0 */ @CheckForNull public ContextMenu getChildrenContextMenu(String prefix) { ContextMenu menu = new ContextMenu(); for (Map.Entry<String, CredentialsWrapper> entry : getCredentials().entrySet()) { String p = ContextMenuIconUtils.buildUrl(prefix, "credential", entry.getKey()); MenuItem item = new MenuItem(p, getMenuItemIconUrlByClassSpec(entry.getValue().getIconClassName() + " icon-md"), entry.getValue().getDisplayName() ); item.subMenu = entry.getValue().getContextMenu(p); menu.add(item); } return menu.items.isEmpty() ? null : menu; }
public ContextMenu from(ModelObjectWithContextMenu self, StaplerRequest request, StaplerResponse response, String view) throws JellyException, IOException { WebApp webApp = WebApp.getCurrent(); final Script s = webApp.getMetaClass(self).getTearOff(JellyClassTearOff.class).findScript(view); if (s!=null) { JellyFacet facet = webApp.getFacet(JellyFacet.class); request.setAttribute("taskTags",this); // <l:task> will look for this variable and populate us request.setAttribute("mode","side-panel"); // run sidepanel but ignore generated HTML facet.scriptInvoker.invokeScript(request,response,new Script() { public Script compile() throws JellyException { return this; } public void run(JellyContext context, XMLOutput output) throws JellyTagException { Functions.initPageVariables(context); s.run(context,output); } },self,new XMLOutput(new DefaultHandler())); } else if (self instanceof Actionable) { // fallback this.addAll(((Actionable)self).getAllActions()); } return this; } }
/** * Creates the children context menu with the supplied prefix to all URLs. * * @param prefix the prefix to prepend to relative urls. * @return the {@link ContextMenu} or {@code null} * @since 2.0 */ @CheckForNull public ContextMenu getChildrenContextMenu(String prefix) { ContextMenu menu = new ContextMenu(); for (Domain d : getStore().getDomains()) { MenuItem item = new MenuItem(d.getUrl(), getMenuItemIconUrlByClassSpec("icon-credentials-domain icon-md"), d.isGlobal() ? Messages.CredentialsStoreAction_GlobalDomainDisplayName() : d.getName() ); item.subMenu = new DomainWrapper(this, d).getContextMenu(ContextMenuIconUtils.buildUrl(prefix, d.getUrl())); menu.add(item); } return menu.items.isEmpty() ? null : menu; }
/** * Adds a menu item for the specified action with the supplied prefix offset and optional sub menu. * * @param menu the menu to add to. * @param prefix the prefix offset of the action urls. * @param action the action. * @param subMenu the sub menu. */ public static void addMenuItem(@NonNull ModelObjectWithContextMenu.ContextMenu menu, @CheckForNull String prefix, @NonNull Action action, @CheckForNull ModelObjectWithContextMenu.ContextMenu subMenu) { if (isContextMenuVisible(action) && action.getIconFileName() != null) { Icon icon = action instanceof IconSpec ? ContextMenuIconUtils.getIcon(action) : null; String base = icon != null ? ContextMenuIconUtils.getQualifiedUrl(icon) : Functions.getIconFilePath(action); ModelObjectWithContextMenu.MenuItem item = new ModelObjectWithContextMenu.MenuItem( ContextMenuIconUtils.buildUrl(prefix, action.getUrlName()), ContextMenuIconUtils.getMenuItemIconUrl(base), action.getDisplayName() ); item.subMenu = subMenu; menu.add(item); } } /** TODO copied from {@link Functions} but currently restricted */
/** * Creates the context menu with the supplied prefix to all URLs. * * @param prefix the prefix to prepend to relative urls. * @return the {@link ContextMenu} or {@code null} * @since 2.0 */ @CheckForNull public ContextMenu getContextMenu(String prefix) { ContextMenu menu = new ContextMenu(); if (getStore().isDomainsModifiable() && getStore().hasPermission(MANAGE_DOMAINS)) { menu.add(ContextMenuIconUtils.buildUrl(prefix, "newDomain"), getMenuItemIconUrlByClassSpec("icon-credentials-new-domain icon-md"), Messages.CredentialsStoreAction_AddDomainAction() ); } for (Action action : getActions()) { ContextMenuIconUtils.addMenuItem(menu, prefix, action); } return menu.items.isEmpty() ? null : menu; }
/** * Creates the children context menu with the supplied prefix to all URLs. * * @param prefix the prefix to prepend to relative urls. * @return the {@link ContextMenu} or {@code null} * @since 2.0 */ @CheckForNull public ContextMenu getChildrenContextMenu(String prefix) { ContextMenu menu = new ContextMenu(); for (Map.Entry<String, CredentialsWrapper> entry : getCredentials().entrySet()) { String p = ContextMenuIconUtils.buildUrl(prefix, "credential", entry.getKey()); MenuItem item = new MenuItem(p, getMenuItemIconUrlByClassSpec(entry.getValue().getIconClassName() + " icon-md"), entry.getValue().getDisplayName() ); item.subMenu = entry.getValue().getContextMenu(p); menu.add(item); } return menu.items.isEmpty() ? null : menu; }
/** * Creates the children context menu with the supplied prefix to all URLs. * * @param prefix the prefix to prepend to relative urls. * @return the {@link ContextMenu} or {@code null} * @since 2.0 */ @CheckForNull public ContextMenu getChildrenContextMenu(String prefix) { ContextMenu menu = new ContextMenu(); for (Domain d : getStore().getDomains()) { MenuItem item = new MenuItem(d.getUrl(), getMenuItemIconUrlByClassSpec("icon-credentials-domain icon-md"), d.isGlobal() ? Messages.CredentialsStoreAction_GlobalDomainDisplayName() : d.getName() ); item.subMenu = new DomainWrapper(this, d).getContextMenu(ContextMenuIconUtils.buildUrl(prefix, d.getUrl())); menu.add(item); } return menu.items.isEmpty() ? null : menu; }
/** * {@inheritDoc} */ // In the general case we would implement ModelObjectWithChildren as the child actions could be viewed as children // but in this case we expose them in the sidebar, so they are more correctly part of the context menu. @Override public ContextMenu doContextMenu(StaplerRequest request, StaplerResponse response) throws Exception { ContextMenu menu = new ContextMenu(); for (CredentialsStoreAction action : getStoreActions()) { ContextMenuIconUtils.addMenuItem( menu, "store", action, action.getContextMenu(ContextMenuIconUtils.buildUrl("store", action.getUrlName())) ); } return menu; }
/** * Creates the context menu with the supplied prefix to all URLs. * * @param prefix the prefix to prepend to relative urls. * @return the {@link ContextMenu} or {@code null} * @since 2.0 */ @CheckForNull public ContextMenu getContextMenu(String prefix) { ContextMenu menu = new ContextMenu(); if (getStore().isDomainsModifiable() && getStore().hasPermission(MANAGE_DOMAINS)) { menu.add(ContextMenuIconUtils.buildUrl(prefix, "newDomain"), getMenuItemIconUrlByClassSpec("icon-credentials-new-domain icon-md"), Messages.CredentialsStoreAction_AddDomainAction() ); } for (Action action : getActions()) { ContextMenuIconUtils.addMenuItem(menu, prefix, action); } return menu.items.isEmpty() ? null : menu; }
@Override public ContextMenu doContextMenu(StaplerRequest request, StaplerResponse response) throws Exception { checkPermission(); Jenkins jenkins = Jenkins.getInstance(); assert jenkins != null; ContextMenu menu = new ContextMenu(); menu.add("newServer", Functions.joinPath(jenkins.getRootUrl(), Functions.getResourcePath(), "images", "24x24", "new-package.png"), Messages.AddNewServer()); for (GerritServer server : getServers()) { menu.add(server); } MenuItem item = new MenuItem() .withUrl("diagnostics") .withDisplayName(DIAGNOSTICS) .withStockIcon("folder.png"); item.subMenu = DIAGNOSTICS.getContextMenu("diagnostics"); menu.add(item); return menu; }
/** * This method is called via AJAX to obtain the context menu for this model object. */ public ContextMenu doContextMenu(StaplerRequest request, StaplerResponse response) throws Exception { if (false) { // this implementation is suffice for most ModelObjects. It uses sidepanel.jelly/.groovy to // generate the context menu return new ContextMenu().from(this,request,response); } else { // otherwise you can also programatically create them. // see the javadoc for various convenience methods to add items return new ContextMenu() .add("http://jenkins-ci.org/","Jenkins project") .add("http://www.cloudbees.com/","CloudBees") .add(new MenuItem().withContextRelativeUrl("/").withStockIcon("gear.png").withDisplayName("top page")); } }