Java tutorial
/* * Copyright 2014 Alfred. * * 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 com.alfredmuponda.lostandfound.pages; import com.alfredmuponda.lostandfound.model.ContactInformation; import com.alfredmuponda.lostandfound.model.Item; import com.alfredmuponda.lostandfound.model.SearchItem; import com.alfredmuponda.lostandfound.model.Delete; import com.alfredmuponda.lostandfound.model.WiaSession; import java.util.Iterator; import java.util.List; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListView; import org.apache.wicket.model.LoadableDetachableModel; import org.apache.wicket.request.mapper.parameter.PageParameters; /** * * @author Alfred */ public class DetailedSearchResults extends WebPage { private final LoadableDetachableModel detailedResultsModel; private SearchItem search; private ContactInformation contactDetails; private List<Item> articles; private final ListView items; public DetailedSearchResults(final PageParameters parameters) { search = new SearchItem(); contactDetails = new ContactInformation(); articles = search.search(parameters.get("uuid").toString()); search.getContactInfo(contactDetails, articles.get(0).getUniqueID()); detailedResultsModel = new LoadableDetachableModel() { @Override protected Object load() { return articles; } }; //List of Lost/Found articles items = new ListView("items", detailedResultsModel) { @Override protected void populateItem(final ListItem item) { final Item theItem = (Item) item.getModelObject(); item.add(new Label("itemid", theItem.getUniqueID())); item.add(new Label("itemtype", theItem.getItemType())); item.add(new Label("description", theItem.getDescription())); item.add(new Label("itemnumber", theItem.getItemID())); item.add(new Link("delete") { @Override public void onClick() { Delete db = new Delete(); db.deleteRecord(theItem.getUniqueID()); articles.remove((Item) item.getModelObject()); detailedResultsModel.detach(); } //Only allow Adim ability to delete individual record @Override public boolean isVisible() { WiaSession session = WiaSession.get(); return session.isAuthenticated() && session.getUser().isAdmin(); } }); } }; add(new HeaderPanel("headerpanel")); add(items); final Label reportID = new Label("reportid", articles.get(0).getUuid()); add(reportID); add(new Label("location", articles.get(0).getLocation())); add(new Label("datelostfound", articles.get(0).getDateLorF())); add(new Label("surname", contactDetails.getSurname())); add(new Label("firstname", contactDetails.getFirstName())); add(new Label("address", contactDetails.getAddress())); add(new Label("phonenumber", contactDetails.getPhoneNumber())); add(new Link("deleterecord") { @Override public void onClick() { Delete db = new Delete(); db.delete(parameters.get("uuid").toString()); /*Implement this*/ articles.removeAll(articles); detailedResultsModel.detach(); reportID.setVisible(false); setVisible(false); } //Allow only the Admin user to delete the entire record @Override public boolean isVisible() { WiaSession session = WiaSession.get(); return session.isAuthenticated() && session.getUser().isAdmin(); } }); } }