package lemming.sense;

import lemming.auth.SignInPage;
import lemming.auth.WebSession;
import lemming.table.FilterPanelColumn;
import lemming.ui.panel.ModalMessagePanel;
import lemming.user.User;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
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.apache.wicket.model.Model;

/**
 * A custom column with actions for senses and and a filter panel as filter.
 */
public class SenseActionPanelColumn extends FilterPanelColumn<Sense> {
    /**
     * Creates a column.
     * 
     * @param displayModel
     *            title of the column
     */
    public SenseActionPanelColumn(IModel<String> displayModel) {
        super(displayModel, Sense.class);
    }

    /**
     * Returns the CSS class of this type of column.
     * 
     * @return A string representing a CSS class.
     */
    @Override
    public String getCssClass() {
        return "actionColumn";
    }

    /**
     * Populates cell items with components.
     * 
     * @param cellItem
     *            cell item that is populated
     * @param componentId
     *            ID of the child component
     * @param rowModel
     *            model of the row
     */
    @Override
    public void populateItem(Item<ICellPopulator<Sense>> cellItem, String componentId, IModel<Sense> rowModel) {
        cellItem.add(new ActionPanel(componentId, rowModel));
    }

    /**
     * A panel with actions for sense objects.
     */
    private class ActionPanel extends Panel {
        /**
         * Creates a action panel.
         * 
         * @param id
         *            ID of the panel
         * @param model
         *            sense model of a cell item
         */
        public ActionPanel(String id, final IModel<Sense> model) {
            super(id, model);

            if (WebSession.get().getUser() == null) {
                setResponsePage(SignInPage.class);
            }

            add(new Link<Void>("editLink") {
                @Override
                public void onClick() {
                    setResponsePage(new SenseEditPage(model, getPage().getPageClass()));
                }
            });
            add(new AjaxLink<Void>("deleteLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    ModalMessagePanel senseDeleteConfirmPanel = (ModalMessagePanel) getPage()
                            .get("senseDeleteConfirmPanel");
                    senseDeleteConfirmPanel.show(target, new Model<Sense>(model.getObject()));
                }

                @Override
                public boolean isVisible() {
                    Sense sense = model.getObject();

                    if (sense.isParentSense() && new SenseDao().hasChildSenses(sense)) {
                        return false;
                    }

                    return true;
                }
            });
        }
    }
}

@@ -2483,33 +2483,27 @@
             
-@Override
+/**
 %0A           
@@ -2511,150 +2511,98 @@
     
-public void onClick(AjaxRequestTarget target) %7B%0A                    ModalMessagePanel senseDeleteConfirmPanel = (ModalMessagePanel) getPage()%0A
+ * Determines if a deserialized file is compatible with%0A                 * this class.%0A   
     
@@ -2603,32 +2603,35 @@
                 
+*/%0A
               .g
@@ -2632,135 +2632,137 @@
     
-.get(%22senseDeleteConfirmPanel%22);%0A                    senseDeleteConfirmPanel.show(target, new Model%3CSense%3E(model.getObject()));
+  private static final long serialVersionUID = 1L;%0A%0A                /**%0A                 * Called when an AjaxLink is configured.
 %0A   
@@ -2766,34 +2766,35 @@
                 
-%7D%0A
+ */
 %0A               
@@ -2825,35 +2825,78 @@
    p
-ublic boolean isVisible() %7B
+rotected void onConfigure() %7B%0A                    super.onConfigure();
 %0A   
@@ -3063,20 +3063,25 @@
     
-return 
+setVisible(
 false
+)
 ;%0A  
@@ -3103,41 +3103,603 @@
    %7D
-%0A%0A                    return true
+ else %7B%0A                        setVisible(true);%0A                    %7D%0A                %7D%0A%0A                /**%0A                 * Called on click.%0A                 *%0A                 * @param target target that produces an Ajax response%0A                 */%0A                @Override%0A                public void onClick(AjaxRequestTarget target) %7B%0A                    ModalMessagePanel senseDeleteConfirmPanel = (ModalMessagePanel) getPage()%0A                            .get(%22senseDeleteConfirmPanel%22);%0A                    senseDeleteConfirmPanel.show(target, new Model%3CSense%3E(model.getObject()))
 ;%0A  

Add comments, replace isVisible() with onConfigure().