Changeset 7855


Ignore:
Timestamp:
Oct 19, 2020, 1:18:36 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2222: Add support for manually adding any-to-any link column in table lists

Added support for enabling the "File viewer" extension in any-to-any links that are targeting a file item.

Location:
trunk
Files:
15 edited

Legend:

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

    r7756 r7855  
    5353  }
    5454 
    55   private final Type type;
    56   private final BasicItem parentItem;
     55  private Type type;
     56  private BasicItem parentItem;
    5757  private File file;
    5858  private AnyToAny any;
     
    125125  public void setCurrentFile(File file)
    126126  {
     127    this.type = Type.FILE;
    127128    this.file = file;
    128129  }
     
    133134  public void setCurrentDataFile(File file, DataFileType fileType, FileSetMember member)
    134135  {
     136    this.type = Type.DATA_FILE;
    135137    this.file = file;
    136138    this.fileType = fileType;
    137139    this.member = member;
     140  }
     141 
     142  /**
     143    Sets the current data file and change the parent item.
     144    @since 3.17
     145  */
     146  public void setCurrentDataFile(BasicItem parentItem, File file, DataFileType fileType, FileSetMember member)
     147  {
     148    setCurrentDataFile(file, fileType, member);
     149    this.parentItem = parentItem;
    138150  }
    139151 
     
    143155  public void setCurrentAnyToAny(File file, AnyToAny any)
    144156  {
     157    this.type = Type.ANY_TO_ANY;
    145158    this.file = file;
    146159    this.any = any;
     160  }
     161 
     162  /**
     163    Sets the current any-to-any linked file and change the parent item.
     164    @since 3.17
     165  */
     166  public void setCurrentAnyToAny(BasicItem parentItem, File file, AnyToAny any)
     167  {
     168    setCurrentAnyToAny(file, any);
     169    this.parentItem = parentItem;
    147170  }
    148171 
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/fileviewer/FileViewerUtil.java

    r7761 r7855  
    2121{
    2222
     23  /**
     24    Get an existing instance that is stored in the given JSP context.
     25    @return A FileViewerUtil instance or null
     26    @since 3.17
     27  */
     28  public static FileViewerUtil get(JspContext jspContext)
     29  {
     30    return (FileViewerUtil)jspContext.getAttribute("net.sf.basedb.clients.web.file-viewer");
     31  }
     32
     33  /**
     34    Get an existing instance or create a new instance. If a new instance is
     35    created it is stored in the given JSP context if {@link ExtensionsInvoker#getNumExtensions()}
     36    is more than 0.
     37   
     38    @return A FileViewerUtil instance
     39    @since 3.17
     40  */
     41  public static FileViewerUtil getOrCreate(JspContext jspContext, FileViewerContext fileContext)
     42  {
     43    FileViewerUtil fileViewer = get(jspContext);
     44    if (fileViewer == null)
     45    {
     46      fileViewer = new FileViewerUtil(jspContext, fileContext);
     47      if (fileViewer.getInvoker().getNumExtensions() > 0)
     48      {
     49        jspContext.setAttribute("net.sf.basedb.clients.web.file-viewer", fileViewer);
     50      }
     51    }
     52    return fileViewer;
     53  }
     54 
    2355  private final JspContext jspContext;
    2456  private final FileViewerContext fileContext;
     
    2658  private String prefix = "[";
    2759  private String suffix = "]";
    28  
     60
     61  /**
     62   
     63    @deprecated In 3.17, use {@link #getOrCreate(JspContext, FileViewerContext)} instead
     64  */
     65  @Deprecated
    2966  public FileViewerUtil(JspContext jspContext, FileViewerContext fileContext)
    3067  {
    3168    this.jspContext = jspContext;
    3269    this.fileContext = fileContext;
     70    Object currentItem = jspContext.getCurrentItem();
    3371    jspContext.setCurrentItem(fileContext);
    3472    this.fileActions = ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.file-viewer");
     73    jspContext.setCurrentItem(currentItem);
    3574  }
    3675 
     
    5190  }
    5291
     92  /**
     93    Get the invoker that is handling the extensions.
     94    @since 3.17
     95  */
     96  public ExtensionsInvoker<ButtonAction> getInvoker()
     97  {
     98    return fileActions;
     99  }
     100 
    53101  /**
    54102    Sets a prefix and suffix string to use before and after the list of actions.
     
    83131  {
    84132    // Need to repeat this since to make sure the correct context is always used
     133    Object currentItem = jspContext.getCurrentItem();
    85134    jspContext.setCurrentItem(fileContext);
    86135   
     
    90139    fileActions.renderDefault();
    91140    jspContext.getPageContext().popBody();
     141    jspContext.setCurrentItem(currentItem);
    92142   
    93143    String result = "";
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/AnyLinkColumn.java

    r7850 r7855  
    11package net.sf.basedb.clients.web.extensions.list;
    22
     3import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil;
    34import net.sf.basedb.clients.web.formatter.AutoItemExportFormatter;
    45import net.sf.basedb.clients.web.formatter.AutoLinkFormatter;
     
    910import net.sf.basedb.core.BasicItem;
    1011import net.sf.basedb.core.DbControl;
     12import net.sf.basedb.core.File;
    1113import net.sf.basedb.core.Item;
    1214import net.sf.basedb.core.ItemNotFoundException;
     
    3638  */
    3739  @SuppressWarnings({ "unchecked", "rawtypes" })
    38   public static AnyLinkColumn create(DbControl dc, int index, Item sourceType, String expr)
     40  public static AnyLinkColumn create(DbControl dc, int index, Item sourceType, String expr, FileViewerUtil fileViewer)
    3941  {
    4042    AnyLinkColumn col = null;
     
    5860      }
    5961     
    60       col = new AnyLinkColumn(index, expr, linkName, targetType, property);
     62      col = new AnyLinkColumn(index, expr, linkName, targetType, property, fileViewer);
    6163      col.setTitle(linkName);
    6264      col.setTooltip((propertyType == null ? "Any" : propertyType.toString()) + " › " + linkName);
     
    6769        col.setValueType(Type.BOOLEAN);
    6870        col.setExportFormatter(new AutoItemExportFormatter());
    69         col.setFormatter((Formatter)new AutoLinkFormatter());
     71        col.setFormatter((Formatter)new AutoLinkFormatter(fileViewer));
    7072      }
    7173      else if (property == null || property.getHibernateType().isEntityType())
     
    7880          // Files should export the path and have extra links
    7981          col.setExportFormatter(new FilePathFormatter());
    80           col.setFormatter((Formatter)new LinkedFileFormatter()); // TODO -- would be nice to support FileViewer extensions!!
     82          col.setFormatter((Formatter)new LinkedFileFormatter(fileViewer));
    8183        }
    8284        else
     
    116118  private final Item targetType;
    117119  private final PropertyPath<BasicItem, ?> property;
     120  private final FileViewerUtil fileViewer;
    118121 
    119   AnyLinkColumn(int index, String id, String linkName, Item targetType, PropertyPath<BasicItem, ?> property)
     122  AnyLinkColumn(int index, String id, String linkName, Item targetType, PropertyPath<BasicItem, ?> property, FileViewerUtil fileViewer)
    120123  {
    121124    this.index = index;
     
    123126    this.targetType = targetType;
    124127    this.property = property;
     128    this.fileViewer = fileViewer;
    125129    setId(id);
    126130    setProperty(id);
     
    140144      {
    141145        BasicItem target = link.getTo();
     146        if (fileViewer != null && target instanceof File)
     147        {
     148          fileViewer.getFileContext().setCurrentAnyToAny(item, (File)target, link);
     149        }
    142150        value = property == null ? target : property.getValue(dc, target);
    143151      }
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/AnyLinkColumnActionFactory.java

    r7850 r7855  
    66import net.sf.basedb.clients.web.extensions.AbstractJspActionFactory;
    77import net.sf.basedb.clients.web.extensions.JspContext;
     8import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerContext;
     9import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil;
    810import net.sf.basedb.core.BasicItem;
    911import net.sf.basedb.core.DbControl;
     
    5052    if (allColumns == null || !allColumns.contains("|")) return false;
    5153
     54    FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, FileViewerContext.file());
    5255    return super.prepareContext(context);
    5356  }
     
    7174
    7275    DbControl dc = jspContext.getDbControl();
     76    FileViewerUtil fileViewer = FileViewerUtil.get(jspContext);
    7377    List<ListColumnAction<BasicItem, Object>> actions = new ArrayList<>();
    7478    for (String col : allColumns.split(","))
     
    7680      if (col.startsWith("|"))
    7781      {
    78         ListColumnAction<BasicItem, Object> action = AnyLinkColumn.create(dc, actions.size(), item, col);
     82        ListColumnAction<BasicItem, Object> action = AnyLinkColumn.create(dc, actions.size(), item, col, fileViewer);
    7983        if (action != null) actions.add(action);
    8084      }
  • trunk/src/clients/web/net/sf/basedb/clients/web/formatter/AutoLinkFormatter.java

    r7850 r7855  
    2323
    2424import net.sf.basedb.clients.web.Base;
     25import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil;
    2526import net.sf.basedb.clients.web.taglib.Page;
    2627import net.sf.basedb.core.BasicItem;
     
    4849  private final boolean enableEditLink;
    4950  private final boolean enableViewDownload;
     51  private final FileViewerUtil fileViewer;
    5052 
    5153  public AutoLinkFormatter()
     
    5456  }
    5557 
     58  public AutoLinkFormatter(FileViewerUtil fileViewer)
     59  {
     60    this.fileViewer = fileViewer;
     61    this.enableEditLink = true;
     62    this.enableViewDownload = true;
     63  }
     64
    5665  public AutoLinkFormatter(boolean enableEditLink, boolean enableViewDownload)
    5766  {
    5867    this.enableEditLink = enableEditLink;
    5968    this.enableViewDownload = enableViewDownload;
     69    this.fileViewer = null;
    6070  }
    6171
     
    6676    if (item instanceof File)
    6777    {
    68       link = Base.getLinkedFile(null, (File)item, false, enableEditLink, enableViewDownload, Page.ROOT());
     78      if (fileViewer != null)
     79      {
     80        link = Base.getLinkedName(null, (File)item, false, enableEditLink) + " " + fileViewer.renderAsString();
     81      }
     82      else
     83      {
     84        link = Base.getLinkedFile(null, (File)item, false, enableEditLink, enableViewDownload, Page.ROOT());
     85      }
    6986    }
    7087    else if (item instanceof Nameable)
  • trunk/src/clients/web/net/sf/basedb/clients/web/formatter/DataFileFormatter.java

    r6837 r7855  
    2626import net.sf.basedb.clients.web.Base;
    2727import net.sf.basedb.clients.web.ModeInfo;
     28import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil;
    2829import net.sf.basedb.clients.web.taglib.Page;
     30import net.sf.basedb.core.BasicItem;
    2931import net.sf.basedb.core.DataFileType;
    3032import net.sf.basedb.core.DbControl;
     
    5254  private final DataFileType fileType;
    5355  private final ModeInfo mode;
     56  private final FileViewerUtil fileViewer;
    5457  private ItemQuery<FileSetMember> memberQuery;
    5558 
     
    5962  public DataFileFormatter(DbControl dc, DataFileType fileType, ModeInfo mode)
    6063  {
     64    this(dc, fileType, mode, null);
     65  }
     66 
     67  /**
     68    Creates a new formatter instance for the given file type and list mode.
     69    @since 3.17
     70  */
     71  public DataFileFormatter(DbControl dc, DataFileType fileType, ModeInfo mode, FileViewerUtil fileViewer)
     72  {
    6173    this.dc = dc;
    6274    this.fileType = fileType;
    6375    this.mode = mode;
     76    this.fileViewer = fileViewer;
    6477  }
    6578
     
    97110      if (mode.hasPropertyLink())
    98111      {
    99         sb.append(Base.getLinkedFile(ID, f, f == null, mode.hasEditLink(), true, Page.ROOT()));
     112        if (fileViewer != null)
     113        {
     114          sb.append(Base.getLinkedName(ID, f, f == null, mode.hasEditLink())).append(" ");
     115          fileViewer.getFileContext().setCurrentDataFile((BasicItem)value.getItem(), f, fileType, mbr);
     116          sb.append(fileViewer.renderAsString());
     117        }
     118        else
     119        {
     120          sb.append(Base.getLinkedFile(ID, f, f == null, mode.hasEditLink(), true, Page.ROOT()));
     121        }
    100122      }
    101123      else
  • trunk/src/clients/web/net/sf/basedb/clients/web/formatter/LinkedFileFormatter.java

    r7850 r7855  
    2323
    2424import net.sf.basedb.clients.web.Base;
     25import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil;
    2526import net.sf.basedb.clients.web.taglib.Page;
    2627import net.sf.basedb.core.File;
     
    4142  private final boolean enableEditLink;
    4243  private final boolean enableViewDownload;
     44  private final FileViewerUtil fileViewer;
    4345 
    4446  public LinkedFileFormatter()
    4547  {
    4648    this(true, true);
     49  }
     50
     51  public LinkedFileFormatter(FileViewerUtil fileViewer)
     52  {
     53    this.fileViewer = fileViewer;
     54    this.enableEditLink = true;
     55    this.enableViewDownload = true;
    4756  }
    4857 
     
    5160    this.enableEditLink = enableEditLink;
    5261    this.enableViewDownload = enableViewDownload;
     62    this.fileViewer = null;
    5363  }
    5464
     
    5666  public String format(File file)
    5767  {
     68    if (fileViewer != null)
     69    {
     70      return Base.getLinkedName(null, file, false, enableEditLink) + " " + fileViewer.renderAsString();
     71    }
    5872    return Base.getLinkedFile(null, file, false, enableEditLink, enableViewDownload, Page.ROOT());
    5973  }
  • trunk/www/common/anytoany/list_anytoany.jsp

    r7761 r7855  
    8787  ExtensionsInvoker<ListColumnAction<AnyToAny,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
    8888  FileViewerContext fileContext = FileViewerContext.anyToAny(item);
    89   FileViewerUtil fileViewer = new FileViewerUtil(jspContext, fileContext);
     89  FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, fileContext);
    9090  %>
    9191  <base:page type="include">
  • trunk/www/common/datafiles/list_files.jsp

    r7760 r7855  
    225225  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, new GuiContext(itemType, GuiContext.Type.ITEM), null);
    226226  FileViewerContext fileContext = FileViewerContext.dataFile((BasicItem)item);
    227   FileViewerUtil fileViewer = new FileViewerUtil(jspContext, fileContext);
     227  FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, fileContext);
    228228  %>
    229229  <base:page type="include">
  • trunk/www/common/overview/info.jsp

    r7762 r7855  
    166166  if (fileContext != null)
    167167  {
    168     fileViewer = new FileViewerUtil(jspContext, fileContext);
     168    fileViewer = FileViewerUtil.getOrCreate(jspContext, fileContext);
    169169  }
    170170  %>
  • trunk/www/filemanager/files/list_files.jsp

    r7760 r7855  
    256256  ExtensionsInvoker<ListColumnAction<File,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
    257257  FileViewerContext fileContext = FileViewerContext.file();
    258   FileViewerUtil fileViewer = new FileViewerUtil(jspContext, fileContext);
     258  FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, fileContext);
    259259  fileViewer.setPrefixAndSuffix("", "");
    260260  %>
  • trunk/www/filemanager/files/view_file.jsp

    r7760 r7855  
    107107  FileViewerContext fileContext = FileViewerContext.file();
    108108  fileContext.setCurrentFile(file);
    109   FileViewerUtil fileViewer = new FileViewerUtil(jspContext, fileContext);
     109  FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, fileContext);
    110110  %>
    111111  <base:page type="iframe" title="<%=title%>" id="view-page">
  • trunk/www/lims/arraydesigns/list_designs.jsp

    r7605 r7855  
    7878  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
    7979  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
     80  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerContext"
     81  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil"
    8082  import="net.sf.basedb.clients.web.util.ProjectSpecificInfoFilter"
    8183  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
     
    166168  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
    167169  ExtensionsInvoker<ListColumnAction<ArrayDesign,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
     170  FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, FileViewerContext.file());
    168171  %>
    169172  <base:page title="<%=title==null ? "Array designs" : title%>" type="<%=mode.getPageType()%>" id="list-page">
     
    399402          sortable="false"
    400403          exportable="true"
    401           formatter="<%=new DataFileFormatter(dc, ft, mode) %>"
     404          formatter="<%=new DataFileFormatter(dc, ft, mode, fileViewer) %>"
    402405        />
    403406        <%
  • trunk/www/views/derivedbioassays/list_bioassays.jsp

    r7842 r7855  
    7676  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
    7777  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
     78  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerContext"
     79  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil"
    7880  import="net.sf.basedb.clients.web.util.ProjectSpecificInfoFilter"
    7981  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
     
    176178  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
    177179  ExtensionsInvoker<ListColumnAction<DerivedBioAssay,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
     180  FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, FileViewerContext.file());
    178181  %>
    179182  <base:page title="<%=title==null ? "Derived bioassays" : title%>" type="<%=mode.getPageType()%>" id="list-page">
     
    422425          sortable="false"
    423426          exportable="true"
    424           formatter="<%=new DataFileFormatter(dc, ft, mode) %>"
     427          formatter="<%=new DataFileFormatter(dc, ft, mode, fileViewer) %>"
    425428        />
    426429        <%
  • trunk/www/views/rawbioassays/list_rawbioassays.jsp

    r7842 r7855  
    8787  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
    8888  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
     89  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerContext"
     90  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil"
    8991  import="net.sf.basedb.clients.web.util.ProjectSpecificInfoFilter"
    9092  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
     
    179181  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
    180182  ExtensionsInvoker<ListColumnAction<RawBioAssay,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
     183  FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, FileViewerContext.file());
    181184  %>
    182185  <base:page title="<%=title==null ? "Raw bioassays" : title%>" type="<%=mode.getPageType()%>" id="list-page">
     
    486489          sortable="false"
    487490          exportable="true"
    488           formatter="<%=new DataFileFormatter(dc, ft, mode) %>"
     491          formatter="<%=new DataFileFormatter(dc, ft, mode, fileViewer) %>"
    489492        />
    490493        <%
Note: See TracChangeset for help on using the changeset viewer.