summaryrefslogtreecommitdiffstats
path: root/java/vaadin/src/main/java/ch/asynk/HelloWorldUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/vaadin/src/main/java/ch/asynk/HelloWorldUI.java')
-rw-r--r--java/vaadin/src/main/java/ch/asynk/HelloWorldUI.java130
1 files changed, 105 insertions, 25 deletions
diff --git a/java/vaadin/src/main/java/ch/asynk/HelloWorldUI.java b/java/vaadin/src/main/java/ch/asynk/HelloWorldUI.java
index f4579be..be65387 100644
--- a/java/vaadin/src/main/java/ch/asynk/HelloWorldUI.java
+++ b/java/vaadin/src/main/java/ch/asynk/HelloWorldUI.java
@@ -3,50 +3,130 @@ package ch.asynk;
import com.vaadin.annotations.PreserveOnRefresh;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
+import com.vaadin.navigator.Navigator;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Button;
-import com.vaadin.ui.Button.ClickEvent;
-import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.CustomLayout;
+import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
+import com.vaadin.ui.MenuBar;
+import com.vaadin.ui.MenuBar.Command;
+import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.Notification;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import ch.asynk.ui.Icons;
+import ch.asynk.ui.ViewMain;
@PreserveOnRefresh
-@Title("Hello!!")
@Theme("mytheme")
+@Title("Hello!!")
public class HelloWorldUI extends UI
{
- private static final long serialVersionUID = 511085335415683713L;
- private static Logger logger = null;
+ private static final long serialVersionUID = 1L;
+
+ private static final String HOME = "Home";
+ private static final String ABOUT = "About";
+
+ private Navigator navigator;
@Override
protected void init(VaadinRequest request)
{
- logger = LoggerFactory.getLogger(this.getClass());
- VerticalLayout content = new VerticalLayout();
- setContent(content);
-
- content.addComponent(new Label("Hello World using mytheme"));
- Button btn = new Button("Push Me!", new ThemeResource("icons/home.png"));
- btn.addClickListener(new ClickListener() {
- private static final long serialVersionUID = 5808429544582385114L;
+ final VerticalLayout vl = new VerticalLayout();
+ vl.setSizeFull();
+ vl.setMargin(true);
+ setContent(vl);
+
+ final MenuBar menu = createMenuBar();
+
+ final HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
+ hsplit.setSplitPosition(80f);
+ hsplit.addComponent(createLeftPanel());
+ hsplit.addComponent(createRightPanel());
+
+ vl.addComponents(menu, hsplit);
+ vl.setExpandRatio(menu, 0);
+ vl.setExpandRatio(hsplit, 1);
+
+ navigateToHome();
+ }
+
+ private Component createLeftPanel()
+ {
+ final VerticalLayout vl = new VerticalLayout();
+ vl.addStyleName("margin-top");
+ vl.addStyleName("margin-right");
+ navigator = new Navigator(this, vl);
+ navigator.addView(HOME, ViewMain.class);
+ return vl;
+ }
+
+ private Component createRightPanel()
+ {
+ final VerticalLayout vl = new VerticalLayout();
+ vl.setMargin(true);
+ vl.addStyleName("mybg");
+ // vl.addStyleName("margin-top");
+ // vl.addStyleName("margin-right");
+ vl.addComponent(new Label("Hello World using mytheme"));
+ Button btn = new Button("Push Me!", Icons.home);
+ btn.addClickListener(new Button.ClickListener() {
+ private static final long serialVersionUID = 1L;
@Override
- public void buttonClick(ClickEvent event) {
+ public void buttonClick(Button.ClickEvent event) {
Notification.show("Pushed!");
- System.out.println("System.out");
- System.err.println("System.err");
- logger.trace("trace");
- logger.debug("debug");
- logger.info("info");
- logger.warn("warn");
- logger.error("error");
+ Daddy.trace("trace");
+ Daddy.debug("debug");
+ Daddy.info("info");
+ Daddy.warn("warn");
+ Daddy.error("error");
}
});
- content.addComponent(btn);
+ vl.addComponent(btn);
+ return vl;
+ }
+
+ private MenuBar createMenuBar()
+ {
+ Command menuCommand = new Command() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ public void menuSelected(MenuItem selectedItem) {
+ String itemText = selectedItem.getText();
+ if (itemText.equals(HOME)) {
+ navigateToHome();
+ } else if (itemText.equals(ABOUT)) {
+ showAbout();
+ } else {
+ Daddy.error("unhandeled MenuItem : " + itemText);
+ }
+ }
+ };
+
+ final MenuBar menu = new MenuBar();
+ menu.addItem(HOME, Icons.home, menuCommand);
+ menu.addItem(ABOUT, Icons.help, menuCommand);
+ MenuBar.MenuItem login = menu.addItem((String) UI.getCurrent().getSession().getAttribute(Daddy.SESSION_STATUS), menuCommand);
+ login.setStyleName("menuRight");
+ menu.setWidth("100%");
+
+ return menu;
+ }
+
+ public void navigateToHome() { navigator.navigateTo(HOME); }
+
+ private void showAbout()
+ {
+ final Window about = new Window(ABOUT);
+ about.setContent( new CustomLayout(ABOUT) );
+ about.setHeight("50%");
+ about.setWidth("600px");
+ about.center();
+ about.setModal(true);
+ UI.getCurrent().addWindow(about);
}
}