3399 |
15 Jun 15 |
nicklas |
1 |
package net.sf.basedb.thumbnails; |
3399 |
15 Jun 15 |
nicklas |
2 |
|
3399 |
15 Jun 15 |
nicklas |
3 |
import net.sf.basedb.clients.web.extensions.AbstractJspActionFactory; |
3399 |
15 Jun 15 |
nicklas |
4 |
import net.sf.basedb.clients.web.extensions.JspContext; |
3399 |
15 Jun 15 |
nicklas |
5 |
import net.sf.basedb.clients.web.extensions.list.AbstractListColumnBean; |
3399 |
15 Jun 15 |
nicklas |
6 |
import net.sf.basedb.clients.web.extensions.list.ListColumnAction; |
3399 |
15 Jun 15 |
nicklas |
7 |
import net.sf.basedb.core.DbControl; |
3399 |
15 Jun 15 |
nicklas |
8 |
import net.sf.basedb.core.File; |
3399 |
15 Jun 15 |
nicklas |
9 |
import net.sf.basedb.core.Item; |
3399 |
15 Jun 15 |
nicklas |
10 |
import net.sf.basedb.core.Nameable; |
3399 |
15 Jun 15 |
nicklas |
11 |
import net.sf.basedb.util.extensions.InvokationContext; |
3399 |
15 Jun 15 |
nicklas |
12 |
|
3399 |
15 Jun 15 |
nicklas |
13 |
/** |
3399 |
15 Jun 15 |
nicklas |
Action factory for the thumbnails list column. |
3399 |
15 Jun 15 |
nicklas |
15 |
|
3399 |
15 Jun 15 |
nicklas |
@author nicklas |
3399 |
15 Jun 15 |
nicklas |
@since 1.0 |
3399 |
15 Jun 15 |
nicklas |
18 |
*/ |
3399 |
15 Jun 15 |
nicklas |
19 |
public class ThumbnailsColumn |
3399 |
15 Jun 15 |
nicklas |
20 |
extends AbstractJspActionFactory<ListColumnAction<Nameable, String>> |
3399 |
15 Jun 15 |
nicklas |
21 |
{ |
3403 |
16 Jun 15 |
nicklas |
22 |
|
3403 |
16 Jun 15 |
nicklas |
23 |
public ThumbnailsColumn() |
3403 |
16 Jun 15 |
nicklas |
24 |
{} |
3399 |
15 Jun 15 |
nicklas |
25 |
|
3399 |
15 Jun 15 |
nicklas |
26 |
@SuppressWarnings("unchecked") |
3399 |
15 Jun 15 |
nicklas |
27 |
@Override |
3399 |
15 Jun 15 |
nicklas |
28 |
public ListColumnAction<Nameable, String>[] getActions(InvokationContext<? super ListColumnAction<Nameable, String>> context) |
3399 |
15 Jun 15 |
nicklas |
29 |
{ |
3399 |
15 Jun 15 |
nicklas |
30 |
JspContext jspContext = (JspContext)context.getClientContext(); |
3399 |
15 Jun 15 |
nicklas |
31 |
String ID = jspContext.getSessionControl().getId(); |
3399 |
15 Jun 15 |
nicklas |
32 |
String home = jspContext.getHome(context.getExtension()); |
3399 |
15 Jun 15 |
nicklas |
33 |
Item guiItem = jspContext.getGuiContext().getItem(); |
3399 |
15 Jun 15 |
nicklas |
34 |
|
3399 |
15 Jun 15 |
nicklas |
35 |
ListColumnAction<Nameable, String> action = null; |
3399 |
15 Jun 15 |
nicklas |
36 |
if (guiItem == Item.FILE) |
3399 |
15 Jun 15 |
nicklas |
37 |
{ |
3399 |
15 Jun 15 |
nicklas |
38 |
action = new ThumbnailColumnAction(ID, home); |
3399 |
15 Jun 15 |
nicklas |
39 |
} |
3399 |
15 Jun 15 |
nicklas |
40 |
return new ListColumnAction[] { action }; |
3399 |
15 Jun 15 |
nicklas |
41 |
} |
3399 |
15 Jun 15 |
nicklas |
42 |
|
3399 |
15 Jun 15 |
nicklas |
43 |
static class ThumbnailColumnAction |
3399 |
15 Jun 15 |
nicklas |
44 |
extends AbstractListColumnBean<Nameable, String> |
3399 |
15 Jun 15 |
nicklas |
45 |
{ |
3399 |
15 Jun 15 |
nicklas |
46 |
private final String ID; |
3399 |
15 Jun 15 |
nicklas |
47 |
private final String home; |
3399 |
15 Jun 15 |
nicklas |
48 |
|
3399 |
15 Jun 15 |
nicklas |
49 |
ThumbnailColumnAction(String ID, String home) |
3399 |
15 Jun 15 |
nicklas |
50 |
{ |
3399 |
15 Jun 15 |
nicklas |
51 |
this.ID = ID; |
3399 |
15 Jun 15 |
nicklas |
52 |
this.home = home; |
3399 |
15 Jun 15 |
nicklas |
53 |
setId("thumbnails"); |
3399 |
15 Jun 15 |
nicklas |
54 |
setTitle("Thumbnail"); |
3399 |
15 Jun 15 |
nicklas |
55 |
} |
3399 |
15 Jun 15 |
nicklas |
56 |
|
3399 |
15 Jun 15 |
nicklas |
57 |
@Override |
3399 |
15 Jun 15 |
nicklas |
58 |
public String getValue(DbControl dc, Nameable fileOrDirectory) |
3399 |
15 Jun 15 |
nicklas |
59 |
{ |
3399 |
15 Jun 15 |
nicklas |
60 |
if (!(fileOrDirectory instanceof File)) return null; |
3399 |
15 Jun 15 |
nicklas |
61 |
String value = null; |
3399 |
15 Jun 15 |
nicklas |
62 |
String name = fileOrDirectory.getName(); |
3417 |
24 Jun 15 |
nicklas |
63 |
if (Thumbnails.getImageLoader((File)fileOrDirectory) != null) |
3399 |
15 Jun 15 |
nicklas |
64 |
{ |
3399 |
15 Jun 15 |
nicklas |
65 |
StringBuilder sb = new StringBuilder(); |
3399 |
15 Jun 15 |
nicklas |
66 |
sb.append("<img src=\"").append(home).append("/Thumbnails.servlet?ID=").append(ID); |
3417 |
24 Jun 15 |
nicklas |
67 |
sb.append("&file="+fileOrDirectory.getId()).append("&size=MEDIUM\""); |
5351 |
10 Apr 19 |
nicklas |
68 |
sb.append(" class=\"thumbnail-img thumbnail-list medium loading auto-init\""); |
3417 |
24 Jun 15 |
nicklas |
69 |
sb.append(" data-auto-init=\"thumbnail\" data-file-id=\"").append(fileOrDirectory.getId()).append("\""); |
3402 |
15 Jun 15 |
nicklas |
70 |
sb.append(">"); |
3399 |
15 Jun 15 |
nicklas |
71 |
value = sb.toString(); |
3399 |
15 Jun 15 |
nicklas |
72 |
} |
3399 |
15 Jun 15 |
nicklas |
73 |
return value; |
3399 |
15 Jun 15 |
nicklas |
74 |
} |
3399 |
15 Jun 15 |
nicklas |
75 |
} |
3399 |
15 Jun 15 |
nicklas |
76 |
|
3399 |
15 Jun 15 |
nicklas |
77 |
} |