package edu.tamu.csdl.dcm.ui.panels; import java.util.ArrayList; import java.util.List; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.form.AjaxButton; import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; import com.inmethod.grid.IGridColumn; import com.inmethod.grid.column.PropertyColumn; import com.inmethod.grid.datagrid.DataGrid; import edu.tamu.csdl.dcm.data.Collection; import edu.tamu.csdl.dcm.model.CollectionDataModel; import edu.tamu.csdl.dcm.model.CollectionDataSource; import edu.tamu.csdl.dcm.util.Store; public class LoadPanel extends Panel { /** * */ private static final long serialVersionUID = 3610144741483525440L; private int userID; private ModalWindow window; private LoadForm form; public LoadPanel(ModalWindow window, int userID) { super(window.getContentId()); this.userID = userID; this.window = window; this.form = new LoadForm("loadform"); add(this.form); } class LoadForm extends Form { /** * */ private static final long serialVersionUID = -4956979569026153640L; private DataGrid table; public LoadForm(String id) { super(id); this.table = generateTable(); add(this.table); AjaxButton loadSubmit = new AjaxButton("loadsubmit") { /** * */ private static final long serialVersionUID = 5643876668191005404L; @Override protected void onSubmit(AjaxRequestTarget arg0, Form arg1) { if(LoadForm.this.table.getSelectedItems().size() > 0) { java.util.Collection selected = LoadForm.this.table.getSelectedItems(); List selectedList = new ArrayList(selected); Collection collection = ((CollectionDataModel) selectedList.get(0)).getCollection(); Store.getInstance(LoadPanel.this.userID).setCollection(collection); LoadPanel.this.window.close(arg0); } else { LoadForm.this.error("No Row Selected!", null); } } }; add(loadSubmit); AjaxButton loadCancel = new AjaxButton("loadcancel"){ /** * */ private static final long serialVersionUID = 7342495723185113323L; @Override protected void onSubmit(AjaxRequestTarget arg0, Form form) { LoadPanel.this.window.close(arg0); } }; add(loadCancel); } private DataGrid generateTable() { List columns = new ArrayList(); columns.add(new PropertyColumn(new Model("Index"),"collectionID", "collectionID")); columns.add(new PropertyColumn(new Model("Name"),"collectionName", "collectionName")); columns.add(new PropertyColumn(new Model("Size"),"size", "size")); DataGrid table = new DataGrid("loadtable", new CollectionDataSource(LoadPanel.this.userID), columns); table.setClickRowToSelect(true); table.setClickRowToDeselect(true); table.setAllowSelectMultiple(false); return table; } @Override protected void onSubmit() { } } public DataGrid getTable() { return this.form.table; } } L