More "Getting Category Stuff Done" Commits

Lots of commented code, but it gets better

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4636 8810af33-2d31-482b-a856-94f89814c4df

Former-commit-id: 41518b9a27
pull/2/head
baka 2017-03-22 17:11:44 +00:00
parent d3235eed28
commit 1de004f2e1
5 changed files with 39 additions and 178 deletions

View File

@ -18,17 +18,7 @@
*/ */
package com.arsdigita.cms.ui.category; package com.arsdigita.cms.ui.category;
import com.arsdigita.bebop.ActionLink; import com.arsdigita.bebop.*;
import com.arsdigita.bebop.BaseLink;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Link;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.event.ActionEvent; import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener; import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.event.ChangeEvent; import com.arsdigita.bebop.event.ChangeEvent;
@ -73,6 +63,7 @@ import org.libreccm.security.User;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemManager; import org.librecms.contentsection.ContentItemManager;
import org.librecms.contentsection.privileges.AdminPrivileges; import org.librecms.contentsection.privileges.AdminPrivileges;
import org.librecms.contentsection.privileges.ItemPrivileges;
/** /**
* Edits a single category. * Edits a single category.
@ -129,8 +120,8 @@ class CategoryItemPane extends BaseItemPane {
//Move link //Move link
final ActionLink moveLink = new MoveLink(new Label(gz("cms.ui.category.move"))); final ActionLink moveLink = new MoveLink(new Label(gz("cms.ui.category.move")));
//final Form moveForm = new CategoryMoveForm(m_category, contextModel); final Form moveForm = new CategoryMoveForm(m_category, contextModel);
//add(moveForm); add(moveForm);
ViewItemLink viewIndexLink = new ViewItemLink(new Label(gz( ViewItemLink viewIndexLink = new ViewItemLink(new Label(gz(
"cms.ui.category.view_index_item")), ""); "cms.ui.category.view_index_item")), "");
@ -174,13 +165,13 @@ class CategoryItemPane extends BaseItemPane {
} }
}; };
/*
CategoryLocalizationAddForm addCategoryLocalizationForm = CategoryLocalizationAddForm addCategoryLocalizationForm =
new CategoryLocalizationAddForm(m_category); new CategoryLocalizationAddForm(m_category);
m_detailPane.add(new CategoryLocalizationSection(addCategoryLocalizationLink)); m_detailPane.add(new CategoryLocalizationSection(addCategoryLocalizationLink));
add(addCategoryLocalizationForm); add(addCategoryLocalizationForm);
connect(addCategoryLocalizationLink, addCategoryLocalizationForm); connect(addCategoryLocalizationLink, addCategoryLocalizationForm);
connect(addCategoryLocalizationForm);*/ connect(addCategoryLocalizationForm);
// Quasimodo: END // Quasimodo: END
// Subcategories // Subcategories
@ -189,11 +180,11 @@ class CategoryItemPane extends BaseItemPane {
// Linked categories // Linked categories
final ActionLink linkAddLink = new ActionLink(new Label(gz("cms.ui.category.linked_add"))); final ActionLink linkAddLink = new ActionLink(new Label(gz("cms.ui.category.linked_add")));
//final Form linkForm = new LinkForm(m_category); final Form linkForm = new LinkForm(m_category);
//add(linkForm); add(linkForm);
//linkAddLink.addActionListener(new NavigationListener(linkForm)); linkAddLink.addActionListener(new NavigationListener(linkForm));
//linkForm.addSubmissionListener(new CancelListener(linkForm)); linkForm.addSubmissionListener(new CancelListener(linkForm));
m_detailPane.add(new LinkedCategorySection(linkAddLink)); m_detailPane.add(new LinkedCategorySection(linkAddLink));
@ -201,13 +192,14 @@ class CategoryItemPane extends BaseItemPane {
m_detailPane.add(new AdminVisible(new CategoryTemplateSection())); m_detailPane.add(new AdminVisible(new CategoryTemplateSection()));
// Permissions // Permissions
m_detailPane.add(new PermissionsSection()); //m_detailPane.add(new PermissionsSection());
m_detailPane.add(new Text("PermissionSection Placeholder"));
connect(indexLink, indexForm); connect(indexLink, indexForm);
connect(indexForm); connect(indexForm);
//connect(moveLink, moveForm); connect(moveLink, moveForm);
//connect(moveForm); connect(moveForm);
connect(orderItemsLink, orderItemsForm); connect(orderItemsLink, orderItemsForm);
connect(orderItemsForm); connect(orderItemsForm);
@ -644,8 +636,7 @@ class CategoryItemPane extends BaseItemPane {
if (!indexItem.isPresent()) { if (!indexItem.isPresent()) {
return false; return false;
} else { } else {
return permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, indexItem.get()); return permissionChecker.isPermitted(ItemPrivileges.EDIT, indexItem.get());
//return isItemEditable((ContentItem) indexItem, state);
} }
} }
}; };

View File

@ -65,8 +65,8 @@ public class CategoryMoveForm extends CMSForm {
setMethod(Form.POST); setMethod(Form.POST);
this.selectedCategory = selectedCategory; this.selectedCategory = selectedCategory;
//final Label header = new Label(GlobalizationUtil.globalize("cms.ui.category.move")); final Label header = new Label(GlobalizationUtil.globalize("cms.ui.category.move"));
final Label header = new Label(); //final Label header = new Label();
header.addPrintListener(new PrintListener() { header.addPrintListener(new PrintListener() {
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {

View File

@ -31,11 +31,13 @@ import org.libreccm.categorization.CategoryTreeModelLite;
* Lists category tree. * Lists category tree.
* *
* @author Tri Tran (tri@arsdigita.com) * @author Tri Tran (tri@arsdigita.com)
* @version $Id: CategoryTreeModelBuilder.java 1942 2009-05-29 07:53:23Z terry $ * @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/ */
class CategoryTreeModelBuilder extends LockableImpl class CategoryTreeModelBuilder extends LockableImpl
implements TreeModelBuilder { implements TreeModelBuilder {
private static String DEFAULT_USE_CONTEXT = "<default>";
private SingleSelectionModel m_contextModel = null; private SingleSelectionModel m_contextModel = null;
public CategoryTreeModelBuilder() { public CategoryTreeModelBuilder() {
@ -59,7 +61,7 @@ class CategoryTreeModelBuilder extends LockableImpl
String context = null; String context = null;
if (m_contextModel != null) { if (m_contextModel != null) {
context = (String) m_contextModel.getSelectedKey(state); context = (String) m_contextModel.getSelectedKey(state);
if ((CategoryUseContextModelBuilder.DEFAULT_USE_CONTEXT).equals(context)) { if ((DEFAULT_USE_CONTEXT).equals(context)) {
context = null; context = null;
} }
} }

View File

@ -55,7 +55,7 @@ import java.util.Optional;
public class IndexItemSelectionForm extends CMSForm { public class IndexItemSelectionForm extends CMSForm {
private static final Logger LOGGER = LogManager.getLogger( private static final Logger LOGGER = LogManager.getLogger(
CategoryEditForm.class); IndexItemSelectionForm.class);
private final CategoryRequestLocal m_category; private final CategoryRequestLocal m_category;
private RadioGroup m_options; private RadioGroup m_options;
@ -159,31 +159,28 @@ public class IndexItemSelectionForm extends CMSForm {
addSubmissionListener(new FormSecurityListener(AdminPrivileges.ADMINISTER_CATEGORIES)); addSubmissionListener(new FormSecurityListener(AdminPrivileges.ADMINISTER_CATEGORIES));
// Process listener // Process listener
addProcessListener(new FormProcessListener() { addProcessListener(event -> {
public void process(FormSectionEvent event) PageState state = event.getPageState();
throws FormProcessException { FormData data = event.getFormData();
PageState state = event.getPageState(); ParameterData param = data.getParameter(m_options.getParameterModel().getName());
FormData data = event.getFormData(); String selectedValue = (String) param.getValue();
ParameterData param = data.getParameter(m_options.getParameterModel().getName());
String selectedValue = (String) param.getValue();
Category category Category category
= getCategory(event.getPageState()); = getCategory(event.getPageState());
if (selectedValue != null) { if (selectedValue != null) {
Optional<ContentItem> optionalItem = contentItemRepository.findById(Long.parseLong(selectedValue)); Optional<ContentItem> optionalItem = contentItemRepository.findById(Long.parseLong(selectedValue));
if (optionalItem.isPresent()) { if (optionalItem.isPresent()) {
ContentItem item = contentItemManager.getDraftVersion(optionalItem.get(), ContentItem.class); ContentItem item = contentItemManager.getDraftVersion(optionalItem.get(), ContentItem.class);
try { try {
categoryManager.setIndexObject(category, item); categoryManager.setIndexObject(category, item);
categoryRepository.save(category); categoryRepository.save(category);
} catch (ObjectNotAssignedToCategoryException e) { } catch (ObjectNotAssignedToCategoryException e) {
throw new FormProcessException(e); throw new FormProcessException(e);
}
} }
} }
} }
}); });
} }
@ -205,7 +202,6 @@ public class IndexItemSelectionForm extends CMSForm {
*/ */
protected Category getCategory(PageState state) { protected Category getCategory(PageState state) {
Category category = m_category.getCategory(state); Category category = m_category.getCategory(state);
Assert.exists(category);
return category; return category;
} }

View File

@ -1,128 +0,0 @@
/*
* 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.category;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.categorization.Category;
import com.arsdigita.categorization.CategoryCollection;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.ui.CategoryForm;
import com.arsdigita.cms.ui.FormSecurityListener;
import com.arsdigita.kernel.ACSObject;
import com.arsdigita.toolbox.ui.Cancellable;
import java.math.BigDecimal;
import org.apache.log4j.Logger;
/**
* A form which edits secondary parents
*
* @author Michael Pih
* @author Stanislav Freidin
* @version $Revision: #18 $ $DateTime: 2004/08/17 23:15:09 $
*/
public class LinkForm extends CategoryForm implements Cancellable {
private final static Logger s_log = Logger.getLogger(LinkForm.class);
private final CategoryRequestLocal m_category;
private final Submit m_cancelButton;
public LinkForm(final CategoryRequestLocal category) {
super("LinkForm");
m_category = category;
m_cancelButton = new Submit("Finish");
add(m_cancelButton, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
setAssignedCaption("Linked Categories");
addSubmissionListener
(new FormSecurityListener(SecurityManager.CATEGORY_ADMIN));
}
public final boolean isCancelled(final PageState state) {
return m_cancelButton.isSelected(state);
}
/**
* Load all categories which are assigned to the current item.
*/
protected void initAssignedCategories(PageState state, CategoryMap m) {
final Category category = m_category.getCategory(state);
final BigDecimal parentID = category.getDefaultParentCategory().getID();
CategoryCollection links = category.getParents();
while ( links.next() ) {
Category cat = links.getCategory();
if ( !cat.getID().equals(parentID) ) {
m.add(cat);
}
}
links.close();
}
/**
* Assign a secondary parent.
*/
public void assignCategory(PageState state, Category category) {
final Category child = m_category.getCategory(state);
if (category.canEdit()) {
category.addChild(child);
category.save();
}
}
/**
* Unassign a secondary parent.
*/
public void unassignCategory(PageState state, Category category) {
final Category child = m_category.getCategory(state);
if (category.canEdit()) {
category.removeChild(child);
category.save();
}
}
/**
* The category cannot be its own parent. Its children cannot
* be parents either.
*/
public Category getExcludedCategory(PageState state) {
return m_category.getCategory(state);
}
/**
* This method returns the URL for the given item to make sure that
* there are not two objects in the same category with the same URL.
*/
protected final String getItemURL(final PageState state) {
return m_category.getCategory(state).getURL();
}
protected final ACSObject getObject(final PageState state) {
return (Category) m_category.getCategory(state);
}
}