diff --git a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/FileAttachmentResources.properties b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/FileAttachmentResources.properties index 1301a4c56..b1a95aec0 100755 --- a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/FileAttachmentResources.properties +++ b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/FileAttachmentResources.properties @@ -8,3 +8,13 @@ cms.contentassets.file_attachment.tableheader_description=Description 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.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 diff --git a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/FileAttachmentResources_de.properties b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/FileAttachmentResources_de.properties index 4eb3510af..9633be664 100644 --- a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/FileAttachmentResources_de.properties +++ b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/FileAttachmentResources_de.properties @@ -8,3 +8,12 @@ cms.contentassets.file_attachment.tableheader_description=Beschreibung 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.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 diff --git a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentModelBuilder.java b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentModelBuilder.java index d4a60d967..5be64c4ba 100755 --- a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentModelBuilder.java +++ b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentModelBuilder.java @@ -124,7 +124,7 @@ public class FileAttachmentModelBuilder extends AbstractTableModelBuilder { **/ @Override public Object getElementAt(int columnIndex) { - if (columnIndex == 4) { + if (columnIndex == 1) { if(FileAttachment.getConfig().isShowAssetIDEnabled()){ // TODO provide API for asset URL ParameterMap params = new ParameterMap(); @@ -135,9 +135,11 @@ public class FileAttachmentModelBuilder extends AbstractTableModelBuilder { .there(Service.getURL()+"/download/asset", params ) .getURL(); }else{ + return _file.getDescription(); } - } else { + + }else{ return null; } } diff --git a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentUpload.java b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentUpload.java index 2a4956b1b..3772e5a22 100755 --- a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentUpload.java +++ b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentUpload.java @@ -16,6 +16,7 @@ package com.arsdigita.cms.contentassets.ui; import com.arsdigita.bebop.ColumnPanel; 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; @@ -39,11 +40,10 @@ import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; import java.io.File; +import java.io.IOException; import org.apache.log4j.Logger; -import java.io.IOException; - /** * 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 $ */ public class FileAttachmentUpload extends Form - implements FormInitListener, FormProcessListener, FormValidationListener { + implements FormInitListener, FormProcessListener, FormValidationListener { private static final Logger s_log = Logger.getLogger(FileAttachmentUpload.class); @@ -60,12 +60,13 @@ public class FileAttachmentUpload extends Form private TextArea m_description; private ItemSelectionModel m_itemModel; private SaveCancelSection m_saveCancelSection; + private TextArea m_captionText; /** * Construct a new FileAttachmentUpload * - * @param itemModel The {@link ItemSelectionModel} which will be responsible for loading the - * current item + * @param itemModel The {@link ItemSelectionModel} which will be responsible + * for loading the current item * */ public FileAttachmentUpload(ItemSelectionModel itemModel) { @@ -131,43 +132,49 @@ public class FileAttachmentUpload extends Form // Add the widgets public void addWidgets() { m_fileUploadSection = new FileUploadSection(FileAttachmentGlobalize.FileTypeLabel(), - "file", - ImageMimeType.MIME_IMAGE_JPEG); + "file", + ImageMimeType.MIME_IMAGE_JPEG); m_fileUploadSection.getFileUploadWidget() - .addValidationListener(new NotNullValidationListener()); + .addValidationListener(new NotNullValidationListener()); add(m_fileUploadSection, ColumnPanel.INSERT); m_description = new TextArea("description"); m_description.setRows(5); m_description.setCols(60); add(new Label(GlobalizationUtil.globalize("cms.contentassets.ui.description"))); + m_description.lock(); add(m_description); } @Override - public void init(FormSectionEvent event) throws FormProcessException { - // Do nothing. + public void init(FormSectionEvent fse) throws FormProcessException { + + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + s_log.debug("Init"); + m_description.setValue(state, null); + } - + @Override public void validate(final FormSectionEvent event) throws FormProcessException { final PageState state = event.getPageState(); final ContentItem item = getContentItem(state); final String fileName = m_fileUploadSection.getFileName(event); - final DataCollection attachments = FileAttachment.getAttachments(item); + while (attachments.next()) { final DataObject attachment = attachments.getDataObject(); if (attachment.get(FileAttachment.NAME).equals(fileName)) { attachments.close(); 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(); - + } - + // process: update the mime type and content @Override public void process(final FormSectionEvent event) throws FormProcessException { @@ -175,34 +182,25 @@ public class FileAttachmentUpload extends Form final PageState state = event.getPageState(); final ContentItem item = getContentItem(state); - -// try { // 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(); - - // Load the asset from file - attachment.setFileOwner(item); - try { - attachment.loadFromFile(fileName, file, "application/octet-stream"); - } catch (IOException ex) { - throw new FormProcessException(ex); - } - attachment.setDescription((String) m_description.getValue(state)); - attachment.save(); + final File file = m_fileUploadSection.getFile(event); + final String fileName = m_fileUploadSection.getFileName(event); + try { + attachment.loadFromFile(fileName, file, "application/octet-stream"); + } catch (IOException ex) { + throw new FormProcessException(ex); + } + attachment.setDescription((String) m_description.getValue(state)); + attachment.setFileOwner(item); + attachment.save(); item.save(); - // Save everything + // Save everything this.setFileAttachment(state); DispatcherHelper.cacheDisable(state.getResponse()); s_log.debug("File Uploaded"); - -// } catch (Exception e) { -// e.printStackTrace(); -// throw new FormProcessException(e); -// } } /** diff --git a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentsStep.java b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentsStep.java index a05e91396..2e64a8765 100755 --- a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentsStep.java +++ b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentsStep.java @@ -28,6 +28,7 @@ import com.arsdigita.cms.ContentItem; 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.ui.CMSContainer; import com.arsdigita.cms.ui.SecurityPropertyEditor; import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; @@ -47,14 +48,13 @@ public class FileAttachmentsStep extends SecurityPropertyEditor { private final ItemSelectionModel m_item; private final AuthoringKitWizard m_parent; - private CMSContainer m_display; private FileAttachmentsTable m_fileList; private FileAttachmentUpload m_uploadForm; - + private FileCaptionForm m_captionForm; private BigDecimalParameter m_fileParam = new BigDecimalParameter("fa"); - private FileAttachmentSelectionModel m_fileModel = - new FileAttachmentSelectionModel(m_fileParam); + private FileAttachmentSelectionModel m_fileModel + = new FileAttachmentSelectionModel(m_fileParam); private Submit m_cancel; private Form m_dcForm; @@ -64,7 +64,7 @@ public class FileAttachmentsStep extends SecurityPropertyEditor { * @param parent */ public FileAttachmentsStep(ItemSelectionModel itemModel, - AuthoringKitWizard parent) { + AuthoringKitWizard parent) { m_parent = parent; m_item = itemModel; @@ -73,22 +73,22 @@ public class FileAttachmentsStep extends SecurityPropertyEditor { //Main label Label mainLabel = new Label(FileAttachmentGlobalize.NoFilesAssociatedMsg()); mainLabel.setFontWeight(Label.ITALIC); - mainLabel.addPrintListener( new PrintListener() { - public void prepare(PrintEvent event) { - PageState state = event.getPageState(); - ContentItem item = (ContentItem) m_item.getSelectedObject(state); - if (item != null) { - DataCollection files = FileAttachment.getAttachments(item); - Label mainTarget = (Label) event.getTarget(); - if (files.isEmpty()) { - mainTarget.setLabel( + mainLabel.addPrintListener(new PrintListener() { + public void prepare(PrintEvent event) { + PageState state = event.getPageState(); + ContentItem item = (ContentItem) m_item.getSelectedObject(state); + if (item != null) { + DataCollection files = FileAttachment.getAttachments(item); + Label mainTarget = (Label) event.getTarget(); + if (files.isEmpty()) { + mainTarget.setLabel( FileAttachmentGlobalize.NoFilesAssociatedMsg()); - } else { - mainTarget.setLabel(""); - } + } else { + mainTarget.setLabel(""); } } - }); + } + }); m_display.add(mainLabel); m_display.add(m_fileList); setDisplayComponent(m_display); @@ -96,17 +96,25 @@ public class FileAttachmentsStep extends SecurityPropertyEditor { // The upload form. m_uploadForm = new FileAttachmentUpload(m_item); add("upload", - FileAttachmentGlobalize.UploadNewFileLabel(), - new WorkflowLockedComponentAccess(m_uploadForm, m_item), - m_uploadForm.getSaveCancelSection().getCancelButton()); + FileAttachmentGlobalize.UploadNewFileLabel(), + new WorkflowLockedComponentAccess(m_uploadForm, m_item), + 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. Form form = new Form("faEdit"); Class editFormClass = FileAttachment.getConfig().getEditFormClass(); - FormSection editForm = (FormSection) - Classes.newInstance(editFormClass, - new Class[] { FileAttachmentSelectionModel.class }, - new Object[] { m_fileModel }); + FormSection editForm = (FormSection) Classes.newInstance(editFormClass, + new Class[]{FileAttachmentSelectionModel.class}, + new Object[]{m_fileModel}); form.add(editForm); WorkflowLockedContainer edit = new WorkflowLockedContainer(m_item); @@ -115,11 +123,11 @@ public class FileAttachmentsStep extends SecurityPropertyEditor { // Reset the editing when this component becomes visible m_parent.getList().addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - PageState state = event.getPageState(); - showDisplayPane(state); - } - }); + public void actionPerformed(ActionEvent event) { + PageState state = event.getPageState(); + showDisplayPane(state); + } + }); } /** @@ -135,5 +143,5 @@ public class FileAttachmentsStep extends SecurityPropertyEditor { public ItemSelectionModel getItemSelectionModel() { return m_item; } - + } diff --git a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentsTable.java b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentsTable.java index cfb514705..de403595b 100755 --- a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentsTable.java +++ b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileAttachmentsTable.java @@ -27,6 +27,7 @@ import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.SecurityManager; import com.arsdigita.cms.contentassets.FileAttachment; +import com.arsdigita.cms.contentassets.util.FileAttachmentGlobalizationUtil; import com.arsdigita.cms.dispatcher.Utilities; import com.arsdigita.domain.DataObjectNotFoundException; import java.math.BigDecimal; @@ -38,7 +39,8 @@ import org.apache.log4j.Logger; * A Table for displaying File attachments * * @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); - 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 UP_EVENT = "up"; private static final String DOWN_EVENT = "down"; 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 FileAttachmentSelectionModel m_fileModel; private RequestLocal m_size; @@ -63,9 +67,10 @@ public class FileAttachmentsTable extends Table { m_fileModel = fileModel; setRowSelectionModel(m_fileModel); getColumn(0).setCellRenderer(new FileLinkCellRenderer()); - getColumn(1).setCellRenderer(new MoveUpLinkCellRenderer()); - getColumn(2).setCellRenderer(new MoveDownLinkCellRenderer()); - getColumn(3).setCellRenderer(new EditLinkCellRenderer()); + //column 1 is description/caption + getColumn(2).setCellRenderer(new MoveUpLinkCellRenderer()); + getColumn(3).setCellRenderer(new MoveDownLinkCellRenderer()); + getColumn(4).setCellRenderer(new EditLinkCellRenderer()); getColumn(5).setCellRenderer(new DeleteLinkCellRenderer()); m_size = new RequestLocal(); m_editor = new RequestLocal() { @@ -73,17 +78,15 @@ public class FileAttachmentsTable extends Table { public Object initialValue(PageState state) { SecurityManager sm = Utilities.getSecurityManager(state); ContentItem item = (ContentItem) m_model - .getSelectedObject(state); + .getSelectedObject(state); Boolean val = new Boolean(sm.canAccess( - state.getRequest(), - SecurityManager.EDIT_ITEM, - item + state.getRequest(), + SecurityManager.EDIT_ITEM, + item )); return val; } - }; - setWidth("100%"); } @@ -129,18 +132,19 @@ public class FileAttachmentsTable extends Table { private class DeleteLinkCellRenderer implements TableCellRenderer { public Component getComponent(final Table table, - PageState state, - Object value, - boolean isSelected, - Object key, - int row, - int column) { + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int column) { SimpleContainer sc = new SimpleContainer(); final String modKey = (String) key; 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) { s.setControlEvent(table, DELETE_EVENT, modKey); @@ -158,12 +162,12 @@ public class FileAttachmentsTable extends Table { private class EditLinkCellRenderer implements TableCellRenderer { public Component getComponent(final Table table, - PageState state, - Object value, - boolean isSelected, - Object key, - int row, - int column) { + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int column) { SimpleContainer sc = new SimpleContainer(); final String modKey = (String) key; @@ -172,39 +176,37 @@ public class FileAttachmentsTable extends Table { if (isSelected) { sc.add(new Label("edit", Label.BOLD)); } 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) { s.setControlEvent(table, EDIT_EVENT, modKey); } - }; sc.add(delLink); } - } return sc; - } - } private class MoveUpLinkCellRenderer implements TableCellRenderer { public Component getComponent(final Table table, - PageState state, - Object value, - boolean isSelected, - Object key, - int row, - int column) { + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int column) { boolean isFirst = (row == 0); SimpleContainer sc = new SimpleContainer(); final String modKey = (String) key; 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) { s.setControlEvent(table, UP_EVENT, modKey); @@ -222,16 +224,16 @@ public class FileAttachmentsTable extends Table { private class MoveDownLinkCellRenderer implements TableCellRenderer { public Component getComponent(final Table table, - PageState state, - Object value, - boolean isSelected, - Object key, - int row, - int column) { + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int column) { if (m_size.get(state) == null) { m_size.set(state, - new Long(((FileAttachmentModelBuilder.FileAttachmentTableModel) table - .getTableModel(state)).size())); + new Long(((FileAttachmentModelBuilder.FileAttachmentTableModel) table + .getTableModel(state)).size())); } boolean isLast = (row == ((Long) m_size.get(state)).intValue() - 1); SimpleContainer sc = new SimpleContainer(); @@ -239,7 +241,8 @@ public class FileAttachmentsTable extends Table { final String modKey = (String) key; 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) { s.setControlEvent(table, DOWN_EVENT, modKey); @@ -258,22 +261,22 @@ public class FileAttachmentsTable extends Table { private class FileLinkCellRenderer implements TableCellRenderer { public Component getComponent(final Table table, - PageState state, - Object value, - boolean isSelected, - Object key, - int row, - int column) { + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int column) { final String downloadKey = (String) key; FileAttachment attachment = new FileAttachment(new BigDecimal(downloadKey)); - final Link link = new Link(attachment.getDisplayName(), - Utilities.getAssetURL(attachment)); - return link; - // Utilities.getAssetURL(attachment)); - //return new Link(attachment.getDisplayName(), - // Utilities.getAssetURL(attachment)); + + if (attachment.getDisplayName().equals("caption")) { + Link link = new Link(" ", "item"); + return link; + } + + return new Link(attachment.getDisplayName(), + Utilities.getAssetURL(attachment)); } - } - } diff --git a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileCaptionForm.java b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileCaptionForm.java new file mode 100644 index 000000000..fb7080bf0 --- /dev/null +++ b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileCaptionForm.java @@ -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; + } + +} diff --git a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileDescriptionForm.java b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileDescriptionForm.java index 1e4e3572f..0a187f272 100755 --- a/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileDescriptionForm.java +++ b/ccm-cms-assets-fileattachment/src/com/arsdigita/cms/contentassets/ui/FileDescriptionForm.java @@ -30,7 +30,6 @@ import com.arsdigita.bebop.form.Submit; import com.arsdigita.bebop.form.TextArea; import com.arsdigita.cms.contentassets.FileAttachment; 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 @@ -46,7 +45,7 @@ public class FileDescriptionForm extends FormSection implements private FileAttachmentSelectionModel m_fileModel; private Submit m_cancel; - + /** * Creates a new form to edit the FileAttachment description by the item * selection model passed in. @@ -77,8 +76,9 @@ public class FileDescriptionForm extends FormSection implements m_description = new TextArea("description"); m_description.setCols(40); 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); }