Umstrukturireung macht die internen Klassen zu externen

git-svn-id: https://svn.libreccm.org/ccm/trunk@1764 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2012-07-12 06:50:52 +00:00
parent 9f93f1a7c5
commit 29eaf69880
1 changed files with 278 additions and 295 deletions

View File

@ -18,46 +18,29 @@
package com.arsdigita.cms.contentassets.ui; package com.arsdigita.cms.contentassets.ui;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.MapComponentSelectionModel; import com.arsdigita.bebop.MapComponentSelectionModel;
import com.arsdigita.bebop.Page; import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel; import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.SimpleContainer; import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.ParameterEvent; import com.arsdigita.bebop.event.ParameterEvent;
import com.arsdigita.bebop.event.ParameterListener; import com.arsdigita.bebop.event.ParameterListener;
import com.arsdigita.bebop.form.TextArea;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.ParameterData; import com.arsdigita.bebop.parameters.ParameterData;
import com.arsdigita.bebop.parameters.StringLengthValidationListener;
import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ReusableImageAsset; import com.arsdigita.cms.ReusableImageAsset;
import com.arsdigita.cms.contentassets.ItemImageAttachment; import com.arsdigita.cms.contentassets.ItemImageAttachment;
import com.arsdigita.cms.ui.FileUploadSection; import com.arsdigita.cms.ui.ImageComponent;
import com.arsdigita.cms.ui.ImageBrowser; import com.arsdigita.cms.ui.ImageLibraryComponent;
import com.arsdigita.cms.ui.ImageChooser; import com.arsdigita.cms.ui.ImageUploadComponent;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataCollection;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import com.arsdigita.util.StringUtils; import com.arsdigita.util.StringUtils;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -205,281 +188,281 @@ public class ImageStepEdit extends SimpleContainer
attachment.setUseContext( component.getUseContext( event ) ); attachment.setUseContext( component.getUseContext( event ) );
} }
interface ImageComponent { // interface ImageComponent {
ReusableImageAsset getImage( FormSectionEvent event ) // ReusableImageAsset getImage( FormSectionEvent event )
throws FormProcessException; // throws FormProcessException;
String getCaption( FormSectionEvent event ); // String getCaption( FormSectionEvent event );
String getDescription( FormSectionEvent event ); // String getDescription( FormSectionEvent event );
String getTitle( FormSectionEvent event ); // String getTitle( FormSectionEvent event );
String getUseContext( FormSectionEvent event ); // String getUseContext( FormSectionEvent event );
SaveCancelSection getSaveCancelSection(); // SaveCancelSection getSaveCancelSection();
Form getForm(); // Form getForm();
} // }
//
private class ImageUploadComponent extends Form // private class ImageUploadComponent extends Form
implements ImageComponent { // implements ImageComponent {
private final FileUploadSection m_imageFile; // private final FileUploadSection m_imageFile;
private final TextField m_caption; // private final TextField m_caption;
private final TextField m_title; // private final TextField m_title;
private final TextArea m_description; // private final TextArea m_description;
private final TextField m_useContext; // private final TextField m_useContext;
private final SaveCancelSection m_saveCancel; // private final SaveCancelSection m_saveCancel;
//
public ImageUploadComponent() { // public ImageUploadComponent() {
super("imageStepEditUpload", new ColumnPanel(2)); // super("imageStepEditUpload", new ColumnPanel(2));
//
setEncType("multipart/form-data"); // setEncType("multipart/form-data");
//
// Ignoring deprecated constructor. // // Ignoring deprecated constructor.
m_imageFile = new FileUploadSection("Image Type", // m_imageFile = new FileUploadSection("Image Type",
"image", ImageAsset.MIME_JPEG); // "image", ImageAsset.MIME_JPEG);
m_imageFile.getFileUploadWidget() // m_imageFile.getFileUploadWidget()
.addValidationListener(new NotNullValidationListener()); // .addValidationListener(new NotNullValidationListener());
//
add( m_imageFile, ColumnPanel.FULL_WIDTH ); // add( m_imageFile, ColumnPanel.FULL_WIDTH );
//
add(new Label("Caption")); // add(new Label("Caption"));
m_caption = new TextField("caption"); // m_caption = new TextField("caption");
m_caption.addValidationListener(new NotNullValidationListener()); // m_caption.addValidationListener(new NotNullValidationListener());
m_caption.addValidationListener(new StringLengthValidationListener(40)); // m_caption.addValidationListener(new StringLengthValidationListener(40));
m_caption.setSize(40); // m_caption.setSize(40);
add(m_caption); // add(m_caption);
//
m_title = new TextField("title"); // m_title = new TextField("title");
m_description = new TextArea("description"); // m_description = new TextArea("description");
//
// We only show the title and description fields in the case where // // We only show the title and description fields in the case where
// getIsImageStepDescriptionAndTitleShown is false. // // getIsImageStepDescriptionAndTitleShown is false.
if (ItemImageAttachment.getConfig().getIsImageStepDescriptionAndTitleShown()) { // if (ItemImageAttachment.getConfig().getIsImageStepDescriptionAndTitleShown()) {
add(new Label("Title")); // add(new Label("Title"));
m_title.addValidationListener(new NotNullValidationListener()); // m_title.addValidationListener(new NotNullValidationListener());
m_title.setSize(40); // m_title.setSize(40);
m_title.addValidationListener(new StringLengthValidationListener(40)); // m_title.addValidationListener(new StringLengthValidationListener(40));
add(m_title); // add(m_title);
//
add(new Label("Description")); // add(new Label("Description"));
m_description.addValidationListener(new NotNullValidationListener()); // m_description.addValidationListener(new NotNullValidationListener());
m_description.addValidationListener(new StringLengthValidationListener(600)); // m_description.addValidationListener(new StringLengthValidationListener(600));
m_description.setCols(30); // m_description.setCols(30);
m_description.setRows(5); // m_description.setRows(5);
add(m_description); // add(m_description);
//
} // }
//
add(new Label("Use Context")); // add(new Label("Use Context"));
m_useContext = new TextField("useContext"); // m_useContext = new TextField("useContext");
m_useContext.setSize(40); // m_useContext.setSize(40);
// Removed to use multiple images with fancyBox //// Removed to use multiple images with fancyBox
// m_useContext.addValidationListener( new UniqueUseContextListener() ); //// m_useContext.addValidationListener( new UniqueUseContextListener() );
add(m_useContext); // add(m_useContext);
//
m_saveCancel = new SaveCancelSection(); // m_saveCancel = new SaveCancelSection();
add(m_saveCancel); // add(m_saveCancel);
//
/* Removed by Quasimodo: Changed editing workflow, so that library comes first // /* Removed by Quasimodo: Changed editing workflow, so that library comes first
* Also, library mode has now a link to upload images whixh will link to this // * Also, library mode has now a link to upload images whixh will link to this
* form. Consequently, this link will create a loop, which isn't fatal but // * form. Consequently, this link will create a loop, which isn't fatal but
* confusing // * confusing
ActionLink library = new ActionLink( "Select an existing image" ); // ActionLink library = new ActionLink( "Select an existing image" );
library.addActionListener( new ActionListener() { // library.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent ev ) { // public void actionPerformed( ActionEvent ev ) {
setImageComponent( ev.getPageState(), LIBRARY ); // setImageComponent( ev.getPageState(), LIBRARY );
} // }
} ); // } );
add( library, ColumnPanel.FULL_WIDTH ); // add( library, ColumnPanel.FULL_WIDTH );
*/ // */
} // }
//
public SaveCancelSection getSaveCancelSection() { // public SaveCancelSection getSaveCancelSection() {
return m_saveCancel; // return m_saveCancel;
} // }
//
public ReusableImageAsset getImage( FormSectionEvent event ) // public ReusableImageAsset getImage( FormSectionEvent event )
throws FormProcessException // throws FormProcessException
{ // {
PageState ps = event.getPageState(); // PageState ps = event.getPageState();
//
String filename = (String) m_imageFile.getFileName( event ); // String filename = (String) m_imageFile.getFileName( event );
File imageFile = m_imageFile.getFile( event ); // File imageFile = m_imageFile.getFile( event );
//
try { // try {
ReusableImageAsset image = new ReusableImageAsset(); // ReusableImageAsset image = new ReusableImageAsset();
image.loadFromFile( filename, imageFile, ImageAsset.MIME_JPEG ); // image.loadFromFile( filename, imageFile, ImageAsset.MIME_JPEG );
image.setDescription( ( String ) m_caption.getValue( ps ) ); // image.setDescription( ( String ) m_caption.getValue( ps ) );
//
return image; // return image;
} catch ( IOException ex ) { // } catch ( IOException ex ) {
s_log.error( "Error loading image from file", ex ); // s_log.error( "Error loading image from file", ex );
throw new FormProcessException( ex.getMessage() ); // throw new FormProcessException( ex.getMessage() );
} // }
} // }
//
public String getCaption( FormSectionEvent event ) { // public String getCaption( FormSectionEvent event ) {
PageState ps = event.getPageState(); // PageState ps = event.getPageState();
return (String) m_caption.getValue( ps ); // return (String) m_caption.getValue( ps );
} // }
//
public String getDescription( FormSectionEvent event ) { // public String getDescription( FormSectionEvent event ) {
PageState ps = event.getPageState(); // PageState ps = event.getPageState();
return (String) m_description.getValue( ps ); // return (String) m_description.getValue( ps );
} // }
//
public String getTitle( FormSectionEvent event ) { // public String getTitle( FormSectionEvent event ) {
PageState ps = event.getPageState(); // PageState ps = event.getPageState();
return (String) m_title.getValue( ps ); // return (String) m_title.getValue( ps );
} // }
//
public String getUseContext( FormSectionEvent event ) { // public String getUseContext( FormSectionEvent event ) {
PageState ps = event.getPageState(); // PageState ps = event.getPageState();
return (String) m_useContext.getValue( ps ); // return (String) m_useContext.getValue( ps );
} // }
//
public Form getForm() { // public Form getForm() {
return this; // return this;
} // }
} // }
//
private class ImageLibraryComponent extends SimpleContainer // private class ImageLibraryComponent extends SimpleContainer
implements ImageComponent { // implements ImageComponent {
private final ImageChooser m_chooser; // private final ImageChooser m_chooser;
private final ItemSelectionModel m_imageModel; // private final ItemSelectionModel m_imageModel;
private final BigDecimalParameter m_imageID; // private final BigDecimalParameter m_imageID;
//
private final Form m_form; // private final Form m_form;
private final TextField m_caption; // private final TextField m_caption;
private final TextField m_description; // private final TextField m_description;
private final TextField m_title; // private final TextField m_title;
private final TextField m_useContext; // private final TextField m_useContext;
private final SaveCancelSection m_saveCancel; // private final SaveCancelSection m_saveCancel;
//
public ImageLibraryComponent() { // public ImageLibraryComponent() {
m_imageID = new BigDecimalParameter( "imageID" ); // m_imageID = new BigDecimalParameter( "imageID" );
m_imageModel = new ItemSelectionModel( m_imageID ); // m_imageModel = new ItemSelectionModel( m_imageID );
//
m_chooser = new ImageChooser( ContentItem.DRAFT ); // m_chooser = new ImageChooser( ContentItem.DRAFT, ImageBrowser.SELECT_IMAGE );
m_chooser.addImageActionListener( new ImageBrowser.LinkActionListener() { // m_chooser.addImageActionListener( new ImageBrowser.LinkActionListener() {
public void deleteClicked( PageState ps, BigDecimal imageID ) { // public void deleteClicked( PageState ps, BigDecimal imageID ) {
s_log.debug( "Clicked delete" ); // s_log.debug( "Clicked delete" );
//
ReusableImageAsset image = // ReusableImageAsset image =
new ReusableImageAsset( imageID ); // new ReusableImageAsset( imageID );
image.delete(); // image.delete();
} // }
//
public void linkClicked( PageState ps, BigDecimal imageID ) { // public void linkClicked( PageState ps, BigDecimal imageID ) {
s_log.debug( "Clicked select" ); // s_log.debug( "Clicked select" );
try { // try {
ReusableImageAsset image = // ReusableImageAsset image =
new ReusableImageAsset( imageID ); // new ReusableImageAsset( imageID );
//
m_imageModel.setSelectedObject( ps, image ); // m_imageModel.setSelectedObject( ps, image );
} catch( DataObjectNotFoundException ex ) { // } catch( DataObjectNotFoundException ex ) {
s_log.error( "Selected non-existant image: " + imageID, ex ); // s_log.error( "Selected non-existant image: " + imageID, ex );
} // }
} // }
} ); // } );
// Don't display the delete links // // Don't display the delete links
/* // /*
m_chooser.getImageBrowser().getColumn(5) // m_chooser.getImageBrowser().getColumn(5)
.setCellRenderer( new TableCellRenderer() { // .setCellRenderer( new TableCellRenderer() {
public Component getComponent( Table table, PageState state, // public Component getComponent( Table table, PageState state,
Object value, boolean isSelected, // Object value, boolean isSelected,
Object key, int row, // Object key, int row,
int column ) { // int column ) {
return new Label( " ", false ); // return new Label( " ", false );
} // }
} ); // } );
*/ // */
add( m_chooser ); // add( m_chooser );
//
m_form = new Form( "imageStepEditLibrary", new ColumnPanel( 2 ) ); // m_form = new Form( "imageStepEditLibrary", new ColumnPanel( 2 ) );
add( m_form ); // add( m_form );
//
m_form.add(new Label("Caption")); // m_form.add(new Label("Caption"));
m_caption = new TextField("caption"); // m_caption = new TextField("caption");
m_caption.addValidationListener(new NotNullValidationListener()); // m_caption.addValidationListener(new NotNullValidationListener());
m_caption.setSize(40); // m_caption.setSize(40);
m_form.add(m_caption); // m_form.add(m_caption);
//
m_description = new TextField("description"); // m_description = new TextField("description");
m_description.addValidationListener(new NotNullValidationListener()); // m_description.addValidationListener(new NotNullValidationListener());
m_description.setSize(40); // m_description.setSize(40);
//
m_title = new TextField("title"); // m_title = new TextField("title");
m_title.addValidationListener(new NotNullValidationListener()); // m_title.addValidationListener(new NotNullValidationListener());
m_title.setSize(40); // m_title.setSize(40);
//
// Only show the title and description fields where these have // // Only show the title and description fields where these have
// been explicitly requested. // // been explicitly requested.
if (ItemImageAttachment.getConfig().getIsImageStepDescriptionAndTitleShown()) { // if (ItemImageAttachment.getConfig().getIsImageStepDescriptionAndTitleShown()) {
m_form.add(new Label("Description")); // m_form.add(new Label("Description"));
m_form.add(m_description); // m_form.add(m_description);
m_form.add(new Label("Title")); // m_form.add(new Label("Title"));
m_form.add(m_title); // m_form.add(m_title);
} // }
//
//
m_form.add(new Label("Use Context")); // m_form.add(new Label("Use Context"));
m_useContext = new TextField("useContext"); // m_useContext = new TextField("useContext");
m_useContext.setSize(40); // m_useContext.setSize(40);
// Removed to use multiple images with fancyBox //// Removed to use multiple images with fancyBox
// m_useContext.addValidationListener( new UniqueUseContextListener() ); //// m_useContext.addValidationListener( new UniqueUseContextListener() );
m_form.add(m_useContext); // m_form.add(m_useContext);
//
m_saveCancel = new SaveCancelSection(); // m_saveCancel = new SaveCancelSection();
m_form.add(m_saveCancel); // m_form.add(m_saveCancel);
//
ActionLink upload = new ActionLink( "Upload a new image" ); // ActionLink upload = new ActionLink( "Upload a new image" );
upload.addActionListener( new ActionListener() { // upload.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent ev ) { // public void actionPerformed( ActionEvent ev ) {
setImageComponent( ev.getPageState(), UPLOAD ); // setImageComponent( ev.getPageState(), UPLOAD );
} // }
} ); // } );
add( upload, ColumnPanel.FULL_WIDTH ); // add( upload, ColumnPanel.FULL_WIDTH );
} // }
//
public ReusableImageAsset getImage( FormSectionEvent event ) { // public ReusableImageAsset getImage( FormSectionEvent event ) {
PageState ps = event.getPageState(); // PageState ps = event.getPageState();
//
return (ReusableImageAsset) m_imageModel.getSelectedItem( ps ); // return (ReusableImageAsset) m_imageModel.getSelectedItem( ps );
} // }
//
@Override // @Override
public void register( Page p ) { // public void register( Page p ) {
super.register( p ); // super.register( p );
//
p.addComponentStateParam( this, m_imageID ); // p.addComponentStateParam( this, m_imageID );
} // }
//
public String getCaption( FormSectionEvent event ) { // public String getCaption( FormSectionEvent event ) {
PageState ps = event.getPageState(); // PageState ps = event.getPageState();
return (String) m_caption.getValue( ps ); // return (String) m_caption.getValue( ps );
} // }
//
public String getDescription( FormSectionEvent event ) { // public String getDescription( FormSectionEvent event ) {
PageState ps = event.getPageState(); // PageState ps = event.getPageState();
return (String) m_description.getValue( ps ); // return (String) m_description.getValue( ps );
} // }
//
public String getTitle( FormSectionEvent event ) { // public String getTitle( FormSectionEvent event ) {
PageState ps = event.getPageState(); // PageState ps = event.getPageState();
return (String) m_title.getValue( ps ); // return (String) m_title.getValue( ps );
} // }
//
//
public String getUseContext( FormSectionEvent event ) { // public String getUseContext( FormSectionEvent event ) {
PageState ps = event.getPageState(); // PageState ps = event.getPageState();
return (String) m_useContext.getValue( ps ); // return (String) m_useContext.getValue( ps );
} // }
//
public Form getForm() { // public Form getForm() {
return m_form; // return m_form;
} // }
//
public SaveCancelSection getSaveCancelSection() { // public SaveCancelSection getSaveCancelSection() {
return m_saveCancel; // return m_saveCancel;
} // }
} // }
private class UniqueUseContextListener implements ParameterListener { private class UniqueUseContextListener implements ParameterListener {
public void validate( ParameterEvent ev ) public void validate( ParameterEvent ev )