Chapter 3 v17 - (21 Steps)


Chapter 2
Chapter 3

File 1:

(AddressBookApplication.java)


File 2:

(HelpWindow.java)


File 3:

(ListView.java)


File 4:

(NavigationTree.java)


File 5:

(PersonForm.java)


File 6:

(PersonList.java)


File 7:

(SharingOptions.java)


1 - STEPS


Step 1:

(AddressBookApplication.java)


[color=#0000ff]
@Override
public void init() {
[/color]
    [color=#ff00ee]
buildMainLayout();
[/color]
[color=#0000ff]
}
[/color]

[color=#ff00ee]
private void buildMainLayout() {
[/color]
   [color=#0000ff]
 setMainWindow(new Window("Address Book Demo application"));
[/color]
[color=#ff00f6]
}
[/color]

Step 2:

(AddressBookApplication.java)


[color=#0000ff]
public class AddressBookApplication extends Application {  
[/color][color=#ff00f6]


    private Button newContact = new Button("Add contact");
    private Button search = new Button("Search");
    private Button share = new Button("Share");
    private Button help = new Button("Help");
    private SplitPanel horizontalSplit = new SplitPanel(
            SplitPanel.ORIENTATION_HORIZONTAL); 
[/color]
[color=#0000ff]

    @Override
    public void init() {
[/color]

Step 3:

(AddressBookApplication.java)


     [color=#0000ff]
private void buildMainLayout() {
        setMainWindow(new Window("Address Book Demo application"));
[/color]
[color=#ff00f6]

        VerticalLayout layout = new VerticalLayout();
        layout.setSizeFull();

        layout.addComponent(createToolbar());
        layout.addComponent(horizontalSplit);
        layout.setExpandRatio(horizontalSplit, 1);

        horizontalSplit.setSplitPosition(200, SplitPanel.UNITS_PIXELS);
        horizontalSplit.setFirstComponent(tree);

        getMainWindow().setContent(layout);
[/color]
   [color=#0000ff]
 }
[/color][color=#ff00f6]


    private HorizontalLayout createToolbar() {
        HorizontalLayout lo = new HorizontalLayout();
        lo.addComponent(newContact);
        lo.addComponent(search);
        lo.addComponent(share);
        lo.addComponent(help);

        return lo;
[/color]
[color=#0000ff]
}
[/color]

Step 4:

(NavigationTree.java)

[color=#ff00f6]

package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.Tree;

public class NavigationTree extends Tree {
     public static final Object SHOW_ALL = "Show all";
     public static final Object SEARCH = "Search";

    public NavigationTree() {
             addItem(SHOW_ALL);
             addItem(SEARCH);
     }
 }

[/color]

Step 5:

(AddressBookApplication.java)

[color=#ff00f6]

[color=#0000ff]
public class AddressBookApplication extends Application {
[/color]

    [color=#ff00f6]
private NavigationTree tree = new NavigationTree();
[/color]

[color=#0000ff]
    private Button newContact = new Button("Add contact");
    private Button search = new Button("Search");
    private Button share = new Button("Share");
    private Button help = new Button("Help");
    private SplitPanel horizontalSplit = new SplitPanel(
            SplitPanel.ORIENTATION_HORIZONTAL); 

    @Override
[/color]

[/color]

Step 6:

(AddressBookApplication.java)

[color=#ff00f6]

[color=#0000ff]
    private HorizontalLayout createToolbar() {
        HorizontalLayout lo = new HorizontalLayout();
        lo.addComponent(newContact);
        lo.addComponent(search);
        lo.addComponent(share);
        lo.addComponent(help);

        return lo;
    }
[/color]

[color=#ff00f6]
    private void setMainComponent(Component c) {
        horizontalSplit.setSecondComponent(c);
    }
[/color]

[color=#0000ff]
}
[/color]

[/color]

Step 7:

(ListView.java)

[color=#ff00f6]

package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.SplitPanel;

public class ListView extends SplitPanel {
     public ListView() {
     }
 }

[/color]

Step 8:

(AddressBookApplication.java)

[color=#ff00f6]

[color=#0000ff]
public class AddressBookApplication extends Application {

    private NavigationTree tree = new NavigationTree();

    private Button newContact = new Button("Add contact");
    private Button search = new Button("Search");
    private Button share = new Button("Share");
    private Button help = new Button("Help");
    private SplitPanel horizontalSplit = new SplitPanel(
            SplitPanel.ORIENTATION_HORIZONTAL); 
[/color]

[color=#ff00f6]
    private ListView listView = null;
[/color]

[color=#0000ff]
    @Override
[/color]

[/color]

Step 9:

(AddressBookApplication.java)


[color=#0000ff]
    private void setMainComponent(Component c) {
        horizontalSplit.setSecondComponent(c);
    }
[/color]
[color=#ff00f6]
 
    private ListView getListView() {
        if (listView == null) {
            listView = new ListView(personList, personForm);
        }
        return listView;
    }
[/color]
[color=#0000ff]
}
[/color]

Step 10:

(AddressBookApplication.java)


[color=#0000ff]
@Override
public void init() {
    buildMainLayout();
[/color]
    [color=#ff00f6]
setMainComponent(getListView());
[/color]
[color=#0000ff]
}

private void buildMainLayout() {
    setMainWindow(new Window("Address Book Demo application"));
[/color]

Step 11:

(PersonList.java)

[color=#ff00f6]

package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.Table;

public class PersonList extends Table {
     public PersonList() {
         // create some dummy data
         addContainerProperty("First Name", String.class, "Mark");
         addContainerProperty("Last Name", String.class, "Smith");
         addItem();
         addItem();
         setSizeFull();
     }
 }

[/color]

Step 12:

(PersonForm.java)

[color=#ff00f6]

package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.Button;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.TextField;

public class PersonForm extends Form {

    private Button save = new Button("Save");
    private Button cancel = new Button("Cancel");

    public PersonForm() {
         addField("First Name", new TextField("First Name"));
         addField("Last Name", new TextField("Last Name"));
         HorizontalLayout footer = new HorizontalLayout();
         footer.setSpacing(true);
         footer.addComponent(save);
         footer.addComponent(cancel);
         setFooter(footer);
     }
}

[/color]

Step 13:

(AddressBookApplication.java)

[color=#0000ff]

public class AddressBookApplication extends Application {

    private NavigationTree tree = new NavigationTree();

    private Button newContact = new Button("Add contact");
    private Button search = new Button("Search");
    private Button share = new Button("Share");
    private Button help = new Button("Help");
    private SplitPanel horizontalSplit = new SplitPanel(
            SplitPanel.ORIENTATION_HORIZONTAL); 

    private ListView listView = null;
[/color]
[color=#ff00f6]
    private PersonList personList = null;
    private PersonForm personForm = null;
[/color]

   [color=#0000ff]
 @Override
[/color]

Step 14:

(AddressBookApplication.java)

 [color=#0000ff]
private ListView getListView() {
     if (listView == null) {
[/color]
         [color=#ff00f6]
personList = new PersonList();
         personForm = new PersonForm();
[/color]
         [color=#0000ff]
listView = new ListView(personList, personForm);
     }
     return listView;
 }
[/color]

Step 15:

(ListView.java)


[color=#0000ff]
package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.SplitPanel;

public class ListView extends SplitPanel {
     public ListView(
[/color][color=#ff00f6]
PersonList personList, PersonForm personForm
[/color][color=#0000ff]
) {
[/color]
         [color=#ff00f6]
setFirstComponent(personList);
         setSecondComponent(personForm);
         setSplitPosition(40);
[/color]
     [color=#0000ff]
}
 }
[/color]

Step 16:

(HelpWindow.java)

[color=#ff00f6]

package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

public class HelpWindow extends Window {
     private static final String HELP_HTML_SNIPPET = "This is "
             + "an application built during <strong><a href=\""
             + "http://dev.vaadin.com/\">Vaadin</a></strong> "
             + "tutorial. Hopefully it doesn't need any real help.";

    public HelpWindow() {
         setCaption("Address Book help");
         addComponent(new Label(HELP_HTML_SNIPPET, Label.CONTENT_XHTML));
     }

}

[/color]

Step 17:

(SharingOptions.java)


[color=#ff00f6]
package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

public class SharingOptions extends Window {
     public SharingOptions() {
         setModal(true);
         setWidth("50%");
         center();

         setCaption("Sharing options");
         addComponent(new Label(
                 "With these setting you can modify contact sharing "
                         + "options. (non-functional, example of modal dialog)"));
         addComponent(new CheckBox("Gmail"));
         addComponent(new CheckBox(".Mac"));
         Button close = new Button("OK");
         addComponent(close);
     }
 }

[/color]

Step 18:

(AddressBookApplication.java)


[color=#0000ff]
@Override
public void init() {
    buildMainLayout();
    setMainComponent(getListView());
[/color]
[color=#ff00f6]
    // getMainWindow().addWindow(getHelpWindow());
[/color]
[color=#0000ff]
}

private void buildMainLayout() {
    setMainWindow(new Window("Address Book Demo application"));
[/color]

Step 19:

(AddressBookApplication.java)


[color=#0000ff]
public class AddressBookApplication extends Application {

    private NavigationTree tree = new NavigationTree();

    private Button newContact = new Button("Add contact");
    private Button search = new Button("Search");
    private Button share = new Button("Share");
    private Button help = new Button("Help");
    private SplitPanel horizontalSplit = new SplitPanel(
            SplitPanel.ORIENTATION_HORIZONTAL);

    // Lazyly created ui references
    private ListView listView = null;
    private PersonList personList = null;
    private PersonForm personForm = null;
[/color]
[color=#ff00f6]
    private HelpWindow helpWindow = null;
    private SharingOptions sharingOptions = null;
[/color]

[color=#0000ff]
    @Override
    public void init() {
        buildMainLayout();
        setMainComponent(getListView());
[/color]

Step 20:

(AddressBookApplication.java)


[color=#0000ff]
    private ListView getListView() {
        if (listView == null) {
            personList = new PersonList();
            personForm = new PersonForm();
            listView = new ListView(personList, personForm);
        }
        return listView;
    }
[/color]

[color=#ff00f6]
    private HelpWindow getHelpWindow() {
        if (helpWindow == null) {
            helpWindow = new HelpWindow();
        }
        return helpWindow;
    }

    private SharingOptions getSharingOptions() {
        if (sharingOptions == null) {
            sharingOptions = new SharingOptions();
        }
        return sharingOptions;
    }
[/color]
[color=#0000ff]
}
[/color]

Step 21:

(AddressBookApplication.java)


[color=#0000ff]
package com.vaadin.demo.tutorial.addressbook;

import com.vaadin.Application;
[/color]
[color=#ff00f6]
import com.vaadin.demo.tutorial.addressbook.ui.HelpWindow;
import com.vaadin.demo.tutorial.addressbook.ui.ListView;
import com.vaadin.demo.tutorial.addressbook.ui.NavigationTree;
import com.vaadin.demo.tutorial.addressbook.ui.PersonForm;
import com.vaadin.demo.tutorial.addressbook.ui.PersonList;
import com.vaadin.demo.tutorial.addressbook.ui.SharingOptions;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.SplitPanel;
import com.vaadin.ui.VerticalLayout;
[/color]
[color=#0000ff]
import com.vaadin.ui.Window;
[/color]

[color=#0000ff]
public class AddressBookApplication extends Application {
[/color]


2 - FINALS


File 1:

(AddressBookApplication.java)


Final:

(AddressBookApplication.java)


package com.vaadin.demo.tutorial.addressbook;

import com.vaadin.Application;
import com.vaadin.demo.tutorial.addressbook.ui.HelpWindow;
import com.vaadin.demo.tutorial.addressbook.ui.ListView;
import com.vaadin.demo.tutorial.addressbook.ui.NavigationTree;
import com.vaadin.demo.tutorial.addressbook.ui.PersonForm;
import com.vaadin.demo.tutorial.addressbook.ui.PersonList;
import com.vaadin.demo.tutorial.addressbook.ui.SharingOptions;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.SplitPanel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class AddressBookApplication extends Application {

    private NavigationTree tree = new NavigationTree();

    private Button newContact = new Button("Add contact");
    private Button search = new Button("Search");
    private Button share = new Button("Share");
    private Button help = new Button("Help");
    private SplitPanel horizontalSplit = new SplitPanel(
            SplitPanel.ORIENTATION_HORIZONTAL);

    // Lazyly created ui references
    private ListView listView = null;
    private PersonList personList = null;
    private PersonForm personForm = null;
    private HelpWindow helpWindow = null;
    private SharingOptions sharingOptions = null;

    @Override
    public void init() {
        buildMainLayout();
        setMainComponent(getListView());

        // uncomment following lines to test other views and windows
        // getMainWindow().addWindow(getHelpWindow());
        // getMainWindow().addWindow(getSharingOptions());
    }

    private void buildMainLayout() {
        setMainWindow(new Window("Address Book Demo application"));

        VerticalLayout layout = new VerticalLayout();
        layout.setSizeFull();

        layout.addComponent(createToolbar());
        layout.addComponent(horizontalSplit);
        layout.setExpandRatio(horizontalSplit, 1);

        horizontalSplit.setSplitPosition(200, SplitPanel.UNITS_PIXELS);
        horizontalSplit.setFirstComponent(tree);

        getMainWindow().setContent(layout);
    }

    private HorizontalLayout createToolbar() {
        HorizontalLayout lo = new HorizontalLayout();
        lo.addComponent(newContact);
        lo.addComponent(search);
        lo.addComponent(share);
        lo.addComponent(help);

        return lo;
    }

    private void setMainComponent(Component c) {
        horizontalSplit.setSecondComponent(c);
    }

    /*
     * View getters exist so we can lazily generate the views, resulting in
     * faster application startup time.
     */
    private ListView getListView() {
        if (listView == null) {
            personList = new PersonList();
            personForm = new PersonForm();
            listView = new ListView(personList, personForm);
        }
        return listView;
    }

    private HelpWindow getHelpWindow() {
        if (helpWindow == null) {
            helpWindow = new HelpWindow();
        }
        return helpWindow;
    }

    private SharingOptions getSharingOptions() {
        if (sharingOptions == null) {
            sharingOptions = new SharingOptions();
        }
        return sharingOptions;
    }
}

File 2:

(HelpWindow.java)


FINAL:

(HelpWindow.java)


package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

public class HelpWindow extends Window {
     private static final String HELP_HTML_SNIPPET = "This is "
             + "an application built during <strong><a href=\""
             + "http://dev.vaadin.com/\">Vaadin</a></strong> "
             + "tutorial. Hopefully it doesn't need any real help.";

    public HelpWindow() {
         setCaption("Address Book help");
         addComponent(new Label(HELP_HTML_SNIPPET, Label.CONTENT_XHTML));
     }

}

File 3:

(ListView.java)


Final:

(ListView.java)


package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.SplitPanel;

public class ListView extends SplitPanel {
    public ListView(PersonList personList, PersonForm personForm) {
        addStyleName("view");
        setFirstComponent(personList);
        setSecondComponent(personForm);
        setSplitPosition(40);
    }
}

File 4:

(NavigationTree.java)


Final:

(NavigationTree.java)


package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.Tree;

public class NavigationTree extends Tree {
    public static final Object SHOW_ALL = "Show all";
    public static final Object SEARCH = "Search";

    public NavigationTree() {
        addItem(SHOW_ALL);
        addItem(SEARCH);
    }
}

File 5:

(PersonForm.java)


Final:

(PersonForm.java)


package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.Button;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.TextField;

public class PersonForm extends Form {

    private Button save = new Button("Save");
    private Button cancel = new Button("Cancel");

    public PersonForm() {
        addField("First Name", new TextField("First Name"));
        addField("Last Name", new TextField("Last Name"));
        HorizontalLayout footer = new HorizontalLayout();
        footer.setSpacing(true);
        footer.addComponent(save);
        footer.addComponent(cancel);
        setFooter(footer);
    }

}

File 6:

(PersonList.java)


Final:

(PersonList.java)


package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.Table;

public class PersonList extends Table {
    public PersonList() {
        // create some dummy data
        addContainerProperty("First Name", String.class, "Mark");
        addContainerProperty("Last Name", String.class, "Smith");
        addItem();
        addItem();
        setSizeFull();
    }
}

File 7:

(SharingOptions.java)


Final:

(SharingOptions.java)


package com.vaadin.demo.tutorial.addressbook.ui;

import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

public class SharingOptions extends Window {
    public SharingOptions() {
        /*
         * Make the window modal, which will disable all other components while
         * it is visible
         */
        setModal(true);

        /* Make the sub window 50% the size of the browser window */
        setWidth("50%");
        /*
         * Center the window both horizontally and vertically in the browser
         * window
         */
        center();

        setCaption("Sharing options");
        addComponent(new Label(
                "With these setting you can modify contact sharing "
                        + "options. (non-functional, example of modal dialog)"));
        addComponent(new CheckBox("Gmail"));
        addComponent(new CheckBox(".Mac"));
        Button close = new Button("OK");
        addComponent(close);
    }
}


3 - INICIALS


File 1:

(AddressBookApplication.java)


Inicio:

[color=#0022ff]

package com.vaadin.demo.tutorial.addressbook;

import com.vaadin.Application;
[color=#ff0000]
import com.vaadin.ui.Label;
[/color]
import com.vaadin.ui.Window;

public class AddressBookApplication extends Application {

	@Override
	public void init() {
		setMainWindow(new Window("Address Book"));
		[color=#ff0000]
getMainWindow().addComponent(new Label("Hello World"));
[/color]
	}

}

[/color]

File 2:

(HelpWindow.java)


Inicio:

[color=#0022ff]

NUEVO
[/color]

File 3:

(ListView.java)


Inicio:

[color=#0022ff]

NUEVO
[/color]

File 4:

(NavigationTree.java)


Inicio:

[color=#0022ff]

NUEVO
[/color]

File 5:

(PersonForm.java)


Inicio:

[color=#0022ff]

NUEVO
[/color]

File 6:

(PersonList.java)


Inicio:

[color=#0022ff]

NUEVO
[/color]

File 7:

(SharingOptions.java)


Inicio:

[color=#0022ff]

NUEVO
[/color]