18 package org.turro.attach.zul.tree;
21 import java.text.DateFormat;
23 import org.turro.action.Contacts;
24 import org.turro.action.Plugins;
25 import org.turro.attach.db.AttachPU;
26 import org.turro.attach.entity.Attachment;
27 import org.turro.attach.zul.PreviewButton;
28 import org.turro.command.Command;
29 import org.turro.command.Context;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.elephant.util.ZkossUtils;
32 import org.turro.i18n.I_;
33 import org.turro.jpa.DaoTransaction;
34 import org.turro.log.SystemLogType;
35 import org.turro.log.SystemLogger;
36 import org.turro.plugin.contacts.IContact;
37 import org.turro.plugin.tagit.TagItCtrl;
38 import org.turro.zkoss.dialog.InputDialog;
39 import org.turro.zkoss.dialog.InputField;
40 import org.zkoss.zk.ui.Component;
41 import org.zkoss.zk.ui.ext.AfterCompose;
42 import org.zkoss.zul.Filedownload;
43 import org.zkoss.zul.Space;
44 import org.zkoss.zul.Treecell;
45 import org.zkoss.zul.Treeitem;
46 import org.zkoss.zul.Treerow;
47 import org.turro.plugin.acceptance.IAcceptanceCtrl;
54 public class AttachFile extends Treeitem implements AfterCompose {
58 private Set<AttachColumn> columns;
62 this.attachment = attachment;
63 this.columns = columns;
69 setImage(getMimeImage());
73 throw new UnsupportedOperationException(
"Do not use");
77 throw new UnsupportedOperationException(
"Do not use");
81 throw new UnsupportedOperationException(
"Do not use");
91 attachment = transaction.saveObject(attachment);
93 if(
getTree().getAttachListener() !=
null) {
103 I_.
get(
"Attachment") +
" " + attachment.
getId(),
105 new InputField(
"Name", attachment.getFileName(), null, 0),
106 new InputField(
"Comment", attachment.getComment(), null, 3),
107 new InputField(
"Show key", attachment.getShowKey(), null, 0),
108 new InputField(
"Validated", attachment.isValidated(), null, 0)
111 public Object execute(Context context) {
113 if(fields.length > 0) {
115 if(
"Name".equals(f.getLabel())) {
117 }
else if(
"Comment".equals(f.getLabel())) {
119 }
else if(
"Show key".equals(f.getLabel())) {
121 }
else if(
"Validated".equals(f.getLabel())) {
125 attachment =
new AttachPU().saveObject(attachment);
126 addCells(
getTree().getColumns());
127 setImage(getMimeImage());
134 public void doDelete() throws InterruptedException {
137 public Object execute(Context context) {
139 if(
getTree().getAttachListener() !=
null) {
155 private String getMimeImage() {
157 return "/_internal/system/mime/empty.png";
163 private void addCells(Set<AttachColumn> columns) {
166 row.setDraggable(
"true");
169 row.getChildren().clear();
171 Treecell cell =
new Treecell(attachment.
getFileName());
172 PreviewButton ap =
new PreviewButton(attachment);
173 cell.appendChild(ap);
175 cell.setStyle(
"font-style:oblique;color:gray");
177 if(!
getTree().isOnlyDownload()) {
178 cell.appendChild(
new Space());
179 IAcceptanceCtrl accept = (IAcceptanceCtrl) Plugins.loadImplementation(IAcceptanceCtrl.class);
180 accept.setEntity(attachment);
181 cell.appendChild((Component) accept);
182 cell.appendChild(
new Space());
183 TagItCtrl tagIt = Plugins.loadImplementation(TagItCtrl.class,
"button");
184 tagIt.setEntity(attachment);
185 if(tagIt instanceof AfterCompose) {
186 ((AfterCompose) tagIt).afterCompose();
188 cell.appendChild((Component) tagIt);
190 row.appendChild(cell);
191 if(columns.contains(AttachColumn.ATTACH_SIZE)) {
192 row.appendChild(
new Treecell(
new org.amic.util.string.BytesFormatter(attachment.
getFileSize()).toString()));
194 if(columns.contains(AttachColumn.ATTACH_DATE)) {
195 DateFormat df = DateFormat.getDateInstance();
196 row.appendChild(
new Treecell(df.format(attachment.
getModification())));
198 if(columns.contains(AttachColumn.ATTACH_VALIDATED)) {
200 row.appendChild(
new Treecell(
"",
"/_internal/system/images/actions/ok.png"));
202 row.appendChild(
new Treecell(
""));
205 if(columns.contains(AttachColumn.ATTACH_OWNER)) {
206 IContact contact = Contacts.getContact();
207 if(contact !=
null) {
208 contact.loadByLogin(attachment.
getOwner());
209 row.appendChild(
new Treecell(contact.getName()));
static< T > T loadImplementation(Class< T > jclass)
void setShowKey(String showKey)
void setValidated(boolean validated)
void setComment(String comment)
void setFileName(String fileName)
AttachContent getAttachContent()
String getFileContentType()
String getFileExtension()
Attachment getAttachment()
AttachFile(String label, Object value)
AttachFile(Attachment attachment, Set< AttachColumn > columns)
AttachListener getAttachListener()
static String getRealPath(String path)
static void confirmDeletion(String message, Command command)
static String get(String msg)
void deleteObject(Object obj)
static ISystemLogger getInstance()
void downloadDone(AttachFile file)
void deleteDone(AttachFile file)
void doLog(SystemLogType type, Object entity, String comment, Serializable data)
void setEntity(Object entity)