ImageSelectPage und ImagePane

Weitere Korrekturen für das EventHandling
endlich die image_search.jsp eingecheckt...

git-svn-id: https://svn.libreccm.org/ccm/trunk@1773 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2012-07-17 06:03:14 +00:00
parent b988c2de2b
commit 4a543c0f5d
6 changed files with 63 additions and 113 deletions

View File

@ -20,12 +20,12 @@ import org.apache.log4j.Logger;
*
* @author Sören Bernstein (quasimodo) <sbernstein@zes.uni-bremen.de>
*/
public class ImageComponentAttachListener implements FormInitListener, FormProcessListener {
public abstract class ImageComponentAbstractListener implements FormInitListener, FormProcessListener {
private static final Logger s_log = Logger.getLogger(ImageComponentSelectListener.class);
MapComponentSelectionModel m_imageComponent;
public ImageComponentAttachListener(MapComponentSelectionModel imageComponent) {
public ImageComponentAbstractListener(MapComponentSelectionModel imageComponent) {
super();
m_imageComponent = imageComponent;
}
@ -33,12 +33,9 @@ public class ImageComponentAttachListener implements FormInitListener, FormProce
public void init(FormSectionEvent event)
throws FormProcessException {
PageState ps = event.getPageState();
setImageComponent(ps, ImageComponent.LIBRARY);
// ItemImageAttachment attachment = m_imageStep.getAttachment(ps);
// if (null == attachment) {
// XXX: Do something
// }
if (!m_imageComponent.isSelected(ps)) {
setImageComponent(ps, ImageComponent.LIBRARY);
}
}
public void process(FormSectionEvent event) throws FormProcessException {
@ -51,33 +48,12 @@ public class ImageComponentAttachListener implements FormInitListener, FormProce
ReusableImageAsset image = component.getImage(event);
// ContentItem item = m_imageStep.getItem(ps);
// if (null == item) {
// s_log.error("No item selected in ImageStepEdit",
// new RuntimeException());
// return;
// }
// ItemImageAttachment attachment = m_imageStep.getAttachment(ps);
// if (null == attachment) {
// attachment = new ItemImageAttachment(item, image);
// }
// attachment.setCaption(component.getCaption(event));
// We only set the description and title based on the UI in
// the case where getIsImageStepDescriptionAndTitleShown is true.
// Otherwise, we leave this as the default value. This means
// existing values are not overwritten if the image is edited when
// isImageStepDescriptionAndTitleShown is false.
// if (ItemImageAttachment.getConfig().getIsImageStepDescriptionAndTitleShown()) {
// attachment.setDescription(component.getDescription(event));
// attachment.setTitle(component.getTitle(event));
// }
// attachment.setUseContext(component.getUseContext(event));
processImage(event, ps, component, image);
}
private ImageComponent getImageComponent(PageState ps) {
protected abstract void processImage(FormSectionEvent event, PageState ps, ImageComponent component, ReusableImageAsset image);
protected ImageComponent getImageComponent(PageState ps) {
if (!m_imageComponent.isSelected(ps)) {
if (s_log.isDebugEnabled()) {
s_log.debug("No component selected");
@ -91,7 +67,7 @@ public class ImageComponentAttachListener implements FormInitListener, FormProce
}
private void setImageComponent(PageState ps, final String activeKey) {
protected void setImageComponent(PageState ps, final String activeKey) {
m_imageComponent.setSelectedKey(ps, activeKey);
if (s_log.isDebugEnabled()) {

View File

@ -4,51 +4,26 @@
*/
package com.arsdigita.cms.ui;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.MapComponentSelectionModel;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.cms.ReusableImageAsset;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.Map;
import org.apache.log4j.Logger;
/**
*
* @author Sören Bernstein (quasimodo) <sbernstein@zes.uni-bremen.de>
*/
public class ImageComponentSelectListener implements FormInitListener, FormProcessListener {
public class ImageComponentSelectListener extends ImageComponentAbstractListener {
private static final Logger s_log = Logger.getLogger(ImageComponentSelectListener.class);
MapComponentSelectionModel m_imageComponent;
public ImageComponentSelectListener(MapComponentSelectionModel imageComponent) {
super();
m_imageComponent = imageComponent;
super(imageComponent);
}
public void init(FormSectionEvent event)
throws FormProcessException {
PageState ps = event.getPageState();
this.m_imageComponent.getComponent(ps);
setImageComponent(ps, ImageComponent.LIBRARY);
}
public void process(FormSectionEvent event) throws FormProcessException {
PageState ps = event.getPageState();
ImageComponent component = getImageComponent(ps);
if (!component.getSaveCancelSection().getSaveButton().isSelected(ps)) {
return;
}
ReusableImageAsset image = component.getImage(event);
protected void processImage(FormSectionEvent event, PageState ps, ImageComponent component, ReusableImageAsset image) {
// SELECT {
String name = image.getDisplayName();
BigDecimal id = image.getID();
@ -56,41 +31,4 @@ public class ImageComponentSelectListener implements FormInitListener, FormProce
BigDecimal height = image.getHeight();
// SELECT }
}
private ImageComponent getImageComponent(PageState ps) {
if (!m_imageComponent.isSelected(ps)) {
if (s_log.isDebugEnabled()) {
s_log.debug("No component selected");
s_log.debug("Selected: " + m_imageComponent.getComponent(ps));
}
m_imageComponent.setSelectedKey(ps, ImageComponent.UPLOAD);
}
return (ImageComponent) m_imageComponent.getComponent(ps);
}
private void setImageComponent(PageState ps, final String activeKey) {
m_imageComponent.setSelectedKey(ps, activeKey);
if (s_log.isDebugEnabled()) {
s_log.debug("Selected component: " + activeKey);
}
Map componentsMap = m_imageComponent.getComponentsMap();
Iterator i = componentsMap.keySet().iterator();
while (i.hasNext()) {
Object key = i.next();
Component component = (Component) componentsMap.get(key);
boolean isVisible = activeKey.equals(key);
if (s_log.isDebugEnabled()) {
s_log.debug("Key: " + key + "; Visibility: " + isVisible);
}
ps.setVisible(component, isVisible);
}
}
}

View File

@ -10,6 +10,7 @@ import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Resettable;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.event.ActionListener;
@ -27,7 +28,7 @@ import java.math.BigDecimal;
*
* @author Sören Bernstein (quasimodo) <sbernstein@zes.uni-bremen.de>
*/
public class ImageLibraryComponent extends SimpleContainer implements ImageComponent {
public class ImageLibraryComponent extends SimpleContainer implements ImageComponent, Resettable {
private final ImageChooser m_chooser;
private final ItemSelectionModel m_imageModel;
@ -158,4 +159,11 @@ public class ImageLibraryComponent extends SimpleContainer implements ImageCompo
add(upload, ColumnPanel.FULL_WIDTH);
}
}
// Reset this component
public void reset(PageState ps) {
// clear selection
m_imageModel.clearSelection(ps);
m_chooser.clearKeyword(ps);
}
}

View File

@ -6,9 +6,14 @@ package com.arsdigita.cms.ui;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.MapComponentSelectionModel;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.TabbedPane;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.event.RequestEvent;
import com.arsdigita.bebop.event.RequestListener;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.CMSConfig;
@ -31,6 +36,7 @@ public class ImageSelectPage extends CMSPage {
private BigDecimalParameter m_sectionId;
private final StringParameter m_imageComponentKey;
private final MapComponentSelectionModel m_imageComponent;
private final ImageComponentSelectListener m_selectListener;
private static final CMSConfig s_conf = CMSConfig.getInstance();
private static final boolean LIMIT_TO_CONTENT_SECTION = false;
public static final String CONTENT_SECTION = "section_id";
@ -49,20 +55,35 @@ public class ImageSelectPage extends CMSPage {
new ParameterSingleSelectionModel(m_imageComponentKey);
m_imageComponent =
new MapComponentSelectionModel(componentModel, new HashMap());
m_selectListener = new ImageComponentSelectListener(m_imageComponent);
m_tabbedPane = createTabbedPane();
m_tabbedPane.setIdAttr("page-body");
add(m_tabbedPane);
// ActionListener to change the image component state param to the right value
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
final PageState ps = event.getPageState();
if (m_tabbedPane.getCurrentPane(ps).equals(m_imageLibrary)) {
m_imageComponent.setSelectedKey(ps, ImageComponent.LIBRARY);
}
if (m_tabbedPane.getCurrentPane(ps).equals(m_imageUpload)) {
m_imageComponent.setSelectedKey(ps, ImageComponent.UPLOAD);
}
}
});
addGlobalStateParam(m_imageComponentKey);
}
protected ImageLibraryComponent getImageLibraryPane() {
if (m_imageLibrary == null) {
m_imageLibrary = new ImageLibraryComponent(ImageComponent.SELECT_IMAGE);
m_imageLibrary.getForm().addInitListener(new ImageComponentSelectListener(m_imageComponent));
m_imageLibrary.getForm().addProcessListener(new ImageComponentSelectListener(m_imageComponent));
m_imageLibrary.getForm().addInitListener(m_selectListener);
m_imageLibrary.getForm().addProcessListener(m_selectListener);
m_imageComponent.getComponentsMap().put(ImageComponent.LIBRARY, m_imageLibrary);
}
return m_imageLibrary;
@ -72,8 +93,8 @@ public class ImageSelectPage extends CMSPage {
if (m_imageUpload == null) {
m_imageUpload = new ImageUploadComponent(ImageComponent.SELECT_IMAGE);
m_imageUpload.getForm().addInitListener(new ImageComponentSelectListener(m_imageComponent));
m_imageUpload.getForm().addProcessListener(new ImageComponentSelectListener(m_imageComponent));
m_imageUpload.getForm().addInitListener(m_selectListener);
m_imageUpload.getForm().addProcessListener(m_selectListener);
m_imageComponent.getComponentsMap().put(ImageComponent.UPLOAD, m_imageUpload);
}
return m_imageUpload;
@ -83,8 +104,8 @@ public class ImageSelectPage extends CMSPage {
TabbedPane pane = new TabbedPane();
pane.setClassAttr(XSL_CLASS);
addToPane(pane, "library", getImageLibraryPane());
addToPane(pane, "upload", getImageUploadPane());
addToPane(pane, ImageComponent.LIBRARY, getImageLibraryPane());
addToPane(pane, ImageComponent.UPLOAD, getImageUploadPane());
pane.setDefaultPane(m_imageLibrary);
return pane;

View File

@ -32,6 +32,7 @@ public class ImagesPane extends LayoutPanel implements Resettable {
//private ImageChooser imageChooser;
private final StringParameter m_imageComponentKey;
private final MapComponentSelectionModel m_imageComponent;
// private final ImageComponentAdminListener m_adminListener;
public ImagesPane() {
// Left column is empty, this is only to provide the same layout for all
@ -47,20 +48,21 @@ public class ImagesPane extends LayoutPanel implements Resettable {
m_imageComponent = new MapComponentSelectionModel(componentModel, new HashMap());
Map selectors = m_imageComponent.getComponentsMap();
// m_adminListener = new ImageComponentAdminListener(m_imageComponent);
ImageUploadComponent upload = new ImageUploadComponent(ImageComponent.ADMIN_IMAGES);
//upload.getForm().addInitListener(new ImageComponentAdminListener(m_imageComponent));
// For future use
// upload.addProcessListener(new ImageComponentAdminListener(m_imageComponent));
//upload.getForm().addInitListener(m_adminListener);
// upload.addProcessListener(m_adminListener);
selectors.put(ImageComponent.UPLOAD, upload);
body.addSegment(
new Label(GlobalizationUtil.globalize("cms.ui.image_upload")),
upload);
ImageLibraryComponent library = new ImageLibraryComponent(ImageComponent.ADMIN_IMAGES);
//library.getForm().addInitListener(new ImageComponentAdminListener(m_imageComponent));
// For future use
// library.getForm().addProcessListener(new ImageComponentAdminListener);
//library.getForm().addInitListener(m_adminListener);
// library.getForm().addProcessListener(m_adminListener);
// library.addUploadLink(new ActionListener() {
//
// public void actionPerformed(ActionEvent ev) {

View File

@ -225,6 +225,7 @@ public class SecurityPropertyEditor extends PropertyEditor {
* @param form The form
* @param cancelButton the "Cancel" button on the form
*/
@Override
public void addListeners(FormSection form, Submit cancelButton) {
addSecurityListener(form);
super.addListeners(form, cancelButton);
@ -247,6 +248,7 @@ public class SecurityPropertyEditor extends PropertyEditor {
super();
}
@Override
public PropertyEditorModel makeModel(PropertyEditor p, PageState s) {
return new AccessListModel (
getProperties(p),
@ -273,16 +275,19 @@ public class SecurityPropertyEditor extends PropertyEditor {
m_manager = Utilities.getSecurityManager(m_state);
}
@Override
public boolean next() {
while(super.next()) {
Object key = getKey();
ComponentAccess ca = (ComponentAccess)m_access.get(key);
if(ca == null) // No access restricitons
if(ca == null) {
return true;
}
if ( ca.canAccess(m_state, m_manager) ) // Access checks out
if ( ca.canAccess(m_state, m_manager) ) {
return true;
}
// Otherwise, skip the property
}