Implementes using points discussed during last meeting
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4686 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
cac8a04e06
commit
6467e05373
|
|
@ -33,6 +33,7 @@ import com.arsdigita.bebop.util.GlobalizationUtil;
|
||||||
import com.arsdigita.bebop.util.SequentialMap;
|
import com.arsdigita.bebop.util.SequentialMap;
|
||||||
import com.arsdigita.cms.CMS;
|
import com.arsdigita.cms.CMS;
|
||||||
import com.arsdigita.cms.ui.authoring.BasicItemForm;
|
import com.arsdigita.cms.ui.authoring.BasicItemForm;
|
||||||
|
import com.arsdigita.globalization.Globalization;
|
||||||
import com.arsdigita.util.StringUtils;
|
import com.arsdigita.util.StringUtils;
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
@ -45,13 +46,7 @@ import org.libreccm.core.CcmObject;
|
||||||
|
|
||||||
import javax.enterprise.inject.spi.CDI;
|
import javax.enterprise.inject.spi.CDI;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.SortedMap;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an abstract class which displays the category assignment UI.
|
* This is an abstract class which displays the category assignment UI.
|
||||||
|
|
@ -367,60 +362,32 @@ public abstract class CategoryForm extends Form
|
||||||
public void process(FormSectionEvent e) throws FormProcessException {
|
public void process(FormSectionEvent e) throws FormProcessException {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class);
|
final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class);
|
||||||
final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
|
|
||||||
|
|
||||||
PageState state = e.getPageState();
|
PageState state = e.getPageState();
|
||||||
FormData data = e.getFormData();
|
FormData data = e.getFormData();
|
||||||
BigDecimal id;
|
Long id;
|
||||||
|
|
||||||
if (m_assign.isSelected(state)) {
|
if (m_assign.isSelected(state)) {
|
||||||
Category cat = new Category();
|
id = ((BigDecimal) data.get(FREE)).longValue();
|
||||||
assignCategory(state, cat);
|
Optional<Category> optional = categoryRepository.findById(id);
|
||||||
|
if (optional.isPresent()) {
|
||||||
|
Category cat = optional.get();
|
||||||
|
assignCategory(state, cat);
|
||||||
|
data.put(ASSIGNED, id);
|
||||||
|
} else {
|
||||||
|
throw new FormProcessException(GlobalizationUtil.globalize(String.format("Can't find category with id %d", id)));
|
||||||
|
}
|
||||||
|
} else if (m_remove.isSelected(state)) {
|
||||||
|
id = ((BigDecimal) data.get(ASSIGNED)).longValue();
|
||||||
|
Optional<Category> optional = categoryRepository.findById(id);
|
||||||
|
if (optional.isPresent()) {
|
||||||
|
Category cat = optional.get();
|
||||||
|
unassignCategory(state, cat);
|
||||||
|
data.put(FREE, id);
|
||||||
|
} else {
|
||||||
|
throw new FormProcessException(GlobalizationUtil.globalize(String.format("Can't find category with id %d", id)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (m_assign.isSelected(state)) {
|
|
||||||
// id = (BigDecimal) data.get(FREE);
|
|
||||||
//
|
|
||||||
// // Assign a new category
|
|
||||||
// try {
|
|
||||||
// Category cat = new Category(
|
|
||||||
// new OID(Category.BASE_DATA_OBJECT_TYPE, id));
|
|
||||||
// if (!cat.canMap()) {
|
|
||||||
// data.addError(
|
|
||||||
// (String) GlobalizationUtil.globalize(
|
|
||||||
// "cms.ui.need_category_map_privilege").localize());
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// assignCategory(state, cat);
|
|
||||||
// // Highlight the item
|
|
||||||
// data.put(ASSIGNED, id);
|
|
||||||
// } catch (DataObjectNotFoundException ex) {
|
|
||||||
// s_log.error("Couldn't find Category", ex);
|
|
||||||
// throw new FormProcessException(ex);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// } else if (m_remove.isSelected(state)) {
|
|
||||||
// id = (BigDecimal) data.get(ASSIGNED);
|
|
||||||
//
|
|
||||||
// // Unassign a category
|
|
||||||
// try {
|
|
||||||
// Category cat = new Category(
|
|
||||||
// new OID(Category.BASE_DATA_OBJECT_TYPE, id));
|
|
||||||
// if (!cat.canMap()) {
|
|
||||||
// data.addError(
|
|
||||||
// (String) GlobalizationUtil.globalize(
|
|
||||||
// "cms.ui.need_category_map_privilege").localize());
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// unassignCategory(state, cat);
|
|
||||||
// // Highlight the item
|
|
||||||
// data.put(FREE, id);
|
|
||||||
// } catch (DataObjectNotFoundException ex) {
|
|
||||||
// s_log.error("Couldn't find category");
|
|
||||||
// throw new FormProcessException(ex);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the form: make sure that a category is selected
|
// Validate the form: make sure that a category is selected
|
||||||
|
|
@ -429,19 +396,16 @@ public abstract class CategoryForm extends Form
|
||||||
public void validate(FormSectionEvent e) throws FormProcessException {
|
public void validate(FormSectionEvent e) throws FormProcessException {
|
||||||
PageState state = e.getPageState();
|
PageState state = e.getPageState();
|
||||||
FormData data = e.getFormData();
|
FormData data = e.getFormData();
|
||||||
|
if (m_assign.isSelected(state)) {
|
||||||
|
if (data.get(FREE) == null) {
|
||||||
|
data.addError(GlobalizationUtil.globalize("cms.ui.category.assign_select_missing"));
|
||||||
|
} else {
|
||||||
|
// we need to make sure that no other item in this
|
||||||
|
// category has the same name (url)
|
||||||
|
Long id = ((BigDecimal) data.get(FREE)).longValue();
|
||||||
|
|
||||||
// if (m_assign.isSelected(state)) {
|
// Assign a new category
|
||||||
// if (data.get(FREE) == null) {
|
|
||||||
// data.addError("Please select a category to assign");
|
|
||||||
// } else {
|
|
||||||
// // we need to make sure that no other item in this
|
|
||||||
// // category has the same name (url)
|
|
||||||
// BigDecimal id = (BigDecimal) data.get(FREE);
|
|
||||||
//
|
|
||||||
// // Assign a new category
|
|
||||||
// try {
|
// try {
|
||||||
// Category cat =
|
|
||||||
// new Category(new OID(Category.BASE_DATA_OBJECT_TYPE, id));
|
|
||||||
// String url = getItemURL(state);
|
// String url = getItemURL(state);
|
||||||
//
|
//
|
||||||
// if (url != null) {
|
// if (url != null) {
|
||||||
|
|
@ -477,12 +441,12 @@ public abstract class CategoryForm extends Form
|
||||||
// + "category with id " + id);
|
// + "category with id " + id);
|
||||||
// throw new FormProcessException(ex);
|
// throw new FormProcessException(ex);
|
||||||
// }
|
// }
|
||||||
// }
|
}
|
||||||
// } else if (m_remove.isSelected(state)) {
|
} else if (m_remove.isSelected(state)) {
|
||||||
// if (data.get(ASSIGNED) == null) {
|
if (data.get(ASSIGNED) == null) {
|
||||||
// data.addError("Please select a category to remove");
|
data.addError(GlobalizationUtil.globalize("cms.ui.category.assign_select_missing"));
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a "filler" option to the option group in order to ensure
|
// Add a "filler" option to the option group in order to ensure
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,15 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.libreccm.categorization.Category;
|
import org.libreccm.categorization.Category;
|
||||||
import org.libreccm.categorization.CategoryManager;
|
import org.libreccm.categorization.CategoryManager;
|
||||||
|
import org.libreccm.categorization.DomainManager;
|
||||||
|
import org.libreccm.categorization.DomainOwnership;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.web.ApplicationManager;
|
||||||
|
import org.libreccm.web.CcmApplication;
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a list of category use contexts for the current
|
* Builds a list of category use contexts for the current
|
||||||
|
|
@ -38,7 +43,6 @@ import java.util.Collection;
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
* @author Scott Seago
|
* @author Scott Seago
|
||||||
* @version $Id: CategoryUseContextModelBuilder.java 2090 2010-04-17 08:04:14Z pboy $
|
|
||||||
*/
|
*/
|
||||||
class CategoryUseContextModelBuilder extends AbstractListModelBuilder {
|
class CategoryUseContextModelBuilder extends AbstractListModelBuilder {
|
||||||
|
|
||||||
|
|
@ -52,31 +56,28 @@ class CategoryUseContextModelBuilder extends AbstractListModelBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Model implements ListModel {
|
private class Model implements ListModel {
|
||||||
private final java.util.List<Category> m_roots;
|
private final Iterator<DomainOwnership> m_roots;
|
||||||
|
private DomainOwnership current;
|
||||||
|
|
||||||
public Model() {
|
public Model() {
|
||||||
final ContentSection section =
|
final ContentSection section =
|
||||||
CMS.getContext().getContentSection();
|
CMS.getContext().getContentSection();
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
m_roots = section.getDomains().iterator();
|
||||||
final CategoryManager manager = cdiUtil.findBean(CategoryManager.class);
|
current = null;
|
||||||
|
|
||||||
m_roots = (Category) CMS.getContext().getContentItem();
|
|
||||||
//m_roots.addOrder(Category.USE_CONTEXT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean next() {
|
public boolean next() {
|
||||||
return m_roots.next();
|
current = m_roots.next();
|
||||||
|
return current != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getElement() {
|
public Object getElement() {
|
||||||
String useContext = m_roots.getUseContext();
|
return current;
|
||||||
return useContext == null ? DEFAULT_USE_CONTEXT : useContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
String useContext = m_roots.getUseContext();
|
return current.getContext() != null ? current.getContext() : DEFAULT_USE_CONTEXT;
|
||||||
return useContext == null ? DEFAULT_USE_CONTEXT : useContext;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,6 +110,7 @@ cms.ui.category.use_context=Use Context
|
||||||
cms.ui.category.use_contexts=Use Contexts
|
cms.ui.category.use_contexts=Use Contexts
|
||||||
cms.ui.category.use_context_must_be_unique=Use context must be unique within a Content Section.
|
cms.ui.category.use_context_must_be_unique=Use context must be unique within a Content Section.
|
||||||
cms.ui.category.view_index_item=View index item
|
cms.ui.category.view_index_item=View index item
|
||||||
|
cms.ui.category.assign_select_missing="Please select a category to assign"
|
||||||
|
|
||||||
cms.ui.authoring.no_types_registered=No types registered
|
cms.ui.authoring.no_types_registered=No types registered
|
||||||
cms.ui.contents_of=Contents of
|
cms.ui.contents_of=Contents of
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue