import com.itmill.toolkit.terminal.ErrorMessage;
import com.itmill.toolkit.terminal.ExternalResource;
import com.itmill.toolkit.terminal.UserError;
-
-import com.itmill.toolkit.ui.*;
+import com.itmill.toolkit.ui.AbstractComponent;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.CheckBox;
+import com.itmill.toolkit.ui.DateField;
+import com.itmill.toolkit.ui.Embedded;
+import com.itmill.toolkit.ui.ExpandLayout;
+import com.itmill.toolkit.ui.GridLayout;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.Layout;
+import com.itmill.toolkit.ui.Link;
+import com.itmill.toolkit.ui.NativeSelect;
+import com.itmill.toolkit.ui.OptionGroup;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.Panel;
+import com.itmill.toolkit.ui.ProgressIndicator;
+import com.itmill.toolkit.ui.RichTextArea;
+import com.itmill.toolkit.ui.Select;
+import com.itmill.toolkit.ui.Slider;
+import com.itmill.toolkit.ui.TabSheet;
+import com.itmill.toolkit.ui.Table;
+import com.itmill.toolkit.ui.TextField;
+import com.itmill.toolkit.ui.Tree;
+import com.itmill.toolkit.ui.TwinColSelect;
+import com.itmill.toolkit.ui.Upload;
+import com.itmill.toolkit.ui.Window;
import com.itmill.toolkit.ui.Component.Event;
import com.itmill.toolkit.ui.Component.Listener;
SampleDatabase sampleDatabase;
// Example Actions for table
- private Action ACTION1 = new Action("Upload");
- private Action ACTION2 = new Action("Download");
- private Action ACTION3 = new Action("Show history");
- private Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 };
+ private final Action ACTION1 = new Action("Upload");
+ private final Action ACTION2 = new Action("Download");
+ private final Action ACTION3 = new Action("Show history");
+ private final Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 };
public void init() {
sampleDatabase = new SampleDatabase();
optionGroup.setContainerDataSource(getSmallContainer());
optionGroup.setItemCaptionPropertyId("UNIT");
- ProgressIndicator pi = new ProgressIndicator(50.0f);
+ ProgressIndicator pi = new ProgressIndicator(new Float(50));
pi.setCaption("ProgressIndicator");
test(layout, pi);
ClassResource res = new ClassResource("m.gif", this);
ErrorMessage errorMsg = new UserError("User error " + c);
- if ((c.getCaption() == null) || (c.getCaption().length() <= 0))
+ if ((c.getCaption() == null) || (c.getCaption().length() <= 0)) {
c.setCaption("Caption " + c);
+ }
c.setDescription("Description " + c);
c.setComponentError(errorMsg);
c.setIcon(res);
test(c);
layout.addComponent(c);
// add separator
- if (!(layout instanceof GridLayout))
+ if (!(layout instanceof GridLayout)) {
layout.addComponent(new Label("<HR />", Label.CONTENT_XHTML));
+ }
}
public void componentEvent(Event event) {
package com.itmill.toolkit.tests.magi;
-import com.itmill.toolkit.ui.*;
-import com.itmill.toolkit.data.*;
+
+import java.text.MessageFormat;
+
+import com.itmill.toolkit.data.Property;
+import com.itmill.toolkit.data.Validator;
import com.itmill.toolkit.data.Property.ValueChangeEvent;
-import java.text.*;
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.TextField;
/* Finnish Social Security Number input field that validates the value. */
-public class SSNField extends CustomComponent implements Property.ValueChangeListener {
- OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
+public class SSNField extends CustomComponent implements
+ Property.ValueChangeListener {
+ OrderedLayout layout = new OrderedLayout(
+ OrderedLayout.ORIENTATION_HORIZONTAL);
TextField myfield;
Label myerror;
/** Validate the given SSN. */
public void validate(Object value) throws InvalidValueException {
String ssn = (String) value;
- if (ssn.length() != 11)
+ if (ssn.length() != 11) {
throw new InvalidValueException("Invalid SSN length");
-
- String numbers = ssn.substring(0,6) + ssn.substring(7,10);
- int checksum = new Integer(numbers) % 31;
- if (!ssn.substring(10).equals("0123456789ABCDEFHJKLMNPRSTUVWXY".substring(checksum,checksum+1)))
+ }
+
+ String numbers = ssn.substring(0, 6) + ssn.substring(7, 10);
+ int checksum = new Integer(numbers).intValue() % 31;
+ if (!ssn.substring(10).equals(
+ "0123456789ABCDEFHJKLMNPRSTUVWXY".substring(checksum,
+ checksum + 1))) {
throw new InvalidValueException("Invalid SSN checksum");
+ }
}
}
-
+
SSNField() {
setCompositionRoot(layout);
layout.setStyle("form");
myfield = new TextField("Social Security Number");
myfield.setColumns(11);
myfield.setFormat(new MessageFormat("{0,number,##}"));
-
+
/* Create and set the validator object for the field. */
- SSNValidator ssnvalidator = new SSNValidator ();
+ SSNValidator ssnvalidator = new SSNValidator();
myfield.addValidator(ssnvalidator);
-
- /* ValueChageEvent will be generated immediately when the component loses focus. */
+
+ /*
+ * ValueChageEvent will be generated immediately when the component
+ * loses focus.
+ */
myfield.setImmediate(true);
-
+
/* Listen for ValueChangeEvent events. */
myfield.addListener(this);
try {
/* Validate the field value. */
myfield.validate();
-
+
/* The value was correct. */
myerror.setValue("Ok");
myfield.setStyle("");
} catch (Validator.InvalidValueException e) {
/* Report the error message to the user. */
myerror.setValue(e.getMessage());
-
- /* The CSS defines that text field with the "error" class will be colored red. */
+
+ /*
+ * The CSS defines that text field with the "error" class will be
+ * colored red.
+ */
myfield.setStyle("error");
- }
+ }
}
}
package com.itmill.toolkit.tests.magi;
-import com.itmill.toolkit.ui.*;
+
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.Table;
public class TableExample extends CustomComponent {
/* Create the table with a caption. */
/* A layout needed for the example. */
OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
- TableExample () {
- setCompositionRoot (layout);
+ TableExample() {
+ setCompositionRoot(layout);
layout.addComponent(table);
/* Define the names, data types, and default values of columns. */
- table.addContainerProperty("First Name", String.class, "(no first name)");
+ table.addContainerProperty("First Name", String.class,
+ "(no first name)");
table.addContainerProperty("Last Name", String.class, "(no last name)");
table.addContainerProperty("Year", Integer.class, null);
-
+
/* We use these entries to generate random items in a table. */
- final String[] firstnames = new String[]{"Donald", "Patty", "Sally", "Douglas"};
- final String[] lastnames = new String[]{"Smith", "Jones", "Adams", "Knuth"};
-
+ final String[] firstnames = new String[] { "Donald", "Patty", "Sally",
+ "Douglas" };
+ final String[] lastnames = new String[] { "Smith", "Jones", "Adams",
+ "Knuth" };
+
/* Add some items in the table and assign them an Item ID (IID). */
- for (int i=0; i<500; i++) {
+ for (int i = 0; i < 500; i++) {
/* Add a randomly generated item in the Table. */
- table.addItem(new Object[]{firstnames[(int) (Math.random() * (firstnames.length-0.01))],
- lastnames [(int) (Math.random() * (lastnames.length-0.01))],
- (int) (1900+Math.random() * 100)}, i);
+ table
+ .addItem(
+ new Object[] {
+ firstnames[(int) (Math.random() * (firstnames.length - 0.01))],
+ lastnames[(int) (Math.random() * (lastnames.length - 0.01))],
+ new Integer(
+ (int) (1900 + Math.random() * 100)) },
+ new Integer(i));
}
/* Set the number of items visible in the table. */
table.setPageLength(10);
-
+
table.setStyle("twincol");
table.setColumnReorderingAllowed(true);
table.setColumnCollapsingAllowed(true);