Skip to content

Commit

Permalink
fixes #346
Browse files Browse the repository at this point in the history
  • Loading branch information
mpostelnicu committed Nov 30, 2020
1 parent 19f5047 commit 223486f
Show file tree
Hide file tree
Showing 19 changed files with 1,002 additions and 4 deletions.
6 changes: 6 additions & 0 deletions forms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>wicketstuff-editable-grid</artifactId>
<version>${wicket.version}</version>
</dependency>

<dependency>
<groupId>org.devgateway.toolkit</groupId>
<artifactId>persistence-mongodb</artifactId>
Expand Down
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)
{

}
}
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>
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;
}
}
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>
Loading

0 comments on commit 223486f

Please sign in to comment.