public final class CmsVaadinUtils extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
CmsVaadinUtils.OptionGroupBuilder
Helper class for building option groups.
|
static class |
CmsVaadinUtils.PropertyId
Container property ids.
|
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
BOOTSTRAP_SCRIPT
The Vaadin bootstrap script, with some macros to be dynamically replaced later.
|
static com.vaadin.data.Container.Filter |
FILTER_NO_FOLDERS
Container filter for the resource type container to show not folder types only.
|
static com.vaadin.data.Container.Filter |
FILTER_XML_CONTENTS
Container filter for the resource type container to show XML content types only.
|
static java.lang.String |
PROPERTY_LABEL
The combo box label item property id.
|
static java.lang.String |
PROPERTY_VALUE
The combo box value item property id.
|
Modifier and Type | Method and Description |
---|---|
static com.vaadin.data.util.IndexedContainer |
buildContainerFromMap(java.lang.String captionProperty,
java.util.Map<java.lang.String,java.lang.String> map)
Builds a container for use in combo boxes from a map of key/value pairs, where the keys are options and the values are captions.
|
static com.vaadin.ui.Button.ClickListener |
createClickListener(java.lang.Runnable action)
Creates a click listener which calls a Runnable when activated.
|
static java.io.InputStream |
filterUtf8ResourceStream(java.io.InputStream stream,
com.google.common.base.Function<java.lang.String,java.lang.String> transformation)
Reads the content of an input stream into a string (using UTF-8 encoding), performs a function on the string, and returns the result
again as an input stream.
|
static java.util.List<CmsProject> |
getAvailableProjects(CmsObject cms)
Returns the available projects.
|
static com.vaadin.data.util.IndexedContainer |
getAvailableSitesContainer(CmsObject cms,
java.lang.String captionPropertyName)
Builds an IndexedContainer containing the sites selectable by the current user.
|
static java.lang.String |
getBootstrapScript(CmsObject cms,
java.lang.String elementId,
java.lang.String servicePath)
Returns the Javascript code to use for initializing a Vaadin UI.
|
static java.lang.String |
getDefaultDesignPath(com.vaadin.ui.Component component)
Returns the path to the design template file of the given component.
|
static java.lang.String |
getMessageText(java.lang.String key,
java.lang.Object... args)
Gets the workplace message for the current locale and the given key and arguments.
|
static com.vaadin.data.util.IndexedContainer |
getProjectsContainer(CmsObject cms,
java.lang.String captionPropertyName)
Returns the selectable projects container.
|
static javax.servlet.http.HttpServletRequest |
getRequest()
Gets the current Vaadin request, cast to a HttpServletRequest.
|
static com.vaadin.data.util.IndexedContainer |
getResourceTypesContainer()
Returns the available resource types container.
|
static com.vaadin.ui.Window |
getWindow(com.vaadin.ui.Component component)
Gets the window which contains a given component.
|
static java.lang.String |
getWorkplaceLink()
Gets the link to the (new) workplace.
|
static com.vaadin.server.ExternalResource |
getWorkplaceResource(java.lang.String subPath)
Gets external resource from workplace resource folder.
|
static CmsMessages |
getWpMessagesForCurrentLocale()
Gets the workplace messages for the current locale.
|
static java.lang.String |
localizeString(java.lang.String baseString)
Uses the currently set locale to resolve localization macros in the input string using workplace message bundles.
|
static java.lang.String |
messageCancel()
Message accessior function.
|
static java.lang.String |
messageOk()
Message accessor function.
|
static void |
prepareComboBox(com.vaadin.ui.ComboBox box,
java.util.Map<?,java.lang.String> options)
Generates the options items for the combo box using the map entry keys as values and the values as labels.
|
static void |
readAndLocalizeDesign(com.vaadin.ui.Component component,
CmsMessages messages,
java.util.Map<java.lang.String,java.lang.String> macros)
Reads the declarative design for a component and localizes it using a messages object.
|
protected static void |
readAndLocalizeDesign(com.vaadin.ui.Component component,
java.io.InputStream designStream,
CmsMessages messages,
java.util.Map<java.lang.String,java.lang.String> macros)
Reads the given design and resolves the given macros and localizations.
|
static java.io.InputStream |
readCustomLayout(java.lang.Class<? extends com.vaadin.ui.Component> layoutClass,
java.lang.String relativeName)
Reads a layout from a resource, applies basic i18n macro substitution on the contained text, and returns a stream of the transformed
data.
|
static <T> void |
setReadonlyValue(com.vaadin.ui.AbstractField<T> field,
T value)
Sets the value of a text field which may be set to read-only mode.
|
static void |
showAlert(java.lang.String title,
java.lang.String message,
java.lang.Runnable callback)
Shows an alert box to the user with the given information, which will perform the given action after the user clicks on OK.
|
static CmsVaadinUtils.OptionGroupBuilder |
startOptionGroup()
Creates a new option group builder.
|
static void |
visitDescendants(com.vaadin.ui.Component component,
com.google.common.base.Predicate<com.vaadin.ui.Component> handler)
Visits all descendants of a given component (including the component itself) and applies a predicate
to each.
|
public static final com.vaadin.data.Container.Filter FILTER_NO_FOLDERS
public static final com.vaadin.data.Container.Filter FILTER_XML_CONTENTS
public static final java.lang.String PROPERTY_LABEL
public static final java.lang.String PROPERTY_VALUE
protected static final java.lang.String BOOTSTRAP_SCRIPT
public static com.vaadin.data.util.IndexedContainer buildContainerFromMap(java.lang.String captionProperty, java.util.Map<java.lang.String,java.lang.String> map)
captionProperty
- the property name to use for captionsmap
- the mappublic static com.vaadin.ui.Button.ClickListener createClickListener(java.lang.Runnable action)
action
- the Runnable to execute on a clickpublic static java.io.InputStream filterUtf8ResourceStream(java.io.InputStream stream, com.google.common.base.Function<java.lang.String,java.lang.String> transformation)
stream
- the stream producing the input datatransformation
- the function to apply to the inputpublic static java.util.List<CmsProject> getAvailableProjects(CmsObject cms)
cms
- the CMS contextpublic static com.vaadin.data.util.IndexedContainer getAvailableSitesContainer(CmsObject cms, java.lang.String captionPropertyName)
cms
- the CMS contextcaptionPropertyName
- the name of the property used to store captionspublic static java.lang.String getBootstrapScript(CmsObject cms, java.lang.String elementId, java.lang.String servicePath) throws java.lang.Exception
cms
- the CMS contextelementId
- the id of the DOM element in which to initialize the UIservicePath
- the UI servlet pathjava.lang.Exception
- if something goes wrongpublic static java.lang.String getDefaultDesignPath(com.vaadin.ui.Component component)
component
- the componentpublic static java.lang.String getMessageText(java.lang.String key, java.lang.Object... args)
key
- the message keyargs
- the message argumentspublic static com.vaadin.data.util.IndexedContainer getProjectsContainer(CmsObject cms, java.lang.String captionPropertyName)
cms
- the CMS contextcaptionPropertyName
- the name of the property used to store captionspublic static javax.servlet.http.HttpServletRequest getRequest()
public static com.vaadin.data.util.IndexedContainer getResourceTypesContainer()
public static com.vaadin.ui.Window getWindow(com.vaadin.ui.Component component)
component
- the componentpublic static java.lang.String getWorkplaceLink()
public static com.vaadin.server.ExternalResource getWorkplaceResource(java.lang.String subPath)
subPath
- path relative to workplace resource folderpublic static CmsMessages getWpMessagesForCurrentLocale()
public static java.lang.String localizeString(java.lang.String baseString)
baseString
- the string to localizepublic static java.lang.String messageCancel()
public static java.lang.String messageOk()
public static void prepareComboBox(com.vaadin.ui.ComboBox box, java.util.Map<?,java.lang.String> options)
box
- the combo box to prepareoptions
- the box optionspublic static void readAndLocalizeDesign(com.vaadin.ui.Component component, CmsMessages messages, java.util.Map<java.lang.String,java.lang.String> macros)
The design will need to be located in the same directory as the component's class and have '.html' as a file extension.
component
- the component for which to read the designmessages
- the message bundle to use for localizationmacros
- the macros to use on the HTML templatepublic static java.io.InputStream readCustomLayout(java.lang.Class<? extends com.vaadin.ui.Component> layoutClass, java.lang.String relativeName)
layoutClass
- the class relative to which the layout resource will be looked uprelativeName
- the file name of the layout filepublic static <T> void setReadonlyValue(com.vaadin.ui.AbstractField<T> field, T value)
When setting a Vaadin field to read-only, you also can't set its value programmatically anymore. So we need to temporarily disable read-only mode, set the value, and then switch back to read-only mode.
field
- the fieldvalue
- the value to setpublic static void showAlert(java.lang.String title, java.lang.String message, java.lang.Runnable callback)
title
- the titlemessage
- the messagecallback
- the callback to execute after clicking OKpublic static CmsVaadinUtils.OptionGroupBuilder startOptionGroup()
public static void visitDescendants(com.vaadin.ui.Component component, com.google.common.base.Predicate<com.vaadin.ui.Component> handler)
If the predicate returns false for a component, no further descendants will be processed.
component
- the componenthandler
- the predicateprotected static void readAndLocalizeDesign(com.vaadin.ui.Component component, java.io.InputStream designStream, CmsMessages messages, java.util.Map<java.lang.String,java.lang.String> macros)
component
- the component whose design to readdesignStream
- stream to read the design frommessages
- the message bundle to use for localization in the design (may be null)macros
- other macros to substitute in the macro design (may be null)