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,163 +39,171 @@ 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>
*/
public class ImageStep extends SecurityPropertyEditor {
private static final Logger s_log = Logger.getLogger(ImageStep.class);
private final ItemSelectionModel m_itemSelection;
private final AttachmentSelectionModel m_attachmentSelection;
private final AuthoringKitWizard m_parent;
private final ImageStepDisplay m_display;
private final ImageStepEdit m_add;
private final OIDParameter m_attachmentOID;
private static final Logger s_log = Logger.getLogger(ImageStep.class);
private final ItemSelectionModel m_itemSelection;
private final AttachmentSelectionModel m_attachmentSelection;
private final AuthoringKitWizard m_parent;
private final ImageStepDisplay m_display;
private final ImageStepEdit m_add;
private final OIDParameter m_attachmentOID;
/**
* Constructor.
*
* @param itemModel The {@link ItemSelectionModel} to use with this
* instance
* @param parent The parent {@link AuthoringKitWizard}
*/
public ImageStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
super();
/**
* Constructor.
*
* @param itemModel The {@link ItemSelectionModel} to use with this instance
* @param parent The parent {@link AuthoringKitWizard}
*/
public ImageStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
super();
m_itemSelection = itemModel;
m_parent = parent;
m_itemSelection = itemModel;
m_parent = parent;
m_attachmentOID = new OIDParameter("attachmentID");
m_attachmentSelection = new AttachmentSelectionModel();
m_attachmentOID = new OIDParameter("attachmentID");
m_attachmentSelection = new AttachmentSelectionModel();
/* Create ImageEditStep to add images to the current item */
m_add = new ImageStepEdit(this);
WorkflowLockedComponentAccess addCA =
new WorkflowLockedComponentAccess(m_add, m_itemSelection);
addComponent("add",
ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.add_image"),
addCA);
/* Create ImageEditStep to add images to the current item */
m_add = new ImageStepEdit(this);
WorkflowLockedComponentAccess addCA = new WorkflowLockedComponentAccess(m_add,
m_itemSelection);
addComponent("add",
ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.add_image"),
addCA);
/* ImageDisplayStep to display all already attached images */
m_display = new ImageStepDisplay(this); // Component to display
setDisplayComponent(m_display); // all attached images.
addComponent("edit",
new ImageAttachmentEditForm(this));
Iterator imageComponents = m_add.getImageComponents();
while (imageComponents.hasNext()) {
ImageComponent component =
(ImageComponent) imageComponents.next();
/* ImageDisplayStep to display all already attached images */
m_display = new ImageStepDisplay(this); // Component to display
setDisplayComponent(m_display); // all attached images.
addListeners(component.getForm(),
component.getSaveCancelSection().getCancelButton());
}
Iterator imageComponents = m_add.getImageComponents();
while (imageComponents.hasNext()) {
ImageComponent component = (ImageComponent) imageComponents.next();
m_parent.getList().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
PageState state = event.getPageState();
showDisplayPane(state);
}
});
}
addListeners(component.getForm(),
component.getSaveCancelSection().getCancelButton());
}
@Override
public void register(Page p) {
super.register(p);
m_parent.getList().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
PageState state = event.getPageState();
showDisplayPane(state);
}
p.addComponentStateParam(this, m_attachmentOID);
}
});
}
/**
* @return the parent wizard
*/
public AuthoringKitWizard getParentWizard() {
return m_parent;
}
@Override
public void register(Page p) {
super.register(p);
/**
* @return The item selection model
*/
public ItemSelectionModel getItemSelectionModel() {
return m_itemSelection;
}
p.addComponentStateParam(this, m_attachmentOID);
}
/**
* @return The currently selected item, null if there isn't one.
*/
public ContentItem getItem(PageState ps) {
return m_itemSelection.getSelectedItem(ps);
}
/**
* @return the parent wizard
*/
public AuthoringKitWizard getParentWizard() {
return m_parent;
}
/**
* @return The currently selected item, null if there isn't one.
*/
public ItemImageAttachment getAttachment(PageState ps) {
return (ItemImageAttachment) m_attachmentSelection.getSelectedAttachment(ps);
}
/**
* @return The item selection model
*/
public ItemSelectionModel getItemSelectionModel() {
return m_itemSelection;
}
private class AttachmentSelectionModel
extends AbstractSingleSelectionModel {
/**
* @return The currently selected item, null if there isn't one.
*/
public ContentItem getItem(PageState ps) {
return m_itemSelection.getSelectedItem(ps);
}
private final RequestLocal m_attachment = new RequestLocal() {
@Override
protected Object initialValue(PageState ps) {
OID oid = (OID) getSelectedKey(ps);
if (null == oid) {
return null;
}
/**
* @return The currently selected item, null if there isn't one.
*/
public ItemImageAttachment getAttachment(PageState ps) {
return m_attachmentSelection.getSelectedAttachment(ps);
}
return DomainObjectFactory.newInstance(oid);
}
};
public void setAttachment(final PageState state, final ItemImageAttachment attachment) {
m_attachmentSelection.setSelectedAttachment(state, attachment);
}
@Override
public Object getSelectedKey(PageState ps) {
OID oid = (OID) ps.getValue(m_attachmentOID);
if (null == oid) {
return null;
}
private class AttachmentSelectionModel
extends AbstractSingleSelectionModel {
return oid;
}
private final RequestLocal m_attachment = new RequestLocal() {
@Override
protected Object initialValue(PageState ps) {
OID oid = (OID) getSelectedKey(ps);
if (null == oid) {
return null;
}
@Override
public void setSelectedKey(PageState ps, Object oid) {
m_attachment.set(ps, null);
ps.setValue(m_attachmentOID, oid);
}
return DomainObjectFactory.newInstance(oid);
}
public ItemImageAttachment getSelectedAttachment(PageState ps) {
return (ItemImageAttachment) m_attachment.get(ps);
}
};
public void setSelectedAttachment(PageState ps,
ItemImageAttachment attachment) {
setSelectedKey(ps, attachment);
m_attachment.set(ps, attachment);
}
@Override
public Object getSelectedKey(PageState ps) {
OID oid = (OID) ps.getValue(m_attachmentOID);
if (null == oid) {
return null;
}
@Override
public ParameterModel getStateParameter() {
return m_attachmentOID;
}
}
return oid;
}
@Override
public void setSelectedKey(PageState ps, Object oid) {
m_attachment.set(ps, null);
ps.setValue(m_attachmentOID, oid);
}
public ItemImageAttachment getSelectedAttachment(PageState ps) {
return (ItemImageAttachment) m_attachment.get(ps);
}
public void setSelectedAttachment(PageState ps,
ItemImageAttachment attachment) {
setSelectedKey(ps, attachment);
m_attachment.set(ps, attachment);
}
@Override
public ParameterModel getStateParameter() {
return m_attachmentOID;
}
}
/**
* Show display pane.
*
* Also, reset the forms for reuse.
*
* @param state
*/
@Override
public void showDisplayPane(PageState state) {
super.showDisplayPane(state);
m_add.reset(state);
}
/**
* Show display pane.
*
* Also, reset the forms for reuse.
*
* @param state
*/
@Override
public void showDisplayPane(PageState state) {
super.showDisplayPane(state);
m_add.reset(state);
}
}

View File

@ -50,404 +50,454 @@ 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>
*/
public class ImageStepDisplay extends SimpleContainer {
private static final Logger S_LOG = Logger.getLogger(ImageStepDisplay.class);
/**
* Represents invoking parent component
*/
private final ImageStep m_imageStep;
private ImageListModelBuilder m_listModelBuilder;
/**
* Name of the delete event
*/
private final static String DELETE = "deleteAttachment";
private final static String MOVEUP = "moveAttachmentUp";
private final static String MOVEDOWN = "moveAttachmentDown";
private static final Logger S_LOG = Logger.getLogger(ImageStepDisplay.class);
/**
* Represents invoking parent component
*/
private final ImageStep m_imageStep;
private ImageListModelBuilder m_listModelBuilder;
/**
* Name of the delete event
*/
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.
*
* @param step
*/
public ImageStepDisplay(ImageStep step) {
super();
/**
* Constructor.
*
* @param step
*/
public ImageStepDisplay(ImageStep step) {
super();
m_imageStep = step;
m_imageStep = step;
/* Message to show in case no image has been attached yet. */
Label mainLabel = new Label(ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.no_image_attached"));
mainLabel.setFontWeight(Label.ITALIC);
/* Message to show in case no image has been attached yet. */
Label mainLabel = new Label(ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.no_image_attached"));
mainLabel.setFontWeight(Label.ITALIC);
m_listModelBuilder = new ImageListModelBuilder();
List imageList = new List(m_listModelBuilder) {
@Override
public void respond(PageState ps) throws ServletException {
if (DELETE.equals(ps.getControlEventName())) {
DomainObjectFactory.newInstance(OID.valueOf(ps.getControlEventValue())).delete();
// Regenerate sortkeys
m_listModelBuilder.getModel().regenSortKeys(ps);
} else if (MOVEUP.equals(ps.getControlEventName())) {
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);
} else {
super.respond(ps);
}
}
};
m_listModelBuilder = new ImageListModelBuilder();
List imageList = new List(m_listModelBuilder) {
@Override
public void respond(PageState ps) throws ServletException {
if (DELETE.equals(ps.getControlEventName())) {
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())));
imageList.setCellRenderer(new ImageListCellRenderer());
imageList.setEmptyView(mainLabel);
m_imageStep.showComponent(ps, "edit");
} else if (MOVEUP.equals(ps.getControlEventName())) {
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);
} else {
super.respond(ps);
}
}
add(imageList); // finally add the component
}
};
/**
* Inner class
*/
private class ImageListModelBuilder extends LockableImpl
implements ListModelBuilder {
imageList.setCellRenderer(new ImageListCellRenderer());
imageList.setEmptyView(mainLabel);
private ImageListModel m_listModel;
add(imageList); // finally add the component
}
/**
*
* @param list
* @param ps
* @return
*/
@Override
public ListModel makeModel(List list, PageState ps) {
ContentItem item = m_imageStep.getItem(ps);
/**
* Inner class
*/
private class ImageListModelBuilder extends LockableImpl
implements ListModelBuilder {
DataCollection attachments =
ItemImageAttachment.getImageAttachments(item);
attachments.addPath(ItemImageAttachment.IMAGE + "."
+ ReusableImageAsset.ID);
attachments.addPath(ItemImageAttachment.IMAGE + "."
+ ReusableImageAsset.OBJECT_TYPE);
attachments.addPath(ItemImageAttachment.IMAGE + "."
+ ReusableImageAsset.HEIGHT);
attachments.addPath(ItemImageAttachment.IMAGE + "."
+ ReusableImageAsset.WIDTH);
private ImageListModel m_listModel;
m_listModel = new ImageListModel(attachments);
return m_listModel;
}
/**
*
* @param list
* @param ps
*
* @return
*/
@Override
public ListModel makeModel(List list, PageState ps) {
ContentItem item = m_imageStep.getItem(ps);
protected ImageListModel getModel() {
return m_listModel;
}
}
DataCollection attachments = ItemImageAttachment.getImageAttachments(item);
attachments.addPath(ItemImageAttachment.IMAGE + "."
+ ReusableImageAsset.ID);
attachments.addPath(ItemImageAttachment.IMAGE + "."
+ ReusableImageAsset.OBJECT_TYPE);
attachments.addPath(ItemImageAttachment.IMAGE + "."
+ ReusableImageAsset.HEIGHT);
attachments.addPath(ItemImageAttachment.IMAGE + "."
+ ReusableImageAsset.WIDTH);
/**
*
*/
private class ImageListModel implements ListModel {
m_listModel = new ImageListModel(attachments);
return m_listModel;
}
private final DataCollection m_attachments;
protected ImageListModel getModel() {
return m_listModel;
}
ImageListModel(DataCollection attachments) {
m_attachments = attachments;
}
}
@Override
public Object getElement() {
return DomainObjectFactory.newInstance(m_attachments.getDataObject());
}
/**
*
*/
private class ImageListModel implements ListModel {
@Override
public String getKey() {
return m_attachments.getDataObject().getOID().toString();
}
private final DataCollection m_attachments;
@Override
public boolean next() {
return m_attachments.next();
}
ImageListModel(DataCollection attachments) {
m_attachments = attachments;
}
public boolean isFirst() {
return m_attachments.isFirst();
}
@Override
public Object getElement() {
return DomainObjectFactory.newInstance(m_attachments.getDataObject());
}
public boolean isLast() {
return m_attachments.isLast();
}
@Override
public String getKey() {
return m_attachments.getDataObject().getOID().toString();
}
/**
* Move an image's position inside the list.
*
* @param oid {@link OID} of the image to move
* @param move position steps (positive or negative) to move
* @param ps Current {@link PageState}
*/
protected void move(OID oid, int move, PageState ps) {
// Get the current ContentItem
ContentItem item = m_imageStep.getItem(ps);
// Get the collection of attached images
DataCollection attachments = ItemImageAttachment.getImageAttachments(item);
@Override
public boolean next() {
return m_attachments.next();
}
// Always need an oid of the image to move
if (oid == null) {
throw new IllegalArgumentException("OID must not be null");
}
public boolean isFirst() {
return m_attachments.isFirst();
}
// No move, nothing to do
if (move == 0) {
return;
}
public boolean isLast() {
return m_attachments.isLast();
}
// Find the image in the collection
while (attachments.next()) {
if (attachments.getDataObject().getOID().equals(oid)) {
break;
}
}
/**
* Move an image's position inside the list.
*
* @param oid {@link OID} of the image to move
* @param move position steps (positive or negative) to move
* @param ps Current {@link PageState}
*/
protected void move(OID oid, int move, PageState ps) {
// Get the current ContentItem
ContentItem item = m_imageStep.getItem(ps);
// Get the collection of attached images
DataCollection attachments = ItemImageAttachment.getImageAttachments(item);
// Throw an {@link IllegalArgumentxception} if the oid was not found
if (!attachments.getDataObject().getOID().equals(oid)) {
throw new IllegalArgumentException("OID " + oid + " is not in collection");
}
// Always need an oid of the image to move
if (oid == null) {
throw new IllegalArgumentException("OID must not be null");
}
// Get the image to move and test if it is really an ItemImageAttachment
DomainObject sortDomainObject = DomainObjectFactory.newInstance(attachments.getDataObject());
if (sortDomainObject instanceof ItemImageAttachment) {
// No move, nothing to do
if (move == 0) {
return;
}
// 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).setSortKey(newSortKey);
((ItemImageAttachment) sortDomainObject).save();
// Find the image in the collection
while (attachments.next()) {
if (attachments.getDataObject().getOID().equals(oid)) {
break;
}
}
// Now, move all the object between the original position and the
// new postition one step in the nessecary direction
if (move < 0) {
while (attachments.previous() && move < 0) {
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.getDataObject());
if (domainObject instanceof ItemImageAttachment) {
((ItemImageAttachment) domainObject).setSortKey(
((ItemImageAttachment) domainObject).getSortKey() + 1);
((ItemImageAttachment) domainObject).save();
move++;
}
}
}
if (move > 0) {
while (attachments.next() && move > 0) {
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.getDataObject());
if (domainObject instanceof ItemImageAttachment) {
((ItemImageAttachment) domainObject).setSortKey(
((ItemImageAttachment) domainObject).getSortKey() - 1);
((ItemImageAttachment) domainObject).save();
move--;
}
}
}
}
// Throw an {@link IllegalArgumentxception} if the oid was not found
if (!attachments.getDataObject().getOID().equals(oid)) {
throw new IllegalArgumentException("OID " + oid + " is not in collection");
}
// close the collection manually to avoid warnings because the list
// will not be closed automatically
attachments.close();
}
// Get the image to move and test if it is really an ItemImageAttachment
DomainObject sortDomainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (sortDomainObject instanceof ItemImageAttachment) {
/**
* Reorganize the sortKeys after removing an item.
*
* @param ps The current {@link PageState}
*/
protected void regenSortKeys(PageState ps) {
// Get the current ContentItem
ContentItem item = m_imageStep.getItem(ps);
// Get the collection of attached images
DataCollection attachments = ItemImageAttachment.getImageAttachments(item);
// 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).setSortKey(newSortKey);
((ItemImageAttachment) sortDomainObject).save();
// Current Position
int pos = 0;
// Iterate through all items and set item sortKey to pos
while (attachments.next()) {
pos++;
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.getDataObject());
if (domainObject instanceof ItemImageAttachment) {
int sortKey = ((ItemImageAttachment) domainObject).getSortKey();
if (sortKey != pos) {
((ItemImageAttachment) domainObject).setSortKey(pos);
domainObject.save();
}
}
}
}
}
// Now, move all the object between the original position and the
// new postition one step in the nessecary direction
if (move < 0) {
while (attachments.previous() && move < 0) {
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (domainObject instanceof ItemImageAttachment) {
((ItemImageAttachment) domainObject).setSortKey(
((ItemImageAttachment) domainObject).getSortKey() + 1);
((ItemImageAttachment) domainObject).save();
move++;
}
}
}
if (move > 0) {
while (attachments.next() && move > 0) {
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (domainObject instanceof ItemImageAttachment) {
((ItemImageAttachment) domainObject).setSortKey(
((ItemImageAttachment) domainObject).getSortKey() - 1);
((ItemImageAttachment) domainObject).save();
move--;
}
}
}
}
/**
*
*/
private class ImageListCellRenderer implements ListCellRenderer {
// close the collection manually to avoid warnings because the list
// will not be closed automatically
attachments.close();
}
/**
*
* @param list
* @param state
* @param value
* @param key
* @param index
* @param isSelected
* @return
*/
@Override
public Component getComponent(final List list, PageState state,
Object value, String key,
int index, boolean isSelected) {
final ItemImageAttachment attachment = (ItemImageAttachment) value;
/**
* Reorganize the sortKeys after removing an item.
*
* @param ps The current {@link PageState}
*/
protected void regenSortKeys(PageState ps) {
// Get the current ContentItem
ContentItem item = m_imageStep.getItem(ps);
// Get the collection of attached images
DataCollection attachments = ItemImageAttachment.getImageAttachments(item);
BoxPanel container = new BoxPanel(BoxPanel.VERTICAL);
container.setBorder(1);
// Current Position
int pos = 0;
// Iterate through all items and set item sortKey to pos
while (attachments.next()) {
pos++;
DomainObject domainObject = DomainObjectFactory.newInstance(attachments.
getDataObject());
if (domainObject instanceof ItemImageAttachment) {
int sortKey = ((ItemImageAttachment) domainObject).getSortKey();
if (sortKey != pos) {
((ItemImageAttachment) domainObject).setSortKey(pos);
domainObject.save();
}
}
}
}
// Add CMS ImageDisplay element to BoxPanel container an overwrite
// generateImagePropertiesXM to add attachment's meta data.
container.add(new ImageDisplay(null) {
@Override
protected void generateImagePropertiesXML(ImageAsset image,
PageState state,
Element element) {
/* Use CMS ImageDisplay to display the image including *
* metadata as name, type, widht, height etc. */
super.generateImagePropertiesXML(image, state, element);
}
// We check config here to see whether additional meta data
// as title and description are configured to be displayed.
// If it is, we display the description and title options
// TODO: Currently without Label, labels for each attribut
// are provided by the theme. Has to be refactored to
// provide labels in Java (including localization).
// Title and description - if displayed - have to be
// positioned above the image and its metadata.
if (ItemImageAttachment.getConfig()
.getIsImageStepDescriptionAndTitleShown()) {
String description = attachment.getDescription();
if (description != null) {
element.addAttribute("description", description);
}
/**
*
*/
private class ImageListCellRenderer implements ListCellRenderer {
String title = attachment.getTitle();
if (title != null) {
element.addAttribute("title", title);
}
}
/**
*
* @param list
* @param state
* @param value
* @param key
* @param index
* @param isSelected
*
* @return
*/
@Override
public Component getComponent(final List list, PageState state,
Object value, String key,
int index, boolean isSelected) {
final ItemImageAttachment attachment = (ItemImageAttachment) value;
element.addAttribute("caption_label", (String) GlobalizationUtil.globalize(
"cms.contentasset.image.ui.caption")
.localize());
element.addAttribute("caption", attachment.getCaption());
BoxPanel container = new BoxPanel(BoxPanel.VERTICAL);
container.setBorder(1);
element.addAttribute("context_label", (String) GlobalizationUtil.globalize(
"cms.contentasset.image.ui.use_context")
.localize());
String useContext = attachment.getUseContext();
if (null == useContext) {
element.addAttribute("context", (String) GlobalizationUtil.globalize(
"cms.ui.unknown")
.localize());
} else {
element.addAttribute("context", useContext);
}
// Add CMS ImageDisplay element to BoxPanel container an overwrite
// generateImagePropertiesXM to add attachment's meta data.
container.add(new ImageDisplay(null) {
@Override
protected void generateImagePropertiesXML(ImageAsset image,
PageState state,
Element element) {
/* Use CMS ImageDisplay to display the image including *
* metadata as name, type, widht, height etc. */
super.generateImagePropertiesXML(image, state, element);
}
// We check config here to see whether additional meta data
// as title and description are configured to be displayed.
// If it is, we display the description and title options
// TODO: Currently without Label, labels for each attribut
// are provided by the theme. Has to be refactored to
// provide labels in Java (including localization).
// Title and description - if displayed - have to be
// positioned above the image and its metadata.
if (ItemImageAttachment.getConfig()
.getIsImageStepDescriptionAndTitleShown()) {
String description = attachment.getDescription();
if (description != null) {
element.addAttribute("description", description);
}
@Override
protected ImageAsset getImageAsset(PageState ps) {
return attachment.getImage();
}
});
String title = attachment.getTitle();
if (title != null) {
element.addAttribute("title", title);
}
}
/* Adds links to move and remove the image in a separate container element */
if (!((ImageListModel) list.getModel(state)).isFirst()) {
ControlLink moveUpLink = new ControlLink(new Label(
ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.move_attached_image_up"))) {
@Override
public void setControlEvent(PageState ps) {
String oid = ps.getControlEventValue();
ps.setControlEvent(list, MOVEUP, oid);
}
element.addAttribute("caption_label", (String) GlobalizationUtil.globalize(
"cms.contentasset.image.ui.caption")
.localize());
element.addAttribute("caption", attachment.getCaption());
// Override generateURL to prevent deleting of the page state
@Override
protected void generateURL(PageState state, Element parent) {
setControlEvent(state);
try {
parent.addAttribute("href", state.stateAsURL());
} catch (IOException e) {
parent.addAttribute("href", "");
}
exportAttributes(parent);
}
};
container.add(moveUpLink);
}
element.addAttribute("context_label", (String) GlobalizationUtil.globalize(
"cms.contentasset.image.ui.use_context")
.localize());
String useContext = attachment.getUseContext();
if (null == useContext) {
element.addAttribute("context", (String) GlobalizationUtil.globalize(
"cms.ui.unknown")
.localize());
} else {
element.addAttribute("context", useContext);
}
if (!((ImageListModel) list.getModel(state)).isLast()) {
ControlLink moveDownLink = new ControlLink(new Label(
ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.move_attached_image_down"))) {
@Override
public void setControlEvent(PageState ps) {
String oid = ps.getControlEventValue();
ps.setControlEvent(list, MOVEDOWN, oid);
}
}
// Override generateURL to prevent deleting of the page state
@Override
protected void generateURL(PageState state, Element parent) {
setControlEvent(state);
try {
parent.addAttribute("href", state.stateAsURL());
} catch (IOException e) {
parent.addAttribute("href", "");
}
exportAttributes(parent);
}
};
container.add(moveDownLink);
}
@Override
protected ImageAsset getImageAsset(PageState ps) {
return attachment.getImage();
}
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();
ps.setControlEvent(list, DELETE, oid);
}
});
// Override generateURL to prevent deleting of the page state
@Override
protected void generateURL(PageState state, Element parent) {
setControlEvent(state);
try {
parent.addAttribute("href", state.stateAsURL());
} catch (IOException e) {
parent.addAttribute("href", "");
}
exportAttributes(parent);
}
};
container.add(deleteLink);
/* Adds links to move and remove the image in a separate container element */
if (!((ImageListModel) list.getModel(state)).isFirst()) {
ControlLink moveUpLink = new ControlLink(new Label(
ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.move_attached_image_up"))) {
@Override
public void setControlEvent(PageState ps) {
String oid = ps.getControlEventValue();
ps.setControlEvent(list, MOVEUP, oid);
}
return container;
}
}
// Override generateURL to prevent deleting of the page state
@Override
protected void generateURL(PageState state, Element parent) {
setControlEvent(state);
try {
parent.addAttribute("href", state.stateAsURL());
} catch (IOException e) {
parent.addAttribute("href", "");
}
exportAttributes(parent);
}
};
container.add(moveUpLink);
}
if (!((ImageListModel) list.getModel(state)).isLast()) {
ControlLink moveDownLink = new ControlLink(new Label(
ImageStepGlobalizationUtil.globalize(
"cms.contentassets.ui.image_step.move_attached_image_down"))) {
@Override
public void setControlEvent(PageState ps) {
String oid = ps.getControlEventValue();
ps.setControlEvent(list, MOVEDOWN, oid);
}
// Override generateURL to prevent deleting of the page state
@Override
protected void generateURL(PageState state, Element parent) {
setControlEvent(state);
try {
parent.addAttribute("href", state.stateAsURL());
} catch (IOException e) {
parent.addAttribute("href", "");
}
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();
ps.setControlEvent(list, DELETE, oid);
}
// Override generateURL to prevent deleting of the page state
@Override
protected void generateURL(PageState state, Element parent) {
setControlEvent(state);
try {
parent.addAttribute("href", state.stateAsURL());
} catch (IOException e) {
parent.addAttribute("href", "");
}
exportAttributes(parent);
}
};
container.add(deleteLink);
return container;
}
}
}