jueves, 6 de febrero de 2020

28. Vaadin 14. How to display programmatically components to the OpenXava (C) way

1. Introduction

OpenXava is a wonderful framework based on the Model. I love it. I am a fan of its creator Mr. Javier Paniza. He has designed a nomenclature for defining the "view" part of an MVC pattern. As he states, programmers can devote to business logic instead of designing complicated HTML, CSS or javascript code on the client-side.
Now responsiveness is a must.

Vaadin has a Horizontal and a Vertical  Layout component, that seems responsive, but when you nest them it is very difficult for me to keep track of the CSS code added by Vaadin Themes.. so you cannot predict how the information is displayed

After struggling about for some days and googling some days too, I found the CSS flex property

Another problem is that you cannot know the real width and height of the components in run time, you should use some unpredictable javascript code that is not recommended.

2. Designing the layout


A simple definition of a view in OpenXava could be:
--------------------------------------------------------------------------------------------------------------------
student   [ firstName,    lastName;
            address       [streetName, number, city ],
            parents       [mother,     father]
          ];
Sports    [ firstSport;   secondSport]
--------------------------------------------------------------------------------------------------------------------

That should produce something like this:

+------------------------------------------------------------------------------+
| +--------------------------------------------------------------------------+ |
| |                                  Student                                 | |
| +--------------------------------------------------------------------------+ |
| |             +-------------+             +-------------+                  | |
| | First Name: |             |  Last Name: |             |                  | |
| |             +-------------+             +-------------+                  | | 
| | +---------------------------------------+ +----------------------------+ | | 
| | |            Address                    | |          Parents           | | |
| | +---------------------------------------+ +----------------------------+ | |
| | |        +------+    +---+       +----+ | |     +------+      +------+ | | |
| | | Street:|      | N. |   | City: |    | | | Mom:|      | Dad: |      | | | |
| | |        +------+    +---+       +----+ | |     +------+      +------+ | | |
| | +---------------------------------------+ +----------------------------+ | |
| |                                                                          | |
| +--------------------------------------------------------------------------+ |
| |                              Sports                                      | |
| +--------------------------------------------------------------------------+ |
| | |                +----------------------------------------+              | |
| | |  First Sport:  |                                        |              | |
| | |                +----------------------------------------+              | |
| | |                +----------------------------------------+              | |
| | |  Second Sport: |                                        |              | |
| | |                +----------------------------------------+              | |
| +--------------------------------------------------------------------------+ |
+------------------------------------------------------------------------------+



Now to simplify I will be using this pseudo Html structure:

Main form: (Horizontal Panel)
   |
   +--> Vertical Panel
        |
        +--> Horizontal Panel (Student)
        |    |
        |    +--> Vertical Panel
        |         |
        |         +--> Horizontal Panel (line of controls)
        |         |    |
        |         |    +--> Field (First Name)
        |         |    |
        |         |    +--> Field (Last Name)
        |         |     
        |         +--> Horizonal Panel  
        |              |
        |              +--> Vertical Panel
        |                   |
        |                   +--> Horizontal Panel (Address)
        |                   |    |
        |                   |    +--> Vertical Panel 
        |                   |        |   
        |                   |        +--> Horizontal Panel (line of controls)
        |                   |             |
        |                   |             +--> Field (Street)
        |                   |             |
        |                   |             +--> Field (Num)
        |                   |             | 
        |                   |             +--> Field (City)
        |                   |
        |                   +--> Horizontal Panel (Parents)
        |                        |
        |                        +--> Vertical Panel 
        |                             |   
        |                             +--> Horizontal Panel (line of controls)
        |                                  |
        |                                  +--> Field (Mom)
        |                                  |
        |                                  +--> Field (Dad)
        +--> Horizonal Panel (Sports) 
             |
             +--> Vertical Panel
                  |
                  +--> Horizontal Panel (line of controls)
                  |    |
                  |    +--> Field (First Sport)
                  |     
                  +--> Horizontal Panel (line of controls)

                       |                        


                       +--> Field (Second Sport)



Note that every group of fields (marked in OpenXava between brackets [..]) is formed by Horizontal Panel + Vertical panel 

Note that each line of controls is formed by a Horizontal Panel 

So the algorithm should identify the elements:

  • group of controls (between brackets [])
  • lines of controls (identified by comma and semicolons (,;)
  • controls 

2. Implementing Horizontal and Vertical Panels for containers and lines of controls in Vaadin

The simple Vaadin Div component and the CSS flex and @media  elements can perform the magic.

The @media is used for determining the form the components are arranged depending on the size of the screen (so we can predict if the user is managing a big screen, tablet or phone)

The flex element is used to wrap controls in a line (line of controls), so we do not need to worry about the length of the controls when they are contained in a line.

Here is  CSS code

/* For using with OX components.*/ 

/*----------------------------------------------------------*/
/* VERTICAL PANEL */
/*----------------------------------------------------------*/ 

/* For vetical layout */
 .flex-column {
    display: flex;
    flex-direction: column;
    flex: 1;
 }


/*----------------------------------------------------------*/
/* HORIZONTAL PANEL: BIG SCREENS */
/*----------------------------------------------------------*/ 
    /* For horizontal layout (line of controls) */
 .flex-row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
 }
 
 
 
 /*When sharing a horizontal with a number of group of controls*/
 .share-with-1 {
  width: 100%;
 }
 .share-with-2 {
  width: 50%;
 }
 .share-with-3 {
  width: 33%;
 }
 .share-with-4 {
  width: 25%;
 }
 .share-with-5 {
  width: 20%;
 }
 .share-with-6 {
  width: 16%;
 }
 .share-with-7 {
  width: 14%;
 }
 .share-with-8 {
  width: 12%;
 }
 .share-with-9 {
  width: 11%;
 }
 .share-with-10 {
  width: 10%;
 }
 
 
/*----------------------------------------------------------*/
/* HORIZONTAL PANEL: MEDIUM SCREENS */
/*----------------------------------------------------------*/ 
 @media all and (max-width: 1000px) {
    .flex-row  {
       /* When on medium sized screens, we center it by evenly distributing empty space around items */
       justify-content: space-around;
    }
    .share-with-1 {
       width: 100%;
    }
    .share-with-2 , .share-with-3 , .share-with-4 , .share-with-5 ,
    .share-with-6 , .share-with-7 , .share-with-8 , .share-with-8 ,
    .share-with-10 {
       width: 50%;
    }
 }

/*----------------------------------------------------------*/
/* HORIZONTAL PANEL: SMALL SCREENS */
/*----------------------------------------------------------*/ 
 @media all and (max-width: 600px) {
    .flex-row  {
     /* On small screens, we are no longer using row direction but column */
     flex-direction: column;
    }
   .share-with-1 , .share-with-2 , .share-with-3 , .share-with-4 ,
  .share-with-5 , .share-with-6 , .share-with-7 , .share-with-8 ,
  .share-with-9 , .share-with-10 {
   width: 100%;
  }
 }
 
 

The vertical panel properties are not affected by the screen size.

. However, horizontal panels must adapt to the width of the screen. (class flex-column)

For groups of controls in one line, in big displays, it is accepted up to 10 columns, in medium ones, 2 columns are accepted and in small devices only one column (class share-with-number_of_groups)

The lines of controls are managed with the flex component (class flex-row).  The behavior (number of columns) can vary depending on both the width of the controls (wrapping) and the width of the screen.



jueves, 14 de noviembre de 2019

27. Vaadin 14. Problem with styles. (3) TextArea

0. Introduction


This post should be used combined with the last two posts.

1. TextArea Styling

This object HAS NO REFERENCE TO the textboxes !!!

1.0 Assign the Vaaadin Theme (For instance Lumo)

1.1 Create a file that contains general values of styles assigned to variables for instance "shared-styles.css" in the "frontend/styles" folder of your project with this info. Note that this file was created in the previous post and no additional information has been added.


 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
html {
  /* Example global custom CSS property definition */
  
  /* 1. FORM FIELDS */
    /* 1.1 enabled */
    --ximo-field-color:                     black;
    --ximo-field-background-color:          white;
    --ximo-field-font-weight:               bold;
    --ximo-field-opacity:                   1.0;
  
    --ximo-field-border-radius:             10px;
    --ximo-field-border-width:              1px 2px 2px 1px;
    --ximo-field-border-style:              solid;
    --ximo-field-border-color:              salmon;
    --ximo-field-margin-right:              15px;
  
    /* 1.2 disabled */
    --ximo-field-disabled-color:            gray;
    --ximo-field-disabled-background-color: white;
    --ximo-field-disabled-font-weight:      bold;
    --ximo-field-disabled-opacity:          0.8;
  
    --ximo-field-disabled-border-radius:    10px;
    --ximo-field-disabled-border-width:     1px 2px 2px 1px;
    --ximo-field-disabled-border-style:     solid;
    --ximo-field-disabled-border-color:     thistle;
    --ximo-field-disabled-margin-right:     15px;
 
 
 /* 2. COMBOBOX */
    /* 1.1 App Selector*/
    --ximo-combo-color:                     maroon;;
    --ximo-combo-font-weight:               bold;
    --ximo-combo-background-image:          linear-gradient(to bottom right, lightpink, white);
    --ximo-combo-border-radius:             10px;
 
    --ximo-combo-border:                    2px;
    --ximo-combo-border-bottom-style:       solid;
    --ximo-combo-border-bottom-width:       medium;
    --ximo-combo-border-bottom-color:       saddlebrown;
}

1.2 The file  "my-textfield-styles.css" in the "frontend/styles" folder is not needed for TextAreas, although it is needed for TextBoxes and ComboBoxes

1.3 Create a file called for instance "current-textarea-styles.css" in the "frontend/styles" folder of your project with this info. These are the styles definitively assigned to TextAreas. Take care!


 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
/* General */
[part="input-field"] {
  
    color:                  var(--ximo-field-color);
    font-weight:            var(--ximo-field-font-weight);
    background-color:       var(--ximo-field-background-color);
    border-radius:          var(--ximo-field-border-radius);
    border-width:           var(--ximo-field-border-width);
    border-style:           var(--ximo-field-border-style);
    border-color:           var(--ximo-field-border-color);
    margin-right:           var(--ximo-field-margin-right);
    
    opacity:                var(--ximo-field-opacity);
    max-width:              35ch;
    min-width:              15ch;
    
    
    --lumo-disabled-text-color: var(--ximo-field-disabled-color);
  
 }
 
/* disabled */ 
:host([disabled]) [part="input-field"] { 
    border-color:      var(--ximo-field-disabled-border-color);
} 

/* For the label part of a text area */
[part="label"] {
    --lumo-disabled-text-color: var(--ximo-field-disabled-color);
} 

Take into account the different part of a TextArea ("input-field" and "label")

1.4 The class that holds the form should have a reference to all the "css" files, using @CssImport


 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
@PageTitle("MainView")
@Route("mainview")
//... other stuff ....

//General Vaadin theme
@Theme(value = Lumo.class)  //(1)

//@ see https://vaadin.com/forum/thread/17197360/17863614 from Niels Nachname
@CssImport(value="styles/my-textfield-styles.css", themeFor="vaadin-text-field") // (2) Select only Text fields
@CssImport("./styles/shared-styles.css")              // (3) General variable setting 
@CssImport("./styles/current-textfields-styles.css")  // (4) Applied style to TextFields using previous variables


@CssImport(value="styles/my-comboboxstyles.css" , themeFor="vaadin-combo-box") //(2A) Select only for Combos
@CssImport("./styles/current-combobox-styles.css")  // (4B) Applied style to TextFields using previous variables

@CssImport(value="styles/current-textareastyles.css" , themeFor="vaadin-text-area") //(2B) Select only for TextAreas


public class MainView extends VerticalLayout implements RouterLayout {

 private TextField myTF=new TextField();
 
 private ComboBox myCmb01=new ComboBox<>();
 private ComboBox myCmb02=new ComboBox<>();
 private ComboBox myCmb03=new ComboBox<>();

 private TextArea myTA=new TextArea();
        
 public MainView() { 
  myTF.setClassName("my-textfield"); //Important
  
  //myCmb01.setClassName("my-textfield"); --> No set classname for  MyCmb01 as gets general CSS of [part="text-field"]
  myCmb02.setClassName("my-combobox-app"); // See current-combobox-styles.css
  myCmb03.setClassName("my-combobox-opt"); // See current-combobox-styles.css

  // No need to set Class for the textArea
   
 }
 //...other stuff

26. Vaadin 14. Problem with styles. (2) ComboBox

0. Introduction


This post should be used with last post

1. ComboBox Styling


Following again the idea of Niels Nachname


1.0 Assign the Vaaadin Theme (For instance Lumo)

1.1 Create a file that contains general values of styles assigned to variables for instance "shared-styles.css" in the "frontend/styles" folder of your project with this info. Here related information for combos have been added- Note that this file was created in the previous post and new information is included.


 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
html {
  /* Example global custom CSS property definition */
  
  /* 1. FORM FIELDS */
    /* 1.1 enabled */
    --ximo-field-color:                     black;
    --ximo-field-background-color:          white;
    --ximo-field-font-weight:               bold;
    --ximo-field-opacity:                   1.0;
  
    --ximo-field-border-radius:             10px;
    --ximo-field-border-width:              1px 2px 2px 1px;
    --ximo-field-border-style:              solid;
    --ximo-field-border-color:              salmon;
    --ximo-field-margin-right:              15px;
  
    /* 1.2 disabled */
    --ximo-field-disabled-color:            gray;
    --ximo-field-disabled-background-color: white;
    --ximo-field-disabled-font-weight:      bold;
    --ximo-field-disabled-opacity:          0.8;
  
    --ximo-field-disabled-border-radius:    10px;
    --ximo-field-disabled-border-width:     1px 2px 2px 1px;
    --ximo-field-disabled-border-style:     solid;
    --ximo-field-disabled-border-color:     thistle;
    --ximo-field-disabled-margin-right:     15px;
 
 
 /* 2. COMBOBOX */
    /* 1.1 App Selector*/
    --ximo-combo-color:                     maroon;;
    --ximo-combo-font-weight:               bold;
    --ximo-combo-background-image:          linear-gradient(to bottom right, lightpink, white);
    --ximo-combo-border-radius:             10px;
 
    --ximo-combo-border:                    2px;
    --ximo-combo-border-bottom-style:       solid;
    --ximo-combo-border-bottom-width:       medium;
    --ximo-combo-border-bottom-color:       saddlebrown;
}

1.2 Create a file called for instance "my-textfield-styles.css" in the "frontend/styles" folder of your project with this info. The styles are redirected to intermediate variables. This file has been created yet in the previous post. Here is a copy



 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
[part="input-field"]{
     background-color: var(--my-background-color, 'auto');
     color:            var(--my-color,            'auto');
     font-size:        var(--my-font-size,        'auto');
     font-weight:      var(--my-font-weight,      'auto');
     background-image: var(--my-background-image, 'auto');
     border:           var(--my-border,           'auto');
     opacity:          var(--my-opacity,          'auto');
 
 
     border-radius:    var(--my-border-radius,    'auto');
     border-width:     var(--my-border-width,     'auto');
     border-style:     var(--my-border-style,     'auto');
     border-color:     var(--my-border-color,     'auto');
   
     border-bottom-style: var(--my-border-bottom-style,    'auto');
     border-bottom-width: var(--my-border-bottom-width,    'auto');
     border-bottom-color: var(--my-border-bottom-color,    'auto'); 
    
     margin-right: var(--my-margin-right,    'auto');
   
}


[part="input-field"][disabled] {
     background-color:   var(--my-background-color, 'auto');
 
     --lumo-disabled-text-color: var(--my-color,  'auto');
 
     font-size:          var(--my-font-size,        'auto');
     font-weight:        var(--my-font-weight,      'auto');
     background-image:   var(--my-background-image, 'auto');
     border:             var(--my-border,           'auto');
     opacity:            var(--my-opacity,          'auto'); 
 
 
     border-radius:       var(--my-border-radius,    'auto');
     border-width:        var(--my-border-width,     'auto');
     border-style:        var(--my-border-style,     'auto');
     border-color:        var(--my-border-color,     'auto');
 
     border-bottom-style: var(--my-border-bottom-style,    'auto');
     border-bottom-width: var(--my-border-bottom-width,    'auto');
     border-bottom-color: var(--my-border-bottom-color,    'auto');     
    
     margin-right:        var(--my-margin-right,    'auto');
     
}


1.3 Create a file called for instance "current-combobox-styles.css" in the "frontend/styles" folder of your project with this info. These are the styles definitively assigned to ComboBoxes. You should assign the classes "my-combobox-app" or "my-combobox-opt" or none of them to the ComboBox.



 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
/* general style for all combos */
[part="text-field"]{ 
    --my-color:               var(--ximo-combo-color); 
    --my-font-size:           110%;
    --my-font-weight:         var(--ximo-combo-font-weight); 
    --my-background-image:    var(--ximo-combo-background-image);
    --my-border-radius:       var(--ximo-combo-border-radius);
 
    --my-border:              var(--ximo-combo-border);
    --my-border-bottom-style: var(--ximo-combo-border-bottom-style);
    --my-border-bottom-width: var(--ximo-combo-border-bottom-width);
    --my-border-bottom-color: var(--ximo-combo-border-bottom-color);
} 

/* explicid for a combo that has been assigned the class "my-combobox-app" */
:host(.my-combobox-app) [part="text-field"]{ 
    --my-font-size:        110%;
}

/* explicid for a combo that has been assigned the class "my-combobox-opt" */
:host(.my-combobox-opt) [part="text-field"]{ 
    --my-font-size:        100%;
    --my-margin-right: 10px;
    
}

1.4 The class that holds the form should have a reference to all the "css" files, using @CssImport


 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
@PageTitle("MainView")
@Route("mainview")
//... other stuff ....

//General Vaadin theme
@Theme(value = Lumo.class)  //(1)

//@ see https://vaadin.com/forum/thread/17197360/17863614 from Niels Nachname
@CssImport(value="styles/my-textfield-styles.css", themeFor="vaadin-text-field") // (2) Select only Text fields
@CssImport("./styles/shared-styles.css")              // (3) General variable setting 
@CssImport("./styles/current-textfields-styles.css")  // (4) Applied style to TextFields using previous variables


@CssImport(value="styles/my-comboboxstyles.css" , themeFor="vaadin-combo-box") //(2A) Select only for Combos
@CssImport("./styles/current-combobox-styles.css")  // (4B) Applied style to ComboBox using previous variables

public class MainView extends VerticalLayout implements RouterLayout {

 private TextField myTF=new TextField();
 private ComboBox myCmb01=new ComboBox<>();
 private ComboBox myCmb02=new ComboBox<>();
 private ComboBox myCmb03=new ComboBox<>();
        
 public MainView() { 
  myTF.setClassName("my-textfield"); //Important
  //myCmb01.setClassName("my-textfield"); --> No set classname for  MyCmb01 as gets general CSS of [part="text-field"]
  myCmb02.setClassName("my-combobox-app"); // See current-combobox-styles.css
  myCmb03.setClassName("my-combobox-opt"); // See current-combobox-styles.css
 }
 //...other stuff





25. Vaadin 14. Problem with styles. (1) TextFields

0. Introduction


Themes in Vaadin are difficult to understand. Changing a CSS attribute may be a complicated and unsuccessful task.

1. TextFields styling

As Niels Nachname states:

1.0 Assign the Vaaadin Theme (For instance Lumo)

1.1 Create a file that contains general values of styles assigned to variables for instance "shared-styles.css" in the "frontend/styles" folder of your project with this info.


 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
html {
  /* Example global custom CSS property definition */
  
  /* 1. FORM FIELDS */
    /* 1.1 enabled */
    --ximo-field-color:                     black;
    --ximo-field-background-color:          white;
    --ximo-field-font-weight:               bold;
    --ximo-field-opacity:                   1.0;
  
    --ximo-field-border-radius:             10px;
    --ximo-field-border-width:              1px 2px 2px 1px;
    --ximo-field-border-style:              solid;
    --ximo-field-border-color:              salmon;
    --ximo-field-margin-right:              15px;
  
    /* 1.2 disabled */
    --ximo-field-disabled-color:            gray;
    --ximo-field-disabled-background-color: white;
    --ximo-field-disabled-font-weight:      bold;
    --ximo-field-disabled-opacity:          0.8;
  
    --ximo-field-disabled-border-radius:    10px;
    --ximo-field-disabled-border-width:     1px 2px 2px 1px;
    --ximo-field-disabled-border-style:     solid;
    --ximo-field-disabled-border-color:     thistle;
    --ximo-field-disabled-margin-right:     15px;
 
}


1.2 Create a file called for instance "my-textfield-styles.css" in the "frontend/styles" folder of your project with this info. The styles are redirected to intermediate variables


 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
[part="input-field"]{
     background-color: var(--my-background-color, 'auto');
     color:            var(--my-color,            'auto');
     font-size:        var(--my-font-size,        'auto');
     font-weight:      var(--my-font-weight,      'auto');
     background-image: var(--my-background-image, 'auto');
     border:           var(--my-border,           'auto');
     opacity:          var(--my-opacity,          'auto');
 
 
     border-radius:    var(--my-border-radius,    'auto');
     border-width:     var(--my-border-width,     'auto');
     border-style:     var(--my-border-style,     'auto');
     border-color:     var(--my-border-color,     'auto');
   
     border-bottom-style: var(--my-border-bottom-style,    'auto');
     border-bottom-width: var(--my-border-bottom-width,    'auto');
     border-bottom-color: var(--my-border-bottom-color,    'auto'); 
    
     margin-right: var(--my-margin-right,    'auto');
   
}


[part="input-field"][disabled] {
     background-color:   var(--my-background-color, 'auto');
 
     --lumo-disabled-text-color: var(--my-color,  'auto');
 
     font-size:          var(--my-font-size,        'auto');
     font-weight:        var(--my-font-weight,      'auto');
     background-image:   var(--my-background-image, 'auto');
     border:             var(--my-border,           'auto');
     opacity:            var(--my-opacity,          'auto'); 
 
 
     border-radius:       var(--my-border-radius,    'auto');
     border-width:        var(--my-border-width,     'auto');
     border-style:        var(--my-border-style,     'auto');
     border-color:        var(--my-border-color,     'auto');
 
     border-bottom-style: var(--my-border-bottom-style,    'auto');
     border-bottom-width: var(--my-border-bottom-width,    'auto');
     border-bottom-color: var(--my-border-bottom-color,    'auto');     
    
     margin-right:        var(--my-margin-right,    'auto');
     
}


1.3 Create a file called for instance "current-textfield-styles.css" in the "frontend/styles" folder of your project with this info. These are the styles definitively assigned to TextFields. You should assign the class "my-textfield" to the TextFields.


 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
/* style assigned in openadmin.ui.forms.elements.FieldBindCreator 
   IT IS USED IN CONJUNCTION WITH edu-textfieldstyles.css !!!!
*/ 
  .my-textfield{
     --my-color:             var(--ximo-field-color);
     --my-font-weight:       var(--ximo-field-font-weight);
     --my-background-color:  var(--ximo-field-background-color);
     --my-border-radius:     var(--ximo-field-border-radius);
     --my-border-width:      var(--ximo-field-border-width);
     --my-border-style:      var(--ximo-field-border-style);
     --my-border-color:      var(--ximo-field-border-color);
     --my-margin-right:      var(--ximo-field-margin-right);
     --my-opacity:           var(--ximo-field-opacity);

     --lumo-disabled-text-color: var(--ximo-field-disabled-color);
  } 
 
  .my-textfield:disabled,
  .my-textfield[disabled]{
     --my-font-weight:           var(--ximo-field-disabled-font-weight);
     --my-border-radius:         var(--ximo-field-disabled-border-radius);
     --my-border-width:          var(--ximo-field-disabled-border-width);
     --my-border-style:          var(--ximo-field-disabled-border-style);
     --my-border-color:          var(--ximo-field-disabled-border-color);
     --my-margin-right:          var(--ximo-field-disabled-margin-right);
  } 
 

Take into account of the variable --lumo.disabled-text-color  


1.4 The class that holds the form should have a reference to all the "css" files, using @CssImport


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@PageTitle("MainView")
@Route("mainview")
//... other stuff ....

//General Vaadin theme
@Theme(value = Lumo.class)  //(1)

//@ see https://vaadin.com/forum/thread/17197360/17863614 from Niels Nachname
@CssImport(value="styles/my-textfield-styles.css", themeFor="vaadin-text-field") // (2) Select only Text fields
@CssImport("./styles/shared-styles.css")              // (3) General variable setting 
@CssImport("./styles/current-textfields-styles.css")  // (4) Applied style to TextFields using previous variables



public class MainView extends VerticalLayout implements RouterLayout {

 private TextField myTF=new TextField();
        
 public MainView() { 
  myTF.setClassName("my-textfield"); //Important
 }
 //...other stuff
}