Package org.opencms.ui
Class CmsVaadinUtils
java.lang.Object
org.opencms.ui.CmsVaadinUtils
Vaadin utility functions.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Helper class for building option groups.static enum
Container property ids. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
The Vaadin bootstrap script, with some macros to be dynamically replaced later.static final com.vaadin.v7.data.Container.Filter
Container filter for the resource type container to show not folder types only.static final com.vaadin.v7.data.Container.Filter
Container filter for the resource type container to show XML content types only.static final String
The combo box label item property id.static final String
The combo box value item property id. -
Method Summary
Modifier and TypeMethodDescriptionstatic com.vaadin.v7.data.util.IndexedContainer
buildContainerFromMap
(String captionProperty, Map<String, 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
(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, List<I_CmsSimpleContextMenuEntry<Collection<T>>> entries) Simple context menu handler for multi-select tables.static InputStream
filterUtf8ResourceStream
(InputStream stream, com.google.common.base.Function<String, 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, String ouFqn, String propCaption, String propIcon, String propOu, List<CmsGroup> blackList, Function<CmsGroup, CmsCssIcon> iconProvider) Get all groups with blacklist.static List<CmsProject>
Returns the available projects.static com.vaadin.v7.data.util.IndexedContainer
getAvailableSitesContainer
(CmsObject cms, String captionPropertyName) Builds an IndexedContainer containing the sites selectable by the current user.static LinkedHashMap<String,
String> Gets available sites as a LinkedHashMap, with site roots as keys and site labels as values.static String
getBootstrapScript
(CmsObject cms, String elementId, String servicePath) Returns the Javascript code to use for initializing a Vaadin UI.static 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, String caption, String iconProp, String ou, 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
(String messageString) Creates a layout with info panel.static com.vaadin.v7.data.util.IndexedContainer
getLanguageContainer
(String captionPropertyName) Get container with languages.static String
getMessageText
(String key, Object... args) Gets the workplace message for the current locale and the given key and arguments.static String
getMessageText
(I_CmsMessageBundle messages, String key, Object... args) Gets the message for the current locale and the given key and arguments.static com.vaadin.v7.ui.ComboBox
getOUComboBox
(CmsObject cms, String baseOu, org.apache.commons.logging.Log log) Creates the ComboBox for OU selection.static com.vaadin.v7.ui.ComboBox
getOUComboBox
(CmsObject cms, String baseOu, org.apache.commons.logging.Log log, boolean includeWebOU) Creates the ComboBox for OU selection.static String
getPathItemId
(com.vaadin.v7.data.Container cnt, String path) Gives item id from path.static com.vaadin.v7.data.util.IndexedContainer
getPrincipalContainer
(CmsObject cms, List<? extends I_CmsPrincipal> list, String captionID, String descID, String iconID, String ouID, String icon, List<com.vaadin.server.FontIcon> iconList) Get container for principal.static com.vaadin.v7.data.util.IndexedContainer
getProjectsContainer
(CmsObject cms, String captionPropertyName) Returns the selectable projects container.static LinkedHashMap<CmsUUID,
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
Gets the current Vaadin request, cast to a HttpServletRequest.static List<I_CmsResourceType>
Gets list of resource types.static com.vaadin.v7.data.util.IndexedContainer
Returns the available resource types container.static com.vaadin.v7.data.util.IndexedContainer
getRoleContainerForUser
(CmsObject cms, CmsUser user, 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 com.vaadin.v7.data.util.IndexedContainer
getWorkplaceLanguageContainer
(String captionPropertyName) Get container with workpalce languages.static String
Gets the link to the (new) workplace.static String
getWorkplaceLink
(String appId) Returns the workplace link for the given app.static String
getWorkplaceLink
(String appId, String appState) Returns the workplace link to the given app with the given state.static String
Returns the workplace link to the given app with the given state including the given request parameters.static com.vaadin.server.ExternalResource
getWorkplaceResource
(String subPath) Gets external resource from workplace resource folder.static CmsMessages
Gets the workplace messages for the current locale.static boolean
hasPathAsItemId
(com.vaadin.v7.data.Container cnt, String path) Checks if path is itemid in container.static boolean
isButtonPressed
(com.vaadin.ui.Button button) Checks if a button is pressed.static String
localizeString
(String baseString) Uses the currently set locale to resolve localization macros in the input string using workplace message bundles.static String
Message accessior function.static String
Message accessior function.static String
Message accessor function.static void
prepareComboBox
(com.vaadin.v7.ui.ComboBox box, Map<?, String> options) Generates the options items for the combo box using the map entry keys as values and the values as labels.protected static void
readAndLocalizeDesign
(com.vaadin.ui.Component component, InputStream designStream, CmsMessages messages, Map<String, String> macros) Reads the given design and resolves the given macros and localizations.static void
readAndLocalizeDesign
(com.vaadin.ui.Component component, CmsMessages messages, Map<String, String> macros) Reads the declarative design for a component and localizes it using a messages object.static InputStream
readCustomLayout
(Class<? extends com.vaadin.ui.Component> layoutClass, 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
Shows an alert box to the user with the given information, which will perform the given action after the user clicks on OK.static void
sortResourceTypes
(List<I_CmsResourceType> resourceTypes) Sorts a list of resource types by their localized explorer type name.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.
-
Field Details
-
FILTER_NO_FOLDERS
Container filter for the resource type container to show not folder types only. -
FILTER_XML_CONTENTS
Container filter for the resource type container to show XML content types only. -
PROPERTY_LABEL
The combo box label item property id.- See Also:
-
PROPERTY_VALUE
The combo box value item property id.- See Also:
-
BOOTSTRAP_SCRIPT
The Vaadin bootstrap script, with some macros to be dynamically replaced later.- See Also:
-
-
Method Details
-
buildContainerFromMap
public static com.vaadin.v7.data.util.IndexedContainer buildContainerFromMap(String captionProperty, Map<String, 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.- Parameters:
captionProperty
- the property name to use for captionsmap
- the map- Returns:
- the new container
-
centerWindow
Centers the parent window of given component.- Parameters:
component
- Component as child of window
-
closeWindow
Closes the window containing the given component.- Parameters:
component
- a component
-
createClickListener
Creates a click listener which calls a Runnable when activated.- Parameters:
action
- the Runnable to execute on a click- Returns:
- the click listener
-
filterUtf8ResourceStream
public static InputStream filterUtf8ResourceStream(InputStream stream, com.google.common.base.Function<String, 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.- Parameters:
stream
- the stream producing the input datatransformation
- the function to apply to the input- Returns:
- the stream producing the transformed input data
-
getAvailableGroupsContainerWithout
public static com.vaadin.v7.data.util.IndexedContainer getAvailableGroupsContainerWithout(CmsObject cms, String ouFqn, String propCaption, String propIcon, String propOu, List<CmsGroup> blackList, Function<CmsGroup, CmsCssIcon> iconProvider) Get all groups with blacklist.- Parameters:
cms
- CmsObjectouFqn
- ou namepropCaption
- propertypropIcon
- property for iconpropOu
- organizational unitblackList
- blacklisticonProvider
- the icon provider- Returns:
- indexed container
-
getAvailableProjects
Returns the available projects.- Parameters:
cms
- the CMS context- Returns:
- the available projects
-
getAvailableSitesContainer
public static com.vaadin.v7.data.util.IndexedContainer getAvailableSitesContainer(CmsObject cms, String captionPropertyName) Builds an IndexedContainer containing the sites selectable by the current user.- Parameters:
cms
- the CMS contextcaptionPropertyName
- the name of the property used to store captions- Returns:
- the container with the available sites
-
getAvailableSitesMap
Gets available sites as a LinkedHashMap, with site roots as keys and site labels as values.- Parameters:
cms
- the current CMS context- Returns:
- the map of available sites
-
getBootstrapScript
public static String getBootstrapScript(CmsObject cms, String elementId, String servicePath) throws Exception Returns the Javascript code to use for initializing a Vaadin UI.- Parameters:
cms
- the CMS contextelementId
- the id of the DOM element in which to initialize the UIservicePath
- the UI servlet path- Returns:
- the Javascript code to initialize Vaadin
- Throws:
Exception
- if something goes wrong
-
getDefaultDesignPath
Returns the path to the design template file of the given component.- Parameters:
component
- the component- Returns:
- the path
-
getGroupsOfUser
public static com.vaadin.v7.data.util.IndexedContainer getGroupsOfUser(CmsObject cms, CmsUser user, String caption, String iconProp, String ou, String propStatus, com.google.common.base.Function<CmsGroup, CmsCssIcon> iconProvider) Gets container with alls groups of a certain user.- Parameters:
cms
- cmsobjectuser
- to find groups forcaption
- caption propertyiconProp
- propertyou
- oupropStatus
- status propertyiconProvider
- the icon provider- Returns:
- Indexed Container
-
getInfoLayout
Creates a layout with info panel.- Parameters:
messageString
- Message to be displayed- Returns:
- layout
-
getLanguageContainer
public static com.vaadin.v7.data.util.IndexedContainer getLanguageContainer(String captionPropertyName) Get container with languages.- Parameters:
captionPropertyName
- name- Returns:
- indexed container
-
getMessageText
Gets the message for the current locale and the given key and arguments.- Parameters:
messages
- the messages instancekey
- the message keyargs
- the message arguments- Returns:
- the message text for the current locale
-
getMessageText
Gets the workplace message for the current locale and the given key and arguments.- Parameters:
key
- the message keyargs
- the message arguments- Returns:
- the message text for the current locale
-
getOUComboBox
public static com.vaadin.v7.ui.ComboBox getOUComboBox(CmsObject cms, String baseOu, org.apache.commons.logging.Log log) Creates the ComboBox for OU selection.- Parameters:
cms
- CmsObjectbaseOu
- OUlog
- Logger object- Returns:
- ComboBox
-
getOUComboBox
public static com.vaadin.v7.ui.ComboBox getOUComboBox(CmsObject cms, String baseOu, org.apache.commons.logging.Log log, boolean includeWebOU) Creates the ComboBox for OU selection.- Parameters:
cms
- CmsObjectbaseOu
- OUlog
- Logger objectincludeWebOU
- include webou?- Returns:
- ComboBox
-
getPathItemId
Gives item id from path.- Parameters:
cnt
- to be usedpath
- to obtain item id from- Returns:
- item id
-
getPrincipalContainer
public static com.vaadin.v7.data.util.IndexedContainer getPrincipalContainer(CmsObject cms, List<? extends I_CmsPrincipal> list, String captionID, String descID, String iconID, String ouID, String icon, List<com.vaadin.server.FontIcon> iconList) Get container for principal.- Parameters:
cms
- cmsobjectlist
- of principalscaptionID
- caption iddescID
- description idiconID
- icon idouID
- ou idicon
- iconiconList
- iconlist- Returns:
- indexedcontainer
-
getProjectsContainer
public static com.vaadin.v7.data.util.IndexedContainer getProjectsContainer(CmsObject cms, String captionPropertyName) Returns the selectable projects container.- Parameters:
cms
- the CMS contextcaptionPropertyName
- the name of the property used to store captions- Returns:
- the projects container
-
getProjectsMap
Gets the available projects for the current user as a map, wth project ids as keys and project names as values.- Parameters:
cms
- the current CMS context- Returns:
- the map of projects
-
getRequest
Gets the current Vaadin request, cast to a HttpServletRequest.- Returns:
- the current request
-
getResourceTypes
Gets list of resource types.- Returns:
- List
-
getResourceTypesContainer
Returns the available resource types container.- Returns:
- the resource types container
-
getRoleContainerForUser
public static com.vaadin.v7.data.util.IndexedContainer getRoleContainerForUser(CmsObject cms, CmsUser user, String captionPropertyName) Returns the roles available for a given user.- Parameters:
cms
- CmsObjectuser
- to get available roles forcaptionPropertyName
- name of caption property- Returns:
- indexed container
-
getWindow
Gets the window which contains a given component.- Parameters:
component
- the component- Returns:
- the window containing the component, or null if no component is found
-
getWorkplaceLanguageContainer
public static com.vaadin.v7.data.util.IndexedContainer getWorkplaceLanguageContainer(String captionPropertyName) Get container with workpalce languages.- Parameters:
captionPropertyName
- name- Returns:
- indexed container
-
getWorkplaceLink
Gets the link to the (new) workplace.- Returns:
- the link to the workplace
-
getWorkplaceLink
Returns the workplace link for the given app.- Parameters:
appId
- the app id- Returns:
- the workplace link
-
getWorkplaceLink
Returns the workplace link to the given app with the given state.- Parameters:
appId
- the app idappState
- the app state- Returns:
- the workplace link
-
getWorkplaceLink
public static String getWorkplaceLink(String appId, String appState, Map<String, String[]> requestParameters) Returns the workplace link to the given app with the given state including the given request parameters.- Parameters:
appId
- the app idappState
- the app staterequestParameters
- the request parameters- Returns:
- the workplace link
-
getWorkplaceResource
Gets external resource from workplace resource folder.- Parameters:
subPath
- path relative to workplace resource folder- Returns:
- the external resource
-
getWpMessagesForCurrentLocale
Gets the workplace messages for the current locale.- Returns:
- the workplace messages
-
hasPathAsItemId
Checks if path is itemid in container.- Parameters:
cnt
- to be checkedpath
- as itemid- Returns:
- true id path is itemid in container
-
isButtonPressed
Checks if a button is pressed.- Parameters:
button
- the button- Returns:
- true if the button is pressed
-
localizeString
Uses the currently set locale to resolve localization macros in the input string using workplace message bundles.- Parameters:
baseString
- the string to localize- Returns:
- the localized string
-
messageCancel
Message accessior function.- Returns:
- the message for Cancel buttons
-
messageClose
Message accessior function.- Returns:
- the message for Cancel buttons
-
messageOk
Message accessor function.- Returns:
- the message for OK buttons
-
prepareComboBox
Generates the options items for the combo box using the map entry keys as values and the values as labels.- Parameters:
box
- the combo box to prepareoptions
- the box options
-
readAndLocalizeDesign
public static void readAndLocalizeDesign(com.vaadin.ui.Component component, CmsMessages messages, Map<String, String> macros) Reads the declarative design for a component and localizes it using a messages object.The design will need to be located in the same directory as the component's class and have '.html' as a file extension.
- Parameters:
component
- the component for which to read the designmessages
- the message bundle to use for localizationmacros
- the macros to use on the HTML template
-
readCustomLayout
public static InputStream readCustomLayout(Class<? extends com.vaadin.ui.Component> layoutClass, 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.- Parameters:
layoutClass
- the class relative to which the layout resource will be looked uprelativeName
- the file name of the layout file- Returns:
- an input stream which produces the transformed layout resource html
-
replaceComponent
public static void replaceComponent(com.vaadin.ui.Component component, com.vaadin.ui.Component replacement) Replaces component with new component.- Parameters:
component
- to be replacedreplacement
- new component
-
setFilterBoxStyle
Configures a text field to look like a filter box for a table.- Parameters:
searchBox
- the text field to configure
-
setReadonlyValue
Sets the value of a text field which may be set to read-only mode.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.
- Parameters:
field
- the fieldvalue
- the value to set
-
showAlert
Shows an alert box to the user with the given information, which will perform the given action after the user clicks on OK.- Parameters:
title
- the titlemessage
- the messagecallback
- the callback to execute after clicking OK
-
sortResourceTypes
Sorts a list of resource types by their localized explorer type name.- Parameters:
resourceTypes
- the resource types
-
startOptionGroup
Creates a new option group builder.- Returns:
- a new option group builder
-
toggleButton
Sets style of a toggle button depending on its current state.- Parameters:
button
- the button to update
-
updateComponentError
public 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.- Parameters:
component
- the componenterror
- the error- Returns:
- true if the error was changed
-
visitDescendants
public 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.If the predicate returns false for a component, no further descendants will be processed.
- Parameters:
component
- the componenthandler
- the predicate
-
waggleMeOnce
Waggle the component.- Parameters:
component
- to be waggled
-
readAndLocalizeDesign
protected static void readAndLocalizeDesign(com.vaadin.ui.Component component, InputStream designStream, CmsMessages messages, Map<String, String> macros) Reads the given design and resolves the given macros and localizations.- Parameters:
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)
-