Revision: 1893
Author: [email protected]
Date: Wed May 26 06:55:36 2010
Log: Change to make all links in the panels bookmarkable. Refactored LinkPanel so it can be reused for generating links to resources in other places. (fixes Issue 281)

new review
update issue 281
All links in the panels are now bookmarkable.
http://code.google.com/p/simal/source/detail?r=1893

Added:
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/LinkPanel.html /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/LinkPanel.java
Deleted:
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/markup/html/repeater/data/table/LinkPropertyColumn$LinkPanel.html
Modified:
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/UserApplication.java /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/DetachablePersonModel.java /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/SortableDoapResourceDataProvider.java /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/SortableFoafResourceDataProvider.java /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/markup/html/repeater/data/table/LinkPropertyColumn.java /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/CategoryListPanel.java /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/PersonListPanel.java /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/ProjectListPanel.java

=======================================
--- /dev/null
+++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/LinkPanel.html Wed May 26 06:55:36 2010
@@ -0,0 +1,23 @@
+<!--
+
+Copyright 2010 University of Oxford
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+<wicket:panel>
+  <a href="#" wicket:id="link">
+    <span wicket:id="label">A link</span>
+  </a>
+</wicket:panel>
=======================================
--- /dev/null
+++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/LinkPanel.java Wed May 26 06:55:36 2010
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2010 University of Oxford
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package uk.ac.osswatch.simal.wicket.panel;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.model.IModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import uk.ac.osswatch.simal.model.IPerson;
+import uk.ac.osswatch.simal.model.IProject;
+import uk.ac.osswatch.simal.model.IResource;
+import uk.ac.osswatch.simal.rdf.SimalRepositoryException;
+import uk.ac.osswatch.simal.wicket.BasePage;
+import uk.ac.osswatch.simal.wicket.doap.CategoryDetailPage;
+import uk.ac.osswatch.simal.wicket.doap.ProjectDetailPage;
+import uk.ac.osswatch.simal.wicket.foaf.PersonDetailPage;
+
+/**
+ * Panel for displaying a link. This can be a regular Link
+ * or a  BookmarkablePageLink can be generated to a sub type
+ * of IResource.
+ */
+public class LinkPanel extends Panel {
+ private static final Logger LOGGER = LoggerFactory.getLogger(LinkPanel.class);
+
+  private static final long serialVersionUID = 7339822533511404418L;
+
+  /**
+   * Simple constructor to generate a link based on whatever Link object
+   * is passed to it.
+   * @param item
+   * @param componentId
+   * @param model
+   * @param link
+   * @param labelModel
+   */
+  public LinkPanel(final Item<?> item, final String componentId,
+      final IModel<?> model, Link<BasePage> link, IModel<?> labelModel) {
+    super(componentId);
+
+    add(link);
+    link.add(new Label("label", labelModel));
+  }
+
+  /**
+   * Constructor to create a link to an IResource, which will be a
+   * bookmarkable link. If the targetResource is null, it will only
+   * a label will be added.
+   * @param componentId
+   * @param targetResource
+   * @param labelModel
+   */
+  public LinkPanel(final String componentId, IResource targetResource,
+      IModel<?> labelModel) {
+    super(componentId);
+    if (targetResource != null) {
+      PageParameters parameters = new PageParameters();
+      try {
+        parameters.add("simalID", targetResource.getSimalID());
+      } catch (SimalRepositoryException e) {
+        LOGGER.warn("Problem accessing target Resource for link : "
+            + e.getMessage(), e);
+      }
+ BookmarkablePageLink<BasePage> link = new BookmarkablePageLink<BasePage>(
+          "link", getTargetPageClass(targetResource), parameters);
+      add(link);
+      link.add(new Label("label", labelModel));
+    } else {
+      add(new Label(componentId, ""));
+    }
+  }
+
+  /**
+   * Easy fix for returning the correct Class for the page that
+   * should be generated for a specific sub class of IResource
+   * @param targetResource
+   * @return Some sub class of BasePage
+   */
+ private Class<? extends BasePage> getTargetPageClass(IResource targetResource) {
+    Class<? extends BasePage> targetClass = null;
+
+    if (targetResource instanceof IProject) {
+      targetClass = ProjectDetailPage.class;
+    } else if (targetResource instanceof IPerson) {
+      targetClass = PersonDetailPage.class;
+    } else {
+      targetClass = CategoryDetailPage.class;
+    }
+
+    return targetClass;
+  }
+
+}
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/markup/html/repeater/data/table/LinkPropertyColumn$LinkPanel.html Sat May 3 15:51:55 2008
+++ /dev/null
@@ -1,23 +0,0 @@
-<!--
-
-Copyright 2008 University of Oxford
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied.  See the License for the
- specific language governing permissions and limitations
- under the License.
-
--->
-
-<wicket:panel>
-  <a href="#" wicket:id="link">
-    <span wicket:id="label">A link</span>
-  </a>
-</wicket:panel>
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/UserApplication.java Sun Dec 13 15:18:48 2009 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/UserApplication.java Wed May 26 06:55:36 2010
@@ -29,7 +29,6 @@
import org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadWebRequest;
 import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.http.WebRequest;
-import org.apache.wicket.request.target.coding.QueryStringUrlCodingStrategy;
 import org.apache.wicket.util.convert.ConverterLocator;

 import uk.ac.osswatch.simal.SimalRepositoryFactory;
@@ -40,6 +39,7 @@
 import uk.ac.osswatch.simal.wicket.authentication.SimalSession;
 import uk.ac.osswatch.simal.wicket.data.URLConverter;
 import uk.ac.osswatch.simal.wicket.doap.CategoryBrowserPage;
+import uk.ac.osswatch.simal.wicket.doap.CategoryDetailPage;
 import uk.ac.osswatch.simal.wicket.doap.ExhibitProjectBrowserPage;
 import uk.ac.osswatch.simal.wicket.doap.ProjectDetailPage;
 import uk.ac.osswatch.simal.wicket.foaf.ExhibitPersonBrowserPage;
@@ -73,22 +73,17 @@
getSecuritySettings().setUnauthorizedComponentInstantiationListener(authorizationStrategy);

                // Project pages
-               mountBookmarkablePage("/project/detail", 
ProjectDetailPage.class);
-               mount(new QueryStringUrlCodingStrategy("/project/detailencoded",
-                               ProjectDetailPage.class));
-
+               mountBookmarkablePage("/project", ProjectDetailPage.class);
                mountBookmarkablePage("/projectBrowser",
                                ExhibitProjectBrowserPage.class);

                // Person Pages
-               mountBookmarkablePage("/person/detail", PersonDetailPage.class);
-               mount(new QueryStringUrlCodingStrategy("/person/detailencoded",
-                               PersonDetailPage.class));
-
+               mountBookmarkablePage("/person", PersonDetailPage.class);
                mountBookmarkablePage("/personBrowser", 
ExhibitPersonBrowserPage.class);

                // Category Pages
                mountBookmarkablePage("/categoryBrowser", 
CategoryBrowserPage.class);
+    mountBookmarkablePage("/category", CategoryDetailPage.class);
        }

        @Override
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/DetachablePersonModel.java Sun Nov 22 17:35:55 2009 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/DetachablePersonModel.java Wed May 26 06:55:36 2010
@@ -19,32 +19,22 @@

 import org.apache.wicket.model.LoadableDetachableModel;

-import uk.ac.osswatch.simal.SimalRepositoryFactory;
 import uk.ac.osswatch.simal.model.IFoafResource;
 import uk.ac.osswatch.simal.model.IPerson;
 import uk.ac.osswatch.simal.rdf.SimalRepositoryException;

public class DetachablePersonModel extends LoadableDetachableModel<IFoafResource> {
   private static final long serialVersionUID = -9017519516676203598L;
-  String uri;
+
+  private IPerson person;

public DetachablePersonModel(IPerson person) throws SimalRepositoryException {
-    this.uri = person.getURI();
-  }
-
-  public DetachablePersonModel(String uri) {
-    this.uri = uri;
+    this.person = person;
+
   }

   @Override
   protected IFoafResource load() {
-    IPerson person;
-    try {
-      person = SimalRepositoryFactory.getPersonService().get(uri);
-    } catch (SimalRepositoryException e) {
-      e.printStackTrace();
-      person = null;
-    }
     return person;
   }

=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/SortableDoapResourceDataProvider.java Wed May 19 06:33:03 2010 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/SortableDoapResourceDataProvider.java Wed May 26 06:55:36 2010
@@ -107,8 +107,8 @@
       current = all.next();
       if (idx >= first && current.getName() != "") {
         result.add(current);
-        idx++;
-      }
+      }
+      idx++;
     }
     return result.iterator();
   }
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/SortableFoafResourceDataProvider.java Sun Nov 23 08:44:00 2008 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/SortableFoafResourceDataProvider.java Wed May 26 06:55:36 2010
@@ -101,7 +101,7 @@
     IFoafResource current;
     while (all.hasNext() && idx - (first + count) < 0) {
       current = all.next();
-      if (idx >= first) {
+      if (idx >= first && current != null) {
         result.add(current);
       }
       idx++;
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/markup/html/repeater/data/table/LinkPropertyColumn.java Sat May 2 16:35:50 2009 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/markup/html/repeater/data/table/LinkPropertyColumn.java Wed May 26 06:55:36 2010
@@ -17,82 +17,76 @@
  * under the License.                                                *
  */

+import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.markup.html.link.PopupSettings;
-import org.apache.wicket.markup.html.panel.Panel;
 import org.apache.wicket.markup.repeater.Item;
 import org.apache.wicket.model.IModel;

+import uk.ac.osswatch.simal.model.IDoapCategory;
+import uk.ac.osswatch.simal.model.IPerson;
+import uk.ac.osswatch.simal.model.IProject;
+import uk.ac.osswatch.simal.model.IResource;
+import uk.ac.osswatch.simal.wicket.BasePage;
+import uk.ac.osswatch.simal.wicket.doap.CategoryDetailPage;
+import uk.ac.osswatch.simal.wicket.doap.ProjectDetailPage;
+import uk.ac.osswatch.simal.wicket.foaf.PersonDetailPage;
+import uk.ac.osswatch.simal.wicket.panel.LinkPanel;
+
 /**
* A utility class for creating a ProperyColumn for DataTables that is also a
- * hyperlink.
- *
- * Your HTML needs:
- *
- * <![CDATA[
- *
- * ]]>
+ * bookmarkable hyperlink. It is generic for the IResources of type Category,
+ * Person and Project.
  */
-public abstract class LinkPropertyColumn extends PropertyColumn {
-  private static final long serialVersionUID = 1L;
-  PopupSettings popupSettings;
-  IModel labelModel;
-
-  public LinkPropertyColumn(IModel displayModel, String sortProperty,
-      String propertyExpression, PopupSettings popupSettings) {
-    this(displayModel, sortProperty, propertyExpression);
-    this.popupSettings = popupSettings;
-  }
-
-  public LinkPropertyColumn(IModel displayModel, IModel labelModel) {
-    super(displayModel, null);
-    this.labelModel = labelModel;
-  }
-
-  public LinkPropertyColumn(IModel displayModel, String sortProperty,
+public class LinkPropertyColumn extends PropertyColumn<IResource> {
+
+  private static final long serialVersionUID = -8731311921605414490L;
+
+ public LinkPropertyColumn(IModel<String> displayModel, String sortProperty,
       String propertyExpression) {
     super(displayModel, sortProperty, propertyExpression);
   }

- public LinkPropertyColumn(IModel displayModel, String propertyExpressions) {
-    super(displayModel, propertyExpressions);
+  /**
+   * Add a link based on the type of resource.
+   */
+  @Override
+  public void populateItem(Item<ICellPopulator<IResource>> item,
+      String componentId, IModel<IResource> model) {
+    IResource targetResource = model.getObject();
+    item
+ .add(new LinkPanel(componentId, targetResource, createLabelModel(model)));
   }

-  @Override
-  public void populateItem(Item item, String componentId, IModel model) {
-    item.add(new LinkPanel(item, componentId, model));
+  /**
+   * Generate the correct response page based on the type of resource this
+   * model is for.
+   * @param item
+   * @param componentId
+   * @param model
+   */
+  public void onClick(Item<?> item, String componentId, IModel<?> model) {
+    IResource resource = (IResource) model.getObject();
+    item.getRequestCycle().setResponsePage(generateResponsePage(resource));
   }

- public abstract void onClick(Item<?> item, String componentId, IModel<?> model);
-
-  @SuppressWarnings("serial")
-  public class LinkPanel extends Panel {
-    private static final long serialVersionUID = 1L;
-
-    public LinkPanel(final Item<?> item, final String componentId,
-        final IModel<?> model) {
-      super(componentId);
-
-      Link<?> link = new Link<String>("link") {
-
-        @Override
-        public void onClick() {
-          LinkPropertyColumn.this.onClick(item, componentId, model);
-        }
-      };
-      link.setPopupSettings(popupSettings);
-
-      add(link);
-
-      IModel<?> tmpLabelModel = labelModel;
-
-      if (labelModel == null) {
-        tmpLabelModel = createLabelModel(model);
-      }
-
-      link.add(new Label("label", tmpLabelModel));
-    }
-  }
-}
+  /**
+   * A somewhat easy fix to generate a subclass of BasePage which is the
+   * correct type based on the type of the IResource it is for.
+   * @param targetResource
+   * @return subtype of BasePage for the specific targetResource
+   */
+  private BasePage generateResponsePage(IResource targetResource) {
+    BasePage targetClass = null;
+
+    if (targetResource instanceof IProject) {
+      targetClass = new ProjectDetailPage((IProject) targetResource);
+    } else if (targetResource instanceof IPerson) {
+      targetClass = new PersonDetailPage((IPerson) targetResource);
+    } else if (targetResource instanceof IDoapCategory) {
+      targetClass = new CategoryDetailPage((IDoapCategory) targetResource);
+    }
+
+    return targetClass;
+  }
+
+}
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/CategoryListPanel.java Sun Mar 28 08:33:38 2010 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/CategoryListPanel.java Wed May 26 06:55:36 2010
@@ -26,8 +26,6 @@
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
 import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.markup.repeater.Item;
-import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;

 import uk.ac.osswatch.simal.SimalRepositoryFactory;
@@ -35,7 +33,6 @@
 import uk.ac.osswatch.simal.model.IResource;
 import uk.ac.osswatch.simal.rdf.SimalRepositoryException;
 import uk.ac.osswatch.simal.wicket.data.SortableCategoryDataProvider;
-import uk.ac.osswatch.simal.wicket.doap.CategoryDetailPage;
import uk.ac.osswatch.simal.wicket.markup.html.repeater.data.table.LinkPropertyColumn;

 /**
@@ -68,16 +65,7 @@
private void addCategoryList(SortableDataProvider<IResource> dataProvider) {
     List<AbstractColumn> columns = new ArrayList<AbstractColumn>();
     columns.add(new LinkPropertyColumn(new Model<String>("Name"), "name",
-        "name") {
-      private static final long serialVersionUID = 2731613682674835708L;
-
-      @Override
-      public void onClick(Item item, String componentId, IModel model) {
-        IDoapCategory category = (IDoapCategory) model.getObject();
- getRequestCycle().setResponsePage(new CategoryDetailPage(category));
-      }
-
-    });
+        "name"));
     columns.add(new PropertyColumn(new Model("Projects"), "projects",
         "projects.size"));
     columns
@@ -89,10 +77,12 @@

   /**
* Add a new category to the list. Useful when new categories are added after
-   * the page has loaded.
+   * the page has loaded.
+   *
    * @param category
    */
   public void addCategory(IDoapCategory category) {
     this.categories.add(category);
   }
-}
+
+}
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/PersonListPanel.java Fri Mar 5 09:53:51 2010 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/PersonListPanel.java Wed May 26 06:55:36 2010
@@ -23,6 +23,7 @@
 import java.util.Set;

import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable; +import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn; import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
 import org.apache.wicket.markup.html.basic.Label;
@@ -43,7 +44,6 @@
 import uk.ac.osswatch.simal.rdf.SimalRepositoryException;
 import uk.ac.osswatch.simal.wicket.data.SortablePersonDataProvider;
 import uk.ac.osswatch.simal.wicket.doap.PersonFilterInputModel;
-import uk.ac.osswatch.simal.wicket.foaf.PersonDetailPage;
import uk.ac.osswatch.simal.wicket.markup.html.repeater.data.table.LinkPropertyColumn;

 /**
@@ -53,7 +53,8 @@
  */
 public class PersonListPanel extends Panel {
   private static final long serialVersionUID = 1L;
- private static final Logger logger = LoggerFactory.getLogger(PersonListPanel.class);
+  private static final Logger logger = LoggerFactory
+      .getLogger(PersonListPanel.class);
   private Set<IPerson> people;
   private String title;
   private String filter = "";
@@ -67,7 +68,8 @@
    *          the wicket ID for the component
    * @param title
    *          the title if this list
-   * @param numberOfPeople the number of people to display per page
+   * @param numberOfPeople
+   *          the number of people to display per page
    * @throws SimalRepositoryException
    */
   public PersonListPanel(String id, String title, int numberOfPeople)
@@ -76,8 +78,8 @@
     this.title = title;
     this.people = SimalRepositoryFactory.getPersonService().getAll();
     populatePanel(numberOfPeople);
-  }
-
+  }
+
   /**
    * Create a panel that lists people filtered with a given filter string.
    *
@@ -85,16 +87,19 @@
    *          the wicket ID for the component
    * @param title
    *          the title if this list
-   * @param numberOfPeople the number of people to display per page
-   * @param filter the filter to use
+   * @param numberOfPeople
+   *          the number of people to display per page
+   * @param filter
+   *          the filter to use
    *
    * @throws SimalRepositoryException
    */
- public PersonListPanel(String id, String title, int numberOfPeople, String filter)
-      throws SimalRepositoryException {
+  public PersonListPanel(String id, String title, int numberOfPeople,
+      String filter) throws SimalRepositoryException {
     super(id);
     this.title = title;
- this.people = SimalRepositoryFactory.getPersonService().filterByName(filter);
+    this.people = SimalRepositoryFactory.getPersonService()
+        .filterByName(filter);
     this.filter = filter;
     populatePanel(numberOfPeople);
   }
@@ -108,10 +113,12 @@
    *          the title if this list
    * @param people
    *          the people to include in the list
-   * @param numberOfPeople the number of people to display per page
+   * @param numberOfPeople
+   *          the number of people to display per page
    * @throws SimalRepositoryException
    */
- public PersonListPanel(String id, String title, Set<IPerson> people, int numberOfPeople) {
+  public PersonListPanel(String id, String title, Set<IPerson> people,
+      int numberOfPeople) {
     super(id);
     this.title = title;
     this.people = people;
@@ -120,56 +127,56 @@

   private void populatePanel(int numberOfPeople) {
     add(new Label("title", title));
-    add(new PersonFilterForm("personFilterForm", this.filter));
-    addPersonList(people, numberOfPeople);
+    add(new PersonFilterForm("personFilterForm", this.filter));
+    addPersonList(people, numberOfPeople);
   }

   @SuppressWarnings("unchecked")
-private void addPersonList(Set<IPerson> people, int numberOfPeople) {
+  private void addPersonList(Set<IPerson> people, int numberOfPeople) {
     List<AbstractColumn> columns = new ArrayList<AbstractColumn>();
-    columns
- .add(new NameLinkPropertyColumn(new Model("Name"), "label", "label"));
-
-    columns.add(new PropertyColumn(new Model("Email"), "email",
-        "email") {
+ columns.add(new LinkPropertyColumn(new Model<String>("Name"), "label", "label"));
+
+ columns.add(new PropertyColumn<IPerson>(new Model<String>("Email"), "email", "email") {
       private static final long serialVersionUID = 1L;

       @Override
- public void populateItem(Item cellItem, String componentId, IModel model) {
-        Iterator<IInternetAddress> emails = ((IPerson) model.getObject())
-            .getEmail().iterator();
-        if (emails.hasNext()) {
-          while (emails.hasNext()) {
+ public void populateItem(Item<ICellPopulator<IPerson>> cellItem, String componentId, IModel<IPerson> model) {
+        IPerson person = model.getObject();
+        String label = "";
+
+        if (person != null) {
+          Iterator<IInternetAddress> emails = ((IPerson) model.getObject())
+              .getEmail().iterator();
+          if (emails.hasNext()) {
             IInternetAddress email = emails.next();
-            String label = email.getObfuscatedAddress();
+            label = email.getObfuscatedAddress();
             if (label.startsWith("mailto:";)) {
               label = label.substring(7);
             }
-            cellItem.add(new Label(componentId, label));
-            break;
-          }
-        } else {
-          cellItem.add(new Label(componentId, ""));
-        }
+          }
+        }
+        cellItem.add(new Label(componentId, label));
       }
     });

- columns.add(new ProjectsPropertyColumn(new Model("Project"), "projects", + columns.add(new ProjectsPropertyColumn(new Model<String>("Project"), "projects",
         "projects"));

     dataProvider = new SortablePersonDataProvider(people);
dataProvider.setSort(SortablePersonDataProvider.SORT_PROPERTY_LABEL, true); - add(new AjaxFallbackDefaultDataTable("dataTable", columns, dataProvider, numberOfPeople)); + add(new AjaxFallbackDefaultDataTable("dataTable", columns, dataProvider,
+        numberOfPeople));
   }

   /**
-   * Update the data displayed by filtering on the name field using a
-   * regular expression.
+ * Update the data displayed by filtering on the name field using a regular
+   * expression.
    *
    * @param nameFilter
    * @throws SimalRepositoryException
    */
- public void filterPeopleByName(String nameFilter) throws SimalRepositoryException {
+  public void filterPeopleByName(String nameFilter)
+      throws SimalRepositoryException {
     dataProvider.filterPeopleByName(nameFilter);
   }

@@ -183,63 +190,46 @@
   public void addPerson(IPerson person) {
     this.people.add(person);
   }
-
-  /**
-   *
-   */
-  private final class NameLinkPropertyColumn extends LinkPropertyColumn {
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * @param displayModel
-     * @param sortProperty
-     * @param propertyExpression
-     */
- private NameLinkPropertyColumn(IModel displayModel, String sortProperty,
-        String propertyExpression) {
-      super(displayModel, sortProperty, propertyExpression);
-    }
-
-    @Override
-    public void onClick(Item item, String componentId, IModel model) {
-      IPerson person = (IPerson) model.getObject();
-      getRequestCycle().setResponsePage(new PersonDetailPage(person));
-    }
-  }

   /**
    *
    */
-  private final class ProjectsPropertyColumn extends PropertyColumn {
-    private static final long serialVersionUID = 1L;
+ private final class ProjectsPropertyColumn extends PropertyColumn<IPerson> {
+
+    private static final long serialVersionUID = 6506230050408318191L;

     /**
      * @param displayModel
      * @param sortProperty
      * @param propertyExpression
      */
- private ProjectsPropertyColumn(IModel displayModel, String sortProperty, + private ProjectsPropertyColumn(IModel<String> displayModel, String sortProperty,
         String propertyExpression) {
       super(displayModel, sortProperty, propertyExpression);
     }

     @Override
- public void populateItem(Item cellItem, String componentId, IModel model) { + public void populateItem(Item<ICellPopulator<IPerson>> cellItem, String componentId, IModel<IPerson> model) {
+      IPerson person = model.getObject();
       Iterator<IProject> projects;
-      try {
-        projects = ((IPerson) model.getObject()).getProjects().iterator();
-        StringBuffer label = new StringBuffer();
-        while (projects.hasNext()) {
-          IProject project = projects.next();
-          label.append(project.getLabel());
-          if (projects.hasNext()) {
-            label.append(", ");
-          }
-        }
-        cellItem.add(new Label(componentId, label.toString()));
-      } catch (SimalRepositoryException e) {
-        cellItem.add(new Label(componentId, "ERROR"));
-      }
+      StringBuffer label = new StringBuffer();
+
+      if(person != null) {
+        try {
+          projects = person.getProjects().iterator();
+          while (projects.hasNext()) {
+            IProject project = projects.next();
+            label.append(project.getLabel());
+            if (projects.hasNext()) {
+              label.append(", ");
+            }
+          }
+        } catch (SimalRepositoryException e) {
+ logger.warn("Unable to retrieve projects for person : " + e.getMessage(), e);
+        }
+      }
+
+      cellItem.add(new Label(componentId, label.toString()));
     }
   }

@@ -250,7 +240,7 @@
   private class PersonFilterForm extends Form<PersonFilterInputModel> {
     private static final long serialVersionUID = 4350446873545711199L;
     private TextField<String> nameFilter;
-
+
     public PersonFilterForm(String name, String filter) {
super(name, new CompoundPropertyModel<PersonFilterInputModel>(inputModel));
       nameFilter = new TextField<String>("nameFilter");
@@ -267,7 +257,7 @@
       } catch (SimalRepositoryException e) {
         logger.error("Unable to perform search", e);
         nameFilter.setModel(new Model<String>("ERROR: contact support"));
-      }
+      }
     }
   }
 }
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/ProjectListPanel.java Mon Nov 23 15:01:40 2009 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/ProjectListPanel.java Wed May 26 06:55:36 2010
@@ -27,9 +27,7 @@
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.TextField;
 import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.markup.repeater.Item;
 import org.apache.wicket.model.CompoundPropertyModel;
-import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,7 +35,6 @@
 import uk.ac.osswatch.simal.model.IProject;
 import uk.ac.osswatch.simal.rdf.SimalRepositoryException;
 import uk.ac.osswatch.simal.wicket.data.SortableProjectDataProvider;
-import uk.ac.osswatch.simal.wicket.doap.ProjectDetailPage;
 import uk.ac.osswatch.simal.wicket.doap.ProjectFilterInputModel;
import uk.ac.osswatch.simal.wicket.markup.html.repeater.data.table.LinkPropertyColumn;

@@ -102,16 +99,7 @@
     add(new ProjectFilterForm("projectFilterForm"));

     List<AbstractColumn> columns = new ArrayList<AbstractColumn>();
-    columns.add(new LinkPropertyColumn(new Model("Name"), "name", "name") {
-      private static final long serialVersionUID = -2174061702366979017L;
-
-      @Override
-      public void onClick(Item item, String componentId, IModel model) {
-        IProject project = (IProject) model.getObject();
-        getRequestCycle().setResponsePage(new ProjectDetailPage(project));
-      }
-
-    });
+    columns.add(new LinkPropertyColumn(new Model("Name"), "name", "name"));
     columns.add(new PropertyColumn(new Model("Description"), "shortDesc",
         "shortDesc"));

--
You received this message because you are subscribed to the Google Groups "Simal 
Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/simal-commits?hl=en.

Reply via email to