Changeset 7855
- Timestamp:
- Oct 19, 2020, 1:18:36 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/fileviewer/FileViewerContext.java
r7756 r7855 53 53 } 54 54 55 private finalType type;56 private finalBasicItem parentItem;55 private Type type; 56 private BasicItem parentItem; 57 57 private File file; 58 58 private AnyToAny any; … … 125 125 public void setCurrentFile(File file) 126 126 { 127 this.type = Type.FILE; 127 128 this.file = file; 128 129 } … … 133 134 public void setCurrentDataFile(File file, DataFileType fileType, FileSetMember member) 134 135 { 136 this.type = Type.DATA_FILE; 135 137 this.file = file; 136 138 this.fileType = fileType; 137 139 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; 138 150 } 139 151 … … 143 155 public void setCurrentAnyToAny(File file, AnyToAny any) 144 156 { 157 this.type = Type.ANY_TO_ANY; 145 158 this.file = file; 146 159 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; 147 170 } 148 171 -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/fileviewer/FileViewerUtil.java
r7761 r7855 21 21 { 22 22 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 23 55 private final JspContext jspContext; 24 56 private final FileViewerContext fileContext; … … 26 58 private String prefix = "["; 27 59 private String suffix = "]"; 28 60 61 /** 62 63 @deprecated In 3.17, use {@link #getOrCreate(JspContext, FileViewerContext)} instead 64 */ 65 @Deprecated 29 66 public FileViewerUtil(JspContext jspContext, FileViewerContext fileContext) 30 67 { 31 68 this.jspContext = jspContext; 32 69 this.fileContext = fileContext; 70 Object currentItem = jspContext.getCurrentItem(); 33 71 jspContext.setCurrentItem(fileContext); 34 72 this.fileActions = ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.file-viewer"); 73 jspContext.setCurrentItem(currentItem); 35 74 } 36 75 … … 51 90 } 52 91 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 53 101 /** 54 102 Sets a prefix and suffix string to use before and after the list of actions. … … 83 131 { 84 132 // Need to repeat this since to make sure the correct context is always used 133 Object currentItem = jspContext.getCurrentItem(); 85 134 jspContext.setCurrentItem(fileContext); 86 135 … … 90 139 fileActions.renderDefault(); 91 140 jspContext.getPageContext().popBody(); 141 jspContext.setCurrentItem(currentItem); 92 142 93 143 String result = ""; -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/AnyLinkColumn.java
r7850 r7855 1 1 package net.sf.basedb.clients.web.extensions.list; 2 2 3 import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil; 3 4 import net.sf.basedb.clients.web.formatter.AutoItemExportFormatter; 4 5 import net.sf.basedb.clients.web.formatter.AutoLinkFormatter; … … 9 10 import net.sf.basedb.core.BasicItem; 10 11 import net.sf.basedb.core.DbControl; 12 import net.sf.basedb.core.File; 11 13 import net.sf.basedb.core.Item; 12 14 import net.sf.basedb.core.ItemNotFoundException; … … 36 38 */ 37 39 @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) 39 41 { 40 42 AnyLinkColumn col = null; … … 58 60 } 59 61 60 col = new AnyLinkColumn(index, expr, linkName, targetType, property );62 col = new AnyLinkColumn(index, expr, linkName, targetType, property, fileViewer); 61 63 col.setTitle(linkName); 62 64 col.setTooltip((propertyType == null ? "Any" : propertyType.toString()) + " › " + linkName); … … 67 69 col.setValueType(Type.BOOLEAN); 68 70 col.setExportFormatter(new AutoItemExportFormatter()); 69 col.setFormatter((Formatter)new AutoLinkFormatter( ));71 col.setFormatter((Formatter)new AutoLinkFormatter(fileViewer)); 70 72 } 71 73 else if (property == null || property.getHibernateType().isEntityType()) … … 78 80 // Files should export the path and have extra links 79 81 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)); 81 83 } 82 84 else … … 116 118 private final Item targetType; 117 119 private final PropertyPath<BasicItem, ?> property; 120 private final FileViewerUtil fileViewer; 118 121 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) 120 123 { 121 124 this.index = index; … … 123 126 this.targetType = targetType; 124 127 this.property = property; 128 this.fileViewer = fileViewer; 125 129 setId(id); 126 130 setProperty(id); … … 140 144 { 141 145 BasicItem target = link.getTo(); 146 if (fileViewer != null && target instanceof File) 147 { 148 fileViewer.getFileContext().setCurrentAnyToAny(item, (File)target, link); 149 } 142 150 value = property == null ? target : property.getValue(dc, target); 143 151 } -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/AnyLinkColumnActionFactory.java
r7850 r7855 6 6 import net.sf.basedb.clients.web.extensions.AbstractJspActionFactory; 7 7 import net.sf.basedb.clients.web.extensions.JspContext; 8 import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerContext; 9 import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil; 8 10 import net.sf.basedb.core.BasicItem; 9 11 import net.sf.basedb.core.DbControl; … … 50 52 if (allColumns == null || !allColumns.contains("|")) return false; 51 53 54 FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, FileViewerContext.file()); 52 55 return super.prepareContext(context); 53 56 } … … 71 74 72 75 DbControl dc = jspContext.getDbControl(); 76 FileViewerUtil fileViewer = FileViewerUtil.get(jspContext); 73 77 List<ListColumnAction<BasicItem, Object>> actions = new ArrayList<>(); 74 78 for (String col : allColumns.split(",")) … … 76 80 if (col.startsWith("|")) 77 81 { 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); 79 83 if (action != null) actions.add(action); 80 84 } -
trunk/src/clients/web/net/sf/basedb/clients/web/formatter/AutoLinkFormatter.java
r7850 r7855 23 23 24 24 import net.sf.basedb.clients.web.Base; 25 import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil; 25 26 import net.sf.basedb.clients.web.taglib.Page; 26 27 import net.sf.basedb.core.BasicItem; … … 48 49 private final boolean enableEditLink; 49 50 private final boolean enableViewDownload; 51 private final FileViewerUtil fileViewer; 50 52 51 53 public AutoLinkFormatter() … … 54 56 } 55 57 58 public AutoLinkFormatter(FileViewerUtil fileViewer) 59 { 60 this.fileViewer = fileViewer; 61 this.enableEditLink = true; 62 this.enableViewDownload = true; 63 } 64 56 65 public AutoLinkFormatter(boolean enableEditLink, boolean enableViewDownload) 57 66 { 58 67 this.enableEditLink = enableEditLink; 59 68 this.enableViewDownload = enableViewDownload; 69 this.fileViewer = null; 60 70 } 61 71 … … 66 76 if (item instanceof File) 67 77 { 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 } 69 86 } 70 87 else if (item instanceof Nameable) -
trunk/src/clients/web/net/sf/basedb/clients/web/formatter/DataFileFormatter.java
r6837 r7855 26 26 import net.sf.basedb.clients.web.Base; 27 27 import net.sf.basedb.clients.web.ModeInfo; 28 import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil; 28 29 import net.sf.basedb.clients.web.taglib.Page; 30 import net.sf.basedb.core.BasicItem; 29 31 import net.sf.basedb.core.DataFileType; 30 32 import net.sf.basedb.core.DbControl; … … 52 54 private final DataFileType fileType; 53 55 private final ModeInfo mode; 56 private final FileViewerUtil fileViewer; 54 57 private ItemQuery<FileSetMember> memberQuery; 55 58 … … 59 62 public DataFileFormatter(DbControl dc, DataFileType fileType, ModeInfo mode) 60 63 { 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 { 61 73 this.dc = dc; 62 74 this.fileType = fileType; 63 75 this.mode = mode; 76 this.fileViewer = fileViewer; 64 77 } 65 78 … … 97 110 if (mode.hasPropertyLink()) 98 111 { 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 } 100 122 } 101 123 else -
trunk/src/clients/web/net/sf/basedb/clients/web/formatter/LinkedFileFormatter.java
r7850 r7855 23 23 24 24 import net.sf.basedb.clients.web.Base; 25 import net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil; 25 26 import net.sf.basedb.clients.web.taglib.Page; 26 27 import net.sf.basedb.core.File; … … 41 42 private final boolean enableEditLink; 42 43 private final boolean enableViewDownload; 44 private final FileViewerUtil fileViewer; 43 45 44 46 public LinkedFileFormatter() 45 47 { 46 48 this(true, true); 49 } 50 51 public LinkedFileFormatter(FileViewerUtil fileViewer) 52 { 53 this.fileViewer = fileViewer; 54 this.enableEditLink = true; 55 this.enableViewDownload = true; 47 56 } 48 57 … … 51 60 this.enableEditLink = enableEditLink; 52 61 this.enableViewDownload = enableViewDownload; 62 this.fileViewer = null; 53 63 } 54 64 … … 56 66 public String format(File file) 57 67 { 68 if (fileViewer != null) 69 { 70 return Base.getLinkedName(null, file, false, enableEditLink) + " " + fileViewer.renderAsString(); 71 } 58 72 return Base.getLinkedFile(null, file, false, enableEditLink, enableViewDownload, Page.ROOT()); 59 73 } -
trunk/www/common/anytoany/list_anytoany.jsp
r7761 r7855 87 87 ExtensionsInvoker<ListColumnAction<AnyToAny,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext); 88 88 FileViewerContext fileContext = FileViewerContext.anyToAny(item); 89 FileViewerUtil fileViewer = new FileViewerUtil(jspContext, fileContext);89 FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, fileContext); 90 90 %> 91 91 <base:page type="include"> -
trunk/www/common/datafiles/list_files.jsp
r7760 r7855 225 225 JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, new GuiContext(itemType, GuiContext.Type.ITEM), null); 226 226 FileViewerContext fileContext = FileViewerContext.dataFile((BasicItem)item); 227 FileViewerUtil fileViewer = new FileViewerUtil(jspContext, fileContext);227 FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, fileContext); 228 228 %> 229 229 <base:page type="include"> -
trunk/www/common/overview/info.jsp
r7762 r7855 166 166 if (fileContext != null) 167 167 { 168 fileViewer = new FileViewerUtil(jspContext, fileContext);168 fileViewer = FileViewerUtil.getOrCreate(jspContext, fileContext); 169 169 } 170 170 %> -
trunk/www/filemanager/files/list_files.jsp
r7760 r7855 256 256 ExtensionsInvoker<ListColumnAction<File,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext); 257 257 FileViewerContext fileContext = FileViewerContext.file(); 258 FileViewerUtil fileViewer = new FileViewerUtil(jspContext, fileContext);258 FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, fileContext); 259 259 fileViewer.setPrefixAndSuffix("", ""); 260 260 %> -
trunk/www/filemanager/files/view_file.jsp
r7760 r7855 107 107 FileViewerContext fileContext = FileViewerContext.file(); 108 108 fileContext.setCurrentFile(file); 109 FileViewerUtil fileViewer = new FileViewerUtil(jspContext, fileContext);109 FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, fileContext); 110 110 %> 111 111 <base:page type="iframe" title="<%=title%>" id="view-page"> -
trunk/www/lims/arraydesigns/list_designs.jsp
r7605 r7855 78 78 import="net.sf.basedb.clients.web.extensions.list.ListColumnAction" 79 79 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" 80 82 import="net.sf.basedb.clients.web.util.ProjectSpecificInfoFilter" 81 83 import="net.sf.basedb.util.extensions.ExtensionsInvoker" … … 166 168 ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext); 167 169 ExtensionsInvoker<ListColumnAction<ArrayDesign,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext); 170 FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, FileViewerContext.file()); 168 171 %> 169 172 <base:page title="<%=title==null ? "Array designs" : title%>" type="<%=mode.getPageType()%>" id="list-page"> … … 399 402 sortable="false" 400 403 exportable="true" 401 formatter="<%=new DataFileFormatter(dc, ft, mode ) %>"404 formatter="<%=new DataFileFormatter(dc, ft, mode, fileViewer) %>" 402 405 /> 403 406 <% -
trunk/www/views/derivedbioassays/list_bioassays.jsp
r7842 r7855 76 76 import="net.sf.basedb.clients.web.extensions.list.ListColumnAction" 77 77 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" 78 80 import="net.sf.basedb.clients.web.util.ProjectSpecificInfoFilter" 79 81 import="net.sf.basedb.util.extensions.ExtensionsInvoker" … … 176 178 ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext); 177 179 ExtensionsInvoker<ListColumnAction<DerivedBioAssay,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext); 180 FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, FileViewerContext.file()); 178 181 %> 179 182 <base:page title="<%=title==null ? "Derived bioassays" : title%>" type="<%=mode.getPageType()%>" id="list-page"> … … 422 425 sortable="false" 423 426 exportable="true" 424 formatter="<%=new DataFileFormatter(dc, ft, mode ) %>"427 formatter="<%=new DataFileFormatter(dc, ft, mode, fileViewer) %>" 425 428 /> 426 429 <% -
trunk/www/views/rawbioassays/list_rawbioassays.jsp
r7842 r7855 87 87 import="net.sf.basedb.clients.web.extensions.list.ListColumnAction" 88 88 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" 89 91 import="net.sf.basedb.clients.web.util.ProjectSpecificInfoFilter" 90 92 import="net.sf.basedb.util.extensions.ExtensionsInvoker" … … 179 181 ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext); 180 182 ExtensionsInvoker<ListColumnAction<RawBioAssay,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext); 183 FileViewerUtil fileViewer = FileViewerUtil.getOrCreate(jspContext, FileViewerContext.file()); 181 184 %> 182 185 <base:page title="<%=title==null ? "Raw bioassays" : title%>" type="<%=mode.getPageType()%>" id="list-page"> … … 486 489 sortable="false" 487 490 exportable="true" 488 formatter="<%=new DataFileFormatter(dc, ft, mode ) %>"491 formatter="<%=new DataFileFormatter(dc, ft, mode, fileViewer) %>" 489 492 /> 490 493 <%
Note: See TracChangeset
for help on using the changeset viewer.