import com.itmill.toolkit.ui.ExpandLayout;
import com.itmill.toolkit.ui.FormLayout;
import com.itmill.toolkit.ui.GridLayout;
+import com.itmill.toolkit.ui.InlineDateField;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.Link;
import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.TextField;
import com.itmill.toolkit.ui.Tree;
import com.itmill.toolkit.ui.Window;
+import com.itmill.toolkit.ui.Button.ClickEvent;
public class MagiTestApplication extends com.itmill.toolkit.Application {
Window main = new Window("Application window");
}
public DownloadStream handleURI(URL context, String relativeUri) {
- // @TODO: Is this enough? Does handleURI() ever need to
- // get these?
- if (relativeUri.startsWith("APP")) {
+ // Let default implementation handle requests for
+ // application resources.
+ if (relativeUri.startsWith("APP"))
return super.handleURI(context, relativeUri);
- }
String example;
String param = null;
"upload", "link", "gridlayout", "orderedlayout",
"formlayout", "panel", "expandlayout", "tabsheet",
"alignment", "alignment/grid", "window", "window/opener",
- "window/multiple", "classresource" };
+ "window/multiple", "classresource", "usererror" };
for (int i = 0; i < examples.length; i++) {
main.addComponent(new Label("<a href='/tk/testbench2/"
+ examples[i] + "'>" + examples[i] + "</a>",
example_TextField(main, param);
} else if (example.equals("textfieldvalidation")) {
example_TextFieldValidation(main, param);
+ } else if (example.equals("usererror")) {
+ example_UserError(main, param);
} else if (example.equals("datefield")) {
example_DateField(main, param);
} else if (example.equals("button")) {
void example_Tree(Window main, String param) {
final Object[][] planets = new Object[][] {
- new Object[] { "Mercury" },
- new Object[] { "Venus" },
- new Object[] { "Earth", "The Moon" },
- new Object[] { "Mars", "Phobos", "Deimos" },
- new Object[] { "Jupiter", "Io", "Europa", "Ganymedes",
- "Callisto" },
- new Object[] { "Saturn", "Titan", "Tethys", "Dione", "Rhea",
- "Iapetus" },
- new Object[] { "Uranus", "Miranda", "Ariel", "Umbriel",
- "Titania", "Oberon" },
- new Object[] { "Neptune", "Triton", "Proteus", "Nereid",
- "Larissa" } };
+ new Object[] {"Mercury"},
+ new Object[] {"Venus"},
+ new Object[] {"Earth", "The Moon"},
+ new Object[] {"Mars", "Phobos", "Deimos"},
+ new Object[] {"Jupiter", "Io", "Europa", "Ganymedes", "Callisto"},
+ new Object[] {"Saturn", "Titan", "Tethys", "Dione", "Rhea", "Iapetus"},
+ new Object[] {"Uranus", "Miranda", "Ariel", "Umbriel", "Titania", "Oberon"},
+ new Object[] {"Neptune", "Triton", "Proteus", "Nereid", "Larissa"}};
final Tree tree = new Tree("The Planets and Major Moons");
});
}
+ void example_UserError(final Window main, String param) {
+ if (param != null) {
+ if (param.equals("form")) {
+
+ final FormLayout layout = new FormLayout();
+ main.addComponent(layout);
+
+ final TextField textfield = new TextField("Enter name");
+ layout.addComponent(textfield);
+ textfield.setComponentError(null);
+
+ final Button button = new Button("Click me!");
+ layout.addComponent(button);
+
+ button.addListener(new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ if (((String)textfield.getValue()).length() == 0)
+ textfield.setComponentError(new UserError("Must not be empty"));
+ else // Clear the error
+ textfield.setComponentError(null);
+ }
+ });
+ }
+ } else {
+ final TextField textfield = new TextField("Enter name");
+ main.addComponent(textfield);
+ textfield.setComponentError(null);
+
+ final Button button = new Button("Click me!");
+ main.addComponent(button);
+
+ button.addListener(new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ if (((String)textfield.getValue()).length() == 0)
+ textfield.setComponentError(new UserError("Must not be empty"));
+ else // Clear the error
+ textfield.setComponentError(null);
+ }
+ });
+ }
+ }
+
void example_DateField(Window main, String param) {
/* Create a DateField with the calendar style. */
final DateField date = new DateField("Here is a calendar field");
}
void example_Panel(Window main, String param) {
+ // Create a panel with a caption.
final Panel panel = new Panel("Contact Information");
+
+ // Create a layout inside the panel
final OrderedLayout form = new FormLayout();
+
+ // Set the layout as the root layout of the panel
+ panel.setLayout(form);
+
+ // Add some components
form.addComponent(new TextField("Name"));
form.addComponent(new TextField("Email"));
+ // Add the panel to the main window
final ClassResource icon = new ClassResource("smiley.jpg", main
.getApplication());
form.addComponent(new Embedded("Image", icon));
/* Add some components of various shapes. */
grid.addComponent(new Button("3x1 button"), 1, 1, 3, 1);
grid.addComponent(new Label("1x2 cell"), 1, 2, 1, 3);
- final DateField date = new DateField("A 2x2 date field");
- date.setStyleName("calendar");
+ final InlineDateField date = new InlineDateField("A 2x2 date field");
+ date.setResolution(DateField.RESOLUTION_DAY);
grid.addComponent(date, 2, 2, 3, 3);
main.addComponent(grid);
// OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
main.setLayout(layout);
layout.addStyleName("example-alignment");
+
layout.getSize().setWidth(400, Size.UNITS_PIXELS);
layout.getSize().setHeight(400, Size.UNITS_PIXELS);
image.addStyleName("omaimage");
main.addComponent(image);
- final EmbeddedButton button = new EmbeddedButton(new ClassResource(
- "smiley.jpg", this));
+ final EmbeddedButton button = new EmbeddedButton(new ClassResource("smiley.jpg", this));
main.addComponent(button);
}
/* Add link to the second window in the main window. */
main.addComponent(new Label("Second window: <a href='"
- + mywindow.getURL() + "'>middle-click to open</a>",
- Label.CONTENT_XHTML));
- main.addComponent(new Label(
- "The second window can be accessed through URL: "
- + mywindow.getURL()));
+ + mywindow.getURL() + "'>middle-click to open</a>",
+ Label.CONTENT_XHTML));
+ main.addComponent(new Label("The second window can be accessed through URL: "
+ + mywindow.getURL()));
}
return;
}
--- /dev/null
+package com.itmill.toolkit.tests.magi;
+
+import com.itmill.toolkit.Application;
+import com.itmill.toolkit.ui.*;
+import com.itmill.toolkit.ui.Button.ClickEvent;
+import com.itmill.toolkit.terminal.*;
+
+public class WindowTestApplication extends Application {
+ Window anotherpage = null;
+
+ public void init() {
+ final Window main = new Window ("Window Test Application");
+ setMainWindow(main);
+ setTheme("tests-magi");
+
+ /* Create a new window. */
+ final Window mywindow = new Window("Second Window");
+
+ /* Manually set the name of the window. */
+ mywindow.setName("mywindow");
+
+ /* Add some content to the window. */
+ mywindow.addComponent(new Label("This is a second window."));
+
+ /* Add the window to the application. */
+ addWindow(mywindow);
+
+ /* Add a button to open a new window. */
+ main.addComponent(new Button("Click to open new window",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ // Open the window.
+ main.open(new ExternalResource(mywindow.getURL()), "_new");
+ }
+ }));
+
+ /* Add a link to the second window. */
+ Link link = new Link("Click to open second window",
+ new ExternalResource(mywindow.getURL()));
+ link.setTargetName("_new");
+ //link.setTargetHeight(300);
+ //link.setTargetWidth(300);
+ //link.setTargetBorder(Link.TARGET_BORDER_DEFAULT);
+ main.addComponent(link);
+
+ /* Add the link manually inside a Label. */
+ main.addComponent(new Label("Second window: <a href='"
+ + mywindow.getURL() + "' target='_new'>click to open</a>",
+ Label.CONTENT_XHTML));
+ main.addComponent(new Label("The second window can be accessed through URL: "
+ + mywindow.getURL()));
+
+ /* Add link to the yet another window that does not yet exist. */
+ main.addComponent(new Label("Yet another window: <a href='"
+ + getURL() + "anotherpage/' target='_new'>click to open</a>",
+ Label.CONTENT_XHTML));
+ main.addComponent(new Label("The yet another window can be accessed through URL: "
+ + getURL()+"anotherpage/"));
+ }
+
+ public Window getWindow(String name) {
+ if (name.equals("anotherpage")) {
+ if (anotherpage == null) {
+ anotherpage = new Window("Yet Another Page");
+ anotherpage.addComponent(new Label("This is a yet another window."));
+ }
+ return anotherpage;
+ }
+ return super.getWindow(name);
+ }
+
+}