Asset AttachFile: captions can now be added to the fileattachmenttable
git-svn-id: https://svn.libreccm.org/ccm/trunk@3361 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
93bf5882cc
commit
aa3758cb9b
|
|
@ -8,3 +8,13 @@ cms.contentassets.file_attachment.tableheader_description=Description
|
||||||
cms.contentassets.file_attachment.list_label=File attachments
|
cms.contentassets.file_attachment.list_label=File attachments
|
||||||
cms.contentassets.file_attachment.already_attached=A file with the name {0} as already been attached.
|
cms.contentassets.file_attachment.already_attached=A file with the name {0} as already been attached.
|
||||||
cms.contentassets.file_attachment.cancelled=Cancelled
|
cms.contentassets.file_attachment.cancelled=Cancelled
|
||||||
|
cms.contentassets.file_attachment.caption=caption
|
||||||
|
cms.contentassets.file_attachment.file=file
|
||||||
|
cms.contentassets.file_attachment.table.edit_attached_file=\u270d
|
||||||
|
#Beschreibung/Zwischentitel:
|
||||||
|
cms.contentassets.file_attachment.caption_or_description=description/caption:
|
||||||
|
cms.contentassets.file_attachment.upload_new_caption=add a caption
|
||||||
|
cms.contentassets.file_attachment.table_edit=edit
|
||||||
|
cms.contentassets.file_attachment.table_up=up
|
||||||
|
cms.contentassets.file_attachment.table_down=down
|
||||||
|
cms.contentassets.file_attachment.table_delete=delete
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,12 @@ cms.contentassets.file_attachment.tableheader_description=Beschreibung
|
||||||
cms.contentassets.file_attachment.list_label=Dateianh\u00e4nge
|
cms.contentassets.file_attachment.list_label=Dateianh\u00e4nge
|
||||||
cms.contentassets.file_attachment.already_attached=Eine Datei mit dem Namen {0} wurde bereits hinzugef\u00fcgt.
|
cms.contentassets.file_attachment.already_attached=Eine Datei mit dem Namen {0} wurde bereits hinzugef\u00fcgt.
|
||||||
cms.contentassets.file_attachment.cancelled=Abgebrochen
|
cms.contentassets.file_attachment.cancelled=Abgebrochen
|
||||||
|
cms.contentassets.file_attachment.caption=Zwischentitel
|
||||||
|
cms.contentassets.file_attachment.file=Datei
|
||||||
|
cms.contentassets.file_attachment.table.edit_attached_file=\u270d
|
||||||
|
cms.contentassets.file_attachment.caption_or_description=Beschreibung/Zwischentitel:
|
||||||
|
cms.contentassets.file_attachment.upload_new_caption=Zwischentitel hinzuf\u00fcgen
|
||||||
|
cms.contentassets.file_attachment.table_edit=bearbeiten
|
||||||
|
cms.contentassets.file_attachment.table_up=nach oben
|
||||||
|
cms.contentassets.file_attachment.table_down=nach unten
|
||||||
|
cms.contentassets.file_attachment.table_delete=l\u00f6schen
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ public class FileAttachmentModelBuilder extends AbstractTableModelBuilder {
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public Object getElementAt(int columnIndex) {
|
public Object getElementAt(int columnIndex) {
|
||||||
if (columnIndex == 4) {
|
if (columnIndex == 1) {
|
||||||
if(FileAttachment.getConfig().isShowAssetIDEnabled()){
|
if(FileAttachment.getConfig().isShowAssetIDEnabled()){
|
||||||
// TODO provide API for asset URL
|
// TODO provide API for asset URL
|
||||||
ParameterMap params = new ParameterMap();
|
ParameterMap params = new ParameterMap();
|
||||||
|
|
@ -135,9 +135,11 @@ public class FileAttachmentModelBuilder extends AbstractTableModelBuilder {
|
||||||
.there(Service.getURL()+"/download/asset", params )
|
.there(Service.getURL()+"/download/asset", params )
|
||||||
.getURL();
|
.getURL();
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
return _file.getDescription();
|
return _file.getDescription();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
}else{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ package com.arsdigita.cms.contentassets.ui;
|
||||||
|
|
||||||
import com.arsdigita.bebop.ColumnPanel;
|
import com.arsdigita.bebop.ColumnPanel;
|
||||||
import com.arsdigita.bebop.Form;
|
import com.arsdigita.bebop.Form;
|
||||||
|
import com.arsdigita.bebop.FormData;
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
import com.arsdigita.bebop.Label;
|
import com.arsdigita.bebop.Label;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
|
|
@ -39,11 +40,10 @@ import com.arsdigita.persistence.DataCollection;
|
||||||
import com.arsdigita.persistence.DataObject;
|
import com.arsdigita.persistence.DataObject;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A form for uploading file attachments. Displays a mime-type selection box.
|
* A form for uploading file attachments. Displays a mime-type selection box.
|
||||||
*
|
*
|
||||||
|
|
@ -52,7 +52,7 @@ import java.io.IOException;
|
||||||
* @version $Id: FileAttachmentUpload.java 287 2005-02-22 00:29:02Z sskracic $
|
* @version $Id: FileAttachmentUpload.java 287 2005-02-22 00:29:02Z sskracic $
|
||||||
*/
|
*/
|
||||||
public class FileAttachmentUpload extends Form
|
public class FileAttachmentUpload extends Form
|
||||||
implements FormInitListener, FormProcessListener, FormValidationListener {
|
implements FormInitListener, FormProcessListener, FormValidationListener {
|
||||||
|
|
||||||
private static final Logger s_log = Logger.getLogger(FileAttachmentUpload.class);
|
private static final Logger s_log = Logger.getLogger(FileAttachmentUpload.class);
|
||||||
|
|
||||||
|
|
@ -60,12 +60,13 @@ public class FileAttachmentUpload extends Form
|
||||||
private TextArea m_description;
|
private TextArea m_description;
|
||||||
private ItemSelectionModel m_itemModel;
|
private ItemSelectionModel m_itemModel;
|
||||||
private SaveCancelSection m_saveCancelSection;
|
private SaveCancelSection m_saveCancelSection;
|
||||||
|
private TextArea m_captionText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new FileAttachmentUpload
|
* Construct a new FileAttachmentUpload
|
||||||
*
|
*
|
||||||
* @param itemModel The {@link ItemSelectionModel} which will be responsible for loading the
|
* @param itemModel The {@link ItemSelectionModel} which will be responsible
|
||||||
* current item
|
* for loading the current item
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public FileAttachmentUpload(ItemSelectionModel itemModel) {
|
public FileAttachmentUpload(ItemSelectionModel itemModel) {
|
||||||
|
|
@ -131,22 +132,28 @@ public class FileAttachmentUpload extends Form
|
||||||
// Add the widgets
|
// Add the widgets
|
||||||
public void addWidgets() {
|
public void addWidgets() {
|
||||||
m_fileUploadSection = new FileUploadSection(FileAttachmentGlobalize.FileTypeLabel(),
|
m_fileUploadSection = new FileUploadSection(FileAttachmentGlobalize.FileTypeLabel(),
|
||||||
"file",
|
"file",
|
||||||
ImageMimeType.MIME_IMAGE_JPEG);
|
ImageMimeType.MIME_IMAGE_JPEG);
|
||||||
m_fileUploadSection.getFileUploadWidget()
|
m_fileUploadSection.getFileUploadWidget()
|
||||||
.addValidationListener(new NotNullValidationListener());
|
.addValidationListener(new NotNullValidationListener());
|
||||||
add(m_fileUploadSection, ColumnPanel.INSERT);
|
add(m_fileUploadSection, ColumnPanel.INSERT);
|
||||||
|
|
||||||
m_description = new TextArea("description");
|
m_description = new TextArea("description");
|
||||||
m_description.setRows(5);
|
m_description.setRows(5);
|
||||||
m_description.setCols(60);
|
m_description.setCols(60);
|
||||||
add(new Label(GlobalizationUtil.globalize("cms.contentassets.ui.description")));
|
add(new Label(GlobalizationUtil.globalize("cms.contentassets.ui.description")));
|
||||||
|
m_description.lock();
|
||||||
add(m_description);
|
add(m_description);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(FormSectionEvent event) throws FormProcessException {
|
public void init(FormSectionEvent fse) throws FormProcessException {
|
||||||
// Do nothing.
|
|
||||||
|
FormData data = fse.getFormData();
|
||||||
|
PageState state = fse.getPageState();
|
||||||
|
s_log.debug("Init");
|
||||||
|
m_description.setValue(state, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -154,14 +161,14 @@ public class FileAttachmentUpload extends Form
|
||||||
final PageState state = event.getPageState();
|
final PageState state = event.getPageState();
|
||||||
final ContentItem item = getContentItem(state);
|
final ContentItem item = getContentItem(state);
|
||||||
final String fileName = m_fileUploadSection.getFileName(event);
|
final String fileName = m_fileUploadSection.getFileName(event);
|
||||||
|
|
||||||
final DataCollection attachments = FileAttachment.getAttachments(item);
|
final DataCollection attachments = FileAttachment.getAttachments(item);
|
||||||
|
|
||||||
while (attachments.next()) {
|
while (attachments.next()) {
|
||||||
final DataObject attachment = attachments.getDataObject();
|
final DataObject attachment = attachments.getDataObject();
|
||||||
if (attachment.get(FileAttachment.NAME).equals(fileName)) {
|
if (attachment.get(FileAttachment.NAME).equals(fileName)) {
|
||||||
attachments.close();
|
attachments.close();
|
||||||
throw new FormProcessException(FileAttachmentGlobalizationUtil.globalize(
|
throw new FormProcessException(FileAttachmentGlobalizationUtil.globalize(
|
||||||
"cms.contentassets.file_attachment.already_attached", new String[]{fileName}));
|
"cms.contentassets.file_attachment.already_attached", new String[]{fileName}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
attachments.close();
|
attachments.close();
|
||||||
|
|
@ -175,34 +182,25 @@ public class FileAttachmentUpload extends Form
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
final PageState state = event.getPageState();
|
||||||
final ContentItem item = getContentItem(state);
|
final ContentItem item = getContentItem(state);
|
||||||
|
|
||||||
// try {
|
|
||||||
// Get the text asset or create a new one
|
// Get the text asset or create a new one
|
||||||
final String fileName = m_fileUploadSection.getFileName(event);
|
|
||||||
final File file = m_fileUploadSection.getFile(event);
|
|
||||||
final FileAttachment attachment = new FileAttachment();
|
final FileAttachment attachment = new FileAttachment();
|
||||||
|
final File file = m_fileUploadSection.getFile(event);
|
||||||
|
final String fileName = m_fileUploadSection.getFileName(event);
|
||||||
|
|
||||||
// Load the asset from file
|
try {
|
||||||
attachment.setFileOwner(item);
|
attachment.loadFromFile(fileName, file, "application/octet-stream");
|
||||||
try {
|
} catch (IOException ex) {
|
||||||
attachment.loadFromFile(fileName, file, "application/octet-stream");
|
throw new FormProcessException(ex);
|
||||||
} catch (IOException ex) {
|
}
|
||||||
throw new FormProcessException(ex);
|
|
||||||
}
|
|
||||||
attachment.setDescription((String) m_description.getValue(state));
|
attachment.setDescription((String) m_description.getValue(state));
|
||||||
|
attachment.setFileOwner(item);
|
||||||
attachment.save();
|
attachment.save();
|
||||||
|
|
||||||
item.save();
|
item.save();
|
||||||
|
|
||||||
// Save everything
|
// Save everything
|
||||||
this.setFileAttachment(state);
|
this.setFileAttachment(state);
|
||||||
DispatcherHelper.cacheDisable(state.getResponse());
|
DispatcherHelper.cacheDisable(state.getResponse());
|
||||||
s_log.debug("File Uploaded");
|
s_log.debug("File Uploaded");
|
||||||
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// throw new FormProcessException(e);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import com.arsdigita.cms.ContentItem;
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
import com.arsdigita.cms.contentassets.FileAttachment;
|
import com.arsdigita.cms.contentassets.FileAttachment;
|
||||||
import com.arsdigita.cms.contentassets.FileAttachmentGlobalize;
|
import com.arsdigita.cms.contentassets.FileAttachmentGlobalize;
|
||||||
|
import com.arsdigita.cms.contentassets.util.FileAttachmentGlobalizationUtil;
|
||||||
import com.arsdigita.cms.ui.CMSContainer;
|
import com.arsdigita.cms.ui.CMSContainer;
|
||||||
import com.arsdigita.cms.ui.SecurityPropertyEditor;
|
import com.arsdigita.cms.ui.SecurityPropertyEditor;
|
||||||
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
|
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
|
||||||
|
|
@ -47,14 +48,13 @@ public class FileAttachmentsStep extends SecurityPropertyEditor {
|
||||||
|
|
||||||
private final ItemSelectionModel m_item;
|
private final ItemSelectionModel m_item;
|
||||||
private final AuthoringKitWizard m_parent;
|
private final AuthoringKitWizard m_parent;
|
||||||
|
|
||||||
private CMSContainer m_display;
|
private CMSContainer m_display;
|
||||||
private FileAttachmentsTable m_fileList;
|
private FileAttachmentsTable m_fileList;
|
||||||
private FileAttachmentUpload m_uploadForm;
|
private FileAttachmentUpload m_uploadForm;
|
||||||
|
private FileCaptionForm m_captionForm;
|
||||||
private BigDecimalParameter m_fileParam = new BigDecimalParameter("fa");
|
private BigDecimalParameter m_fileParam = new BigDecimalParameter("fa");
|
||||||
private FileAttachmentSelectionModel m_fileModel =
|
private FileAttachmentSelectionModel m_fileModel
|
||||||
new FileAttachmentSelectionModel(m_fileParam);
|
= new FileAttachmentSelectionModel(m_fileParam);
|
||||||
private Submit m_cancel;
|
private Submit m_cancel;
|
||||||
private Form m_dcForm;
|
private Form m_dcForm;
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ public class FileAttachmentsStep extends SecurityPropertyEditor {
|
||||||
* @param parent
|
* @param parent
|
||||||
*/
|
*/
|
||||||
public FileAttachmentsStep(ItemSelectionModel itemModel,
|
public FileAttachmentsStep(ItemSelectionModel itemModel,
|
||||||
AuthoringKitWizard parent) {
|
AuthoringKitWizard parent) {
|
||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
m_item = itemModel;
|
m_item = itemModel;
|
||||||
|
|
||||||
|
|
@ -73,22 +73,22 @@ public class FileAttachmentsStep extends SecurityPropertyEditor {
|
||||||
//Main label
|
//Main label
|
||||||
Label mainLabel = new Label(FileAttachmentGlobalize.NoFilesAssociatedMsg());
|
Label mainLabel = new Label(FileAttachmentGlobalize.NoFilesAssociatedMsg());
|
||||||
mainLabel.setFontWeight(Label.ITALIC);
|
mainLabel.setFontWeight(Label.ITALIC);
|
||||||
mainLabel.addPrintListener( new PrintListener() {
|
mainLabel.addPrintListener(new PrintListener() {
|
||||||
public void prepare(PrintEvent event) {
|
public void prepare(PrintEvent event) {
|
||||||
PageState state = event.getPageState();
|
PageState state = event.getPageState();
|
||||||
ContentItem item = (ContentItem) m_item.getSelectedObject(state);
|
ContentItem item = (ContentItem) m_item.getSelectedObject(state);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
DataCollection files = FileAttachment.getAttachments(item);
|
DataCollection files = FileAttachment.getAttachments(item);
|
||||||
Label mainTarget = (Label) event.getTarget();
|
Label mainTarget = (Label) event.getTarget();
|
||||||
if (files.isEmpty()) {
|
if (files.isEmpty()) {
|
||||||
mainTarget.setLabel(
|
mainTarget.setLabel(
|
||||||
FileAttachmentGlobalize.NoFilesAssociatedMsg());
|
FileAttachmentGlobalize.NoFilesAssociatedMsg());
|
||||||
} else {
|
} else {
|
||||||
mainTarget.setLabel("");
|
mainTarget.setLabel("");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
m_display.add(mainLabel);
|
m_display.add(mainLabel);
|
||||||
m_display.add(m_fileList);
|
m_display.add(m_fileList);
|
||||||
setDisplayComponent(m_display);
|
setDisplayComponent(m_display);
|
||||||
|
|
@ -96,17 +96,25 @@ public class FileAttachmentsStep extends SecurityPropertyEditor {
|
||||||
// The upload form.
|
// The upload form.
|
||||||
m_uploadForm = new FileAttachmentUpload(m_item);
|
m_uploadForm = new FileAttachmentUpload(m_item);
|
||||||
add("upload",
|
add("upload",
|
||||||
FileAttachmentGlobalize.UploadNewFileLabel(),
|
FileAttachmentGlobalize.UploadNewFileLabel(),
|
||||||
new WorkflowLockedComponentAccess(m_uploadForm, m_item),
|
new WorkflowLockedComponentAccess(m_uploadForm, m_item),
|
||||||
m_uploadForm.getSaveCancelSection().getCancelButton());
|
m_uploadForm.getSaveCancelSection().getCancelButton());
|
||||||
|
|
||||||
|
// The caption form
|
||||||
|
m_captionForm = new FileCaptionForm(m_item);
|
||||||
|
add("caption",
|
||||||
|
FileAttachmentGlobalizationUtil.globalize(
|
||||||
|
"cms.contentassets.file_attachment.upload_new_caption"),
|
||||||
|
new WorkflowLockedComponentAccess(m_captionForm, m_item),
|
||||||
|
m_captionForm.getSaveCancelSection().getCancelButton());
|
||||||
|
addSecurityListener(m_captionForm);
|
||||||
|
|
||||||
// File asset metadata form.
|
// File asset metadata form.
|
||||||
Form form = new Form("faEdit");
|
Form form = new Form("faEdit");
|
||||||
Class editFormClass = FileAttachment.getConfig().getEditFormClass();
|
Class editFormClass = FileAttachment.getConfig().getEditFormClass();
|
||||||
FormSection editForm = (FormSection)
|
FormSection editForm = (FormSection) Classes.newInstance(editFormClass,
|
||||||
Classes.newInstance(editFormClass,
|
new Class[]{FileAttachmentSelectionModel.class},
|
||||||
new Class[] { FileAttachmentSelectionModel.class },
|
new Object[]{m_fileModel});
|
||||||
new Object[] { m_fileModel });
|
|
||||||
form.add(editForm);
|
form.add(editForm);
|
||||||
|
|
||||||
WorkflowLockedContainer edit = new WorkflowLockedContainer(m_item);
|
WorkflowLockedContainer edit = new WorkflowLockedContainer(m_item);
|
||||||
|
|
@ -115,11 +123,11 @@ public class FileAttachmentsStep extends SecurityPropertyEditor {
|
||||||
|
|
||||||
// Reset the editing when this component becomes visible
|
// Reset the editing when this component becomes visible
|
||||||
m_parent.getList().addActionListener(new ActionListener() {
|
m_parent.getList().addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
PageState state = event.getPageState();
|
PageState state = event.getPageState();
|
||||||
showDisplayPane(state);
|
showDisplayPane(state);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import com.arsdigita.cms.ContentItem;
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
import com.arsdigita.cms.SecurityManager;
|
import com.arsdigita.cms.SecurityManager;
|
||||||
import com.arsdigita.cms.contentassets.FileAttachment;
|
import com.arsdigita.cms.contentassets.FileAttachment;
|
||||||
|
import com.arsdigita.cms.contentassets.util.FileAttachmentGlobalizationUtil;
|
||||||
import com.arsdigita.cms.dispatcher.Utilities;
|
import com.arsdigita.cms.dispatcher.Utilities;
|
||||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
@ -38,7 +39,8 @@ import org.apache.log4j.Logger;
|
||||||
* A Table for displaying File attachments
|
* A Table for displaying File attachments
|
||||||
*
|
*
|
||||||
* @author Scott Seago (sseago@redhat.com)
|
* @author Scott Seago (sseago@redhat.com)
|
||||||
* @version $Id: FileAttachmentsTable.java 1592 2007-06-21 16:48:55Z lbcfrancois $
|
* @version $Id: FileAttachmentsTable.java 1592 2007-06-21 16:48:55Z lbcfrancois
|
||||||
|
* $
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
@ -46,12 +48,14 @@ public class FileAttachmentsTable extends Table {
|
||||||
|
|
||||||
private static final Logger s_log = Logger.getLogger(FileAttachmentsTable.class);
|
private static final Logger s_log = Logger.getLogger(FileAttachmentsTable.class);
|
||||||
|
|
||||||
public static final String[] s_tableHeaders = {"File", " ", " ", " ", "Description", " "};
|
public static final String[] s_tableHeaders = {"File", "Description/Caption", " ", " ", " ", " "};
|
||||||
|
|
||||||
private static final String DELETE_EVENT = "delete";
|
private static final String DELETE_EVENT = "delete";
|
||||||
private static final String UP_EVENT = "up";
|
private static final String UP_EVENT = "up";
|
||||||
private static final String DOWN_EVENT = "down";
|
private static final String DOWN_EVENT = "down";
|
||||||
private static final String EDIT_EVENT = "edit";
|
private static final String EDIT_EVENT = "edit";
|
||||||
|
// private static final String EDIT_EVENT = FileAttachmentGlobalizationUtil.globalize("cms.contentassets.file_attachment.table.edit_attached_file");
|
||||||
|
|
||||||
private ItemSelectionModel m_model;
|
private ItemSelectionModel m_model;
|
||||||
private FileAttachmentSelectionModel m_fileModel;
|
private FileAttachmentSelectionModel m_fileModel;
|
||||||
private RequestLocal m_size;
|
private RequestLocal m_size;
|
||||||
|
|
@ -63,9 +67,10 @@ public class FileAttachmentsTable extends Table {
|
||||||
m_fileModel = fileModel;
|
m_fileModel = fileModel;
|
||||||
setRowSelectionModel(m_fileModel);
|
setRowSelectionModel(m_fileModel);
|
||||||
getColumn(0).setCellRenderer(new FileLinkCellRenderer());
|
getColumn(0).setCellRenderer(new FileLinkCellRenderer());
|
||||||
getColumn(1).setCellRenderer(new MoveUpLinkCellRenderer());
|
//column 1 is description/caption
|
||||||
getColumn(2).setCellRenderer(new MoveDownLinkCellRenderer());
|
getColumn(2).setCellRenderer(new MoveUpLinkCellRenderer());
|
||||||
getColumn(3).setCellRenderer(new EditLinkCellRenderer());
|
getColumn(3).setCellRenderer(new MoveDownLinkCellRenderer());
|
||||||
|
getColumn(4).setCellRenderer(new EditLinkCellRenderer());
|
||||||
getColumn(5).setCellRenderer(new DeleteLinkCellRenderer());
|
getColumn(5).setCellRenderer(new DeleteLinkCellRenderer());
|
||||||
m_size = new RequestLocal();
|
m_size = new RequestLocal();
|
||||||
m_editor = new RequestLocal() {
|
m_editor = new RequestLocal() {
|
||||||
|
|
@ -73,17 +78,15 @@ public class FileAttachmentsTable extends Table {
|
||||||
public Object initialValue(PageState state) {
|
public Object initialValue(PageState state) {
|
||||||
SecurityManager sm = Utilities.getSecurityManager(state);
|
SecurityManager sm = Utilities.getSecurityManager(state);
|
||||||
ContentItem item = (ContentItem) m_model
|
ContentItem item = (ContentItem) m_model
|
||||||
.getSelectedObject(state);
|
.getSelectedObject(state);
|
||||||
Boolean val = new Boolean(sm.canAccess(
|
Boolean val = new Boolean(sm.canAccess(
|
||||||
state.getRequest(),
|
state.getRequest(),
|
||||||
SecurityManager.EDIT_ITEM,
|
SecurityManager.EDIT_ITEM,
|
||||||
item
|
item
|
||||||
));
|
));
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
setWidth("100%");
|
setWidth("100%");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,18 +132,19 @@ public class FileAttachmentsTable extends Table {
|
||||||
private class DeleteLinkCellRenderer implements TableCellRenderer {
|
private class DeleteLinkCellRenderer implements TableCellRenderer {
|
||||||
|
|
||||||
public Component getComponent(final Table table,
|
public Component getComponent(final Table table,
|
||||||
PageState state,
|
PageState state,
|
||||||
Object value,
|
Object value,
|
||||||
boolean isSelected,
|
boolean isSelected,
|
||||||
Object key,
|
Object key,
|
||||||
int row,
|
int row,
|
||||||
int column) {
|
int column) {
|
||||||
SimpleContainer sc = new SimpleContainer();
|
SimpleContainer sc = new SimpleContainer();
|
||||||
|
|
||||||
final String modKey = (String) key;
|
final String modKey = (String) key;
|
||||||
|
|
||||||
if (Boolean.TRUE.equals(m_editor.get(state))) {
|
if (Boolean.TRUE.equals(m_editor.get(state))) {
|
||||||
ControlLink delLink = new ControlLink("Delete") {
|
ControlLink delLink = new ControlLink(new Label(FileAttachmentGlobalizationUtil.globalize(
|
||||||
|
"cms.contentassets.file_attachment.table_delete"))) {
|
||||||
|
|
||||||
public void setControlEvent(PageState s) {
|
public void setControlEvent(PageState s) {
|
||||||
s.setControlEvent(table, DELETE_EVENT, modKey);
|
s.setControlEvent(table, DELETE_EVENT, modKey);
|
||||||
|
|
@ -158,12 +162,12 @@ public class FileAttachmentsTable extends Table {
|
||||||
private class EditLinkCellRenderer implements TableCellRenderer {
|
private class EditLinkCellRenderer implements TableCellRenderer {
|
||||||
|
|
||||||
public Component getComponent(final Table table,
|
public Component getComponent(final Table table,
|
||||||
PageState state,
|
PageState state,
|
||||||
Object value,
|
Object value,
|
||||||
boolean isSelected,
|
boolean isSelected,
|
||||||
Object key,
|
Object key,
|
||||||
int row,
|
int row,
|
||||||
int column) {
|
int column) {
|
||||||
SimpleContainer sc = new SimpleContainer();
|
SimpleContainer sc = new SimpleContainer();
|
||||||
|
|
||||||
final String modKey = (String) key;
|
final String modKey = (String) key;
|
||||||
|
|
@ -172,39 +176,37 @@ public class FileAttachmentsTable extends Table {
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
sc.add(new Label("edit", Label.BOLD));
|
sc.add(new Label("edit", Label.BOLD));
|
||||||
} else {
|
} else {
|
||||||
ControlLink delLink = new ControlLink("edit") {
|
ControlLink delLink = new ControlLink(new Label(FileAttachmentGlobalizationUtil.globalize(
|
||||||
|
"cms.contentassets.file_attachment.table_edit"))) {
|
||||||
|
|
||||||
public void setControlEvent(PageState s) {
|
public void setControlEvent(PageState s) {
|
||||||
s.setControlEvent(table, EDIT_EVENT, modKey);
|
s.setControlEvent(table, EDIT_EVENT, modKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
sc.add(delLink);
|
sc.add(delLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return sc;
|
return sc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MoveUpLinkCellRenderer implements TableCellRenderer {
|
private class MoveUpLinkCellRenderer implements TableCellRenderer {
|
||||||
|
|
||||||
public Component getComponent(final Table table,
|
public Component getComponent(final Table table,
|
||||||
PageState state,
|
PageState state,
|
||||||
Object value,
|
Object value,
|
||||||
boolean isSelected,
|
boolean isSelected,
|
||||||
Object key,
|
Object key,
|
||||||
int row,
|
int row,
|
||||||
int column) {
|
int column) {
|
||||||
boolean isFirst = (row == 0);
|
boolean isFirst = (row == 0);
|
||||||
SimpleContainer sc = new SimpleContainer();
|
SimpleContainer sc = new SimpleContainer();
|
||||||
|
|
||||||
final String modKey = (String) key;
|
final String modKey = (String) key;
|
||||||
|
|
||||||
if (!isFirst && Boolean.TRUE.equals(m_editor.get(state))) {
|
if (!isFirst && Boolean.TRUE.equals(m_editor.get(state))) {
|
||||||
ControlLink delLink = new ControlLink("up") {
|
ControlLink delLink = new ControlLink(new Label(FileAttachmentGlobalizationUtil.globalize(
|
||||||
|
"cms.contentassets.file_attachment.table_up"))) {
|
||||||
|
|
||||||
public void setControlEvent(PageState s) {
|
public void setControlEvent(PageState s) {
|
||||||
s.setControlEvent(table, UP_EVENT, modKey);
|
s.setControlEvent(table, UP_EVENT, modKey);
|
||||||
|
|
@ -222,16 +224,16 @@ public class FileAttachmentsTable extends Table {
|
||||||
private class MoveDownLinkCellRenderer implements TableCellRenderer {
|
private class MoveDownLinkCellRenderer implements TableCellRenderer {
|
||||||
|
|
||||||
public Component getComponent(final Table table,
|
public Component getComponent(final Table table,
|
||||||
PageState state,
|
PageState state,
|
||||||
Object value,
|
Object value,
|
||||||
boolean isSelected,
|
boolean isSelected,
|
||||||
Object key,
|
Object key,
|
||||||
int row,
|
int row,
|
||||||
int column) {
|
int column) {
|
||||||
if (m_size.get(state) == null) {
|
if (m_size.get(state) == null) {
|
||||||
m_size.set(state,
|
m_size.set(state,
|
||||||
new Long(((FileAttachmentModelBuilder.FileAttachmentTableModel) table
|
new Long(((FileAttachmentModelBuilder.FileAttachmentTableModel) table
|
||||||
.getTableModel(state)).size()));
|
.getTableModel(state)).size()));
|
||||||
}
|
}
|
||||||
boolean isLast = (row == ((Long) m_size.get(state)).intValue() - 1);
|
boolean isLast = (row == ((Long) m_size.get(state)).intValue() - 1);
|
||||||
SimpleContainer sc = new SimpleContainer();
|
SimpleContainer sc = new SimpleContainer();
|
||||||
|
|
@ -239,7 +241,8 @@ public class FileAttachmentsTable extends Table {
|
||||||
final String modKey = (String) key;
|
final String modKey = (String) key;
|
||||||
|
|
||||||
if (!isLast && Boolean.TRUE.equals(m_editor.get(state))) {
|
if (!isLast && Boolean.TRUE.equals(m_editor.get(state))) {
|
||||||
ControlLink delLink = new ControlLink("down") {
|
ControlLink delLink = new ControlLink(new Label(FileAttachmentGlobalizationUtil.globalize(
|
||||||
|
"cms.contentassets.file_attachment.table_down"))) {
|
||||||
|
|
||||||
public void setControlEvent(PageState s) {
|
public void setControlEvent(PageState s) {
|
||||||
s.setControlEvent(table, DOWN_EVENT, modKey);
|
s.setControlEvent(table, DOWN_EVENT, modKey);
|
||||||
|
|
@ -258,22 +261,22 @@ public class FileAttachmentsTable extends Table {
|
||||||
private class FileLinkCellRenderer implements TableCellRenderer {
|
private class FileLinkCellRenderer implements TableCellRenderer {
|
||||||
|
|
||||||
public Component getComponent(final Table table,
|
public Component getComponent(final Table table,
|
||||||
PageState state,
|
PageState state,
|
||||||
Object value,
|
Object value,
|
||||||
boolean isSelected,
|
boolean isSelected,
|
||||||
Object key,
|
Object key,
|
||||||
int row,
|
int row,
|
||||||
int column) {
|
int column) {
|
||||||
final String downloadKey = (String) key;
|
final String downloadKey = (String) key;
|
||||||
FileAttachment attachment = new FileAttachment(new BigDecimal(downloadKey));
|
FileAttachment attachment = new FileAttachment(new BigDecimal(downloadKey));
|
||||||
final Link link = new Link(attachment.getDisplayName(),
|
|
||||||
Utilities.getAssetURL(attachment));
|
if (attachment.getDisplayName().equals("caption")) {
|
||||||
return link;
|
Link link = new Link(" ", "item");
|
||||||
// Utilities.getAssetURL(attachment));
|
return link;
|
||||||
//return new Link(attachment.getDisplayName(),
|
}
|
||||||
// Utilities.getAssetURL(attachment));
|
|
||||||
|
return new Link(attachment.getDisplayName(),
|
||||||
|
Utilities.getAssetURL(attachment));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,211 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Open Software License v2.1
|
||||||
|
* (the "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
* http://rhea.redhat.com/licenses/osl2.1.html.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS
|
||||||
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||||
|
* implied. See the License for the specific language governing
|
||||||
|
* rights and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.contentassets.ui;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.ColumnPanel;
|
||||||
|
import com.arsdigita.bebop.Embedded;
|
||||||
|
import com.arsdigita.bebop.Form;
|
||||||
|
import com.arsdigita.bebop.FormData;
|
||||||
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.SaveCancelSection;
|
||||||
|
import com.arsdigita.bebop.event.FormInitListener;
|
||||||
|
import com.arsdigita.bebop.event.FormProcessListener;
|
||||||
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
|
import com.arsdigita.bebop.event.FormValidationListener;
|
||||||
|
import com.arsdigita.bebop.form.CheckboxGroup;
|
||||||
|
import com.arsdigita.bebop.form.DHTMLEditor;
|
||||||
|
import com.arsdigita.bebop.form.Option;
|
||||||
|
import com.arsdigita.bebop.form.RadioGroup;
|
||||||
|
import com.arsdigita.bebop.form.TextArea;
|
||||||
|
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
||||||
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
import com.arsdigita.cms.ContentItem;
|
||||||
|
import com.arsdigita.cms.ContentSection;
|
||||||
|
import com.arsdigita.cms.FileAsset;
|
||||||
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
import com.arsdigita.cms.contentassets.FileAttachment;
|
||||||
|
import com.arsdigita.cms.contentassets.FileAttachmentGlobalize;
|
||||||
|
import com.arsdigita.cms.contentassets.util.FileAttachmentGlobalizationUtil;
|
||||||
|
import com.arsdigita.cms.contenttypes.Link;
|
||||||
|
import com.arsdigita.cms.ui.FileUploadSection;
|
||||||
|
import com.arsdigita.cms.util.GlobalizationUtil;
|
||||||
|
import com.arsdigita.dispatcher.DispatcherHelper;
|
||||||
|
import com.arsdigita.mimetypes.ImageMimeType;
|
||||||
|
import com.arsdigita.mimetypes.MimeType;
|
||||||
|
import com.arsdigita.persistence.DataCollection;
|
||||||
|
import com.arsdigita.persistence.DataObject;
|
||||||
|
import com.arsdigita.persistence.OID;
|
||||||
|
import com.arsdigita.util.StringUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A form for uploading file attachments. Displays a mime-type selection box.
|
||||||
|
*
|
||||||
|
* @author Scott Seago (sseago@redhat.com)
|
||||||
|
* @version $Revision: #2 $ $DateTime: 2004/03/30 18:21:14 $
|
||||||
|
* @version $Id: FileAttachmentUpload.java 287 2005-02-22 00:29:02Z sskracic $
|
||||||
|
*/
|
||||||
|
public class FileCaptionForm extends Form
|
||||||
|
implements FormInitListener, FormProcessListener, FormValidationListener {
|
||||||
|
|
||||||
|
private static final Logger s_log = Logger.getLogger(FileAttachmentUpload.class);
|
||||||
|
|
||||||
|
private FileUploadSection m_fileUploadSection;
|
||||||
|
private TextArea m_description;
|
||||||
|
private ItemSelectionModel m_itemModel;
|
||||||
|
private SaveCancelSection m_saveCancelSection;
|
||||||
|
private Boolean isFile;
|
||||||
|
private TextArea m_captionText;
|
||||||
|
private RadioGroup m_dType;
|
||||||
|
private Option m_file;
|
||||||
|
private CheckboxGroup m_checkbox;
|
||||||
|
private DHTMLEditor content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new FileAttachmentUpload
|
||||||
|
*
|
||||||
|
* @param itemModel The {@link ItemSelectionModel} which will be responsible
|
||||||
|
* for loading the current item
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public FileCaptionForm(ItemSelectionModel itemModel) {
|
||||||
|
super("CaptionAttachmentUpload", new ColumnPanel(2));
|
||||||
|
m_itemModel = itemModel;
|
||||||
|
|
||||||
|
ColumnPanel panel = (ColumnPanel) getPanel();
|
||||||
|
panel.setBorder(false);
|
||||||
|
panel.setPadColor("#FFFFFF");
|
||||||
|
panel.setColumnWidth(1, "20%");
|
||||||
|
panel.setColumnWidth(2, "80%");
|
||||||
|
panel.setWidth("2%");
|
||||||
|
|
||||||
|
addWidgets();
|
||||||
|
|
||||||
|
m_saveCancelSection = new SaveCancelSection();
|
||||||
|
add(m_saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
|
||||||
|
|
||||||
|
addInitListener(this);
|
||||||
|
addProcessListener(this);
|
||||||
|
addValidationListener(this);
|
||||||
|
setMethod(Form.POST);
|
||||||
|
setEncType("multipart/form-data");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the item selection model used in this form
|
||||||
|
*/
|
||||||
|
public ItemSelectionModel getItemSelectionModel() {
|
||||||
|
return m_itemModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the save/cancel section for this form
|
||||||
|
*/
|
||||||
|
public SaveCancelSection getSaveCancelSection() {
|
||||||
|
return m_saveCancelSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param state The page state
|
||||||
|
*
|
||||||
|
* @return the currently selected item
|
||||||
|
*/
|
||||||
|
public ContentItem getContentItem(PageState state) {
|
||||||
|
return (ContentItem) m_itemModel.getSelectedObject(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the image asset. This will probably be done in the process listener
|
||||||
|
*
|
||||||
|
* @param state The page state
|
||||||
|
* @param asset The image asset
|
||||||
|
*/
|
||||||
|
// this may not be needed at all -- it was in the medqic code for some reason.
|
||||||
|
// we should remove if possible
|
||||||
|
public void setFileAttachment(PageState state) {
|
||||||
|
ContentItem item = getContentItem(state);
|
||||||
|
// Force the item to reload, since the assets query is cached ?
|
||||||
|
// ?
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the widgets
|
||||||
|
public void addWidgets() {
|
||||||
|
|
||||||
|
|
||||||
|
m_captionText = new TextArea("caption");
|
||||||
|
m_captionText.setCols(10);
|
||||||
|
m_captionText.setRows(1);
|
||||||
|
m_captionText.addValidationListener(new NotNullValidationListener());
|
||||||
|
m_captionText.lock();
|
||||||
|
add(new Label(FileAttachmentGlobalizationUtil.globalize(
|
||||||
|
"cms.contentassets.file_attachment.caption")));
|
||||||
|
add(m_captionText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(FormSectionEvent fse) throws FormProcessException {
|
||||||
|
|
||||||
|
FormData data = fse.getFormData();
|
||||||
|
PageState state = fse.getPageState();
|
||||||
|
s_log.debug("Init");
|
||||||
|
m_captionText.setValue(state, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate(final FormSectionEvent event) throws FormProcessException {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
// process: update the mime type and content
|
||||||
|
@Override
|
||||||
|
public void process(final FormSectionEvent event) throws FormProcessException {
|
||||||
|
s_log.debug("Uploading File");
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
final ContentItem item = getContentItem(state);
|
||||||
|
final FileAttachment attachment = new FileAttachment();
|
||||||
|
|
||||||
|
try {
|
||||||
|
attachment.setCaption();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new FormProcessException(ex);
|
||||||
|
}
|
||||||
|
attachment.setDescription((String) m_captionText.getValue(state));
|
||||||
|
|
||||||
|
attachment.setFileOwner(item);
|
||||||
|
attachment.save();
|
||||||
|
item.save();
|
||||||
|
|
||||||
|
// Save everything
|
||||||
|
this.setFileAttachment(state);
|
||||||
|
DispatcherHelper.cacheDisable(state.getResponse());
|
||||||
|
s_log.debug("File Uploaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the save/cancel section for this form
|
||||||
|
*/
|
||||||
|
public FileUploadSection getFileUploadSection() {
|
||||||
|
return m_fileUploadSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -30,7 +30,6 @@ import com.arsdigita.bebop.form.Submit;
|
||||||
import com.arsdigita.bebop.form.TextArea;
|
import com.arsdigita.bebop.form.TextArea;
|
||||||
import com.arsdigita.cms.contentassets.FileAttachment;
|
import com.arsdigita.cms.contentassets.FileAttachment;
|
||||||
import com.arsdigita.cms.contentassets.util.FileAttachmentGlobalizationUtil;
|
import com.arsdigita.cms.contentassets.util.FileAttachmentGlobalizationUtil;
|
||||||
import com.arsdigita.cms.util.GlobalizationUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form to edit the description of a file attachment. File description edit
|
* Form to edit the description of a file attachment. File description edit
|
||||||
|
|
@ -77,8 +76,9 @@ public class FileDescriptionForm extends FormSection implements
|
||||||
m_description = new TextArea("description");
|
m_description = new TextArea("description");
|
||||||
m_description.setCols(40);
|
m_description.setCols(40);
|
||||||
m_description.setRows(5);
|
m_description.setRows(5);
|
||||||
add(new Label(GlobalizationUtil
|
|
||||||
.globalize("cms.contenttypes.ui.description")));
|
add(new Label(FileAttachmentGlobalizationUtil
|
||||||
|
.globalize("cms.contentassets.file_attachment.caption_or_description")));
|
||||||
|
|
||||||
add(m_description);
|
add(m_description);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue