- New filter for ObjectLists which operates on a category system (either the

one used for the navigation or a secondary one). The filter can also be used 
  for implementing a search for tags (which are in fact categories).
- Some formating


git-svn-id: https://svn.libreccm.org/ccm/trunk@2325 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2013-09-28 17:05:01 +00:00
parent e209bd4b5e
commit bf25dc8dd2
5 changed files with 360 additions and 217 deletions

View File

@ -649,6 +649,7 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
private final Object m_key; private final Object m_key;
private Object m_nextKey; private Object m_nextKey;
public StepComponent(Object key) { public StepComponent(Object key) {
m_key = key; m_key = key;
} }

View File

@ -0,0 +1,144 @@
package com.arsdigita.navigation.ui.object;
import com.arsdigita.categorization.Category;
import com.arsdigita.categorization.CategoryCollection;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.CompoundFilter;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.FilterFactory;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.xml.Element;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class CategoryFilter {
private final String label;
private final Category filterRootCat;
// private boolean descendCategories = true;
//private String value;
private final List<String> values = new ArrayList<String>();
public static CategoryFilter createCategoryFilter(final String label, final String categoryName) {
final DataCollection collection = SessionManager.getSession().retrieve(
Category.BASE_DATA_OBJECT_TYPE);
collection.addEqualsFilter(Category.NAME, categoryName);
if (collection.next()) {
final Category category = (Category) DomainObjectFactory.newInstance(
collection.getDataObject());
return new CategoryFilter(label, category);
} else {
throw new IllegalArgumentException(String.format(
"A category with the provided name '%s' does not exist", categoryName));
}
}
public CategoryFilter(final String label, final Category filterRootCat) {
this.label = label;
this.filterRootCat = filterRootCat;
}
// public boolean getDescendCategories() {
// return descendCategories;
// }
//
// public void setDescendCategories(final boolean descendCategories) {
// this.descendCategories = descendCategories;
// }
public void applyFilter(final DataCollection objects) {
// for(String value : values) {
// if ((value != null) && !value.isEmpty()) {
// if(descendCategories) {
// com.arsdigita.persistence.Filter filter = objects.addInSubqueryFilter("parent.id",
// "com.arsdigita.categorization.objectIDsInSubtree");
// filter.set("categoryID", value);
// objects.addFilter(filter);
// } else {
// objects.addEqualsFilter("parent.categories.id", value);
// }
// }
// }
if (!values.isEmpty()) {
// if (descendCategories) {
final FilterFactory filterFactory = objects.getFilterFactory();
final CompoundFilter compoundFilter = filterFactory.and();
for (String value : values) {
final com.arsdigita.persistence.Filter filter = filterFactory.in("parent.id",
"com.arsdigita.categorization.objectIDsInSubtree");
filter.set("categoryID", value);
compoundFilter.addFilter(filter);
}
objects.addFilter(compoundFilter);
// com.arsdigita.persistence.Filter filter = objects.addInSubqueryFilter("parent.id",
// "com.arsdigita.categorization.objectIDsInSubtree");
// filter.set("categoryID", values.get(0));
// } else {
// final com.arsdigita.persistence.Filter filter = objects.addFilter(
// "parent.categories.id IN :categories");
// filter.set("categories", values);
//objects.addEqualsFilter("parent.categories.id", values.get(0));
// final FilterFactory filterFactory = objects.getFilterFactory();
// final CompoundFilter compoundFilter = filterFactory.or();
// for (String value : values) {
// final com.arsdigita.persistence.Filter filter = filterFactory.equals(
// "parent.categories.id", value);
// compoundFilter.addFilter(filter);
// }
//
// objects.addFilter(compoundFilter);
// }
}
}
public Element getXml() {
final Element filter = new Element("filter");
filter.addAttribute("name", "categoryFilter");
filter.addAttribute("label", label);
final CategoryCollection categories = filterRootCat.getChildren();
categories.addOrder("name");
Category category;
while (categories.next()) {
category = categories.getCategory();
addCategoryToFilter(filter, category);
}
return filter;
}
private void addCategoryToFilter(final Element parent, final Category category) {
final Element elem = new Element("category");
elem.addAttribute("id", category.getID().toString());
//if ((value != null) && !value.isEmpty() && value.equals(category.getID().toString())) {
if ((values != null) && !values.isEmpty() && values.contains(category.getID().toString())) {
elem.addAttribute("selected", "selected");
}
elem.setText(category.getName());
parent.addContent(elem);
}
public void setValue(final String value) {
if ((value != null) && !value.isEmpty()) {
final String[] tokens = value.split(" ");
for (String token : tokens) {
values.add(token.trim());
}
}
}
}

View File

@ -91,7 +91,7 @@ public class CustomizableObjectList extends ComplexObjectList {
*/ */
private final Map<String, Filter> filters = private final Map<String, Filter> filters =
new LinkedHashMap<String, Filter>(); new LinkedHashMap<String, Filter>();
//private CategoryFilter categoryFilter; private CategoryFilter categoryFilter;
/** /**
* The available sort fields. We use an {@link LinkedHashMap} here to * The available sort fields. We use an {@link LinkedHashMap} here to
* preserve the insertation order. * preserve the insertation order.
@ -179,12 +179,13 @@ public class CustomizableObjectList extends ComplexObjectList {
filters.put(label, filter); filters.put(label, filter);
} }
// public CategoryFilter addCategoryFilter(final String label, public CategoryFilter addCategoryFilter(final String label,
// final String rootCategory) { final String rootCategory) {
// categoryFilter = CategoryFilter.createCategoryFilter(label, rootCategory); categoryFilter = CategoryFilter.createCategoryFilter(label, rootCategory);
//
// return categoryFilter; return categoryFilter;
// } }
/** /**
* Add a sort field option. * Add a sort field option.
* *
@ -248,9 +249,9 @@ public class CustomizableObjectList extends ComplexObjectList {
final DataCollection objects = super.getObjects(request, response); final DataCollection objects = super.getObjects(request, response);
// if ((objects != null) && (categoryFilter != null)) { if ((objects != null) && (categoryFilter != null)) {
// categoryFilter.applyFilter(objects); categoryFilter.applyFilter(objects);
// } }
return objects; return objects;
} }
@ -327,15 +328,15 @@ public class CustomizableObjectList extends ComplexObjectList {
filterEntry.getValue().setValue(value); filterEntry.getValue().setValue(value);
} }
} }
// if (categoryFilter != null) { if (categoryFilter != null) {
// final String value = Globalization.decodeParameter(request, "categoryFilter"); final String value = Globalization.decodeParameter(request, "categoryFilter");
//
// if ((value != null) && !value.isEmpty()) {
// categoryFilter.setValue(value);
// }
// }
if (!filters.isEmpty()) { if ((value != null) && !value.isEmpty()) {
categoryFilter.setValue(value);
}
}
if (!filters.isEmpty() || (categoryFilter != null)) {
final Element controls = content.newChildElement("filterControls"); final Element controls = content.newChildElement("filterControls");
controls.addAttribute("customName", m_customName); controls.addAttribute("customName", m_customName);
@ -344,9 +345,9 @@ public class CustomizableObjectList extends ComplexObjectList {
for (Map.Entry<String, Filter> filterEntry : filters.entrySet()) { for (Map.Entry<String, Filter> filterEntry : filters.entrySet()) {
filterElems.addContent(filterEntry.getValue().getXml()); filterElems.addContent(filterEntry.getValue().getXml());
} }
// if (categoryFilter != null) { if (categoryFilter != null) {
// filterElems.addContent(categoryFilter.getXml()); filterElems.addContent(categoryFilter.getXml());
// } }
if (!sortFields.isEmpty()) { if (!sortFields.isEmpty()) {
//Look for a sort parameter. If one is found, use one to sort the data //Look for a sort parameter. If one is found, use one to sort the data
@ -371,4 +372,5 @@ public class CustomizableObjectList extends ComplexObjectList {
return content; return content;
} }
} }

View File

@ -12,7 +12,6 @@
* rights and limitations under the License. * rights and limitations under the License.
* *
*/ */
package com.arsdigita.portalworkspace.ui.admin; package com.arsdigita.portalworkspace.ui.admin;
import com.arsdigita.bebop.Form; import com.arsdigita.bebop.Form;
@ -27,8 +26,6 @@ import com.arsdigita.portalworkspace.WorkspacePage;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* Entry page for PortalWorkspace administration. * Entry page for PortalWorkspace administration.
* *
@ -42,11 +39,9 @@ import org.apache.log4j.Logger;
public class AdminPane extends SimpleContainer { public class AdminPane extends SimpleContainer {
private static final Logger s_log = Logger.getLogger(AdminPane.class); private static final Logger s_log = Logger.getLogger(AdminPane.class);
private ApplicationSelectionModel m_app; private ApplicationSelectionModel m_app;
private CategoryComponent m_catComponent; private CategoryComponent m_catComponent;
private DeleteApplicationComponent m_deleteApplicationComponent; private DeleteApplicationComponent m_deleteApplicationComponent;
/** /**
@ -59,16 +54,15 @@ public class AdminPane extends SimpleContainer {
m_app = new ApplicationSelectionModel("application", true); m_app = new ApplicationSelectionModel("application", true);
/* Add component to select a Navigation Category for this portal */ /* Add component to select a Navigation Category for this portal */
m_catComponent = new CategoryComponent(m_app); m_catComponent = new CategoryComponent(m_app);
m_catComponent.setIdAttr("categoryComponent"); m_catComponent.setIdAttr("categoryComponent");
add(m_catComponent); add(m_catComponent);
/* Add component "Extrem Action": Delete this portal */ /* Add component "Extrem Action": Delete this portal */
m_deleteApplicationComponent = new DeleteApplicationComponent(m_app, m_deleteApplicationComponent = new DeleteApplicationComponent(m_app,
m_app.getDefaultApplication().getApplicationType()); m_app.getDefaultApplication().
getApplicationType());
m_deleteApplicationComponent.setIdAttr("deleteComponent"); m_deleteApplicationComponent.setIdAttr("deleteComponent");
add(m_deleteApplicationComponent); add(m_deleteApplicationComponent);
@ -80,6 +74,7 @@ public class AdminPane extends SimpleContainer {
.getResource(); .getResource();
return (Group) workspace.getParty(); return (Group) workspace.getParty();
} }
}; };
members.setIdAttr("memberDisplay"); members.setIdAttr("memberDisplay");
add(members); add(members);
@ -92,6 +87,7 @@ public class AdminPane extends SimpleContainer {
.getResource(); .getResource();
return (Group) workspace.getParty(); return (Group) workspace.getParty();
} }
}); });
form.setIdAttr("memberUserPicker"); form.setIdAttr("memberUserPicker");
add(form); add(form);
@ -110,6 +106,7 @@ public class AdminPane extends SimpleContainer {
} }
return admins.getGroup(); return admins.getGroup();
} }
}; };
admins.setIdAttr("adminDisplay"); admins.setIdAttr("adminDisplay");
add(admins); add(admins);
@ -128,8 +125,10 @@ public class AdminPane extends SimpleContainer {
} }
return admins.getGroup(); return admins.getGroup();
} }
}); });
adminForm.setIdAttr("adminUserPicker"); adminForm.setIdAttr("adminUserPicker");
add(adminForm); add(adminForm);
} }
} }

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.portalworkspace.ui.admin; package com.arsdigita.portalworkspace.ui.admin;
import com.arsdigita.portalworkspace.ui.sitemap.ApplicationSelectionModel; import com.arsdigita.portalworkspace.ui.sitemap.ApplicationSelectionModel;
@ -52,17 +51,11 @@ public class CategoryComponent extends SimpleContainer {
private static final Logger s_log = Logger private static final Logger s_log = Logger
.getLogger(CategoryComponent.class); .getLogger(CategoryComponent.class);
private ACSObjectSelectionModel m_catModel; private ACSObjectSelectionModel m_catModel;
private CategoryTree m_tree; private CategoryTree m_tree;
private ApplicationSelectionModel m_appModel; private ApplicationSelectionModel m_appModel;
private Label m_error; private Label m_error;
private static final Application m_app = Web.getContext().getApplication(); private static final Application m_app = Web.getContext().getApplication();
private static final Category m_root = Category.getRootForObject(m_app); private static final Category m_root = Category.getRootForObject(m_app);
/** /**
@ -96,6 +89,7 @@ public class CategoryComponent extends SimpleContainer {
* *
*/ */
private class CategoryTree extends Tree { private class CategoryTree extends Tree {
public CategoryTree(ACSObjectSelectionModel categoryModel) { public CategoryTree(ACSObjectSelectionModel categoryModel) {
super(new SectionTreeModelBuilder()); super(new SectionTreeModelBuilder());
setSelectionModel(categoryModel); setSelectionModel(categoryModel);
@ -108,6 +102,7 @@ public class CategoryComponent extends SimpleContainer {
* *
*/ */
private class CategoryTreeActionListener implements ActionListener { private class CategoryTreeActionListener implements ActionListener {
private ACSObjectSelectionModel m_catModel; private ACSObjectSelectionModel m_catModel;
public CategoryTreeActionListener(ACSObjectSelectionModel catModel) { public CategoryTreeActionListener(ACSObjectSelectionModel catModel) {
@ -149,6 +144,7 @@ public class CategoryComponent extends SimpleContainer {
} }
} }
} }
} }
/** /**
@ -171,5 +167,6 @@ public class CategoryComponent extends SimpleContainer {
Assert.exists(root, Category.class); Assert.exists(root, Category.class);
return new CategoryTreeModelLite(root); return new CategoryTreeModelLite(root);
} }
} }
} }