View Javadoc
1   package info.magnolia.ui.field;
2   
3   import java.util.Arrays;
4   import java.util.List;
5   
6   import com.vaadin.annotations.JavaScript;
7   import com.vaadin.server.AbstractClientConnector;
8   import com.vaadin.server.AbstractJavaScriptExtension;
9   import com.vaadin.ui.Component;
10  
11  /**
12   * Helps applying additional styles to the form layout rows that contain certain complex fields,
13   * see {@link FormRowOutliner#supportedTypes}. The respective client-side implementation
14   * seeks for the table row element wrapping the form component and applies {@code .form-row-outlined} style to
15   * it.
16   *
17   * In addition, the row preceding to the outline one gets the {@code .before-form-row-outlined}, which
18   * is needed to overcome the margin/padding styling limitations of the table elements.
19   *
20   * Finally, the outlined component itself gets {@code .outlined} style name, so that additional rules can be
21   * easily applied to it.
22   */
23  @JavaScript("formRowOutliner.js")
24  public class FormRowOutliner extends AbstractJavaScriptExtension {
25  
26      private static final List<Class> supportedTypes = Arrays.asList(
27              CompositeFieldDefinition.class,
28              MultiFieldDefinition.class);
29  
30      public static void considerOutlining(Component component, EditorPropertyDefinition definition) {
31          if (supportedTypes.stream().anyMatch(type -> type.isInstance(definition))) {
32              new FormRowOutliner().extend((AbstractClientConnector) component);
33              component.addStyleName("outlined");
34          }
35      }
36  }