diff --git a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources.properties b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources.properties index 2f4049796..9fe55d875 100755 --- a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources.properties +++ b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources.properties @@ -7,3 +7,5 @@ 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 +cms.contentassets.ui.image_step.image_table.thumbnail=Thumbnail +cms.contentassets.ui.image_step.remove_attached_image.confirm=Are you sure to remove this attached image? diff --git a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources_de.properties b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources_de.properties index 2a0175d66..bfc342564 100644 --- a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources_de.properties +++ b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources_de.properties @@ -7,3 +7,5 @@ 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 +cms.contentassets.ui.image_step.image_table.thumbnail=Vorschau +cms.contentassets.ui.image_step.remove_attached_image.confirm=Sind Sie sicher das Sie die Zuordnung dieses Bildes entfernen m\u00f6chten? diff --git a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources_en.properties b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources_en.properties index 2f4049796..f5d57b0c2 100755 --- a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources_en.properties +++ b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ImageStepResources_en.properties @@ -7,3 +7,5 @@ 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 +cms.contentassets.ui.image_step.image_table.thumbnail=Thumbnail +cms.contentassets.ui.image_step.remove_attached_image.confirm=cms.contentassets.ui.image_step.remove_attached_image.confirm diff --git a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ui/ImageStep.java b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ui/ImageStep.java index 224caa989..2325e629c 100755 --- a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ui/ImageStep.java +++ b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ui/ImageStep.java @@ -50,7 +50,8 @@ public class ImageStep extends SecurityPropertyEditor { private final ItemSelectionModel m_itemSelection; private final AttachmentSelectionModel m_attachmentSelection; private final AuthoringKitWizard m_parent; - private final ImageStepDisplay m_display; + //private final ImageStepDisplay m_display; + private final ImageStepDisplayTable m_display; private final ImageStepEdit m_add; private final OIDParameter m_attachmentOID; @@ -84,7 +85,8 @@ public class ImageStep extends SecurityPropertyEditor { new ImageAttachmentEditForm(this)); /* ImageDisplayStep to display all already attached images */ - m_display = new ImageStepDisplay(this); // Component to display + //m_display = new ImageStepDisplay(this); // Component to display + m_display = new ImageStepDisplayTable(this); setDisplayComponent(m_display); // all attached images. Iterator imageComponents = m_add.getImageComponents(); diff --git a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ui/ImageStepDisplay.java b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ui/ImageStepDisplay.java index d94e3f8fd..1087e4df4 100755 --- a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ui/ImageStepDisplay.java +++ b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ui/ImageStepDisplay.java @@ -94,6 +94,7 @@ public class ImageStepDisplay extends SimpleContainer { m_listModelBuilder = new ImageListModelBuilder(); List imageList = new List(m_listModelBuilder) { + @Override public void respond(PageState ps) throws ServletException { if (DELETE.equals(ps.getControlEventName())) { @@ -146,13 +147,13 @@ public class ImageStepDisplay extends SimpleContainer { DataCollection attachments = ItemImageAttachment.getImageAttachments(item); attachments.addPath(ItemImageAttachment.IMAGE + "." - + ReusableImageAsset.ID); + + ReusableImageAsset.ID); attachments.addPath(ItemImageAttachment.IMAGE + "." - + ReusableImageAsset.OBJECT_TYPE); + + ReusableImageAsset.OBJECT_TYPE); attachments.addPath(ItemImageAttachment.IMAGE + "." - + ReusableImageAsset.HEIGHT); + + ReusableImageAsset.HEIGHT); attachments.addPath(ItemImageAttachment.IMAGE + "." - + ReusableImageAsset.WIDTH); + + ReusableImageAsset.WIDTH); m_listModel = new ImageListModel(attachments); return m_listModel; @@ -243,7 +244,7 @@ public class ImageStepDisplay extends SimpleContainer { int newSortKey = Math.max(1, Math.min((int) attachments.size(), ((ItemImageAttachment) sortDomainObject). - getSortKey() + move)); + getSortKey() + move)); ((ItemImageAttachment) sortDomainObject).setSortKey(newSortKey); ((ItemImageAttachment) sortDomainObject).save(); @@ -338,6 +339,7 @@ public class ImageStepDisplay extends SimpleContainer { // 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, @@ -368,18 +370,18 @@ public class ImageStepDisplay extends SimpleContainer { } element.addAttribute("caption_label", (String) GlobalizationUtil.globalize( - "cms.contentasset.image.ui.caption") - .localize()); + "cms.contentasset.image.ui.caption") + .localize()); element.addAttribute("caption", attachment.getCaption()); element.addAttribute("context_label", (String) GlobalizationUtil.globalize( - "cms.contentasset.image.ui.use_context") - .localize()); + "cms.contentasset.image.ui.use_context") + .localize()); String useContext = attachment.getUseContext(); if (null == useContext) { element.addAttribute("context", (String) GlobalizationUtil.globalize( - "cms.ui.unknown") - .localize()); + "cms.ui.unknown") + .localize()); } else { element.addAttribute("context", useContext); } @@ -398,6 +400,7 @@ public class ImageStepDisplay extends SimpleContainer { 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(); @@ -424,6 +427,7 @@ public class ImageStepDisplay extends SimpleContainer { 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(); @@ -500,4 +504,5 @@ public class ImageStepDisplay extends SimpleContainer { } } + } diff --git a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ui/ImageStepDisplayTable.java b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ui/ImageStepDisplayTable.java new file mode 100644 index 000000000..97f6e3df2 --- /dev/null +++ b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/contentassets/ui/ImageStepDisplayTable.java @@ -0,0 +1,571 @@ +/* + * Copyright (c) 2010 Jens Pelzetter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.contentassets.ui; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.ControlLink; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.Table; +import com.arsdigita.bebop.event.TableActionEvent; +import com.arsdigita.bebop.event.TableActionListener; +import com.arsdigita.bebop.table.TableCellRenderer; +import com.arsdigita.bebop.table.TableColumn; +import com.arsdigita.bebop.table.TableColumnModel; +import com.arsdigita.bebop.table.TableModel; +import com.arsdigita.bebop.table.TableModelBuilder; +import com.arsdigita.cms.CMS; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ImageAsset; +import com.arsdigita.cms.Service; +import com.arsdigita.cms.contentassets.ItemImageAttachment; +import com.arsdigita.cms.contentassets.util.ImageStepGlobalizationUtil; +import com.arsdigita.cms.ui.ImageDisplay; +import com.arsdigita.cms.util.GlobalizationUtil; +import com.arsdigita.domain.DomainObject; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.globalization.GlobalizedMessage; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.OID; +import com.arsdigita.util.LockableImpl; +import com.arsdigita.web.URL; +import com.arsdigita.xml.Element; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + */ +public class ImageStepDisplayTable extends Table { + + private final static String TABLE_COL_EDIT = "table_col_edit"; + private final static String TABLE_COL_DEL = "table_col_del"; + private final static String TABLE_COL_UP = "table_col_up"; + private final static String TABLE_COL_DOWN = "table_col_down"; + private final static int TABLE_COL_INDEX_THUMBNAIL = 0; + private final static int TABLE_COL_INDEX_NAME = 1; + private final static int TABLE_COL_INDEX_DIMENSIONS = 2; + private final static int TABLE_COL_INDEX_TYPE = 3; + private final static int TABLE_COL_INDEX_CAPTION = 4; + private final static int TABLE_COL_INDEX_EDIT = 5; + private final static int TABLE_COL_INDEX_UP = 6; + private final static int TABLE_COL_INDEX_DOWN = 7; + private final static int TABLE_COL_INDEX_DEL = 8; + private final static int UP = -1; + private final static int DOWN = 1; + + private final ImageStep imageStep; + + public ImageStepDisplayTable(final ImageStep imageStep) { + super(); + this.imageStep = imageStep; + setEmptyView(new Label(ImageStepGlobalizationUtil.globalize( + "cms.contentassets.ui.image_step.no_image_attached"))); + + final TableColumnModel columnModel = getColumnModel(); + columnModel.add(new TableColumn( + TABLE_COL_INDEX_THUMBNAIL, + ImageStepGlobalizationUtil.globalize( + "cms.contentassets.ui.image_step.image_table.thumbnail"))); + + columnModel.add(new TableColumn( + TABLE_COL_INDEX_NAME, + GlobalizationUtil.globalize( + "cms.contentasset.image.ui.display.name"))); + + columnModel.add(new TableColumn( + TABLE_COL_INDEX_DIMENSIONS, + GlobalizationUtil.globalize("cms.contentasset.image.ui.display.dimensions"))); + + columnModel.add(new TableColumn( + TABLE_COL_INDEX_TYPE, + GlobalizationUtil.globalize( + "cms.contentasset.image.ui.display.type"))); + + columnModel.add(new TableColumn( + TABLE_COL_INDEX_CAPTION, + GlobalizationUtil.globalize("cms.contentasset.image.ui.caption"))); + + columnModel.add(new TableColumn( + TABLE_COL_INDEX_EDIT, + ImageStepGlobalizationUtil.globalize( + "cms.contentassets.ui.image_step.edit_attached_image"), + TABLE_COL_EDIT)); + + columnModel.add(new TableColumn( + TABLE_COL_INDEX_UP, + ImageStepGlobalizationUtil.globalize( + "cms.contentassets.ui.image_step.move_attached_image_up"), + TABLE_COL_UP)); + + columnModel.add(new TableColumn( + TABLE_COL_INDEX_DOWN, + ImageStepGlobalizationUtil.globalize( + "cms.contentassets.ui.image_step.move_attached_image_down"), + TABLE_COL_DOWN)); + + columnModel.add(new TableColumn( + TABLE_COL_INDEX_DEL, + ImageStepGlobalizationUtil.globalize( + "cms.contentassets.ui.image_step.remove_attached_image"), + TABLE_COL_DEL)); + + setModelBuilder(new ImageTableModelBuilder(imageStep)); + + columnModel.get(0).setCellRenderer(new ThumbnailCellRenderer()); + columnModel.get(1).setCellRenderer(new NameCellRenderer()); + columnModel.get(2).setCellRenderer(new DimensionsCellRenderer()); + columnModel.get(3).setCellRenderer(new TypeCellRenderer()); + columnModel.get(4).setCellRenderer(new CaptionCellRenderer()); + columnModel.get(5).setCellRenderer(new EditCellRenderer()); + columnModel.get(6).setCellRenderer(new UpCellRenderer()); + columnModel.get(7).setCellRenderer(new DownCellRenderer()); + columnModel.get(8).setCellRenderer(new DeleteCellRenderer()); + + addTableActionListener(new ImageStepTableActionListener()); + + } + + private class ImageTableModelBuilder extends LockableImpl implements TableModelBuilder { + + private final ImageStep imageStep; + + public ImageTableModelBuilder(final ImageStep imageStep) { + this.imageStep = imageStep; + } + + @Override + public TableModel makeModel(final Table table, + final PageState state) { + table.getRowSelectionModel().clearSelection(state); + return new ImageTableModel(table, state, imageStep.getItem(state)); + } + + } + + private class ImageTableModel implements TableModel { + + private final Table table; + private final ContentItem item; + private final DataCollection images; + + public ImageTableModel(final Table table, + final PageState state, + final ContentItem item) { + this.table = table; + this.item = item; + images = ItemImageAttachment.getImageAttachments(item); + } + + @Override + public int getColumnCount() { + return table.getColumnModel().size(); + } + + @Override + public boolean nextRow() { + if (images == null) { + return false; + } else { + return images.next(); + } + } + + @Override + public Object getElementAt(final int columnIndex) { + final ItemImageAttachment image = (ItemImageAttachment) DomainObjectFactory.newInstance( + images.getDataObject()); + + switch (columnIndex) { + case TABLE_COL_INDEX_THUMBNAIL: + return image; + case TABLE_COL_INDEX_NAME: + return image.getImage().getName(); + case TABLE_COL_INDEX_DIMENSIONS: + return String.format("%sx%s px", image.getImage().getWidth().toString(), + image.getImage().getHeight().toString()); + case TABLE_COL_INDEX_TYPE: + return image.getImage().getMimeType().getLabel(); + case TABLE_COL_INDEX_CAPTION: + return image.getCaption(); + case TABLE_COL_INDEX_EDIT: + return ImageStepGlobalizationUtil.globalize( + "cms.contentassets.ui.image_step.edit_attached_image"); + case TABLE_COL_INDEX_UP: + return ImageStepGlobalizationUtil.globalize( + "cms.contentassets.ui.image_step.move_attached_image_up"); + case TABLE_COL_INDEX_DOWN: + return ImageStepGlobalizationUtil.globalize( + "cms.contentassets.ui.image_step.move_attached_image_down"); + case TABLE_COL_INDEX_DEL: + return ImageStepGlobalizationUtil.globalize( + "cms.contentassets.ui.image_step.remove_attached_image"); + default: + return null; + + } + } + + @Override + public Object getKeyAt(final int columnIndex) { + return images.getDataObject().getOID().toString(); + } + + } + + private class ThumbnailCellRenderer extends LockableImpl implements TableCellRenderer { + + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + final ItemImageAttachment image = (ItemImageAttachment) value; + + return new ImageStepImageDisplay(image.getImage()); + } + + } + + private class ImageStepImageDisplay extends ImageDisplay { + + private final ImageAsset image; + + public ImageStepImageDisplay(final ImageAsset image) { + super(null); + this.image = image; + } + + @Override + protected ImageAsset getImageAsset(final PageState state) { + return image; + } + + @Override + protected void generateImagePropertiesXML(final ImageAsset image, + final PageState state, + final Element element) { + element.addAttribute("name", image.getName()); + element.addAttribute("src", URL.getDispatcherPath() + + Service.getImageURL(image)); + final BigDecimal width = image.getWidth(); + if (width != null) { + element.addAttribute("width", width.toString()); + } + final BigDecimal height = image.getHeight(); + if (height != null) { + element.addAttribute("height", height.toString()); + } + element.addAttribute("plain", "true"); + } + + } + + private class NameCellRenderer extends LockableImpl implements TableCellRenderer { + + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + return new Label((String) value); + } + + } + + private class DimensionsCellRenderer extends LockableImpl implements TableCellRenderer { + + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + return new Label((String) value); + } + + } + + private class TypeCellRenderer extends LockableImpl implements TableCellRenderer { + + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + return new Label((String) value); + } + + } + + private class CaptionCellRenderer extends LockableImpl implements TableCellRenderer { + + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + return new Label((String) value); + } + + } + + private class EditCellRenderer extends LockableImpl implements TableCellRenderer { + + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + final com.arsdigita.cms.SecurityManager securityManager = CMS.getSecurityManager(state); + final ContentItem item = imageStep.getItem(state); + + final boolean canEdit = securityManager.canAccess( + state.getRequest(), + com.arsdigita.cms.SecurityManager.EDIT_ITEM, + item); + + if (canEdit) { + return new ControlLink(new Label((GlobalizedMessage) value)); + } else { + return new Label(""); + } + } + + } + + private class UpCellRenderer extends LockableImpl implements TableCellRenderer { + + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + if (0 == row) { + //First row, don't show up link + return new Label(""); + } else { + return new ControlLink(new Label((GlobalizedMessage) value)); + } + } + + } + + private class DownCellRenderer extends LockableImpl implements TableCellRenderer { + + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + final ContentItem item = imageStep.getItem(state); + final DataCollection images = ItemImageAttachment.getImageAttachments(item); + + if ((images.size() - 1) == row) { + //Last row in table, don't show down link + return new Label(""); + } else { + return new ControlLink(new Label((GlobalizedMessage) value)); + } + } + + } + + private class DeleteCellRenderer extends LockableImpl implements TableCellRenderer { + + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + final com.arsdigita.cms.SecurityManager securityManager = CMS.getSecurityManager(state); + final ContentItem item = imageStep.getItem(state); + + final boolean canEdit = securityManager.canAccess( + state.getRequest(), + com.arsdigita.cms.SecurityManager.EDIT_ITEM, + item); + + if (canEdit) { + final ControlLink link = new ControlLink(new Label((GlobalizedMessage) value)); + link.setConfirmation(ImageStepGlobalizationUtil.globalize( + "cms.contentassets.ui.image_step.remove_attached_image.confirm")); + + return link; + } else { + return new Label(""); + } + } + + } + + private class ImageStepTableActionListener implements TableActionListener { + + public ImageStepTableActionListener() { + //Nothing + } + + @Override + public void cellSelected(final TableActionEvent event) { + final PageState state = event.getPageState(); + final TableColumn column = getColumnModel().get(event.getColumn().intValue()); + + if (TABLE_COL_EDIT.equals(column.getHeaderKey().toString())) { + imageStep.setAttachment(state, ItemImageAttachment.retrieve(OID.valueOf(event + .getRowKey().toString()))); + imageStep.showComponent(state, "edit"); + } else if (TABLE_COL_UP.equals(column.getHeaderKey().toString())) { + move(OID.valueOf(event.getRowKey().toString()), UP, state); + } else if (TABLE_COL_DOWN.equals(column.getHeaderKey().toString())) { + move(OID.valueOf(event.getRowKey().toString()), DOWN, state); + } else if (TABLE_COL_DEL.equals(column.getHeaderKey().toString())) { + DomainObjectFactory.newInstance(OID.valueOf(event.getRowKey().toString())).delete(); + regenSortKeys(state); + } + + } + + @Override + public void headSelected(final TableActionEvent event) { + //Nothing to do here. + } + + } + + private void regenSortKeys(final PageState state) { + final ContentItem item = imageStep.getItem(state); + final DataCollection images = ItemImageAttachment.getImageAttachments(item); + + int pos = 0; + while (images.next()) { + pos++; + final DomainObject domainObject = DomainObjectFactory + .newInstance(images.getDataObject()); + + if (domainObject instanceof ItemImageAttachment) { + final ItemImageAttachment image = (ItemImageAttachment) domainObject; + if (image.getSortKey() != pos) { + image.setSortKey(pos); + image.save(); + } + } + + } + } + + private void move(final OID imageOid, final int direction, final PageState state) { + final ContentItem item = imageStep.getItem(state); + final DataCollection images = ItemImageAttachment.getImageAttachments(item); + + if (imageOid == null) { + throw new IllegalArgumentException("OID of ImageAttachment must not be null."); + } + + // No move, nothing to do + if (direction == 0) { + return; + } + + // Find the image in the collection + while (images.next()) { + if (images.getDataObject().getOID().equals(imageOid)) { + break; + } + } + + // Throw an {@link IllegalArgumentxception} if the imageOid was not found + if (!images.getDataObject().getOID().equals(imageOid)) { + throw new IllegalArgumentException("OID " + imageOid + " is not in collection"); + } + + // Get the image to move and test if it is really an ItemImageAttachment + final DomainObject sortDomainObject = DomainObjectFactory + .newInstance(images.getDataObject()); + int move = direction; + if (sortDomainObject instanceof ItemImageAttachment) { + + // Change the sortKey of the ItemImageAttachment to the desired + // value but respect bounds of the current list + final int newSortKey = Math.max(1, + Math.min((int) images.size(), + ((ItemImageAttachment) sortDomainObject). + getSortKey() + move)); + ((ItemImageAttachment) sortDomainObject).setSortKey(newSortKey); + sortDomainObject.save(); + + // Now, move all the object between the original position and the + // new postition one step in the nessecary direction + if (move < 0) { + while (images.previous() && move < 0) { + final DomainObject domainObject = DomainObjectFactory.newInstance(images. + getDataObject()); + if (domainObject instanceof ItemImageAttachment) { + ((ItemImageAttachment) domainObject).setSortKey( + ((ItemImageAttachment) domainObject).getSortKey() + 1); + domainObject.save(); + move++; + } + } + } + if (move > 0) { + while (images.next() && move > 0) { + final DomainObject domainObject = DomainObjectFactory.newInstance(images. + getDataObject()); + if (domainObject instanceof ItemImageAttachment) { + ((ItemImageAttachment) domainObject).setSortKey( + ((ItemImageAttachment) domainObject).getSortKey() - 1); + domainObject.save(); + move--; + } + } + } + } + + // close the collection manually to avimageOid warnings because the list + // will not be closed automatically + images.close(); + } + +} diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ImageDisplay.java b/ccm-cms/src/com/arsdigita/cms/ui/ImageDisplay.java index 11e6c0f9f..1e71c5fe2 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/ImageDisplay.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ImageDisplay.java @@ -32,8 +32,7 @@ import com.arsdigita.xml.Element; import java.math.BigDecimal; /** - * Displays a single ImageAsset, showing its image, width, height, name and - * mime-type. + * Displays a single ImageAsset, showing its image, width, height, name and mime-type. * * @author Michael Pih (pihman@arsdigita.com) * @author Stanislav Freidin (sfreidin@arsdigita.com) @@ -41,117 +40,119 @@ import java.math.BigDecimal; */ public class ImageDisplay extends SimpleComponent { - private final ItemSelectionModel m_item; + private final ItemSelectionModel m_item; - /** - * Construct a new ImageDisplay - * - * @param m The {@link ItemSelectionModel} which will supply this component - * with the {@link ImageAsset} - */ - public ImageDisplay(ItemSelectionModel m) { - super(); - m_item = m; - } + /** + * Construct a new ImageDisplay + * + * @param m The {@link ItemSelectionModel} which will supply this component with the + * {@link ImageAsset} + */ + public ImageDisplay(ItemSelectionModel m) { + super(); + m_item = m; + } - /** - * @return the {@link ItemSelectionModel} which supplies this component with - * the {@link ImageAsset} - */ - public final ItemSelectionModel getImageSelectionModel() { - return m_item; - } + /** + * @return the {@link ItemSelectionModel} which supplies this component with the + * {@link ImageAsset} + */ + public final ItemSelectionModel getImageSelectionModel() { + return m_item; + } - /** - * - * @param state - * @param parent - */ - @Override - public void generateXML(PageState state, Element parent) { - if (isVisible(state)) { + /** + * + * @param state + * @param parent + */ + @Override + public void generateXML(PageState state, Element parent) { + if (isVisible(state)) { - ImageAsset image = getImageAsset(state); + ImageAsset image = getImageAsset(state); - if (image == null) { - return; - } + if (image == null) { + return; + } - Element element = new Element("cms:imageDisplay", CMS.CMS_XML_NS); + Element element = new Element("cms:imageDisplay", CMS.CMS_XML_NS); - if (image != null) { - generateImagePropertiesXML(image, state, element); - } + if (image != null) { + generateImagePropertiesXML(image, state, element); + } - exportAttributes(element); - parent.addContent(element); - } - } + exportAttributes(element); + parent.addContent(element); + } + } - /** - * Generates the property xml. - * - * @param image - * @param state - * @param element - */ - protected void generateImagePropertiesXML(ImageAsset image, - PageState state, - Element element) { + /** + * Generates the property xml. + * + * @param image + * @param state + * @param element + */ + protected void generateImagePropertiesXML(ImageAsset image, + PageState state, + Element element) { - element.addAttribute("name_label", (String) GlobalizationUtil.globalize( - "cms.contentasset.image.ui.display.name") - .localize()); - element.addAttribute("name", image.getName()); - element.addAttribute("src", URL.getDispatcherPath() - + Service.getImageURL(image)); + element.addAttribute("name_label", (String) GlobalizationUtil.globalize( + "cms.contentasset.image.ui.display.name") + .localize()); + element.addAttribute("name", image.getName()); + element.addAttribute("src", URL.getDispatcherPath() + + Service.getImageURL(image)); - element.addAttribute("mime_type_label", (String) GlobalizationUtil.globalize( - "cms.contentasset.image.ui.display.type") - .localize()); - MimeType mimeType = image.getMimeType(); - if (mimeType != null) { - element.addAttribute("mime_type", mimeType.getLabel()); - } + element.addAttribute("mime_type_label", (String) GlobalizationUtil.globalize( + "cms.contentasset.image.ui.display.type") + .localize()); + MimeType mimeType = image.getMimeType(); + if (mimeType != null) { + element.addAttribute("mime_type", mimeType.getLabel()); + } - element.addAttribute("width_label", (String) GlobalizationUtil.globalize( - "cms.contentasset.image.ui.display.width") - .localize()); - BigDecimal width = image.getWidth(); - if (width != null) { - element.addAttribute("width", width.toString()); - } else { - element.addAttribute("width", (String) GlobalizationUtil.globalize( - "cms.ui.unknown") - .localize()); - } + element.addAttribute("width_label", (String) GlobalizationUtil.globalize( + "cms.contentasset.image.ui.display.width") + .localize()); + BigDecimal width = image.getWidth(); + if (width != null) { + element.addAttribute("width", width.toString()); + } else { + element.addAttribute("width", (String) GlobalizationUtil.globalize( + "cms.ui.unknown") + .localize()); + } - element.addAttribute("height_label", (String) GlobalizationUtil.globalize( - "cms.contentasset.image.ui.display.height") - .localize()); - BigDecimal height = image.getHeight(); - if (height != null) { - element.addAttribute("height", height.toString()); - } else { - element.addAttribute("height", (String) GlobalizationUtil.globalize( - "cms.ui.unknown") - .localize()); - } + element.addAttribute("height_label", (String) GlobalizationUtil.globalize( + "cms.contentasset.image.ui.display.height") + .localize()); + BigDecimal height = image.getHeight(); + if (height != null) { + element.addAttribute("height", height.toString()); + } else { + element.addAttribute("height", (String) GlobalizationUtil.globalize( + "cms.ui.unknown") + .localize()); + } - element.addAttribute("dimension_label", (String) GlobalizationUtil.globalize( - "cms.contentasset.image.ui.display.dimensions") - .localize()); + element.addAttribute("dimension_label", (String) GlobalizationUtil.globalize( + "cms.contentasset.image.ui.display.dimensions") + .localize()); - } + } + + /** + * + * @param state + * + * @return + */ + protected ImageAsset getImageAsset(PageState state) { + ImageAsset image = (ImageAsset) m_item.getSelectedObject(state); + Assert.exists(image, "Image asset"); + return image; + } - /** - * - * @param state - * @return - */ - protected ImageAsset getImageAsset(PageState state) { - ImageAsset image = (ImageAsset) m_item.getSelectedObject(state); - Assert.exists(image, "Image asset"); - return image; - } } diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ImageUploadComponent.java b/ccm-cms/src/com/arsdigita/cms/ui/ImageUploadComponent.java index a7979944d..04457b6e4 100644 --- a/ccm-cms/src/com/arsdigita/cms/ui/ImageUploadComponent.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ImageUploadComponent.java @@ -25,65 +25,64 @@ import java.io.IOException; /** * An image upload component. * - * This component can be used in different places to add image upload - * capabilities in a convinient way. This class uses a listener class which - * should be extended from {@link ImageComponentAbstractListener}. + * This component can be used in different places to add image upload capabilities in a convinient + * way. This class uses a listener class which should be extended from + * {@link ImageComponentAbstractListener}. * * @author unknown * @author Sören Bernstein */ public class ImageUploadComponent extends Form implements ImageComponent { - private final FileUploadSection m_imageFile; - private final TextField m_caption; - private final TextField m_title; - private final TextArea m_description; - private final TextField m_useContext; - private final SaveCancelSection m_saveCancel; - private int m_mode; + private final FileUploadSection m_imageFile; + private final TextField m_caption; + private final TextField m_title; + private final TextArea m_description; + private final TextField m_useContext; + private final SaveCancelSection m_saveCancel; + private int m_mode; - /** - * Creates an ImageUploadComponent in attach mode. - */ - public ImageUploadComponent() { - this(ImageComponent.ATTACH_IMAGE); - } + /** + * Creates an ImageUploadComponent in attach mode. + */ + public ImageUploadComponent() { + this(ImageComponent.ATTACH_IMAGE); + } - /** - * Creates an ImageUploadComponent with the selected mode. - * - * @param mode The operation mode (see {@link ImageComponent) - */ - public ImageUploadComponent(int mode) { - super("imageUploadComponent", new ColumnPanel(2)); - m_mode = mode; - setEncType("multipart/form-data"); - m_imageFile = new FileUploadSection(GlobalizationUtil.globalize( - "cms.contentasset.image.ui.type"), - "image", - ImageAsset.MIME_JPEG); - m_imageFile.getFileUploadWidget() - .addValidationListener(new NotNullValidationListener()); - add(m_imageFile, ColumnPanel.FULL_WIDTH); + /** + * Creates an ImageUploadComponent with the selected mode. + * + * @param mode The operation mode (see {@link ImageComponent) + */ + public ImageUploadComponent(int mode) { + super("imageUploadComponent", new ColumnPanel(2)); + m_mode = mode; + setEncType("multipart/form-data"); + m_imageFile = new FileUploadSection(GlobalizationUtil.globalize( + "cms.contentasset.image.ui.type"), + "image", + ImageAsset.MIME_JPEG); + m_imageFile.getFileUploadWidget() + .addValidationListener(new NotNullValidationListener()); + add(m_imageFile, ColumnPanel.FULL_WIDTH); - // Initialize all widgets - m_caption = new TextField("caption"); - m_title = new TextField("title"); - m_description = new TextArea("description"); - m_useContext = new TextField("useContext"); + // Initialize all widgets + m_caption = new TextField("caption"); + m_title = new TextField("title"); + m_description = new TextArea("description"); + m_useContext = new TextField("useContext"); - // add widget only if we are in attach mode - if (m_mode == ImageComponent.ATTACH_IMAGE) { - add(new Label(GlobalizationUtil - .globalize("cms.contentasset.image.ui.caption"))); - m_caption.addValidationListener(new NotNullValidationListener()); - m_caption.addValidationListener(new StringLengthValidationListener(40)); - m_caption.setSize(40); - add(m_caption); - - // We only show the title and description fields in the case where - // getIsImageStepDescriptionAndTitleShown is false. + // add widget only if we are in attach mode + if (m_mode == ImageComponent.ATTACH_IMAGE) { + add(new Label(GlobalizationUtil + .globalize("cms.contentasset.image.ui.caption"))); + m_caption.addValidationListener(new NotNullValidationListener()); + m_caption.addValidationListener(new StringLengthValidationListener(40)); + m_caption.setSize(40); + add(m_caption); + // We only show the title and description fields in the case where + // getIsImageStepDescriptionAndTitleShown is false. // if (ItemImageAttachment.getConfig().getIsImageStepDescriptionAndTitleShown()) { // add(new Label("Title")); // m_title.addValidationListener(new NotNullValidationListener()); @@ -99,79 +98,79 @@ public class ImageUploadComponent extends Form implements ImageComponent { // add(m_description); // // } + add(new Label(GlobalizationUtil + .globalize("cms.contentasset.image.ui.use_context"))); + m_useContext.setSize(40); + add(m_useContext); + } + m_saveCancel = new SaveCancelSection(); + add(m_saveCancel); - add(new Label(GlobalizationUtil - .globalize("cms.contentasset.image.ui.use_context"))); - m_useContext.setSize(40); - add(m_useContext); - } - m_saveCancel = new SaveCancelSection(); - add(m_saveCancel); + /* + * Removed by Quasimodo: Changed editing workflow, so that library comes + * first Also, library mode has now a link to upload images which will + * link to this form. Consequently, this link will create a loop, which + * isn't fatal but confusing. + * + * ActionLink library = new ActionLink("Select an existing image" ); + * library.addActionListener( new ActionListener() { + * public void actionPerformed( ActionEvent ev ) { + * setImageComponent( ev.getPageState(), LIBRARY ); + * } + * } ); + * add( library, ColumnPanel.FULL_WIDTH ); + */ + } - /* - * Removed by Quasimodo: Changed editing workflow, so that library comes - * first Also, library mode has now a link to upload images which will - * link to this form. Consequently, this link will create a loop, which - * isn't fatal but confusing. - * - * ActionLink library = new ActionLink("Select an existing image" ); - * library.addActionListener( new ActionListener() { - * public void actionPerformed( ActionEvent ev ) { - * setImageComponent( ev.getPageState(), LIBRARY ); - * } - * } ); - * add( library, ColumnPanel.FULL_WIDTH ); - */ - } + @Override + public SaveCancelSection getSaveCancelSection() { + return m_saveCancel; + } - @Override - public SaveCancelSection getSaveCancelSection() { - return m_saveCancel; - } - - @Override - public ReusableImageAsset getImage(FormSectionEvent event) - throws FormProcessException { - PageState ps = event.getPageState(); - String filename = (String) m_imageFile.getFileName(event); - File imageFile = m_imageFile.getFile(event); - try { - ReusableImageAsset image = new ReusableImageAsset(); - image.loadFromFile(filename, imageFile, ImageAsset.MIME_JPEG); + @Override + public ReusableImageAsset getImage(FormSectionEvent event) + throws FormProcessException { + PageState ps = event.getPageState(); + String filename = (String) m_imageFile.getFileName(event); + File imageFile = m_imageFile.getFile(event); + try { + ReusableImageAsset image = new ReusableImageAsset(); + image.loadFromFile(filename, imageFile, ImageAsset.MIME_JPEG); // image.setDescription((String) m_caption.getValue(ps)); - return image; - } catch (IOException ex) { - ImagesPane.S_LOG.error("Error loading image from file", ex); - throw new FormProcessException(ex.getMessage()); - } - } + return image; + } catch (IOException ex) { + ImagesPane.S_LOG.error("Error loading image from file", ex); + throw new FormProcessException(ex.getMessage()); + } + } - @Override - public String getCaption(FormSectionEvent event) { - PageState ps = event.getPageState(); - return (String) m_caption.getValue(ps); - } + @Override + public String getCaption(FormSectionEvent event) { + PageState ps = event.getPageState(); + return (String) m_caption.getValue(ps); + } - @Override - public String getDescription(FormSectionEvent event) { - PageState ps = event.getPageState(); - return (String) m_description.getValue(ps); - } + @Override + public String getDescription(FormSectionEvent event) { + PageState ps = event.getPageState(); + return (String) m_description.getValue(ps); + } - @Override - public String getTitle(FormSectionEvent event) { - PageState ps = event.getPageState(); - return (String) m_title.getValue(ps); - } + @Override + public String getTitle(FormSectionEvent event) { + PageState ps = event.getPageState(); + return (String) m_title.getValue(ps); + } - @Override - public String getUseContext(FormSectionEvent event) { - PageState ps = event.getPageState(); - return (String) m_useContext.getValue(ps); - } + @Override + public String getUseContext(FormSectionEvent event) { + PageState ps = event.getPageState(); + return (String) m_useContext.getValue(ps); + } + + @Override + public Form getForm() { + return this; + } - @Override - public Form getForm() { - return this; - } } diff --git a/ccm-sci-bundle/bundles/devel/cfg/project.xml b/ccm-sci-bundle/bundles/devel/cfg/project.xml index 57eec1982..4be7ec591 100644 --- a/ccm-sci-bundle/bundles/devel/cfg/project.xml +++ b/ccm-sci-bundle/bundles/devel/cfg/project.xml @@ -9,7 +9,7 @@ name="ScientificCMS" prettyName="Scientific CMS" version="2.3.0" - release="devel-SNAPSHOT-r2664" + release="devel-SNAPSHOT-r2691" webxml="sci-web.xml" portletxml="sci-portlet.xml" webapp="libreccm" diff --git a/ccm-sci-bundle/web/themes/mandalay/includes/cms/cmsImageDisplay.xsl b/ccm-sci-bundle/web/themes/mandalay/includes/cms/cmsImageDisplay.xsl index 2106ec4d7..580bed8a0 100644 --- a/ccm-sci-bundle/web/themes/mandalay/includes/cms/cmsImageDisplay.xsl +++ b/ccm-sci-bundle/web/themes/mandalay/includes/cms/cmsImageDisplay.xsl @@ -31,121 +31,129 @@ + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:bebop="http://www.arsdigita.com/bebop/1.0" + xmlns:cms="http://www.arsdigita.com/cms/1.0" + xmlns:nav="http://ccm.redhat.com/navigation" + xmlns:mandalay="http://mandalay.quasiweb.de" + exclude-result-prefixes="xsl bebop cms nav mandalay" + version="1.0"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - -
- - - - - -
-
- - - - - - - - - - - - - - - - - - - -
-
- - - - - x -
-
- - - - - -
-
- - - - - - - - -
- -
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + +
+
+ + + + + + x + +
+
+ + + + + + + +
+
+ + + + + + + + +
+
+ +
diff --git a/ccm-sci-bundle/web/themes/mandalay/includes/mandalay/imageGallery.xsl b/ccm-sci-bundle/web/themes/mandalay/includes/mandalay/imageGallery.xsl index ee7dd80bd..abe3dcdb6 100644 --- a/ccm-sci-bundle/web/themes/mandalay/includes/mandalay/imageGallery.xsl +++ b/ccm-sci-bundle/web/themes/mandalay/includes/mandalay/imageGallery.xsl @@ -47,7 +47,7 @@ - - - - + --> diff --git a/ccm-sci-bundle/web/themes/mandalay/settings/imageGallery.xml b/ccm-sci-bundle/web/themes/mandalay/settings/imageGallery.xml index fe9538c99..503279372 100644 --- a/ccm-sci-bundle/web/themes/mandalay/settings/imageGallery.xml +++ b/ccm-sci-bundle/web/themes/mandalay/settings/imageGallery.xml @@ -19,6 +19,16 @@ along with Mandalay. If not, see . --> + + + 10 20