Changeset 4870


Ignore:
Timestamp:
Apr 1, 2009, 1:38:59 PM (13 years ago)
Author:
Nicklas Nordborg
Message:

References #1271: Add extension points to all toolbars

Infrastructure is in place. I have used experiment list page as a prototype. Changes include:

  • Renderer and renderer factory for toolbar buttons
  • Add support for WrappingRenderer? to allow an extension point to add HTML around what is generated by a parent renderer.
    • Make it possible to programmatically register extension points
    • The table.Button taglib also uses the ToolbarButtonRenderer?
Location:
trunk
Files:
6 added
12 edited

Legend:

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

    r4618 r4870  
    3232
    3333import net.sf.basedb.clients.web.extensions.service.Services;
     34import net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil;
    3435import net.sf.basedb.clients.web.servlet.ExtensionsServlet;
    3536import net.sf.basedb.core.AccessControlled;
     
    135136    registry = new Registry();
    136137   
     138    // Toolbar extensions are added programmatically
     139    // must be done before scanning files otherwise it is not
     140    // possible to register extension for the toolbars
     141    ToolbarUtil.registerExtensionPoints(registry);
     142   
    137143    // Load settings
    138144    File settingsFile = new File(directory.getExtensionDirectory(), "settings.xml");
     
    143149    lastScanResults = extensionsDir.installAndUpdateExtensions(registry,
    144150      servletContext, false, false);
     151
    145152    initAutoInstaller();
    146153    initialised = true;
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/extensions/Render.java

    r4512 r4870  
    2323package net.sf.basedb.clients.web.taglib.extensions;
    2424
     25import java.io.IOException;
     26
    2527import javax.servlet.jsp.JspException;
    2628import javax.servlet.jsp.tagext.TagSupport;
     
    2931import net.sf.basedb.util.extensions.ExtensionsInvoker;
    3032import net.sf.basedb.util.extensions.Renderer;
     33import net.sf.basedb.util.extensions.WrappingRenderer;
    3134
    3235/**
     
    4144      item=...
    4245      renderer=...
     46      wrapper=...
    4347  />
    4448</pre>
     
    8286    <td>no</td>
    8387    <td>
    84       The renderer to use. If not null, the
    85       {@link ExtensionsInvoker#render(net.sf.basedb.util.extensions.Renderer)}
    86       method is used, otherwise {@link ExtensionsInvoker#renderDefault()}.
     88      The {@link Renderer} to use. If not null, the
     89      {@link ExtensionsInvoker#render(Renderer)}
     90      method is used, otherwise {@link ExtensionsInvoker#renderDefault()}
     91      or {@link ExtensionsInvoker#renderDefault(WrappingRenderer)}.
     92    </td>
     93  </tr>
     94  <tr>
     95    <td>wrapper</td>
     96    <td>-</td>
     97    <td>no</td>
     98    <td>
     99      The {@link WrappingRenderer} to use. If not null and no renderer
     100      has been given, the {@link ExtensionsInvoker#renderDefault(WrappingRenderer)}
     101      method is used.
    87102    </td>
    88103  </tr>
     
    110125  private Renderer renderer = null;
    111126 
     127  // An optional wrapper
     128  private WrappingRenderer wrapper = null;
     129 
    112130  public void setExtensions(ExtensionsInvoker extensions)
    113131  {
     
    130148  }
    131149
     150  public void setWrapper(WrappingRenderer wrapper)
     151  {
     152    this.wrapper = wrapper;
     153  }
     154 
    132155  @SuppressWarnings("unchecked")
    133156  public int doStartTag()
     
    135158  {
    136159    if (item != null && context != null) context.setCurrentItem(item);
    137     if (renderer == null)
     160    try
    138161    {
    139       extensions.renderDefault();
     162      if (renderer == null)
     163      {
     164        extensions.renderDefault(wrapper);
     165      }
     166      else if (wrapper != null)
     167      {
     168        wrapper.setParent(renderer);
     169        extensions.render(wrapper);
     170      }
     171      else
     172      {
     173        extensions.render(renderer);
     174      }
     175      pageContext.getOut().print("</td>");
    140176    }
    141     else
     177    catch (IOException ex)
    142178    {
    143       extensions.render(renderer);
     179      throw new JspException(ex);
    144180    }
    145181    return SKIP_BODY;
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/table/Button.java

    r4512 r4870  
    2323package net.sf.basedb.clients.web.taglib.table;
    2424
     25import net.sf.basedb.clients.web.extensions.toolbar.ButtonAction;
     26import net.sf.basedb.clients.web.extensions.toolbar.ToolbarButtonRenderer;
    2527import net.sf.basedb.clients.web.taglib.Page;
    2628
     29import javax.servlet.http.HttpServletRequest;
    2730import javax.servlet.jsp.JspException;
    2831import javax.servlet.jsp.JspTagException;
     32import javax.servlet.jsp.JspWriter;
    2933import javax.servlet.jsp.tagext.TagSupport;
    3034
     
    4246      style=...
    4347      image=...
    44       imagealign=left|right
     48      imagealign=left|right (no longer supported)
    4549      onclick=...
    4650      title=...
     
    109113    <td>
    110114      If the image should be aligned to the left or right of the text.
     115      No longer supported.
    111116    </td>
    112117  </tr>
     
    162167public class Button
    163168  extends TagSupport
     169  implements ButtonAction
    164170{
    165171
     
    308314  }
    309315
     316  @Override
     317  public String getIcon()
     318  {
     319    return ((HttpServletRequest)pageContext.getRequest()).getContextPath()+"/images/" + getImage();
     320  }
     321  @Override
     322  public String getOnClick()
     323  {
     324    return getOnclick();
     325  }
     326  @Override
     327  public boolean isEnabled()
     328  {
     329    return !isDisabled();
     330  }
     331 
    310332  /*
    311333    Display methods
     
    319341    table = toolbar.getTable();
    320342    Page page = table != null ? table.getPage() : (Page)findAncestorWithClass(this, Page.class);
    321 
    322343    boolean displayImage = getImage() != null && toolbar.hasImages();
    323344    boolean displayText = toolbar.hasText() || !displayImage;
    324    
    325     StringBuilder sb = new StringBuilder();
    326     sb.append("<td");
    327     if (getId() != null) sb.append(" id=\"").append(getId()).append("\"");
    328     if (getClazz() != null)
    329     {
    330       sb.append(" class=\"").append(getClazz()).append(isDisabled() ? "_disabled" : "").append("\"");
    331       if (!isDisabled())
    332       {
    333         sb.append(" onmouseover=\"this.className='").append(getClazz()).append("_hover';\"");
    334         sb.append(" onmouseout=\"this.className='").append(getClazz()).append("';\"");
    335       }
    336     }
    337     if (getOnclick() != null && !isDisabled()) sb.append(" onclick=\"").append(getOnclick()).append("\"");
    338     if (getStyle() != null) sb.append(" style=\"").append(getStyle()).append("\"");
    339     String tooltip = getTooltip();
    340     if (!displayText && tooltip == null) tooltip = getTitle();
    341     if (tooltip != null) sb.append(" title=\"").append(tooltip).append("\"");
    342     sb.append(">");
    343     if (displayImage)
    344     {
    345       sb.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>");
    346       if ("left".equalsIgnoreCase(getImagealign()))
    347       {
    348         sb.append("<td><img src=\"").append(page.getRoot()).append("images/").append(getImage()).append("\"");
    349         sb.append(" border=\"0\"></td>");
    350       }
    351       sb.append("<td>");
    352     }
    353     if (displayText && getTitle() != null) sb.append("&nbsp;").append(getTitle()).append("&nbsp;");
    354     if (displayImage)
    355     {
    356       sb.append("</td>");
    357       if (!"left".equalsIgnoreCase(getImagealign()))
    358       {
    359         sb.append("<td><img src=\"").append(page.getRoot()).append("images/").append(getImage()).append("\"");
    360         sb.append(" border=\"0\"></td>");
    361       }
    362       sb.append("</tr></table>");
    363     }
    364     sb.append("</td>\n");
     345 
     346    String html = new ToolbarButtonRenderer().getHTML(this, displayText, displayImage);
    365347    try
    366348    {
    367       pageContext.getOut().print(sb.toString());
     349      JspWriter out = pageContext.getOut();
     350      out.print("<td>" + html + "</td>");
    368351    }
    369352    catch (Exception ex)
  • trunk/src/core/net/sf/basedb/util/extensions/ExtensionsInvoker.java

    r4618 r4870  
    9393  /**
    9494    Render all actions using the renderers created by the
    95     default renderer factory as specified by the registered
     95    default renderer factories as specified by the registered
    9696    extension points and/or extensions.
    9797    @see ExtensionPoint#getRendererFactory()
     
    9999  */
    100100  public void renderDefault()
     101  {
     102    renderDefault(null);
     103  }
     104 
     105  /**
     106    Render all actions by wrapping the default renderers by the
     107    given wrapping renderer.
     108    @param wrapper A wrapping renderer, or null to not wrap
     109      the default renderers
     110    @since 2.12
     111  */
     112  public void renderDefault(WrappingRenderer<A> wrapper)
    101113  {
    102114    ActionIterator<A> it = iterate();
     
    114126          throw new NullPointerException("No renderer for extension: " + it.getExtension());
    115127        }
     128        if (wrapper != null)
     129        {
     130          wrapper.setParent(renderer);
     131          renderer = wrapper;
     132        }
    116133        renderer.render(action);
    117134      }
     
    124141    }
    125142  }
     143
    126144 
    127145  /**
  • trunk/src/core/net/sf/basedb/util/extensions/Registry.java

    r4618 r4870  
    518518    for (String id : extensionPointIds)
    519519    {
     520      if (id == null) continue;
     521     
    520522      // Find a registered extension point for each ID
    521523      RegisteredExtensionPoint<Action> rep =
  • trunk/www/WEB-INF/extensions.tld

    r4510 r4870  
    8585      <rtexprvalue>true</rtexprvalue>
    8686    </attribute>
     87    <attribute>
     88      <name>wrapper</name>
     89      <required>false</required>
     90      <rtexprvalue>true</rtexprvalue>
     91    </attribute>
    8792  </tag>
    88 
    89 
    9093</taglib>
  • trunk/www/WEB-INF/extensions/core-extensions.xml

    r4510 r4870  
    5353      Extension point for the Tools column in the bioassayset tree
    5454      view of an experiment. Extensions should provide ActionButton
    55       instances. The default renderer factory is ActionButtonRendererFactory,
     55      instances. The default renderer factory is CompactButtonRendererFactory,
    5656      but this can be overridden by the extensions. Note that the tree
    5757      contains items of more than one type: BioAssaySet, Transformation and
     
    7979    </description>
    8080  </extension-point>
     81  <!--
     82    Toolbar extension points:
     83    In addition to the extension points in this file, the web
     84    client also defines a lot of toolbar extension points for the
     85    list and single-item view pages. Those extension points are registered
     86    programmatically. For more information see Extensions -> Installed extensions
     87    in the web client interface.
     88  -->
    8189 
    8290</extensions>
  • trunk/www/admin/extensions/details.jsp

    r4618 r4870  
    6060  }
    6161  String text = factory.getClass().getName();
    62   String parameters = file.getFactoryParameters(factory);
     62  String parameters = file == null ? null : file.getFactoryParameters(factory);
    6363  if (parameters != null)
    6464  {
     
    396396          <td class="prompt">File</td>
    397397          <td>
    398             <a href="javascript:showFile('<%=HTML.javaScriptEncode(epFile.getName())%>')"
    399             ><%=epFile.getName()%></a>
    400             (<%=epFile.isModified() ? "Modified" : "Up to date" %>;
    401             <%=epFile.hasError() ? "Error" : "Ok" %>)
     398            <%
     399            if (epFile != null)
     400            {
     401              %>
     402              <a href="javascript:showFile('<%=HTML.javaScriptEncode(epFile.getName())%>')"
     403              ><%=epFile.getName()%></a>
     404              (<%=epFile.isModified() ? "Modified" : "Up to date" %>;
     405              <%=epFile.hasError() ? "Error" : "Ok" %>)
     406              <%
     407            }
     408            %>
    402409          </td>
    403410        </tr>
  • trunk/www/admin/extensions/tree.jsp

    r4795 r4870  
    4949  String icon = ec.isEnabled(ep) ? "ExtensionPoint" : "ExtensionPointDisabled";
    5050  ExtensionsFile f = ec.getFileByExtensionId(id);
    51   if (f == null || f.hasError() || ec.getLastExtensionPointError(id) != null)
     51  if ((f != null && f.hasError()) || ec.getLastExtensionPointError(id) != null)
    5252  {
    5353    icon = "ExtensionPointError";
     
    6565  String icon = ec.isEnabled(ext) ? "Extension" : "ExtensionDisabled";
    6666  ExtensionsFile f = ec.getFileByExtensionId(id);
    67   if (f == null || f.hasError() || ec.getLastExtensionError(id) != null)
     67  if ((f != null && f.hasError()) || ec.getLastExtensionError(id) != null)
    6868  {
    6969    icon = "ExtensionError";
  • trunk/www/include/styles/table.css

    r4711 r4870  
    5959}
    6060
    61 .itemlist .toolbar .button_hover {
     61.itemlist .toolbar .button:hover {
    6262  background: #F0F0F0;
    63   border-top: 1px solid #FFFFFF;
    64   border-left: 1px solid #FFFFFF;
    65   border-bottom: 0px solid #999999;
    66   border-right: 1px solid #999999;
    67   padding: 3px;
    68   cursor: pointer;
    6963}
    7064
  • trunk/www/include/styles/toolbar.css

    r4510 r4870  
    4949}
    5050
     51.toolbar .button:hover {
     52  background: #F0F0F0;
     53}
     54
    5155.toolbar .label {
    5256  font-weight: bold;
     
    5660  border-right: 2px solid #999999;
    5761  padding: 3px;
    58 }
    59 
    60 .toolbar .button_hover {
    61   background: #F0F0F0;
    62   border-top: 1px solid #FFFFFF;
    63   border-left: 1px solid #FFFFFF;
    64   border-bottom: 0px solid #999999;
    65   border-right: 1px solid #999999;
    66   padding: 3px;
    67   cursor: pointer;
    6862}
    6963
  • trunk/www/views/experiments/list_experiments.jsp

    r4698 r4870  
    5656  import="net.sf.basedb.util.formatter.Formatter"
    5757  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
     58  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
     59  import="net.sf.basedb.clients.web.extensions.JspContext"
     60  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
     61  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
     62  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
    5863  import="java.util.Iterator"
    5964  import="java.util.List"
     
    6368<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
    6469<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
     70<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
    6571<%!
    6672  private static final Item itemType = Item.EXPERIMENT;
     
    9399  int numListed = 0;
    94100  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
     101  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext);
     102  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext, guiContext);
    95103  %>
    96104  <base:page title="<%=title==null ? "Experiments" : title%>" type="<%=mode.getPageType()%>">
    97105  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
     106    <ext:scripts context="<%=jspContext%>" />
     107    <ext:stylesheets context="<%=jspContext%>" />
    98108    <script language="JavaScript">
    99109    var submitPage = 'index.jsp';
     
    445455          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
    446456        />
     457        <ext:render extensions="<%=invoker%>" context="<%=jspContext%>"
     458          wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
    447459      </tbl:toolbar>
    448460      <tbl:navigator
Note: See TracChangeset for help on using the changeset viewer.