org.apache.wicket.extensions.markup.html.form.palette
Class Palette<T>

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.MarkupContainer
          extended by org.apache.wicket.markup.html.WebMarkupContainer
              extended by org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup
                  extended by org.apache.wicket.markup.html.panel.Panel
                      extended by org.apache.wicket.extensions.markup.html.form.palette.Palette<T>
Type Parameters:
T - Type of model object
All Implemented Interfaces:
Serializable, IClusterable, IConverterLocator, IHeaderContributor, IHeaderPartContainerProvider

public class Palette<T>
extends Panel
implements IHeaderContributor

Palette is a component that allows the user to easily select and order multiple items by moving them from one select box into another.

When creating a Palette object make sure your IChoiceRenderer returns a specific ID, not the index.

Ajaxifying the palette: The palette itself cannot be ajaxified because it is a panel and therefore does not receive any javascript events. Instead ajax behaviors can be attached to the recorder component which supports the javascript onchange event. The behavior should be attached by overriding newRecorderComponent() Example:

  Form form=new Form(...);
  Palette palette=new Palette(...) {
    protected Recorder newRecorderComponent()
    {
      Recorder recorder=super.newRecorderComponent();     
      recorder.add(new AjaxFormComponentUpdatingBehavior("onchange") {...});
      return recorder;
    }
  }
 
 

Author:
Igor Vaynberg ( ivaynberg )
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.wicket.Component
Component.ComponentModelChange, Component.EnabledChange, Component.IVisitor<T extends Component>, Component.VisibilityChange
 
Field Summary
 
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_CONFIGURED, FLAG_INITIALIZED, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER
 
Constructor Summary
Palette(String id, IModel<? extends Collection<? extends T>> choicesModel, IChoiceRenderer<T> choiceRenderer, int rows, boolean allowOrder)
           
Palette(String id, IModel<List<T>> model, IModel<? extends Collection<? extends T>> choicesModel, IChoiceRenderer<T> choiceRenderer, int rows, boolean allowOrder)
           
 
Method Summary
protected  String buildJSCall(String funcName)
          builds javascript handler call
protected  Map<String,String> getAdditionalAttributesForChoices(Object choice)
           
protected  Map<String,String> getAdditionalAttributesForSelection(Object choice)
           
 String getAddOnClickJS()
           
 IChoiceRenderer<T> getChoiceRenderer()
           
 Collection<? extends T> getChoices()
           
protected  Component getChoicesComponent()
           
 String getChoicesOnFocusJS()
           
protected  ResourceReference getCSS()
          Returns the resource reference of the default stylesheet.
 String getDownOnClickJS()
           
 Collection<T> getModelCollection()
           
 Recorder<T> getRecorderComponent()
          Returns recorder component.
 String getRemoveOnClickJS()
           
 int getRows()
           
 Iterator<T> getSelectedChoices()
           
protected  Component getSelectionComponent()
           
 String getSelectionOnFocusJS()
           
protected  StyleSheetReference getStyleSheet()
          Can be overridden by clients for custom style sheet
 Iterator<T> getUnselectedChoices()
           
 String getUpOnClickJS()
           
 boolean isPaletteEnabled()
          Return true if the palette is enabled, false otherwise
protected  Component newAddComponent()
          factory method for the addcomponent
protected  Component newAvailableHeader(String componentId)
          factory method for the available items header
protected  Component newChoicesComponent()
          factory method for the available items component
protected  Component newDownComponent()
          factory method for the move down component
protected  Recorder<T> newRecorderComponent()
          factory method to create the tracker component
protected  Component newRemoveComponent()
          factory method for the remove component
protected  Component newSelectedHeader(String componentId)
          factory method for the selected items header
protected  Component newSelectionComponent()
          factory method for the selected items component
protected  Component newUpComponent()
          factory method for the move up component
protected  void onBeforeRender()
          Called just before a component is rendered.
protected  void onDetach()
          Called to allow a component to detach resources after use.
 void renderHead(IHeaderResponse response)
          Renders header contributions
protected  void updateModel()
          The model object is assumed to be a Collection, and it is modified in-place.
 
Methods inherited from class org.apache.wicket.markup.html.panel.Panel
onComponentTag, onComponentTagBody, renderHead
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup
newHeaderPartContainer, renderHeadFromAssociatedMarkupFile
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getMarkupType, getWebPage, getWebRequest
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, autoAdd, contains, findMarkupStream, get, get, getAssociatedMarkupStream, getMarkupStream, hasAssociatedMarkup, internalAdd, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onAfterRenderChildren, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, renderNext, replace, setDefaultModel, setMarkupStream, size, swap, toString, toString, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, callOnBeforeRenderIfNotVisible, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, configure, continueToOriginalDestination, debug, detach, detachBehaviors, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getBehaviors, getBehaviors, getBehaviorsRawList, getClassRelativePath, getComponentBorder, getConverter, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdImpl, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalAttach, internalDetach, internalOnAttach, internalOnDetach, internalOnModelChanged, isActionAuthorized, isAncestorOf, isAttached, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markAttached, markRendering, modelChanged, modelChanging, onAfterRender, onAttach, onBeginRequest, onConfigure, onEndRequest, onInitialize, onModelChanged, onModelChanging, onRemove, prepareForRender, prepareForRender, redirectToInterceptPage, remove, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, setAuto, setComponentBorder, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, urlFor, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Palette

public Palette(String id,
               IModel<? extends Collection<? extends T>> choicesModel,
               IChoiceRenderer<T> choiceRenderer,
               int rows,
               boolean allowOrder)
Parameters:
id - Component id
choicesModel - Model representing collection of all available choices
choiceRenderer - Render used to render choices. This must use unique IDs for the objects, not the index.
rows - Number of choices to be visible on the screen with out scrolling
allowOrder - Allow user to move selections up and down

Palette

public Palette(String id,
               IModel<List<T>> model,
               IModel<? extends Collection<? extends T>> choicesModel,
               IChoiceRenderer<T> choiceRenderer,
               int rows,
               boolean allowOrder)
Parameters:
id - Component id
model - Model representing collection of user's selections
choicesModel - Model representing collection of all available choices
choiceRenderer - Render used to render choices. This must use unique IDs for the objects, not the index.
rows - Number of choices to be visible on the screen with out scrolling
allowOrder - Allow user to move selections up and down
Method Detail

onBeforeRender

protected void onBeforeRender()
Description copied from class: Component
Called just before a component is rendered.

NOTE: If you override this, you *must* call super.onBeforeRender() within your implementation. Because this method is responsible for cascading Component.onBeforeRender() call to its children it is strongly recommended that super call is made at the end of the override.

Overrides:
onBeforeRender in class Component
See Also:
Component.callOnBeforeRenderIfNotVisible()

getCSS

protected ResourceReference getCSS()
Returns the resource reference of the default stylesheet. You may return null to avoid using any stylesheet.

Returns:
A resource reference

getStyleSheet

protected StyleSheetReference getStyleSheet()
Can be overridden by clients for custom style sheet

Returns:
the style sheet reference

isPaletteEnabled

public final boolean isPaletteEnabled()
Return true if the palette is enabled, false otherwise

Returns:
true if the palette is enabled, false otherwise

getSelectedChoices

public Iterator<T> getSelectedChoices()
Returns:
iterator over selected choices

getUnselectedChoices

public Iterator<T> getUnselectedChoices()
Returns:
iterator over unselected choices

newRecorderComponent

protected Recorder<T> newRecorderComponent()
factory method to create the tracker component

Returns:
tracker component

newAvailableHeader

protected Component newAvailableHeader(String componentId)
factory method for the available items header

Parameters:
componentId - component id of the returned header component
Returns:
available items component

newSelectedHeader

protected Component newSelectedHeader(String componentId)
factory method for the selected items header

Parameters:
componentId - component id of the returned header component
Returns:
header component

newDownComponent

protected Component newDownComponent()
factory method for the move down component

Returns:
move down component

newUpComponent

protected Component newUpComponent()
factory method for the move up component

Returns:
move up component

newRemoveComponent

protected Component newRemoveComponent()
factory method for the remove component

Returns:
remove component

newAddComponent

protected Component newAddComponent()
factory method for the addcomponent

Returns:
add component

newSelectionComponent

protected Component newSelectionComponent()
factory method for the selected items component

Returns:
selected items component

getAdditionalAttributesForSelection

protected Map<String,String> getAdditionalAttributesForSelection(Object choice)
See Also:
AbstractOptions.getAdditionalAttributes(Object)

newChoicesComponent

protected Component newChoicesComponent()
factory method for the available items component

Returns:
available items component

getAdditionalAttributesForChoices

protected Map<String,String> getAdditionalAttributesForChoices(Object choice)
See Also:
AbstractOptions.getAdditionalAttributes(Object)

getChoicesComponent

protected Component getChoicesComponent()

getSelectionComponent

protected Component getSelectionComponent()

getRecorderComponent

public final Recorder<T> getRecorderComponent()
Returns recorder component. Recorder component is a form component used to track the selection of the palette. It receives onchange javascript event whenever a change in selection occurs.

Returns:
recorder component

getChoices

public Collection<? extends T> getChoices()
Returns:
collection representing all available items

getModelCollection

public Collection<T> getModelCollection()
Returns:
collection representing selected items

getChoiceRenderer

public IChoiceRenderer<T> getChoiceRenderer()
Returns:
choice renderer

getRows

public int getRows()
Returns:
items visible without scrolling

updateModel

protected final void updateModel()
The model object is assumed to be a Collection, and it is modified in-place. Then IModel.setObject(Object) is called with the same instance: it allows the Model to be notified of changes even when Model.getObject() returns a different Collection at every invocation.

See Also:
FormComponent.updateModel()

buildJSCall

protected String buildJSCall(String funcName)
builds javascript handler call

Parameters:
funcName - name of javascript function to call
Returns:
string representing the call tho the function with palette params

getChoicesOnFocusJS

public String getChoicesOnFocusJS()
Returns:
choices component on focus javascript handler

getSelectionOnFocusJS

public String getSelectionOnFocusJS()
Returns:
selection component on focus javascript handler

getAddOnClickJS

public String getAddOnClickJS()
Returns:
add action javascript handler

getRemoveOnClickJS

public String getRemoveOnClickJS()
Returns:
remove action javascript handler

getUpOnClickJS

public String getUpOnClickJS()
Returns:
move up action javascript handler

getDownOnClickJS

public String getDownOnClickJS()
Returns:
move down action javascript handler

onDetach

protected void onDetach()
Description copied from class: Component
Called to allow a component to detach resources after use. Overrides of this method MUST call the super implementation, the most logical place to do this is the last line of the override method.

Overrides:
onDetach in class Component

renderHead

public void renderHead(IHeaderResponse response)
Renders header contributions

Specified by:
renderHead in interface IHeaderContributor
Parameters:
response -


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.