org.opencms.widgets
Class CmsCategoryWidget

java.lang.Object
  extended by org.opencms.widgets.A_CmsWidget
      extended by org.opencms.widgets.CmsCategoryWidget
All Implemented Interfaces:
I_CmsWidget

public class CmsCategoryWidget
extends A_CmsWidget

Provides a widget for a category based dependent select boxes.

Since:
7.0.3
Version:
$Revision: 1.8 $
Author:
Michael Moossen

Field Summary
static java.lang.String CONFIGURATION_CATEGORY
          Configuration parameter to set the category to display.
static java.lang.String CONFIGURATION_ONLYLEAFS
          Configuration parameter to set the 'only leaf' flag parameter.
static java.lang.String CONFIGURATION_PROPERTY
          Configuration parameter to set the 'property' parameter.
 
Fields inherited from class org.opencms.widgets.A_CmsWidget
HELP_POSTFIX, LABEL_PREFIX
 
Constructor Summary
CmsCategoryWidget()
          Creates a new category widget.
CmsCategoryWidget(java.lang.String configuration)
          Creates a category widget with the specified options.
 
Method Summary
protected  java.lang.String buildSelectBox(java.lang.String baseId, int level, java.util.List options, java.lang.String selected, boolean hasError, boolean last)
          Generates html code for the category selection.
 java.lang.String getConfiguration()
          Returns the configuration string.
protected  java.util.Locale getDefaultLocale(CmsObject cms, java.lang.String resource)
          Returns the default locale in the content of the given resource.
 java.lang.String getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog)
          Generates the necessary JavaScript inclusion code for this widget.
 java.lang.String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param)
          Generates the widget HTML for the provided widget parameter.
protected  CmsResource getResource(CmsObject cms, I_CmsWidgetParameter param)
          Returns the right resource, depending on the locale.
protected  java.lang.String getStartingCategory(CmsObject cms, java.lang.String referencePath)
          Returns the starting category depending on the configuration options.
 boolean isOnlyLeafs()
          Check if only leaf selection is allowed.
 I_CmsWidget newInstance()
          Creates a duplicate of this widget instance.
 void setConfiguration(java.lang.String configuration)
          Sets the configuration of this widget.
 void setEditorValue(CmsObject cms, java.util.Map formParameters, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param)
          Sets the value of in the given widget parameter by reading the "right" value from the offered map of parameters.
 
Methods inherited from class org.opencms.widgets.A_CmsWidget
equals, getDialogHtmlEnd, getDialogInitCall, getDialogInitMethod, getHelpBubble, getHelpKey, getHelpText, getJsHelpMouseHandler, getJSIncludeFile, getLabelKey, getWidgetStringValue, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIGURATION_CATEGORY

public static final java.lang.String CONFIGURATION_CATEGORY
Configuration parameter to set the category to display.

See Also:
Constant Field Values

CONFIGURATION_ONLYLEAFS

public static final java.lang.String CONFIGURATION_ONLYLEAFS
Configuration parameter to set the 'only leaf' flag parameter.

See Also:
Constant Field Values

CONFIGURATION_PROPERTY

public static final java.lang.String CONFIGURATION_PROPERTY
Configuration parameter to set the 'property' parameter.

See Also:
Constant Field Values
Constructor Detail

CmsCategoryWidget

public CmsCategoryWidget()
Creates a new category widget.


CmsCategoryWidget

public CmsCategoryWidget(java.lang.String configuration)
Creates a category widget with the specified options.

Parameters:
configuration - the configuration for the widget
Method Detail

getConfiguration

public java.lang.String getConfiguration()
Description copied from class: A_CmsWidget
Returns the configuration string.

Specified by:
getConfiguration in interface I_CmsWidget
Overrides:
getConfiguration in class A_CmsWidget
Returns:
the configuration string
See Also:
A_CmsWidget.getConfiguration()

getDialogIncludes

public java.lang.String getDialogIncludes(CmsObject cms,
                                          I_CmsWidgetDialog widgetDialog)
Description copied from interface: I_CmsWidget
Generates the necessary JavaScript inclusion code for this widget.

Specified by:
getDialogIncludes in interface I_CmsWidget
Overrides:
getDialogIncludes in class A_CmsWidget
Parameters:
cms - the current users OpenCms context
widgetDialog - the dialog where the widget is used on
Returns:
the JavaScript inclusion code
See Also:
I_CmsWidget.getDialogIncludes(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)

setEditorValue

public void setEditorValue(CmsObject cms,
                           java.util.Map formParameters,
                           I_CmsWidgetDialog widgetDialog,
                           I_CmsWidgetParameter param)
Description copied from interface: I_CmsWidget
Sets the value of in the given widget parameter by reading the "right" value from the offered map of parameters.

Specified by:
setEditorValue in interface I_CmsWidget
Overrides:
setEditorValue in class A_CmsWidget
Parameters:
cms - the current users OpenCms context
formParameters - the map of parameters to get the value from
widgetDialog - the dialog where the widget is used on
param - the widget parameter to generate the widget for
See Also:
A_CmsWidget.setEditorValue(org.opencms.file.CmsObject, java.util.Map, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)

getDialogWidget

public java.lang.String getDialogWidget(CmsObject cms,
                                        I_CmsWidgetDialog widgetDialog,
                                        I_CmsWidgetParameter param)
Description copied from interface: I_CmsWidget
Generates the widget HTML for the provided widget parameter.

Parameters:
cms - an initialized instance of a CmsObject
widgetDialog - the dialog where the widget is used on
param - the widget parameter to generate the widget for
Returns:
the widget HTML for the provided widget parameter
See Also:
I_CmsWidget.getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)

isOnlyLeafs

public boolean isOnlyLeafs()
Check if only leaf selection is allowed.

Returns:
true, if only leaf selection is allowed

newInstance

public I_CmsWidget newInstance()
Description copied from interface: I_CmsWidget
Creates a duplicate of this widget instance.

Returns:
a duplicate of this widget instance
See Also:
I_CmsWidget.newInstance()

setConfiguration

public void setConfiguration(java.lang.String configuration)
Description copied from interface: I_CmsWidget
Sets the configuration of this widget.

This can be used to enable / disable certain widget features that should not always be available, or to pass specific initialization information to the widget. It depends on the widget implementation on how this information is used.

Specified by:
setConfiguration in interface I_CmsWidget
Overrides:
setConfiguration in class A_CmsWidget
Parameters:
configuration - the configuration to set
See Also:
A_CmsWidget.setConfiguration(java.lang.String)

buildSelectBox

protected java.lang.String buildSelectBox(java.lang.String baseId,
                                          int level,
                                          java.util.List options,
                                          java.lang.String selected,
                                          boolean hasError,
                                          boolean last)
Generates html code for the category selection.

Parameters:
baseId - the widget id
level - the category deep level
options - the list of CmsSelectWidgetOption objects
selected - the selected option
hasError - if to display error message
last - if it is the last level
Returns:
html code

getDefaultLocale

protected java.util.Locale getDefaultLocale(CmsObject cms,
                                            java.lang.String resource)
Returns the default locale in the content of the given resource.

Parameters:
cms - the cms context
resource - the resource path to get the default locale for
Returns:
the default locale of the resource

getResource

protected CmsResource getResource(CmsObject cms,
                                  I_CmsWidgetParameter param)
Returns the right resource, depending on the locale.

Parameters:
cms - the cms context
param - the widget parameter
Returns:
the resource to get/set the categories for

getStartingCategory

protected java.lang.String getStartingCategory(CmsObject cms,
                                               java.lang.String referencePath)
Returns the starting category depending on the configuration options.

Parameters:
cms - the cms context
referencePath - the right resource path
Returns:
the starting category