diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-10-06 10:45:37 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-10-06 10:45:37 +0200 |
commit | 94d89be45dfe30a4c9432aa7b5649757f8f2a663 (patch) | |
tree | d2195e98bafc310a2a038aa6451a75ae521cb739 /vaadin-app/src | |
parent | 500d88f0b33ccdec130e2676bdd6e82cf385841a (diff) | |
download | skeletons-94d89be45dfe30a4c9432aa7b5649757f8f2a663.zip skeletons-94d89be45dfe30a4c9432aa7b5649757f8f2a663.tar.gz |
vaadin-app: use Context class
Diffstat (limited to 'vaadin-app/src')
5 files changed, 40 insertions, 71 deletions
diff --git a/vaadin-app/src/ch/asynk/helloworld/DataMappingLayout.java b/vaadin-app/src/ch/asynk/helloworld/DataMappingLayout.java index 301d1aa..70d3b0e 100644 --- a/vaadin-app/src/ch/asynk/helloworld/DataMappingLayout.java +++ b/vaadin-app/src/ch/asynk/helloworld/DataMappingLayout.java @@ -13,10 +13,13 @@ import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.TextField; public class DataMappingLayout extends FormLayout { - + // private static final long serialVersionUID = 1L; + // + private Context ctx = null; - public DataMappingLayout() { + public DataMappingLayout(Context context) { + ctx = context; // final TextField tf1 = new TextField("Property.ValueChangeListener"); tf1.setImmediate(true); @@ -135,7 +138,7 @@ public class DataMappingLayout extends FormLayout { nextButton.addListener( new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { - getApplication().getMainWindow().setContent( new LayoutLayout() ); + getApplication().getMainWindow().setContent( new LayoutLayout(ctx) ); } }); } diff --git a/vaadin-app/src/ch/asynk/helloworld/EndLayout.java b/vaadin-app/src/ch/asynk/helloworld/EndLayout.java index d8375be..2b5c15f 100644 --- a/vaadin-app/src/ch/asynk/helloworld/EndLayout.java +++ b/vaadin-app/src/ch/asynk/helloworld/EndLayout.java @@ -6,10 +6,13 @@ import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; public class EndLayout extends VerticalLayout { - + // private static final long serialVersionUID = 1L; + // + private Context ctx = null; - public EndLayout() { + public EndLayout(Context context) { + ctx = context; // final Label lb1 = new Label(); lb1.setCaption("That's all folks"); diff --git a/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java b/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java index d9cfaa1..d5e3091 100644 --- a/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java +++ b/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java @@ -1,85 +1,39 @@ package ch.asynk.helloworld; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; - import com.vaadin.Application; import com.vaadin.terminal.Terminal; -import com.vaadin.terminal.UserError; -import com.vaadin.terminal.SystemError; -import com.vaadin.terminal.ErrorMessage; -import com.vaadin.terminal.VariableOwner; -import com.vaadin.terminal.URIHandler; -import com.vaadin.terminal.ParameterHandler; -import com.vaadin.terminal.gwt.server.ChangeVariablesErrorEvent; +import com.vaadin.terminal.Sizeable; import com.vaadin.ui.Window; -import com.vaadin.ui.AbstractComponent; public class HelloWorldApp extends Application { + // private static final long serialVersionUID = 1L; - private static Logger logger = Logger.getLogger("com.heraeus.hmsa"); - public static Properties props = new Properties(); - + // + private Context ctx = null; + public Context getCtx() { + return ctx; + } + // @Override public void init() { - init_properties(); + ctx = new Context(this); setTheme("asynk"); final Window mainWindow = new Window("Hello World Application"); - mainWindow.setContent( new MainLayout() ); + mainWindow.setWidth(900,Sizeable.UNITS_PIXELS); setMainWindow(mainWindow); + mainWindow.setContent( new MainLayout(ctx) ); setLogoutURL("http://asynk.ch"); - logger.warning("hell : "+props.getProperty("hello.next")+" "+props.getProperty("hello.world")); + ctx.getLogger().warning("hell : "+ctx.getProps().getProperty("hello.next")+" "+ctx.getProps().getProperty("hello.world")); } - private void init_properties() { - // - String properties_file = "Application.properties"; - logger.info("doing stuff : "); - java.io.InputStream is = null; - try { - is = HelloWorldApp.class.getClassLoader().getResourceAsStream(properties_file); - } - catch(java.lang.Exception x) { - logger.log(Level.SEVERE,"Error loading "+properties_file+"' properties",x); - return; - } - if (is!=null) { - try { - props.load(is); - } - catch (java.io.IOException e) { - logger.log(Level.SEVERE,"Error reading properties '"+properties_file+"' ",e); - } - } else { - logger.warning("'"+properties_file+"' file not found"); - } + public void notifyError(String title, String msg){ + getMainWindow().showNotification(title,msg,Window.Notification.TYPE_ERROR_MESSAGE); } @Override public void terminalError(Terminal.ErrorEvent event) { // Call the default implementation. - //super.terminalError(event); - // http://dev.vaadin.com/browser/releases/6.6.6/src/com/vaadin/Application.java#L1190 - final Throwable t = event.getThrowable(); - Object owner = null; - if (event instanceof VariableOwner.ErrorEvent) { - owner = ((VariableOwner.ErrorEvent) event).getVariableOwner(); - } else if (event instanceof URIHandler.ErrorEvent) { - owner = ((URIHandler.ErrorEvent) event).getURIHandler(); - } else if (event instanceof ParameterHandler.ErrorEvent) { - owner = ((ParameterHandler.ErrorEvent) event).getParameterHandler(); - } else if (event instanceof ChangeVariablesErrorEvent) { - owner = ((ChangeVariablesErrorEvent) event).getComponent(); - } - if (owner instanceof AbstractComponent) { - if (t instanceof ErrorMessage) { - ((AbstractComponent) owner).setComponentError((ErrorMessage)t); - } else { - //((AbstractComponent) owner).setComponentError(new SystemError(t)); - ((AbstractComponent) owner).setComponentError(new UserError("User Error!")); - } - } + super.terminalError(event); // Some custom behaviour. if (getMainWindow() != null) { getMainWindow().showNotification("An unchecked exception occured!", event.getThrowable().toString(), Window.Notification.TYPE_ERROR_MESSAGE); diff --git a/vaadin-app/src/ch/asynk/helloworld/LayoutLayout.java b/vaadin-app/src/ch/asynk/helloworld/LayoutLayout.java index f5efedf..6ebb1e3 100644 --- a/vaadin-app/src/ch/asynk/helloworld/LayoutLayout.java +++ b/vaadin-app/src/ch/asynk/helloworld/LayoutLayout.java @@ -11,10 +11,13 @@ import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.ListSelect; public class LayoutLayout extends VerticalLayout { - + // private static final long serialVersionUID = 1L; + // + private Context ctx = null; - public LayoutLayout() { + public LayoutLayout(Context context) { + ctx = context; // final AbstractComponent topComponent = buildTopComponent(); topComponent.setWidth(500,UNITS_PIXELS); @@ -32,7 +35,7 @@ public class LayoutLayout extends VerticalLayout { nextButton.addListener( new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { - getApplication().getMainWindow().setContent( new EndLayout() ); + getApplication().getMainWindow().setContent( new EndLayout(ctx) ); } }); } diff --git a/vaadin-app/src/ch/asynk/helloworld/MainLayout.java b/vaadin-app/src/ch/asynk/helloworld/MainLayout.java index 0aaea6c..48fb7f1 100644 --- a/vaadin-app/src/ch/asynk/helloworld/MainLayout.java +++ b/vaadin-app/src/ch/asynk/helloworld/MainLayout.java @@ -11,8 +11,14 @@ import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Window.Notification; public class MainLayout extends VerticalLayout { - + // private static final long serialVersionUID = 1L; + // + private Context ctx = null; + + public MainLayout(Context context) { + ctx = context; + // public MainLayout() { Label label = new Label("Hello world"); @@ -41,7 +47,7 @@ public class MainLayout extends VerticalLayout { nextButton.addListener( new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { - getApplication().getMainWindow().setContent( new DataMappingLayout() ); + getApplication().getMainWindow().setContent( new DataMappingLayout(ctx) ); } }); } |