com.premiumminds.webapp.wicket.bootstrap.crudifier.view.CrudifierView Maven / Gradle / Ivy
/**
* Copyright (C) 2014 Premium Minds.
*
* This file is part of pm-wicket-utils.
*
* pm-wicket-utils is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* pm-wicket-utils is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with pm-wicket-utils. If not, see .
*/
package com.premiumminds.webapp.wicket.bootstrap.crudifier.view;
import java.beans.PropertyDescriptor;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.wicket.IGenericComponent;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;
import com.premiumminds.webapp.wicket.bootstrap.crudifier.IObjectRenderer;
import com.premiumminds.webapp.wicket.bootstrap.crudifier.LabelProperty;
import com.premiumminds.webapp.wicket.bootstrap.crudifier.form.CrudifierEntitySettings;
public class CrudifierView extends Panel implements IGenericComponent {
private static final long serialVersionUID = -151637566983702881L;
private CrudifierEntitySettings entitySettings = new CrudifierEntitySettings();
private Map, IObjectRenderer>> renderers = new HashMap, IObjectRenderer>>();
public CrudifierView(String id, IModel model) {
super(id, model);
add(new Label("legend", new StringResourceModel("legend", this, getModel(), "Unknown")){
private static final long serialVersionUID = -7854751811138463187L;
@Override
protected void onConfigure() {
super.onConfigure();
setVisible(!getDefaultModelObjectAsString().isEmpty());
}
});
}
@Override
protected void onConfigure() {
RepeatingView view = new RepeatingView("control");
if(null != getModelObject()) {
for(final String property : getPropertiesByOrder(getModelObject().getClass())){
WebMarkupContainer control = new WebMarkupContainer(view.newChildId());
view.addOrReplace(control);
control.addOrReplace(new Label("label", new StringResourceModel("controls."+property+".label", this, getModel(), property)));
control.addOrReplace(new LabelProperty("input", new PropertyModel