Creating and Using Themes
Custom themes are placed in ITMILL/themes folder of the
web application (in the WebContent directory) as
illustrated in Figure 6.1, “Theme Contents”. You need to
have a theme folder for each theme you use in your application, although
applications rarely need more than a single theme. For example, if you want to
define a theme with name mytheme, you will place it in
folder ITMILL/themes/mytheme.
Styling Standard Components
Each user interface component in IT Mill Toolkit has a set of style
classes that you can use to control the appearance of the component. Some
components have additional elements that also allow styling.
The following table lists the style classes of all client-side components
of IT Mill Toolkit. Notice that a single server-side component can have
multiple client-side implementations. For example, a
Button can be rendered on the client side either as
a regular button or a check box, depending on the
switchMode attribute of the button. For details
regarding the mapping to client-side components, see the section called “Defining a Widget Set”. Each client-side component type has its own style class
and a number of additional classes that depend on the client-side state of
the component. For example, a text field will have
i-textfield-focus class when mouse pointer hovers over
the component. This state is purely on the client-side and is not passed
to the server.
Some client-side components can be shared by different server-side
components. There is also the
IUnknownComponent, which is a component that
indicates an internal error in a situation where the server asked to
render a component which is not available on the client-side.
Table 6.1. Default CSS Style Names of IT Mill Toolkit Components
| Server-Side Component | Client-Side Widget | CSS Class Name | State Indicators |
|---|
| Button | IButton | i-button | |
| ICheckBox | | |
| CustomComponent | ICustomComponent | i-customcomponent | |
| CustomLayout | ICustomLayout | | |
| DateField | IDateField | i-datefield | |
| ICalendar | i-datefield-entrycalendar | |
| IDateFieldCalendar | i-datefield-calendar | |
| IPopupCalendar | i-datefield-calendar | |
| ITextualDate | | i-readonly, i-textfield-error |
| Embedded | IEmbedded | - | |
| Form | IForm | i-form | |
| FormLayout | IFormLayout | - | |
| GridLayout | IGridLayout | - | |
| Label | ILabel | i-label | |
| Link | ILink | i-link | readonly, enabled |
| OptionGroup | IOptionGroup | i-select-optiongroup | |
| OrderedLayout | IOrderedLayout | i-orderedlayout | |
| IOrderedLayoutHorizontal | i-orderedlayout | |
| IOrderedLayoutVertical | i-orderedlayout | |
| Panel | IPanel | i-panel (i-panel-caption, i-panel-content, i-panel-deco) | |
| Select | | | |
| IListSelect | i-listselect | |
| IFilterSelect | i-filterselect | | |
| Slider | ISlider | i-slider | |
| SplitPanel | ISplitPanel | - | |
| ISplitPanelHorizontal | - | |
| ISplitPanelVertical | - | |
| Table | IScrollTable | i-table | |
| ITablePaging | i-table (i-table-tbody) | |
| TabSheet | ITabSheet | i-tabsheet (i-tabsheet-content, i-tablsheet-tabs) | |
| TextField | ITextField | i-textfield | i-textfield-focus |
| ITextArea | | |
| IPasswordField | | |
| Tree | ITree | i-tree (i-tree-node-selected) | |
| TwinColSelect | ITwinColSelect | i-select-twincol (i-select-twincol-selections, i-select-twincol-buttons, i-select-twincol-deco) | |
| Upload | IUpload | - | |
| Window | IWindow | i-window | |
| - | CalendarEntry | - | |
| - | CalendarPanel | i-datefield-calendarpanel | |
| - | ContextMenu | i-contextmenu | |
| - | IUnknownComponent | itmtk-unknown (itmtk-unknown-caption) | |
| - | IView | - | |
| - | Menubar | gwt-MenuBar | |
| - | MenuItem | gwt-MenuItem | |
| - | Time | i-datefield-time (i-select) | |
Style names of sub-components are shown in parentheses.
The default styling of components is defined in the default theme. The
overall default theme consists of the default themes of all included
widget sets. The default theme of the
DefaultWidgetSet widget set is located under
com.itmill.toolkit.terminal.gwt package, under
public/default folder. The
styles.css includes all the widget-specific
stylesheets located in the subfolders.
Default theme of custom GWT widgets is detailed in the section called “Styling GWT Widgets”.
Using a theme is simple, you only need to set the theme with
setTheme().
Defining the appearance of a user interface component is fairly
simple. First, you create a component and add a custom style name for it
with addStyleName(). Then you write the CSS
element that defines the formatting for the component.
IT Mill Toolkit Release 4 had an inheritance mechanism for themes. In
Release 5, the themes were greatly simplified. The inheritance mechanism
was removed, and now there is only one level of inheritance, where each
custom theme inherits the default theme.
More complex inheritance of themes did have advantages in certain use
cases. For example, a web application could have a base theme for all
users, and themes for specific user roles (normal/moderator/administrator
or student/teacher/administrator) or even individual users.
While there is no actual inheritance mechanism, it is trivial to implement
inheritance with the @import statement in CSS. For
example, let us assume that we have the base theme of an application with
name myapp and a specific
myapp-student theme for users with the student
role. The stylesheet of the base theme would be located in
themes/myapp/styles.css. We can then "inherit" it in
themes/myapp-student/styles.css with a simple
@import statement:
@import "../myapp/styles.css";
body {
background: green;
}
This would make the page look just as with the base theme, except for the
green background. You could use the theme inheritance as follows:
public class MyApplication extends com.itmill.toolkit.Application {
public void init() {
setTheme("myapp");
...
}
public void login(User user) {
if (user.role == User.ROLE_STUDENT)
setTheme("myapp-student");
...
}
public void logout() {
setTheme("myapp");
...
}
}