Per-request configuration of WYSIWIG-Editor buttonbar
From OpenCms Wiki
(Difference between revisions)
(New page: The following CustomWidget shows an approach, how to render different button bars in WYSIWIG-Editor, dependent on the current request. The examples renders different button bars for users...) |
m (activate syntax highlighting) |
||
Line 5: | Line 5: | ||
For the sake of brevity the example does not build the button bar definitions from the configuration. | For the sake of brevity the example does not build the button bar definitions from the configuration. | ||
− | < | + | <source lang="java"> |
package f3.widget; | package f3.widget; | ||
Line 106: | Line 106: | ||
} | } | ||
} | } | ||
− | </ | + | </source> |
Line 113: | Line 113: | ||
To use the widget, you would reference it in the xml schema defintion of your content type | To use the widget, you would reference it in the xml schema defintion of your content type | ||
− | < | + | <source lang="xml"> |
<xsd:annotation> | <xsd:annotation> | ||
<xsd:appinfo> | <xsd:appinfo> | ||
Line 124: | Line 124: | ||
</xsd:annotation> | </xsd:annotation> | ||
− | </ | + | </source> |
Latest revision as of 14:14, 22 December 2011
The following CustomWidget shows an approach, how to render different button bars in WYSIWIG-Editor, dependent on the current request.
The examples renders different button bars for users in different organization units. Of course, any other information from the request can be used as well to distinct button bar settings.
For the sake of brevity the example does not build the button bar definitions from the configuration.
package f3.widget; import org.opencms.file.CmsObject; import org.opencms.widgets.CmsHtmlWidget; import org.opencms.widgets.CmsHtmlWidgetOption; import org.opencms.widgets.I_CmsWidget; import org.opencms.widgets.I_CmsWidgetDialog; import org.opencms.widgets.I_CmsWidgetParameter; /** * This widget returns a WYSIWIG-Editor whose button bar * depends on the organization unit of the current user * * * @author cf * */ public class F3HtmlWidget extends CmsHtmlWidget{ // config for main organization unit private CmsHtmlWidgetOption forMainOU = new CmsHtmlWidgetOption("link, source, buttonbar:" + "[;undo;redo;-;find;replace;-;selectall;removeformat;-;cut;copy;paste;-;bold;italic;-;subscript;superscript;];" + "[;orderedlist;unorderedlist;];[;source;-;formatselect;style;editorlink;link;anchor;unlink;]; " + "[;imagegallery;downloadgallery;linkgallery;htmlgallery;tablegallery;-;-;specialchar;-;print;]"); // config for other organization units private CmsHtmlWidgetOption forOtherOU = new CmsHtmlWidgetOption("buttonbar:" + "[;undo;redo;-;find;replace;-;selectall;removeformat;-;cut;copy;paste;-;bold;italic;-;subscript;superscript;];" + "[;orderedlist;unorderedlist;]; [;specialchar;-;print;]"); /** * @see org.opencms.widgets.CmsHtmlWidget#getDialogIncludes(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog) */ @Override public String getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) { setConfiguration(cms); return super.getDialogIncludes(cms, widgetDialog); } /** * @see org.opencms.widgets.CmsHtmlWidget#getDialogInitCall(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog) */ @Override public String getDialogInitCall(CmsObject cms, I_CmsWidgetDialog widgetDialog) { setConfiguration(cms); return super.getDialogInitCall(cms, widgetDialog); } /** * @see org.opencms.widgets.CmsHtmlWidget#getDialogInitMethod(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog) */ @Override public String getDialogInitMethod(CmsObject cms, I_CmsWidgetDialog widgetDialog) { setConfiguration(cms); return super.getDialogInitMethod(cms, widgetDialog); } /** * @see org.opencms.widgets.CmsHtmlWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter) */ public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { setConfiguration(cms); return super.getDialogWidget(cms, widgetDialog, param); } /** * @see org.opencms.widgets.I_CmsWidget#newInstance() */ public I_CmsWidget newInstance() { return new F3HtmlWidget(); } /** * Sets the configuration dependent on the users OU * @param cms */ protected void setConfiguration(CmsObject cms){ // default setHtmlWidgetOption(forOtherOU); if(cms.getRequestContext().getCurrentUser()!=null){ if("".equals(cms.getRequestContext().getCurrentUser().getOuFqn())){ setHtmlWidgetOption(forMainOU); } } } }
Enabling the widget
To use the widget, you would reference it in the xml schema defintion of your content type
<xsd:annotation> <xsd:appinfo> ... <layouts> <layout element="articleText" widget="f3.widget.F3HtmlWidget"/> </layouts> ... </xsd:appinfo> </xsd:annotation>