Changeset 4262


Ignore:
Timestamp:
Apr 30, 2008, 9:54:50 AM (15 years ago)
Author:
Nicklas Nordborg
Message:

References #933: Create extension points for some selected places in the web client

Added support for submenus

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/menu/FixedMenuItemFactory.java

    r4207 r4262  
    11/**
    2   $Id$
     2  $Id$
    33
    44  Copyright (C) Authors contributing to this file.
     
    5252  private MenuItemAction[] actions;
    5353 
     54  private String menuId;
     55  private String submenuId;
    5456  private String icon;
    5557  private String onClick;
     
    9496
    9597  @Override
     98  public String getMenuId()
     99  {
     100    return menuId;
     101  }
     102 
     103  @Override
    96104  public String getOnClick()
    97105  {
     
    103111  {
    104112    return style;
     113  }
     114
     115  @Override
     116  public String getSubmenuId()
     117  {
     118    return submenuId;
    105119  }
    106120
     
    147161  }
    148162
     163  public void setMenuId(String menuId)
     164  {
     165    this.menuId = menuId;
     166  }
     167 
    149168  @VariableSetter
    150169  public void setOnClick(String onClick)
     
    158177  }
    159178
     179  public void setSubmenuId(String submenuId)
     180  {
     181    this.submenuId = submenuId;
     182  }
     183
    160184  public void setTitle(String title)
    161185  {
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/menu/MenuItemAction.java

    r4187 r4262  
    2727
    2828/**
    29   An action for extensions to the menu system. Currently, two menu
     29  An action for extensions to the menu system. The extension point
     30  will add menu items to the <code>Extensions</code> menu.
     31 
     32  Currently, two menu
    3033  subtypes are supported: a real menu item and a menu separator.
    3134  Submenus are not supported.
     
    4346  */
    4447  public MenuType getType();
     48 
     49  /**
     50    The ID of the menu where this menu item belongs, or null if
     51    it belongs to the top-level menu.
     52  */
     53  public String getMenuId();
     54 
     55  /**
     56    The ID of a new submenu. This value is required when the menu item is
     57    a {@link MenuType#SUBMENU}, and is ignored otherwise.
     58  */
     59  public String getSubmenuId();
    4560 
    4661  /**
     
    144159   
    145160    /**
     161      A menu item that opens a submenu.
     162    */
     163    SUBMENU,
     164   
     165    /**
    146166      This is a separator line. All properties except
    147167      {@link MenuItemAction#isVisible()} and {@link MenuItemAction#getStyle()}
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/menu/MenuItemBean.java

    r4187 r4262  
    3636{
    3737
     38  private String menuId;
     39  private String submenuId;
    3840  private String icon;
    3941  private String onClick;
     
    5860    Create a new initialised menu item action
    5961  */
    60   public MenuItemBean(MenuType type,
     62  public MenuItemBean(MenuType type, String menuId, String submenuId,
    6163    String title, String onClick, String tooltip, String icon, String style,
    6264    boolean enabled, boolean visible)
    6365  {
    6466    this.type = type;
     67    this.menuId = menuId;
     68    this.submenuId = submenuId;
    6569    this.title = title;
    6670    this.onClick = onClick;
     
    8387
    8488  @Override
     89  public String getMenuId()
     90  {
     91    return menuId;
     92  }
     93 
     94  @Override
    8595  public String getOnClick()
    8696  {
     
    92102  {
    93103    return style;
     104  }
     105 
     106  @Override
     107  public String getSubmenuId()
     108  {
     109    return submenuId;
    94110  }
    95111
     
    130146  }
    131147
     148  public void setMenuId(String menuId)
     149  {
     150    this.menuId = menuId;
     151  }
     152 
    132153  public void setOnClick(String onClick)
    133154  {
     
    138159  {
    139160    this.style = style;
     161  }
     162 
     163  public void setSubmenuId(String submenuId)
     164  {
     165    this.submenuId = submenuId;
    140166  }
    141167
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/menu/PermissionMenuItemFactory.java

    r4233 r4262  
    11/**
    2   $Id$
     2  $Id$
    33
    44  Copyright (C) Authors contributing to this file.
     
    6868  private String onClick;
    6969  private MenuType type;
     70  private String menuId;
     71  private String submenuId;
    7072
    7173  private Permission visiblePermission;
     
    114116      // Menu item should be visible but disabled
    115117      action = new MenuItemBean(
    116         type, disabledTitle, null, disabledTooltip, disabledIcon, disabledStyle, false, true);
     118        type, menuId, submenuId, disabledTitle, null, disabledTooltip, disabledIcon, disabledStyle, false, true);
    117119    }
    118120    else
     
    120122      // Menu item is visible and enabled
    121123      action = new MenuItemBean(
    122         type, enabledTitle, onClick, enabledTooltip, enabledIcon, enabledStyle, true, true);
     124        type, menuId, submenuId, enabledTitle, onClick, enabledTooltip, enabledIcon, enabledStyle, true, true);
    123125    }
    124126    return new MenuItemAction[] { action };
     
    191193    this.disabledIcon = icon;
    192194  }
     195 
     196  public void setMenuId(String menuId)
     197  {
     198    this.menuId = menuId;
     199  }
    193200
    194201  /**
     
    222229    this.enabledStyle = style;
    223230    this.disabledStyle = style;
     231  }
     232 
     233  public void setSubmenuId(String submenuId)
     234  {
     235    this.submenuId = submenuId;
    224236  }
    225237
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/menu/Submenu.java

    r4093 r4262  
    178178  */
    179179  private String icon = null;
     180 
     181  private boolean iconAbsolute = false;
    180182
    181183
     
    244246  {
    245247    return icon;
     248  }
     249  public void setIconabsolute(boolean absolute)
     250  {
     251    this.iconAbsolute = absolute;
     252  }
     253 
     254  public boolean isIconabsolute()
     255  {
     256    return iconAbsolute;
    246257  }
    247258
     
    277288      sb.append("<img src=\"").append(menu.getRoot()).append("images/submenu.gif\" alt=\"&gt;\" style=\"float: right; padding-right: 4px;\">");
    278289      String theIcon = getIcon() == null ? "padding.gif" : getIcon();
    279       sb.append("<img src=\"").append(menu.getRoot()).append("images/").append(theIcon).append("\" alt=\"\" style=\"padding-left: 4px; padding-right: 4px;\">");
     290      if (!isIconabsolute())
     291      {
     292        // The icon is in the 'images' directory
     293        theIcon = menu.getRoot() + "images/" + theIcon;
     294      }     
     295     
     296      sb.append("<img src=\"").append(theIcon).append("\" alt=\"\" style=\"padding-left: 4px; padding-right: 4px;\">");
    280297    }
    281298    String padding = menu.isVertical() ? "&nbsp;" : "";
  • trunk/www/WEB-INF/menu.tld

    r4187 r4262  
    171171      <rtexprvalue>true</rtexprvalue>
    172172    </attribute>
     173    <attribute>
     174      <name>iconabsolute</name>
     175      <required>false</required>
     176      <rtexprvalue>true</rtexprvalue>
     177    </attribute>
    173178  </tag>
    174179  <tag>
  • trunk/www/include/menu.jsp

    r4237 r4262  
    6464  import="net.sf.basedb.util.extensions.ActionIterator"
    6565  import="java.util.HashMap"
     66  import="java.util.Map"
    6667  import="java.util.ArrayList"
     68  import="java.util.LinkedList"
    6769  import="java.util.List"
    6870  import="java.util.Arrays"
     
    957959        "net.sf.basedb.clients.web.menu.extensions");
    958960    ExtensionsControl ec = ExtensionsControl.get(dc);
    959     ActionIterator<MenuItemAction> items = invoker.iterate();
    960     boolean addSeparator = false;
    961     %>
    962     <m:menu id="extensions" style="display: none">
     961    ActionIterator<MenuItemAction> it = invoker.iterate();
     962    Map<String, List<MenuItemAction>> menus = new HashMap<String, List<MenuItemAction>>();
     963    while (it.hasNext())
     964    {
     965      MenuItemAction action = it.next();
     966      String menuId = action.getMenuId();
     967      menuId = menuId == null ? "extensions" : "extensions." + menuId;
     968      List<MenuItemAction> actions = menus.get(menuId);
     969      if (actions == null)
     970      {
     971        actions = new LinkedList<MenuItemAction>();
     972        menus.put(menuId, actions);
     973      }
     974      actions.add(action);
     975    }
     976   
     977    for (Map.Entry<String, List<MenuItemAction>> entry : menus.entrySet())
     978    {
     979      String menuId = entry.getKey();
     980      List<MenuItemAction> actions = entry.getValue();
     981      %>
     982      <m:menu id="<%=menuId%>" style="display: none;">
    963983      <%
    964       while (items.hasNext())
     984      for (MenuItemAction action : actions)
    965985      {
    966         MenuItemAction item = items.next();
    967         Extension extension = items.getExtension();
    968         if (item.getType() == MenuItemAction.MenuType.SEPARATOR)
     986        if (action.getType() == MenuItemAction.MenuType.SEPARATOR)
    969987        {
    970           addSeparator = false;
    971988          %>
    972           <m:menuseparator style="<%=item.getStyle()%>" visible="<%=item.isVisible()%>" />
     989          <m:menuseparator style="<%=action.getStyle()%>" visible="<%=action.isVisible()%>" />
    973990          <%
    974991        }
    975         else if (item.getType() == MenuItemAction.MenuType.MENUITEM)
     992        else if (action.getType() == MenuItemAction.MenuType.MENUITEM)
    976993        {
    977           addSeparator = true;
    978994          %>
    979995          <m:menuitem
    980             style="<%=item.getStyle()%>"
    981             title="<%=item.getTitle()%>"
    982             icon="<%=item.getIcon()%>"
     996            style="<%=action.getStyle()%>"
     997            title="<%=action.getTitle()%>"
     998            icon="<%=action.getIcon()%>"
    983999            iconabsolute="true"
    984             tooltip="<%=item.getTooltip()%>"
    985             enabled="<%=item.isEnabled()%>"
    986             visible="<%=item.isVisible()%>"
    987             onclick="<%=item.getOnClick()%>"
     1000            tooltip="<%=action.getTooltip()%>"
     1001            enabled="<%=action.isEnabled()%>"
     1002            visible="<%=action.isVisible()%>"
     1003            onclick="<%=action.getOnClick()%>"
     1004          />
     1005          <%
     1006        }
     1007        else if (action.getType() == MenuItemAction.MenuType.SUBMENU)
     1008        {
     1009          %>
     1010          <m:submenu
     1011            subid="<%="extensions." + action.getSubmenuId()%>"
     1012            style="<%=action.getStyle()%>"
     1013            title="<%=action.getTitle()%>"
     1014            icon="<%=action.getIcon()%>"
     1015            iconabsolute="true"
     1016            tooltip="<%=action.getTooltip()%>"
     1017            enabled="<%=action.isEnabled()%>"
     1018            visible="<%=action.isVisible()%>"
    9881019          />
    9891020          <%
    9901021        }
    9911022      }
    992       if (addSeparator)
     1023      if ("extensions".equals(menuId))
    9931024      {
     1025        if (actions.size() > 0)
     1026        {
     1027          %>
     1028          <m:menuseparator />
     1029          <%
     1030        }
    9941031        %>
    995         <m:menuseparator />
     1032        <m:menuitem
     1033          title="Installed extensions"
     1034          onclick="<%="Menu.openUrl('"+root+"admin/extensions/index.jsp?ID="+ID+"')"%>"
     1035          tooltip="Display and administrate installed extensions"
     1036        />
     1037        <m:menuitem
     1038          title="Manual scan&hellip;"
     1039          onclick="<%="Main.openPopup('"+root+"admin/extensions/manual_scan.jsp?ID=" + ID + "', 'ManualScan', 500, 400);"%>"
     1040          enabled="<%=ec.hasPermission(Permission.WRITE)%>"
     1041          tooltip="Start a manual scan for new, updated and deleted extensions"
     1042        />
    9961043        <%
    9971044      }
    9981045      %>
    999       <m:menuitem
    1000         title="Installed extensions"
    1001         onclick="<%="Menu.openUrl('"+root+"admin/extensions/index.jsp?ID="+ID+"')"%>"
    1002         tooltip="Display and administrate installed extensions"
    1003       />
    1004       <m:menuitem
    1005         title="Manual scan&hellip;"
    1006         onclick="<%="Main.openPopup('"+root+"admin/extensions/manual_scan.jsp?ID=" + ID + "', 'ManualScan', 500, 400);"%>"
    1007         enabled="<%=ec.hasPermission(Permission.WRITE)%>"
    1008         tooltip="Start a manual scan for new, updated and deleted extensions"
    1009       />
    1010     </m:menu>
     1046      </m:menu>
     1047      <%
     1048    }
     1049    %>
    10111050   
    10121051    <%
Note: See TracChangeset for help on using the changeset viewer.