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.v7.data.Container.Filter |
FILTER_NO_FOLDERS
Container filter for the resource type container to show not folder types only.
|
static com.vaadin.v7.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.v7.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 void |
centerWindow(com.vaadin.ui.Component component)
Centers the parent window of given component.
|
static void |
closeWindow(com.vaadin.ui.Component component)
Closes the window containing the given component.
|
static com.vaadin.ui.Button.ClickListener |
createClickListener(java.lang.Runnable action)
Creates a click listener which calls a Runnable when activated.
|
static <T> void |
defaultHandleContextMenuForMultiselect(com.vaadin.v7.ui.Table table,
CmsContextMenu menu,
com.vaadin.v7.event.ItemClickEvent event,
java.util.List<I_CmsSimpleContextMenuEntry<java.util.Collection<T>>> entries)
Simple context menu handler for multi-select tables.
|
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 com.vaadin.v7.data.util.IndexedContainer |
getAvailableGroupsContainerWithout(CmsObject cms,
java.lang.String ouFqn,
java.lang.String propCaption,
java.lang.String propIcon,
java.lang.String propOu,
java.util.List<CmsGroup> blackList,
java.util.function.Function<CmsGroup,CmsCssIcon> iconProvider)
Get all groups with blacklist.
|
static java.util.List<CmsProject> |
getAvailableProjects(CmsObject cms)
Returns the available projects.
|
static com.vaadin.v7.data.util.IndexedContainer |
getAvailableSitesContainer(CmsObject cms,
java.lang.String captionPropertyName)
Builds an IndexedContainer containing the sites selectable by the current user.
|
static java.util.LinkedHashMap<java.lang.String,java.lang.String> |
getAvailableSitesMap(CmsObject cms)
Gets available sites as a LinkedHashMap, with site roots as keys and site labels as values.
|
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 com.vaadin.v7.data.util.IndexedContainer |
getGroupsOfUser(CmsObject cms,
CmsUser user,
java.lang.String caption,
java.lang.String iconProp,
java.lang.String ou,
java.lang.String propStatus,
com.google.common.base.Function<CmsGroup,CmsCssIcon> iconProvider)
Gets container with alls groups of a certain user.
|
static com.vaadin.v7.ui.VerticalLayout |
getInfoLayout(java.lang.String messageString)
Creates a layout with info panel.
|
static com.vaadin.v7.data.util.IndexedContainer |
getLanguageContainer(java.lang.String captionPropertyName)
Get container with languages.
|
static java.lang.String |
getMessageText(I_CmsMessageBundle messages,
java.lang.String key,
java.lang.Object... args)
Gets the message for the current locale and the given key and arguments.
|
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.v7.ui.ComboBox |
getOUComboBox(CmsObject cms,
java.lang.String baseOu,
org.apache.commons.logging.Log log)
Creates the ComboBox for OU selection.
|
static com.vaadin.v7.ui.ComboBox |
getOUComboBox(CmsObject cms,
java.lang.String baseOu,
org.apache.commons.logging.Log log,
boolean includeWebOU)
Creates the ComboBox for OU selection.
|
static java.lang.String |
getPathItemId(com.vaadin.v7.data.Container cnt,
java.lang.String path)
Gives item id from path.
|
static com.vaadin.v7.data.util.IndexedContainer |
getPrincipalContainer(CmsObject cms,
java.util.List<? extends I_CmsPrincipal> list,
java.lang.String captionID,
java.lang.String descID,
java.lang.String iconID,
java.lang.String ouID,
java.lang.String icon,
java.util.List<com.vaadin.server.FontIcon> iconList)
Get container for principal.
|
static com.vaadin.v7.data.util.IndexedContainer |
getProjectsContainer(CmsObject cms,
java.lang.String captionPropertyName)
Returns the selectable projects container.
|
static java.util.LinkedHashMap<CmsUUID,java.lang.String> |
getProjectsMap(CmsObject cms)
Gets the available projects for the current user as a map, wth project ids as keys and project names as values.
|
static javax.servlet.http.HttpServletRequest |
getRequest()
Gets the current Vaadin request, cast to a HttpServletRequest.
|
static java.util.List<I_CmsResourceType> |
getResourceTypes()
Gets list of resource types.
|
static com.vaadin.v7.data.util.IndexedContainer |
getResourceTypesContainer()
Returns the available resource types container.
|
static com.vaadin.v7.data.util.IndexedContainer |
getRoleContainerForUser(CmsObject cms,
CmsUser user,
java.lang.String captionPropertyName)
Returns the roles available for a given user.
|
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 java.lang.String |
getWorkplaceLink(java.lang.String appId)
Returns the workplace link for the given app.
|
static java.lang.String |
getWorkplaceLink(java.lang.String appId,
java.lang.String appState)
Returns the workplace link to the given app with the given state.
|
static java.lang.String |
getWorkplaceLink(java.lang.String appId,
java.lang.String appState,
java.util.Map<java.lang.String,java.lang.String[]> requestParameters)
Returns the workplace link to the given app with the given state including the given request parameters.
|
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 boolean |
hasPathAsItemId(com.vaadin.v7.data.Container cnt,
java.lang.String path)
Checks if path is itemid in container.
|
static boolean |
isButtonPressed(com.vaadin.ui.Button button)
Checks if a button is pressed.
|
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 |
messageClose()
Message accessior function.
|
static java.lang.String |
messageOk()
Message accessor function.
|
static void |
prepareComboBox(com.vaadin.v7.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 void |
replaceComponent(com.vaadin.ui.Component component,
com.vaadin.ui.Component replacement)
Replaces component with new component.
|
static void |
setFilterBoxStyle(com.vaadin.ui.TextField searchBox)
Configures a text field to look like a filter box for a table.
|
static <T> void |
setReadonlyValue(com.vaadin.v7.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 |
toggleButton(com.vaadin.ui.Button button)
Sets style of a toggle button depending on its current state.
|
static boolean |
updateComponentError(com.vaadin.ui.AbstractComponent component,
com.vaadin.server.ErrorMessage error)
Updates the component error of a component, but only if it differs from the currently set
error.
|
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.
|
static void |
waggleMeOnce(com.vaadin.ui.Component component)
Waggle the component.
|
public static final com.vaadin.v7.data.Container.Filter FILTER_NO_FOLDERS
public static final com.vaadin.v7.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.v7.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 void centerWindow(com.vaadin.ui.Component component)
component
- Component as child of windowpublic static void closeWindow(com.vaadin.ui.Component component)
component
- a componentpublic static com.vaadin.ui.Button.ClickListener createClickListener(java.lang.Runnable action)
action
- the Runnable to execute on a clickpublic static <T> void defaultHandleContextMenuForMultiselect(com.vaadin.v7.ui.Table table, CmsContextMenu menu, com.vaadin.v7.event.ItemClickEvent event, java.util.List<I_CmsSimpleContextMenuEntry<java.util.Collection<T>>> entries)
table
- the tablemenu
- the table's context menuevent
- the click evententries
- the context menu entriespublic 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 com.vaadin.v7.data.util.IndexedContainer getAvailableGroupsContainerWithout(CmsObject cms, java.lang.String ouFqn, java.lang.String propCaption, java.lang.String propIcon, java.lang.String propOu, java.util.List<CmsGroup> blackList, java.util.function.Function<CmsGroup,CmsCssIcon> iconProvider)
cms
- CmsObjectouFqn
- ou namepropCaption
- propertypropIcon
- property for iconpropOu
- organizational unitblackList
- blacklisticonProvider
- the icon providerpublic static java.util.List<CmsProject> getAvailableProjects(CmsObject cms)
cms
- the CMS contextpublic static com.vaadin.v7.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.util.LinkedHashMap<java.lang.String,java.lang.String> getAvailableSitesMap(CmsObject cms)
cms
- the current CMS contextpublic 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 com.vaadin.v7.data.util.IndexedContainer getGroupsOfUser(CmsObject cms, CmsUser user, java.lang.String caption, java.lang.String iconProp, java.lang.String ou, java.lang.String propStatus, com.google.common.base.Function<CmsGroup,CmsCssIcon> iconProvider)
cms
- cmsobjectuser
- to find groups forcaption
- caption propertyiconProp
- propertyou
- oupropStatus
- status propertyiconProvider
- the icon providerpublic static com.vaadin.v7.ui.VerticalLayout getInfoLayout(java.lang.String messageString)
messageString
- Message to be displayedpublic static com.vaadin.v7.data.util.IndexedContainer getLanguageContainer(java.lang.String captionPropertyName)
captionPropertyName
- namepublic static java.lang.String getMessageText(I_CmsMessageBundle messages, java.lang.String key, java.lang.Object... args)
messages
- the messages instancekey
- the message keyargs
- the message argumentspublic static java.lang.String getMessageText(java.lang.String key, java.lang.Object... args)
key
- the message keyargs
- the message argumentspublic static com.vaadin.v7.ui.ComboBox getOUComboBox(CmsObject cms, java.lang.String baseOu, org.apache.commons.logging.Log log)
cms
- CmsObjectbaseOu
- OUlog
- Logger objectpublic static com.vaadin.v7.ui.ComboBox getOUComboBox(CmsObject cms, java.lang.String baseOu, org.apache.commons.logging.Log log, boolean includeWebOU)
cms
- CmsObjectbaseOu
- OUlog
- Logger objectincludeWebOU
- include webou?public static java.lang.String getPathItemId(com.vaadin.v7.data.Container cnt, java.lang.String path)
cnt
- to be usedpath
- to obtain item id frompublic static com.vaadin.v7.data.util.IndexedContainer getPrincipalContainer(CmsObject cms, java.util.List<? extends I_CmsPrincipal> list, java.lang.String captionID, java.lang.String descID, java.lang.String iconID, java.lang.String ouID, java.lang.String icon, java.util.List<com.vaadin.server.FontIcon> iconList)
cms
- cmsobjectlist
- of principalscaptionID
- caption iddescID
- description idiconID
- icon idouID
- ou idicon
- iconiconList
- iconlistpublic static com.vaadin.v7.data.util.IndexedContainer getProjectsContainer(CmsObject cms, java.lang.String captionPropertyName)
cms
- the CMS contextcaptionPropertyName
- the name of the property used to store captionspublic static java.util.LinkedHashMap<CmsUUID,java.lang.String> getProjectsMap(CmsObject cms)
cms
- the current CMS contextpublic static javax.servlet.http.HttpServletRequest getRequest()
public static java.util.List<I_CmsResourceType> getResourceTypes()
public static com.vaadin.v7.data.util.IndexedContainer getResourceTypesContainer()
public static com.vaadin.v7.data.util.IndexedContainer getRoleContainerForUser(CmsObject cms, CmsUser user, java.lang.String captionPropertyName)
cms
- CmsObjectuser
- to get available roles forcaptionPropertyName
- name of caption propertypublic static com.vaadin.ui.Window getWindow(com.vaadin.ui.Component component)
component
- the componentpublic static java.lang.String getWorkplaceLink()
public static java.lang.String getWorkplaceLink(java.lang.String appId)
appId
- the app idpublic static java.lang.String getWorkplaceLink(java.lang.String appId, java.lang.String appState)
appId
- the app idappState
- the app statepublic static java.lang.String getWorkplaceLink(java.lang.String appId, java.lang.String appState, java.util.Map<java.lang.String,java.lang.String[]> requestParameters)
appId
- the app idappState
- the app staterequestParameters
- the request parameterspublic static com.vaadin.server.ExternalResource getWorkplaceResource(java.lang.String subPath)
subPath
- path relative to workplace resource folderpublic static CmsMessages getWpMessagesForCurrentLocale()
public static boolean hasPathAsItemId(com.vaadin.v7.data.Container cnt, java.lang.String path)
cnt
- to be checkedpath
- as itemidpublic static boolean isButtonPressed(com.vaadin.ui.Button button)
button
- the buttonpublic static java.lang.String localizeString(java.lang.String baseString)
baseString
- the string to localizepublic static java.lang.String messageCancel()
public static java.lang.String messageClose()
public static java.lang.String messageOk()
public static void prepareComboBox(com.vaadin.v7.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 void replaceComponent(com.vaadin.ui.Component component, com.vaadin.ui.Component replacement)
component
- to be replacedreplacement
- new componentpublic static void setFilterBoxStyle(com.vaadin.ui.TextField searchBox)
searchBox
- the text field to configurepublic static <T> void setReadonlyValue(com.vaadin.v7.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 toggleButton(com.vaadin.ui.Button button)
button
- the button to updatepublic static boolean updateComponentError(com.vaadin.ui.AbstractComponent component, com.vaadin.server.ErrorMessage error)
component
- the componenterror
- the errorpublic 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 predicatepublic static void waggleMeOnce(com.vaadin.ui.Component component)
component
- to be waggledprotected 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)