Revision: 1876
Author: [email protected]
Date: Sun Mar 28 08:33:38 2010
Log: Add new categories to a project from the ProjectDetailPage (Issue 25)
http://code.google.com/p/simal/source/detail?r=1876

Added:
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/AbstractAddDoapResourcePanel.java /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/AddCategoryPanel.html /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/AddCategoryPanel.java /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/SelectCategoryInputModel.java
Modified:
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/ProjectDetailPage.html /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/ProjectDetailPage.java /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/foaf/AddPersonPanel.html /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/foaf/AddPersonPanel.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/test/java/uk/ac/osswatch/simal/wicket/doap/TestProjectDetailPage.java

=======================================
--- /dev/null
+++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/AbstractAddDoapResourcePanel.java Sun Mar 28 08:33:38 2010
@@ -0,0 +1,228 @@
+package uk.ac.osswatch.simal.wicket.panel;
+
+/*
+ * 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.                                                *
+ */
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.AjaxFormValidatingBehavior;
+import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
+import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.panel.FeedbackPanel;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.util.time.Duration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract container for adding a new DOAP resource. This is an AJAX enabled + * container that either shows the form in the subclass or a command link to
+ * display the form.
+ */
+public abstract class AbstractAddDoapResourcePanel extends Panel {
+  private static final long serialVersionUID = -4529601431958052094L;
+
+  public static final Logger LOGGER = LoggerFactory
+      .getLogger(AbstractAddDoapResourcePanel.class);
+
+  /** Visibility toggle so that either the link or the form is visible. */
+  private boolean formVisible = false;
+
+  FeedbackPanel feedback;
+
+  private Panel updatePanel;
+
+  /**
+ * Create a new container that will initially display the command link to show
+   * the form.
+   *
+   * @param wicketid
+   *          the id of the HTML component to host the container
+   * @param updatePanel
+ * the panel that should be updated when the DOAP resource has been
+   *          added (must have setOutputMarkupId(true)
+   */
+  public AbstractAddDoapResourcePanel(String wicketid, Panel updatePanel) {
+    super(wicketid);
+    this.updatePanel = updatePanel;
+    setOutputMarkupId(true);
+    add(new NewDoapResourceLink("newLink"));
+    add(new AddDoapResourceForm("doapResourceForm"));
+  }
+
+  /**
+   * Processes the result when the form is submitted.
+   */
+  protected abstract void processAddSubmit();
+
+  /**
+   * Add fields to the form for a specific add-form.
+   * @param addDoapResourceForm
+   */
+ protected abstract void addFormFields(AddDoapResourceForm addDoapResourceForm);
+
+  /**
+   * Inputmodel used for this specific form.
+   * @return
+   */
+  public abstract Object getInputModel();
+
+  /**
+ * Called when the new DOAP resource link is clicked. Shows the form, and hides the
+   * link.
+   *
+   * @param target
+   *          the request target.
+   */
+  void onShowForm(AjaxRequestTarget target) {
+    formVisible = true;
+    target.addComponent(this);
+  }
+
+  /**
+ * Called when the cancel link is clicked. Hides the form, and shows the link.
+   *
+   * @param target
+   *          the request target.
+   */
+  void onHideForm(AjaxRequestTarget target) {
+    formVisible = false;
+    target.addComponent(this);
+  }
+
+  /**
+ * Link for adding the DOAP resource described in the form to the repository.
+   *
+   */
+  private final class AddDoapResourceButton extends AjaxFallbackButton {
+    private static final long serialVersionUID = -3425972816770998300L;
+
+    private AddDoapResourceButton(String id, Form<Object> form) {
+      super(id, form);
+    }
+
+    /**
+ * Handle the submit request by creating the person and, where appropriate,
+     * assigning them to a project.
+     *
+     * @param target
+     *          the request target.
+     */
+    @Override
+    public void onSubmit(AjaxRequestTarget target, Form<?> form) {
+      processAddSubmit();
+      onHideForm(target);
+      target.addComponent(updatePanel);
+    }
+
+    protected void onError(AjaxRequestTarget target, Form<?> form) {
+      target.addComponent(feedback);
+    }
+  }
+
+  /** Link for cancelling a new DOAP resource action. */
+  @SuppressWarnings("unchecked")
+  private final class CancelLink extends AjaxFallbackLink {
+
+    private static final long serialVersionUID = -1058382750336408613L;
+
+    public CancelLink(String id) {
+      super(id);
+    }
+
+    /**
+     * When the link is clicked the form is shown and the link is hidden.
+     *
+     * @param target
+     *          the request target.
+     */
+    @Override
+    public void onClick(AjaxRequestTarget target) {
+      onHideForm(target);
+    }
+
+  }
+
+  /** Link for displaying the AddDoapResourceForm. */
+  @SuppressWarnings("unchecked")
+  private final class NewDoapResourceLink extends AjaxFallbackLink {
+    private static final long serialVersionUID = 8333095362462779919L;
+
+    public NewDoapResourceLink(String id) {
+      super(id);
+    }
+
+    /**
+     * When the link is clicked the form is shown and the link is hidden.
+     *
+     * @param target
+     *          the request target.
+     */
+    @Override
+    public void onClick(AjaxRequestTarget target) {
+      onShowForm(target);
+    }
+
+    @Override
+    public boolean isVisible() {
+      return !formVisible;
+    }
+
+  }
+
+  /**
+ * Displays a form for adding a DOAP resource to the project. The visibility of + * this component is mutually exclusive with the visibility of the new link.
+   */
+  public final class AddDoapResourceForm extends Form<Object> {
+    private static final long serialVersionUID = 2931852197898067993L;
+
+    public AddDoapResourceForm(String id) {
+      super(id, new CompoundPropertyModel<Object>(getInputModel()));
+
+      setOutputMarkupId(true);
+      addFormFields(this);
+
+      feedback = new FeedbackPanel("feedback");
+      feedback.setOutputMarkupId(true);
+      add(feedback);
+
+      AjaxFormValidatingBehavior.addToAllFormComponents(this, "onkeyup",
+          Duration.ONE_SECOND);
+
+      add(new AddDoapResourceButton("addDoapResourceButton", this));
+      add(new CancelLink("cancelLink"));
+    }
+
+    @Override
+    public boolean isVisible() {
+      return formVisible;
+    }
+  }
+
+  /**
+   * Cancel addition of a person.
+   *
+   * @param target
+   */
+  void onCancel(AjaxRequestTarget target) {
+    formVisible = false;
+    target.addComponent(this);
+  }
+
+}
=======================================
--- /dev/null
+++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/AddCategoryPanel.html Sun Mar 28 08:33:38 2010
@@ -0,0 +1,34 @@
+<!--
+
+ 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.
+
+-->
+
+<html xmlns:wicket>
+<wicket:panel>
+  <a href="#" wicket:id="newLink">New</a>
+  <form wicket:id="doapResourceForm">
+    <fieldset>
+      <legend>Add category</legend>
+      <p>Select catgory to add:
+               <select wicket:id="listedCategories"></select>
+                       </p>
+      <div wicket:id="feedback">[[ feedback ]]</div>
+      <input type="submit" value="Add" wicket:id="addDoapResourceButton"/>
+      <a href="#" wicket:id="cancelLink">Cancel</a>
+    </fieldset>
+  </form>
+</wicket:panel>
+</html>
=======================================
--- /dev/null
+++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/AddCategoryPanel.java Sun Mar 28 08:33:38 2010
@@ -0,0 +1,146 @@
+package uk.ac.osswatch.simal.wicket.panel;
+
+/*
+ * 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.                                                *
+ */
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.wicket.markup.html.form.ChoiceRenderer;
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.model.PropertyModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import uk.ac.osswatch.simal.SimalRepositoryFactory;
+import uk.ac.osswatch.simal.model.IDoapCategory;
+import uk.ac.osswatch.simal.model.IProject;
+import uk.ac.osswatch.simal.model.utils.DoapResourceByNameComparator;
+import uk.ac.osswatch.simal.rdf.SimalRepositoryException;
+import uk.ac.osswatch.simal.wicket.ErrorReportPage;
+import uk.ac.osswatch.simal.wicket.UserReportableException;
+import uk.ac.osswatch.simal.wicket.doap.ProjectDetailPage;
+
+/**
+ * Container for adding a new category. This is an AJAX enabled container that + * either shows the form for selecting a category or a command link to display
+ * the form.
+ */
+public class AddCategoryPanel extends AbstractAddDoapResourcePanel {
+
+  private static final long serialVersionUID = -7126291323723696950L;
+
+  public static final Logger LOGGER = LoggerFactory
+      .getLogger(AddCategoryPanel.class);
+
+  private SelectCategoryInputModel inputModel;
+  DropDownChoice<IDoapCategory> categoryField;
+
+  private CategoryListPanel updatePanel;
+
+  private IProject project;
+
+  /**
+ * Create a new container that will initially display the command link to show
+   * the form.
+   *
+   * @param wicketid
+   *          the id of the HTML component to host the container
+   * @param updatePanel
+ * the panel that should be updated when the category has been added
+   *          (must have setOutputMarkupId(true)
+   */
+ public AddCategoryPanel(String wicketid, IProject project, CategoryListPanel updatePanel) {
+    super(wicketid, updatePanel);
+    this.project = project;
+    this.updatePanel = updatePanel;
+  }
+
+  /*
+   * (non-Javadoc)
+   *
+   * @see
+ * uk.ac.osswatch.simal.wicket.panel.AbstractAddPanel#addFormFields(uk.ac.
+   * osswatch.simal.wicket.panel.AbstractAddPanel.AddDoapResourceForm)
+   */
+  @Override
+  protected void addFormFields(AddDoapResourceForm addDoapResourceForm) {
+    inputModel = new SelectCategoryInputModel();
+    Set<IDoapCategory> allCategories;
+    try {
+      allCategories = SimalRepositoryFactory.getCategoryService().getAll();
+    } catch (SimalRepositoryException e) {
+ LOGGER.warn("Could not retreive all categories for adding new Category");
+      allCategories = new HashSet<IDoapCategory>();
+    }
+    List<IDoapCategory> allCategoriesListed = new ArrayList<IDoapCategory>(
+        allCategories);
+ Collections.sort(allCategoriesListed, new DoapResourceByNameComparator());
+
+    categoryField = new DropDownChoice<IDoapCategory>("listedCategories",
+        new PropertyModel<IDoapCategory>(inputModel, "comboChoice"),
+ allCategoriesListed, new ChoiceRenderer<IDoapCategory>("name", "label")) {
+
+      private static final long serialVersionUID = -6627368071258835746L;
+
+      /**
+ * Whether this component's onSelectionChanged event handler should called
+       * using javascript if the selection changes.
+       *
+       * @return True if this component's onSelectionChanged event handler
+       *         should called using javascript if the selection changes
+       */
+      protected boolean wantOnSelectionChangedNotifications() {
+        return false;
+      }
+    };
+    addDoapResourceForm.add(categoryField);
+  }
+
+  /**
+   * Return the inputModel for this panel.
+   *
+ * @see uk.ac.osswatch.simal.wicket.panel.AbstractAddPanel#getInputModel()
+   */
+  @Override
+  public Object getInputModel() {
+    return this.inputModel;
+  }
+
+  /**
+   * Add category to the project and to the existing list.
+   *
+ * @see uk.ac.osswatch.simal.wicket.panel.AbstractAddPanel#processAddSubmit()
+   */
+  @Override
+  protected void processAddSubmit() {
+    IDoapCategory selectedCategory = inputModel.getcomboChoice();
+    if (selectedCategory != null) {
+      project.addCategory(selectedCategory);
+      updatePanel.addCategory(selectedCategory);
+    } else {
+      UserReportableException error = new UserReportableException(
+          "Unable to generate a category from the given form data",
+          ProjectDetailPage.class);
+      setResponsePage(new ErrorReportPage(error));
+    }
+  }
+
+}
=======================================
--- /dev/null
+++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/SelectCategoryInputModel.java Sun Mar 28 08:33:38 2010
@@ -0,0 +1,52 @@
+package uk.ac.osswatch.simal.wicket.panel;
+
+/*
+ * 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.                                                *
+ */
+
+import java.util.List;
+
+import org.apache.wicket.IClusterable;
+
+import uk.ac.osswatch.simal.model.IDoapCategory;
+
+/**
+ * A Java bean usable as input model for managing a selection of Categories.
+ */
+public class SelectCategoryInputModel implements IClusterable {
+
+  private static final long serialVersionUID = -6143804114236894073L;
+
+  private List<IDoapCategory> listedCategories;
+
+  private IDoapCategory comboChoice;
+
+  public IDoapCategory getcomboChoice() {
+      return comboChoice;
+  }
+
+  public void setComboChoice(IDoapCategory comboChoice) {
+      this.comboChoice = comboChoice;
+  }
+
+  public void setListedCategories(List<IDoapCategory> listedCategories) {
+    this.listedCategories = listedCategories;
+  }
+
+  public List<IDoapCategory> getListedCategories() {
+    return listedCategories;
+  }
+}
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/ProjectDetailPage.html Mon Nov 16 16:02:19 2009 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/ProjectDetailPage.html Sun Mar 28 08:33:38 2010
@@ -94,6 +94,7 @@

     <div class="rightcolumn">
       <h2>Categories</h2>
+      <div wicket:id="addCategoryPanel">Add Category Panel</div>
       <div wicket:id="categoryList" >Category List Panel</div>

       <h2>Operating System(s)</h2>
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/ProjectDetailPage.java Sun Nov 22 16:38:35 2009 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/ProjectDetailPage.java Sun Mar 28 08:33:38 2010
@@ -47,6 +47,7 @@
 import uk.ac.osswatch.simal.wicket.UserReportableException;
 import uk.ac.osswatch.simal.wicket.data.SortableDoapResourceDataProvider;
 import uk.ac.osswatch.simal.wicket.foaf.AddPersonPanel;
+import uk.ac.osswatch.simal.wicket.panel.AddCategoryPanel;
 import uk.ac.osswatch.simal.wicket.panel.CategoryListPanel;
 import uk.ac.osswatch.simal.wicket.panel.PersonListPanel;
 import uk.ac.osswatch.simal.wicket.panel.ReleasesPanel;
@@ -216,7 +217,11 @@
new SortableDoapResourceDataProvider(project.getScreenshots()), false));

     // facets
-    add(new CategoryListPanel("categoryList", project.getCategories()));
+ CategoryListPanel categoryList = new CategoryListPanel("categoryList", project.getCategories());
+    categoryList.setOutputMarkupId(true);
+    add(categoryList);
+    add(new AddCategoryPanel("addCategoryPanel", project, categoryList));
+
     add(getRepeatingLabels("OSes", "OS", project.getOSes()));
     add(getRepeatingLabels("programmingLanguages", "programmingLanguage",
         project.getProgrammingLanguages()));
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/foaf/AddPersonPanel.html Fri Aug 15 17:34:33 2008 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/foaf/AddPersonPanel.html Sun Mar 28 08:33:38 2010
@@ -19,13 +19,13 @@
 <html xmlns:wicket>
 <wicket:panel>
   <a href="#" wicket:id="newLink">New</a>
-  <form wicket:id="personForm">
+  <form wicket:id="doapResourceForm">
     <fieldset>
       <legend>Person Details</legend>
       <p>Name: <input type="text" wicket:id="name" /></p>
       <p>Email: <input type="text" wicket:id="email" /></p>
       <div wicket:id="feedback">[[ feedback ]]</div>
-      <input type="submit" value="Add" wicket:id="addPersonButton"/>
+      <input type="submit" value="Add" wicket:id="addDoapResourceButton"/>
       <a href="#" wicket:id="cancelLink">Cancel</a>
     </fieldset>
   </form>
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/foaf/AddPersonPanel.java Sun Nov 22 16:49:29 2009 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/foaf/AddPersonPanel.java Sun Mar 28 08:33:38 2010
@@ -17,17 +17,8 @@
  * under the License.                                                *
  */

-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormValidatingBehavior;
-import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
-import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
-import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.RequiredTextField;
 import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.markup.html.panel.FeedbackPanel;
-import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.CompoundPropertyModel;
-import org.apache.wicket.util.time.Duration;
 import org.apache.wicket.validation.validator.EmailAddressValidator;
 import org.apache.wicket.validation.validator.StringValidator;

@@ -37,6 +28,7 @@
 import uk.ac.osswatch.simal.wicket.ErrorReportPage;
 import uk.ac.osswatch.simal.wicket.UserReportableException;
 import uk.ac.osswatch.simal.wicket.doap.ProjectDetailPage;
+import uk.ac.osswatch.simal.wicket.panel.AbstractAddDoapResourcePanel;
 import uk.ac.osswatch.simal.wicket.panel.PersonListPanel;

 /**
@@ -44,7 +36,7 @@
* either shows the form for entering data about a person or a command link to
  * display the form.
  */
-public class AddPersonPanel extends Panel {
+public class AddPersonPanel extends AbstractAddDoapResourcePanel {
   private static final long serialVersionUID = 8348295085251890400L;

   public static final int HELPER = 1;
@@ -54,12 +46,10 @@
   public static final int TESTER = 16;
   public static final int TRANSLATOR = 32;

-  /** Visibility toggle so that either the link or the form is visible. */
-  private boolean formVisible = false;
   private FoafFormInputModel inputModel = new FoafFormInputModel();
   TextField<String> nameField;
   TextField<String> emailField;
-  FeedbackPanel feedback;
+
   private int personRole;
   private IProject project;

@@ -81,191 +71,73 @@
    */
   public AddPersonPanel(String wicketid, IProject project, int role,
       PersonListPanel updatePanel) {
-    super(wicketid);
+    super(wicketid, updatePanel);
     this.personRole = role;
     this.project = project;
     this.updatePanel = updatePanel;
     setOutputMarkupId(true);
-    add(new NewPersonLink("newLink"));
-    add(new AddPersonForm("personForm"));
   }

-  /**
- * Called when the new person link is clicked. Shows the form, and hides the
-   * link.
-   *
-   * @param target
-   *          the request target.
-   */
-  void onShowPersonForm(AjaxRequestTarget target) {
-    formVisible = true;
-    target.addComponent(this);
-  }
-
-  /**
- * Called when the cancel link is clicked. Hides the form, and shows the link.
-   *
-   * @param target
-   *          the request target.
+
+  /* (non-Javadoc)
+ * @see uk.ac.osswatch.simal.wicket.panel.AbstractAddDoapResourcePanel#addFormFields(uk.ac.osswatch.simal.wicket.panel.AbstractAddDoapResourcePanel.AddDoapResourceForm)
    */
-  void onHidePersonForm(AjaxRequestTarget target) {
-    formVisible = false;
-    target.addComponent(this);
-  }
-
-  /**
-   * Link for adding a person described in the form to the repository.
-   *
-   */
-  private final class AddPersonButton extends AjaxFallbackButton {
-    private static final long serialVersionUID = -3425972816770998300L;
-
-    private AddPersonButton(String id, Form<FoafFormInputModel> form) {
-      super(id, form);
-    }
-
-    /**
- * Handle the submit request by creating the person and, where appropriate,
-     * assigning them to a project.
-     *
-     * @param target
-     *          the request target.
-     */
-    @Override
-    public void onSubmit(AjaxRequestTarget target, Form<?> form) {
-      inputModel.setName(nameField.getValue());
-      inputModel.setEmail(emailField.getValue());
-      try {
-        IPerson person = inputModel.getPerson();
-        if (project != null) {
-          switch (personRole) {
-          case MAINTAINER:
-            project.addMaintainer(person);
-            break;
-          case DEVELOPER:
-            project.addDeveloper(person);
-            break;
-          case TESTER:
-            project.addTester(person);
-            break;
-          case HELPER:
-            project.addHelper(person);
-            break;
-          case DOCUMENTOR:
-            project.addDocumenter(person);
-            break;
-          case TRANSLATOR:
-            project.addTranslator(person);
-            break;
-          }
-        }
-        updatePanel.addPerson(person);
-      } catch (SimalRepositoryException e) {
-        UserReportableException error = new UserReportableException(
-            "Unable to generate a person from the given form data",
-            ProjectDetailPage.class, e);
-        setResponsePage(new ErrorReportPage(error));
-      }
-      onHidePersonForm(target);
-      target.addComponent(updatePanel);
-    }
-
-    protected void onError(AjaxRequestTarget target, Form<?> form) {
-      target.addComponent(feedback);
-    }
+  @Override
+  protected void addFormFields(AddDoapResourceForm addDoapResourceForm) {
+
+ addDoapResourceForm.add(nameField = new RequiredTextField<String>("name"));
+    nameField.add(StringValidator.minimumLength(4));
+
+ addDoapResourceForm.add(emailField = new RequiredTextField<String>("email"));
+    emailField.add(EmailAddressValidator.getInstance());
   }

-  /** Link for cancelling a new person action. */
-  @SuppressWarnings("unchecked")
-  private final class CancelLink extends AjaxFallbackLink {
-    private static final long serialVersionUID = 8333095362462779919L;
-
-    public CancelLink(String id) {
-      super(id);
-    }
-
-    /**
-     * When the link is clicked the form is shown and the link is hidden.
-     *
-     * @param target
-     *          the request target.
-     */
-    @Override
-    public void onClick(AjaxRequestTarget target) {
-      onHidePersonForm(target);
-    }
-
-  }
-
-  /** Link for displaying the AddPersonForm. */
-  @SuppressWarnings("unchecked")
-  private final class NewPersonLink extends AjaxFallbackLink {
-    private static final long serialVersionUID = 8333095362462779919L;
-
-    public NewPersonLink(String id) {
-      super(id);
-    }
-
-    /**
-     * When the link is clicked the form is shown and the link is hidden.
-     *
-     * @param target
-     *          the request target.
-     */
-    @Override
-    public void onClick(AjaxRequestTarget target) {
-      onShowPersonForm(target);
-    }
-
-    @Override
-    public boolean isVisible() {
-      return !formVisible;
-    }
-
-  }
-
-  /**
-   * Displays a form for creating a person record. The visibility of this
- * component is mutually exclusive with the visibility of the new person link.
+  /* (non-Javadoc)
+ * @see uk.ac.osswatch.simal.wicket.panel.AbstractAddDoapResourcePanel#getInputModel()
    */
-  private final class AddPersonForm extends Form<FoafFormInputModel> {
-    private static final long serialVersionUID = 2931852197898067993L;
-
-    public AddPersonForm(String id) {
-      super(id, new CompoundPropertyModel<FoafFormInputModel>(inputModel));
-      setOutputMarkupId(true);
-
-      feedback = new FeedbackPanel("feedback");
-      feedback.setOutputMarkupId(true);
-      add(feedback);
-
-      add(nameField = new RequiredTextField<String>("name"));
-      nameField.add(StringValidator.minimumLength(4));
-
-      add(emailField = new RequiredTextField<String>("email"));
-      emailField.add(EmailAddressValidator.getInstance());
-
-      AjaxFormValidatingBehavior.addToAllFormComponents(this, "onkeyup",
-          Duration.ONE_SECOND);
-
-      add(new AddPersonButton("addPersonButton", this));
-      add(new CancelLink("cancelLink"));
-    }
-
-    @Override
-    public boolean isVisible() {
-      return formVisible;
-    }
+  @Override
+  public Object getInputModel() {
+    return inputModel;
   }

-  /**
-   * Cancel addition of a person.
-   *
-   * @param target
+  /* (non-Javadoc)
+ * @see uk.ac.osswatch.simal.wicket.panel.AbstractAddDoapResourcePanel#processAddSubmit()
    */
-  void onCancel(AjaxRequestTarget target) {
-    formVisible = false;
-    target.addComponent(this);
+  @Override
+  protected void processAddSubmit() {
+    inputModel.setName(nameField.getValue());
+    inputModel.setEmail(emailField.getValue());
+    try {
+      IPerson person = inputModel.getPerson();
+      if (project != null) {
+        switch (personRole) {
+        case MAINTAINER:
+          project.addMaintainer(person);
+          break;
+        case DEVELOPER:
+          project.addDeveloper(person);
+          break;
+        case TESTER:
+          project.addTester(person);
+          break;
+        case HELPER:
+          project.addHelper(person);
+          break;
+        case DOCUMENTOR:
+          project.addDocumenter(person);
+          break;
+        case TRANSLATOR:
+          project.addTranslator(person);
+          break;
+        }
+      }
+      updatePanel.addPerson(person);
+    } catch (SimalRepositoryException e) {
+      UserReportableException error = new UserReportableException(
+          "Unable to generate a person from the given form data",
+          ProjectDetailPage.class, e);
+      setResponsePage(new ErrorReportPage(error));
+    }
   }

 }
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/CategoryListPanel.java Mon Nov 23 15:01:40 2009 +++ /trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/CategoryListPanel.java Sun Mar 28 08:33:38 2010
@@ -30,6 +30,7 @@
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;

+import uk.ac.osswatch.simal.SimalRepositoryFactory;
 import uk.ac.osswatch.simal.model.IDoapCategory;
 import uk.ac.osswatch.simal.model.IResource;
 import uk.ac.osswatch.simal.rdf.SimalRepositoryException;
@@ -45,14 +46,19 @@
 public class CategoryListPanel extends Panel {
   private static final long serialVersionUID = -7641153470731218965L;

+  private Set<IDoapCategory> categories;
+
   public CategoryListPanel(String id) throws SimalRepositoryException {
     super(id);
- SortableDataProvider<IResource> dataProvider = new SortableCategoryDataProvider();
+    this.categories = SimalRepositoryFactory.getCategoryService().getAll();
+ SortableDataProvider<IResource> dataProvider = new SortableCategoryDataProvider(
+        this.categories);
     addCategoryList(dataProvider);
   }

   public CategoryListPanel(String id, Set<IDoapCategory> categories) {
     super(id);
+    this.categories = categories;
SortableDataProvider<IResource> dataProvider = new SortableCategoryDataProvider(
         categories);
     addCategoryList(dataProvider);
@@ -80,4 +86,13 @@
dataProvider.setSort(SortableCategoryDataProvider.SORT_PROPERTY_NAME, true); add(new AjaxFallbackDefaultDataTable("dataTable", columns, dataProvider, 15));
   }
-}
+
+  /**
+ * Add a new category to the list. Useful when new categories are added after
+   * the page has loaded.
+   * @param category
+   */
+  public void addCategory(IDoapCategory category) {
+    this.categories.add(category);
+  }
+}
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/doap/TestProjectDetailPage.java Sun Nov 22 16:26:46 2009 +++ /trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/doap/TestProjectDetailPage.java Sun Mar 28 08:33:38 2010
@@ -41,7 +41,6 @@
return new ProjectDetailPage(SimalRepositoryFactory.getProjectService().getProject(projectURI));
         } catch (SimalRepositoryException e) {
           System.err.println("Can't find the test project");
-          System.exit(1);
           return null;
         }
       }
@@ -100,6 +99,28 @@
FormTester formTester = tester.newFormTester("addReviewPanel:reviewForm");

            formTester.submit();
+  }
+
+  /**
+   * Check the add Category form is working OK.
+   *
+   * @throws SimalRepositoryException
+   */
+  @Test
+  public void testAddCategory() throws SimalRepositoryException {
+    tester.assertVisible("addCategoryPanel");
+    tester.assertVisible("addCategoryPanel:newLink");
+
+    tester.assertInvisible("addCategoryPanel:doapResourceForm");
+    tester.assertVisible("addCategoryPanel:newLink");
+    tester.clickLink("addCategoryPanel:newLink");
+
+    tester.assertVisible("addCategoryPanel:doapResourceForm");
+    tester.assertInvisible("addCategoryPanel:newLink");
+
+    tester.clickLink("addCategoryPanel:doapResourceForm:cancelLink");
+    tester.assertInvisible("addCategoryPanel:doapResourceForm");
+
   }

   /**
@@ -112,26 +133,26 @@
     tester.assertVisible("addMaintainerPanel");
     tester.assertVisible("addMaintainerPanel:newLink");

-    tester.assertInvisible("addMaintainerPanel:personForm");
+    tester.assertInvisible("addMaintainerPanel:doapResourceForm");
     tester.assertVisible("addMaintainerPanel:newLink");
     tester.clickLink("addMaintainerPanel:newLink");

-    tester.assertVisible("addMaintainerPanel:personForm");
+    tester.assertVisible("addMaintainerPanel:doapResourceForm");
     tester.assertInvisible("addMaintainerPanel:newLink");

-    tester.clickLink("addMaintainerPanel:personForm:cancelLink");
-    tester.assertInvisible("addMaintainerPanel:personForm");
+    tester.clickLink("addMaintainerPanel:doapResourceForm:cancelLink");
+    tester.assertInvisible("addMaintainerPanel:doapResourceForm");

     /**
      * Commented out as the submit does not seem to work with an Ajax form
      *
      * FormTester formTester = tester
-     *   .newFormTester("addMaintainerPanel:personForm");
+     *   .newFormTester("addMaintainerPanel:doapResourceForm");
      *
      * tester.clickLink("addMaintainerPanel:newLink"); formTester =
-     * tester.newFormTester("addMaintainerPanel:personForm");
+     * tester.newFormTester("addMaintainerPanel:doapResourceForm");
      * formTester.setValue("name", "New Person"); formTester.submit();
-     * tester.assertInvisible("addMaintainerPanel:personForm");
+     * tester.assertInvisible("addMaintainerPanel:doapResourceForm");
      *
      * Set<IPerson> peopleAfter =
* UserApplication.getRepository().getProject(projectURI).getMaintainers();

--
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