Show IWidgetPublisher.java syntax highlighted
package org.integratedmodelling.thinkcap.widget;
import java.util.HashMap;
import org.apache.velocity.VelocityContext;
import org.integratedmodelling.thinkcap.ThinkcapSession;
import org.integratedmodelling.thinklab.exception.ThinklabException;
/**
* One of these is created and installed for a particular widget type for each widget we want
* available through template macros. It's used by the widget manager to create a widget by class name
* and to process the response to it between template renderings (if the widget allows input).
*
* @see ThinkcapWidgetManager.registerWidgetPublisher
* @author Ferdinando Villa
*
*/
public interface IWidgetPublisher {
/**
* Create a widget of the particular type we're installed for. Use passed arguments. If the widget
* is implemented as a macro and has no java peer, just return null.
*
* @param name
* @param session
* @param parameters
* @return
*/
public abstract IThinkcapWidget constructWidget(String name, ThinkcapSession session, Object ... parameters);
/**
* Must return a unique widget class name.
* @return
*/
public abstract String getWidgetClassName();
/**
* <p>This one is called only if a field is found in the response that is called
* widget_signature_xxxx (where xxxx is the name of the widget it comes from) and
* has the widget class name as value (must be the class name registered with ThinkCap, not
* necessarily the actual Java class name). If called, it is supposed to do the following:</p>
*
* <ul>
* <li>Process the response by extracting all fields that come from the widget;</li>
* <li>Create any necessary processed response and set it in the context</li>
* <li>Remove all "raw" widget fields from the context</li>
* </ul>
*
* <p>Its obvious use is in input widgets. When used properly, all the logics of widget processing
* can be hidden in the widget constructor, and no additional Java is necessary to implement
* a page containing widgets.</p>
*
* <p>If a widget does not need this one it will not be called, so just define it to
* do nothing. </p>
*
* @param args
* @param ctx
* @throws IMAException
*/
public abstract void processWidgetResponse(String widgetName, HashMap<String, String> args,
VelocityContext ctx) throws ThinklabException;
}
See more files for this project here