CCM NG: FolderAdminPane ported to CCM NG
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4241 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
f69b3e51d4
commit
b6ede27c36
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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.ui;
|
||||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.form.Submit;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
/**
|
||||
* @author Justin Ross
|
||||
*/
|
||||
public abstract class BaseDeleteForm extends BaseForm
|
||||
implements FormProcessListener {
|
||||
|
||||
protected final Submit m_delete;
|
||||
protected final Submit m_cancel;
|
||||
|
||||
public BaseDeleteForm(final Component message) {
|
||||
super("delete", new Label(gz("cms.ui.attention")));
|
||||
|
||||
addComponent(message);
|
||||
|
||||
m_delete = new Submit("delete", gz("cms.ui.delete"));
|
||||
addAction(m_delete);
|
||||
|
||||
m_cancel = new Submit("cancel", gz("cms.ui.cancel"));
|
||||
addAction(m_cancel);
|
||||
|
||||
addProcessListener(this);
|
||||
}
|
||||
|
||||
public BaseDeleteForm(final GlobalizedMessage message) {
|
||||
this(new Label(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isCancelled(final PageState state) {
|
||||
return m_cancel.isSelected(state);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,194 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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.ui;
|
||||
|
||||
import com.arsdigita.bebop.BoxPanel;
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.GridPanel;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.form.FormErrorDisplay;
|
||||
import com.arsdigita.bebop.form.Submit;
|
||||
import com.arsdigita.bebop.form.TextArea;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.bebop.parameters.NotEmptyValidationListener;
|
||||
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
||||
import com.arsdigita.bebop.parameters.StringLengthValidationListener;
|
||||
import com.arsdigita.bebop.parameters.TrimmedStringParameter;
|
||||
import com.arsdigita.cms.ui.item.ContentItemRequestLocal;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.toolbox.ui.Cancellable;
|
||||
import com.arsdigita.toolbox.ui.Section;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.librecms.CmsConstants;
|
||||
|
||||
/**
|
||||
* A convenience class for CMS forms.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
|
||||
*/
|
||||
public abstract class BaseForm extends Form implements Cancellable {
|
||||
|
||||
private static final Logger s_log = Logger.getLogger(BaseForm.class);
|
||||
|
||||
private final BodySection m_body;
|
||||
private final BoxPanel m_actions;
|
||||
private Cancel m_cancel;
|
||||
|
||||
protected BaseForm(final String name, final Label heading) {
|
||||
super(name, new GridPanel(1));
|
||||
|
||||
setRedirecting(true);
|
||||
|
||||
m_body = new BodySection(heading);
|
||||
m_actions = new BoxPanel(BoxPanel.HORIZONTAL);
|
||||
|
||||
add(m_body);
|
||||
add(m_actions);
|
||||
|
||||
addComponent(new FormErrorDisplay(this));
|
||||
}
|
||||
|
||||
protected BaseForm(final String name,
|
||||
final GlobalizedMessage heading) {
|
||||
this(name, new Label(heading));
|
||||
}
|
||||
|
||||
private class BodySection extends Section {
|
||||
|
||||
final SimpleContainer m_container;
|
||||
|
||||
BodySection(final Label heading) {
|
||||
setHeading(heading);
|
||||
|
||||
m_container = new GridPanel(2);
|
||||
setBody(m_container);
|
||||
}
|
||||
|
||||
final void add(final Component component) {
|
||||
m_container.add(component);
|
||||
}
|
||||
|
||||
final void add(final Component component, int hints) {
|
||||
m_container.add(component, hints);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected final void addComponent(final Component component) {
|
||||
m_body.add(component, GridPanel.FULL_WIDTH);
|
||||
}
|
||||
|
||||
protected final void addField(final Label name, final Component widget) {
|
||||
m_body.add(name);
|
||||
m_body.add(widget);
|
||||
}
|
||||
|
||||
protected final void addField(final GlobalizedMessage name,
|
||||
final Component widget) {
|
||||
addField(new Label(name), widget);
|
||||
}
|
||||
|
||||
protected final void addAction(final Submit button) {
|
||||
m_actions.add(button);
|
||||
}
|
||||
|
||||
protected final void addAction(final Cancel button) {
|
||||
m_cancel = button;
|
||||
m_actions.add(button);
|
||||
}
|
||||
|
||||
protected final void addSecurityListener(final String action) {
|
||||
addSubmissionListener(new FormSecurityListener(action));
|
||||
}
|
||||
|
||||
protected final void addSecurityListener(final String action,
|
||||
final ContentItemRequestLocal item) {
|
||||
addSubmissionListener(new FormSecurityListener(action, item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled(final PageState state) {
|
||||
return m_cancel != null && m_cancel.isSelected(state);
|
||||
}
|
||||
|
||||
protected final class Name extends TextField {
|
||||
|
||||
public Name(final String key, final int max, final boolean required) {
|
||||
super(new TrimmedStringParameter(key));
|
||||
|
||||
if (required) {
|
||||
addValidationListener(new NotEmptyValidationListener());
|
||||
}
|
||||
|
||||
setSize(40);
|
||||
setMaxLength(max);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected final class Description extends TextArea {
|
||||
|
||||
public Description(final String key,
|
||||
final int maxLength,
|
||||
final boolean isRequired) {
|
||||
super(new TrimmedStringParameter(key));
|
||||
Assert.isTrue(maxLength > 0, "Max length cannot be negative");
|
||||
|
||||
if (isRequired) {
|
||||
addValidationListener(NotNullValidationListener.DEFAULT);
|
||||
}
|
||||
addValidationListener(new StringLengthValidationListener(maxLength));
|
||||
setCols(40);
|
||||
setRows(5);
|
||||
setWrap(TextArea.SOFT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected final class Finish extends Submit {
|
||||
|
||||
public Finish() {
|
||||
super("finish", gz("cms.ui.finish"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected final class Cancel extends Submit {
|
||||
|
||||
public Cancel() {
|
||||
super("cancel", gz("cms.ui.cancel"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static final GlobalizedMessage gz(final String key) {
|
||||
return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE);
|
||||
}
|
||||
|
||||
protected static final String lz(final String key) {
|
||||
return (String) gz(key).localize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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.ui;
|
||||
|
||||
import com.arsdigita.bebop.Container;
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.toolbox.ui.Cancellable;
|
||||
|
||||
/**
|
||||
* A convenience class for CMS forms. The "CMS Admin" class eliminates
|
||||
* the nested tables created by the Bebop ColumnPanel. This is mainly
|
||||
* to increase form rendering.
|
||||
*
|
||||
* @author Michael Pih
|
||||
*/
|
||||
public class CMSForm extends Form implements Cancellable {
|
||||
|
||||
public static final String CLASS = "CMS Admin";
|
||||
|
||||
public CMSForm(final String name) {
|
||||
super(name);
|
||||
|
||||
setClassAttr(CLASS);
|
||||
getPanel().setClassAttr(CLASS);
|
||||
}
|
||||
|
||||
public CMSForm(final String name, final Container panel) {
|
||||
super(name, panel);
|
||||
|
||||
setClassAttr(CLASS);
|
||||
panel.setClassAttr(CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the form has been cancelled.
|
||||
* Override this method if the form can be cancelled.
|
||||
*
|
||||
* @param state The page state
|
||||
* @return true if the form is cancelled, false otherwise
|
||||
*/
|
||||
public boolean isCancelled(PageState state) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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.ui;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import com.arsdigita.cms.dispatcher.Utilities;
|
||||
import com.arsdigita.cms.ui.item.ContentItemRequestLocal;
|
||||
import com.arsdigita.dispatcher.AccessDeniedException;
|
||||
|
||||
import org.libreccm.security.User;
|
||||
|
||||
import com.arsdigita.util.Assert;
|
||||
import com.arsdigita.web.Web;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
|
||||
/**
|
||||
* @author Justin Ross <jross@redhat.com>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class FormSecurityListener implements FormSubmissionListener {
|
||||
|
||||
private static Logger s_log = Logger.getLogger(FormSecurityListener.class);
|
||||
|
||||
private final String m_action;
|
||||
private final ContentItemRequestLocal m_item;
|
||||
|
||||
public FormSecurityListener(final String action,
|
||||
final ContentItemRequestLocal item) {
|
||||
Assert.exists(action, String.class);
|
||||
|
||||
m_action = action;
|
||||
m_item = item;
|
||||
}
|
||||
|
||||
public FormSecurityListener(final String action) {
|
||||
this(action, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void submitted(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
|
||||
|
||||
if (m_item == null) {
|
||||
if (permissionChecker.isPermitted(m_action)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
final ContentItem item = m_item.getContentItem(state);
|
||||
|
||||
if (permissionChecker.isPermitted(m_action, item)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new AccessDeniedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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.ui.folder;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.ParameterEvent;
|
||||
import com.arsdigita.bebop.event.ParameterListener;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
final class ChildUniqueValidationListener implements ParameterListener {
|
||||
|
||||
private final FolderRequestLocal m_parent;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param parent
|
||||
*/
|
||||
public ChildUniqueValidationListener(final FolderRequestLocal parent) {
|
||||
m_parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param e
|
||||
* @throws FormProcessException
|
||||
*/
|
||||
@Override
|
||||
public final void validate(final ParameterEvent e)
|
||||
throws FormProcessException {
|
||||
final PageState state = e.getPageState();
|
||||
final String name = (String) e.getParameterData().getValue();
|
||||
|
||||
if (name != null) {
|
||||
validateNameUniqueness(m_parent.getFolder(state), name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parent
|
||||
* @param name
|
||||
* @throws FormProcessException
|
||||
*/
|
||||
private void validateNameUniqueness(final Category parent,
|
||||
final String name)
|
||||
throws FormProcessException {
|
||||
|
||||
//ToDo
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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.ui.folder;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
|
||||
class FolderAddForm extends FolderBaseForm {
|
||||
|
||||
private static Logger s_log = Logger.getLogger(FolderAddForm.class);
|
||||
|
||||
private final SingleSelectionModel<Long> m_model;
|
||||
private final FolderRequestLocal m_parent;
|
||||
|
||||
public FolderAddForm(final SingleSelectionModel model,
|
||||
final FolderRequestLocal parent) {
|
||||
super("folder-add");
|
||||
|
||||
m_model = model;
|
||||
m_parent = parent;
|
||||
|
||||
m_fragment.addValidationListener(new ChildUniqueValidationListener(
|
||||
parent));
|
||||
|
||||
addProcessListener(new ProcessListener());
|
||||
}
|
||||
|
||||
private class ProcessListener implements FormProcessListener {
|
||||
|
||||
public final void process(final FormSectionEvent e)
|
||||
throws FormProcessException {
|
||||
final PageState state = e.getPageState();
|
||||
|
||||
final Category folder = new Category();
|
||||
|
||||
folder.setParentCategory(m_parent.getFolder(state));
|
||||
folder.setDisplayName((String) m_title.getValue(state));
|
||||
folder.setName((String) m_fragment.getValue(state));
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryRepository categoryRepo = cdiUtil.findBean(
|
||||
CategoryRepository.class);
|
||||
categoryRepo.save(folder);
|
||||
|
||||
m_model.setSelectedKey(state, folder.getObjectId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -29,26 +29,29 @@ import com.arsdigita.bebop.event.ActionListener;
|
|||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.cms.ContentSection;
|
||||
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
|
||||
import com.arsdigita.cms.ui.BaseDeleteForm;
|
||||
import com.arsdigita.cms.util.GlobalizationUtil;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.toolbox.ui.SelectionPanel;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.librecms.CmsConstants;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* A pane that contains a folder tree on the left and a folder
|
||||
* manipulator on the right.
|
||||
* A pane that contains a folder tree on the left and a folder manipulator on
|
||||
* the right.
|
||||
*
|
||||
* @author Justin Ross <jross@redhat.com>
|
||||
* @version $Id: FolderAdminPane.java 1942 2009-05-29 07:53:23Z terry $
|
||||
*/
|
||||
public class FolderAdminPane extends SelectionPanel {
|
||||
|
||||
private static final Logger s_log = Logger.getLogger
|
||||
(FolderAdminPane.class);
|
||||
private static final Logger s_log = Logger.getLogger(FolderAdminPane.class);
|
||||
|
||||
private final FolderRequestLocal m_folder;
|
||||
|
||||
|
|
@ -69,16 +72,23 @@ public class FolderAdminPane extends SelectionPanel {
|
|||
setEdit(new ActionLink(new Label(gz("cms.ui.folder.edit"))),
|
||||
new FolderEditForm(m_folder));
|
||||
|
||||
final BaseDeleteForm delete = new BaseDeleteForm
|
||||
(new Label(gz("cms.ui.folder.delete_prompt"))) {
|
||||
public final void process(final FormSectionEvent e)
|
||||
throws FormProcessException {
|
||||
final PageState state = e.getPageState();
|
||||
final BaseDeleteForm delete = new BaseDeleteForm(new Label(gz(
|
||||
"cms.ui.folder.delete_prompt"))) {
|
||||
|
||||
m_folder.getFolder(state).delete();
|
||||
getSelectionModel().clearSelection(state);
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public final void process(final FormSectionEvent e)
|
||||
throws FormProcessException {
|
||||
final PageState state = e.getPageState();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryRepository categoryRepo = cdiUtil.findBean(
|
||||
CategoryRepository.class);
|
||||
|
||||
categoryRepo.delete(m_folder.getFolder(state));
|
||||
getSelectionModel().clearSelection(state);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
setDelete(new ActionLink(new Label(gz("cms.ui.folder.delete"))),
|
||||
delete);
|
||||
|
|
@ -91,6 +101,7 @@ public class FolderAdminPane extends SelectionPanel {
|
|||
addAction(getDeleteLink());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(final Page page) {
|
||||
super.register(page);
|
||||
|
||||
|
|
@ -99,31 +110,35 @@ public class FolderAdminPane extends SelectionPanel {
|
|||
}
|
||||
|
||||
private class PreselectListener implements ActionListener {
|
||||
|
||||
@Override
|
||||
public final void actionPerformed(final ActionEvent e) {
|
||||
final PageState state = e.getPageState();
|
||||
final SingleSelectionModel model = getSelectionModel();
|
||||
final SingleSelectionModel<Long> model = getSelectionModel();
|
||||
|
||||
if (!model.isSelected(state)) {
|
||||
final BigDecimal value = (BigDecimal) state.getValue(m_param);
|
||||
final Long value = (Long) state.getValue(m_param);
|
||||
|
||||
if (value == null) {
|
||||
final ContentSection section =
|
||||
CMS.getContext().getContentSection();
|
||||
final ContentSection section = CMS.getContext()
|
||||
.getContentSection();
|
||||
|
||||
model.setSelectedKey
|
||||
(state, section.getRootFolder().getID());
|
||||
model.setSelectedKey(state, section.getRootDocumentsFolder()
|
||||
.getObjectId());
|
||||
} else {
|
||||
model.setSelectedKey(state, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static GlobalizedMessage gz(final String key) {
|
||||
return GlobalizationUtil.globalize(key);
|
||||
return new GlobalizedMessage(key, CmsConstants.CMS_FOLDER_BUNDLE);
|
||||
}
|
||||
|
||||
private static String lz(final String key) {
|
||||
return (String) gz(key).localize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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.ui.folder;
|
||||
|
||||
import com.arsdigita.bebop.GridPanel;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SaveCancelSection;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
||||
import com.arsdigita.bebop.parameters.TrimmedStringParameter;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import com.arsdigita.cms.ui.CMSForm;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.web.Web;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.librecms.CmsConstants;
|
||||
|
||||
/**
|
||||
* Class FolderForm implements the basic form for creating or renaming folders.
|
||||
*
|
||||
* @author Jon Orris <jorris@redhat.com>
|
||||
* @version $Id$
|
||||
*/
|
||||
abstract class FolderBaseForm extends CMSForm {
|
||||
|
||||
private static Logger s_log = Logger.getLogger(FolderBaseForm.class);
|
||||
|
||||
public static final String NAME = "ContentItemName";
|
||||
public static final String TITLE = "ContentPageTitle";
|
||||
|
||||
private static final String TITLE_ON_FOCUS = "if (this.form." + NAME + ".value == '') {"
|
||||
+ " defaulting = true;" + " this.form."
|
||||
+ NAME + ".value = urlize(this.value);" + "}";
|
||||
|
||||
private static final String TITLE_ON_KEY_UP = "if (defaulting) {" + " this.form." + NAME
|
||||
+ ".value = urlize(this.value)" + "}";
|
||||
|
||||
private static final String FRAGMENT_ON_FOCUS = "defaulting = false";
|
||||
|
||||
private static final String FRAGMENT_ON_BLUR = "if (this.value == '') {"
|
||||
+ " defaulting = true;"
|
||||
+ " this.value = urlize(this.form." + TITLE
|
||||
+ ".value)" + "} else {"
|
||||
+ " this.value = urlize(this.value);" + "}";
|
||||
|
||||
private Label m_script = new Label(
|
||||
String.format(
|
||||
"<script language=\"javascript\" src=\"%s/javascript/manipulate-input.js\"></script>",
|
||||
Web.getWebappContextPath()),
|
||||
false);
|
||||
|
||||
final TextField m_title;
|
||||
final TextField m_fragment;
|
||||
final SaveCancelSection m_submits;
|
||||
|
||||
public FolderBaseForm(final String name) {
|
||||
super(name);
|
||||
|
||||
add(m_script, GridPanel.FULL_WIDTH);
|
||||
|
||||
// Title
|
||||
add(new Label(gz("cms.ui.folder.name")));
|
||||
|
||||
m_title = new TextField(new TrimmedStringParameter(TITLE));
|
||||
add(m_title);
|
||||
|
||||
m_title.addValidationListener(new NotNullValidationListener());
|
||||
m_title.setOnFocus(TITLE_ON_FOCUS);
|
||||
|
||||
m_title.setOnFocus(TITLE_ON_FOCUS);
|
||||
m_title.setOnKeyUp(TITLE_ON_KEY_UP);
|
||||
|
||||
// Fragment
|
||||
add(new Label(gz("cms.ui.folder.fragment")));
|
||||
|
||||
m_fragment = new TextField(new TrimmedStringParameter(NAME));
|
||||
add(m_fragment);
|
||||
|
||||
m_fragment.addValidationListener(new NotNullValidationListener());
|
||||
|
||||
m_fragment.setOnFocus(FRAGMENT_ON_FOCUS);
|
||||
m_fragment.setOnBlur(FRAGMENT_ON_BLUR);
|
||||
|
||||
m_submits = new SaveCancelSection();
|
||||
add(m_submits, GridPanel.FULL_WIDTH);
|
||||
}
|
||||
|
||||
public final boolean isCancelled(final PageState state) {
|
||||
return m_submits.getCancelButton().isSelected(state);
|
||||
}
|
||||
|
||||
private static GlobalizedMessage gz(final String key) {
|
||||
return new GlobalizedMessage(key, CmsConstants.CMS_FOLDER_BUNDLE);
|
||||
}
|
||||
|
||||
private static String lz(final String key) {
|
||||
return (String) gz(key).localize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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.ui.folder;
|
||||
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormInitListener;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
|
||||
class FolderEditForm extends FolderBaseForm {
|
||||
|
||||
private static Logger s_log = Logger.getLogger(FolderEditForm.class);
|
||||
|
||||
private final FolderRequestLocal m_folder;
|
||||
|
||||
public FolderEditForm(final FolderRequestLocal folder) {
|
||||
super("folder-edit");
|
||||
|
||||
m_folder = folder;
|
||||
|
||||
// XXX need to do name uniqueness valdation on m_fragment here
|
||||
// as well.
|
||||
|
||||
addInitListener(new InitListener());
|
||||
addProcessListener(new ProcessListener());
|
||||
}
|
||||
|
||||
private static FolderRequestLocal parent(final FolderRequestLocal folder) {
|
||||
final FolderRequestLocal parent = new FolderRequestLocal(null) {
|
||||
@Override
|
||||
protected final Object initialValue(final PageState state) {
|
||||
return folder.getFolder(state).getParent().get();
|
||||
}
|
||||
};
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
private class InitListener implements FormInitListener {
|
||||
public final void init(final FormSectionEvent e) {
|
||||
final PageState state = e.getPageState();
|
||||
|
||||
final Category folder = m_folder.getFolder(state);
|
||||
|
||||
m_title.setValue(state, folder.getDisplayName());
|
||||
m_fragment.setValue(state, folder.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private class ProcessListener implements FormProcessListener {
|
||||
public final void process(final FormSectionEvent e)
|
||||
throws FormProcessException {
|
||||
final PageState state = e.getPageState();
|
||||
|
||||
final Category folder = m_folder.getFolder(state);
|
||||
|
||||
folder.setDisplayName((String) m_title.getValue(state));
|
||||
folder.setName((String) m_fragment.getValue(state));
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryRepository categoryRepo = cdiUtil.findBean(CategoryRepository.class);
|
||||
categoryRepo.save(folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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.ui.item;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.RequestLocal;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link RequestLocal} storing a content item.
|
||||
*/
|
||||
public abstract class ContentItemRequestLocal extends RequestLocal {
|
||||
|
||||
public final ContentItem getContentItem(final PageState state) {
|
||||
final ContentItem item = (ContentItem) get(state);
|
||||
|
||||
Assert.exists(item, "ContentItem item");
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +50,6 @@ import org.apache.log4j.Logger;
|
|||
|
||||
/**
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ModalPanel extends ComponentMap {
|
||||
|
||||
|
|
|
|||
|
|
@ -37,13 +37,12 @@ import org.apache.log4j.Logger;
|
|||
|
||||
/**
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SelectionPanel extends LayoutPanel implements Resettable {
|
||||
|
||||
private static final Logger s_log = Logger.getLogger(SelectionPanel.class);
|
||||
|
||||
private SingleSelectionModel m_model;
|
||||
private SingleSelectionModel<Long> m_model;
|
||||
private Component m_selector;
|
||||
private ActionGroup m_group;
|
||||
private final ModalPanel m_body;
|
||||
|
|
@ -60,7 +59,7 @@ public class SelectionPanel extends LayoutPanel implements Resettable {
|
|||
|
||||
protected void build(final Component title,
|
||||
final Component selector,
|
||||
final SingleSelectionModel model) {
|
||||
final SingleSelectionModel<Long> model) {
|
||||
m_model = model;
|
||||
m_selector = selector;
|
||||
|
||||
|
|
@ -198,11 +197,11 @@ public class SelectionPanel extends LayoutPanel implements Resettable {
|
|||
m_selector = selector;
|
||||
}
|
||||
|
||||
public final void setSelectionModel(final SingleSelectionModel model) {
|
||||
public final void setSelectionModel(final SingleSelectionModel<Long> model) {
|
||||
m_model = model;
|
||||
}
|
||||
|
||||
public final SingleSelectionModel getSelectionModel() {
|
||||
public final SingleSelectionModel<Long> getSelectionModel() {
|
||||
return m_model;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue