-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19f5047
commit 223486f
Showing
19 changed files
with
1,002 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...org/devgateway/toolkit/forms/wicket/components/form/AbstractDgEditablePropertyColumn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.devgateway.toolkit.forms.wicket.components.form; | ||
|
||
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.form.FormComponent; | ||
import org.apache.wicket.markup.repeater.Item; | ||
import org.apache.wicket.model.IModel; | ||
import org.wicketstuff.egrid.column.EditableGridActionsPanel; | ||
|
||
/** | ||
* @author mpostelnicu | ||
* @param <T> | ||
* @param <S> | ||
* @param <Z> | ||
*/ | ||
public abstract class AbstractDgEditablePropertyColumn<T, S, Z> extends PropertyColumn<T, S> implements IDgEditableGridColumn<Z> | ||
{ | ||
public AbstractDgEditablePropertyColumn(IModel<String> displayModel, String propertyExpression) | ||
{ | ||
super(displayModel, propertyExpression); | ||
} | ||
|
||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public final void populateItem(final Item<ICellPopulator<T>> item, final String componentId, final IModel<T> rowModel) | ||
{ | ||
|
||
final Item<T> rowItem = ((Item<T>) item.findParent(Item.class)); | ||
|
||
if (inEditingMode(rowItem)) | ||
{ | ||
GenericBootstrapFormComponent<Z, ? extends FormComponent<Z>> provider = | ||
getEditableCellPanel(componentId, (IModel<Z>) getDataModel(rowModel)); | ||
item.add(provider); | ||
} | ||
else | ||
{ | ||
super.populateItem(item, componentId, rowModel); | ||
} | ||
} | ||
|
||
private boolean inEditingMode(Item<T> rowItem) | ||
{ | ||
return rowItem.getMetaData(EditableGridActionsPanel.EDITING); | ||
} | ||
|
||
protected void addBehaviors(FormComponent<T> editorComponent) | ||
{ | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/DgEditableGrid.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" > | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||
<title>Insert title here</title> | ||
</head> | ||
<body> | ||
|
||
<wicket:panel> | ||
<form wicket:id="form"> | ||
<table wicket:id="dataTable"></table> | ||
</form> | ||
</wicket:panel> | ||
|
||
</body> | ||
</html> |
223 changes: 223 additions & 0 deletions
223
forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/DgEditableGrid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
package org.devgateway.toolkit.forms.wicket.components.form; | ||
|
||
import de.agilecoders.wicket.core.markup.html.bootstrap.navigation.ajax.BootstrapAjaxPagingNavigator; | ||
import org.apache.wicket.AttributeModifier; | ||
import org.apache.wicket.Component; | ||
import org.apache.wicket.ajax.AjaxRequestTarget; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; | ||
import org.apache.wicket.markup.html.form.Form; | ||
import org.apache.wicket.markup.html.form.IFormSubmitter; | ||
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator; | ||
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 org.wicketstuff.egrid.column.EditableGridActionsColumn; | ||
import org.wicketstuff.egrid.component.EditableDataTable; | ||
import org.wicketstuff.egrid.component.EditableDataTable.RowItem; | ||
import org.wicketstuff.egrid.provider.IEditableDataProvider; | ||
import org.wicketstuff.egrid.toolbar.EditableGridHeadersToolbar; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author Nadeem Mohammad, mpostelnicu | ||
* | ||
*/ | ||
public class DgEditableGrid<T, S> extends Panel | ||
{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private EditableDataTable<T, S> dataTable; | ||
|
||
public DgEditableGrid(final String id, final List<? extends IColumn<T, S>> columns, | ||
final IEditableDataProvider<T, S> dataProvider, final long rowsPerPage, Class<T> clazz) | ||
{ | ||
super(id); | ||
List<IColumn<T, S>> newCols = new ArrayList<IColumn<T, S>>(); | ||
newCols.addAll(columns); | ||
newCols.add(newActionsColumn()); | ||
|
||
add(buildForm(newCols, dataProvider, rowsPerPage, clazz)); | ||
} | ||
|
||
private Component buildForm(final List<? extends IColumn<T, S>> columns, | ||
final IEditableDataProvider<T, S> dataProvider, long rowsPerPage, Class<T> clazz) | ||
{ | ||
Form<T> form = new NonValidatingForm<T>("form"); | ||
form.setOutputMarkupId(true); | ||
this.dataTable = newDataTable(columns, dataProvider, rowsPerPage, clazz); | ||
form.add(this.dataTable); | ||
return form; | ||
} | ||
|
||
public final DgEditableGrid<T, S> setTableBodyCss(final String cssStyle) | ||
{ | ||
this.dataTable.setTableBodyCss(cssStyle); | ||
return this; | ||
} | ||
|
||
public final DgEditableGrid<T, S> setTableCss(final String cssStyle) | ||
{ | ||
this.dataTable.add(AttributeModifier.replace("class", cssStyle)); | ||
return this; | ||
} | ||
|
||
private static class NonValidatingForm<T> extends Form<T> | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
public NonValidatingForm(String id) | ||
{ | ||
super(id); | ||
} | ||
@Override | ||
public void process(IFormSubmitter submittingComponent) | ||
{ | ||
delegateSubmit(submittingComponent); | ||
} | ||
|
||
} | ||
|
||
private EditableDataTable<T, S> newDataTable(final List<? extends IColumn<T, S>> columns, | ||
final IEditableDataProvider<T, S> dataProvider, long rowsPerPage, Class<T> clazz) | ||
{ | ||
final EditableDataTable<T, S> dataTable = new EditableDataTable<T, S>("dataTable", columns, | ||
dataProvider, rowsPerPage, clazz) | ||
{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected void onError(AjaxRequestTarget target) | ||
{ | ||
DgEditableGrid.this.onError(target); | ||
} | ||
@Override | ||
protected Item<T> newRowItem(String id, int index, IModel<T> model) { | ||
return super.newRowItem(id, index, model); | ||
} | ||
}; | ||
|
||
dataTable.setOutputMarkupId(true); | ||
|
||
dataTable.addTopToolbar(new DgEditableGridNavigationToolbar(dataTable) { | ||
@Override | ||
protected PagingNavigator newPagingNavigator(String navigatorId, EditableDataTable<?, ?> table) { | ||
return new BootstrapAjaxPagingNavigator(navigatorId, table); | ||
} | ||
}); | ||
dataTable.addTopToolbar(new EditableGridHeadersToolbar<T, S>(dataTable, dataProvider)); | ||
if (displayAddFeature()) | ||
{ | ||
dataTable.addBottomToolbar(newAddBottomToolbar(dataProvider, clazz, dataTable)); | ||
} | ||
|
||
return dataTable; | ||
} | ||
|
||
protected RowItem<T> newRowItem(String id, int index, IModel<T> model) { | ||
return new RowItem<T>(id, index, model); | ||
} | ||
|
||
private DgEditableGridBottomToolbar<T, S> newAddBottomToolbar( | ||
final IEditableDataProvider<T, S> dataProvider, Class<T> clazz, | ||
final EditableDataTable<T, S> dataTable) | ||
{ | ||
return new DgEditableGridBottomToolbar<T, S>(dataTable, clazz) | ||
{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected void onAdd(AjaxRequestTarget target, T newRow) | ||
{ | ||
dataProvider.add(newRow); | ||
target.add(dataTable); | ||
DgEditableGrid.this.onAdd(target, newRow); | ||
} | ||
|
||
@Override | ||
protected void onError(AjaxRequestTarget target) | ||
{ | ||
super.onError(target); | ||
DgEditableGrid.this.onError(target); | ||
} | ||
|
||
}; | ||
} | ||
|
||
private EditableGridActionsColumn<T, S> newActionsColumn() | ||
{ | ||
return new EditableGridActionsColumn<T, S>(new Model<String>("Actions")) | ||
{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected void onError(AjaxRequestTarget target, IModel<T> rowModel) | ||
{ | ||
DgEditableGrid.this.onError(target); | ||
} | ||
|
||
@Override | ||
protected void onSave(AjaxRequestTarget target, IModel<T> rowModel) | ||
{ | ||
DgEditableGrid.this.onSave(target, rowModel); | ||
} | ||
|
||
@Override | ||
protected void onDelete(AjaxRequestTarget target, IModel<T> rowModel) | ||
{ | ||
DgEditableGrid.this.onDelete(target, rowModel); | ||
} | ||
|
||
@Override | ||
protected void onCancel(AjaxRequestTarget target) | ||
{ | ||
DgEditableGrid.this.onCancel(target); | ||
} | ||
|
||
@Override | ||
protected boolean allowDelete(Item<T> rowItem) { | ||
return DgEditableGrid.this.allowDelete(rowItem); | ||
} | ||
}; | ||
} | ||
|
||
protected boolean allowDelete(Item<T> rowItem) { | ||
return true; | ||
} | ||
|
||
protected void onCancel(AjaxRequestTarget target) | ||
{ | ||
|
||
} | ||
|
||
|
||
protected void onDelete(AjaxRequestTarget target, IModel<T> rowModel) | ||
{ | ||
|
||
} | ||
|
||
protected void onSave(AjaxRequestTarget target, IModel<T> rowModel) | ||
{ | ||
|
||
} | ||
|
||
protected void onError(AjaxRequestTarget target) | ||
{ | ||
|
||
} | ||
|
||
protected void onAdd(AjaxRequestTarget target, T newRow) | ||
{ | ||
|
||
} | ||
|
||
protected boolean displayAddFeature() { | ||
return true; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...java/org/devgateway/toolkit/forms/wicket/components/form/DgEditableGridBottomToolbar.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
<html xmlns:wicket="http://wicket.sourceforge.net/"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||
<title>EditableGrid Table Toolbar</title> | ||
</head> | ||
<body> | ||
<wicket:panel> | ||
|
||
<tr> | ||
<form wicket:id ="addToolbarForm"> | ||
<td wicket:id="cells"> | ||
<span wicket:id="cell">[cell data]</span> | ||
</td> | ||
|
||
<td> | ||
<a wicket:id="add" href="#">Add</a> | ||
</td> | ||
|
||
</form> | ||
</tr> | ||
|
||
</wicket:panel> | ||
</body> | ||
</html> |
Oops, something went wrong.