Class CmsVaadinUtils

java.lang.Object
org.opencms.ui.CmsVaadinUtils

public final class CmsVaadinUtils extends Object
Vaadin utility functions.

  • Field Details

  • 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 captions
      map - the map
      Returns:
      the new container
    • centerWindow

      public static void centerWindow(com.vaadin.ui.Component component)
      Centers the parent window of given component.

      Parameters:
      component - Component as child of window
    • closeWindow

      public static void closeWindow(com.vaadin.ui.Component component)
      Closes the window containing the given component.
      Parameters:
      component - a component
    • createClickListener

      public static com.vaadin.ui.Button.ClickListener createClickListener(Runnable action)
      Creates a click listener which calls a Runnable when activated.

      Parameters:
      action - the Runnable to execute on a click
      Returns:
      the click listener
    • defaultHandleContextMenuForMultiselect

      public 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.
      Parameters:
      table - the table
      menu - the table's context menu
      event - the click event
      entries - the context menu entries
    • 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 data
      transformation - 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 - CmsObject
      ouFqn - ou name
      propCaption - property
      propIcon - property for icon
      propOu - organizational unit
      blackList - blacklist
      iconProvider - 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 context
      captionPropertyName - 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 context
      elementId - the id of the DOM element in which to initialize the UI
      servicePath - the UI servlet path
      Returns:
      the Javascript code to initialize Vaadin
      Throws:
      Exception - if something goes wrong
    • getDefaultDesignPath

      public static String getDefaultDesignPath(com.vaadin.ui.Component component)
      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 - cmsobject
      user - to find groups for
      caption - caption property
      iconProp - property
      ou - ou
      propStatus - status property
      iconProvider - the icon provider
      Returns:
      Indexed Container
    • getInfoLayout

      public static com.vaadin.v7.ui.VerticalLayout getInfoLayout(String messageString)
      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

      public static String getMessageText(I_CmsMessageBundle messages, String key, Object... args)
      Gets the message for the current locale and the given key and arguments.

      Parameters:
      messages - the messages instance
      key - the message key
      args - the message arguments
      Returns:
      the message text for the current locale
    • getMessageText

      public static String getMessageText(String key, Object... args)
      Gets the workplace message for the current locale and the given key and arguments.

      Parameters:
      key - the message key
      args - 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 - CmsObject
      baseOu - OU
      log - 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 - CmsObject
      baseOu - OU
      log - Logger object
      includeWebOU - include webou?
      Returns:
      ComboBox
    • getPathItemId

      public static String getPathItemId(com.vaadin.v7.data.Container cnt, String path)
      Gives item id from path.

      Parameters:
      cnt - to be used
      path - 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 - cmsobject
      list - of principals
      captionID - caption id
      descID - description id
      iconID - icon id
      ouID - ou id
      icon - icon
      iconList - 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 context
      captionPropertyName - 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

      public static javax.servlet.http.HttpServletRequest getRequest()
      Gets the current Vaadin request, cast to a HttpServletRequest.

      Returns:
      the current request
    • getResourceTypes

      Gets list of resource types.

      Returns:
      List
    • getResourceTypesContainer

      public static com.vaadin.v7.data.util.IndexedContainer 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 - CmsObject
      user - to get available roles for
      captionPropertyName - name of caption property
      Returns:
      indexed container
    • getWindow

      public static com.vaadin.ui.Window getWindow(com.vaadin.ui.Component component)
      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

      public static String getWorkplaceLink()
      Gets the link to the (new) workplace.

      Returns:
      the link to the workplace
    • getWorkplaceLink

      public static String getWorkplaceLink(String appId)
      Returns the workplace link for the given app.

      Parameters:
      appId - the app id
      Returns:
      the workplace link
    • getWorkplaceLink

      public static String getWorkplaceLink(String appId, String appState)
      Returns the workplace link to the given app with the given state.

      Parameters:
      appId - the app id
      appState - 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 id
      appState - the app state
      requestParameters - the request parameters
      Returns:
      the workplace link
    • getWorkplaceResource

      public static com.vaadin.server.ExternalResource getWorkplaceResource(String subPath)
      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

      public static boolean hasPathAsItemId(com.vaadin.v7.data.Container cnt, String path)
      Checks if path is itemid in container.

      Parameters:
      cnt - to be checked
      path - as itemid
      Returns:
      true id path is itemid in container
    • isButtonPressed

      public static boolean isButtonPressed(com.vaadin.ui.Button button)
      Checks if a button is pressed.

      Parameters:
      button - the button
      Returns:
      true if the button is pressed
    • localizeString

      public static String localizeString(String baseString)
      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

      public static String messageCancel()
      Message accessior function.

      Returns:
      the message for Cancel buttons
    • messageClose

      public static String messageClose()
      Message accessior function.

      Returns:
      the message for Cancel buttons
    • messageOk

      public static String messageOk()
      Message accessor function.

      Returns:
      the message for OK buttons
    • prepareComboBox

      public 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.

      Parameters:
      box - the combo box to prepare
      options - 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 design
      messages - the message bundle to use for localization
      macros - 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 up
      relativeName - 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 replaced
      replacement - new component
    • setFilterBoxStyle

      public static void setFilterBoxStyle(com.vaadin.ui.TextField searchBox)
      Configures a text field to look like a filter box for a table.
      Parameters:
      searchBox - the text field to configure
    • setReadonlyValue

      public 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.

      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 field
      value - the value to set
    • showAlert

      public static void showAlert(String title, String message, 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.

      Parameters:
      title - the title
      message - the message
      callback - the callback to execute after clicking OK
    • sortResourceTypes

      public static void sortResourceTypes(List<I_CmsResourceType> resourceTypes)
      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

      public static void toggleButton(com.vaadin.ui.Button button)
      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 component
      error - 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 component
      handler - the predicate
    • waggleMeOnce

      public static void waggleMeOnce(com.vaadin.ui.Component component)
      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 read
      designStream - stream to read the design from
      messages - 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)