The caption of an ItemImageAttachment can now be edited (Issue #1575)

git-svn-id: https://svn.libreccm.org/ccm/trunk@2607 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2014-04-08 15:05:15 +00:00
parent 6fdc39c8d9
commit e3f40b4e7f
6 changed files with 612 additions and 473 deletions

View File

@ -5,3 +5,5 @@ cms.contentassets.ui.image_step.no_image_attached=This item does not have any as
cms.contentassets.ui.image_step.remove_attached_image=Remove image attachment cms.contentassets.ui.image_step.remove_attached_image=Remove image attachment
cms.contentassets.ui.image_step.move_attached_image_down=Move down cms.contentassets.ui.image_step.move_attached_image_down=Move down
cms.contentassets.ui.image_step.move_attached_image_up=Move up cms.contentassets.ui.image_step.move_attached_image_up=Move up
cms.contentassets.ui.image_step.edit_attached_image=Edit caption
cms.contentassets.ui.image_step.caption=Caption

View File

@ -5,3 +5,5 @@ cms.contentassets.ui.image_step.no_image_attached=Diesem Dokument ist noch kein
cms.contentassets.ui.image_step.remove_attached_image=Aus der Liste entfernen cms.contentassets.ui.image_step.remove_attached_image=Aus der Liste entfernen
cms.contentassets.ui.image_step.move_attached_image_down=Nach unten verschieben cms.contentassets.ui.image_step.move_attached_image_down=Nach unten verschieben
cms.contentassets.ui.image_step.move_attached_image_up=Nach oben verschieben cms.contentassets.ui.image_step.move_attached_image_up=Nach oben verschieben
cms.contentassets.ui.image_step.edit_attached_image=Bildunterschrift editieren
cms.contentassets.ui.image_step.caption=Bildunterschrift

View File

@ -5,3 +5,5 @@ cms.contentassets.ui.image_step.no_image_attached=This item does not have any as
cms.contentassets.ui.image_step.remove_attached_image=Remove image attachment cms.contentassets.ui.image_step.remove_attached_image=Remove image attachment
cms.contentassets.ui.image_step.move_attached_image_down=Move down cms.contentassets.ui.image_step.move_attached_image_down=Move down
cms.contentassets.ui.image_step.move_attached_image_up=Move up cms.contentassets.ui.image_step.move_attached_image_up=Move up
cms.contentassets.ui.image_step.edit_attached_image=Edit caption
cms.contentassets.ui.image_step.caption=Caption

View File

@ -0,0 +1,75 @@
package com.arsdigita.cms.contentassets.ui;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
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.FormSubmissionListener;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.cms.contentassets.ItemImageAttachment;
import com.arsdigita.cms.contentassets.util.ImageStepGlobalizationUtil;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
*/
public class ImageAttachmentEditForm extends Form
implements FormInitListener, FormProcessListener, FormSubmissionListener {
final ImageStep imageStep;
final SaveCancelSection saveCancelSection;
public ImageAttachmentEditForm(final ImageStep imageStep) {
super("ImageAttachmentEditForm");
this.imageStep = imageStep;
final Label label = new Label(ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.caption"));
final TextField captionField = new TextField(CAPTION);
add(label);
add(captionField);
saveCancelSection = new SaveCancelSection();
add(saveCancelSection);
addInitListener(this);
addProcessListener(this);
}
private static final String CAPTION = "caption";
@Override
public void init(final FormSectionEvent event) throws FormProcessException {
final ItemImageAttachment attachment = imageStep.getAttachment(event.getPageState());
event.getFormData().put(CAPTION, attachment.getCaption());
}
@Override
public void process(final FormSectionEvent event) throws FormProcessException {
final ItemImageAttachment attachment = imageStep.getAttachment(event.getPageState());
attachment.setCaption(event.getFormData().getString(CAPTION));
attachment.save();
imageStep.showDisplayPane(event.getPageState());
}
@Override
public void submitted(final FormSectionEvent event) throws FormProcessException {
if (saveCancelSection.getCancelButton().isSelected(event.getPageState())) {
imageStep.setAttachment(event.getPageState(), null);
imageStep.showDisplayPane(event.getPageState());
}
}
}

View File

@ -39,8 +39,7 @@ import java.util.Iterator;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* Pluggable authoring step as the main entry point to add an ImageAsset to a * Pluggable authoring step as the main entry point to add an ImageAsset to a content item.
* content item.
* *
* @author unknown * @author unknown
* @author Sören Bernstein <quasi@quasiweb.de> * @author Sören Bernstein <quasi@quasiweb.de>
@ -58,8 +57,7 @@ public class ImageStep extends SecurityPropertyEditor {
/** /**
* Constructor. * Constructor.
* *
* @param itemModel The {@link ItemSelectionModel} to use with this * @param itemModel The {@link ItemSelectionModel} to use with this instance
* instance
* @param parent The parent {@link AuthoringKitWizard} * @param parent The parent {@link AuthoringKitWizard}
*/ */
public ImageStep(ItemSelectionModel itemModel, public ImageStep(ItemSelectionModel itemModel,
@ -75,21 +73,23 @@ public class ImageStep extends SecurityPropertyEditor {
/* Create ImageEditStep to add images to the current item */ /* Create ImageEditStep to add images to the current item */
m_add = new ImageStepEdit(this); m_add = new ImageStepEdit(this);
WorkflowLockedComponentAccess addCA = WorkflowLockedComponentAccess addCA = new WorkflowLockedComponentAccess(m_add,
new WorkflowLockedComponentAccess(m_add, m_itemSelection); m_itemSelection);
addComponent("add", addComponent("add",
ImageStepGlobalizationUtil.globalize( ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.add_image"), "cms.contentassets.ui.image_step.add_image"),
addCA); addCA);
addComponent("edit",
new ImageAttachmentEditForm(this));
/* ImageDisplayStep to display all already attached images */ /* ImageDisplayStep to display all already attached images */
m_display = new ImageStepDisplay(this); // Component to display m_display = new ImageStepDisplay(this); // Component to display
setDisplayComponent(m_display); // all attached images. setDisplayComponent(m_display); // all attached images.
Iterator imageComponents = m_add.getImageComponents(); Iterator imageComponents = m_add.getImageComponents();
while (imageComponents.hasNext()) { while (imageComponents.hasNext()) {
ImageComponent component = ImageComponent component = (ImageComponent) imageComponents.next();
(ImageComponent) imageComponents.next();
addListeners(component.getForm(), addListeners(component.getForm(),
component.getSaveCancelSection().getCancelButton()); component.getSaveCancelSection().getCancelButton());
@ -101,6 +101,7 @@ public class ImageStep extends SecurityPropertyEditor {
PageState state = event.getPageState(); PageState state = event.getPageState();
showDisplayPane(state); showDisplayPane(state);
} }
}); });
} }
@ -136,7 +137,11 @@ public class ImageStep extends SecurityPropertyEditor {
* @return The currently selected item, null if there isn't one. * @return The currently selected item, null if there isn't one.
*/ */
public ItemImageAttachment getAttachment(PageState ps) { public ItemImageAttachment getAttachment(PageState ps) {
return (ItemImageAttachment) m_attachmentSelection.getSelectedAttachment(ps); return m_attachmentSelection.getSelectedAttachment(ps);
}
public void setAttachment(final PageState state, final ItemImageAttachment attachment) {
m_attachmentSelection.setSelectedAttachment(state, attachment);
} }
private class AttachmentSelectionModel private class AttachmentSelectionModel
@ -152,6 +157,7 @@ public class ImageStep extends SecurityPropertyEditor {
return DomainObjectFactory.newInstance(oid); return DomainObjectFactory.newInstance(oid);
} }
}; };
@Override @Override
@ -184,6 +190,7 @@ public class ImageStep extends SecurityPropertyEditor {
public ParameterModel getStateParameter() { public ParameterModel getStateParameter() {
return m_attachmentOID; return m_attachmentOID;
} }
} }
/** /**
@ -198,4 +205,5 @@ public class ImageStep extends SecurityPropertyEditor {
super.showDisplayPane(state); super.showDisplayPane(state);
m_add.reset(state); m_add.reset(state);
} }
} }

View File

@ -50,12 +50,13 @@ import javax.servlet.ServletException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* Component displays the currently attached images for an content item. It is * Component displays the currently attached images for an content item. It is part of the entry
* part of the entry point image authoring step {@see ImageStep}. * point image authoring step {
* *
* It creates a list of images including meta information (name, type, width, * @see ImageStep}.
* etc.), a link to remove from the list for each image and at the bottom a link *
* to add another image. * It creates a list of images including meta information (name, type, width, etc.), a link to
* remove from the list for each image and at the bottom a link to add another image.
* *
* @author unknown * @author unknown
* @author Sören Bernstein <quasi@quasiweb.de> * @author Sören Bernstein <quasi@quasiweb.de>
@ -74,6 +75,7 @@ public class ImageStepDisplay extends SimpleContainer {
private final static String DELETE = "deleteAttachment"; private final static String DELETE = "deleteAttachment";
private final static String MOVEUP = "moveAttachmentUp"; private final static String MOVEUP = "moveAttachmentUp";
private final static String MOVEDOWN = "moveAttachmentDown"; private final static String MOVEDOWN = "moveAttachmentDown";
private final static String EDIT = "editAttachment";
/** /**
* Constructor. * Constructor.
@ -98,14 +100,23 @@ public class ImageStepDisplay extends SimpleContainer {
DomainObjectFactory.newInstance(OID.valueOf(ps.getControlEventValue())).delete(); DomainObjectFactory.newInstance(OID.valueOf(ps.getControlEventValue())).delete();
// Regenerate sortkeys // Regenerate sortkeys
m_listModelBuilder.getModel().regenSortKeys(ps); m_listModelBuilder.getModel().regenSortKeys(ps);
} else if (EDIT.equals(ps.getControlEventName())) {
m_imageStep.setAttachment(
ps, ItemImageAttachment.retrieve(OID.valueOf(ps.
getControlEventValue())));
m_imageStep.showComponent(ps, "edit");
} else if (MOVEUP.equals(ps.getControlEventName())) { } else if (MOVEUP.equals(ps.getControlEventName())) {
m_listModelBuilder.getModel().move(OID.valueOf(ps.getControlEventValue()), -1, ps); m_listModelBuilder.getModel().move(OID.valueOf(ps.getControlEventValue()), -1,
ps);
} else if (MOVEDOWN.equals(ps.getControlEventName())) { } else if (MOVEDOWN.equals(ps.getControlEventName())) {
m_listModelBuilder.getModel().move(OID.valueOf(ps.getControlEventValue()), 1, ps); m_listModelBuilder.getModel().
move(OID.valueOf(ps.getControlEventValue()), 1, ps);
} else { } else {
super.respond(ps); super.respond(ps);
} }
} }
}; };
imageList.setCellRenderer(new ImageListCellRenderer()); imageList.setCellRenderer(new ImageListCellRenderer());
@ -126,14 +137,14 @@ public class ImageStepDisplay extends SimpleContainer {
* *
* @param list * @param list
* @param ps * @param ps
*
* @return * @return
*/ */
@Override @Override
public ListModel makeModel(List list, PageState ps) { public ListModel makeModel(List list, PageState ps) {
ContentItem item = m_imageStep.getItem(ps); ContentItem item = m_imageStep.getItem(ps);
DataCollection attachments = DataCollection attachments = ItemImageAttachment.getImageAttachments(item);
ItemImageAttachment.getImageAttachments(item);
attachments.addPath(ItemImageAttachment.IMAGE + "." attachments.addPath(ItemImageAttachment.IMAGE + "."
+ ReusableImageAsset.ID); + ReusableImageAsset.ID);
attachments.addPath(ItemImageAttachment.IMAGE + "." attachments.addPath(ItemImageAttachment.IMAGE + "."
@ -150,6 +161,7 @@ public class ImageStepDisplay extends SimpleContainer {
protected ImageListModel getModel() { protected ImageListModel getModel() {
return m_listModel; return m_listModel;
} }
} }
/** /**
@ -222,14 +234,16 @@ public class ImageStepDisplay extends SimpleContainer {
} }
// Get the image to move and test if it is really an ItemImageAttachment // Get the image to move and test if it is really an ItemImageAttachment
DomainObject sortDomainObject = DomainObjectFactory.newInstance(attachments.getDataObject()); DomainObject sortDomainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (sortDomainObject instanceof ItemImageAttachment) { if (sortDomainObject instanceof ItemImageAttachment) {
// Change the sortKey of the ItemImageAttachment to the desired // Change the sortKey of the ItemImageAttachment to the desired
// value but respect bounds of the current list // value but respect bounds of the current list
int newSortKey = Math.max(1, int newSortKey = Math.max(1,
Math.min((int) attachments.size(), Math.min((int) attachments.size(),
((ItemImageAttachment) sortDomainObject).getSortKey() + move)); ((ItemImageAttachment) sortDomainObject).
getSortKey() + move));
((ItemImageAttachment) sortDomainObject).setSortKey(newSortKey); ((ItemImageAttachment) sortDomainObject).setSortKey(newSortKey);
((ItemImageAttachment) sortDomainObject).save(); ((ItemImageAttachment) sortDomainObject).save();
@ -237,7 +251,8 @@ public class ImageStepDisplay extends SimpleContainer {
// new postition one step in the nessecary direction // new postition one step in the nessecary direction
if (move < 0) { if (move < 0) {
while (attachments.previous() && move < 0) { while (attachments.previous() && move < 0) {
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.getDataObject()); DomainObject domainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (domainObject instanceof ItemImageAttachment) { if (domainObject instanceof ItemImageAttachment) {
((ItemImageAttachment) domainObject).setSortKey( ((ItemImageAttachment) domainObject).setSortKey(
((ItemImageAttachment) domainObject).getSortKey() + 1); ((ItemImageAttachment) domainObject).getSortKey() + 1);
@ -248,7 +263,8 @@ public class ImageStepDisplay extends SimpleContainer {
} }
if (move > 0) { if (move > 0) {
while (attachments.next() && move > 0) { while (attachments.next() && move > 0) {
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.getDataObject()); DomainObject domainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (domainObject instanceof ItemImageAttachment) { if (domainObject instanceof ItemImageAttachment) {
((ItemImageAttachment) domainObject).setSortKey( ((ItemImageAttachment) domainObject).setSortKey(
((ItemImageAttachment) domainObject).getSortKey() - 1); ((ItemImageAttachment) domainObject).getSortKey() - 1);
@ -280,7 +296,8 @@ public class ImageStepDisplay extends SimpleContainer {
// Iterate through all items and set item sortKey to pos // Iterate through all items and set item sortKey to pos
while (attachments.next()) { while (attachments.next()) {
pos++; pos++;
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.getDataObject()); DomainObject domainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (domainObject instanceof ItemImageAttachment) { if (domainObject instanceof ItemImageAttachment) {
int sortKey = ((ItemImageAttachment) domainObject).getSortKey(); int sortKey = ((ItemImageAttachment) domainObject).getSortKey();
if (sortKey != pos) { if (sortKey != pos) {
@ -290,6 +307,7 @@ public class ImageStepDisplay extends SimpleContainer {
} }
} }
} }
} }
/** /**
@ -305,6 +323,7 @@ public class ImageStepDisplay extends SimpleContainer {
* @param key * @param key
* @param index * @param index
* @param isSelected * @param isSelected
*
* @return * @return
*/ */
@Override @Override
@ -371,6 +390,7 @@ public class ImageStepDisplay extends SimpleContainer {
protected ImageAsset getImageAsset(PageState ps) { protected ImageAsset getImageAsset(PageState ps) {
return attachment.getImage(); return attachment.getImage();
} }
}); });
/* Adds links to move and remove the image in a separate container element */ /* Adds links to move and remove the image in a separate container element */
@ -395,6 +415,7 @@ public class ImageStepDisplay extends SimpleContainer {
} }
exportAttributes(parent); exportAttributes(parent);
} }
}; };
container.add(moveUpLink); container.add(moveUpLink);
} }
@ -420,13 +441,39 @@ public class ImageStepDisplay extends SimpleContainer {
} }
exportAttributes(parent); exportAttributes(parent);
} }
}; };
container.add(moveDownLink); container.add(moveDownLink);
} }
ControlLink editLink = new ControlLink(new Label(
ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.edit_attached_image"))) {
@Override
public void setControlEvent(final PageState state) {
final String oid = state.getControlEventValue();
state.setControlEvent(list, EDIT, oid);
}
@Override
public void generateURL(final PageState state, Element parent) {
setControlEvent(state);
try {
parent.addAttribute("href", state.stateAsURL());
} catch (IOException ex) {
parent.addAttribute("href", "");
}
}
};
container.add(editLink);
ControlLink deleteLink = new ControlLink(new Label( ControlLink deleteLink = new ControlLink(new Label(
ImageStepGlobalizationUtil.globalize( ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.remove_attached_image"))) { "cms.contentassets.ui.image_step.remove_attached_image"))) {
@Override @Override
public void setControlEvent(PageState ps) { public void setControlEvent(PageState ps) {
String oid = ps.getControlEventValue(); String oid = ps.getControlEventValue();
@ -444,10 +491,13 @@ public class ImageStepDisplay extends SimpleContainer {
} }
exportAttributes(parent); exportAttributes(parent);
} }
}; };
container.add(deleteLink); container.add(deleteLink);
return container; return container;
} }
} }
} }