All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.uqbar.wicket.xtend.WicketExtensionFactoryMethods Maven / Gradle / Ivy

package org.uqbar.wicket.xtend;

import com.google.common.base.Objects;
import java.io.Serializable;
import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.validation.IValidationError;
import org.apache.wicket.validation.ValidationError;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.uqbar.commons.model.Entity;
import org.uqbar.commons.model.Home;
import org.uqbar.commons.model.UserException;
import org.uqbar.commons.utils.ApplicationContext;
import org.uqbar.wicket.xtend.XButton;
import org.uqbar.wicket.xtend.XChoiceRenderer;
import org.uqbar.wicket.xtend.XLoadableDetachableModel;

/**
 * Wicket extension methods to make it easy to use in xtend.
 * Also using all the power that comes with xtend like extension methods, closures, etc.
 */
@SuppressWarnings("all")
public class WicketExtensionFactoryMethods implements Serializable {
  public  CompoundPropertyModel asCompoundModel(final M aModelObject) {
    return new CompoundPropertyModel(aModelObject);
  }
  
  public  Home home(final Class aType) {
    ApplicationContext _instance = ApplicationContext.getInstance();
    return _instance.>getSingleton(aType);
  }
  
  public IValidationError asValidationError(final String aMessage) {
    ValidationError _validationError = new ValidationError();
    final Procedure1 _function = new Procedure1() {
      public void apply(final ValidationError it) {
        it.setMessage(aMessage);
      }
    };
    return ObjectExtensions.operator_doubleArrow(_validationError, _function);
  }
  
  public void apply(final Component component, final Procedure0 procedure) {
    try {
      procedure.apply();
    } catch (final Throwable _t) {
      if (_t instanceof UserException) {
        final UserException e = (UserException)_t;
        String _message = e.getMessage();
        IValidationError _asValidationError = this.asValidationError(_message);
        component.error(_asValidationError);
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
  
  public MarkupContainer addChild(final MarkupContainer container, final Component child) {
    return container.add(child);
  }
  
  public Label label(final MarkupContainer container, final String id) {
    final Procedure1