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

View File

@ -50,12 +50,13 @@ import javax.servlet.ServletException;
import org.apache.log4j.Logger;
/**
* Component displays the currently attached images for an content item. It is
* part of the entry point image authoring step {@see ImageStep}.
* Component displays the currently attached images for an content item. It is part of the entry
* point image authoring step {
*
* 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.
* @see ImageStep}.
*
* 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 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 MOVEUP = "moveAttachmentUp";
private final static String MOVEDOWN = "moveAttachmentDown";
private final static String EDIT = "editAttachment";
/**
* Constructor.
@ -98,14 +100,23 @@ public class ImageStepDisplay extends SimpleContainer {
DomainObjectFactory.newInstance(OID.valueOf(ps.getControlEventValue())).delete();
// Regenerate sortkeys
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())) {
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())) {
m_listModelBuilder.getModel().move(OID.valueOf(ps.getControlEventValue()), 1, ps);
m_listModelBuilder.getModel().
move(OID.valueOf(ps.getControlEventValue()), 1, ps);
} else {
super.respond(ps);
}
}
};
imageList.setCellRenderer(new ImageListCellRenderer());
@ -126,14 +137,14 @@ public class ImageStepDisplay extends SimpleContainer {
*
* @param list
* @param ps
*
* @return
*/
@Override
public ListModel makeModel(List list, PageState ps) {
ContentItem item = m_imageStep.getItem(ps);
DataCollection attachments =
ItemImageAttachment.getImageAttachments(item);
DataCollection attachments = ItemImageAttachment.getImageAttachments(item);
attachments.addPath(ItemImageAttachment.IMAGE + "."
+ ReusableImageAsset.ID);
attachments.addPath(ItemImageAttachment.IMAGE + "."
@ -150,6 +161,7 @@ public class ImageStepDisplay extends SimpleContainer {
protected ImageListModel getModel() {
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
DomainObject sortDomainObject = DomainObjectFactory.newInstance(attachments.getDataObject());
DomainObject sortDomainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (sortDomainObject instanceof ItemImageAttachment) {
// Change the sortKey of the ItemImageAttachment to the desired
// value but respect bounds of the current list
int newSortKey = Math.max(1,
Math.min((int) attachments.size(),
((ItemImageAttachment) sortDomainObject).getSortKey() + move));
((ItemImageAttachment) sortDomainObject).
getSortKey() + move));
((ItemImageAttachment) sortDomainObject).setSortKey(newSortKey);
((ItemImageAttachment) sortDomainObject).save();
@ -237,7 +251,8 @@ public class ImageStepDisplay extends SimpleContainer {
// new postition one step in the nessecary direction
if (move < 0) {
while (attachments.previous() && move < 0) {
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.getDataObject());
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (domainObject instanceof ItemImageAttachment) {
((ItemImageAttachment) domainObject).setSortKey(
((ItemImageAttachment) domainObject).getSortKey() + 1);
@ -248,7 +263,8 @@ public class ImageStepDisplay extends SimpleContainer {
}
if (move > 0) {
while (attachments.next() && move > 0) {
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.getDataObject());
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (domainObject instanceof ItemImageAttachment) {
((ItemImageAttachment) domainObject).setSortKey(
((ItemImageAttachment) domainObject).getSortKey() - 1);
@ -280,7 +296,8 @@ public class ImageStepDisplay extends SimpleContainer {
// Iterate through all items and set item sortKey to pos
while (attachments.next()) {
pos++;
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.getDataObject());
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (domainObject instanceof ItemImageAttachment) {
int sortKey = ((ItemImageAttachment) domainObject).getSortKey();
if (sortKey != pos) {
@ -290,6 +307,7 @@ public class ImageStepDisplay extends SimpleContainer {
}
}
}
}
/**
@ -305,6 +323,7 @@ public class ImageStepDisplay extends SimpleContainer {
* @param key
* @param index
* @param isSelected
*
* @return
*/
@Override
@ -371,6 +390,7 @@ public class ImageStepDisplay extends SimpleContainer {
protected ImageAsset getImageAsset(PageState ps) {
return attachment.getImage();
}
});
/* Adds links to move and remove the image in a separate container element */
@ -395,6 +415,7 @@ public class ImageStepDisplay extends SimpleContainer {
}
exportAttributes(parent);
}
};
container.add(moveUpLink);
}
@ -420,13 +441,39 @@ public class ImageStepDisplay extends SimpleContainer {
}
exportAttributes(parent);
}
};
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(
ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.remove_attached_image"))) {
@Override
public void setControlEvent(PageState ps) {
String oid = ps.getControlEventValue();
@ -444,10 +491,13 @@ public class ImageStepDisplay extends SimpleContainer {
}
exportAttributes(parent);
}
};
container.add(deleteLink);
return container;
}
}
}