SlideShare una empresa de Scribd logo
1 de 54
GWT Training – Session II

Client-Side Implementation

Snehal Masne
www.TechProceed.com
Contents


The User Interface






Static widgets
Form widgets
Complex widgets
Panels

This are slides are based from the book “Google Web Toolkit Applications” by Ryan Desbury, 2008, Pearson Education

www.TechProceed.com
The User Interface






GWT contains classes for building dynamic
re-usable components (called widgets) based
upon web browser's user interface features
The user interface framework is similar to
Java AWT/Swing
For the purpose of this tutorial, we divide the
different types of widgets into four categories
– Static widgets, form widgets, complex
widgets and panels
www.TechProceed.com
The User Interface Groups

www.TechProceed.com
Static Widgets






They do not have any internal state or
change dynamically on their own
Can be part of a dynamic user interface in
which the user interface code can change
their properties and location at runtime, but
not as a result of user actions
Includes






Label
HTML
Image
Hyperlink
www.TechProceed.com
The Entry-Point Class










Before we start building our user interface, we need to understand the EntryPoint Class
Think of this class as the main class of your application with the java main()
method that the JVM invokes first
The Entry-Point class contains onModuleLoad() method which is the method that
the GWT compiler calls first
The class implements com.google.gwt.core.client.EntryPoint interface
For the GWTTraining project, GWTTraining.java is the Entry-Point class (which
is defined in the application's GWT configuration file)‫‏‬

import com.google.gwt.core.client.EntryPoint
public class GWTTraining implements EntryPoint {
public void onModuleLoad() {
//your initial code goes here
}
}
www.TechProceed.com
Label
















A widget that contains arbitrary text, not interpreted as HTML. This widget uses a <div> element,
causing it to be displayed with block layout
Open the GWTTraining project in Eclipse
Create a new Entry Point class called GWTTrainingWidget under File > New. We would use this entry
class for our widgets tutorial.
In the GWTTraining.gwt.xml configuration file, delete the entry-point definition for
my.utm.kase.gettraining.client.GWTTraining. We only want to display the GWTTrainingWidgets entrypoint when we run the applicaiton.
Also edit the GWTTraining.html and delete the contents of the <body> tag so that we start from an
empty page.
Add the following import statements
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
Add the following code in the onModuleLoad() method
Label label = new Label("Welcome to CASE, UTM");
RootPanel.get().add(label);
The code creates a new label widget and adds it to the root panel
A‫‏‬simple‫‏‬text‫“‏‬Welcome‫‏‬to‫‏‬CASE,‫‏‬UTM”‫‏‬is‫‏‬displayed‫‏‬when‫‏‬you‫‏‬run‫‏‬the‫‏‬application.

www.TechProceed.com
Label – Embellishing with CSS





A great feature of GWT is letting you to achieve great presentations using CSS
GWT widgets have default CSS names that let you set their style
The label widget CSS is .gwt-Label { }
Add the following to the /war/GWTTraining.css to change the appearance of the
label widget:
.gwt-Label{
background-color:silver;
color:green;
text-align-center;
border-style:groove;
border-width:thick;
border-color:navy;
}

www.TechProceed.com
Label – Embellishing with CSS






If you use the default GWT CSS names for the widgets, all widgets of the same
class are affected.
To demonstrate this, let's create another label widget by adding the following
code in the GWTTrainingWidgets.java file:
Label label2 = new Label("Where Advanced Learning Begins");
RootPanel.get().add(label2);
label2 also has the same appearance as the first label because it also inherits from .gwtLabel CSS name.

www.TechProceed.com
Label – Embellishing with CSS









We can apply a different style for a particular label instead of the general class definition
To demonstrate that add the following custom CSS definition in GWTTraining.css
.label2 {
background-color:orange;
border-style:ridge;
border-width:thick;
border-color:navy;
}
Add the following code to set the style to label2 (before adding it to the root panel:
label2.setStylePrimaryName("label2");
When you refresh the browser you will see that label2 now has its own customized style.
Styling with CSS is the same for all the other widgets in GWT. The default style names of
the widgets can be found in the GWT API Java documentation.

Info: CSS is a very powerful language that gives the web great look and feel. Because it is separated from the content (usually
HTML), customizing the pages becomes very flexible. For further reading you may want to check: The Ultimate CSS
reference

www.TechProceed.com
Customizing programatically


Some properties of the Label (and other
widgets as well) can be customized
programatically

www.TechProceed.com
HTML Widget







Used for rendering HTML
Add the following codes to GWTTrainingWidgets.java
RootPanel.get().add(new HTML("<hr/>"));
//add a horizontal line break
RootPanel.get().add(new HTML("<b>CASE in bold</>")); //add bold text
RootPanel.get().add(new HTML("<a href='http://www.case.utm.my'>Find
more about CASE</a>"));
RootPanel.get().add(new HTML("<hr/>"));
//add a horizontal line break
Add import statement for com.google.gwt.user.client.ui.HTML
Refresh the browser to view the changes
The HTML widget can be customized using CSS just like the Label widget. The default CSS
name is .gwt-HTML

www.TechProceed.com
The Image Widget





Accepts a URL pointing to an image file and renders it
Create images folder: /war/gwttraining/images.
Add case_logo.jpg to the folder which is provided in the training resources CD
Add the following code:
String url = GWT.getModuleBaseURL() + "images/case_logo.jpg";
Image image = new Image(url);
RootPanel.get().add(image);



CSS default style name is .gwt-Image

www.TechProceed.com
The Image Widget




Add the following code to display image from an external server:
RootPanel.get().add(new
Image("http://www.case.utm.my/v2/images/intro_pic/case_intro_pic_1%20copy.g
if"));
The following output should be displayed when the browser is refreshed

www.TechProceed.com
The Form Widgets







Widgets typically used with HTML forms
Unlike traditional HTML forms, data is submitted to the server asynchrnously
without refreshing the page
GET form widgets can be used in ways similar to desktop applications and not
necessarily inside a HTML form
The widgets include:
 Button, CheckBox, RadioButton, ListBox, TextBox
 PasswordTextBox, TextArea, FileUpload, Hiddein
 ToggleButton, PushButton, SuggestBox and RichTextArea

www.TechProceed.com
The Button Widget









Wraps‫‏‬the‫‏‬HTML‫‏‬form‫‏‬input‫‏‬with‫‏‬the‫‏‬type‫‏‬button‫<(‏‬input‫‏‬type=”button”>)‫‏‬
Can be used to invoke any action in the application
To see the Button widget in action add the following code:
Button alertButton = new Button("Alert"); //create the button
alertButton.addClickHandler( new ClickHandler() { //handle event
@Override
public void onClick(ClickEvent event) {
//handle button event here
Window.alert("Alert button clicked!");
}
});
//add alertButton to root widget
RootPanel.get().add(new HTML("<hr/>"));
//add a horizontal line
RootPanel.get().add(alertButton);
//add button to root panel
Just like other GWT widgets, the Button widget events are handled using the Observer pattern
The observer (Event handler) observes the state of the subject (the user interface, e.g Button).
When‫‏‬the‫‏‬subject’s‫‏‬state‫‏‬changes,‫‏‬the‫‏‬observer‫‏‬is‫‏‬notified.
The default CSS name is .gwt-Button

www.TechProceed.com
ToggleButton and PushButton
Widget




Both similar to Button widget
When ToggleButton is clicked it remains in a 'pressed state' until clicked again
A PushButton supports customization of its look based on its state
//toggle and push buttons
ToggleButton toggleButton = new ToggleButton("Toggle me");
PushButton pushButton = new PushButton("I'm a push button");
pushButton.setSize("150", "40");
RootPanel.get().add(toggleButton);
RootPanel.get().add(pushButton);



You‫‏‬can‫‏‬set‫‏‬some‫‏‬widget‫‏‬properties‫“‏‬programmatically”‫‏‬without‫‏‬using‫‏‬CSS‫‏‬
definition just as is done above in setting the size of the PushButton. However
using CSS is the most recommended because it separates the presentation from
the Java code which improves flexibility and maintainability.

www.TechProceed.com
Button Widgets with Images






You may create buttons (Button, ToggleButton or PushButton) with images instead of
text captions
ToggleButton can be created with two images so that they can be represented in
pressed and released states.
ToggleButton imgToggleButton = new ToggleButton(
new Image(GWT.getModuleBaseURL() + "images/h_toggle.jpg"),
new Image(GWT.getModuleBaseURL() + "images/v_toggle.jpg")‫‏‬
);
imgToggleButton.setSize("60", "60");
RootPanel.get().add(new HTML("<hr/>"));
//add a horizontal line
RootPanel.get().add(imgToggleButton);
//add imgToggleButton to
//root panel
Copy the h_toggle.jpg and v_toggle.jpg to /war/gwttraining/images

Released State

Pressed State
www.TechProceed.com
Styling Button States with Css




You can use CSS to generate different styles for ToggleButton and PushButton
based on their states
The default names for the states are shown in table below:

www.TechProceed.com
Checkbox Widget







Wraps‫‏‬HTML’s‫‏‬check‫‏‬box‫‏‬input‫‏‬tag‫<(‏‬input‫‏‬type=”button”>)‫‏‬
Has two states - Checked/Unchecked
You can programmatically set the state with the setChecked method by passing true for
checked or false for unchecked
Supports focus behavior and click events
Default CSS name is .gwt-Checkbox

www.TechProceed.com
Checkbox Widget - Code
Sample
//checkbox widget
final CheckBox checkBox = new CheckBox("Do u love GWT?");
checkBox.addClickHandler( new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
//handle event
if( checkBox.getValue() ) {
Window.lert("Yeah, welcome to the world of GWT");
}
else {
Window.alert("Sorry, u are missing a lot. U gotta think again");
}
}
});
RootPanel.get().add(new HTML("<hr/>"));
RootPanel.get().add(checkBox);

//add a horizontal break line

www.TechProceed.com
RadioButton Widget


Usually belongs to a group of other
RadioButtons so that only one selection can
be made

www.TechProceed.com
RadioButton Widget – Sample
Code
//radio button widget
final RadioButton redButton = new RadioButton("color", "red");
final RadioButton orangeButton = new RadioButton("color", "orange");
final RadioButton greenButton = new RadioButton("color", "green");
final Label label3 = new Label("");
label3.setSize("25", "25");
label3.setStylePrimaryName("label3");
ClickHandler radioButtonsHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if( event.getSource() == redButton ) {
label3.setStylePrimaryName("red");
}
else if( event.getSource() == orangeButton ) {
label3.setStylePrimaryName("orange");
}
else {
label3.setStylePrimaryName("green");
}
}
};
www.TechProceed.com
RadioButton Widget – Sample
Code (cont'd)‫‏‬
redButton.addClickHandler(radioButtonsHandler);
orangeButton.addClickHandler(radioButtonsHandler);
greenButton.addClickHandler(radioButtonsHandler);
RootPanel.get().add(new HTML("<hr/>")); //add a horizontal break line
//add to root panel
RootPanel.get().add(label3);
RootPanel.get().add(redButton);
RootPanel.get().add(orangeButton);
RootPanel.get().add(greenButton);
CSS Stlye
.label3 {
border-style:groove;
width: 25px;
height: 25px;
}
.red {
background-color:red;
}
.orange {
background-color:orange;
}
.green {
background-color:green;
}
www.TechProceed.com
ListBox Widget




A group of options in a form of list in which
only one option can be selected
Two forms:



Normal list
Drop down list

www.TechProceed.com
ListBox Widget – Sample Code
final ListBox colorList = new ListBox();
colorList.addItem("Red");
colorList.addItem("Orange");
colorList.addItem("Green");
colorList.addChangeHandler( new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
if( colorList.getSelectedIndex() == 0 ) {
label3.setStylePrimaryName("red");
redButton.setValue(true);
}
else if( colorList.getSelectedIndex() == 1 ) {
label3.setStylePrimaryName("orange");
orangeButton.setValue(true);
}
else {
label3.setStylePrimaryName("green");
greenButton.setValue(true);
}
}
});

RootPanel.get().add(new HTML("<hr/>")); //add a horizontal break line
RootPanel.get().add(colorList);
www.TechProceed.com
ListBox Sample Code – cont'd




The previous code displays the drop down
format of the ListBox
Use the following code to change to the
normal format:
//change the list box format
colorList.setVisibleItemCount(3);

www.TechProceed.com
SuggestBox Widget









A text box with drop-down suggestions based
on the word that you type
Usually used when the list of items are too
much to be displayed at a time
E.g. Google Suggest
Uses SuggestOracle instance to plug in
dynamic results from datasource on the
server
MultiWordSuggestOracle can be used if the
suggest list is generated at the client side
www.TechProceed.com
SuggestBox – Sample Code
//SuggestBox
String suggestString = "The Faculty of Computer Science and Information "
+ "Systems, UTM provides specialist teaching and conducts research "
+ "in fundamental and applied computer science, software "
+ "engineering, artificial intelligence and cognitive science. "
+ "We are proud to deliver outstanding undergraduate and "
+ "postgraduate education that offers varied and exciting "
+ "career opportunities around the world.";
String words[] = suggestString.split(" ");
MultiWordSuggestOracle suggestOracle = new MultiWordSuggestOracle();
suggestOracle.addAll(Arrays.asList(words));
SuggestBox suggestBox = new SuggestBox(suggestOracle);
RootPanel.get().add(new HTML("<hr/>"));
RootPanel.get().add(suggestBox);

//add a horizontal break line

CSS Styles
.gwt-SuggestBox {}
.gwt-SuggestBoxPopup { border: 2px solid #C3D9FF; background-color:#E8EEF7; }
.gwt-SuggestBoxPopup .item { }
.gwt-SuggestBoxPopup .item-selected { background-color:#C3D9FF;}
www.TechProceed.com
TextBox Widget


Encapsulates‫‏‬HTML’s‫‏‬input‫‏‬tag‫‏‬with‫‏‬type‫‏‬input‫<(‏‬input‫‏‬type=”input”>)



Typically used for capturing small text input from user
//TextBox widget
final TextBox emailBox = new TextBox();
emailBox.setText("<Enter your email>");
emailBox.setStylePrimaryName("emailBox-blank");
//add focus gain handler
emailBox.addFocusHandler( new FocusHandler() {
@Override
public void onFocus(FocusEvent event) {
String emailText = emailBox.getText();
if( emailText.equals("<Enter your email>")) {
emailBox.setText("");
}
emailBox.removeStyleName("emailBox-blank");
}
});
www.TechProceed.com
TextBox Widget – cont'd
//add focus lost handler
emailBox.addFocusListener(new FocusListenerAdapter() {
public void onLostFocus(Widget sender) {
String emailText = emailBox.getText();
if( emailText.equals("")) {
emailBox.setStylePrimaryName("emailBox-blank");
emailBox.setText("<Enter your email>");
}
}
});
RootPanel.get().add(new HTML("<hr/>"));
RootPanel.get().add(emailBox);

//add a horizontal break line

www.TechProceed.com
PasswordTextBox Widget


Similar to TextBox but its contents are hidden
to protect sensitive data
//PasswordTextBox widget
PasswordTextBox passwordBox = new PasswordTextBox();
RootPanel.get().add(new HTML("<hr/>"));
RootPanel.get().add(passwordBox);

www.TechProceed.com
TextArea Widget


Similar to TextBox but contents can span
multiple pages
//TextArea widget
TextArea textArea = new TextArea();
textArea.setCharacterWidth(80);
textArea.setVisibleLines(10);
RootPanel.get().add(new HTML("<hr/>"));
RootPanel.get().add( textArea );

www.TechProceed.com
FileUpload Widget




Encapsulates‫‏‬HTML’s‫‏‬input‫‏‬tag‫‏‬with‫‏‬its‫‏‬type‫‏‬
attribute set to file (<input type='file'>)‫‏‬
Allows users to select a file from their local
file system, usually to be uploaded to the
server
//FileUpload widget
FileUpload fileUpload = new FileUpload();
RootPanel.get().add(new HTML("<hr/>"));
RootPanel.get().add( fileUpload );

www.TechProceed.com
Hidden Widget




Encapsulates‫‏‬HTML’s‫‏‬input‫‏‬tag‫‏‬of‫‏‬type‫‏‬
hidden (<input type='hidden'>)‫‏‬
It is used with the FormPanel to submit a
form asynchronously to the server.

www.TechProceed.com
Complex Widgets










User interface widgets in web pages that do
not have HTML tag equivalents.
They are created by compositing HTML tags
together and handling user events through
JavaScript to emulate more
sophisticated widgets.
GWT has some complex widgets in its library
Advanced custom widgets can also be built
with GWT
www.TechProceed.com
Tree Widget






Displays a hierarchical view of data that can
be expanded and collapsed similar to tree
widgets in desktop applications typically
You can add simple text or widgets as
children of the tree
The TreeItem widget can be used to achieve
several levels of hierarchy

www.TechProceed.com
TreeWidget – Sample Code
//Tree Widget
Tree rootTree = new Tree();
TreeItem treeItem1 = new TreeItem("Contact 1");
treeItem1.addItem(new Image(GWT.getModuleBaseURL() + "images/contact.jpg"));
treeItem1.addItem(new Image(GWT.getModuleBaseURL() +
"images/mail.jpeg"));
TreeItem treeItem2 = new TreeItem("Contact 2");
treeItem2.addItem(new Image("images/contact.jpg"));
treeItem2.addItem(new Image("images/mail.jpeg"));
rootTree.addItem(treeItem1);
rootTree.addItem(treeItem2);
RootPanel.get().add(new HTML("<hr/>"));
RootPanel.get().add( rootTree );
CSS Style Rules
.gwt-Tree {}
.gwt-Tree .gwt-TreeItem {}
.gwt-Tree .gwt-TreeItem-selected {}
www.TechProceed.com
MenuBar Widget



Similar to menu bars on desktop applications
Displays list of menus to be selected
//MenuBar widget
MenuBar lecturerMenu = new MenuBar(true); //orient vertically
lecturerMenu.addItem("Save Records" , new Command() {
public void execute() {
Window.alert("Saved");
}
});
MenuBar studentMenu = new MenuBar(true); //orient vertically
studentMenu.addItem("Register" , new Command() {
public void execute() {
//add register event
}
});

www.TechProceed.com
MenuBar Widget – cont'd
studentMenu.addItem("View Records" , new Command() {
public void execute() {
//view records event
}
});
MenuBar menu = new MenuBar();
menu.addItem("Lecturer", lecturerMenu);
menu.addItem("Student", studentMenu);
RootPanel.get().add(menu, 0, 0);

www.TechProceed.com
MenuBar Widget – CSS Styles
.gwt-MenuBar {
background-color:#F3F5F6;
border: 1px;
}
.gwt-MenuBar .gwt-MenuItem {
font-size: 9pt;
cursor:hand;
cursor:pointer;
padding:2px 5px 2px 5px;
margin:0px;
}
.gwt-MenuBar .gwt-MenuItem-selected {
background-color:#316AC5;
color:white;
}

www.TechProceed.com
Simple Layout Panels






Panels are used to organize the layout of the
various widgets we have covered so far.
GWT has several layout widgets that provide
this functionality
The simple Layout Panels include:





FlowPanel
VerticalPanel
HorizontalPanel

www.TechProceed.com
FlowPanel



It functions like the HTML layout
Child widgets of the FlowPanel are displayed
horizontally and then wrapped to the next row
down when there is not enough horizontal room
left
//FlowPanel
FlowPanel flowPanel = new FlowPanel();
for( int i = 1; i <= 20; i++ ) {
flowPanel.add(new Button("Button " + String.valueOf(i)));
}
RootPanel.get().add(flowPanel);

www.TechProceed.com
FlowPanel – cont'd




If you run the code and resize the browser window
smaller, you will see that the child widgets (buttons)
are displaced to the next row when the space
becomes insufficient to display in one row
The result is opposite if you resize the window
bigger

www.TechProceed.com
HorizontalPanel and
VerticalPanel




HorizontalPanel is similar to FlowPanel but
uses scrollbar to display its widgets if there is
no enough room instead of displacing to the
next row
VerticalPanel organizes its child widgets in a
vertical orientation

www.TechProceed.com
HorizontalSplitPanel and
VerticalSplitPanel


They are divided into two panels that be
resized

www.TechProceed.com
FlexTable and Grid Widgets







Encapsulates HTML's table tag (<table />)‫‏‬
They display child widgets in a grid spanning
vertically and horizontally.
The Grid widget enforces an explicitly set
number of rows and cells for each row.
The FlexTable is more flexible, allowing cells
to be added as needed, rows to have a
variable number of cells, and cells to span
multiple rows or columns
www.TechProceed.com
FlexTable and Grid Widgets –
cont'd
//Grid
Grid grid = new Grid(3,3);
for( int i = 0; i < 3; i++) {
for( int j = 0; j < 3; j++ ) {
grid.setWidget(i,j,new Image(GWT.getModuleBaseURL() +
"images/tree2.jpg"));
}
}
//FlexTable
FlexTable flexTable = new FlexTable();
flexTable.setWidget(0,0, new HTML("Flex Table Widget"));
flexTable.getFlexCellFormatter().setColSpan(0, 0, 4);
for( int i = 0; i < 4; i++ ) {
flexTable.setWidget(1, i, new Image(GWT.getModuleBaseURL() +
"images/tree.jpeg"));
}

www.TechProceed.com
FlexTable and Grid Widgets –
cont'd
flexTable.setWidget(2,0, new Image(GWT.getModuleBaseURL() + "images/tree2.jpg"));
flexTable.setWidget(2,1, new Image(GWT.getModuleBaseURL() + "images/tree2.jpg"));
flexTable.getFlexCellFormatter().setColSpan(2, 0, 2);
flexTable.getFlexCellFormatter().setColSpan(2, 1, 2);
flexTable.setWidget(3, 0, new Image(GWT.getModuleBaseURL() +
"images/tree_big.png"));
flexTable.getFlexCellFormatter().setColSpan(3, 0, 4);
HorizontalSplitPanel hSplitPanel = new HorizontalSplitPanel();
hSplitPanel.setLeftWidget(flexTable);
hSplitPanel.setRightWidget(grid);
RootPanel.get().add(hSplitPanel);

www.TechProceed.com
Customizing the Widgets
HorizontalSplitPanel hSplitPanel = new HorizontalSplitPanel();
hSplitPanel.setLeftWidget(flexTable);
hSplitPanel.setRightWidget(grid);
RootPanel.get().add(hSplitPanel);
//vertical panel 2
VerticalPanel vPanel2 = new VerticalPanel();
vPanel2.add(rootTree);
vPanel2.add(flowPanel);
RootPanel.get().add(vPanel2);

www.TechProceed.com
Customizing the Widgets –
cont'd
//vertical panel 3
HorizontalPanel hPanel2 = new HorizontalPanel();
hPanel2.add(checkBox);
hPanel2.add(label3);
hPanel2.add(redButton);
hPanel2.add(orangeButton);
hPanel2.add(greenButton);
hPanel2.add(colorList);
VerticalPanel vPanel4 = new VerticalPanel();
vPanel4.add(textArea);
vPanel4.add(fileUpload);
RootPanel.get().add(vPanel4);

www.TechProceed.com
TabPanel


Displays just one of its child widgets at a time and provides controls to select the
child to display
//TabPanel
TabPanel tabPanel = new TabPanel();
tabPanel.add(vPanel2, "Buttons");
tabPanel.add(hPanel2, "Options");
tabPanel.add(vPanel4, "Text");
tabPanel.setSize("100%", "100%");
RootPanel.get().add(tabPanel);

www.TechProceed.com
Other Widgets















DeckPanel
DockPanel
StackPanel
HTMLPanel
LazyPanel
Composite
SimplePanel
ScrollPanel
FocusPanel
FormPanel
DisclosurePanel
PopupPanel
DialogBox

www.TechProceed.com
This brings us to the end of the 2nd session of
the GWT Training. In the next session we
would learn how to establish communication
between the client and server.

Thank you

www.TechProceed.com

Más contenido relacionado

La actualidad más candente

WPF - the future of GUI is near
WPF - the future of GUI is nearWPF - the future of GUI is near
WPF - the future of GUI is nearBartlomiej Filipek
 
Intro to Web Components, Polymer & Vaadin Elements
Intro to Web Components, Polymer & Vaadin ElementsIntro to Web Components, Polymer & Vaadin Elements
Intro to Web Components, Polymer & Vaadin ElementsManuel Carrasco Moñino
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuAppUniverz Org
 
Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentationBrian Hogg
 
TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08Andy Gelme
 
Miha Lesjak Mobilizing The Web with Web Runtime
Miha Lesjak Mobilizing The Web with Web RuntimeMiha Lesjak Mobilizing The Web with Web Runtime
Miha Lesjak Mobilizing The Web with Web RuntimeNokiaAppForum
 
Native look and feel bbui & alicejs
Native look and feel bbui & alicejsNative look and feel bbui & alicejs
Native look and feel bbui & alicejs.toster
 
Drupal website in 45 mins
Drupal website in 45 minsDrupal website in 45 mins
Drupal website in 45 minsRachit Gupta
 

La actualidad más candente (11)

WPF - the future of GUI is near
WPF - the future of GUI is nearWPF - the future of GUI is near
WPF - the future of GUI is near
 
Intro to Web Components, Polymer & Vaadin Elements
Intro to Web Components, Polymer & Vaadin ElementsIntro to Web Components, Polymer & Vaadin Elements
Intro to Web Components, Polymer & Vaadin Elements
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
 
Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentation
 
Voyager: The Widget Router
Voyager: The Widget RouterVoyager: The Widget Router
Voyager: The Widget Router
 
TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08
 
Miha Lesjak Mobilizing The Web with Web Runtime
Miha Lesjak Mobilizing The Web with Web RuntimeMiha Lesjak Mobilizing The Web with Web Runtime
Miha Lesjak Mobilizing The Web with Web Runtime
 
04b swing tutorial
04b swing tutorial04b swing tutorial
04b swing tutorial
 
Native look and feel bbui & alicejs
Native look and feel bbui & alicejsNative look and feel bbui & alicejs
Native look and feel bbui & alicejs
 
iphonedevcon 2010: Cooking with iAd
iphonedevcon 2010:  Cooking with iAd iphonedevcon 2010:  Cooking with iAd
iphonedevcon 2010: Cooking with iAd
 
Drupal website in 45 mins
Drupal website in 45 minsDrupal website in 45 mins
Drupal website in 45 mins
 

Destacado

Destacado (6)

ValueLabs - inspired by Potential - Insurance
ValueLabs - inspired by Potential - InsuranceValueLabs - inspired by Potential - Insurance
ValueLabs - inspired by Potential - Insurance
 
Clase 9a: Obstruyentes sonoras -b d g-
Clase 9a: Obstruyentes sonoras  -b d g-Clase 9a: Obstruyentes sonoras  -b d g-
Clase 9a: Obstruyentes sonoras -b d g-
 
Libro de ingles 9no grado
Libro de ingles 9no gradoLibro de ingles 9no grado
Libro de ingles 9no grado
 
Ingles 9
Ingles 9Ingles 9
Ingles 9
 
English book 2 teacher 2015 - 2016
English book 2   teacher 2015 - 2016English book 2   teacher 2015 - 2016
English book 2 teacher 2015 - 2016
 
9a.-embajada de Ecuador
 9a.-embajada de Ecuador 9a.-embajada de Ecuador
9a.-embajada de Ecuador
 

Similar a GWT training session 2

GWT Training - Session 2/3
GWT Training - Session 2/3GWT Training - Session 2/3
GWT Training - Session 2/3Faiz Bashir
 
Creating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlCreating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlIlia Idakiev
 
Custom controls
Custom controlsCustom controls
Custom controlsaspnet123
 
Adding a view
Adding a viewAdding a view
Adding a viewNhan Do
 
Why NextCMS: Layout Editor
Why NextCMS: Layout EditorWhy NextCMS: Layout Editor
Why NextCMS: Layout EditorPhuoc Nguyen Huu
 
The battle between the states (all about flutter stateless & stateful widgets...
The battle between the states (all about flutter stateless & stateful widgets...The battle between the states (all about flutter stateless & stateful widgets...
The battle between the states (all about flutter stateless & stateful widgets...Katy Slemon
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web ToolkitsYiguang Hu
 
Drupal For Dummies
Drupal For DummiesDrupal For Dummies
Drupal For DummiesKoen Delvaux
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginMainak Goswami
 
Code Driven Development Zaporozhye DrupalForum
Code Driven Development Zaporozhye DrupalForumCode Driven Development Zaporozhye DrupalForum
Code Driven Development Zaporozhye DrupalForumYuriy Gerasimov
 
Asp.Net 2.0 Presentation
Asp.Net 2.0 PresentationAsp.Net 2.0 Presentation
Asp.Net 2.0 Presentationsasidhar
 
Creating, debugging and deploying extension packages for Microsoft Visual Stu...
Creating, debugging and deploying extension packages for Microsoft Visual Stu...Creating, debugging and deploying extension packages for Microsoft Visual Stu...
Creating, debugging and deploying extension packages for Microsoft Visual Stu...PVS-Studio
 
Web Components Everywhere
Web Components EverywhereWeb Components Everywhere
Web Components EverywhereIlia Idakiev
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerKaty Slemon
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010vchircu
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event HandlingWebStackAcademy
 

Similar a GWT training session 2 (20)

GWT Training - Session 2/3
GWT Training - Session 2/3GWT Training - Session 2/3
GWT Training - Session 2/3
 
Creating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlCreating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-html
 
Custom controls
Custom controlsCustom controls
Custom controls
 
Wave Workshop
Wave WorkshopWave Workshop
Wave Workshop
 
Adding a view
Adding a viewAdding a view
Adding a view
 
Why NextCMS: Layout Editor
Why NextCMS: Layout EditorWhy NextCMS: Layout Editor
Why NextCMS: Layout Editor
 
The battle between the states (all about flutter stateless & stateful widgets...
The battle between the states (all about flutter stateless & stateful widgets...The battle between the states (all about flutter stateless & stateful widgets...
The battle between the states (all about flutter stateless & stateful widgets...
 
Hats tutorial custom widget
Hats tutorial   custom widgetHats tutorial   custom widget
Hats tutorial custom widget
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
Drupal For Dummies
Drupal For DummiesDrupal For Dummies
Drupal For Dummies
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
 
Code Driven Development Zaporozhye DrupalForum
Code Driven Development Zaporozhye DrupalForumCode Driven Development Zaporozhye DrupalForum
Code Driven Development Zaporozhye DrupalForum
 
Asp.Net 2.0 Presentation
Asp.Net 2.0 PresentationAsp.Net 2.0 Presentation
Asp.Net 2.0 Presentation
 
Creating, debugging and deploying extension packages for Microsoft Visual Stu...
Creating, debugging and deploying extension packages for Microsoft Visual Stu...Creating, debugging and deploying extension packages for Microsoft Visual Stu...
Creating, debugging and deploying extension packages for Microsoft Visual Stu...
 
Web Components Everywhere
Web Components EverywhereWeb Components Everywhere
Web Components Everywhere
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue router
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
 

Último

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 

GWT training session 2

  • 1. GWT Training – Session II Client-Side Implementation Snehal Masne www.TechProceed.com
  • 2. Contents  The User Interface     Static widgets Form widgets Complex widgets Panels This are slides are based from the book “Google Web Toolkit Applications” by Ryan Desbury, 2008, Pearson Education www.TechProceed.com
  • 3. The User Interface    GWT contains classes for building dynamic re-usable components (called widgets) based upon web browser's user interface features The user interface framework is similar to Java AWT/Swing For the purpose of this tutorial, we divide the different types of widgets into four categories – Static widgets, form widgets, complex widgets and panels www.TechProceed.com
  • 4. The User Interface Groups www.TechProceed.com
  • 5. Static Widgets    They do not have any internal state or change dynamically on their own Can be part of a dynamic user interface in which the user interface code can change their properties and location at runtime, but not as a result of user actions Includes     Label HTML Image Hyperlink www.TechProceed.com
  • 6. The Entry-Point Class      Before we start building our user interface, we need to understand the EntryPoint Class Think of this class as the main class of your application with the java main() method that the JVM invokes first The Entry-Point class contains onModuleLoad() method which is the method that the GWT compiler calls first The class implements com.google.gwt.core.client.EntryPoint interface For the GWTTraining project, GWTTraining.java is the Entry-Point class (which is defined in the application's GWT configuration file)‫‏‬ import com.google.gwt.core.client.EntryPoint public class GWTTraining implements EntryPoint { public void onModuleLoad() { //your initial code goes here } } www.TechProceed.com
  • 7. Label          A widget that contains arbitrary text, not interpreted as HTML. This widget uses a <div> element, causing it to be displayed with block layout Open the GWTTraining project in Eclipse Create a new Entry Point class called GWTTrainingWidget under File > New. We would use this entry class for our widgets tutorial. In the GWTTraining.gwt.xml configuration file, delete the entry-point definition for my.utm.kase.gettraining.client.GWTTraining. We only want to display the GWTTrainingWidgets entrypoint when we run the applicaiton. Also edit the GWTTraining.html and delete the contents of the <body> tag so that we start from an empty page. Add the following import statements import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.RootPanel; Add the following code in the onModuleLoad() method Label label = new Label("Welcome to CASE, UTM"); RootPanel.get().add(label); The code creates a new label widget and adds it to the root panel A‫‏‬simple‫‏‬text‫“‏‬Welcome‫‏‬to‫‏‬CASE,‫‏‬UTM”‫‏‬is‫‏‬displayed‫‏‬when‫‏‬you‫‏‬run‫‏‬the‫‏‬application. www.TechProceed.com
  • 8. Label – Embellishing with CSS     A great feature of GWT is letting you to achieve great presentations using CSS GWT widgets have default CSS names that let you set their style The label widget CSS is .gwt-Label { } Add the following to the /war/GWTTraining.css to change the appearance of the label widget: .gwt-Label{ background-color:silver; color:green; text-align-center; border-style:groove; border-width:thick; border-color:navy; } www.TechProceed.com
  • 9. Label – Embellishing with CSS    If you use the default GWT CSS names for the widgets, all widgets of the same class are affected. To demonstrate this, let's create another label widget by adding the following code in the GWTTrainingWidgets.java file: Label label2 = new Label("Where Advanced Learning Begins"); RootPanel.get().add(label2); label2 also has the same appearance as the first label because it also inherits from .gwtLabel CSS name. www.TechProceed.com
  • 10. Label – Embellishing with CSS      We can apply a different style for a particular label instead of the general class definition To demonstrate that add the following custom CSS definition in GWTTraining.css .label2 { background-color:orange; border-style:ridge; border-width:thick; border-color:navy; } Add the following code to set the style to label2 (before adding it to the root panel: label2.setStylePrimaryName("label2"); When you refresh the browser you will see that label2 now has its own customized style. Styling with CSS is the same for all the other widgets in GWT. The default style names of the widgets can be found in the GWT API Java documentation. Info: CSS is a very powerful language that gives the web great look and feel. Because it is separated from the content (usually HTML), customizing the pages becomes very flexible. For further reading you may want to check: The Ultimate CSS reference www.TechProceed.com
  • 11. Customizing programatically  Some properties of the Label (and other widgets as well) can be customized programatically www.TechProceed.com
  • 12. HTML Widget      Used for rendering HTML Add the following codes to GWTTrainingWidgets.java RootPanel.get().add(new HTML("<hr/>")); //add a horizontal line break RootPanel.get().add(new HTML("<b>CASE in bold</>")); //add bold text RootPanel.get().add(new HTML("<a href='http://www.case.utm.my'>Find more about CASE</a>")); RootPanel.get().add(new HTML("<hr/>")); //add a horizontal line break Add import statement for com.google.gwt.user.client.ui.HTML Refresh the browser to view the changes The HTML widget can be customized using CSS just like the Label widget. The default CSS name is .gwt-HTML www.TechProceed.com
  • 13. The Image Widget     Accepts a URL pointing to an image file and renders it Create images folder: /war/gwttraining/images. Add case_logo.jpg to the folder which is provided in the training resources CD Add the following code: String url = GWT.getModuleBaseURL() + "images/case_logo.jpg"; Image image = new Image(url); RootPanel.get().add(image);  CSS default style name is .gwt-Image www.TechProceed.com
  • 14. The Image Widget   Add the following code to display image from an external server: RootPanel.get().add(new Image("http://www.case.utm.my/v2/images/intro_pic/case_intro_pic_1%20copy.g if")); The following output should be displayed when the browser is refreshed www.TechProceed.com
  • 15. The Form Widgets     Widgets typically used with HTML forms Unlike traditional HTML forms, data is submitted to the server asynchrnously without refreshing the page GET form widgets can be used in ways similar to desktop applications and not necessarily inside a HTML form The widgets include:  Button, CheckBox, RadioButton, ListBox, TextBox  PasswordTextBox, TextArea, FileUpload, Hiddein  ToggleButton, PushButton, SuggestBox and RichTextArea www.TechProceed.com
  • 16. The Button Widget       Wraps‫‏‬the‫‏‬HTML‫‏‬form‫‏‬input‫‏‬with‫‏‬the‫‏‬type‫‏‬button‫<(‏‬input‫‏‬type=”button”>)‫‏‬ Can be used to invoke any action in the application To see the Button widget in action add the following code: Button alertButton = new Button("Alert"); //create the button alertButton.addClickHandler( new ClickHandler() { //handle event @Override public void onClick(ClickEvent event) { //handle button event here Window.alert("Alert button clicked!"); } }); //add alertButton to root widget RootPanel.get().add(new HTML("<hr/>")); //add a horizontal line RootPanel.get().add(alertButton); //add button to root panel Just like other GWT widgets, the Button widget events are handled using the Observer pattern The observer (Event handler) observes the state of the subject (the user interface, e.g Button). When‫‏‬the‫‏‬subject’s‫‏‬state‫‏‬changes,‫‏‬the‫‏‬observer‫‏‬is‫‏‬notified. The default CSS name is .gwt-Button www.TechProceed.com
  • 17. ToggleButton and PushButton Widget    Both similar to Button widget When ToggleButton is clicked it remains in a 'pressed state' until clicked again A PushButton supports customization of its look based on its state //toggle and push buttons ToggleButton toggleButton = new ToggleButton("Toggle me"); PushButton pushButton = new PushButton("I'm a push button"); pushButton.setSize("150", "40"); RootPanel.get().add(toggleButton); RootPanel.get().add(pushButton);  You‫‏‬can‫‏‬set‫‏‬some‫‏‬widget‫‏‬properties‫“‏‬programmatically”‫‏‬without‫‏‬using‫‏‬CSS‫‏‬ definition just as is done above in setting the size of the PushButton. However using CSS is the most recommended because it separates the presentation from the Java code which improves flexibility and maintainability. www.TechProceed.com
  • 18. Button Widgets with Images    You may create buttons (Button, ToggleButton or PushButton) with images instead of text captions ToggleButton can be created with two images so that they can be represented in pressed and released states. ToggleButton imgToggleButton = new ToggleButton( new Image(GWT.getModuleBaseURL() + "images/h_toggle.jpg"), new Image(GWT.getModuleBaseURL() + "images/v_toggle.jpg")‫‏‬ ); imgToggleButton.setSize("60", "60"); RootPanel.get().add(new HTML("<hr/>")); //add a horizontal line RootPanel.get().add(imgToggleButton); //add imgToggleButton to //root panel Copy the h_toggle.jpg and v_toggle.jpg to /war/gwttraining/images Released State Pressed State www.TechProceed.com
  • 19. Styling Button States with Css   You can use CSS to generate different styles for ToggleButton and PushButton based on their states The default names for the states are shown in table below: www.TechProceed.com
  • 20. Checkbox Widget      Wraps‫‏‬HTML’s‫‏‬check‫‏‬box‫‏‬input‫‏‬tag‫<(‏‬input‫‏‬type=”button”>)‫‏‬ Has two states - Checked/Unchecked You can programmatically set the state with the setChecked method by passing true for checked or false for unchecked Supports focus behavior and click events Default CSS name is .gwt-Checkbox www.TechProceed.com
  • 21. Checkbox Widget - Code Sample //checkbox widget final CheckBox checkBox = new CheckBox("Do u love GWT?"); checkBox.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { //handle event if( checkBox.getValue() ) { Window.lert("Yeah, welcome to the world of GWT"); } else { Window.alert("Sorry, u are missing a lot. U gotta think again"); } } }); RootPanel.get().add(new HTML("<hr/>")); RootPanel.get().add(checkBox); //add a horizontal break line www.TechProceed.com
  • 22. RadioButton Widget  Usually belongs to a group of other RadioButtons so that only one selection can be made www.TechProceed.com
  • 23. RadioButton Widget – Sample Code //radio button widget final RadioButton redButton = new RadioButton("color", "red"); final RadioButton orangeButton = new RadioButton("color", "orange"); final RadioButton greenButton = new RadioButton("color", "green"); final Label label3 = new Label(""); label3.setSize("25", "25"); label3.setStylePrimaryName("label3"); ClickHandler radioButtonsHandler = new ClickHandler() { @Override public void onClick(ClickEvent event) { if( event.getSource() == redButton ) { label3.setStylePrimaryName("red"); } else if( event.getSource() == orangeButton ) { label3.setStylePrimaryName("orange"); } else { label3.setStylePrimaryName("green"); } } }; www.TechProceed.com
  • 24. RadioButton Widget – Sample Code (cont'd)‫‏‬ redButton.addClickHandler(radioButtonsHandler); orangeButton.addClickHandler(radioButtonsHandler); greenButton.addClickHandler(radioButtonsHandler); RootPanel.get().add(new HTML("<hr/>")); //add a horizontal break line //add to root panel RootPanel.get().add(label3); RootPanel.get().add(redButton); RootPanel.get().add(orangeButton); RootPanel.get().add(greenButton); CSS Stlye .label3 { border-style:groove; width: 25px; height: 25px; } .red { background-color:red; } .orange { background-color:orange; } .green { background-color:green; } www.TechProceed.com
  • 25. ListBox Widget   A group of options in a form of list in which only one option can be selected Two forms:   Normal list Drop down list www.TechProceed.com
  • 26. ListBox Widget – Sample Code final ListBox colorList = new ListBox(); colorList.addItem("Red"); colorList.addItem("Orange"); colorList.addItem("Green"); colorList.addChangeHandler( new ChangeHandler() { @Override public void onChange(ChangeEvent event) { if( colorList.getSelectedIndex() == 0 ) { label3.setStylePrimaryName("red"); redButton.setValue(true); } else if( colorList.getSelectedIndex() == 1 ) { label3.setStylePrimaryName("orange"); orangeButton.setValue(true); } else { label3.setStylePrimaryName("green"); greenButton.setValue(true); } } }); RootPanel.get().add(new HTML("<hr/>")); //add a horizontal break line RootPanel.get().add(colorList); www.TechProceed.com
  • 27. ListBox Sample Code – cont'd   The previous code displays the drop down format of the ListBox Use the following code to change to the normal format: //change the list box format colorList.setVisibleItemCount(3); www.TechProceed.com
  • 28. SuggestBox Widget      A text box with drop-down suggestions based on the word that you type Usually used when the list of items are too much to be displayed at a time E.g. Google Suggest Uses SuggestOracle instance to plug in dynamic results from datasource on the server MultiWordSuggestOracle can be used if the suggest list is generated at the client side www.TechProceed.com
  • 29. SuggestBox – Sample Code //SuggestBox String suggestString = "The Faculty of Computer Science and Information " + "Systems, UTM provides specialist teaching and conducts research " + "in fundamental and applied computer science, software " + "engineering, artificial intelligence and cognitive science. " + "We are proud to deliver outstanding undergraduate and " + "postgraduate education that offers varied and exciting " + "career opportunities around the world."; String words[] = suggestString.split(" "); MultiWordSuggestOracle suggestOracle = new MultiWordSuggestOracle(); suggestOracle.addAll(Arrays.asList(words)); SuggestBox suggestBox = new SuggestBox(suggestOracle); RootPanel.get().add(new HTML("<hr/>")); RootPanel.get().add(suggestBox); //add a horizontal break line CSS Styles .gwt-SuggestBox {} .gwt-SuggestBoxPopup { border: 2px solid #C3D9FF; background-color:#E8EEF7; } .gwt-SuggestBoxPopup .item { } .gwt-SuggestBoxPopup .item-selected { background-color:#C3D9FF;} www.TechProceed.com
  • 30. TextBox Widget  Encapsulates‫‏‬HTML’s‫‏‬input‫‏‬tag‫‏‬with‫‏‬type‫‏‬input‫<(‏‬input‫‏‬type=”input”>)  Typically used for capturing small text input from user //TextBox widget final TextBox emailBox = new TextBox(); emailBox.setText("<Enter your email>"); emailBox.setStylePrimaryName("emailBox-blank"); //add focus gain handler emailBox.addFocusHandler( new FocusHandler() { @Override public void onFocus(FocusEvent event) { String emailText = emailBox.getText(); if( emailText.equals("<Enter your email>")) { emailBox.setText(""); } emailBox.removeStyleName("emailBox-blank"); } }); www.TechProceed.com
  • 31. TextBox Widget – cont'd //add focus lost handler emailBox.addFocusListener(new FocusListenerAdapter() { public void onLostFocus(Widget sender) { String emailText = emailBox.getText(); if( emailText.equals("")) { emailBox.setStylePrimaryName("emailBox-blank"); emailBox.setText("<Enter your email>"); } } }); RootPanel.get().add(new HTML("<hr/>")); RootPanel.get().add(emailBox); //add a horizontal break line www.TechProceed.com
  • 32. PasswordTextBox Widget  Similar to TextBox but its contents are hidden to protect sensitive data //PasswordTextBox widget PasswordTextBox passwordBox = new PasswordTextBox(); RootPanel.get().add(new HTML("<hr/>")); RootPanel.get().add(passwordBox); www.TechProceed.com
  • 33. TextArea Widget  Similar to TextBox but contents can span multiple pages //TextArea widget TextArea textArea = new TextArea(); textArea.setCharacterWidth(80); textArea.setVisibleLines(10); RootPanel.get().add(new HTML("<hr/>")); RootPanel.get().add( textArea ); www.TechProceed.com
  • 34. FileUpload Widget   Encapsulates‫‏‬HTML’s‫‏‬input‫‏‬tag‫‏‬with‫‏‬its‫‏‬type‫‏‬ attribute set to file (<input type='file'>)‫‏‬ Allows users to select a file from their local file system, usually to be uploaded to the server //FileUpload widget FileUpload fileUpload = new FileUpload(); RootPanel.get().add(new HTML("<hr/>")); RootPanel.get().add( fileUpload ); www.TechProceed.com
  • 35. Hidden Widget   Encapsulates‫‏‬HTML’s‫‏‬input‫‏‬tag‫‏‬of‫‏‬type‫‏‬ hidden (<input type='hidden'>)‫‏‬ It is used with the FormPanel to submit a form asynchronously to the server. www.TechProceed.com
  • 36. Complex Widgets       User interface widgets in web pages that do not have HTML tag equivalents. They are created by compositing HTML tags together and handling user events through JavaScript to emulate more sophisticated widgets. GWT has some complex widgets in its library Advanced custom widgets can also be built with GWT www.TechProceed.com
  • 37. Tree Widget    Displays a hierarchical view of data that can be expanded and collapsed similar to tree widgets in desktop applications typically You can add simple text or widgets as children of the tree The TreeItem widget can be used to achieve several levels of hierarchy www.TechProceed.com
  • 38. TreeWidget – Sample Code //Tree Widget Tree rootTree = new Tree(); TreeItem treeItem1 = new TreeItem("Contact 1"); treeItem1.addItem(new Image(GWT.getModuleBaseURL() + "images/contact.jpg")); treeItem1.addItem(new Image(GWT.getModuleBaseURL() + "images/mail.jpeg")); TreeItem treeItem2 = new TreeItem("Contact 2"); treeItem2.addItem(new Image("images/contact.jpg")); treeItem2.addItem(new Image("images/mail.jpeg")); rootTree.addItem(treeItem1); rootTree.addItem(treeItem2); RootPanel.get().add(new HTML("<hr/>")); RootPanel.get().add( rootTree ); CSS Style Rules .gwt-Tree {} .gwt-Tree .gwt-TreeItem {} .gwt-Tree .gwt-TreeItem-selected {} www.TechProceed.com
  • 39. MenuBar Widget   Similar to menu bars on desktop applications Displays list of menus to be selected //MenuBar widget MenuBar lecturerMenu = new MenuBar(true); //orient vertically lecturerMenu.addItem("Save Records" , new Command() { public void execute() { Window.alert("Saved"); } }); MenuBar studentMenu = new MenuBar(true); //orient vertically studentMenu.addItem("Register" , new Command() { public void execute() { //add register event } }); www.TechProceed.com
  • 40. MenuBar Widget – cont'd studentMenu.addItem("View Records" , new Command() { public void execute() { //view records event } }); MenuBar menu = new MenuBar(); menu.addItem("Lecturer", lecturerMenu); menu.addItem("Student", studentMenu); RootPanel.get().add(menu, 0, 0); www.TechProceed.com
  • 41. MenuBar Widget – CSS Styles .gwt-MenuBar { background-color:#F3F5F6; border: 1px; } .gwt-MenuBar .gwt-MenuItem { font-size: 9pt; cursor:hand; cursor:pointer; padding:2px 5px 2px 5px; margin:0px; } .gwt-MenuBar .gwt-MenuItem-selected { background-color:#316AC5; color:white; } www.TechProceed.com
  • 42. Simple Layout Panels    Panels are used to organize the layout of the various widgets we have covered so far. GWT has several layout widgets that provide this functionality The simple Layout Panels include:    FlowPanel VerticalPanel HorizontalPanel www.TechProceed.com
  • 43. FlowPanel   It functions like the HTML layout Child widgets of the FlowPanel are displayed horizontally and then wrapped to the next row down when there is not enough horizontal room left //FlowPanel FlowPanel flowPanel = new FlowPanel(); for( int i = 1; i <= 20; i++ ) { flowPanel.add(new Button("Button " + String.valueOf(i))); } RootPanel.get().add(flowPanel); www.TechProceed.com
  • 44. FlowPanel – cont'd   If you run the code and resize the browser window smaller, you will see that the child widgets (buttons) are displaced to the next row when the space becomes insufficient to display in one row The result is opposite if you resize the window bigger www.TechProceed.com
  • 45. HorizontalPanel and VerticalPanel   HorizontalPanel is similar to FlowPanel but uses scrollbar to display its widgets if there is no enough room instead of displacing to the next row VerticalPanel organizes its child widgets in a vertical orientation www.TechProceed.com
  • 46. HorizontalSplitPanel and VerticalSplitPanel  They are divided into two panels that be resized www.TechProceed.com
  • 47. FlexTable and Grid Widgets     Encapsulates HTML's table tag (<table />)‫‏‬ They display child widgets in a grid spanning vertically and horizontally. The Grid widget enforces an explicitly set number of rows and cells for each row. The FlexTable is more flexible, allowing cells to be added as needed, rows to have a variable number of cells, and cells to span multiple rows or columns www.TechProceed.com
  • 48. FlexTable and Grid Widgets – cont'd //Grid Grid grid = new Grid(3,3); for( int i = 0; i < 3; i++) { for( int j = 0; j < 3; j++ ) { grid.setWidget(i,j,new Image(GWT.getModuleBaseURL() + "images/tree2.jpg")); } } //FlexTable FlexTable flexTable = new FlexTable(); flexTable.setWidget(0,0, new HTML("Flex Table Widget")); flexTable.getFlexCellFormatter().setColSpan(0, 0, 4); for( int i = 0; i < 4; i++ ) { flexTable.setWidget(1, i, new Image(GWT.getModuleBaseURL() + "images/tree.jpeg")); } www.TechProceed.com
  • 49. FlexTable and Grid Widgets – cont'd flexTable.setWidget(2,0, new Image(GWT.getModuleBaseURL() + "images/tree2.jpg")); flexTable.setWidget(2,1, new Image(GWT.getModuleBaseURL() + "images/tree2.jpg")); flexTable.getFlexCellFormatter().setColSpan(2, 0, 2); flexTable.getFlexCellFormatter().setColSpan(2, 1, 2); flexTable.setWidget(3, 0, new Image(GWT.getModuleBaseURL() + "images/tree_big.png")); flexTable.getFlexCellFormatter().setColSpan(3, 0, 4); HorizontalSplitPanel hSplitPanel = new HorizontalSplitPanel(); hSplitPanel.setLeftWidget(flexTable); hSplitPanel.setRightWidget(grid); RootPanel.get().add(hSplitPanel); www.TechProceed.com
  • 50. Customizing the Widgets HorizontalSplitPanel hSplitPanel = new HorizontalSplitPanel(); hSplitPanel.setLeftWidget(flexTable); hSplitPanel.setRightWidget(grid); RootPanel.get().add(hSplitPanel); //vertical panel 2 VerticalPanel vPanel2 = new VerticalPanel(); vPanel2.add(rootTree); vPanel2.add(flowPanel); RootPanel.get().add(vPanel2); www.TechProceed.com
  • 51. Customizing the Widgets – cont'd //vertical panel 3 HorizontalPanel hPanel2 = new HorizontalPanel(); hPanel2.add(checkBox); hPanel2.add(label3); hPanel2.add(redButton); hPanel2.add(orangeButton); hPanel2.add(greenButton); hPanel2.add(colorList); VerticalPanel vPanel4 = new VerticalPanel(); vPanel4.add(textArea); vPanel4.add(fileUpload); RootPanel.get().add(vPanel4); www.TechProceed.com
  • 52. TabPanel  Displays just one of its child widgets at a time and provides controls to select the child to display //TabPanel TabPanel tabPanel = new TabPanel(); tabPanel.add(vPanel2, "Buttons"); tabPanel.add(hPanel2, "Options"); tabPanel.add(vPanel4, "Text"); tabPanel.setSize("100%", "100%"); RootPanel.get().add(tabPanel); www.TechProceed.com
  • 54. This brings us to the end of the 2nd session of the GWT Training. In the next session we would learn how to establish communication between the client and server. Thank you www.TechProceed.com