aboutsummaryrefslogtreecommitdiffstats
path: root/documentation/components/components-customcomponent.asciidoc
blob: dd5a86b82316962296931b9a7c3f475dafc33833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
title: Composition with CustomComponent
order: 31
layout: page
---

[[components.customcomponent]]
= Composition with CustomComponent

The ease of making new user interface components is one of the core features of
Vaadin. Typically, you simply combine existing built-in components to produce
composite components. In many applications, such composite components make up
the majority of the user interface.

As described earlier in
<<dummy/../../../framework/application/application-architecture#application.architecture.composition,"Compositing
Components">>, you have two basic ways to create a composite - either by
extending a layout component or the [classname]#CustomComponent#, which
typically wraps around a layout component. The benefit of wrapping a layout
composite in [classname]#CustomComponent# is mainly encapsulation - hiding the
implementation details of the composition. Otherwise, a user of the composite
could rely on implementation details, which would create an unwanted dependency.

To create a composite, you need to inherit the [classname]#CustomComponent# and
set the __composition root__ component in the constructor. The composition root
is typically a layout component that contains other components.

For example:

[source, java]
----
class MyComposite extends CustomComponent {
    public MyComposite(String message) {
        // A layout structure used for composition
        Panel panel = new Panel("My Custom Component");
        VerticalLayout panelContent = new VerticalLayout();
        panel.setContent(panelContent);

        // Compose from multiple components
        Label label = new Label(message);
        panelContent.addComponent(label);
        panelContent.addComponent(new Button("Ok"));

        // Set the size as undefined at all levels
        panelContent.setSizeUndefined();
        panel.setSizeUndefined();
        setSizeUndefined();

        // The composition root MUST be set
        setCompositionRoot(panel);
    }
}
----

Take note of the sizing when trying to make a customcomponent that shrinks to
fit the contained components. You have to set the size as undefined at all
levels; the sizing of the composite component and the composition root are
separate.

You can use the component as follows:

[source, java]
----
MyComposite mycomposite = new MyComposite("Hello");
----

The rendered component is shown in <<figure.components.customcomponent>>.

[[figure.components.customcomponent]]
.A custom composite component
image::img/customcomponent-example1.png[width=25%, scaledwidth=40%]

You can also inherit any other components, such as layouts, to attain similar
composition.
((("Google Web Toolkit")))
Even further, you can create entirely new low-level components, by integrating
pure client-side components or by extending the client-side functionality of
built-in components. Development of new components is covered in
<<dummy/../../../framework/gwt/gwt-overview.asciidoc#gwt.overview,"Integrating
with the Server-Side">>.
background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <!-- defines the layout master -->
  <fo:layout-master-set>
    <fo:simple-page-master master-name="first"
                           page-height="29.7cm" page-width="21cm"
                           margin-top="1cm"
                           margin-bottom="2cm"
                           margin-left="2.5cm"
                           margin-right="2.5cm">
    <fo:region-body margin-top="3cm"/>
     <fo:region-before extent="3cm"/>
     <fo:region-after extent="1.5cm"/>
    </fo:simple-page-master>
  </fo:layout-master-set>

  <!-- starts actual layout -->
  <fo:page-sequence master-reference="first">

  <!-- Inserts a header with the page number -->
  <fo:static-content flow-name="xsl-region-before">
    <fo:block text-align="end" font-size="10pt" font-family="serif" line-height="14pt">
          XSL-FO Example: simple list - p. <fo:page-number/>
    </fo:block>
  </fo:static-content>

  <fo:flow flow-name="xsl-region-body">

      <!-- title -->
      <fo:block font-size="14pt"
                font-family="sans-serif"
                line-height="18pt"
                space-before.optimum="3pt"
                space-after.optimum="3pt"
                font-weight="bold"
                start-indent="15pt">
          Validity Constraint: Standalone Document Declaration
      </fo:block>

      <!-- normal text -->
      <fo:block font-size="12pt"
                font-family="sans-serif"
                line-height="15pt"
                space-after.optimum="3pt" >
          The standalone document declaration must have the value "no" if
          any external markup declarations contain declarations of:
      </fo:block>

      <!-- list -->
      <fo:list-block>

        <!-- list item -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>
              attributes with default values, if elements to which these attributes apply appear in the document without specifications of values for these attributes, or
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>

        <!-- list item -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>
              entities (other than amp, lt, gt, apos, quot), if references to those entities appear in the document, or
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>

        <!-- list entry -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>
              attributes with values subject to normalization, where the attribute appears in the document with a value which will
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>

        <!-- list entry -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>
              change as a result of normalization, or
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>

        <!-- list entry -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>

              element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white spaceadsfadsfsssssssssssssss thin any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white spaceadsfadsfssssssssthin any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white spaceadsfadsfssssssssthin any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white spaceadsfadsfssssssssthin any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white spaceadsfadsfssssssss
              element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. elementtance of those types. sfg sfd gdg d d
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>




 <fo:list-item>
  <fo:list-item-label end-indent="label-end()"> <fo:block/></fo:list-item-label>
   <fo:list-item-body start-indent="body-start()">
   <fo:list-block>

         <!-- list item -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>
              attributes with default values, if elements to which these attributes apply appear in the document without specifications of values for these attributes, or
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
  <!-- list item -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>
              attributes with default values, if elements to which these attributes apply appear in the document without specifications of values for these attributes, or
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
  <!-- list item -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>
              attributes with default values, if elements to which these attributes apply appear in the document without specifications of values for these attributes, or
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
  <!-- list item -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>
              attributes with default values, if elements to which these attributes apply appear in the document without specifications of values for these attributes, or
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </fo:list-block>
          </fo:list-item-body>
    </fo:list-item>


        <!-- list entry -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>
              element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. elementtance of those types.
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
        <!-- list entry -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>
              element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. elementtance of those types.
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
        <!-- list entry -->
        <fo:list-item>
          <!-- insert a bullet -->
          <fo:list-item-label end-indent="label-end()">
            <fo:block>&#x2022;</fo:block>
          </fo:list-item-label>
          <!-- list text -->
          <fo:list-item-body start-indent="body-start()">
            <fo:block>
              element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. element types with element content, if white space occurs directly within any instance of those types. elementtance of those types.
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>








      </fo:list-block>


    </fo:flow>
  </fo:page-sequence>
</fo:root>