Changeset 7760


Ignore:
Timestamp:
Nov 27, 2019, 2:37:26 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2199: Implement a "File viewer" extension point

Implemented in the file manger list and single-item pages.

Location:
trunk
Files:
5 edited

Legend:

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

    r7759 r7760  
    2424  private final FileViewerContext fileContext;
    2525  private final ExtensionsInvoker<ButtonAction> fileActions;
     26  private String prefix = "[";
     27  private String suffix = "]";
    2628 
    2729  public FileViewerUtil(JspContext jspContext, FileViewerContext fileContext)
     
    5052
    5153  /**
     54    Sets a prefix and suffix string to use before and after the list of actions.
     55    The default is "[" and "]".
     56  */
     57  public void setPrefixAndSuffix(String prefix, String suffix)
     58  {
     59    this.prefix = prefix;
     60    this.suffix = suffix;
     61  }
     62 
     63  /**
    5264    Rended the extensions with the current file context information.
    5365  */
     
    6880    if (result != null && result.length() > 0)
    6981    {
    70       jspContext.getOut().write("<span class=\"file-actions\">[" + result + "]</span>");
     82      jspContext.getOut().write("<span class=\"file-actions\">" + prefix + result + suffix + "</span>");
    7183    }
    7284  }
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/fileviewer/ViewAndDownloadActionFactory.java

    r7758 r7760  
    33import net.sf.basedb.clients.web.extensions.AbstractJspActionFactory;
    44import net.sf.basedb.clients.web.extensions.JspContext;
     5import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerContext.Type;
    56import net.sf.basedb.clients.web.extensions.toolbar.ButtonAction;
    67import net.sf.basedb.clients.web.extensions.toolbar.ButtonBean;
     
    3435    if (l == Location.OFFLINE)
    3536    {
    36       ButtonBean offline = new ButtonBean();
    37       offline.setVisible(true);
    38       offline.setIcon(jspContext.getRoot()+"/images/offline.png");
    39       offline.setTitle("This file is offline");
    40       actions = new ButtonAction[] { offline };
     37      if (fctx.getType() == Type.FILE)
     38      {
     39        // Here we add an "Upload" action
     40        ButtonBean upload = new ButtonBean();
     41        upload.setVisible(true);
     42        upload.setClazz("link auto-init");
     43        upload.setIcon(jspContext.getRoot()+"/images/upload.png");
     44        upload.setTitle("Upload this file again");
     45        upload.setDynamicAttribute("data-file-id", f.getId());
     46        upload.setDynamicAttribute("data-auto-init", "upload-file");
     47        actions = new ButtonAction[] { upload };
     48      }
     49      else
     50      {
     51        ButtonBean offline = new ButtonBean();
     52        offline.setVisible(true);
     53        offline.setIcon(jspContext.getRoot()+"/images/offline.png");
     54        offline.setTitle("This file is offline");
     55        actions = new ButtonAction[] { offline };
     56      }
    4157    }
    4258    else if (l.isDownloadable())
  • trunk/www/common/datafiles/list_files.jsp

    r7757 r7760  
    229229  <base:page type="include">
    230230  <base:body>
    231   <ext:scripts context="<%=jspContext%>" />
     231    <ext:scripts context="<%=jspContext%>" />
    232232    <base:section
    233233      id="datafiles"
  • trunk/www/filemanager/files/list_files.jsp

    r7703 r7760  
    7272  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
    7373  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
     74  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil"
     75  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerContext"
    7476  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
    7577  import="java.util.Iterator"
     
    253255  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
    254256  ExtensionsInvoker<ListColumnAction<File,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
     257  FileViewerContext fileContext = FileViewerContext.file();
     258  FileViewerUtil fileViewer = new FileViewerUtil(jspContext, fileContext);
     259  fileViewer.setPrefixAndSuffix("", "");
    255260  %>
    256261  <base:page title="<%=title==null ? "Files" : title%>" type="iframe" id="list-page">
     
    837842            {
    838843              File item = files.next();
     844              fileContext.setCurrentFile(item);
    839845              int itemId = item.getId();
    840846              Location location = item.getLocation();
     
    976982                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
    977983                <tbl:cell column="lastUpdate" value="<%=item.getLastUpdate()%>" />
    978                 <tbl:cell column="actions">
    979                   <%
    980                   if (location.isDownloadable())
    981                   {
    982                     %>
    983                     <base:icon
    984                       subclass="link auto-init"
    985                       data-auto-init="view-file"
    986                       data-file-id="<%=itemId %>"
    987                       image="view.png"
    988                       tooltip="<%="View the contents of this file (" + fileSize + ")"%>" />
    989                     <base:icon
    990                       subclass="link auto-init"
    991                       data-auto-init="download-file"
    992                       data-file-id="<%=itemId%>"
    993                       image="download.png"
    994                       tooltip="<%="Download the contents of this file (" + fileSize + ")"%>" />
    995                     <%
    996                   }
    997                   else if (location == Location.OFFLINE)
    998                   {
    999                     %>
    1000                     <base:icon
    1001                       subclass="link auto-init"
    1002                       data-auto-init="upload-file"
    1003                       data-file-id="<%=itemId%>"
    1004                       image="upload.png" tooltip="Upload this file again"
    1005                     />
    1006                     <%
    1007                   }
    1008                   %>
    1009                 </tbl:cell>
     984                <tbl:cell column="actions"><%fileViewer.render();%></tbl:cell>
    1010985                <tbl:cell column="permissions"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
    1011986                <tbl:cell column="sharedTo">
  • trunk/www/filemanager/files/view_file.jsp

    r7604 r7760  
    5454  import="net.sf.basedb.clients.web.extensions.toolbar.ButtonAction"
    5555  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
     56  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil"
     57  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerContext"
    5658  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
    5759  import="java.util.Collections"
     
    103105  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, file);
    104106  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
     107  FileViewerContext fileContext = FileViewerContext.file();
     108  fileContext.setCurrentFile(file);
     109  FileViewerUtil fileViewer = new FileViewerUtil(jspContext, fileContext);
    105110  %>
    106111  <base:page type="iframe" title="<%=title%>" id="view-page">
     
    254259      <tr>
    255260        <th>Location</th>
    256         <td><%=location%>       
     261        <td><%=location%>
    257262        <%
    258         if (location.isDownloadable())
     263        fileViewer.render();
     264        if (location == Location.PRIMARY && file.hasPermission(Permission.WRITE) && !file.isWriteProtected())
    259265        {
    260           %>
    261           [<base:icon
    262             subclass="link auto-init"
    263             data-auto-init="view-file"
    264             data-file-id="<%=itemId%>"
    265             image="view.png"
    266             tooltip="<%="View the contents of this file (" + bytes + ")"%>" />
    267           <base:icon
    268             subclass="link auto-init"
    269             data-auto-init="download-file"
    270             data-file-id="<%=itemId%>"
    271             image="download.png"
    272             tooltip="<%="Download the contents of this file (" + bytes + ")"%>" />
    273           <%
    274           if (location == Location.PRIMARY && file.hasPermission(Permission.WRITE) && !file.isWriteProtected())
    275           {
    276             %>
    277             | <span class="link"
    278               id="moveOffline"
    279               data-file-id="<%=itemId %>"
    280               data-location="OFFLINE"
    281               >move offline</span>
    282             | <span class="link auto-init"
    283               data-auto-init="upload-file"
    284               data-file-id="<%=itemId%>">replace</span>
    285             <%
    286           }
    287           %>
    288           ]
    289           <%
    290         }       
    291         else if (location == Location.OFFLINE)
    292         {
    293           %>
    294           [<base:icon
    295             subclass="link auto-init"
     266          %> [<span class="link"
     267            id="moveOffline"
     268            data-file-id="<%=itemId %>"
     269            data-location="OFFLINE"
     270            >move offline</span>
     271          | <span class="link auto-init"
    296272            data-auto-init="upload-file"
    297             data-file-id="<%=itemId%>"
    298             image="upload.png" tooltip="Upload this file again" />]
     273            data-file-id="<%=itemId%>">replace</span>]
    299274          <%
    300275        }
Note: See TracChangeset for help on using the changeset viewer.