From 8c1dd9d8a116526af85573e147e0253bff441a13 Mon Sep 17 00:00:00 2001 From: baka Date: Wed, 10 May 2017 15:39:25 +0000 Subject: [PATCH] Ticket #2683 - Implements the image form git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4723 8810af33-2d31-482b-a856-94f89814c4df --- .../cms/ui/assets/forms/ImageForm.java | 133 ++++++++++++++++++ .../org/librecms/CmsResources.properties | 3 + .../org/librecms/CmsResources_de.properties | 3 + .../org/librecms/CmsResources_fr.properties | 3 + 4 files changed, 142 insertions(+) create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageForm.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageForm.java new file mode 100644 index 000000000..8f713b6d5 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageForm.java @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.cms.ui.assets.forms; + +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.form.TextField; +import com.arsdigita.cms.ui.assets.AssetPane; +import com.arsdigita.cms.ui.assets.AssetSearchWidget; +import com.arsdigita.globalization.GlobalizedMessage; +import org.librecms.CmsConstants; +import org.librecms.assets.BinaryAsset; +import org.librecms.assets.Image; +import org.librecms.assets.LegalMetadata; +import org.librecms.contentsection.Asset; + +import java.util.Optional; + +/** + * + * @author Yannick Bülter + */ +public class ImageForm extends BinaryAssetForm { + + private TextField width; + private TextField height; + private AssetSearchWidget assetSearchWidget; + + public ImageForm(final AssetPane assetPane) { + super(assetPane); + } + + @Override + protected void addWidgets() { + + width = new TextField("width-text"); + height = new TextField("height-text"); + assetSearchWidget = new AssetSearchWidget("legal-metadata", LegalMetadata.class); + + add(new Label(new GlobalizedMessage( + "cms.ui.assets.image.width.label", + CmsConstants.CMS_BUNDLE + ))); + add(width); + + add(new Label(new GlobalizedMessage( + "cms.ui.assets.image.height.label", + CmsConstants.CMS_BUNDLE + ))); + add(height); + + add(new Label(new GlobalizedMessage( + "cms.ui.assets.image.legal_metadata.label", + CmsConstants.CMS_BUNDLE + ))); + add(assetSearchWidget); + } + + @Override + protected void initForm(PageState state, Optional selectedAsset) { + + super.initForm(state, selectedAsset); + + if (selectedAsset.isPresent()) { + + Image image = (Image) selectedAsset.get(); + + width.setValue(state, + Long.toString(image.getWidth())); + height.setValue(state, + Long.toString(image.getHeight())); + final LegalMetadata legalMetadata = image + .getLegalMetadata(); + if (legalMetadata != null) { + assetSearchWidget.setValue(state, legalMetadata.getObjectId()); + } + } + } + + @Override + protected Asset createAsset(final FormSectionEvent event) + throws FormProcessException { + + final Image image = (Image) super.createAsset(event); + + final PageState state = event.getPageState(); + + image.setHeight(Long.parseLong((String) height.getValue(state))); + image.setWidth(Long.parseLong((String) width.getValue(state))); + image.setLegalMetadata((LegalMetadata) assetSearchWidget.getValue(state)); + + return image; + } + + @Override + protected void updateAsset(final Asset asset, + final FormSectionEvent event) + throws FormProcessException { + + super.updateAsset(asset, event); + + final PageState state = event.getPageState(); + + final Image image = (Image) asset; + + image.setHeight(Long.parseLong((String) height.getValue(state))); + image.setWidth(Long.parseLong((String) width.getValue(state))); + image.setLegalMetadata((LegalMetadata) assetSearchWidget.getValue(state)); + } + + @Override + protected BinaryAsset createBinaryAsset(final PageState state) { + return new Image(); + } +} diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties index 75b96ba33..5451c1abb 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties @@ -272,6 +272,9 @@ cms.ui.assets.binaryasset.description=Description cms.ui.assets.binaryasset.filename=File name cms.ui.assets.binaryasset.mimetype=Type cms.ui.assets.binaryasset.size=Size (bytes) +cms.ui.assets.image.width.label=Width +cms.ui.assets.image.height.label=Height +cms.ui.assets.image.legal_metadata.label=Legal metadata cms.ui.categories=Categories cms.ui.new_item=Create new content item cms.ui.authoring.content_type=Content Type: diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties index 4a061f166..e289374fa 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties @@ -270,6 +270,9 @@ cms.ui.assets.binaryasset.description=Beschreibung cms.ui.assets.binaryasset.filename=Dateiname cms.ui.assets.binaryasset.mimetype=Typ cms.ui.assets.binaryasset.size=Gr\u00f6\u00dfe (Bytes) +cms.ui.assets.image.width.label=Breite +cms.ui.assets.image.height.label=H\u00f6he +cms.ui.assets.image.legal_metadata.label=Rechtliche Informationen cms.ui.categories=Kategorien cms.ui.new_item=Neues Content Item angelegen cms.ui.authoring.content_type=Content Typ: diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties index f40fcf720..ee5323668 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties @@ -229,6 +229,9 @@ cms.ui.assets.binaryasset.description=Description cms.ui.assets.binaryasset.filename=File name cms.ui.assets.binaryasset.mimetype=Type cms.ui.assets.binaryasset.size=Size (bytes) +cms.ui.assets.image.width.label=Width +cms.ui.assets.image.height.label=Height +cms.ui.assets.image.legal_metadata.label=Legal metadata cms.ui.categories=Categories cms.ui.new_item=New item cms.ui.authoring.content_type=Content Type: