summaryrefslogtreecommitdiffstats
path: root/java-vaadin/src/ch
diff options
context:
space:
mode:
Diffstat (limited to 'java-vaadin/src/ch')
-rw-r--r--java-vaadin/src/ch/asynk/helloworld/Context.java55
-rw-r--r--java-vaadin/src/ch/asynk/helloworld/DataMappingLayout.java170
-rw-r--r--java-vaadin/src/ch/asynk/helloworld/EndLayout.java31
-rw-r--r--java-vaadin/src/ch/asynk/helloworld/HelloWorldApp.java42
-rw-r--r--java-vaadin/src/ch/asynk/helloworld/LayoutLayout.java109
-rw-r--r--java-vaadin/src/ch/asynk/helloworld/MainLayout.java75
-rw-r--r--java-vaadin/src/ch/asynk/helloworld/Resources.java9
7 files changed, 491 insertions, 0 deletions
diff --git a/java-vaadin/src/ch/asynk/helloworld/Context.java b/java-vaadin/src/ch/asynk/helloworld/Context.java
new file mode 100644
index 0000000..c59016d
--- /dev/null
+++ b/java-vaadin/src/ch/asynk/helloworld/Context.java
@@ -0,0 +1,55 @@
+package ch.asynk.helloworld;
+
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class Context {
+ //
+ private static final long serialVersionUID = 1L;
+ //
+ private Logger log = Logger.getLogger("ch.asynk");
+ public Logger getLogger() {
+ return log;
+ }
+ //
+ private Properties props = null;
+ public Properties getProps() {
+ return props;
+ }
+ //
+ private HelloWorldApp app = null;
+ public HelloWorldApp getApp() {
+ return app;
+ }
+ //
+ public Context(HelloWorldApp application) {
+ app = application;
+ initProps();
+ }
+ //
+ private void initProps() {
+ props = new Properties();
+ //
+ String properties_file = "Application.properties";
+ log.info("doing stuff : ");
+ java.io.InputStream is = null;
+ try {
+ is = HelloWorldApp.class.getClassLoader().getResourceAsStream(properties_file);
+ }
+ catch(java.lang.Exception x) {
+ log.log(Level.SEVERE,"Error loading "+properties_file+"' properties",x);
+ return;
+ }
+ if (is!=null) {
+ try {
+ props.load(is);
+ }
+ catch (java.io.IOException e) {
+ log.log(Level.SEVERE,"Error reading properties '"+properties_file+"' ",e);
+ }
+ } else {
+ log.warning("'"+properties_file+"' file not found");
+ }
+ }
+}
diff --git a/java-vaadin/src/ch/asynk/helloworld/DataMappingLayout.java b/java-vaadin/src/ch/asynk/helloworld/DataMappingLayout.java
new file mode 100644
index 0000000..42801d8
--- /dev/null
+++ b/java-vaadin/src/ch/asynk/helloworld/DataMappingLayout.java
@@ -0,0 +1,170 @@
+package ch.asynk.helloworld;
+
+import com.vaadin.terminal.UserError;
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.util.ObjectProperty;
+import com.vaadin.data.Validator;
+import com.vaadin.data.validator.DoubleValidator;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.FormLayout;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.TextField;
+
+public class DataMappingLayout extends VerticalLayout {
+ //
+ private static final long serialVersionUID = 1L;
+ //
+ private Context ctx = null;
+
+ public DataMappingLayout(Context context) {
+ ctx = context;
+ //
+ final AbstractComponent pa = buildPanel();
+ pa.setWidth(600,UNITS_PIXELS);
+ pa.setHeight(400,UNITS_PIXELS);
+ addComponent(pa);
+ setComponentAlignment(pa, Alignment.MIDDLE_CENTER);
+ //
+ }
+ //
+ private AbstractComponent buildPanel() {
+ Panel panel = new Panel("Data Mapping Layout");
+ FormLayout layout = new FormLayout();
+ panel.setContent(layout);
+ //
+ final TextField tf1 = new TextField("Property.ValueChangeListener");
+ tf1.setImmediate(true);
+ layout.addComponent(tf1);
+ final Label lb1 = new Label();
+ lb1.setCaption("The Value");
+ layout.addComponent(lb1);
+ tf1.addListener( new Property.ValueChangeListener() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ String value = (String) tf1.getValue();
+ lb1.setValue(value);
+ }
+ });
+ //
+ Double trouble = 66.6;
+ final ObjectProperty<Double> property = new ObjectProperty<Double>(trouble);
+ final TextField tf2 = new TextField("ObjectProperty + Validator", property);
+ tf2.setImmediate(true);
+ tf2.addValidator( new DoubleValidator("It should be a double") );
+ //tf2.setValidationVisible(false); // nothing will happen
+ layout.addComponent(tf2);
+ final Label lb2 = new Label(property);
+ lb2.setCaption("The Value");
+ layout.addComponent(lb2);
+ //
+ final TextField tf3 = new TextField("No spaces");
+ layout.addComponent(tf3);
+ tf3.setComponentError(null); // (actually the default)
+ final Button b1 = new Button("Ok!");
+ layout.addComponent(b1);
+ b1.addListener(new Button.ClickListener() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ public void buttonClick(ClickEvent event) {
+ if (! ((String) tf3.getValue()).matches("^\\w*$")) {
+ tf3.setComponentError(new UserError("Must be letters and numbers"));
+ } else {
+ tf3.setComponentError(null);
+ }
+ }
+ });
+ //
+ // final Validator intValidator = new Validator() { ... }
+ class MyIntValidator implements Validator {
+ private static final long serialVersionUID = 1L;
+ public boolean isValid(Object value) {
+ if (value == null || !(value instanceof String)) {
+ return false;
+ }
+ return ((String) value).matches("[1-9][0-9]{4}");
+ }
+ public void validate(Object value) throws InvalidValueException {
+ if (!isValid(value)) {
+ if (value != null && value.toString().startsWith("0")) {
+ throw new InvalidValueException("Must not start with a zero.");
+ } else {
+ throw new InvalidValueException("Must be a number 10000-99999.");
+ }
+ }
+ }
+ };
+ final TextField tf5 = new TextField("MyIntValidator");
+ tf5.addValidator(new MyIntValidator());
+ tf5.setImmediate(true);
+ layout.addComponent(tf5);
+ //
+ class IntegerObjectProperty implements Property {
+ private static final long serialVersionUID = 1L;
+ Integer data = 0;
+ boolean readOnly = false;
+ public Class<?> getType() {
+ return Integer.class;
+ }
+ public Object getValue() {
+ return data;
+ }
+ public boolean isReadOnly() {
+ return readOnly;
+ }
+ public void setReadOnly(boolean newStatus) {
+ readOnly = newStatus;
+ }
+ public void setValue(Object newValue) throws ReadOnlyException, ConversionException {
+ if (readOnly)
+ throw new ReadOnlyException();
+ if (newValue instanceof Integer)
+ data = (Integer) newValue;
+ else if (newValue instanceof String)
+ try {
+ data = Integer.parseInt((String) newValue, 16);
+ } catch (NumberFormatException e) {
+ throw new ConversionException("Must be an integer (from property)");
+ }
+ else
+ throw new ConversionException("Unknown entry type (from property)");
+ }
+ @Override
+ public String toString() {
+ return Integer.toHexString(data)+" (hex)";
+ }
+ };
+ final IntegerObjectProperty intProperty = new IntegerObjectProperty();
+ intProperty.setValue(666);
+ final TextField tf4 = new TextField("MyObjectProperty",intProperty);
+ tf4.setImmediate(true);
+ tf4.setErrorHandler(new ComponentErrorHandler() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ public boolean handleComponentError(ComponentErrorEvent event) {
+ tf4.setComponentError(new UserError("Must be an integer (from handler)"));
+ return true;
+ }
+ });
+ layout.addComponent(tf4);
+ //
+ Button nextButton = new Button("next layout");
+ nextButton.setDescription("Go to next layout");
+ layout.addComponent(nextButton );
+ nextButton.addListener( new Button.ClickListener() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ public void buttonClick(ClickEvent event) {
+ getApplication().getMainWindow().setContent( new LayoutLayout(ctx) );
+ }
+ });
+ //
+ return panel;
+ }
+}
diff --git a/java-vaadin/src/ch/asynk/helloworld/EndLayout.java b/java-vaadin/src/ch/asynk/helloworld/EndLayout.java
new file mode 100644
index 0000000..2b5c15f
--- /dev/null
+++ b/java-vaadin/src/ch/asynk/helloworld/EndLayout.java
@@ -0,0 +1,31 @@
+package ch.asynk.helloworld;
+
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Label;
+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(Context context) {
+ ctx = context;
+ //
+ final Label lb1 = new Label();
+ lb1.setCaption("That's all folks");
+ addComponent(lb1);
+ //
+ Button closeButton = new Button("close the application");
+ closeButton.setDescription("This will close the application");
+ addComponent(closeButton );
+ closeButton.addListener( new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ getApplication().getMainWindow().getApplication().close();
+ }
+ });
+ }
+};
diff --git a/java-vaadin/src/ch/asynk/helloworld/HelloWorldApp.java b/java-vaadin/src/ch/asynk/helloworld/HelloWorldApp.java
new file mode 100644
index 0000000..d5e3091
--- /dev/null
+++ b/java-vaadin/src/ch/asynk/helloworld/HelloWorldApp.java
@@ -0,0 +1,42 @@
+package ch.asynk.helloworld;
+
+import com.vaadin.Application;
+import com.vaadin.terminal.Terminal;
+import com.vaadin.terminal.Sizeable;
+import com.vaadin.ui.Window;
+
+public class HelloWorldApp extends Application {
+ //
+ private static final long serialVersionUID = 1L;
+ //
+ private Context ctx = null;
+ public Context getCtx() {
+ return ctx;
+ }
+ //
+ @Override
+ public void init() {
+ ctx = new Context(this);
+ setTheme("asynk");
+ final Window mainWindow = new Window("Hello World Application");
+ mainWindow.setWidth(900,Sizeable.UNITS_PIXELS);
+ setMainWindow(mainWindow);
+ mainWindow.setContent( new MainLayout(ctx) );
+ setLogoutURL("http://asynk.ch");
+ ctx.getLogger().warning("hell : "+ctx.getProps().getProperty("hello.next")+" "+ctx.getProps().getProperty("hello.world"));
+ }
+
+ 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);
+ // Some custom behaviour.
+ if (getMainWindow() != null) {
+ getMainWindow().showNotification("An unchecked exception occured!", event.getThrowable().toString(), Window.Notification.TYPE_ERROR_MESSAGE);
+ }
+ }
+}
diff --git a/java-vaadin/src/ch/asynk/helloworld/LayoutLayout.java b/java-vaadin/src/ch/asynk/helloworld/LayoutLayout.java
new file mode 100644
index 0000000..6ebb1e3
--- /dev/null
+++ b/java-vaadin/src/ch/asynk/helloworld/LayoutLayout.java
@@ -0,0 +1,109 @@
+package ch.asynk.helloworld;
+
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Button;
+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(Context context) {
+ ctx = context;
+ //
+ final AbstractComponent topComponent = buildTopComponent();
+ topComponent.setWidth(500,UNITS_PIXELS);
+ topComponent.setHeight(400,UNITS_PIXELS);
+ addComponent(topComponent);
+ setComponentAlignment(topComponent, Alignment.MIDDLE_CENTER);
+ //
+ final AbstractComponent grid = buildGrid();
+ grid.setSizeFull();
+ addComponent(grid);
+ //
+ Button nextButton = new Button("next layout");
+ nextButton.setDescription("Go to next layout");
+ addComponent(nextButton );
+ nextButton.addListener( new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ getApplication().getMainWindow().setContent( new EndLayout(ctx) );
+ }
+ });
+ }
+
+ private AbstractComponent buildTopComponent() {
+
+ Panel panel = new Panel("Panel 1");
+ VerticalLayout layout = (VerticalLayout) panel.getContent();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+ layout.setHeight(100,UNITS_PERCENTAGE);
+ //
+ float width = 90;
+ float height = 100;
+ //
+ ListSelect receptionList = new ListSelect("List 1");
+ receptionList.setWidth(width, UNITS_PERCENTAGE);
+ receptionList.setHeight(height, UNITS_PERCENTAGE);
+ layout.addComponent(receptionList);
+ //
+ ListSelect splitList = new ListSelect("List 2");
+ splitList.setWidth(width, UNITS_PERCENTAGE);
+ splitList.setHeight(height, UNITS_PERCENTAGE);
+ layout.addComponent(splitList);
+ //
+ ListSelect ctrlList = new ListSelect("Liste 3");
+ ctrlList.setWidth(width, UNITS_PERCENTAGE);
+ ctrlList.setHeight(height, UNITS_PERCENTAGE);
+ layout.addComponent(ctrlList);
+ //
+ Button goButton = new Button("Select");
+ goButton.setHeight(height, UNITS_PERCENTAGE);
+ layout.addComponent(goButton);
+ //
+ layout.setExpandRatio(receptionList,3.0f);
+ layout.setExpandRatio(splitList,3.0f);
+ layout.setExpandRatio(ctrlList,3.0f);
+ layout.setExpandRatio(goButton,1.0f);
+ layout.setComponentAlignment(goButton, Alignment.MIDDLE_CENTER);
+ //
+ return panel;
+ }
+
+ private AbstractComponent buildGrid() {
+ Panel panel = new Panel("Grid Panel");
+ VerticalLayout layout = (VerticalLayout) panel.getContent();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+ layout.setHeight(100,UNITS_PERCENTAGE);
+ //
+ GridLayout grid = new GridLayout(3, 3);
+ grid.setSizeFull();
+ grid.addStyleName("mygrid");
+ // excess space usage
+ //grid.setColumnExpandRatio(1, 1);
+ //grid.setColumnExpandRatio(2, 5);
+ //grid.setRowExpandRatio(1, 1);
+ Button b0 = new Button("[0;0] [0;2]");
+ b0.setSizeFull();
+ grid.addComponent(b0,0,0,0,2);
+ final Panel p2 = new Panel("Panel 2");
+ p2.setSizeFull();
+ grid.addComponent(p2,1,0,2,1);
+ Button b1 = new Button("[1;2] [2;2]");
+ b1.setSizeFull();
+ grid.addComponent(b1,1,2,2,2);
+ panel.setContent(grid);
+ //
+ return panel;
+ }
+}
diff --git a/java-vaadin/src/ch/asynk/helloworld/MainLayout.java b/java-vaadin/src/ch/asynk/helloworld/MainLayout.java
new file mode 100644
index 0000000..d4481c1
--- /dev/null
+++ b/java-vaadin/src/ch/asynk/helloworld/MainLayout.java
@@ -0,0 +1,75 @@
+package ch.asynk.helloworld;
+
+import java.util.Date;
+
+import com.vaadin.terminal.UserError;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Button;
+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;
+ //
+ final AbstractComponent pa = buildPanel();
+ pa.setWidth(250,UNITS_PIXELS);
+ pa.setHeight(300,UNITS_PIXELS);
+ addComponent(pa);
+ setComponentAlignment(pa, Alignment.MIDDLE_CENTER);
+ //
+ }
+
+ private AbstractComponent buildPanel() {
+ Panel panel = new Panel("Main Layout");
+ VerticalLayout layout = (VerticalLayout) panel.getContent();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+ layout.setHeight(100,UNITS_PERCENTAGE);
+ //
+ Label label = new Label("Hello world");
+ layout.addComponent(label);
+ //
+ Button clockBtn = new Button("What is the time?");
+ layout.addComponent( clockBtn );
+ clockBtn.setIcon(Resources.clockIcon);
+ clockBtn.addListener( new Button.ClickListener() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ public void buttonClick(ClickEvent event) {
+ ctx.getApp().notifyError("The time is " + new Date(), "<i>italic</i> <b>bold</b> description");
+ event.getButton().setComponentError( new UserError("Stop pressing this button !!") );
+ }
+ });
+ ///
+ layout.addComponent( new Button("throw an exception", new Button.ClickListener() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ public void buttonClick(ClickEvent event) {
+ throw new RuntimeException("Wahou !! : exception");
+ }
+ }));
+ //
+ Button nextButton = new Button("next layout");
+ nextButton.setDescription("Go to next layout");
+ layout.addComponent(nextButton );
+ nextButton.addListener( new Button.ClickListener() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ public void buttonClick(ClickEvent event) {
+ ctx.getApp().getMainWindow().setContent( new DataMappingLayout(ctx) );
+ }
+ });
+ //
+ return panel;
+ }
+}
diff --git a/java-vaadin/src/ch/asynk/helloworld/Resources.java b/java-vaadin/src/ch/asynk/helloworld/Resources.java
new file mode 100644
index 0000000..dcf0449
--- /dev/null
+++ b/java-vaadin/src/ch/asynk/helloworld/Resources.java
@@ -0,0 +1,9 @@
+package ch.asynk.helloworld;
+
+import com.vaadin.terminal.ThemeResource;
+
+public class Resources {
+
+ private static final long serialVersionUID = 1L;
+ public static final ThemeResource clockIcon = new ThemeResource("icons/clock.png");
+}