diff options
Diffstat (limited to 'src/com/vaadin/demo/sampler')
247 files changed, 10223 insertions, 0 deletions
diff --git a/src/com/vaadin/demo/sampler/APIResource.java b/src/com/vaadin/demo/sampler/APIResource.java new file mode 100644 index 0000000000..f7138aac12 --- /dev/null +++ b/src/com/vaadin/demo/sampler/APIResource.java @@ -0,0 +1,57 @@ +package com.vaadin.demo.sampler; + +/** + * A NamedExternalResource pointing to the javadoc for the given class. Knows + * where the javadocs are located for some common APIs, but one can also specify + * a javadoc baseurl. The name will be set to the class simpleName. + * + */ +public class APIResource extends NamedExternalResource { + + private static final String ITMILL_BASE = "http://toolkit.itmill.com/demo/doc/api/"; + private static final String JAVA_BASE = "http://java.sun.com/javase/6/docs/api/"; + private static final String SERVLET_BASE = "http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2"; + private static final String PORTLET_BASE = "http://developers.sun.com/docs/jscreator/apis/portlet"; + + public APIResource(Class clazz) { + this(resolveBaseUrl(clazz), clazz); + } + + public APIResource(String baseUrl, Class clazz) { + super(resolveName(clazz), getJavadocUrl(baseUrl, clazz)); + } + + private static String getJavadocUrl(String baseUrl, Class clazz) { + if (!baseUrl.endsWith("/")) { + baseUrl += "/"; + } + String path = clazz.getName().replaceAll("\\.", "/"); + path = path.replaceAll("\\$", "."); + return baseUrl + path + ".html"; + } + + /** + * Tries to resolve the javadoc baseurl for the given class by looking at + * the packagename. + * + * @param clazz + * @return + */ + private static String resolveBaseUrl(Class clazz) { + String name = clazz.getName(); + if (name.startsWith("javax.servlet.")) { + return SERVLET_BASE; + } else if (name.startsWith("javax.portlet.")) { + return PORTLET_BASE; + } else if (name.startsWith("java.") || name.startsWith("javax.")) { + return JAVA_BASE; + } + return ITMILL_BASE; + } + + private static String resolveName(Class clazz) { + Class ec = clazz.getEnclosingClass(); + return (ec != null ? ec.getSimpleName() + "." : "") + + clazz.getSimpleName(); + } +} diff --git a/src/com/vaadin/demo/sampler/ActiveLink.java b/src/com/vaadin/demo/sampler/ActiveLink.java new file mode 100644 index 0000000000..375728aafc --- /dev/null +++ b/src/com/vaadin/demo/sampler/ActiveLink.java @@ -0,0 +1,164 @@ +package com.vaadin.demo.sampler; + +import java.io.Serializable; +import java.lang.reflect.Method; +import java.util.HashSet; +import java.util.Map; + +import com.vaadin.terminal.PaintException; +import com.vaadin.terminal.PaintTarget; +import com.vaadin.terminal.Resource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Link; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; + +@SuppressWarnings("serial") +public class ActiveLink extends Link { + + private static final String TAG = "activelink"; + + private static final Method LINK_FOLLOWED_METHOD; + + private HashSet listeners = new HashSet(); + + public ActiveLink() { + super(); + } + + public ActiveLink(String caption, Resource resource, String targetName, + int width, int height, int border) { + super(caption, resource, targetName, width, height, border); + } + + public ActiveLink(String caption, Resource resource) { + super(caption, resource); + } + + @Override + public String getTag() { + return TAG; + } + + static { + try { + LINK_FOLLOWED_METHOD = LinkActivatedListener.class + .getDeclaredMethod("linkActivated", + new Class[] { LinkActivatedEvent.class }); + } catch (final java.lang.NoSuchMethodException e) { + // This should never happen + throw new java.lang.RuntimeException( + "Internal error finding methods in ActiveLink"); + } + } + + /** + * Adds the link activated listener. + * + * @param listener + * the Listener to be added. + */ + public void addListener(LinkActivatedListener listener) { + listeners.add(listener); + addListener(LinkActivatedEvent.class, listener, LINK_FOLLOWED_METHOD); + if (listeners.size() == 1) { + requestRepaint(); + } + } + + /** + * Removes the link activated listener. + * + * @param listener + * the Listener to be removed. + */ + public void removeListener(ClickListener listener) { + listeners.remove(listener); + removeListener(ClickEvent.class, listener, LINK_FOLLOWED_METHOD); + if (listeners.size() == 0) { + requestRepaint(); + } + } + + /** + * Emits the options change event. + */ + protected void fireClick(boolean linkOpened) { + fireEvent(new LinkActivatedEvent(this, linkOpened)); + } + + @Override + public void paintContent(PaintTarget target) throws PaintException { + super.paintContent(target); + + if (listeners.size() > 0) { + target.addVariable(this, "activated", false); + target.addVariable(this, "opened", false); + } + } + + @Override + public void changeVariables(Object source, Map variables) { + super.changeVariables(source, variables); + if (!isReadOnly() && variables.containsKey("activated")) { + final Boolean activated = (Boolean) variables.get("activated"); + final Boolean opened = (Boolean) variables.get("opened"); + if (activated != null && activated.booleanValue() && !isReadOnly()) { + fireClick((opened != null && opened.booleanValue() ? true + : false)); + } + } + } + + public class LinkActivatedEvent extends Component.Event { + + private boolean linkOpened; + + /** + * New instance of text change event. + * + * @param source + * the Source of the event. + */ + public LinkActivatedEvent(Component source, boolean linkOpened) { + super(source); + this.linkOpened = linkOpened; + } + + /** + * Gets the ActiveLink where the event occurred. + * + * @return the Source of the event. + */ + public ActiveLink getActiveLink() { + return (ActiveLink) getSource(); + } + + /** + * Indicates whether or not the link was opened on the client, i.e in a + * new window/tab. If the link was not opened, the listener should react + * to the event and "do something", otherwise the link does nothing. + * + * @return true if the link was opened on the client + */ + public boolean isLinkOpened() { + return linkOpened; + } + } + + /** + * ActiveLink click listener + */ + public interface LinkActivatedListener extends Serializable { + + /** + * ActiveLink has been activated. + * + * @param event + * ActiveLink click event. + */ + public void linkActivated(LinkActivatedEvent event); + + } + +} diff --git a/src/com/vaadin/demo/sampler/CodeLabel.java b/src/com/vaadin/demo/sampler/CodeLabel.java new file mode 100644 index 0000000000..fba8a8ac9f --- /dev/null +++ b/src/com/vaadin/demo/sampler/CodeLabel.java @@ -0,0 +1,31 @@ +package com.vaadin.demo.sampler; + +import com.vaadin.ui.Label; + +public class CodeLabel extends Label { + + private static final String TAG = "codelabel"; + + public CodeLabel() { + setContentMode(CONTENT_PREFORMATTED); + } + + public CodeLabel(String content) { + super(content, CONTENT_PREFORMATTED); + } + + @Override + public String getTag() { + return TAG; + } + + @Override + public void setContentMode(int contentMode) { + if (contentMode != CONTENT_PREFORMATTED) { + throw new UnsupportedOperationException( + "Only preformatted content supported"); + } + super.setContentMode(CONTENT_PREFORMATTED); + } + +} diff --git a/src/com/vaadin/demo/sampler/ExampleUtil.java b/src/com/vaadin/demo/sampler/ExampleUtil.java new file mode 100644 index 0000000000..3888dd25fa --- /dev/null +++ b/src/com/vaadin/demo/sampler/ExampleUtil.java @@ -0,0 +1,242 @@ +package com.vaadin.demo.sampler; + +import java.util.Locale; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.util.HierarchicalContainer; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.terminal.Resource; +import com.vaadin.terminal.ThemeResource; + +public final class ExampleUtil { + public static final String lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ut massa eget erat dapibus sollicitudin. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque a augue. Praesent non elit. Duis sapien dolor, cursus eget, pulvinar eget, eleifend a, est. Integer in nunc. Vivamus consequat ipsum id sapien. Duis eu elit vel libero posuere luctus. Aliquam ac turpis. Aenean vitae justo in sem iaculis pulvinar. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam sit amet mi. " + + "<br/>" + + "Aenean auctor, mi sit amet ultricies pulvinar, dui urna adipiscing odio, ut faucibus odio mauris eget justo. Mauris quis magna quis augue interdum porttitor. Sed interdum, tortor laoreet tincidunt ullamcorper, metus velit hendrerit nunc, id laoreet mauris arcu vitae est. Nulla nec nisl. Mauris orci nibh, tempor nec, sollicitudin ac, venenatis sed, lorem. Quisque dignissim tempus erat. Maecenas molestie, pede ac ultrices interdum, felis neque vulputate quam, in sodales felis odio quis mi. Aliquam massa pede, pharetra quis, tincidunt quis, fringilla at, mauris. Vestibulum a massa. Vestibulum luctus odio ut quam. Maecenas congue convallis diam. Cras urna arcu, vestibulum vitae, blandit ut, laoreet id, risus. Ut condimentum, arcu sit amet placerat blandit, augue nibh pretium nunc, in tempus sem dolor non leo. Etiam fringilla mauris a odio. Nunc lorem diam, interdum eget, lacinia in, scelerisque sit amet, purus. Nam ornare. " + + "<br/>" + + "Donec placerat dui ut orci. Phasellus quis lacus at nisl elementum cursus. Cras bibendum egestas nulla. Phasellus pulvinar ullamcorper odio. Etiam ipsum. Proin tincidunt. Aliquam aliquet. Etiam purus odio, commodo sed, feugiat volutpat, scelerisque molestie, velit. Aenean sed sem sit amet libero sodales ultrices. Donec dictum, arcu sed iaculis porttitor, est mauris pulvinar purus, sit amet porta purus neque in risus. Mauris libero. Maecenas rhoncus. Morbi quis nisl. " + + "<br/>" + + "Vestibulum laoreet tortor eu elit. Cras euismod nulla eu sapien. Sed imperdiet. Maecenas vel sapien. Nulla at purus eu diam auctor lobortis. Donec pede eros, lacinia tincidunt, tempus eu, molestie nec, velit. Nullam ipsum odio, euismod non, aliquet nec, consequat ac, felis. Duis fermentum mauris sed justo. Suspendisse potenti. Praesent at libero sit amet ipsum imperdiet fermentum. Aliquam enim nisl, dictum id, lacinia sit amet, elementum posuere, ipsum. Integer luctus dictum libero. Pellentesque sed pede sed nisl bibendum porttitor. Phasellus tempor interdum nisi. Mauris nec magna. Phasellus massa pede, vehicula sed, ornare at, ullamcorper ut, nisl. Sed turpis nisl, hendrerit sit amet, consequat id, auctor nec, arcu. Quisque fringilla tincidunt massa. In eleifend, nulla sed mollis vestibulum, mauris orci facilisis ante, id pharetra dolor ipsum vitae sem. Integer dictum. " + + "<br/>" + + "Nunc ut odio. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec mauris tellus, dapibus vel, hendrerit vel, sollicitudin ut, ligula. Ut justo metus, accumsan placerat, ultrices sit amet, congue at, nulla. Integer in quam. Cras sollicitudin mattis magna. Vestibulum neque eros, egestas ut, tincidunt vel, ullamcorper non, ligula. Vivamus eu lacus. Donec rhoncus metus et odio. Donec est. Nulla facilisi. Suspendisse potenti. Etiam tempor pede nec ante. Vestibulum adipiscing velit vel neque. " + + "<br/>" + + "Quisque ornare erat rhoncus lectus. Donec vitae ante at enim mollis egestas. Mauris convallis. Fusce convallis, nisl eu sagittis suscipit, risus ligula aliquam libero, in imperdiet neque mi non risus. Aenean dictum ultricies risus. Praesent ut ligula vitae purus ornare auctor. Cras tellus mauris, adipiscing ac, dignissim auctor, faucibus in, sem. Cras mauris libero, pharetra sit amet, lacinia eu, vehicula eleifend, sapien. Donec ac tellus. Sed eros dui, vulputate vel, auctor pharetra, tincidunt at, ipsum. Duis at dolor ac leo condimentum pulvinar. Donec molestie, dolor et fringilla elementum, nibh nibh iaculis orci, eu elementum odio turpis et odio. Phasellus fermentum, justo id placerat egestas, arcu nunc molestie ante, non imperdiet ligula lectus sed erat. Quisque sed ligula. Sed ac nulla. Nullam massa. " + + "<br/>" + + "Sed a purus. Mauris non nibh blandit neque cursus scelerisque. Quisque ultrices sem nec dolor. Donec non diam ut dui consequat venenatis. Nullam risus massa, egestas in, facilisis tristique, molestie sed, mi. Duis euismod turpis sit amet quam. Vestibulum ornare felis eget dolor. Phasellus ac urna vel sapien lacinia adipiscing. Donec egestas felis id mi. Sed erat. Vestibulum porta vulputate neque. Maecenas scelerisque, sem id sodales pretium, sem mauris rhoncus magna, at scelerisque tortor mauris nec dui. Nullam blandit rhoncus velit. Nam accumsan, enim id vestibulum feugiat, lorem nibh placerat urna, eget laoreet diam tortor at lorem. Suspendisse imperdiet consectetur dolor. "; + private static final String[] iso3166 = new String[] { "AFGHANISTAN", "AF", + "ÅLAND ISLANDS", "AX", "ALBANIA", "AL", "ALGERIA", "DZ", + "AMERICAN SAMOA", "AS", "ANDORRA", "AD", "ANGOLA", "AO", + "ANGUILLA", "AI", "ANTARCTICA", "AQ", "ANTIGUA AND BARBUDA", "AG", + "ARGENTINA", "AR", "ARMENIA", "AM", "ARUBA", "AW", "AUSTRALIA", + "AU", "AUSTRIA", "AT", "AZERBAIJAN", "AZ", "BAHAMAS", "BS", + "BAHRAIN", "BH", "BANGLADESH", "BD", "BARBADOS", "BB", "BELARUS", + "BY", "BELGIUM", "BE", "BELIZE", "BZ", "BENIN", "BJ", "BERMUDA", + "BM", "BHUTAN", "BT", "BOLIVIA", "BO", "BOSNIA AND HERZEGOVINA", + "BA", "BOTSWANA", "BW", "BOUVET ISLAND", "BV", "BRAZIL", "BR", + "BRITISH INDIAN OCEAN TERRITORY", "IO", "BRUNEI DARUSSALAM", "BN", + "BULGARIA", "BG", "BURKINA FASO", "BF", "BURUNDI", "BI", + "CAMBODIA", "KH", "CAMEROON", "CM", "CANADA", "CA", "CAPE VERDE", + "CV", "CAYMAN ISLANDS", "KY", "CENTRAL AFRICAN REPUBLIC", "CF", + "CHAD", "TD", "CHILE", "CL", "CHINA", "CN", "CHRISTMAS ISLAND", + "CX", "COCOS (KEELING) ISLANDS", "CC", "COLOMBIA", "CO", "COMOROS", + "KM", "CONGO", "CG", "CONGO, THE DEMOCRATIC REPUBLIC OF THE", "CD", + "COOK ISLANDS", "CK", "COSTA RICA", "CR", "CÔTE D'IVOIRE", "CI", + "CROATIA", "HR", "CUBA", "CU", "CYPRUS", "CY", "CZECH REPUBLIC", + "CZ", "DENMARK", "DK", "DJIBOUTI", "DJ", "DOMINICA", "DM", + "DOMINICAN REPUBLIC", "DO", "ECUADOR", "EC", "EGYPT", "EG", + "EL SALVADOR", "SV", "EQUATORIAL GUINEA", "GQ", "ERITREA", "ER", + "ESTONIA", "EE", "ETHIOPIA", "ET", "FALKLAND ISLANDS (MALVINAS)", + "FK", "FAROE ISLANDS", "FO", "FIJI", "FJ", "FINLAND", "FI", + "FRANCE", "FR", "FRENCH GUIANA", "GF", "FRENCH POLYNESIA", "PF", + "FRENCH SOUTHERN TERRITORIES", "TF", "GABON", "GA", "GAMBIA", "GM", + "GEORGIA", "GE", "GERMANY", "DE", "GHANA", "GH", "GIBRALTAR", "GI", + "GREECE", "GR", "GREENLAND", "GL", "GRENADA", "GD", "GUADELOUPE", + "GP", "GUAM", "GU", "GUATEMALA", "GT", "GUERNSEY", "GG", "GUINEA", + "GN", "GUINEA-BISSAU", "GW", "GUYANA", "GY", "HAITI", "HT", + "HEARD ISLAND AND MCDONALD ISLANDS", "HM", + "HOLY SEE (VATICAN CITY STATE)", "VA", "HONDURAS", "HN", + "HONG KONG", "HK", "HUNGARY", "HU", "ICELAND", "IS", "INDIA", "IN", + "INDONESIA", "ID", "IRAN, ISLAMIC REPUBLIC OF", "IR", "IRAQ", "IQ", + "IRELAND", "IE", "ISLE OF MAN", "IM", "ISRAEL", "IL", "ITALY", + "IT", "JAMAICA", "JM", "JAPAN", "JP", "JERSEY", "JE", "JORDAN", + "JO", "KAZAKHSTAN", "KZ", "KENYA", "KE", "KIRIBATI", "KI", + "KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF", "KP", + "KOREA, REPUBLIC OF", "KR", "KUWAIT", "KW", "KYRGYZSTAN", "KG", + "LAO PEOPLE'S DEMOCRATIC REPUBLIC", "LA", "LATVIA", "LV", + "LEBANON", "LB", "LESOTHO", "LS", "LIBERIA", "LR", + "LIBYAN ARAB JAMAHIRIYA", "LY", "LIECHTENSTEIN", "LI", "LITHUANIA", + "LT", "LUXEMBOURG", "LU", "MACAO", "MO", + "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF", "MK", "MADAGASCAR", + "MG", "MALAWI", "MW", "MALAYSIA", "MY", "MALDIVES", "MV", "MALI", + "ML", "MALTA", "MT", "MARSHALL ISLANDS", "MH", "MARTINIQUE", "MQ", + "MAURITANIA", "MR", "MAURITIUS", "MU", "MAYOTTE", "YT", "MEXICO", + "MX", "MICRONESIA, FEDERATED STATES OF", "FM", + "MOLDOVA, REPUBLIC OF", "MD", "MONACO", "MC", "MONGOLIA", "MN", + "MONTENEGRO", "ME", "MONTSERRAT", "MS", "MOROCCO", "MA", + "MOZAMBIQUE", "MZ", "MYANMAR", "MM", "NAMIBIA", "NA", "NAURU", + "NR", "NEPAL", "NP", "NETHERLANDS", "NL", "NETHERLANDS ANTILLES", + "AN", "NEW CALEDONIA", "NC", "NEW ZEALAND", "NZ", "NICARAGUA", + "NI", "NIGER", "NE", "NIGERIA", "NG", "NIUE", "NU", + "NORFOLK ISLAND", "NF", "NORTHERN MARIANA ISLANDS", "MP", "NORWAY", + "NO", "OMAN", "OM", "PAKISTAN", "PK", "PALAU", "PW", + "PALESTINIAN TERRITORY, OCCUPIED", "PS", "PANAMA", "PA", + "PAPUA NEW GUINEA", "PG", "PARAGUAY", "PY", "PERU", "PE", + "PHILIPPINES", "PH", "PITCAIRN", "PN", "POLAND", "PL", "PORTUGAL", + "PT", "PUERTO RICO", "PR", "QATAR", "QA", "REUNION", "RE", + "ROMANIA", "RO", "RUSSIAN FEDERATION", "RU", "RWANDA", "RW", + "SAINT BARTHÉLEMY", "BL", "SAINT HELENA", "SH", + "SAINT KITTS AND NEVIS", "KN", "SAINT LUCIA", "LC", "SAINT MARTIN", + "MF", "SAINT PIERRE AND MIQUELON", "PM", + "SAINT VINCENT AND THE GRENADINES", "VC", "SAMOA", "WS", + "SAN MARINO", "SM", "SAO TOME AND PRINCIPE", "ST", "SAUDI ARABIA", + "SA", "SENEGAL", "SN", "SERBIA", "RS", "SEYCHELLES", "SC", + "SIERRA LEONE", "SL", "SINGAPORE", "SG", "SLOVAKIA", "SK", + "SLOVENIA", "SI", "SOLOMON ISLANDS", "SB", "SOMALIA", "SO", + "SOUTH AFRICA", "ZA", + "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS", "GS", "SPAIN", + "ES", "SRI LANKA", "LK", "SUDAN", "SD", "SURINAME", "SR", + "SVALBARD AND JAN MAYEN", "SJ", "SWAZILAND", "SZ", "SWEDEN", "SE", + "SWITZERLAND", "CH", "SYRIAN ARAB REPUBLIC", "SY", + "TAIWAN, PROVINCE OF CHINA", "TW", "TAJIKISTAN", "TJ", + "TANZANIA, UNITED REPUBLIC OF", "TZ", "THAILAND", "TH", + "TIMOR-LESTE", "TL", "TOGO", "TG", "TOKELAU", "TK", "TONGA", "TO", + "TRINIDAD AND TOBAGO", "TT", "TUNISIA", "TN", "TURKEY", "TR", + "TURKMENISTAN", "TM", "TURKS AND CAICOS ISLANDS", "TC", "TUVALU", + "TV", "UGANDA", "UG", "UKRAINE", "UA", "UNITED ARAB EMIRATES", + "AE", "UNITED KINGDOM", "GB", "UNITED STATES", "US", + "UNITED STATES MINOR OUTLYING ISLANDS", "UM", "URUGUAY", "UY", + "UZBEKISTAN", "UZ", "VANUATU", "VU", "VENEZUELA", "VE", "VIET NAM", + "VN", "VIRGIN ISLANDS, BRITISH", "VG", "VIRGIN ISLANDS, U.S.", + "VI", "WALLIS AND FUTUNA", "WF", "WESTERN SAHARA", "EH", "YEMEN", + "YE", "ZAMBIA", "ZM", "ZIMBABWE", "ZW" }; + public static final Object iso3166_PROPERTY_NAME = "name"; + public static final Object iso3166_PROPERTY_SHORT = "short"; + public static final Object iso3166_PROPERTY_FLAG = "flag"; + public static final Object hw_PROPERTY_NAME = "name"; + + public static final Object locale_PROPERTY_LOCALE = "locale"; + public static final Object locale_PROPERTY_NAME = "name"; + private static final String[][] locales = { { "fi", "FI", "Finnish" }, + { "de", "DE", "German" }, { "en", "US", "US - English" }, + { "sv", "SE", "Swedish" } }; + private static final String[][] hardware = { // + { "Desktops", "Dell OptiPlex GX240", "Dell OptiPlex GX260", + "Dell OptiPlex GX280" }, + { "Monitors", "Benq T190HD", "Benq T220HD", "Benq T240HD" }, + { "Laptops", "IBM ThinkPad T40", "IBM ThinkPad T43", + "IBM ThinkPad T60" } }; + + public static final Object PERSON_PROPERTY_FIRSTNAME = "First Name"; + public static final Object PERSON_PROPERTY_LASTNAME = "Last Name"; + private static final String[] firstnames = new String[] { "John", "Mary", + "Joe", "Sarah", "Jeff", "Jane", "Peter", "Marc", "Robert", "Paula", + "Lenny", "Kenny", "Nathan", "Nicole", "Laura", "Jos", "Josie", + "Linus" }; + private static final String[] lastnames = new String[] { "Torvalds", + "Smith", "Adams", "Black", "Wilson", "Richards", "Thompson", + "McGoff", "Halas", "Jones", "Beck", "Sheridan", "Picard", "Hill", + "Fielding", "Einstein" }; + + public static IndexedContainer getPersonContainer() { + IndexedContainer contactContainer = new IndexedContainer(); + contactContainer.addContainerProperty(PERSON_PROPERTY_FIRSTNAME, + String.class, ""); + contactContainer.addContainerProperty(PERSON_PROPERTY_LASTNAME, + String.class, ""); + for (int i = 0; i < 50;) { + String fn = firstnames[(int) (Math.random() * firstnames.length)]; + String ln = lastnames[(int) (Math.random() * lastnames.length)]; + String id = fn + ln; + Item item = contactContainer.addItem(id); + if (item != null) { + i++; + item.getItemProperty(PERSON_PROPERTY_FIRSTNAME).setValue(fn); + item.getItemProperty(PERSON_PROPERTY_LASTNAME).setValue(ln); + } + } + return contactContainer; + } + + public static IndexedContainer getLocaleContainer() { + IndexedContainer localeContainer = new IndexedContainer(); + localeContainer.addContainerProperty(locale_PROPERTY_LOCALE, + Locale.class, null); + localeContainer.addContainerProperty(locale_PROPERTY_NAME, + String.class, null); + for (int i = 0; i < locales.length; i++) { + String id = locales[i][2]; + Item item = localeContainer.addItem(id); + item.getItemProperty(locale_PROPERTY_LOCALE).setValue( + new Locale(locales[i][0], locales[i][1])); + item.getItemProperty(locale_PROPERTY_NAME).setValue(locales[i][2]); + } + + return localeContainer; + } + + @Deprecated + public static IndexedContainer getStaticISO3166Container() { + return getISO3166Container(); + } + + public static IndexedContainer getISO3166Container() { + IndexedContainer c = new IndexedContainer(); + fillIso3166Container(c); + return c; + } + + private static void fillIso3166Container(IndexedContainer container) { + container.addContainerProperty(iso3166_PROPERTY_NAME, String.class, + null); + container.addContainerProperty(iso3166_PROPERTY_SHORT, String.class, + null); + container.addContainerProperty(iso3166_PROPERTY_FLAG, Resource.class, + null); + for (int i = 0; i < iso3166.length; i++) { + String name = iso3166[i++]; + String id = iso3166[i]; + Item item = container.addItem(id); + item.getItemProperty(iso3166_PROPERTY_NAME).setValue(name); + item.getItemProperty(iso3166_PROPERTY_SHORT).setValue(id); + item.getItemProperty(iso3166_PROPERTY_FLAG).setValue( + new ThemeResource("flags/" + id.toLowerCase() + ".gif")); + } + container.sort(new Object[] { iso3166_PROPERTY_NAME }, + new boolean[] { true }); + } + + public static HierarchicalContainer getHardwareContainer() { + Item item = null; + int itemId = 0; // Increasing numbering for itemId:s + + // Create new container + HierarchicalContainer hwContainer = new HierarchicalContainer(); + // Create containerproperty for name + hwContainer.addContainerProperty(hw_PROPERTY_NAME, String.class, null); + for (int i = 0; i < hardware.length; i++) { + // Add new item + item = hwContainer.addItem(itemId); + // Add name property for item + item.getItemProperty(hw_PROPERTY_NAME).setValue(hardware[i][0]); + // Allow children + hwContainer.setChildrenAllowed(itemId, true); + itemId++; + for (int j = 1; j < hardware[i].length; j++) { + // Add child items + item = hwContainer.addItem(itemId); + item.getItemProperty(hw_PROPERTY_NAME).setValue(hardware[i][j]); + hwContainer.setParent(itemId, itemId - j); + hwContainer.setChildrenAllowed(itemId, false); + itemId++; + } + } + return hwContainer; + } + + public static void fillContainerWithEmailAddresses(Container c, int amount) { + for (int i = 0; i < amount; i++) { + // TODO + } + } + +} diff --git a/src/com/vaadin/demo/sampler/Feature.java b/src/com/vaadin/demo/sampler/Feature.java new file mode 100644 index 0000000000..e62951b340 --- /dev/null +++ b/src/com/vaadin/demo/sampler/Feature.java @@ -0,0 +1,203 @@ +package com.vaadin.demo.sampler; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Serializable; + +import com.vaadin.ui.Component; + +/** + * Represents one feature or sample, with associated example. + * <p> + * + * </p> + * + */ +abstract public class Feature implements Serializable { + + public static final Object PROPERTY_ICON = "Icon"; + public static final Object PROPERTY_NAME = "Name"; + public static final Object PROPERTY_DESCRIPTION = "Description"; + + private static final String MSG_SOURCE_NOT_AVAILABLE = "I'm terribly sorry," + + " but it seems the source could not be found.\n" + + "Please try adding the source folder to the classpath for your" + + " server, or tell the administrator to do so!"; + + private static final Object MUTEX = new Object(); + private String javaSource = null; + + /** + * Gets the name of this feature. Try not to exceed 25 characters too much. + * + * @return + */ + abstract public String getName(); + + /** + * Gets the description for this feature. Should describe what the example + * intends to showcase. May contain HTML. 100 words should be enough, and + * about 7 rows... + * + * @return the description + */ + abstract public String getDescription(); + + /** + * Gets related resources, i.e links to resources related to the example. + * <p> + * Good candidates are resources used to make the example (CSS, images, + * custom layouts), documentation links (reference manual), articles (e.g. + * pattern description, usability discussion). + * </p> + * <p> + * May return null, if the example has no related resources. + * </p> + * <p> + * The name of the NamedExternalResource will be shown in the UI. <br/> + * Note that Javadoc should be referenced via {@link #getRelatedAPI()}. + * </p> + * + * @see #getThemeBase() + * @return related external stuff + */ + abstract public NamedExternalResource[] getRelatedResources(); + + /** + * Gets related API resources, i.e links to javadoc of used classes. + * <p> + * Good candidates are IT Mill classes being demoed in the example, or other + * classes playing an important role in the example. + * </p> + * <p> + * May return null, if the example uses no interesting classes. + * <p> + * + * @return + */ + abstract public APIResource[] getRelatedAPI(); + + /** + * Gets related Features; the classes returned should extend Feature. + * <p> + * Good candidates are Features similar to this one, Features using the + * functionality demoed in this one, and Features being used in this one. + * </p> + * <p> + * May return null, if no other Features are related to this one. + * <p> + * + * @return + */ + abstract public Class[] getRelatedFeatures(); + + /** + * Gets the name of the icon for this feature, usually simpleName + + * extension. + * + * @return + */ + public String getIconName() { + String icon = getClass().getSimpleName() + ".png"; + return icon; + } + + /** + * Get the example instance. Override if instantiation needs parameters. + * + * @return + */ + public Component getExample() { + + String className = this.getClass().getName() + "Example"; + try { + Class<?> classObject = getClass().getClassLoader().loadClass( + className); + return (Component) classObject.newInstance(); + } catch (ClassNotFoundException e) { + return null; + } catch (InstantiationException e) { + return null; + } catch (IllegalAccessException e) { + return null; + } + + } + + public String getSource() { + synchronized (MUTEX) { + if (javaSource == null) { + StringBuffer src = new StringBuffer(); + try { + /* + * Use package name + class name so the class loader won't + * have to guess the package name. + */ + String resourceName = "/" + + getExample().getClass().getName().replace('.', + '/') + ".java"; + InputStream is = getClass().getResourceAsStream( + resourceName); + BufferedReader bis = new BufferedReader( + new InputStreamReader(is)); + for (String line = bis.readLine(); null != line; line = bis + .readLine()) { + src.append(line); + src.append("\n"); + } + javaSource = src.toString(); + } catch (Exception e) { + System.err.println(MSG_SOURCE_NOT_AVAILABLE + " (" + + getPathName() + ")"); + javaSource = MSG_SOURCE_NOT_AVAILABLE; + } + } + } + return javaSource; + + } + + public String getSourceHTML() { + return getSource(); + } + + /** + * Gets the name used when resolving the path for this feature. Usually no + * need to override. + * + * @return + */ + public String getPathName() { + return getClass().getSimpleName(); + } + + /** + * Gets the base url used to reference theme resources. + * + * @return + */ + protected static final String getThemeBase() { + return SamplerApplication.getThemeBase(); + } + + @Override + public String toString() { + return getName(); + } + + @Override + public boolean equals(Object obj) { + // A feature is uniquely identified by its class name + if (obj == null) { + return false; + } + return obj.getClass() == getClass(); + } + + @Override + public int hashCode() { + // A feature is uniquely identified by its class name + return getClass().hashCode(); + } +}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/FeatureSet.java b/src/com/vaadin/demo/sampler/FeatureSet.java new file mode 100644 index 0000000000..80a8e83206 --- /dev/null +++ b/src/com/vaadin/demo/sampler/FeatureSet.java @@ -0,0 +1,543 @@ +package com.vaadin.demo.sampler; + +import java.util.Collections; +import java.util.LinkedList; + +import com.vaadin.data.Item; +import com.vaadin.data.Property; +import com.vaadin.data.util.HierarchicalContainer; +import com.vaadin.demo.sampler.features.accordions.AccordionDisabled; +import com.vaadin.demo.sampler.features.accordions.AccordionIcons; +import com.vaadin.demo.sampler.features.blueprints.ProminentPrimaryAction; +import com.vaadin.demo.sampler.features.buttons.ButtonLink; +import com.vaadin.demo.sampler.features.buttons.ButtonPush; +import com.vaadin.demo.sampler.features.buttons.ButtonSwitch; +import com.vaadin.demo.sampler.features.commons.Errors; +import com.vaadin.demo.sampler.features.commons.Icons; +import com.vaadin.demo.sampler.features.commons.Tooltips; +import com.vaadin.demo.sampler.features.commons.Validation; +import com.vaadin.demo.sampler.features.dates.DateInline; +import com.vaadin.demo.sampler.features.dates.DateLocale; +import com.vaadin.demo.sampler.features.dates.DatePopup; +import com.vaadin.demo.sampler.features.dates.DateResolution; +import com.vaadin.demo.sampler.features.form.FormBasic; +import com.vaadin.demo.sampler.features.layouts.ApplicationLayout; +import com.vaadin.demo.sampler.features.layouts.CustomLayouts; +import com.vaadin.demo.sampler.features.layouts.ExpandingComponent; +import com.vaadin.demo.sampler.features.layouts.GridLayoutBasic; +import com.vaadin.demo.sampler.features.layouts.HorizontalLayoutBasic; +import com.vaadin.demo.sampler.features.layouts.LayoutAlignment; +import com.vaadin.demo.sampler.features.layouts.LayoutMargin; +import com.vaadin.demo.sampler.features.layouts.LayoutSpacing; +import com.vaadin.demo.sampler.features.layouts.SplitPanelBasic; +import com.vaadin.demo.sampler.features.layouts.VerticalLayoutBasic; +import com.vaadin.demo.sampler.features.layouts.WebLayout; +import com.vaadin.demo.sampler.features.link.LinkCurrentWindow; +import com.vaadin.demo.sampler.features.link.LinkNoDecorations; +import com.vaadin.demo.sampler.features.link.LinkSizedWindow; +import com.vaadin.demo.sampler.features.notifications.NotificationCustom; +import com.vaadin.demo.sampler.features.notifications.NotificationError; +import com.vaadin.demo.sampler.features.notifications.NotificationHumanized; +import com.vaadin.demo.sampler.features.notifications.NotificationTray; +import com.vaadin.demo.sampler.features.notifications.NotificationWarning; +import com.vaadin.demo.sampler.features.panels.PanelBasic; +import com.vaadin.demo.sampler.features.panels.PanelLight; +import com.vaadin.demo.sampler.features.selects.ComboBoxContains; +import com.vaadin.demo.sampler.features.selects.ComboBoxInputPrompt; +import com.vaadin.demo.sampler.features.selects.ComboBoxNewItems; +import com.vaadin.demo.sampler.features.selects.ComboBoxPlain; +import com.vaadin.demo.sampler.features.selects.ComboBoxStartsWith; +import com.vaadin.demo.sampler.features.selects.ListSelectMultiple; +import com.vaadin.demo.sampler.features.selects.ListSelectSingle; +import com.vaadin.demo.sampler.features.selects.NativeSelection; +import com.vaadin.demo.sampler.features.selects.TwinColumnSelect; +import com.vaadin.demo.sampler.features.table.TableActions; +import com.vaadin.demo.sampler.features.table.TableCellStyling; +import com.vaadin.demo.sampler.features.table.TableColumnAlignment; +import com.vaadin.demo.sampler.features.table.TableColumnCollapsing; +import com.vaadin.demo.sampler.features.table.TableColumnHeaders; +import com.vaadin.demo.sampler.features.table.TableColumnReordering; +import com.vaadin.demo.sampler.features.table.TableHeaderIcons; +import com.vaadin.demo.sampler.features.table.TableLazyLoading; +import com.vaadin.demo.sampler.features.table.TableMouseEvents; +import com.vaadin.demo.sampler.features.table.TableRowHeaders; +import com.vaadin.demo.sampler.features.table.TableRowStyling; +import com.vaadin.demo.sampler.features.table.TableSorting; +import com.vaadin.demo.sampler.features.tabsheets.TabSheetDisabled; +import com.vaadin.demo.sampler.features.tabsheets.TabSheetIcons; +import com.vaadin.demo.sampler.features.tabsheets.TabSheetScrolling; +import com.vaadin.demo.sampler.features.text.LabelPlain; +import com.vaadin.demo.sampler.features.text.LabelPreformatted; +import com.vaadin.demo.sampler.features.text.LabelRich; +import com.vaadin.demo.sampler.features.text.RichTextEditor; +import com.vaadin.demo.sampler.features.text.TextArea; +import com.vaadin.demo.sampler.features.text.TextFieldInputPrompt; +import com.vaadin.demo.sampler.features.text.TextFieldSecret; +import com.vaadin.demo.sampler.features.text.TextFieldSingle; +import com.vaadin.demo.sampler.features.trees.TreeActions; +import com.vaadin.demo.sampler.features.trees.TreeMouseEvents; +import com.vaadin.demo.sampler.features.trees.TreeMultiSelect; +import com.vaadin.demo.sampler.features.trees.TreeSingleSelect; +import com.vaadin.demo.sampler.features.windows.NativeWindow; +import com.vaadin.demo.sampler.features.windows.Subwindow; +import com.vaadin.demo.sampler.features.windows.SubwindowAutoSized; +import com.vaadin.demo.sampler.features.windows.SubwindowClose; +import com.vaadin.demo.sampler.features.windows.SubwindowModal; +import com.vaadin.demo.sampler.features.windows.SubwindowPositioned; +import com.vaadin.demo.sampler.features.windows.SubwindowSized; + +/** + * Contains the FeatureSet implementation and the structure for the feature + * 'tree'. + * <p> + * Each set is implemented as it's own class to facilitate linking to sets in + * the same way as linking to individual features. + * </p> + * + */ +public class FeatureSet extends Feature { + + /* + * MAIN structure; root is always a FeatureSet that is not shown + */ + static final FeatureSet FEATURES = new FeatureSet("All", new Feature[] { + // Main sets + // new Blueprints(), disabled for now, until more samples are ready + new Components(), // + }); + + /* + * TOP LEVEL + */ + public static class Blueprints extends FeatureSet { + public Blueprints() { + super("Blueprints", new Feature[] { + // Blueprints + new ProminentPrimaryAction(), // + }); + } + } + + public static class Components extends FeatureSet { + public Components() { + super("Components", new Feature[] { + // + new Common(), // + new Accordions(), // + new Buttons(), // + new Dates(), // + new Forms(), // + new Layouts(), // + new Links(), // + new Notifications(), // + new Panels(), // + new Selects(), // + new Tables(),// + new Tabsheets(), // + new Texts(), // + new TextFields(), // + new Trees(), // + new Windows(), // + }); + } + } + + /* + * LEVEL 2 + */ + public static class Buttons extends FeatureSet { + public Buttons() { + super( + "Buttons", + "Buttons", + "A button is one of the fundamental building blocks of any application.", + new Feature[] { + // + new ButtonPush(), // basic + new ButtonLink(), // link + new ButtonSwitch(), // switch/checkbox + + }); + } + } + + public static class Links extends FeatureSet { + public Links() { + super( + "Links", + "Links", + "An external link. This is the basic HTML-style link, changing the url of the browser w/o triggering a server-side event (like the link-styled Button).", + new Feature[] { + // + new LinkCurrentWindow(), // basic + new LinkNoDecorations(), // new win + new LinkSizedWindow(), // new win + + }); + } + } + + public static class Notifications extends FeatureSet { + public Notifications() { + super( + "Notifications", + "Notifications", + "Notifications are lightweight informational messages, used to inform the user of various events.", + new Feature[] { + // + new NotificationHumanized(), // humanized + new NotificationWarning(), // warning + new NotificationTray(), // tray + new NotificationError(), // error + new NotificationCustom(), // error + }); + } + } + + public static class Common extends FeatureSet { + public Common() { + super("Common", new Feature[] { + // + new Tooltips(), // + new Icons(), // + new Errors(), // + new Validation(), // TODO this should point to Form instead + }); + } + } + + public static class Selects extends FeatureSet { + public Selects() { + super("Selects", new Feature[] { + // + new ListSelectSingle(), // + new ListSelectMultiple(), // + new TwinColumnSelect(), // + new NativeSelection(), // + new ComboBoxPlain(), // + new ComboBoxInputPrompt(), // + new ComboBoxStartsWith(), // + new ComboBoxContains(), // + new ComboBoxNewItems(), // + + }); + } + } + + public static class Layouts extends FeatureSet { + public Layouts() { + super( + "Layouts", + "Layouts", + "Making a usable, good looking, dynamic layout can be tricky, but with the right tools almost anything is possible.<br/>", + new Feature[] { + // + new LayoutMargin(), // + new LayoutSpacing(), // + new VerticalLayoutBasic(), // + new HorizontalLayoutBasic(), // + new GridLayoutBasic(), // + new LayoutAlignment(), // + new ExpandingComponent(), // + new SplitPanelBasic(), // + new ApplicationLayout(), // + new WebLayout(), // + new CustomLayouts(), // + }); + } + } + + public static class Tabsheets extends FeatureSet { + public Tabsheets() { + super( + "Tabsheets", + "Tabsheets", + "A Tabsheet organizes multiple components so that only the one component associated with the currently selected 'tab' is shown. Typically a tab will contain a Layout, which in turn may contain many components.", + new Feature[] { + // + new TabSheetIcons(), // + new TabSheetScrolling(), // + new TabSheetDisabled(), // + }); + } + } + + public static class Accordions extends FeatureSet { + public Accordions() { + super( + "Accordions", + "Accordions", + "An accordion component is a specialized case of a tabsheet." + + " Within an accordion, the tabs are organized vertically," + + " and the content will be shown directly below the tab.", + new Feature[] { + // + new AccordionIcons(), // + new AccordionDisabled(), // + }); + } + } + + public static class Panels extends FeatureSet { + public Panels() { + super( + "Panels", + "Panels", + "Panel is a simple container that supports scrolling.<br/>It's internal layout (by default VerticalLayout) can be configured or exchanged to get desired results. Components that are added to the Panel will in effect be added to the layout.", + new Feature[] { + // + new PanelBasic(), // + new PanelLight(), // + }); + } + } + + public static class Forms extends FeatureSet { + public Forms() { + super("Forms", "Forms", + "The Form -component provides a convenient way to organize" + + " related fields visually.", new Feature[] { + // + new FormBasic(), // + }); + } + } + + public static class Windows extends FeatureSet { + public Windows() { + super( + "Windows", + "Windows", + "Windows can (for instance) organize the UI, save space (popup windows), focus attention (modal windows), or provide multiple views for the same data for multitasking or dual screen setups (native browser windows).", + new Feature[] { + // + new Subwindow(), // + new SubwindowModal(), // + new SubwindowAutoSized(), // + new SubwindowSized(), // + new SubwindowPositioned(), // + new SubwindowClose(), // + new NativeWindow(), // + }); + } + } + + public static class Tables extends FeatureSet { + public Tables() { + super( + "Table (Grid)", + "Table (Grid)", + "A Table, also known as a (Data)Grid, can be used to show data in a tabular fashion. It's well suited for showing large datasets.", + new Feature[] { + // + new TableHeaderIcons(), // + new TableColumnHeaders(), // + new TableColumnReordering(), // + new TableColumnCollapsing(), // + new TableColumnAlignment(), // + new TableCellStyling(), // + new TableSorting(), // + new TableRowHeaders(), // + new TableRowStyling(), // + new TableActions(), // + new TableMouseEvents(), // + new TableLazyLoading(), // + }); + } + } + + public static class Texts extends FeatureSet { + public Texts() { + super( + "Texts", + "Texts", + "A label is a simple component that allows you to add (optionally formatted) text components to your application.", + new Feature[] { + // + new LabelPlain(), // + new LabelPreformatted(), // + new LabelRich(), // + }); + } + } + + public static class TextFields extends FeatureSet { + public TextFields() { + super( + "TextFields", + "Text inputs", + "Text inputs are probably the most needed components in any application that require user input or editing.", + new Feature[] { + // + new TextFieldSingle(), // + new TextFieldSecret(), // + new TextFieldInputPrompt(), // + new TextArea(), // + new RichTextEditor(), // + }); + } + } + + public static class Trees extends FeatureSet { + public Trees() { + super( + "Trees", + "Trees", + "The Tree component provides a natural way to represent data that has hierarchical relationships, such as filesystems or message threads.", + new Feature[] { + // + new TreeSingleSelect(), // + new TreeMultiSelect(), // + new TreeActions(), // + new TreeMouseEvents(), // + }); + } + } + + public static class Dates extends FeatureSet { + public Dates() { + super( + "Dates", + "Dates", + "The DateField component can be used to produce various date and time input fields with different resolutions. The date and time format used with this component is reported to the Toolkit by the browser.", + new Feature[] { + // + new DatePopup(), // + new DateInline(), // + new DateLocale(), // + new DateResolution(), // + }); + } + } + + // ---------------------------------------------------------- + /* + * FeatureSet implementation follows. + */ + + private String pathname; + + private String name; + + private String desc; + + private String icon = "folder.gif"; + + private Feature[] content; + + private HierarchicalContainer container = null; + + private boolean containerRecursive = false; + + FeatureSet(String pathname, Feature[] content) { + this(pathname, pathname, "", content); + } + + FeatureSet(String pathname, String name, Feature[] content) { + this(pathname, name, "", content); + } + + FeatureSet(String pathname, String name, String desc, Feature[] content) { + this.pathname = pathname; + this.name = name; + this.desc = desc; + this.content = content; + } + + Feature[] getFeatures() { + return content; + } + + Feature getFeatureByPath(String path) { + LinkedList<String> parts = new LinkedList<String>(); + Collections.addAll(parts, path.split("/")); + FeatureSet f = this; + while (f != null) { + Feature[] fs = f.getFeatures(); + f = null; // break while if no new found + String part = parts.remove(0); + for (int i = 0; i < fs.length; i++) { + if (fs[i].getPathName().equalsIgnoreCase(part)) { + if (parts.isEmpty()) { + return fs[i]; + } else if (fs[i] instanceof FeatureSet) { + f = (FeatureSet) fs[i]; + break; + } else { + return null; + } + } + } + } + return null; + } + + HierarchicalContainer getContainer(boolean recurse) { + if (container == null || containerRecursive != recurse) { + container = new HierarchicalContainer(); + container.addContainerProperty(PROPERTY_NAME, String.class, ""); + container.addContainerProperty(PROPERTY_DESCRIPTION, String.class, + ""); + // fill + addFeatures(this, container, recurse); + } + return container; + } + + private void addFeatures(FeatureSet f, HierarchicalContainer c, + boolean recurse) { + Feature[] features = f.getFeatures(); + for (int i = 0; i < features.length; i++) { + Item item = c.addItem(features[i]); + Property property = item.getItemProperty(PROPERTY_NAME); + property.setValue(features[i].getName()); + property = item.getItemProperty(PROPERTY_DESCRIPTION); + property.setValue(features[i].getDescription()); + if (recurse) { + c.setParent(features[i], f); + if (features[i] instanceof FeatureSet) { + addFeatures((FeatureSet) features[i], c, recurse); + } + } + if (!(features[i] instanceof FeatureSet)) { + c.setChildrenAllowed(features[i], false); + } + } + } + + @Override + public String getDescription() { + return desc; + } + + @Override + public String getPathName() { + return pathname; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getIconName() { + return icon; + } + + @Override + public APIResource[] getRelatedAPI() { + return null; + } + + @Override + public Class[] getRelatedFeatures() { + return null; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/FeatureView.java b/src/com/vaadin/demo/sampler/FeatureView.java new file mode 100644 index 0000000000..02ff91117b --- /dev/null +++ b/src/com/vaadin/demo/sampler/FeatureView.java @@ -0,0 +1,258 @@ +package com.vaadin.demo.sampler; + +import java.util.HashMap; + +import com.vaadin.demo.sampler.ActiveLink.LinkActivatedEvent; +import com.vaadin.demo.sampler.ActiveLink.LinkActivatedListener; +import com.vaadin.demo.sampler.SamplerApplication.SamplerWindow; +import com.vaadin.terminal.ExternalResource; +import com.vaadin.terminal.ThemeResource; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Link; +import com.vaadin.ui.Panel; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; +import com.vaadin.ui.Button.ClickEvent; + +public class FeatureView extends HorizontalLayout { + + private static final String MSG_SHOW_SRC = "Show Javaâ„¢ source »"; + + private Panel right; + private VerticalLayout left; + + private VerticalLayout controls; + + private ActiveLink showSrc; + + private HashMap<Feature, Component> exampleCache = new HashMap<Feature, Component>(); + + private Feature currentFeature; + + private Window srcWindow; + + public FeatureView() { + + setWidth("100%"); + setMargin(true); + setSpacing(true); + setStyleName("sample-view"); + + left = new VerticalLayout(); + left.setWidth("100%"); + left.setSpacing(true); + left.setMargin(false); + addComponent(left); + setExpandRatio(left, 1); + + right = new Panel(); + right.getLayout().setMargin(true, false, false, false); + right.setStyleName(Panel.STYLE_LIGHT); + right.addStyleName("feature-info"); + right.setWidth("369px"); + addComponent(right); + + controls = new VerticalLayout(); + controls.setWidth("100%"); + controls.setStyleName("feature-controls"); + + HorizontalLayout controlButtons = new HorizontalLayout(); + controls.addComponent(controlButtons); + + Button resetExample = new Button("Reset example", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + resetExample(); + } + }); + resetExample.setStyleName(Button.STYLE_LINK); + resetExample.addStyleName("showcode"); + controlButtons.addComponent(resetExample); + + controlButtons.addComponent(new Label("|")); + + showSrc = new ActiveLink(); + showSrc + .setDescription("Right / middle / ctrl / shift -click for browser window/tab"); + showSrc.addListener(new LinkActivatedListener() { + + public void linkActivated(LinkActivatedEvent event) { + if (!event.isLinkOpened()) { + showSource(currentFeature.getSource()); + } + + } + + }); + showSrc.setCaption(MSG_SHOW_SRC); + showSrc.addStyleName("showcode"); + showSrc.setTargetBorder(Link.TARGET_BORDER_NONE); + controlButtons.addComponent(showSrc); + + } + + public void showSource(String source) { + if (srcWindow == null) { + srcWindow = new Window("Javaâ„¢ source"); + ((VerticalLayout) srcWindow.getLayout()).setSizeUndefined(); + srcWindow.setWidth("70%"); + srcWindow.setHeight("60%"); + srcWindow.setPositionX(100); + srcWindow.setPositionY(100); + } + srcWindow.removeAllComponents(); + srcWindow.addComponent(new CodeLabel(source)); + + if (srcWindow.getParent() == null) { + getWindow().addWindow(srcWindow); + } + } + + private void resetExample() { + if (currentFeature != null) { + Feature f = currentFeature; + currentFeature = null; + exampleCache.remove(f); + setFeature(f); + } + } + + public void setFeature(Feature feature) { + if (feature != currentFeature) { + currentFeature = feature; + right.removeAllComponents(); + left.removeAllComponents(); + + left.addComponent(controls); + controls.setCaption(feature.getName()); + + left.addComponent(getExampleFor(feature)); + + right.setCaption("Description and Resources"); + + final Feature parent = (Feature) SamplerApplication + .getAllFeatures().getParent(feature); + String desc = parent.getDescription(); + boolean hasParentDesc = false; + + final Label parentLabel = new Label(parent.getDescription()); + if (desc != null && desc != "") { + parentLabel.setContentMode(Label.CONTENT_XHTML); + right.addComponent(parentLabel); + hasParentDesc = true; + } + + desc = feature.getDescription(); + if (desc != null && desc != "") { + // Sample description uses additional decorations if a parent + // description is found + final Label l = new Label( + "<div class=\"outer-deco\"><div class=\"deco\"><span class=\"deco\"></span>" + + desc + "</div></div>", Label.CONTENT_XHTML); + right.addComponent(l); + if (hasParentDesc) { + l.setStyleName("sample-description"); + } else { + l.setStyleName("description"); + } + } + + { // open src in new window -link + String path = SamplerApplication.getPathFor(currentFeature); + showSrc.setTargetName(path); + showSrc.setResource(new ExternalResource(getApplication() + .getURL() + + "src/" + path)); + } + + NamedExternalResource[] resources = feature.getRelatedResources(); + if (resources != null) { + VerticalLayout res = new VerticalLayout(); + Label caption = new Label("<span>Additional Resources</span>", + Label.CONTENT_XHTML); + caption.setStyleName("section"); + caption.setWidth("100%"); + res.addComponent(caption); + res.setMargin(false, false, true, false); + for (NamedExternalResource r : resources) { + final Link l = new Link(r.getName(), r); + l + .setIcon(new ThemeResource( + "../default/icons/16/note.png")); + res.addComponent(l); + } + right.addComponent(res); + } + + APIResource[] apis = feature.getRelatedAPI(); + if (apis != null) { + VerticalLayout api = new VerticalLayout(); + Label caption = new Label("<span>API Documentation</span>", + Label.CONTENT_XHTML); + caption.setStyleName("section"); + caption.setWidth("100%"); + api.addComponent(caption); + api.setMargin(false, false, true, false); + for (APIResource r : apis) { + final Link l = new Link(r.getName(), r); + l.setIcon(new ThemeResource( + "../default/icons/16/document-txt.png")); + api.addComponent(l); + } + right.addComponent(api); + } + + Class[] features = feature.getRelatedFeatures(); + if (features != null) { + VerticalLayout rel = new VerticalLayout(); + Label caption = new Label("<span>Related Samples</span>", + Label.CONTENT_XHTML); + caption.setStyleName("section"); + caption.setWidth("100%"); + rel.addComponent(caption); + rel.setMargin(false, false, true, false); + for (Class c : features) { + final Feature f = SamplerApplication.getFeatureFor(c); + if (f != null) { + String path = SamplerApplication.getPathFor(f); + ActiveLink al = new ActiveLink(f.getName(), + new ExternalResource(getApplication().getURL() + + "#" + path)); + al.setIcon(new ThemeResource( + (f instanceof FeatureSet ? "icons/category.gif" + : "icons/sample.png"))); + al.addListener(new LinkActivatedListener() { + public void linkActivated(LinkActivatedEvent event) { + if (event.isLinkOpened()) { + getWindow() + .showNotification( + f.getName() + + " opened if new window/tab"); + } else { + SamplerWindow w = (SamplerWindow) getWindow(); + w.setFeature(f); + } + } + }); + rel.addComponent(al); + } + } + right.addComponent(rel); + } + } + + } + + private Component getExampleFor(Feature f) { + Component ex = exampleCache.get(f); + if (ex == null) { + ex = f.getExample(); + exampleCache.put(f, ex); + } + return ex; + } + +} diff --git a/src/com/vaadin/demo/sampler/GoogleAnalytics.java b/src/com/vaadin/demo/sampler/GoogleAnalytics.java new file mode 100644 index 0000000000..345844cee6 --- /dev/null +++ b/src/com/vaadin/demo/sampler/GoogleAnalytics.java @@ -0,0 +1,54 @@ +package com.vaadin.demo.sampler; + +import com.vaadin.terminal.PaintException; +import com.vaadin.terminal.PaintTarget; +import com.vaadin.ui.AbstractComponent; + +public class GoogleAnalytics extends AbstractComponent { + + private String trackerId; + private String pageId; + private String domainName; + + private static final String TAG = "googleanalytics"; + + public GoogleAnalytics(String trackerId) { + this.trackerId = trackerId; + } + + public GoogleAnalytics(String trackerId, String domainName) { + this(trackerId); + this.domainName = domainName; + } + + @Override + public String getTag() { + return TAG; + } + + public String getTrackerId() { + return trackerId; + } + + public String getDomainName() { + return domainName; + } + + public void trackPageview(String pageId) { + this.pageId = pageId; + requestRepaint(); + } + + @Override + public void paintContent(PaintTarget target) throws PaintException { + super.paintContent(target); + target.addAttribute("trackerid", trackerId); + if (pageId != null) { + target.addAttribute("pageid", pageId); + } + if (domainName != null) { + target.addAttribute("domain", domainName); + } + } + +} diff --git a/src/com/vaadin/demo/sampler/ModeSwitch.java b/src/com/vaadin/demo/sampler/ModeSwitch.java new file mode 100644 index 0000000000..c6565c0c61 --- /dev/null +++ b/src/com/vaadin/demo/sampler/ModeSwitch.java @@ -0,0 +1,106 @@ +package com.vaadin.demo.sampler; + +import java.util.HashMap; +import java.util.Iterator; + +import com.vaadin.terminal.Resource; +import com.vaadin.ui.Button; +import com.vaadin.ui.CustomComponent; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Button.ClickEvent; + +@SuppressWarnings("serial") +public class ModeSwitch extends CustomComponent { + + GridLayout layout = new GridLayout(3, 1); + + HashMap<Object, Button> idToButton = new HashMap<Object, Button>(); + Object mode = null; + + public ModeSwitch() { + setSizeUndefined(); + layout.setSizeUndefined(); + setCompositionRoot(layout); + setStyleName("ModeSwitch"); + } + + public Object getMode() { + return mode; + } + + public void setMode(Object mode) { + if (idToButton.containsKey(mode)) { + this.mode = mode; + updateStyles(); + fireEvent(new ModeSwitchEvent()); + } + } + + public void addListener(ModeSwitchListener listener) { + super.addListener(listener); + } + + public void addMode(Object id, String caption, String description, + Resource icon) { + if (idToButton.containsKey(id)) { + removeMode(id); + } + Button b = new Button(); + if (caption != null) { + b.setCaption(caption); + } + if (description != null) { + b.setDescription(description); + } + if (icon != null) { + b.setIcon(icon); + } + b.setData(id); + b.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + setMode(event.getButton().getData()); + } + }); + idToButton.put(id, b); + layout.addComponent(b); + updateStyles(); + } + + public void removeMode(Object id) { + Button b = idToButton.remove(id); + layout.removeComponent(b); + updateStyles(); + } + + private void updateStyles() { + boolean first = true; + for (Iterator it = layout.getComponentIterator(); it.hasNext();) { + Button b = (Button) it.next(); + String isOn = (b.getData() == mode ? "-on" : ""); + if (first) { + first = false; + b.setStyleName("first" + isOn); + } else if (!it.hasNext()) { + b.setStyleName("last" + isOn); + } else { + b.setStyleName("mid" + isOn); + } + } + } + + public interface ModeSwitchListener extends Listener { + + } + + public class ModeSwitchEvent extends Event { + + public ModeSwitchEvent() { + super(ModeSwitch.this); + } + + public Object getMode() { + return ModeSwitch.this.getMode(); + } + } + +} diff --git a/src/com/vaadin/demo/sampler/NamedExternalResource.java b/src/com/vaadin/demo/sampler/NamedExternalResource.java new file mode 100644 index 0000000000..16573f2ebb --- /dev/null +++ b/src/com/vaadin/demo/sampler/NamedExternalResource.java @@ -0,0 +1,18 @@ +package com.vaadin.demo.sampler; + +import com.vaadin.terminal.ExternalResource; + +public class NamedExternalResource extends ExternalResource { + + private String name; + + public NamedExternalResource(String name, String sourceURL) { + super(sourceURL); + this.name = name; + } + + public String getName() { + return name; + } + +} diff --git a/src/com/vaadin/demo/sampler/SamplerApplication.java b/src/com/vaadin/demo/sampler/SamplerApplication.java new file mode 100644 index 0000000000..bab73cd6a9 --- /dev/null +++ b/src/com/vaadin/demo/sampler/SamplerApplication.java @@ -0,0 +1,777 @@ +package com.vaadin.demo.sampler; + +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; + +import com.vaadin.Application; +import com.vaadin.data.Property; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.util.HierarchicalContainer; +import com.vaadin.data.util.ObjectProperty; +import com.vaadin.demo.sampler.ActiveLink.LinkActivatedEvent; +import com.vaadin.demo.sampler.ModeSwitch.ModeSwitchEvent; +import com.vaadin.event.ItemClickEvent; +import com.vaadin.event.ItemClickEvent.ItemClickListener; +import com.vaadin.terminal.ClassResource; +import com.vaadin.terminal.DownloadStream; +import com.vaadin.terminal.ExternalResource; +import com.vaadin.terminal.Resource; +import com.vaadin.terminal.ThemeResource; +import com.vaadin.terminal.URIHandler; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.CustomComponent; +import com.vaadin.ui.Embedded; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Panel; +import com.vaadin.ui.PopupView; +import com.vaadin.ui.SplitPanel; +import com.vaadin.ui.Table; +import com.vaadin.ui.Tree; +import com.vaadin.ui.UriFragmentUtility; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.PopupView.PopupVisibilityEvent; +import com.vaadin.ui.UriFragmentUtility.FragmentChangedEvent; +import com.vaadin.ui.UriFragmentUtility.FragmentChangedListener; + +@SuppressWarnings("serial") +public class SamplerApplication extends Application { + + // All features in one container + private static final HierarchicalContainer allFeatures = FeatureSet.FEATURES + .getContainer(true); + + // init() inits + private static final String THEME_NAME = "sampler"; + + // used when trying to guess theme location + private static String APP_URL = null; + + @Override + public void init() { + setTheme("sampler"); + setMainWindow(new SamplerWindow()); + APP_URL = getURL().toString(); + } + + /** + * Tries to guess theme location. + * + * @return + */ + public static String getThemeBase() { + try { + URI uri = new URI(APP_URL + "../ITMILL/themes/" + THEME_NAME + "/"); + return uri.normalize().toString(); + } catch (Exception e) { + System.err.println("Theme location could not be resolved:" + e); + } + return "/ITMILL/themes/" + THEME_NAME + "/"; + } + + // Supports multiple browser windows + @Override + public Window getWindow(String name) { + Window w = super.getWindow(name); + if (w == null) { + if (name.startsWith("src")) { + w = new SourceWindow(); + } else { + w = new SamplerWindow(); + w.setName(name); + } + + addWindow(w); + } + return w; + + } + + /** + * Gets absolute path for given Feature + * + * @param f + * the Feature whose path to get, of null if not found + * @return the path of the Feature + */ + public static String getPathFor(Feature f) { + if (f == null) { + return ""; + } + if (allFeatures.containsId(f)) { + String path = f.getPathName(); + f = (Feature) allFeatures.getParent(f); + while (f != null) { + path = f.getPathName() + "/" + path; + f = (Feature) allFeatures.getParent(f); + } + return path; + } + return ""; + } + + /** + * Gets the instance for the given Feature class, e.g DummyFeature.class. + * + * @param clazz + * @return + */ + public static Feature getFeatureFor(Class clazz) { + for (Iterator it = allFeatures.getItemIds().iterator(); it.hasNext();) { + Feature f = (Feature) it.next(); + if (f.getClass() == clazz) { + return f; + } + } + return null; + } + + /** + * The main window for Sampler, contains the full application UI. + * + */ + class SamplerWindow extends Window { + private FeatureList currentList = new FeatureGrid(); + private FeatureView featureView = new FeatureView(); + private ObjectProperty currentFeature = new ObjectProperty(null, + Feature.class); + + private ModeSwitch mode; + + private SplitPanel mainSplit; + private Tree navigationTree; + // itmill: UA-658457-6 + private GoogleAnalytics webAnalytics = new GoogleAnalytics( + "UA-658457-6", "none"); + // "backbutton" + UriFragmentUtility uriFragmentUtility = new UriFragmentUtility(); + + // breadcrumbs + BreadCrumbs breadcrumbs = new BreadCrumbs(); + + Button previousSample; + Button nextSample; + private ComboBox search; + + @Override + public void detach() { + super.detach(); + + search.setContainerDataSource(null); + navigationTree.setContainerDataSource(null); + } + + SamplerWindow() { + // Main top/expanded-bottom layout + VerticalLayout mainExpand = new VerticalLayout(); + setLayout(mainExpand); + setSizeFull(); + mainExpand.setSizeFull(); + + // topbar (navigation) + HorizontalLayout nav = new HorizontalLayout(); + mainExpand.addComponent(nav); + nav.setHeight("44px"); + nav.setWidth("100%"); + nav.setStyleName("topbar"); + nav.setSpacing(true); + nav.setMargin(false, true, false, false); + + // Upper left logo + Component logo = createLogo(); + nav.addComponent(logo); + nav.setComponentAlignment(logo, Alignment.MIDDLE_LEFT); + + // Breadcrumbs + nav.addComponent(breadcrumbs); + nav.setExpandRatio(breadcrumbs, 1); + nav.setComponentAlignment(breadcrumbs, Alignment.MIDDLE_LEFT); + + // invisible analytics -component + nav.addComponent(webAnalytics); + + // "backbutton" + nav.addComponent(uriFragmentUtility); + uriFragmentUtility.addListener(new FragmentChangedListener() { + public void fragmentChanged(FragmentChangedEvent source) { + String frag = source.getUriFragmentUtility().getFragment(); + setFeature(frag); + } + }); + + // Main left/right split; hidden menu tree + mainSplit = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); + mainSplit.setSizeFull(); + mainSplit.setStyleName("main-split"); + mainExpand.addComponent(mainSplit); + mainExpand.setExpandRatio(mainSplit, 1); + + // List/grid/coverflow + mode = createModeSwitch(); + mode.setMode(currentList); + nav.addComponent(mode); + nav.setComponentAlignment(mode, Alignment.MIDDLE_LEFT); + + // Layouts for top area buttons + HorizontalLayout quicknav = new HorizontalLayout(); + HorizontalLayout arrows = new HorizontalLayout(); + nav.addComponent(quicknav); + nav.addComponent(arrows); + nav.setComponentAlignment(quicknav, Alignment.MIDDLE_LEFT); + nav.setComponentAlignment(arrows, Alignment.MIDDLE_LEFT); + quicknav.setStyleName("segment"); + arrows.setStyleName("segment"); + + // Previous sample + previousSample = createPrevButton(); + arrows.addComponent(previousSample); + // Next sample + nextSample = createNextButton(); + arrows.addComponent(nextSample); + // "Search" combobox + // TODO add input prompt + Component searchComponent = createSearch(); + quicknav.addComponent(searchComponent); + + // Menu tree, initially hidden + navigationTree = createMenuTree(); + mainSplit.setFirstComponent(navigationTree); + + // Show / hide tree + Component treeSwitch = createTreeSwitch(); + quicknav.addComponent(treeSwitch); + + addListener(new CloseListener() { + public void windowClose(CloseEvent e) { + if (getMainWindow() != SamplerWindow.this) { + SamplerApplication.this + .removeWindow(SamplerWindow.this); + } + } + }); + } + + @SuppressWarnings("unchecked") + public void removeSubwindows() { + Collection<Window> wins = getChildWindows(); + if (null != wins) { + for (Window w : wins) { + removeWindow(w); + } + } + } + + /** + * Displays a Feature(Set) + * + * @param f + * the Feature(Set) to show + */ + public void setFeature(Feature f) { + removeSubwindows(); + currentFeature.setValue(f); + String path = getPathFor(f); + webAnalytics.trackPageview(path); + uriFragmentUtility.setFragment(path, false); + breadcrumbs.setPath(path); + + previousSample.setEnabled(f != null); + nextSample.setEnabled(!allFeatures.isLastId(f)); + + updateFeatureList(currentList); + } + + /** + * Displays a Feature(Set) matching the given path, or the main view if + * no matching Feature(Set) is found. + * + * @param path + * the path of the Feature(Set) to show + */ + public void setFeature(String path) { + Feature f = FeatureSet.FEATURES.getFeatureByPath(path); + setFeature(f); + } + + /* + * SamplerWindow helpers + */ + + private Component createSearch() { + search = new ComboBox(); + search.setWidth("160px"); + search.setNewItemsAllowed(false); + search.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS); + search.setNullSelectionAllowed(true); + search.setImmediate(true); + search.setContainerDataSource(allFeatures); + for (Iterator it = allFeatures.getItemIds().iterator(); it + .hasNext();) { + Object id = it.next(); + if (id instanceof FeatureSet) { + search.setItemIcon(id, new ClassResource("folder.gif", + SamplerApplication.this)); + } + } + search.addListener(new ComboBox.ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + Feature f = (Feature) event.getProperty().getValue(); + if (f != null) { + SamplerWindow.this.setFeature(f); + event.getProperty().setValue(null); + } + + } + }); + // TODO add icons for section/sample + /* + * PopupView pv = new PopupView("", search) { public void + * changeVariables(Object source, Map variables) { + * super.changeVariables(source, variables); if (isPopupVisible()) { + * search.focus(); } } }; + */ + PopupView pv = new PopupView("<span></span>", search); + pv.addListener(new PopupView.PopupVisibilityListener() { + public void popupVisibilityChange(PopupVisibilityEvent event) { + if (event.isPopupVisible()) { + search.focus(); + } + } + }); + pv.setStyleName("quickjump"); + pv.setDescription("Quick jump"); + + return pv; + } + + private Component createLogo() { + Button logo = new Button("", new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + setFeature((Feature) null); + } + }); + logo.setDescription("↶ Home"); + logo.setStyleName(Button.STYLE_LINK); + logo.addStyleName("logo"); + logo.setIcon(new ThemeResource("sampler/sampler.png")); + return logo; + } + + private Button createNextButton() { + Button b = new Button("", new ClickListener() { + public void buttonClick(ClickEvent event) { + Object curr = currentFeature.getValue(); + Object next = allFeatures.nextItemId(curr); + while (next != null && next instanceof FeatureSet) { + next = allFeatures.nextItemId(next); + } + if (next != null) { + currentFeature.setValue(next); + } else { + // could potentially occur if there is an empty section + showNotification("Last sample"); + } + } + }); + b.setStyleName("next"); + b.setDescription("Jump to the next sample"); + return b; + } + + private Button createPrevButton() { + Button b = new Button("", new ClickListener() { + public void buttonClick(ClickEvent event) { + Object curr = currentFeature.getValue(); + Object prev = allFeatures.prevItemId(curr); + while (prev != null && prev instanceof FeatureSet) { + prev = allFeatures.prevItemId(prev); + } + currentFeature.setValue(prev); + } + }); + b.setEnabled(false); + b.setStyleName("previous"); + b.setDescription("Jump to the previous sample"); + return b; + } + + private Component createTreeSwitch() { + final Button b = new Button(); + b.setStyleName("tree-switch"); + b.setDescription("Toggle sample tree visibility"); + b.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + if (b.getStyleName().contains("down")) { + b.removeStyleName("down"); + mainSplit.setSplitPosition(0); + navigationTree.setVisible(false); + mainSplit.setLocked(true); + } else { + b.addStyleName("down"); + mainSplit.setSplitPosition(20); + mainSplit.setLocked(false); + navigationTree.setVisible(true); + } + } + }); + mainSplit.setSplitPosition(0); + navigationTree.setVisible(false); + mainSplit.setLocked(true); + return b; + } + + private ModeSwitch createModeSwitch() { + ModeSwitch m = new ModeSwitch(); + m.addMode(currentList, "", "View as Icons", new ThemeResource( + "sampler/grid.png")); + /*- no CoverFlow yet + m.addMode(coverFlow, "", "View as Icons", new ThemeResource( + "sampler/flow.gif")); + */ + m.addMode(new FeatureTable(), "", "View as List", + new ThemeResource("sampler/list.png")); + m.addListener(new ModeSwitch.ModeSwitchListener() { + public void componentEvent(Event event) { + if (event instanceof ModeSwitchEvent) { + updateFeatureList((FeatureList) ((ModeSwitchEvent) event) + .getMode()); + } + } + }); + return m; + } + + private Tree createMenuTree() { + final Tree tree = new Tree(); + tree.setImmediate(true); + tree.setStyleName("menu"); + tree.setContainerDataSource(allFeatures); + currentFeature.addListener(new Property.ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + Feature f = (Feature) event.getProperty().getValue(); + Feature v = (Feature) tree.getValue(); + if ((f != null && !f.equals(v)) || (f == null && v != null)) { + tree.setValue(f); + } + } + }); + for (int i = 0; i < FeatureSet.FEATURES.getFeatures().length; i++) { + tree + .expandItemsRecursively(FeatureSet.FEATURES + .getFeatures()[i]); + } + tree.expandItemsRecursively(FeatureSet.FEATURES); + tree.addListener(new Tree.ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + Feature f = (Feature) event.getProperty().getValue(); + setFeature(f); + } + }); + return tree; + } + + private void updateFeatureList(FeatureList list) { + currentList = list; + Feature val = (Feature) currentFeature.getValue(); + if (val == null) { + currentList.setFeatureContainer(allFeatures); + mainSplit.setSecondComponent(currentList); + mode.setVisible(true); + } else if (val instanceof FeatureSet) { + currentList.setFeatureContainer(((FeatureSet) val) + .getContainer(true)); + mainSplit.setSecondComponent(currentList); + mode.setVisible(true); + } else { + mainSplit.setSecondComponent(featureView); + featureView.setFeature(val); + mode.setVisible(false); + } + + } + + } + + private class BreadCrumbs extends CustomComponent implements + ActiveLink.LinkActivatedListener { + HorizontalLayout layout; + + BreadCrumbs() { + layout = new HorizontalLayout(); + layout.setSpacing(true); + setCompositionRoot(layout); + setStyleName("breadcrumbs"); + setPath(null); + } + + public void setPath(String path) { + // could be optimized: always builds path from scratch + layout.removeAllComponents(); + + { // home + ActiveLink link = new ActiveLink("Home", new ExternalResource( + "#")); + link.addListener(this); + layout.addComponent(link); + } + + if (path != null && !"".equals(path)) { + String parts[] = path.split("/"); + String current = ""; + ActiveLink link = null; + for (int i = 0; i < parts.length; i++) { + layout.addComponent(new Label("»", + Label.CONTENT_XHTML)); + current += (i > 0 ? "/" : "") + parts[i]; + Feature f = FeatureSet.FEATURES.getFeatureByPath(current); + link = new ActiveLink(f.getName(), new ExternalResource("#" + + getPathFor(f))); + link.setData(f); + link.addListener(this); + layout.addComponent(link); + } + if (link != null) { + link.setStyleName("bold"); + } + } + + } + + public void linkActivated(LinkActivatedEvent event) { + if (!event.isLinkOpened()) { + ((SamplerWindow) getWindow()).setFeature((Feature) event + .getActiveLink().getData()); + } + } + } + + /** + * Components capable of listing Features should implement this. + * + */ + interface FeatureList extends Component { + /** + * Shows the given Features + * + * @param c + * Container with Features to show. + */ + public void setFeatureContainer(HierarchicalContainer c); + } + + /** + * Table -mode FeatureList. Displays the features in a Table. + */ + private class FeatureTable extends Table implements FeatureList { + private HashMap<Object, Resource> iconCache = new HashMap<Object, Resource>(); + + FeatureTable() { + setStyleName("featuretable"); + alwaysRecalculateColumnWidths = true; + setSelectable(false); + setSizeFull(); + setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN); + addGeneratedColumn(Feature.PROPERTY_ICON, + new Table.ColumnGenerator() { + public Component generateCell(Table source, + Object itemId, Object columnId) { + Feature f = (Feature) itemId; + if (f instanceof FeatureSet) { + // no icon for sections + return null; + } + String resId = "75-" + f.getIconName(); + Resource res = iconCache.get(resId); + if (res == null) { + res = new ClassResource(f.getClass(), resId, + SamplerApplication.this); + iconCache.put(resId, res); + + } + Embedded emb = new Embedded("", res); + emb.setWidth("48px"); + emb.setHeight("48px"); + emb.setType(Embedded.TYPE_IMAGE); + return emb; + } + + }); + addGeneratedColumn("", new Table.ColumnGenerator() { + public Component generateCell(Table source, Object itemId, + Object columnId) { + final Feature feature = (Feature) itemId; + if (feature instanceof FeatureSet) { + return null; + } else { + ActiveLink b = new ActiveLink("View sample ‣", + new ExternalResource("#" + getPathFor(feature))); + b.addListener(new ActiveLink.LinkActivatedListener() { + public void linkActivated(LinkActivatedEvent event) { + if (!event.isLinkOpened()) { + ((SamplerWindow) getWindow()) + .setFeature(feature); + } + } + }); + + b.setStyleName(Button.STYLE_LINK); + return b; + } + } + + }); + + addListener(new ItemClickListener() { + public void itemClick(ItemClickEvent event) { + Feature f = (Feature) event.getItemId(); + if (event.getButton() == ItemClickEvent.BUTTON_MIDDLE + || event.isCtrlKey() || event.isShiftKey()) { + getWindow().open( + new ExternalResource(getURL() + "#" + + getPathFor(f)), "_blank"); + } else { + ((SamplerWindow) getWindow()).setFeature(f); + } + } + }); + + setCellStyleGenerator(new CellStyleGenerator() { + public String getStyle(Object itemId, Object propertyId) { + if (propertyId == null && itemId instanceof FeatureSet) { + if (allFeatures.isRoot(itemId)) { + return "section"; + } else { + return "subsection"; + } + + } + return null; + } + }); + } + + public void setFeatureContainer(HierarchicalContainer c) { + setContainerDataSource(c); + setVisibleColumns(new Object[] { Feature.PROPERTY_ICON, + Feature.PROPERTY_NAME, "" }); + setColumnWidth(Feature.PROPERTY_ICON, 60); + + } + + } + + private class FeatureGrid extends Panel implements FeatureList { + + GridLayout grid = new GridLayout(11, 1); + private HashMap<Object, Resource> iconCache = new HashMap<Object, Resource>(); + + FeatureGrid() { + setSizeFull(); + setLayout(grid); + grid.setSizeUndefined(); + grid.setSpacing(true); + setStyleName(Panel.STYLE_LIGHT); + } + + public void setFeatureContainer(HierarchicalContainer c) { + grid.removeAllComponents(); + Collection features = c.getItemIds(); + for (Iterator it = features.iterator(); it.hasNext();) { + final Feature f = (Feature) it.next(); + if (f instanceof FeatureSet) { + grid.newLine(); + Label title = new Label(f.getName()); + if (c.isRoot(f)) { + title.setWidth("100%"); + title.setStyleName("section"); + grid.setRows(grid.getCursorY() + 1); + grid.addComponent(title, 0, grid.getCursorY(), grid + .getColumns() - 1, grid.getCursorY()); + grid + .setComponentAlignment(title, + Alignment.MIDDLE_LEFT); + } else { + title.setStyleName("subsection"); + grid.addComponent(title); + grid + .setComponentAlignment(title, + Alignment.MIDDLE_LEFT); + } + + } else { + if (grid.getCursorX() == 0) { + grid.space(); + } + Button b = new Button(); + b.setStyleName(Button.STYLE_LINK); + b.addStyleName("screenshot"); + String resId = "75-" + f.getIconName(); + Resource res = iconCache.get(resId); + if (res == null) { + res = new ClassResource(f.getClass(), resId, + SamplerApplication.this); + iconCache.put(resId, res); + + } + b.setIcon(res); + b.setWidth("75px"); + b.setHeight("75px"); + b.setDescription("<h3>" + f.getName() + "</h3>"); + b.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + ((SamplerWindow) getWindow()).setFeature(f); + } + }); + grid.addComponent(b); + } + } + } + } + + public static HierarchicalContainer getAllFeatures() { + return allFeatures; + } + + public class SourceWindow extends Window { + public SourceWindow() { + addURIHandler(new URIHandler() { + public DownloadStream handleURI(URL context, String relativeUri) { + Feature f = FeatureSet.FEATURES + .getFeatureByPath(relativeUri); + if (f != null) { + addComponent(new CodeLabel(f.getSource())); + } else { + addComponent(new Label("Sorry, no source found for " + + relativeUri)); + } + return null; + } + + }); + + addListener(new CloseListener() { + public void windowClose(CloseEvent e) { + SamplerApplication.this.removeWindow(SourceWindow.this); + } + }); + } + } + + @Override + public void close() { + removeWindow(getMainWindow()); + + super.close(); + } + +} diff --git a/src/com/vaadin/demo/sampler/features/accordions/75-AccordionDisabled.png b/src/com/vaadin/demo/sampler/features/accordions/75-AccordionDisabled.png Binary files differnew file mode 100644 index 0000000000..fb3e3fe844 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/accordions/75-AccordionDisabled.png diff --git a/src/com/vaadin/demo/sampler/features/accordions/75-AccordionIcons.png b/src/com/vaadin/demo/sampler/features/accordions/75-AccordionIcons.png Binary files differnew file mode 100644 index 0000000000..c38a1aefc8 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/accordions/75-AccordionIcons.png diff --git a/src/com/vaadin/demo/sampler/features/accordions/AccordionDisabled.java b/src/com/vaadin/demo/sampler/features/accordions/AccordionDisabled.java new file mode 100644 index 0000000000..b9be6b4add --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/accordions/AccordionDisabled.java @@ -0,0 +1,36 @@ +package com.vaadin.demo.sampler.features.accordions;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Accordion;
+
+public class AccordionDisabled extends Feature {
+ @Override
+ public String getName() {
+ return "Accordion, disabled tabs";
+ }
+
+ @Override
+ public String getDescription() {
+ return "You can disable, enable, hide and show accordion 'tabs'.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Accordion.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { AccordionIcons.class, FeatureSet.Tabsheets.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/accordions/AccordionDisabledExample.java b/src/com/vaadin/demo/sampler/features/accordions/AccordionDisabledExample.java new file mode 100644 index 0000000000..ae8e817ade --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/accordions/AccordionDisabledExample.java @@ -0,0 +1,87 @@ +package com.vaadin.demo.sampler.features.accordions;
+
+import com.vaadin.terminal.ThemeResource;
+import com.vaadin.ui.Accordion;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
+import com.vaadin.ui.TabSheet.Tab;
+
+public class AccordionDisabledExample extends VerticalLayout implements
+ Accordion.SelectedTabChangeListener, Button.ClickListener {
+
+ private Accordion a;
+ private Button b1;
+ private Button b2;
+ private Label l1;
+ private Label l2;
+ private Label l3;
+ private Tab t1;
+ private Tab t2;
+ private Tab t3;
+
+ private static final ThemeResource icon1 = new ThemeResource(
+ "icons/action_save.gif");
+ private static final ThemeResource icon2 = new ThemeResource(
+ "icons/comment_yellow.gif");
+ private static final ThemeResource icon3 = new ThemeResource(
+ "icons/icon_info.gif");
+
+ public AccordionDisabledExample() {
+ setSpacing(true);
+
+ l1 = new Label("There are no previously saved actions.");
+ l2 = new Label("There are no saved notes.");
+ l3 = new Label("There are currently no issues.");
+
+ a = new Accordion();
+ a.setHeight("300px");
+ a.setWidth("400px");
+ t1 = a.addTab(l1, "Saved actions", icon1);
+ t2 = a.addTab(l2, "Notes", icon2);
+ t3 = a.addTab(l3, "Issues", icon3);
+ a.addListener(this);
+
+ b1 = new Button("Disable 'Notes' tab");
+ b2 = new Button("Hide 'Issues' tab");
+ b1.addListener(this);
+ b2.addListener(this);
+
+ HorizontalLayout hl = new HorizontalLayout();
+ hl.setSpacing(true);
+ hl.addComponent(b1);
+ hl.addComponent(b2);
+
+ addComponent(a);
+ addComponent(hl);
+ }
+
+ public void selectedTabChange(SelectedTabChangeEvent event) {
+ String c = a.getTab(event.getTabSheet().getSelectedTab()).getCaption();
+ getWindow().showNotification("Selected tab: " + c);
+ }
+
+ public void buttonClick(ClickEvent event) {
+ if (b1.equals(event.getButton())) { // b1 clicked
+ if (t2.isEnabled()) {
+ t2.setEnabled(false);
+ b1.setCaption("Enable 'Notes' tab");
+ } else {
+ t2.setEnabled(true);
+ b1.setCaption("Disable 'Notes' tab");
+ }
+ } else { // b2 clicked
+ if (t3.isVisible()) {
+ t3.setVisible(false);
+ b2.setCaption("Show 'Issues' tab");
+ } else {
+ t3.setVisible(true);
+ b2.setCaption("Hide 'Issues' tab");
+ }
+ }
+ a.requestRepaint();
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/accordions/AccordionIcons.java b/src/com/vaadin/demo/sampler/features/accordions/AccordionIcons.java new file mode 100644 index 0000000000..d6f0cf9e48 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/accordions/AccordionIcons.java @@ -0,0 +1,37 @@ +package com.vaadin.demo.sampler.features.accordions;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Accordion;
+
+public class AccordionIcons extends Feature {
+ @Override
+ public String getName() {
+ return "Accordion with icons";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The accordion 'tabs' can contain icons in addition to the caption.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Accordion.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { AccordionDisabled.class,
+ FeatureSet.Tabsheets.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/accordions/AccordionIconsExample.java b/src/com/vaadin/demo/sampler/features/accordions/AccordionIconsExample.java new file mode 100644 index 0000000000..42047581a0 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/accordions/AccordionIconsExample.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.accordions;
+
+import com.vaadin.terminal.ThemeResource;
+import com.vaadin.ui.Accordion;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
+
+public class AccordionIconsExample extends HorizontalLayout implements
+ Accordion.SelectedTabChangeListener {
+
+ private static final ThemeResource icon1 = new ThemeResource(
+ "icons/action_save.gif");
+ private static final ThemeResource icon2 = new ThemeResource(
+ "icons/comment_yellow.gif");
+ private static final ThemeResource icon3 = new ThemeResource(
+ "icons/icon_info.gif");
+
+ private Accordion a;
+
+ public AccordionIconsExample() {
+ setSpacing(true);
+
+ Label l1 = new Label("There are no previously saved actions.");
+ Label l2 = new Label("There are no saved notes.");
+ Label l3 = new Label("There are currently no issues.");
+
+ a = new Accordion();
+ a.setHeight("300px");
+ a.setWidth("400px");
+ a.addTab(l1, "Saved actions", icon1);
+ a.addTab(l2, "Notes", icon2);
+ a.addTab(l3, "Issues", icon3);
+ a.addListener(this);
+
+ addComponent(a);
+ }
+
+ public void selectedTabChange(SelectedTabChangeEvent event) {
+ String c = a.getTabCaption(event.getTabSheet().getSelectedTab());
+ getWindow().showNotification("Selected tab: " + c);
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/blueprints/75-ProminentPrimaryAction.png b/src/com/vaadin/demo/sampler/features/blueprints/75-ProminentPrimaryAction.png Binary files differnew file mode 100644 index 0000000000..d249324e0c --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/blueprints/75-ProminentPrimaryAction.png diff --git a/src/com/vaadin/demo/sampler/features/blueprints/ProminentPrimaryAction.java b/src/com/vaadin/demo/sampler/features/blueprints/ProminentPrimaryAction.java new file mode 100644 index 0000000000..d3eaa06d8b --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/blueprints/ProminentPrimaryAction.java @@ -0,0 +1,55 @@ +package com.vaadin.demo.sampler.features.blueprints; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.demo.sampler.features.buttons.ButtonLink; +import com.vaadin.demo.sampler.features.buttons.ButtonPush; +import com.vaadin.ui.Button; +import com.vaadin.ui.Link; + +public class ProminentPrimaryAction extends Feature { + + @Override + public String getName() { + return "Prominent primary action"; + } + + @Override + public String getDescription() { + return "A primary action is an action that is clearly the" + + " default, and it should be visually more prominent" + + " than the secondary actions.<br/>Good candidates" + + " include <i>Save</i>, <i>Submit</i>, <i>Continue</i>, <i>Next</i>," + + " <i>Finish</i> and so on.<br/>Note that 'dangerous' actions" + + " that can not be undone should not be primary, and that it's" + + " not always possible to identify a primary action" + + " - don't force it if it's not obvious."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Button.class), + new APIResource(Link.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { ButtonPush.class, ButtonLink.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return new NamedExternalResource[] { + + new NamedExternalResource("CSS for 'Sign up' button", + getThemeBase() + "prominentprimaryaction/styles.css"), + + new NamedExternalResource( + "Article: Primary & Secondary Actions in Web Forms (LukeW)", + "http://www.lukew.com/resources/articles/psactions.asp"), + new NamedExternalResource( + "Article: Primary & Secondary Actions (UI Pattern Factory)", + "http://uipatternfactory.com/p=primary-and-secondary-actions/") }; + } +} diff --git a/src/com/vaadin/demo/sampler/features/blueprints/ProminentPrimaryActionExample.java b/src/com/vaadin/demo/sampler/features/blueprints/ProminentPrimaryActionExample.java new file mode 100644 index 0000000000..bbbb3d6b6a --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/blueprints/ProminentPrimaryActionExample.java @@ -0,0 +1,68 @@ +package com.vaadin.demo.sampler.features.blueprints; + +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; + +public class ProminentPrimaryActionExample extends VerticalLayout implements + Button.ClickListener { + + public ProminentPrimaryActionExample() { + setSpacing(true); + + { // Cancel / Save + HorizontalLayout horiz = new HorizontalLayout(); + horiz.setCaption("Save/cancel example:"); + horiz.setSpacing(true); + horiz.setMargin(true); + addComponent(horiz); + Button secondary = new Button("Cancel", this); + secondary.setStyleName(Button.STYLE_LINK); + horiz.addComponent(secondary); + Button primary = new Button("Save", this); + horiz.addComponent(primary); + } + + { // Sign up / Sign in + HorizontalLayout horiz = new HorizontalLayout(); + horiz.setCaption("Sign up example:"); + horiz.setSpacing(true); + horiz.setMargin(true); + addComponent(horiz); + Button primary = new Button("Sign up", this); + primary.addStyleName("primary"); + horiz.addComponent(primary); + Button secondary = new Button("or Sign in", this); + secondary.setStyleName(Button.STYLE_LINK); + horiz.addComponent(secondary); + horiz.setComponentAlignment(secondary, Alignment.MIDDLE_LEFT); + } + + { // Login / Forgot password? + VerticalLayout vert = new VerticalLayout(); + vert.setCaption("Login example:"); + vert.setSizeUndefined(); + vert.setSpacing(true); + vert.setMargin(true); + addComponent(vert); + Button primary = new Button("Login", this); + vert.addComponent(primary); + vert.setComponentAlignment(primary, Alignment.BOTTOM_RIGHT); + Button secondary = new Button("Forgot your password?", this); + secondary.setStyleName(Button.STYLE_LINK); + vert.addComponent(secondary); + vert.setComponentAlignment(secondary, Alignment.BOTTOM_RIGHT); + } + + } + + /* + * Shows a notification when a button is clicked. + */ + public void buttonClick(ClickEvent event) { + getWindow().showNotification( + "\"" + event.getButton().getCaption() + "\" clicked"); + } +} diff --git a/src/com/vaadin/demo/sampler/features/buttons/75-ButtonLink.png b/src/com/vaadin/demo/sampler/features/buttons/75-ButtonLink.png Binary files differnew file mode 100644 index 0000000000..4e6963f8d1 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/buttons/75-ButtonLink.png diff --git a/src/com/vaadin/demo/sampler/features/buttons/75-ButtonPush.png b/src/com/vaadin/demo/sampler/features/buttons/75-ButtonPush.png Binary files differnew file mode 100644 index 0000000000..6520e205ff --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/buttons/75-ButtonPush.png diff --git a/src/com/vaadin/demo/sampler/features/buttons/75-ButtonSwitch.png b/src/com/vaadin/demo/sampler/features/buttons/75-ButtonSwitch.png Binary files differnew file mode 100644 index 0000000000..6df1b3935d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/buttons/75-ButtonSwitch.png diff --git a/src/com/vaadin/demo/sampler/features/buttons/ButtonLink.java b/src/com/vaadin/demo/sampler/features/buttons/ButtonLink.java new file mode 100644 index 0000000000..f9f73852bf --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/buttons/ButtonLink.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.buttons; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.demo.sampler.features.blueprints.ProminentPrimaryAction; +import com.vaadin.demo.sampler.features.link.LinkCurrentWindow; +import com.vaadin.ui.Button; + +public class ButtonLink extends Feature { + + @Override + public String getName() { + return "Link button"; + } + + @Override + public String getDescription() { + return "A link-styled button works like a push button, but looks like" + + " a Link.<br/> It does not actually link somewhere, but" + + " triggers a server-side event, just like a regular button."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Button.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { ButtonPush.class, ButtonSwitch.class, + LinkCurrentWindow.class, ProminentPrimaryAction.class, + FeatureSet.Links.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/buttons/ButtonLinkExample.java b/src/com/vaadin/demo/sampler/features/buttons/ButtonLinkExample.java new file mode 100644 index 0000000000..4b2e00ea7a --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/buttons/ButtonLinkExample.java @@ -0,0 +1,51 @@ +package com.vaadin.demo.sampler.features.buttons; + +import com.vaadin.terminal.ThemeResource; +import com.vaadin.ui.Button; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; + +public class ButtonLinkExample extends VerticalLayout implements + Button.ClickListener { + + private static final String CAPTION = "Help"; + private static final String TOOLTIP = "Show help"; + private static final ThemeResource ICON = new ThemeResource( + "icons/icon_info.gif"); + private static final String NOTIFICATION = "Help clicked"; + + public ButtonLinkExample() { + setSpacing(true); + + // Button w/ text and tooltip + Button b = new Button(CAPTION); + b.setStyleName(Button.STYLE_LINK); + b.setDescription(TOOLTIP); + b.addListener(this); // react to clicks + addComponent(b); + + // Button w/ text, icon and tooltip + b = new Button(CAPTION); + b.setStyleName(Button.STYLE_LINK); + b.setDescription(TOOLTIP); + b.setIcon(ICON); + b.addListener(this); // react to clicks + addComponent(b); + + // Button w/ icon and tooltip + b = new Button(); + b.setStyleName(Button.STYLE_LINK); + b.setDescription(TOOLTIP); + b.setIcon(ICON); + b.addListener(this); // react to clicks + addComponent(b); + + } + + /* + * Shows a notification when a button is clicked. + */ + public void buttonClick(ClickEvent event) { + getWindow().showNotification(NOTIFICATION); + } +} diff --git a/src/com/vaadin/demo/sampler/features/buttons/ButtonPush.java b/src/com/vaadin/demo/sampler/features/buttons/ButtonPush.java new file mode 100644 index 0000000000..4b9dc23480 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/buttons/ButtonPush.java @@ -0,0 +1,40 @@ +package com.vaadin.demo.sampler.features.buttons; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.demo.sampler.features.blueprints.ProminentPrimaryAction; +import com.vaadin.ui.Button; + +public class ButtonPush extends Feature { + + @Override + public String getName() { + return "Push button"; + } + + @Override + public String getDescription() { + return "A push-button, which can be considered a 'regular' button," + + " returns to it's 'unclicked' state after emitting an event" + + " when the user clicks it."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Button.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { ButtonLink.class, ButtonSwitch.class, + ProminentPrimaryAction.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/buttons/ButtonPushExample.java b/src/com/vaadin/demo/sampler/features/buttons/ButtonPushExample.java new file mode 100644 index 0000000000..67d6e61b60 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/buttons/ButtonPushExample.java @@ -0,0 +1,48 @@ +package com.vaadin.demo.sampler.features.buttons; + +import com.vaadin.terminal.ThemeResource; +import com.vaadin.ui.Button; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; + +public class ButtonPushExample extends VerticalLayout implements + Button.ClickListener { + + private static final String CAPTION = "Save"; + private static final String TOOLTIP = "Save changes"; + private static final ThemeResource ICON = new ThemeResource( + "icons/action_save.gif"); + private static final String NOTIFICATION = "Changes have been saved"; + + public ButtonPushExample() { + setSpacing(true); + + // Button w/ text and tooltip + Button b = new Button(CAPTION); + b.setDescription(TOOLTIP); + b.addListener(this); // react to clicks + addComponent(b); + + // Button w/ text, icon and tooltip + b = new Button(CAPTION); + b.setDescription(TOOLTIP); + b.setIcon(ICON); + b.addListener(this); // react to clicks + addComponent(b); + + // Button w/ icon and tooltip + b = new Button(); + b.setDescription(TOOLTIP); + b.setIcon(ICON); + b.addListener(this); // react to clicks + addComponent(b); + + } + + /* + * Shows a notification when a button is clicked. + */ + public void buttonClick(ClickEvent event) { + getWindow().showNotification(NOTIFICATION); + } +} diff --git a/src/com/vaadin/demo/sampler/features/buttons/ButtonSwitch.java b/src/com/vaadin/demo/sampler/features/buttons/ButtonSwitch.java new file mode 100644 index 0000000000..4a86668f62 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/buttons/ButtonSwitch.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.buttons; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Button; + +public class ButtonSwitch extends Feature { + + @Override + public String getName() { + return "Switch button"; + } + + @Override + public String getDescription() { + return "A switch button works like a regular push button, triggering" + + " a server-side event, but it's state is 'sticky': the button" + + " toggles between it's on and off states, instead of popping" + + " right back out.<br/>Also know as a CheckBox."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Button.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { ButtonPush.class, ButtonLink.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/buttons/ButtonSwitchExample.java b/src/com/vaadin/demo/sampler/features/buttons/ButtonSwitchExample.java new file mode 100644 index 0000000000..5bc0442ce4 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/buttons/ButtonSwitchExample.java @@ -0,0 +1,52 @@ +package com.vaadin.demo.sampler.features.buttons; + +import com.vaadin.terminal.ThemeResource; +import com.vaadin.ui.Button; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; + +public class ButtonSwitchExample extends VerticalLayout implements + Button.ClickListener { + + private static final String CAPTION = "Allow HTML"; + private static final String TOOLTIP = "Allow/disallow HTML in comments"; + private static final ThemeResource ICON = new ThemeResource( + "icons/page_code.gif"); + + public ButtonSwitchExample() { + setSpacing(true); + + // Button w/ text and tooltip + Button b = new Button(CAPTION); + b.setSwitchMode(true); + b.setDescription(TOOLTIP); + b.addListener(this); // react to clicks + addComponent(b); + + // Button w/ text, icon and tooltip + b = new Button(CAPTION); + b.setSwitchMode(true); + b.setDescription(TOOLTIP); + b.setIcon(ICON); + b.addListener(this); // react to clicks + addComponent(b); + + // Button w/ icon and tooltip + b = new Button(); + b.setSwitchMode(true); + b.setDescription(TOOLTIP); + b.setIcon(ICON); + b.addListener(this); // react to clicks + addComponent(b); + + } + + /* + * Shows a notification when a button is clicked. + */ + public void buttonClick(ClickEvent event) { + boolean enabled = event.getButton().booleanValue(); + getWindow().showNotification( + "HTML " + (enabled ? "enabled" : "disabled")); + } +} diff --git a/src/com/vaadin/demo/sampler/features/commons/75-Errors.png b/src/com/vaadin/demo/sampler/features/commons/75-Errors.png Binary files differnew file mode 100644 index 0000000000..26b29ce24f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/75-Errors.png diff --git a/src/com/vaadin/demo/sampler/features/commons/75-Icons.png b/src/com/vaadin/demo/sampler/features/commons/75-Icons.png Binary files differnew file mode 100644 index 0000000000..23c733579b --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/75-Icons.png diff --git a/src/com/vaadin/demo/sampler/features/commons/75-Tooltips.png b/src/com/vaadin/demo/sampler/features/commons/75-Tooltips.png Binary files differnew file mode 100644 index 0000000000..217daeb920 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/75-Tooltips.png diff --git a/src/com/vaadin/demo/sampler/features/commons/75-Validation.png b/src/com/vaadin/demo/sampler/features/commons/75-Validation.png Binary files differnew file mode 100644 index 0000000000..058ec7db9f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/75-Validation.png diff --git a/src/com/vaadin/demo/sampler/features/commons/Errors.java b/src/com/vaadin/demo/sampler/features/commons/Errors.java new file mode 100644 index 0000000000..5cac780621 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/Errors.java @@ -0,0 +1,52 @@ +package com.vaadin.demo.sampler.features.commons; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.demo.sampler.features.form.FormBasic; +import com.vaadin.demo.sampler.features.notifications.NotificationError; +import com.vaadin.ui.AbstractComponent; + +public class Errors extends Feature { + + private static final String desc = "A <i>component error</i> can be set to" + + " indicate an error - an error indicator icon will appear," + + " and the error message will appear as a 'tooltip' when" + + " mousing over.<br/>" + + "You can do this on almost any component, but please note" + + " that from a usability standpoint it's not always the best" + + " solution.<br/>" + + "<i>Component error</i> is most useful to indicate what is" + + " causing the error (e.g an 'email' TextField), so that the user" + + " can find and correct the problem. <br/>" + + "On the other hand, it is usually not a good idea to set an error" + + " on a Button: the user can not click 'Save' differently to" + + " correct the error.<br/>" + + "If there is no component causing the error, consider using a" + + " (styled) Label or a Notification to indicate the error."; + + @Override + public String getName() { + return "Error indicator"; + } + + public String getDescription() { + return desc; + } + + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(AbstractComponent.class) }; + } + + public Class[] getRelatedFeatures() { + // TODO link validation sample, form sample + return new Class[] { Validation.class, FormBasic.class, + NotificationError.class }; + } + + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/commons/ErrorsExample.java b/src/com/vaadin/demo/sampler/features/commons/ErrorsExample.java new file mode 100644 index 0000000000..fc5b1eff24 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/ErrorsExample.java @@ -0,0 +1,24 @@ +package com.vaadin.demo.sampler.features.commons; + +import com.vaadin.terminal.UserError; +import com.vaadin.ui.Panel; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +public class ErrorsExample extends VerticalLayout { + + public ErrorsExample() { + setSpacing(true); + + Panel panel = new Panel("Configure this"); + panel.setComponentError(new UserError("'Input' contains an error")); + addComponent(panel); + + TextField input = new TextField("Input"); + input + .setComponentError(new UserError( + "This field is never satisfied.")); + panel.addComponent(input); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/commons/Icons.java b/src/com/vaadin/demo/sampler/features/commons/Icons.java new file mode 100644 index 0000000000..0baf8fca6e --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/Icons.java @@ -0,0 +1,55 @@ +package com.vaadin.demo.sampler.features.commons; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.terminal.ApplicationResource; +import com.vaadin.terminal.ClassResource; +import com.vaadin.terminal.ExternalResource; +import com.vaadin.terminal.FileResource; +import com.vaadin.terminal.Resource; +import com.vaadin.terminal.StreamResource; +import com.vaadin.terminal.ThemeResource; +import com.vaadin.ui.Component; + +public class Icons extends Feature { + + @Override + public String getName() { + return "Icons"; + } + + @Override + public String getDescription() { + return "Most components can have an <i>icon</i>," + + " which is usually displayed next to the caption.<br/>" + + "When used correctly, icons can make it significantly" + + " easier for the user to find a specific functionality." + + " Beware of overuse, which will have the opposite effect."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Component.class), + new APIResource(Resource.class), + new APIResource(ApplicationResource.class), + new APIResource(ClassResource.class), + new APIResource(ExternalResource.class), + new APIResource(FileResource.class), + new APIResource(StreamResource.class), + new APIResource(ThemeResource.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + // TODO link embedded sample + return null; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/commons/IconsExample.java b/src/com/vaadin/demo/sampler/features/commons/IconsExample.java new file mode 100644 index 0000000000..39d31dbfcf --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/IconsExample.java @@ -0,0 +1,49 @@ +package com.vaadin.demo.sampler.features.commons; + +import com.vaadin.terminal.ExternalResource; +import com.vaadin.terminal.ThemeResource; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.Link; +import com.vaadin.ui.Panel; +import com.vaadin.ui.VerticalLayout; + +public class IconsExample extends VerticalLayout { + + public IconsExample() { + setSpacing(true); + + /* Button w/ icon */ + Button button = new Button("Save"); + button.setIcon(new ThemeResource("icons/action_save.gif")); + addComponent(button); + + /* Label */; + Label l = new Label("Icons are very handy"); + l.setCaption("Comment"); + l.setIcon(new ThemeResource("icons/comment_yellow.gif")); + addComponent(l); + + /* Panel w/ links */ + Panel p = new Panel("Handy links"); + p.setIcon(new ThemeResource("icons/icon_info.gif")); + addComponent(p); + Link lnk = new Link("http://www.itmill.com", new ExternalResource( + "http://www.itmill.com")); + lnk.setIcon(new ThemeResource("icons/icon_world.gif")); + p.addComponent(lnk); + lnk = new Link("http://www.itmill.com/developers/", + new ExternalResource("http://www.itmill.com/developers/")); + lnk.setIcon(new ThemeResource("icons/icon_world.gif")); + p.addComponent(lnk); + lnk = new Link("http://dev.itmill.com/", new ExternalResource( + "http://dev.itmill.com/")); + lnk.setIcon(new ThemeResource("icons/icon_world.gif")); + p.addComponent(lnk); + lnk = new Link("http://forum.itmill.com", new ExternalResource( + "http://forum.itmill.com")); + lnk.setIcon(new ThemeResource("icons/icon_world.gif")); + p.addComponent(lnk); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/commons/Tooltips.java b/src/com/vaadin/demo/sampler/features/commons/Tooltips.java new file mode 100644 index 0000000000..eac86146fe --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/Tooltips.java @@ -0,0 +1,40 @@ +package com.vaadin.demo.sampler.features.commons; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.AbstractComponent; + +public class Tooltips extends Feature { + + @Override + public String getName() { + return "Tooltips"; + } + + @Override + public String getDescription() { + return "Most components can have a <i>description</i>," + + " which is shown as a <i>\"tooltip\"</i>." + + " Descriptions may have formatted ('rich') content.<br/>" + + ""; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(AbstractComponent.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + // TODO Auto-generated method stub + return null; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/commons/TooltipsExample.java b/src/com/vaadin/demo/sampler/features/commons/TooltipsExample.java new file mode 100644 index 0000000000..932286df76 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/TooltipsExample.java @@ -0,0 +1,56 @@ +package com.vaadin.demo.sampler.features.commons; + +import com.vaadin.ui.Button; +import com.vaadin.ui.RichTextArea; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; + +public class TooltipsExample extends VerticalLayout { + + private static final String editTxt = "Edit tooltip"; + private static final String applyTxt = "Apply"; + + public TooltipsExample() { + setSpacing(true); + + /* Plain tooltip (description) */ + Button plain = new Button("Mouse over for plain tooltip"); + plain.setStyleName(Button.STYLE_LINK); + // add the tooltip: + plain.setDescription("A simple plaintext tooltip"); + addComponent(plain); + + /* Richtext tooltip (description) */ + Button rich = new Button("Mouse over for richtext tooltip"); + rich.setStyleName(Button.STYLE_LINK); + // add the tooltip: + rich + .setDescription("<h2><img src=\"../ITMILL/themes/sampler/icons/comment_yellow.gif\"/>A richtext tooltip</h2>" + + "<ul>" + + "<li>HTML formatting</li><li>Images<br/>" + + "</li><li>etc...</li></ul>"); + addComponent(rich); + + /* Edit */ + final RichTextArea rte = new RichTextArea(); + rte.setValue("Click <b>" + editTxt + + "</b> to edit this tooltip, then <b>" + applyTxt + "</b>"); + rte.setVisible(false); // hide editor initially + addComponent(rte); + Button apply = new Button(editTxt, new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + if (rte.isVisible()) { + rte.setVisible(false); + event.getButton().setDescription((String) rte.getValue()); + event.getButton().setCaption(editTxt); + } else { + rte.setVisible(true); + event.getButton().setCaption(applyTxt); + } + } + }); + apply.setDescription((String) rte.getValue()); + addComponent(apply); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/commons/Validation.java b/src/com/vaadin/demo/sampler/features/commons/Validation.java new file mode 100644 index 0000000000..3ff516a5ba --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/Validation.java @@ -0,0 +1,46 @@ +package com.vaadin.demo.sampler.features.commons; + +import com.vaadin.data.Validatable; +import com.vaadin.data.Validator; +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.demo.sampler.features.form.FormPojoExample; +import com.vaadin.ui.Component; +import com.vaadin.ui.Form; + +public class Validation extends Feature { + + @Override + public String getName() { + return "Validation"; + } + + private static final String desc = "Fields can have Validators that check" + + " entered values. This is most useful when used within a Form, but" + + " but can be used to validate single, stand-alone Fields as well."; + + @Override + public Component getExample() { + return new FormPojoExample(); + } + + public String getDescription() { + return desc; + } + + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Validatable.class), + new APIResource(Validator.class), new APIResource(Form.class) }; + } + + public Class[] getRelatedFeatures() { + return new Class[] { Errors.class, FeatureSet.Forms.class }; + } + + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/commons/ValidationExample.java b/src/com/vaadin/demo/sampler/features/commons/ValidationExample.java new file mode 100644 index 0000000000..873b641ec7 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/commons/ValidationExample.java @@ -0,0 +1,62 @@ +package com.vaadin.demo.sampler.features.commons; + +import java.util.HashSet; + +import com.vaadin.data.Validator; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.data.validator.CompositeValidator; +import com.vaadin.data.validator.StringLengthValidator; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +public class ValidationExample extends VerticalLayout { + + HashSet usernames = new HashSet(); + + public ValidationExample() { + setSpacing(true); + + TextField pin = new TextField("PIN"); + pin.setWidth("50px"); + // optional; validate at once instead of when clicking 'save' (e.g) + pin.setImmediate(true); + addComponent(pin); + // add the validator + pin.addValidator(new StringLengthValidator("Must be 4-6 characters", 4, + 6, false)); + + TextField username = new TextField("Username"); + // optional; validate at once instead of when clicking 'save' (e.g) + username.setImmediate(true); + addComponent(username); + CompositeValidator usernameValidator = new CompositeValidator(); + username.addValidator(usernameValidator); + usernameValidator.addValidator(new StringLengthValidator( + "Username must be at least 4 characters", 4, 255, false)); + usernameValidator.addValidator(new Validator() { + + public boolean isValid(Object value) { + return !usernames.contains(value); + } + + public void validate(Object value) throws InvalidValueException { + if (!isValid(value)) { + throw new Validator.InvalidValueException("Username " + + value + " already in use"); + } + } + }); + username.addListener(new ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + TextField tf = (TextField) event.getProperty(); + tf.validate(); + usernames.add(tf.getValue()); + addComponent(new Label("Added " + tf.getValue() + + " to usernames")); + } + }); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/dates/75-DateInline.png b/src/com/vaadin/demo/sampler/features/dates/75-DateInline.png Binary files differnew file mode 100644 index 0000000000..4368f420a9 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/75-DateInline.png diff --git a/src/com/vaadin/demo/sampler/features/dates/75-DateLocale.png b/src/com/vaadin/demo/sampler/features/dates/75-DateLocale.png Binary files differnew file mode 100644 index 0000000000..a608e59873 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/75-DateLocale.png diff --git a/src/com/vaadin/demo/sampler/features/dates/75-DatePopup.png b/src/com/vaadin/demo/sampler/features/dates/75-DatePopup.png Binary files differnew file mode 100644 index 0000000000..1030469dc2 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/75-DatePopup.png diff --git a/src/com/vaadin/demo/sampler/features/dates/75-DateResolution.png b/src/com/vaadin/demo/sampler/features/dates/75-DateResolution.png Binary files differnew file mode 100644 index 0000000000..ca6ddcf16e --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/75-DateResolution.png diff --git a/src/com/vaadin/demo/sampler/features/dates/DateInline.java b/src/com/vaadin/demo/sampler/features/dates/DateInline.java new file mode 100644 index 0000000000..46a298f9d8 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/DateInline.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.dates;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.InlineDateField;
+
+public class DateInline extends Feature {
+ @Override
+ public String getName() {
+ return "Inline date selection";
+ }
+
+ @Override
+ public String getDescription() {
+ return "In this example, the resolution is set to be one day"
+ + " and the DateField component is shown as an inline calendar"
+ + " component.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(DateField.class),
+ new APIResource(InlineDateField.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { DatePopup.class, DateLocale.class,
+ DateResolution.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/dates/DateInlineExample.java b/src/com/vaadin/demo/sampler/features/dates/DateInlineExample.java new file mode 100644 index 0000000000..5490b77a61 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/DateInlineExample.java @@ -0,0 +1,40 @@ +package com.vaadin.demo.sampler.features.dates;
+
+import java.text.DateFormat;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.InlineDateField;
+import com.vaadin.ui.VerticalLayout;
+
+public class DateInlineExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private InlineDateField datetime;
+
+ public DateInlineExample() {
+ setSpacing(true);
+
+ datetime = new InlineDateField("Please select the starting time:");
+
+ // Set the value of the PopupDateField to current date
+ datetime.setValue(new java.util.Date());
+
+ // Set the correct resolution
+ datetime.setResolution(InlineDateField.RESOLUTION_DAY);
+
+ // Add valuechangelistener
+ datetime.addListener(this);
+ datetime.setImmediate(true);
+
+ addComponent(datetime);
+ }
+
+ public void valueChange(ValueChangeEvent event) {
+ // Get the new value and format it to the current locale
+ DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT);
+ String dateOut = dateFormatter.format(event.getProperty().getValue());
+ // Show notification
+ getWindow().showNotification("Starting date: " + dateOut);
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/dates/DateLocale.java b/src/com/vaadin/demo/sampler/features/dates/DateLocale.java new file mode 100644 index 0000000000..f150afcdfd --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/DateLocale.java @@ -0,0 +1,42 @@ +package com.vaadin.demo.sampler.features.dates;
+
+import java.util.Locale;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.InlineDateField;
+
+public class DateLocale extends Feature {
+ @Override
+ public String getName() {
+ return "Date selection, locale";
+ }
+
+ @Override
+ public String getDescription() {
+ return "In this example, you can select a different locale"
+ + " from the combo box and see how the calendar component"
+ + " is localized.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(DateField.class),
+ new APIResource(InlineDateField.class),
+ new APIResource(Locale.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { DateInline.class, DatePopup.class,
+ DateResolution.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/dates/DateLocaleExample.java b/src/com/vaadin/demo/sampler/features/dates/DateLocaleExample.java new file mode 100644 index 0000000000..1e2e810b16 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/DateLocaleExample.java @@ -0,0 +1,48 @@ +package com.vaadin.demo.sampler.features.dates;
+
+import java.util.Locale;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.demo.sampler.ExampleUtil;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.InlineDateField;
+import com.vaadin.ui.VerticalLayout;
+
+public class DateLocaleExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private InlineDateField datetime;
+ private ComboBox localeSelection;
+
+ public DateLocaleExample() {
+ setSpacing(true);
+
+ datetime = new InlineDateField("Please select the starting time:");
+
+ // Set the value of the PopupDateField to current date
+ datetime.setValue(new java.util.Date());
+
+ // Set the correct resolution
+ datetime.setResolution(InlineDateField.RESOLUTION_MIN);
+ datetime.setImmediate(true);
+
+ // Create selection and fill it with locales
+ localeSelection = new ComboBox("Select date format:");
+ localeSelection.addListener(this);
+ localeSelection.setImmediate(true);
+ localeSelection
+ .setContainerDataSource(ExampleUtil.getLocaleContainer());
+
+ addComponent(datetime);
+ addComponent(localeSelection);
+ }
+
+ public void valueChange(ValueChangeEvent event) {
+ Item selected = localeSelection.getItem(event.getProperty().getValue());
+ datetime.setLocale((Locale) selected.getItemProperty(
+ ExampleUtil.locale_PROPERTY_LOCALE).getValue());
+ datetime.requestRepaint();
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/dates/DatePopup.java b/src/com/vaadin/demo/sampler/features/dates/DatePopup.java new file mode 100644 index 0000000000..fcc51cc853 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/DatePopup.java @@ -0,0 +1,38 @@ +package com.vaadin.demo.sampler.features.dates;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.PopupDateField;
+
+public class DatePopup extends Feature {
+ @Override
+ public String getName() {
+ return "Pop-up date selection";
+ }
+
+ @Override
+ public String getDescription() {
+ return "In this example, the resolution is set to be one day"
+ + " and the DateField component is shown as a calendar pop-up.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(DateField.class),
+ new APIResource(PopupDateField.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { DateInline.class, DateLocale.class,
+ DateResolution.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/dates/DatePopupExample.java b/src/com/vaadin/demo/sampler/features/dates/DatePopupExample.java new file mode 100644 index 0000000000..31e77a0e4a --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/DatePopupExample.java @@ -0,0 +1,46 @@ +package com.vaadin.demo.sampler.features.dates;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.PopupDateField;
+import com.vaadin.ui.VerticalLayout;
+
+public class DatePopupExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private PopupDateField datetime;
+
+ public DatePopupExample() {
+ setSpacing(true);
+
+ datetime = new PopupDateField("Please select the starting time:");
+
+ // Set the value of the PopupDateField to current date
+ datetime.setValue(new java.util.Date());
+
+ // Set the correct resolution
+ datetime.setResolution(PopupDateField.RESOLUTION_DAY);
+
+ // Add valuechangelistener
+ datetime.addListener(this);
+ datetime.setImmediate(true);
+
+ addComponent(datetime);
+ }
+
+ public void valueChange(ValueChangeEvent event) {
+ // Get the new value and format it to the current locale
+ DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT);
+ Object value = event.getProperty().getValue();
+ if (value == null || !(value instanceof Date)) {
+ getWindow().showNotification("Invalid date entered");
+ } else {
+ String dateOut = dateFormatter.format(value);
+ // Show notification
+ getWindow().showNotification("Starting date: " + dateOut);
+ }
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/dates/DateResolution.java b/src/com/vaadin/demo/sampler/features/dates/DateResolution.java new file mode 100644 index 0000000000..ba3d7d112f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/DateResolution.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.dates;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.InlineDateField;
+
+public class DateResolution extends Feature {
+ @Override
+ public String getName() {
+ return "Date selection, resolution";
+ }
+
+ @Override
+ public String getDescription() {
+ return "In this example, you can select a different resolution"
+ + " from the combo box and see how the calendar component"
+ + " changes.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(DateField.class),
+ new APIResource(InlineDateField.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { DateInline.class, DatePopup.class,
+ DateLocale.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/dates/DateResolutionExample.java b/src/com/vaadin/demo/sampler/features/dates/DateResolutionExample.java new file mode 100644 index 0000000000..dbbceeb7ec --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/dates/DateResolutionExample.java @@ -0,0 +1,69 @@ +package com.vaadin.demo.sampler.features.dates;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.InlineDateField;
+import com.vaadin.ui.VerticalLayout;
+
+public class DateResolutionExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ public static final Object resolution_PROPERTY_NAME = "name";
+ // Resolution fields from DateField
+ private static final int[] resolutions = { InlineDateField.RESOLUTION_YEAR,
+ InlineDateField.RESOLUTION_MONTH, InlineDateField.RESOLUTION_DAY,
+ InlineDateField.RESOLUTION_HOUR, InlineDateField.RESOLUTION_MIN,
+ InlineDateField.RESOLUTION_SEC, InlineDateField.RESOLUTION_MSEC };
+ private static final String[] resolutionNames = { "Year", "Month", "Day",
+ "Hour", "Minute", "Second", "Millisecond" };
+
+ private InlineDateField datetime;
+ private ComboBox localeSelection;
+
+ public DateResolutionExample() {
+ setSpacing(true);
+
+ datetime = new InlineDateField("Please select the starting time:");
+
+ // Set the value of the PopupDateField to current date
+ datetime.setValue(new java.util.Date());
+
+ // Set the correct resolution
+ datetime.setResolution(InlineDateField.RESOLUTION_DAY);
+ datetime.setImmediate(true);
+
+ // Create selection
+ localeSelection = new ComboBox("Select resolution:");
+ localeSelection.setNullSelectionAllowed(false);
+ localeSelection.addListener(this);
+ localeSelection.setImmediate(true);
+
+ // Fill the selection with choices, set captions correctly
+ localeSelection.setContainerDataSource(getResolutionContainer());
+ localeSelection.setItemCaptionPropertyId(resolution_PROPERTY_NAME);
+ localeSelection.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_PROPERTY);
+
+ addComponent(datetime);
+ addComponent(localeSelection);
+ }
+
+ public void valueChange(ValueChangeEvent event) {
+ datetime.setResolution((Integer) event.getProperty().getValue());
+ datetime.requestRepaint();
+ }
+
+ private IndexedContainer getResolutionContainer() {
+ IndexedContainer resolutionContainer = new IndexedContainer();
+ resolutionContainer.addContainerProperty(resolution_PROPERTY_NAME,
+ String.class, null);
+ for (int i = 0; i < resolutions.length; i++) {
+ Item added = resolutionContainer.addItem(resolutions[i]);
+ added.getItemProperty(resolution_PROPERTY_NAME).setValue(
+ resolutionNames[i]);
+ }
+ return resolutionContainer;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/form/75-FormBasic.png b/src/com/vaadin/demo/sampler/features/form/75-FormBasic.png Binary files differnew file mode 100644 index 0000000000..5044c729a6 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/form/75-FormBasic.png diff --git a/src/com/vaadin/demo/sampler/features/form/75-FormPojo.png b/src/com/vaadin/demo/sampler/features/form/75-FormPojo.png Binary files differnew file mode 100644 index 0000000000..df237b7cfc --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/form/75-FormPojo.png diff --git a/src/com/vaadin/demo/sampler/features/form/FormBasic.java b/src/com/vaadin/demo/sampler/features/form/FormBasic.java new file mode 100644 index 0000000000..25bd9197d2 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/form/FormBasic.java @@ -0,0 +1,55 @@ +package com.vaadin.demo.sampler.features.form; + +import com.vaadin.data.Validatable; +import com.vaadin.data.Validator; +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.demo.sampler.features.commons.Errors; +import com.vaadin.demo.sampler.features.commons.Validation; +import com.vaadin.ui.Component; +import com.vaadin.ui.Form; + +public class FormBasic extends Feature { + + @Override + public String getName() { + return "Form"; + } + + @Override + public Component getExample() { + return new FormPojoExample(); + } + + @Override + public String getDescription() { + return "A Form is most useful when connected to a data source, and" + + " provides buffering and customization features to support" + + " that scenario. A Form can easily be used as a POJO" + + " or Bean editor by wrapping the bean using BeanItem. <br/>" + + "The basic functionality only requires a couple of lines of" + + " code, then Validators and other customizations can be " + + "applied to taste. <br/>Enter something and try discarding or " + + "applying."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Validatable.class), + new APIResource(Validator.class), new APIResource(Form.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { Validation.class, Errors.class, + FeatureSet.Forms.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/form/FormPojo.java b/src/com/vaadin/demo/sampler/features/form/FormPojo.java new file mode 100644 index 0000000000..b2f92faa14 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/form/FormPojo.java @@ -0,0 +1,51 @@ +package com.vaadin.demo.sampler.features.form; + +import com.vaadin.data.Validatable; +import com.vaadin.data.Validator; +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.demo.sampler.features.commons.Errors; +import com.vaadin.demo.sampler.features.commons.Validation; +import com.vaadin.ui.Component; +import com.vaadin.ui.Form; + +public class FormPojo extends Feature { + + @Override + public String getName() { + return "Bean-bound form"; + } + + @Override + public Component getExample() { + return new FormPojoExample(); + } + + @Override + public String getDescription() { + return "A Form can easily be used as a POJO or Bean editor by wrapping the" + + " bean using BeanItem. The basic functionality only requires" + + " a couple of lines of code, then Validators and other" + + " customizations can be applied to taste."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Validatable.class), + new APIResource(Validator.class), new APIResource(Form.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { Validation.class, Errors.class, + FeatureSet.Forms.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/form/FormPojoExample.java b/src/com/vaadin/demo/sampler/features/form/FormPojoExample.java new file mode 100644 index 0000000000..e8e0ebb4b2 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/form/FormPojoExample.java @@ -0,0 +1,253 @@ +package com.vaadin.demo.sampler.features.form; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Date; +import java.util.UUID; + +import com.vaadin.data.Item; +import com.vaadin.data.Validator; +import com.vaadin.data.util.BeanItem; +import com.vaadin.data.validator.StringLengthValidator; +import com.vaadin.demo.sampler.ExampleUtil; +import com.vaadin.ui.BaseFieldFactory; +import com.vaadin.ui.Button; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.Field; +import com.vaadin.ui.Form; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; +import com.vaadin.ui.Button.ClickEvent; + +@SuppressWarnings("serial") +public class FormPojoExample extends VerticalLayout { + + // the 'POJO' we're editing + Person person; + + public FormPojoExample() { + + person = new Person(); // a person POJO + BeanItem personItem = new BeanItem(person); // item from POJO + + // Create the Form + final Form personForm = new Form(); + personForm.setWriteThrough(false); // we want explicit 'apply' + personForm.setInvalidCommitted(false); // no invalid values in datamodel + + // FieldFactory for customizing the fields and adding validators + personForm.setFieldFactory(new PersonFieldFactory()); + personForm.setItemDataSource(personItem); // bind to POJO via BeanItem + + // Determines which properties are shown, and in which order: + personForm.setVisibleItemProperties(Arrays.asList(new String[] { + "firstName", "lastName", "countryCode", "password", + "birthdate", "shoesize", "uuid" })); + + // Add form to layout + addComponent(personForm); + + // The cancel / apply buttons + HorizontalLayout buttons = new HorizontalLayout(); + buttons.setSpacing(true); + Button discardChanges = new Button("Discard changes", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + personForm.discard(); + } + }); + discardChanges.setStyleName(Button.STYLE_LINK); + buttons.addComponent(discardChanges); + + Button apply = new Button("Apply", new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + try { + personForm.commit(); + } catch (Exception e) { + // Ingnored, we'll let the Form handle the errors + } + } + }); + buttons.addComponent(apply); + personForm.getLayout().addComponent(buttons); + + // button for showing the internal state of the POJO + Button showPojoState = new Button("Show POJO internal state", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + showPojoState(); + } + }); + addComponent(showPojoState); + } + + private void showPojoState() { + Window.Notification n = new Window.Notification("POJO state", + Window.Notification.TYPE_TRAY_NOTIFICATION); + n.setPosition(Window.Notification.POSITION_CENTERED); + n.setDescription("First name: " + person.getFirstName() + + "<br/>Last name: " + person.getLastName() + "<br/>Country: " + + person.getCountryCode() + "<br/>Birthdate: " + + person.getBirthdate() + "<br/>Shoe size: " + + +person.getShoesize() + "<br/>Password: " + + person.getPassword() + "<br/>UUID: " + person.getUuid()); + getWindow().showNotification(n); + } + + private class PersonFieldFactory extends BaseFieldFactory { + + final ComboBox countries = new ComboBox("Country"); + + public PersonFieldFactory() { + countries.setWidth("30em"); + countries.setContainerDataSource(ExampleUtil + .getStaticISO3166Container()); + countries + .setItemCaptionPropertyId(ExampleUtil.iso3166_PROPERTY_NAME); + countries.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG); + countries.setFilteringMode(ComboBox.FILTERINGMODE_STARTSWITH); + } + + @Override + public Field createField(Item item, Object propertyId, + Component uiContext) { + if ("countryCode".equals(propertyId)) { + // filtering ComboBox w/ country names + return countries; + } + Field f = super.createField(item, propertyId, uiContext); + if ("firstName".equals(propertyId)) { + TextField tf = (TextField) f; + tf.setRequired(true); + tf.setRequiredError("Please enter a First Name"); + tf.setWidth("15em"); + tf.addValidator(new StringLengthValidator( + "First Name must be 3-25 characters", 3, 25, false)); + } else if ("lastName".equals(propertyId)) { + TextField tf = (TextField) f; + tf.setRequired(true); + tf.setRequiredError("Please enter a Last Name"); + tf.setWidth("20em"); + tf.addValidator(new StringLengthValidator( + "Last Name must be 3-50 characters", 3, 50, false)); + } else if ("password".equals(propertyId)) { + TextField tf = (TextField) f; + tf.setSecret(true); + tf.setRequired(true); + tf.setRequiredError("Please enter a password"); + tf.setWidth("10em"); + tf.addValidator(new StringLengthValidator( + "Password must be 6-20 characters", 6, 20, false)); + } else if ("shoesize".equals(propertyId)) { + TextField tf = (TextField) f; + tf.addValidator(new IntegerValidator( + "Shoe size must be an Integer")); + tf.setWidth("2em"); + } else if ("uuid".equals(propertyId)) { + TextField tf = (TextField) f; + tf.setWidth("20em"); + } + + return f; + } + } + + public class Person implements Serializable { + + private String firstName = ""; + private String lastName = ""; + private Date birthdate; + private int shoesize = 42; + private String password = ""; + private UUID uuid; + private String countryCode = ""; + + public Person() { + uuid = UUID.randomUUID(); + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Date getBirthdate() { + return birthdate; + } + + public void setBirthdate(Date birthdate) { + this.birthdate = birthdate; + } + + public int getShoesize() { + return shoesize; + } + + public void setShoesize(int shoesize) { + this.shoesize = shoesize; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public UUID getUuid() { + return uuid; + } + + public String getCountryCode() { + return countryCode; + } + + public void setCountryCode(String countryCode) { + this.countryCode = countryCode; + } + + } + + public class IntegerValidator implements Validator { + + private String message; + + public IntegerValidator(String message) { + this.message = message; + } + + public boolean isValid(Object value) { + if (value == null || !(value instanceof String)) { + return false; + } + try { + Integer.parseInt((String) value); + } catch (Exception e) { + return false; + } + return true; + } + + public void validate(Object value) throws InvalidValueException { + if (!isValid(value)) { + throw new InvalidValueException(message); + } + } + + } +} diff --git a/src/com/vaadin/demo/sampler/features/layouts/75-ApplicationLayout.png b/src/com/vaadin/demo/sampler/features/layouts/75-ApplicationLayout.png Binary files differnew file mode 100644 index 0000000000..ee1d0a1c78 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/75-ApplicationLayout.png diff --git a/src/com/vaadin/demo/sampler/features/layouts/75-CustomLayouts.png b/src/com/vaadin/demo/sampler/features/layouts/75-CustomLayouts.png Binary files differnew file mode 100644 index 0000000000..a37e342d9e --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/75-CustomLayouts.png diff --git a/src/com/vaadin/demo/sampler/features/layouts/75-ExpandingComponent.png b/src/com/vaadin/demo/sampler/features/layouts/75-ExpandingComponent.png Binary files differnew file mode 100644 index 0000000000..dcc9ac5550 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/75-ExpandingComponent.png diff --git a/src/com/vaadin/demo/sampler/features/layouts/75-GridLayoutBasic.png b/src/com/vaadin/demo/sampler/features/layouts/75-GridLayoutBasic.png Binary files differnew file mode 100644 index 0000000000..a9c298cf3f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/75-GridLayoutBasic.png diff --git a/src/com/vaadin/demo/sampler/features/layouts/75-HorizontalLayoutBasic.png b/src/com/vaadin/demo/sampler/features/layouts/75-HorizontalLayoutBasic.png Binary files differnew file mode 100644 index 0000000000..d83a7183d5 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/75-HorizontalLayoutBasic.png diff --git a/src/com/vaadin/demo/sampler/features/layouts/75-LayoutAlignment.png b/src/com/vaadin/demo/sampler/features/layouts/75-LayoutAlignment.png Binary files differnew file mode 100644 index 0000000000..3aedc76879 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/75-LayoutAlignment.png diff --git a/src/com/vaadin/demo/sampler/features/layouts/75-LayoutMargin.png b/src/com/vaadin/demo/sampler/features/layouts/75-LayoutMargin.png Binary files differnew file mode 100644 index 0000000000..802ef00a86 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/75-LayoutMargin.png diff --git a/src/com/vaadin/demo/sampler/features/layouts/75-LayoutSpacing.png b/src/com/vaadin/demo/sampler/features/layouts/75-LayoutSpacing.png Binary files differnew file mode 100644 index 0000000000..502bdc169b --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/75-LayoutSpacing.png diff --git a/src/com/vaadin/demo/sampler/features/layouts/75-SplitPanelBasic.png b/src/com/vaadin/demo/sampler/features/layouts/75-SplitPanelBasic.png Binary files differnew file mode 100644 index 0000000000..562d6af32b --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/75-SplitPanelBasic.png diff --git a/src/com/vaadin/demo/sampler/features/layouts/75-VerticalLayoutBasic.png b/src/com/vaadin/demo/sampler/features/layouts/75-VerticalLayoutBasic.png Binary files differnew file mode 100644 index 0000000000..2e6bf6b484 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/75-VerticalLayoutBasic.png diff --git a/src/com/vaadin/demo/sampler/features/layouts/75-WebLayout.png b/src/com/vaadin/demo/sampler/features/layouts/75-WebLayout.png Binary files differnew file mode 100644 index 0000000000..a9405c768c --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/75-WebLayout.png diff --git a/src/com/vaadin/demo/sampler/features/layouts/ApplicationLayout.java b/src/com/vaadin/demo/sampler/features/layouts/ApplicationLayout.java new file mode 100644 index 0000000000..38194b4c64 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/ApplicationLayout.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.VerticalLayout;
+
+public class ApplicationLayout extends Feature {
+
+ @Override
+ public String getName() {
+ return "Application-style layout";
+ }
+
+ @Override
+ public String getDescription() {
+ return "It can be helpful to distinguish between <i>web-style</i> and"
+ + " <i>application-style</i> layouting (although this is a"
+ + " simplification). Both styles are supported, and can be used"
+ + " simultaneously.<br/> Application-style layouting uses relatively"
+ + " -sized components, growing dynamically with the window, and"
+ + " causing scrollbars to appear on well-defined areas within the"
+ + " window."
+ + "<br/>Try resizing the window to see how the content reacts.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(HorizontalLayout.class),
+ new APIResource(VerticalLayout.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { WebLayout.class, CustomLayouts.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return null;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/layouts/ApplicationLayoutExample.java b/src/com/vaadin/demo/sampler/features/layouts/ApplicationLayoutExample.java new file mode 100644 index 0000000000..79b6e1258f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/ApplicationLayoutExample.java @@ -0,0 +1,99 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import java.util.Iterator;
+
+import com.vaadin.demo.sampler.ExampleUtil;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.Tree;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Window.CloseEvent;
+
+public class ApplicationLayoutExample extends VerticalLayout {
+
+ Window win = new ApplicationLayoutWindow();
+ Button open = new Button("Open sample in subwindow");
+
+ public ApplicationLayoutExample() {
+ setMargin(true);
+
+ // We'll open this example in a separate window, configure it
+ win.setWidth("70%");
+ win.setHeight("70%");
+ win.center();
+ // Allow opening window again when closed
+ win.addListener(new Window.CloseListener() {
+ public void windowClose(CloseEvent e) {
+ open.setEnabled(true);
+ }
+ });
+
+ // 'open sample' button
+ addComponent(open);
+ open.addListener(new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ getWindow().addWindow(win);
+ open.setEnabled(false);
+ }
+ });
+ addComponent(new Label(
+ ("Don't worry: the content of the window is not supposed to make sense...")));
+
+ }
+
+ class ApplicationLayoutWindow extends Window {
+ ApplicationLayoutWindow() {
+ // Our main layout is a horizontal layout
+ HorizontalLayout main = new HorizontalLayout();
+ main.setSizeFull();
+ setLayout(main);
+
+ // Tree to the left
+ Panel treePanel = new Panel(); // for scrollbars
+ treePanel.setStyleName(Panel.STYLE_LIGHT);
+ treePanel.setHeight("100%");
+ treePanel.setWidth(null);
+ treePanel.getLayout().setSizeUndefined();
+ addComponent(treePanel);
+
+ Tree tree = new Tree();
+ tree.setContainerDataSource(ExampleUtil.getHardwareContainer());
+ tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME);
+ for (Iterator it = tree.rootItemIds().iterator(); it.hasNext();) {
+ tree.expandItemsRecursively(it.next());
+ }
+ treePanel.addComponent(tree);
+
+ // vertically divide the right area
+ VerticalLayout left = new VerticalLayout();
+ left.setSizeFull();
+ addComponent(left);
+ main.setExpandRatio(left, 1.0f); // use all available space
+
+ // table on top
+ Table tbl = new Table();
+ tbl.setWidth("100%");
+ tbl.setContainerDataSource(ExampleUtil.getISO3166Container());
+ tbl.setSortDisabled(true);
+ tbl.setPageLength(7);
+ left.addComponent(tbl);
+
+ // Label on bottom
+ Panel textPanel = new Panel(); // for scrollbars
+ textPanel.setStyleName(Panel.STYLE_LIGHT);
+ textPanel.setSizeFull();
+ left.addComponent(textPanel);
+ left.setExpandRatio(textPanel, 1.0f); // use all available space
+
+ Label text = new Label(ExampleUtil.lorem, Label.CONTENT_XHTML);
+ text.setWidth("500px"); // some limit is good for text
+ textPanel.addComponent(text);
+
+ }
+ }
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/features/layouts/CustomLayouts.java b/src/com/vaadin/demo/sampler/features/layouts/CustomLayouts.java new file mode 100644 index 0000000000..8ade132ac2 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/CustomLayouts.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.CustomLayout;
+
+public class CustomLayouts extends Feature {
+
+ @Override
+ public String getName() {
+ return "Custom layout";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The CustomLayout allows you to make a layout in regular HTML,"
+ + " using styles and embedding images to suit your needs."
+ + " You can even make the layout using a WYSIWYG editor.<br/>"
+ + " Marking an area in the HTML as a named <i>location</i>"
+ + " will allow you to replace that area with a component later."
+ + "<br/>HTML prototypes can often be quickly converted into a"
+ + " working application this way, providing a clear path from"
+ + " design to implementation.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(CustomLayout.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { WebLayout.class, ApplicationLayout.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return new NamedExternalResource[] { new NamedExternalResource(
+ "Layout HTML (view source)", getThemeBase()
+ + "layouts/examplecustomlayout.html") };
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/layouts/CustomLayoutsExample.java b/src/com/vaadin/demo/sampler/features/layouts/CustomLayoutsExample.java new file mode 100644 index 0000000000..f829009555 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/CustomLayoutsExample.java @@ -0,0 +1,30 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CustomLayout;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+
+public class CustomLayoutsExample extends VerticalLayout {
+
+ public CustomLayoutsExample() {
+ setMargin(true);
+
+ // Create the custom layout and set it as a component in
+ // the current layout
+ CustomLayout custom = new CustomLayout("examplecustomlayout");
+ addComponent(custom);
+
+ // Create components and bind them to the location tags
+ // in the custom layout.
+ TextField username = new TextField();
+ custom.addComponent(username, "username");
+
+ TextField password = new TextField();
+ password.setSecret(true);
+ custom.addComponent(password, "password");
+
+ Button ok = new Button("Login");
+ custom.addComponent(ok, "okbutton");
+ }
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/features/layouts/ExpandingComponent.java b/src/com/vaadin/demo/sampler/features/layouts/ExpandingComponent.java new file mode 100644 index 0000000000..8a58d73eb7 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/ExpandingComponent.java @@ -0,0 +1,41 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.HorizontalLayout;
+
+public class ExpandingComponent extends Feature {
+
+ @Override
+ public String getName() {
+ return "Expanding components";
+ }
+
+ @Override
+ public String getDescription() {
+ return "You can <i>expand</i> components to make them"
+ + " occupy the space left over by other components.<br/>"
+ + " If more than one component is expanded, the <i>ratio</i>"
+ + " determines how the leftover space is shared between the"
+ + " expanded components.<br/>Mousover each component for a"
+ + " description (tooltip).<br/> Also try resizing the window.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(HorizontalLayout.class),
+
+ };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] {};
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return null;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/layouts/ExpandingComponentExample.java b/src/com/vaadin/demo/sampler/features/layouts/ExpandingComponentExample.java new file mode 100644 index 0000000000..1638fbe8a2 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/ExpandingComponentExample.java @@ -0,0 +1,64 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.VerticalLayout;
+
+public class ExpandingComponentExample extends VerticalLayout {
+
+ public ExpandingComponentExample() {
+ setSpacing(true);
+
+ { // Basic scenario: single expanded component
+ HorizontalLayout layout = new HorizontalLayout();
+ layout.setWidth("100%"); // make the layout grow with the window
+ // size
+ addComponent(layout);
+
+ Button naturalButton = new Button("Natural");
+ naturalButton
+ .setDescription("This button does not have an explicit size - instead, it's size depends on it's content - a.k.a <i>natural size.</i>");
+ layout.addComponent(naturalButton);
+
+ Button expandedButton = new Button("Expanded");
+ expandedButton.setWidth("100%");
+ expandedButton
+ .setDescription("This button is set to 100% and expanded, and will thus occupy the space left over by the other components.");
+ layout.addComponent(expandedButton);
+ layout.setExpandRatio(expandedButton, 1.0f);
+
+ Button sizedButton = new Button("Explicit");
+ sizedButton.setWidth("150px");
+ sizedButton
+ .setDescription("This button is explicitly set to be 150 pixels wide.");
+ layout.addComponent(sizedButton);
+ }
+
+ { // Ratio example
+ HorizontalLayout layout = new HorizontalLayout();
+ layout.setWidth("100%"); // make the layout grow with the window
+ // size
+ addComponent(layout);
+
+ Button naturalButton = new Button("Natural");
+ naturalButton
+ .setDescription("This button does not have an explicit size - instead, it's size depends on it's content - a.k.a <i>natural size.</i>");
+ layout.addComponent(naturalButton);
+
+ Button expandedButton1 = new Button("Ratio 1.0");
+ expandedButton1.setWidth("100%");
+ expandedButton1
+ .setDescription("This button is set to 100% and expanded with a ratio of 1.0, and will in this example occupy 1:2 of the leftover space.");
+ layout.addComponent(expandedButton1);
+ layout.setExpandRatio(expandedButton1, 1.0f);
+
+ Button expandedButton2 = new Button("Ratio 2.0");
+ expandedButton2.setWidth("100%");
+ expandedButton2
+ .setDescription("This button is set to 100% and expanded with a ratio of 2.0, and will in this example occupy 2:1 of the leftover space.");
+ layout.addComponent(expandedButton2);
+ layout.setExpandRatio(expandedButton2, 2.0f);
+ }
+
+ }
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/features/layouts/GridLayoutBasic.java b/src/com/vaadin/demo/sampler/features/layouts/GridLayoutBasic.java new file mode 100644 index 0000000000..e850e5ab4c --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/GridLayoutBasic.java @@ -0,0 +1,40 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.GridLayout;
+
+public class GridLayoutBasic extends Feature {
+
+ @Override
+ public String getName() {
+ return "Grid layout";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The GridLayout allows you to create a grid of components."
+ + " The grid may have an arbitrary number of cells in each direction"
+ + " and you can easily set components to fill multiple cells.<br/>It supports all basic features, plus some advanced stuff - including spacing, margin, alignment, and expand ratios.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(GridLayout.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { HorizontalLayoutBasic.class,
+ VerticalLayoutBasic.class, LayoutSpacing.class,
+ LayoutMargin.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return new NamedExternalResource[] { new NamedExternalResource(
+ "CSS for the layout", getThemeBase()
+ + "layouts/gridexample.css") };
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/layouts/GridLayoutBasicExample.java b/src/com/vaadin/demo/sampler/features/layouts/GridLayoutBasicExample.java new file mode 100644 index 0000000000..6b5e430664 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/GridLayoutBasicExample.java @@ -0,0 +1,55 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import com.vaadin.terminal.Sizeable;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.VerticalLayout;
+
+public class GridLayoutBasicExample extends VerticalLayout {
+
+ public GridLayoutBasicExample() {
+ // Create a grid layout
+ final GridLayout grid = new GridLayout(3, 3);
+ grid.setSpacing(true);
+
+ // The style allows us to visualize the cell borders in this example.
+ grid.addStyleName("gridexample");
+
+ grid.setWidth(400, Sizeable.UNITS_PIXELS);
+ grid.setHeight(400, Sizeable.UNITS_PIXELS);
+
+ // First we insert four components that occupy one cell each
+ Button topleft = new Button("Top Left");
+ grid.addComponent(topleft, 0, 0);
+ grid.setComponentAlignment(topleft, Alignment.MIDDLE_CENTER);
+
+ Button topcenter = new Button("Top Center");
+ grid.addComponent(topcenter, 1, 0);
+ grid.setComponentAlignment(topcenter, Alignment.MIDDLE_CENTER);
+
+ Button bottomleft = new Button("Bottom Left");
+ grid.addComponent(bottomleft, 0, 2);
+ grid.setComponentAlignment(bottomleft, Alignment.MIDDLE_CENTER);
+
+ Button bottomcenter = new Button("Bottom Center");
+ grid.addComponent(bottomcenter, 1, 2);
+ grid.setComponentAlignment(bottomcenter, Alignment.MIDDLE_CENTER);
+
+ // Insert a component that occupies all the rightmost cells
+ Button topright = new Button("Extra height");
+ grid.addComponent(topright, 2, 0, 2, 2);
+ grid.setComponentAlignment(topright, Alignment.MIDDLE_CENTER);
+
+ // Insert a component that occupies two cells in horizontal direction
+ Button middleleft = new Button("This is a wide cell in GridLayout");
+ grid.addComponent(middleleft, 0, 1, 1, 1);
+ grid.setComponentAlignment(middleleft, Alignment.MIDDLE_CENTER);
+
+ // Add the layout to the containing layout.
+ addComponent(grid);
+
+ // Align the grid itself within its container layout.
+ setComponentAlignment(grid, Alignment.MIDDLE_CENTER);
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/layouts/HorizontalLayoutBasic.java b/src/com/vaadin/demo/sampler/features/layouts/HorizontalLayoutBasic.java new file mode 100644 index 0000000000..3c72b2733f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/HorizontalLayoutBasic.java @@ -0,0 +1,35 @@ +package com.vaadin.demo.sampler.features.layouts; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.HorizontalLayout; + +public class HorizontalLayoutBasic extends Feature { + + @Override + public String getName() { + return "Horizontal layout"; + } + + @Override + public String getDescription() { + return "The HorizontalLayout arranges components horizontally.<br/>It supports all basic features, plus some advanced stuff - including spacing, margin, alignment, and expand ratios."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(HorizontalLayout.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { VerticalLayoutBasic.class, LayoutSpacing.class, + LayoutAlignment.class, }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } +} diff --git a/src/com/vaadin/demo/sampler/features/layouts/HorizontalLayoutBasicExample.java b/src/com/vaadin/demo/sampler/features/layouts/HorizontalLayoutBasicExample.java new file mode 100644 index 0000000000..4b09f218bc --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/HorizontalLayoutBasicExample.java @@ -0,0 +1,48 @@ +package com.vaadin.demo.sampler.features.layouts; + +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextField; + +public class HorizontalLayoutBasicExample extends HorizontalLayout { + + public HorizontalLayoutBasicExample() { + // this is a HorizontalLayout + + // First TextField + TextField tf = new TextField(); + tf.setWidth("70px"); + addComponent(tf); + + // A dash + Label dash = new Label("-"); + addComponent(dash); + setComponentAlignment(dash, "middle"); + + // Second TextField + tf = new TextField(); + tf.setWidth("70px"); + addComponent(tf); + + // Another dash + dash = new Label("-"); + addComponent(dash); + setComponentAlignment(dash, "middle"); + + // Third TextField + tf = new TextField(); + tf.setWidth("70px"); + addComponent(tf); + + // Yet another dash + dash = new Label("-"); + addComponent(dash); + setComponentAlignment(dash, "middle"); + + // Forth and last TextField + tf = new TextField(); + tf.setWidth("70px"); + addComponent(tf); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/layouts/LayoutAlignment.java b/src/com/vaadin/demo/sampler/features/layouts/LayoutAlignment.java new file mode 100644 index 0000000000..531ae1acdc --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/LayoutAlignment.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.layouts; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.VerticalLayout; + +public class LayoutAlignment extends Feature { + + @Override + public String getName() { + return "Component Alignment"; + } + + @Override + public String getDescription() { + return "GridLayout, VerticalLayout, and HorizontalLayout, " + + "which are tabular layouts consisting of cells, " + + "support alignment of components within the layout cells. " + + "The alignment of a component within its respective cell " + + "is set with setComponentAlignment()."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(VerticalLayout.class), + new APIResource(HorizontalLayout.class), + new APIResource(GridLayout.class), }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { HorizontalLayoutBasic.class, + VerticalLayoutBasic.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } +} diff --git a/src/com/vaadin/demo/sampler/features/layouts/LayoutAlignmentExample.java b/src/com/vaadin/demo/sampler/features/layouts/LayoutAlignmentExample.java new file mode 100644 index 0000000000..853aedd003 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/LayoutAlignmentExample.java @@ -0,0 +1,88 @@ +package com.vaadin.demo.sampler.features.layouts; + +import com.vaadin.terminal.gwt.client.ui.AlignmentInfo.Bits; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.VerticalLayout; + +public class LayoutAlignmentExample extends VerticalLayout { + + @SuppressWarnings("deprecation") + public LayoutAlignmentExample() { + // Create a grid layout + final GridLayout grid = new GridLayout(1, 9); + grid.setSpacing(true); + + // The style allows us to visualize the cell borders in this example. + grid.addStyleName("gridexample"); + + grid.setWidth("300px"); + grid.setHeight("500px"); + + // Put a component in each cell with respective alignment. + // We'll use different ways to set the alignment: constants, bitmasks, + // and string-shorthand. + + // Here we use the shorthand constants to set the alignment: + // Alignment.TOP_LEFT, Alignment.TOP_CENTER, Alignment.TOP_RIGHT + // Alignment.MIDDLE_LEFT, Alignment.MIDDLE_CENTER, + // Alignment.MIDDLE_RIGHT + // Alignment.BOTTOM_LEFT, Alignment.BOTTOM_CENTER, + // Alignment.BOTTOM_RIGHT + + Button topleft = new Button("Top Left"); + grid.addComponent(topleft); + grid.setComponentAlignment(topleft, Alignment.TOP_LEFT); + + Button topcenter = new Button("Top Center"); + grid.addComponent(topcenter); + grid.setComponentAlignment(topcenter, Alignment.TOP_CENTER); + + Button topright = new Button("Top Right"); + grid.addComponent(topright); + grid.setComponentAlignment(topright, Alignment.TOP_RIGHT); + + // Here we use bit additions to set the alignment: + // Bits.ALIGNMENT_LEFT, Bits.ALIGNMENT_RIGHT + // Bits.ALIGNMENT_TOP, Bits.ALIGNMENT_BOTTOM + // Bits.ALIGNMENT_VERTICAL_CENTER, Bits.ALIGNMENT_HORIZONTAL_CENTER + + Button middleleft = new Button("Middle Left"); + grid.addComponent(middleleft); + grid.setComponentAlignment(middleleft, new Alignment( + Bits.ALIGNMENT_VERTICAL_CENTER | Bits.ALIGNMENT_LEFT)); + + Button middlecenter = new Button("Middle Center"); + grid.addComponent(middlecenter); + grid.setComponentAlignment(middlecenter, new Alignment( + Bits.ALIGNMENT_VERTICAL_CENTER + | Bits.ALIGNMENT_HORIZONTAL_CENTER)); + + Button middleright = new Button("Middle Right"); + grid.addComponent(middleright); + grid.setComponentAlignment(middleright, new Alignment( + Bits.ALIGNMENT_VERTICAL_CENTER | Bits.ALIGNMENT_RIGHT)); + + // Here we'll use the convenient string-shorthand: + + Button bottomleft = new Button("Bottom Left"); + grid.addComponent(bottomleft); + grid.setComponentAlignment(bottomleft, "bottom left"); + + Button bottomcenter = new Button("Bottom Center"); + grid.addComponent(bottomcenter); + grid.setComponentAlignment(bottomcenter, "bottom center"); + + Button bottomright = new Button("Bottom Right"); + grid.addComponent(bottomright); + grid.setComponentAlignment(bottomright, "bottom right"); + + // Add the layout to the containing layout. + addComponent(grid); + + // Align the grid itself within its container layout. + setComponentAlignment(grid, Alignment.MIDDLE_CENTER); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/layouts/LayoutMargin.java b/src/com/vaadin/demo/sampler/features/layouts/LayoutMargin.java new file mode 100644 index 0000000000..e2c88434d9 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/LayoutMargin.java @@ -0,0 +1,47 @@ +package com.vaadin.demo.sampler.features.layouts; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.VerticalLayout; + +public class LayoutMargin extends Feature { + + @Override + public String getName() { + return "Layout margin"; + } + + @Override + public String getDescription() { + return "Layouts can have margins on any of the sides. The actual size" + + " of the margin is determined by the theme, and can be" + + " customized using CSS - in this example, the right margin" + + " size is increased.<br/>Note that <i>margin</i>" + + " is the space around the layout as a whole, and" + + " <i>spacing</i> is the space between the component within" + + " the layout."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(VerticalLayout.class), + new APIResource(HorizontalLayout.class), + new APIResource(GridLayout.class), }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { LayoutSpacing.class, HorizontalLayoutBasic.class, + VerticalLayoutBasic.class, GridLayoutBasic.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return new NamedExternalResource[] { new NamedExternalResource( + "CSS for the layout", getThemeBase() + + "layouts/marginexample.css") }; + } +} diff --git a/src/com/vaadin/demo/sampler/features/layouts/LayoutMarginExample.java b/src/com/vaadin/demo/sampler/features/layouts/LayoutMarginExample.java new file mode 100644 index 0000000000..355486db79 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/LayoutMarginExample.java @@ -0,0 +1,58 @@ +package com.vaadin.demo.sampler.features.layouts; + +import com.vaadin.ui.Button; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; + +public class LayoutMarginExample extends GridLayout implements + Button.ClickListener { + + VerticalLayout marginLayout; + Button topMargin; + Button rightMargin; + Button bottomMargin; + Button leftMargin; + + public LayoutMarginExample() { + super(3, 3); + + space(); + topMargin = new Button("Top margin", this); + topMargin.setSwitchMode(true); + addComponent(topMargin); + setComponentAlignment(topMargin, "center"); + + space(); + leftMargin = new Button("Left margin", this); + leftMargin.setSwitchMode(true); + addComponent(leftMargin); + setComponentAlignment(leftMargin, "middle"); + + marginLayout = new VerticalLayout(); + marginLayout.setStyleName("marginexample"); + marginLayout.setSizeUndefined(); + addComponent(marginLayout); + marginLayout.addComponent(new Label("Margins all around?")); + + rightMargin = new Button("Right margin", this); + rightMargin.setSwitchMode(true); + addComponent(rightMargin); + setComponentAlignment(rightMargin, "middle"); + + space(); + bottomMargin = new Button("Bottom margin", this); + bottomMargin.setSwitchMode(true); + addComponent(bottomMargin); + setComponentAlignment(bottomMargin, "center"); + + } + + public void buttonClick(ClickEvent event) { + marginLayout.setMargin(topMargin.booleanValue(), rightMargin + .booleanValue(), bottomMargin.booleanValue(), leftMargin + .booleanValue()); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/layouts/LayoutSpacing.java b/src/com/vaadin/demo/sampler/features/layouts/LayoutSpacing.java new file mode 100644 index 0000000000..b6d214289e --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/LayoutSpacing.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.layouts; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.VerticalLayout; + +public class LayoutSpacing extends Feature { + + @Override + public String getName() { + return "Layout Spacing"; + } + + @Override + public String getDescription() { + return "Spacing between components can be enabled or disabled." + + " The actual size of the spacing is determined by the theme," + + " and can be customized with CSS.<br/>Note that <i>spacing</i>" + + " is the space between components within the layout, and" + + " <i>margin</i> is the space around the layout as a whole."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(VerticalLayout.class), + new APIResource(HorizontalLayout.class), + new APIResource(GridLayout.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { LayoutMargin.class, HorizontalLayoutBasic.class, + VerticalLayoutBasic.class, GridLayoutBasic.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } +} diff --git a/src/com/vaadin/demo/sampler/features/layouts/LayoutSpacingExample.java b/src/com/vaadin/demo/sampler/features/layouts/LayoutSpacingExample.java new file mode 100644 index 0000000000..62891ac77d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/LayoutSpacingExample.java @@ -0,0 +1,38 @@ +package com.vaadin.demo.sampler.features.layouts; + +import com.vaadin.ui.Button; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; + +public class LayoutSpacingExample extends VerticalLayout { + + public LayoutSpacingExample() { + // Create a grid layout. + final GridLayout grid = new GridLayout(3, 3); + + // Add the layout to the containing layout. + addComponent(grid); + + // Add a style to allow customization of the layout. + grid.addStyleName("spacingexample"); + + // Populate the layout with components. + for (int i = 0; i < 9; i++) { + grid.addComponent(new Button("Component " + (i + 1))); + } + + // CheckBox for toggling spacing on and off + final CheckBox spacing = new CheckBox("Spacing enabled"); + spacing.setImmediate(true); + spacing.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + grid.setSpacing(spacing.booleanValue()); + } + }); + addComponent(spacing); + + setSpacing(true); // enable spacing for the example itself + } +} diff --git a/src/com/vaadin/demo/sampler/features/layouts/SplitPanelBasic.java b/src/com/vaadin/demo/sampler/features/layouts/SplitPanelBasic.java new file mode 100644 index 0000000000..3ac9fe606e --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/SplitPanelBasic.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.SplitPanel;
+
+public class SplitPanelBasic extends Feature {
+
+ @Override
+ public String getName() {
+ return "Split panel";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The SplitPanel has two resizable component areas, either"
+ + " vertically or horizontally oriented. The split position"
+ + " can optionally be locked.<br/> By nesting split panels,"
+ + " one can make quite complicated, dynamic layouts.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(SplitPanel.class),
+
+ };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] {};
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return null;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/layouts/SplitPanelBasicExample.java b/src/com/vaadin/demo/sampler/features/layouts/SplitPanelBasicExample.java new file mode 100644 index 0000000000..b1dd1972ab --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/SplitPanelBasicExample.java @@ -0,0 +1,50 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.SplitPanel;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class SplitPanelBasicExample extends VerticalLayout {
+
+ public static final String brownFox = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. ";
+
+ public SplitPanelBasicExample() {
+ // First a vertical SplitPanel
+ final SplitPanel vert = new SplitPanel();
+ vert.setHeight("450px");
+ vert.setWidth("100%");
+ // vert.setOrientation(SplitPanel.ORIENTATION_VERTICAL); // default
+ vert.setSplitPosition(150, SplitPanel.UNITS_PIXELS);
+ addComponent(vert);
+
+ // add a label to the upper area
+ vert.addComponent(new Label(brownFox));
+
+ // Add a horizontal SplitPanel to the lower area
+ final SplitPanel horiz = new SplitPanel();
+ horiz.setOrientation(SplitPanel.ORIENTATION_HORIZONTAL);
+ horiz.setSplitPosition(50); // percent
+ vert.addComponent(horiz);
+
+ // left component:
+ horiz.addComponent(new Label(brownFox));
+
+ // right component:
+ horiz.addComponent(new Label(brownFox));
+
+ // Lock toggle button
+ Button toggleLocked = new Button("Splits locked",
+ new Button.ClickListener() {
+ // inline click.listener
+ public void buttonClick(ClickEvent event) {
+ vert.setLocked(event.getButton().booleanValue());
+ horiz.setLocked(event.getButton().booleanValue());
+ }
+ });
+ toggleLocked.setSwitchMode(true);
+ addComponent(toggleLocked);
+
+ }
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/features/layouts/VerticalLayoutBasic.java b/src/com/vaadin/demo/sampler/features/layouts/VerticalLayoutBasic.java new file mode 100644 index 0000000000..64a085abda --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/VerticalLayoutBasic.java @@ -0,0 +1,37 @@ +package com.vaadin.demo.sampler.features.layouts; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.VerticalLayout; + +public class VerticalLayoutBasic extends Feature { + + @Override + public String getName() { + return "Vertical layout"; + } + + @Override + public String getDescription() { + return "The VerticalLayout arranges components vertically. " + + " It is 100% wide by default, which is nice in many cases," + + " but something to be aware of if trouble arises.<br/>It supports all basic features, plus some advanced stuff - including spacing, margin, alignment, and expand ratios."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(VerticalLayout.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { HorizontalLayoutBasic.class, LayoutSpacing.class, + LayoutAlignment.class, }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } +} diff --git a/src/com/vaadin/demo/sampler/features/layouts/VerticalLayoutBasicExample.java b/src/com/vaadin/demo/sampler/features/layouts/VerticalLayoutBasicExample.java new file mode 100644 index 0000000000..7881f325c2 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/VerticalLayoutBasicExample.java @@ -0,0 +1,18 @@ +package com.vaadin.demo.sampler.features.layouts; + +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +public class VerticalLayoutBasicExample extends VerticalLayout { + + public VerticalLayoutBasicExample() { + // this is a VerticalLayout + // let's add some components + for (int i = 0; i < 5; i++) { + TextField tf = new TextField("Row " + (i + 1)); + tf.setWidth("300px"); + // Add the component to the VerticalLayout + addComponent(tf); + } + } +} diff --git a/src/com/vaadin/demo/sampler/features/layouts/WebLayout.java b/src/com/vaadin/demo/sampler/features/layouts/WebLayout.java new file mode 100644 index 0000000000..6edad21e4f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/WebLayout.java @@ -0,0 +1,44 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.VerticalLayout;
+
+public class WebLayout extends Feature {
+
+ @Override
+ public String getName() {
+ return "Web-style layout";
+ }
+
+ @Override
+ public String getDescription() {
+ return "It can be helpful to distinguish between <i>web-style</i> and"
+ + " <i>application-style</i> layouting (although this is a"
+ + " simplification). Both styles are supported, and can be used"
+ + " simultaneously.<br/> Web-style layouting allows the content"
+ + " to dictate the size of the components by \"pushing\" the"
+ + " size, causing scrollbars to appear for the whole window"
+ + " when needed. This can be achieved by not setting the size"
+ + " for components, or setting an absolute size (e.g 200px)."
+ + "<br/>Try resizing the window to see how the content reacts.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(HorizontalLayout.class),
+ new APIResource(VerticalLayout.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { ApplicationLayout.class, CustomLayouts.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return null;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/layouts/WebLayoutExample.java b/src/com/vaadin/demo/sampler/features/layouts/WebLayoutExample.java new file mode 100644 index 0000000000..a0fe32df5d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/layouts/WebLayoutExample.java @@ -0,0 +1,87 @@ +package com.vaadin.demo.sampler.features.layouts;
+
+import java.util.Iterator;
+
+import com.vaadin.demo.sampler.ExampleUtil;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.Tree;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Window.CloseEvent;
+
+public class WebLayoutExample extends VerticalLayout {
+
+ Window win = new WebLayoutWindow();
+ Button open = new Button("Open sample in subwindow");
+
+ public WebLayoutExample() {
+ setMargin(true);
+
+ // We'll open this example in a separate window, configure it
+ win.setWidth("70%");
+ win.setHeight("70%");
+ win.center();
+ // Allow opening window again when closed
+ win.addListener(new Window.CloseListener() {
+ public void windowClose(CloseEvent e) {
+ open.setEnabled(true);
+ }
+ });
+
+ // 'open sample' button
+ addComponent(open);
+ open.addListener(new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ getWindow().addWindow(win);
+ open.setEnabled(false);
+ }
+ });
+
+ addComponent(new Label(
+ ("Don't worry: the content of the window is not supposed to make sense...")));
+
+ }
+
+ class WebLayoutWindow extends Window {
+ WebLayoutWindow() {
+ // Our main layout is a horiozontal layout
+ HorizontalLayout main = new HorizontalLayout();
+ main.setMargin(true);
+ main.setSpacing(true);
+ setLayout(main);
+
+ // Tree to the left
+ Tree tree = new Tree();
+ tree.setContainerDataSource(ExampleUtil.getHardwareContainer());
+ tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME);
+ for (Iterator it = tree.rootItemIds().iterator(); it.hasNext();) {
+ tree.expandItemsRecursively(it.next());
+ }
+ addComponent(tree);
+
+ // vertically divide the right area
+ VerticalLayout left = new VerticalLayout();
+ left.setSpacing(true);
+ addComponent(left);
+
+ // table on top
+ Table tbl = new Table();
+ tbl.setWidth("500px");
+ tbl.setContainerDataSource(ExampleUtil.getISO3166Container());
+ tbl.setSortDisabled(true);
+ tbl.setPageLength(7);
+ left.addComponent(tbl);
+
+ // Label on bottom
+ Label text = new Label(ExampleUtil.lorem, Label.CONTENT_XHTML);
+ text.setWidth("500px"); // some limit is good for text
+ left.addComponent(text);
+
+ }
+ }
+
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/features/link/75-LinkCurrentWindow.png b/src/com/vaadin/demo/sampler/features/link/75-LinkCurrentWindow.png Binary files differnew file mode 100644 index 0000000000..c9bcfd729e --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/link/75-LinkCurrentWindow.png diff --git a/src/com/vaadin/demo/sampler/features/link/75-LinkNoDecorations.png b/src/com/vaadin/demo/sampler/features/link/75-LinkNoDecorations.png Binary files differnew file mode 100644 index 0000000000..6ec2449a59 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/link/75-LinkNoDecorations.png diff --git a/src/com/vaadin/demo/sampler/features/link/75-LinkSizedWindow.png b/src/com/vaadin/demo/sampler/features/link/75-LinkSizedWindow.png Binary files differnew file mode 100644 index 0000000000..46333cd88d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/link/75-LinkSizedWindow.png diff --git a/src/com/vaadin/demo/sampler/features/link/LinkCurrentWindow.java b/src/com/vaadin/demo/sampler/features/link/LinkCurrentWindow.java new file mode 100644 index 0000000000..4880f42d0b --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/link/LinkCurrentWindow.java @@ -0,0 +1,38 @@ +package com.vaadin.demo.sampler.features.link; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.demo.sampler.features.buttons.ButtonLink; +import com.vaadin.ui.Link; + +public class LinkCurrentWindow extends Feature { + + @Override + public String getName() { + return "Link"; + } + + @Override + public String getDescription() { + return "By default, links open in the current browser window (use the browser back-button to get back)."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Link.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { LinkNoDecorations.class, LinkSizedWindow.class, + ButtonLink.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/link/LinkCurrentWindowExample.java b/src/com/vaadin/demo/sampler/features/link/LinkCurrentWindowExample.java new file mode 100644 index 0000000000..153f572258 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/link/LinkCurrentWindowExample.java @@ -0,0 +1,38 @@ +package com.vaadin.demo.sampler.features.link; + +import com.vaadin.terminal.ExternalResource; +import com.vaadin.terminal.ThemeResource; +import com.vaadin.ui.Link; +import com.vaadin.ui.VerticalLayout; + +public class LinkCurrentWindowExample extends VerticalLayout { + + private static final String CAPTION = "Open Google"; + private static final String TOOLTIP = "http://www.google.com"; + private static final ThemeResource ICON = new ThemeResource( + "icons/icon_world.gif"); + + public LinkCurrentWindowExample() { + setSpacing(true); + + // Link w/ text and tooltip + Link l = new Link(CAPTION, + new ExternalResource("http://www.google.com")); + l.setDescription(TOOLTIP); + addComponent(l); + + // Link w/ text, icon and tooltip + l = new Link(CAPTION, new ExternalResource("http://www.google.com")); + l.setDescription(TOOLTIP); + l.setIcon(ICON); + addComponent(l); + + // Link w/ icon and tooltip + l = new Link(); + l.setResource(new ExternalResource("http://www.google.com")); + l.setDescription(TOOLTIP); + l.setIcon(ICON); + addComponent(l); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/link/LinkNoDecorations.java b/src/com/vaadin/demo/sampler/features/link/LinkNoDecorations.java new file mode 100644 index 0000000000..7f20dc65c8 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/link/LinkNoDecorations.java @@ -0,0 +1,38 @@ +package com.vaadin.demo.sampler.features.link; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.demo.sampler.features.buttons.ButtonLink; +import com.vaadin.ui.Link; + +public class LinkNoDecorations extends Feature { + + @Override + public String getName() { + return "Link, configure window"; + } + + @Override + public String getDescription() { + return "Links can open new browser windows, and configure the amount of browser features shown, such as toolbar and addressbar.<br/>These links open a browser window without decorations."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Link.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { LinkCurrentWindow.class, LinkSizedWindow.class, + ButtonLink.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/link/LinkNoDecorationsExample.java b/src/com/vaadin/demo/sampler/features/link/LinkNoDecorationsExample.java new file mode 100644 index 0000000000..65ac59f12d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/link/LinkNoDecorationsExample.java @@ -0,0 +1,44 @@ +package com.vaadin.demo.sampler.features.link; + +import com.vaadin.terminal.ExternalResource; +import com.vaadin.terminal.ThemeResource; +import com.vaadin.ui.Link; +import com.vaadin.ui.VerticalLayout; + +public class LinkNoDecorationsExample extends VerticalLayout { + + private static final String CAPTION = "Open Google in new window"; + private static final String TOOLTIP = "http://www.google.com (opens in new window)"; + private static final ThemeResource ICON = new ThemeResource( + "icons/icon_world.gif"); + + public LinkNoDecorationsExample() { + setSpacing(true); + + // Link w/ text and tooltip + Link l = new Link(CAPTION, + new ExternalResource("http://www.google.com")); + l.setTargetName("_blank"); + l.setTargetBorder(Link.TARGET_BORDER_NONE); + l.setDescription(TOOLTIP); + addComponent(l); + + // Link w/ text, icon and tooltip + l = new Link(CAPTION, new ExternalResource("http://www.google.com")); + l.setTargetName("_blank"); + l.setTargetBorder(Link.TARGET_BORDER_NONE); + l.setDescription(TOOLTIP); + l.setIcon(ICON); + addComponent(l); + + // Link w/ icon and tooltip + l = new Link(); + l.setResource(new ExternalResource("http://www.google.com")); + l.setTargetName("_blank"); + l.setTargetBorder(Link.TARGET_BORDER_NONE); + l.setDescription(TOOLTIP); + l.setIcon(ICON); + addComponent(l); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/link/LinkSizedWindow.java b/src/com/vaadin/demo/sampler/features/link/LinkSizedWindow.java new file mode 100644 index 0000000000..9b8f8e5488 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/link/LinkSizedWindow.java @@ -0,0 +1,38 @@ +package com.vaadin.demo.sampler.features.link; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.demo.sampler.features.buttons.ButtonLink; +import com.vaadin.ui.Link; + +public class LinkSizedWindow extends Feature { + + @Override + public String getName() { + return "Link, sized window"; + } + + @Override + public String getDescription() { + return "Links can configure the size of the opened window.<br/>These links open a small fixed size window without decorations."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Link.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { LinkCurrentWindow.class, LinkNoDecorations.class, + ButtonLink.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/link/LinkSizedWindowExample.java b/src/com/vaadin/demo/sampler/features/link/LinkSizedWindowExample.java new file mode 100644 index 0000000000..8d47deea45 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/link/LinkSizedWindowExample.java @@ -0,0 +1,52 @@ +package com.vaadin.demo.sampler.features.link; + +import com.vaadin.terminal.ExternalResource; +import com.vaadin.terminal.Resource; +import com.vaadin.terminal.ThemeResource; +import com.vaadin.ui.Link; +import com.vaadin.ui.VerticalLayout; + +public class LinkSizedWindowExample extends VerticalLayout { + + private static final String CAPTION = "Open Google in small window"; + private static final String TOOLTIP = "http://www.google.com (opens in small window)"; + private static final ThemeResource ICON = new ThemeResource( + "icons/icon_world.gif"); + private static final Resource TARGET = new ExternalResource( + "http://www.google.com/m"); + + public LinkSizedWindowExample() { + setSpacing(true); + + // Link w/ text and tooltip + Link l = new Link(CAPTION, TARGET); + l.setTargetName("_blank"); + l.setTargetWidth(300); + l.setTargetHeight(300); + l.setTargetBorder(Link.TARGET_BORDER_NONE); + l.setDescription(TOOLTIP); + addComponent(l); + + // Link w/ text, icon and tooltip + l = new Link(CAPTION, TARGET); + l.setTargetName("_blank"); + l.setTargetWidth(300); + l.setTargetHeight(300); + l.setTargetBorder(Link.TARGET_BORDER_NONE); + l.setDescription(TOOLTIP); + l.setIcon(ICON); + addComponent(l); + + // Link w/ icon and tooltip + l = new Link(); + l.setResource(TARGET); + l.setTargetName("_blank"); + l.setTargetWidth(300); + l.setTargetHeight(300); + l.setTargetBorder(Link.TARGET_BORDER_NONE); + l.setDescription(TOOLTIP); + l.setIcon(ICON); + addComponent(l); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/notifications/75-NotificationCustom.png b/src/com/vaadin/demo/sampler/features/notifications/75-NotificationCustom.png Binary files differnew file mode 100644 index 0000000000..87aebc88f0 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/75-NotificationCustom.png diff --git a/src/com/vaadin/demo/sampler/features/notifications/75-NotificationError.png b/src/com/vaadin/demo/sampler/features/notifications/75-NotificationError.png Binary files differnew file mode 100644 index 0000000000..e16a49ddef --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/75-NotificationError.png diff --git a/src/com/vaadin/demo/sampler/features/notifications/75-NotificationHumanized.png b/src/com/vaadin/demo/sampler/features/notifications/75-NotificationHumanized.png Binary files differnew file mode 100644 index 0000000000..a2dd395f84 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/75-NotificationHumanized.png diff --git a/src/com/vaadin/demo/sampler/features/notifications/75-NotificationTray.png b/src/com/vaadin/demo/sampler/features/notifications/75-NotificationTray.png Binary files differnew file mode 100644 index 0000000000..31c256673f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/75-NotificationTray.png diff --git a/src/com/vaadin/demo/sampler/features/notifications/75-NotificationWarning.png b/src/com/vaadin/demo/sampler/features/notifications/75-NotificationWarning.png Binary files differnew file mode 100644 index 0000000000..0626d17bda --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/75-NotificationWarning.png diff --git a/src/com/vaadin/demo/sampler/features/notifications/NotificationCustom.java b/src/com/vaadin/demo/sampler/features/notifications/NotificationCustom.java new file mode 100644 index 0000000000..dc6780d3c6 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/NotificationCustom.java @@ -0,0 +1,45 @@ +package com.vaadin.demo.sampler.features.notifications; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Window; + +public class NotificationCustom extends Feature { + + @Override + public String getName() { + return "Customized notification"; + } + + @Override + public String getDescription() { + return "A notification can have a caption, a richtext" + + " description, and an icon. Position and delay can" + + " also be customized.<br/>Note that more often than" + + " not, less is more: try to make the messages short" + + " and to the point."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Window.class), + new APIResource(Window.Notification.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { NotificationHumanized.class, + NotificationWarning.class, NotificationError.class, + NotificationTray.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return new NamedExternalResource[] { new NamedExternalResource( + "Monolog Boxes and Transparent Messages", + "http://humanized.com/weblog/2006/09/11/monolog_boxes_and_transparent_messages/") }; + + } + +} diff --git a/src/com/vaadin/demo/sampler/features/notifications/NotificationCustomExample.java b/src/com/vaadin/demo/sampler/features/notifications/NotificationCustomExample.java new file mode 100644 index 0000000000..ce20e77827 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/NotificationCustomExample.java @@ -0,0 +1,133 @@ +package com.vaadin.demo.sampler.features.notifications; + +import com.vaadin.data.Item; +import com.vaadin.data.Property; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.NativeSelect; +import com.vaadin.ui.RichTextArea; +import com.vaadin.ui.Slider; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Window.Notification; + +public class NotificationCustomExample extends VerticalLayout { + + private static final Object CAPTION_PROPERTY = new Object(); + + public NotificationCustomExample() { + setSpacing(true); + setWidth(null); // layout will grow with content + + final TextField caption = new TextField("Caption", "Message sent"); + caption + .setDescription("Main info; a short caption-only notification is often most effective."); + caption.setWidth("200px"); + addComponent(caption); + + final RichTextArea description = new RichTextArea(); + description.setValue("<p>to <i>john.doe@example.com</i></p>"); + description.setCaption("Description"); + description + .setDescription("Additional information; try to keep it short."); + addComponent(description); + + HorizontalLayout horiz = new HorizontalLayout(); + horiz.setSpacing(true); + addComponent(horiz); + + final NativeSelect position = new NativeSelect("Position"); + position.setNullSelectionAllowed(false); + horiz.addComponent(position); + initPositionItems(position); + + final NativeSelect style = new NativeSelect("Style"); + style.setNullSelectionAllowed(false); + horiz.addComponent(style); + initTypeItems(style); + + final Slider delay = new Slider("Delay (msec), -1 means click to hide"); + delay + .setDescription("Delay before fading<br/>Pull all the way to the left to get -1, which means forever (click to hide)."); + delay.setWidth("100%"); // 'description' will push width + delay.setMin(Notification.DELAY_FOREVER); + delay.setMax(10000); + addComponent(delay); + + // TODO icon select + + Button show = new Button("Show notification", + new Button.ClickListener() { + // "Inline" click listener; this is where the + // notification is actually created and shown. + public void buttonClick(ClickEvent event) { + // create Notification instance and customize + Notification n = new Notification((String) caption + .getValue(), (String) description.getValue(), + (Integer) style.getValue()); + n.setPosition((Integer) position.getValue()); + Double d = (Double) delay.getValue(); + n.setDelayMsec(d.intValue()); // sec->msec + getWindow().showNotification(n); + } + }); + addComponent(show); + setComponentAlignment(show, Alignment.MIDDLE_RIGHT); + + } + + /* + * Helper to fill the position select with the various possibilities + */ + private void initPositionItems(NativeSelect position) { + position.addContainerProperty(CAPTION_PROPERTY, String.class, null); + position.setItemCaptionPropertyId(CAPTION_PROPERTY); + Item i = position.addItem(Notification.POSITION_TOP_LEFT); + Property c = i.getItemProperty(CAPTION_PROPERTY); + c.setValue("Top left"); + i = position.addItem(Notification.POSITION_CENTERED_TOP); + c = i.getItemProperty(CAPTION_PROPERTY); + c.setValue("Top centered"); + i = position.addItem(Notification.POSITION_TOP_RIGHT); + c = i.getItemProperty(CAPTION_PROPERTY); + c.setValue("Top right"); + i = position.addItem(Notification.POSITION_CENTERED); + c = i.getItemProperty(CAPTION_PROPERTY); + c.setValue("Centered"); + i = position.addItem(Notification.POSITION_BOTTOM_LEFT); + c = i.getItemProperty(CAPTION_PROPERTY); + c.setValue("Bottom left"); + i = position.addItem(Notification.POSITION_CENTERED_BOTTOM); + c = i.getItemProperty(CAPTION_PROPERTY); + c.setValue("Bottom, centered"); + i = position.addItem(Notification.POSITION_BOTTOM_RIGHT); + c = i.getItemProperty(CAPTION_PROPERTY); + c.setValue("Bottom right"); + position.setValue(Notification.POSITION_CENTERED); + } + + /* + * Helper to fill the position select with the various possibilities + */ + private void initTypeItems(NativeSelect type) { + type.addContainerProperty(CAPTION_PROPERTY, String.class, null); + type.setItemCaptionPropertyId(CAPTION_PROPERTY); + Item i = type.addItem(Notification.TYPE_HUMANIZED_MESSAGE); + Property c = i.getItemProperty(CAPTION_PROPERTY); + c.setValue("Humanized"); + i = type.addItem(Notification.TYPE_WARNING_MESSAGE); + c = i.getItemProperty(CAPTION_PROPERTY); + c.setValue("Warning"); + i = type.addItem(Notification.TYPE_ERROR_MESSAGE); + c = i.getItemProperty(CAPTION_PROPERTY); + c.setValue("Error"); + i = type.addItem(Notification.TYPE_TRAY_NOTIFICATION); + c = i.getItemProperty(CAPTION_PROPERTY); + c.setValue("Tray"); + + type.setValue(Notification.TYPE_HUMANIZED_MESSAGE); + } + +} diff --git a/src/com/vaadin/demo/sampler/features/notifications/NotificationError.java b/src/com/vaadin/demo/sampler/features/notifications/NotificationError.java new file mode 100644 index 0000000000..406249658a --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/NotificationError.java @@ -0,0 +1,46 @@ +package com.vaadin.demo.sampler.features.notifications; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Window; + +public class NotificationError extends Feature { + + @Override + public String getName() { + return "Error notification"; + } + + @Override + public String getDescription() { + return "<p>The <i>Error</i> notification is modal, and is to be used for" + + " messages that must be seen by the user.<br/>" + + " The <i>Error</i> message must be closed by clicking" + + " the notification.</p><p>Candidates for an" + + " <i>Error</i> notification include 'Save failed'," + + " 'Permission denied', and other situations that the" + + " user must be made aware of.<br/>It's a good idea to" + + " provide hints about what went wrong, and how the user'" + + " can proceed to correct the situation.</p>"; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Window.class), + new APIResource(Window.Notification.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { NotificationHumanized.class, + NotificationTray.class, NotificationWarning.class, + NotificationCustom.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/notifications/NotificationErrorExample.java b/src/com/vaadin/demo/sampler/features/notifications/NotificationErrorExample.java new file mode 100644 index 0000000000..3860e7fd17 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/NotificationErrorExample.java @@ -0,0 +1,42 @@ +package com.vaadin.demo.sampler.features.notifications; + +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Window.Notification; + +public class NotificationErrorExample extends VerticalLayout { + + public NotificationErrorExample() { + setSpacing(true); + setWidth(null); // layout will grow with content + + final TextField caption = new TextField("Caption", "Upload failed"); + caption.setWidth("200px"); + addComponent(caption); + + final TextField description = new TextField( + "Description", + "Invoices-2008.csv could not be read.<br/>" + + "Perhaps the file is damaged, or in the wrong format?<br/>" + + "Try re-exporting and uploading the file again."); + description.setWidth("300px"); + addComponent(description); + + Button show = new Button("Show notification", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + getWindow().showNotification( + (String) caption.getValue(), + (String) description.getValue(), + Notification.TYPE_ERROR_MESSAGE); + + } + }); + addComponent(show); + setComponentAlignment(show, Alignment.MIDDLE_RIGHT); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/notifications/NotificationHumanized.java b/src/com/vaadin/demo/sampler/features/notifications/NotificationHumanized.java new file mode 100644 index 0000000000..dfc14d3466 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/NotificationHumanized.java @@ -0,0 +1,48 @@ +package com.vaadin.demo.sampler.features.notifications; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Window; + +public class NotificationHumanized extends Feature { + + @Override + public String getName() { + return "Humanized notification"; + } + + @Override + public String getDescription() { + return "<p>The <i>Humanized</i> notification is an implementation of" + + " the <i>transparent message</i> -pattern, and can be used" + + " to indicate non-critical events while interrupting" + + " the user as little as possible.<br/>" + + "The <i>Humanized</i> message quickly fades away once" + + " the user interacts with the application (i.e. moves" + + " mouse, types).</p><p>Candidates for a" + + " <i>Humanized</i> notification include 'XYZ saved'," + + " 'Added XYZ', and other messages that the user can" + + " safely ignore, once the application is familliar.</p>"; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Window.class), + new APIResource(Window.Notification.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { NotificationTray.class, NotificationWarning.class, + NotificationError.class, NotificationCustom.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return new NamedExternalResource[] { new NamedExternalResource( + "Monolog Boxes and Transparent Messages", + "http://humanized.com/weblog/2006/09/11/monolog_boxes_and_transparent_messages/") }; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/notifications/NotificationHumanizedExample.java b/src/com/vaadin/demo/sampler/features/notifications/NotificationHumanizedExample.java new file mode 100644 index 0000000000..8d70a2e2b9 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/NotificationHumanizedExample.java @@ -0,0 +1,37 @@ +package com.vaadin.demo.sampler.features.notifications; + +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; + +public class NotificationHumanizedExample extends VerticalLayout { + + public NotificationHumanizedExample() { + setSpacing(true); + setWidth(null); // layout will grow with content + + final TextField caption = new TextField("Caption", "Document saved"); + caption.setWidth("200px"); + addComponent(caption); + + final TextField description = new TextField("Description", + "Invoices-2008.csv"); + description.setWidth("300px"); + addComponent(description); + + Button show = new Button("Show notification", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + getWindow().showNotification( + (String) caption.getValue(), + (String) description.getValue()); + + } + }); + addComponent(show); + setComponentAlignment(show, Alignment.MIDDLE_RIGHT); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/notifications/NotificationTray.java b/src/com/vaadin/demo/sampler/features/notifications/NotificationTray.java new file mode 100644 index 0000000000..9401f90d0b --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/NotificationTray.java @@ -0,0 +1,49 @@ +package com.vaadin.demo.sampler.features.notifications; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Window; + +public class NotificationTray extends Feature { + + @Override + public String getName() { + return "Tray notification"; + } + + @Override + public String getDescription() { + return "<p>The <i>Tray</i> notification shows up in the lower right corner," + + " and is meant to interrupt the user as little as possible" + + " even if it's shown for a while. " + + "The <i>Tray</i> message fades away after a few moments" + + " once the user interacts with the application (e.g. moves" + + " mouse, types)</p><p>Candidates for a" + + " <i>Tray</i> notification include 'New message received'," + + " 'Job XYZ completed' – generally notifications about events" + + " that have been delayed, or occur in the background" + + " (as opposed to being a direct result of the users last action.)</p>"; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Window.class), + new APIResource(Window.Notification.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { NotificationHumanized.class, + NotificationWarning.class, NotificationError.class, + NotificationCustom.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return new NamedExternalResource[] { new NamedExternalResource( + "Monolog Boxes and Transparent Messages", + "http://humanized.com/weblog/2006/09/11/monolog_boxes_and_transparent_messages/") }; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/notifications/NotificationTrayExample.java b/src/com/vaadin/demo/sampler/features/notifications/NotificationTrayExample.java new file mode 100644 index 0000000000..a7d78ebfca --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/NotificationTrayExample.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.notifications; + +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Window.Notification; + +public class NotificationTrayExample extends VerticalLayout { + + public NotificationTrayExample() { + setSpacing(true); + setWidth(null); // layout will grow with content + + final TextField caption = new TextField("Caption", "New message"); + caption.setWidth("200px"); + addComponent(caption); + + final TextField description = new TextField("Description", + "<b>John:</b> Could you upload Invoices-2008.csv so that..."); + description.setWidth("300px"); + addComponent(description); + + Button show = new Button("Show notification", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + getWindow().showNotification( + (String) caption.getValue(), + (String) description.getValue(), + Notification.TYPE_TRAY_NOTIFICATION); + + } + }); + addComponent(show); + setComponentAlignment(show, Alignment.MIDDLE_RIGHT); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/notifications/NotificationWarning.java b/src/com/vaadin/demo/sampler/features/notifications/NotificationWarning.java new file mode 100644 index 0000000000..303361c6d1 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/NotificationWarning.java @@ -0,0 +1,49 @@ +package com.vaadin.demo.sampler.features.notifications; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Window; + +public class NotificationWarning extends Feature { + + @Override + public String getName() { + return "Warning notification"; + } + + @Override + public String getDescription() { + return "<p>The <i>Warning</i> notification is an implementation of" + + " the <i>transparent message</i> -pattern, and is meant" + + " to interrupt the user as little as possible, while" + + " still drawing the needed attention." + + "The <i>Warning</i> message fades away after a few moments" + + " once the user interacts with the application (e.g. moves" + + " mouse, types)</p><p>Candidates for a" + + " <i>Warning</i> notification include 'You canceled XYZ'," + + " 'XYZ deleted', and other situations that the user should" + + " be made aware of, but are probably intentional.</p>"; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Window.class), + new APIResource(Window.Notification.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { NotificationHumanized.class, + NotificationTray.class, NotificationError.class, + NotificationCustom.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return new NamedExternalResource[] { new NamedExternalResource( + "Monolog Boxes and Transparent Messages", + "http://humanized.com/weblog/2006/09/11/monolog_boxes_and_transparent_messages/") }; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/notifications/NotificationWarningExample.java b/src/com/vaadin/demo/sampler/features/notifications/NotificationWarningExample.java new file mode 100644 index 0000000000..ae98aeb739 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/notifications/NotificationWarningExample.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.notifications; + +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Window.Notification; + +public class NotificationWarningExample extends VerticalLayout { + + public NotificationWarningExample() { + setSpacing(true); + setWidth(null); // layout will grow with content + + final TextField caption = new TextField("Caption", "Upload canceled"); + caption.setWidth("200px"); + addComponent(caption); + + final TextField description = new TextField("Description", + "Invoices-2008.csv will not be processed"); + description.setWidth("300px"); + addComponent(description); + + Button show = new Button("Show notification", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + getWindow().showNotification( + (String) caption.getValue(), + (String) description.getValue(), + Notification.TYPE_WARNING_MESSAGE); + + } + }); + addComponent(show); + setComponentAlignment(show, Alignment.MIDDLE_RIGHT); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/panels/75-PanelBasic.png b/src/com/vaadin/demo/sampler/features/panels/75-PanelBasic.png Binary files differnew file mode 100644 index 0000000000..3307b22067 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/panels/75-PanelBasic.png diff --git a/src/com/vaadin/demo/sampler/features/panels/75-PanelLight.png b/src/com/vaadin/demo/sampler/features/panels/75-PanelLight.png Binary files differnew file mode 100644 index 0000000000..c36e16af47 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/panels/75-PanelLight.png diff --git a/src/com/vaadin/demo/sampler/features/panels/PanelBasic.java b/src/com/vaadin/demo/sampler/features/panels/PanelBasic.java new file mode 100644 index 0000000000..5d659b04a5 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/panels/PanelBasic.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.panels;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.Panel;
+
+public class PanelBasic extends Feature {
+ @Override
+ public String getName() {
+ return "Panel";
+ }
+
+ @Override
+ public String getDescription() {
+ return "";
+
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Panel.class),
+ new APIResource(Layout.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { PanelLight.class, FeatureSet.Layouts.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/panels/PanelBasicExample.java b/src/com/vaadin/demo/sampler/features/panels/PanelBasicExample.java new file mode 100644 index 0000000000..498337ff43 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/panels/PanelBasicExample.java @@ -0,0 +1,47 @@ +package com.vaadin.demo.sampler.features.panels;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+
+public class PanelBasicExample extends VerticalLayout implements ClickListener {
+
+ private Panel panel;
+
+ public PanelBasicExample() {
+ setSpacing(true);
+
+ // Panel 1 - with caption
+ panel = new Panel("This is a standard Panel");
+ panel.setHeight("200px"); // we want scrollbars
+
+ // let's adjust the panels default layout (a VerticalLayout)
+ VerticalLayout layout = (VerticalLayout) panel.getLayout();
+ layout.setMargin(true); // we want a margin
+ layout.setSpacing(true); // and spacing between components
+ addComponent(panel);
+
+ // Let's add a few rows to provoke scrollbars:
+ for (int i = 0; i < 20; i++) {
+ panel.addComponent(new Label(
+ "The quick brown fox jumps over the lazy dog."));
+ }
+
+ // Caption toggle:
+ Button b = new Button("Toggle caption");
+ b.addListener(this);
+ addComponent(b);
+
+ }
+
+ public void buttonClick(ClickEvent event) {
+ if (panel.getCaption().equals("")) {
+ panel.setCaption("This is a standard Panel");
+ } else {
+ panel.setCaption("");
+ }
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/panels/PanelLight.java b/src/com/vaadin/demo/sampler/features/panels/PanelLight.java new file mode 100644 index 0000000000..ddb4138913 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/panels/PanelLight.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.panels;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.Panel;
+
+public class PanelLight extends Feature {
+ @Override
+ public String getName() {
+ return "Panel, light style";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The 'light' panel has less decorations than the regular Panel style.";
+
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Panel.class),
+ new APIResource(Layout.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { PanelBasic.class, FeatureSet.Layouts.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/panels/PanelLightExample.java b/src/com/vaadin/demo/sampler/features/panels/PanelLightExample.java new file mode 100644 index 0000000000..38aa53ca5f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/panels/PanelLightExample.java @@ -0,0 +1,49 @@ +package com.vaadin.demo.sampler.features.panels;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+
+public class PanelLightExample extends VerticalLayout implements ClickListener {
+
+ private Panel panel;
+
+ public PanelLightExample() {
+ setSpacing(true);
+
+ setSpacing(true);
+
+ // Panel 1 - with caption
+ panel = new Panel("This is a light Panel");
+ panel.setStyleName(Panel.STYLE_LIGHT);
+ panel.setHeight("200px"); // we want scrollbars
+
+ // let's adjust the panels default layout (a VerticalLayout)
+ VerticalLayout layout = (VerticalLayout) panel.getLayout();
+ layout.setMargin(true); // we want a margin
+ layout.setSpacing(true); // and spacing between components
+ addComponent(panel);
+
+ // Let's add a few rows to provoke scrollbars:
+ for (int i = 0; i < 20; i++) {
+ panel.addComponent(new Label(
+ "The quick brown fox jumps over the lazy dog."));
+ }
+
+ // Caption toggle:
+ Button b = new Button("Toggle caption");
+ b.addListener(this);
+ addComponent(b);
+ }
+
+ public void buttonClick(ClickEvent event) {
+ if (panel.getCaption() == null) {
+ panel.setCaption("This is a light Panel");
+ } else {
+ panel.setCaption(null);
+ }
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxContains.png b/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxContains.png Binary files differnew file mode 100644 index 0000000000..af8cdf2215 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxContains.png diff --git a/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxInputPrompt.png b/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxInputPrompt.png Binary files differnew file mode 100644 index 0000000000..3ef7a48faa --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxInputPrompt.png diff --git a/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxNewItems.png b/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxNewItems.png Binary files differnew file mode 100644 index 0000000000..c79228fdcf --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxNewItems.png diff --git a/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxPlain.png b/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxPlain.png Binary files differnew file mode 100644 index 0000000000..603c8c6cab --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxPlain.png diff --git a/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxStartsWith.png b/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxStartsWith.png Binary files differnew file mode 100644 index 0000000000..2b5d0f1bd0 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/75-ComboBoxStartsWith.png diff --git a/src/com/vaadin/demo/sampler/features/selects/75-ListSelectMultiple.png b/src/com/vaadin/demo/sampler/features/selects/75-ListSelectMultiple.png Binary files differnew file mode 100644 index 0000000000..628b5787f8 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/75-ListSelectMultiple.png diff --git a/src/com/vaadin/demo/sampler/features/selects/75-ListSelectSingle.png b/src/com/vaadin/demo/sampler/features/selects/75-ListSelectSingle.png Binary files differnew file mode 100644 index 0000000000..b4ac1f4999 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/75-ListSelectSingle.png diff --git a/src/com/vaadin/demo/sampler/features/selects/75-NativeSelection.png b/src/com/vaadin/demo/sampler/features/selects/75-NativeSelection.png Binary files differnew file mode 100644 index 0000000000..8d39ff69b5 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/75-NativeSelection.png diff --git a/src/com/vaadin/demo/sampler/features/selects/75-TwinColumnSelect.png b/src/com/vaadin/demo/sampler/features/selects/75-TwinColumnSelect.png Binary files differnew file mode 100644 index 0000000000..b8e0dae88a --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/75-TwinColumnSelect.png diff --git a/src/com/vaadin/demo/sampler/features/selects/ComboBoxContains.java b/src/com/vaadin/demo/sampler/features/selects/ComboBoxContains.java new file mode 100644 index 0000000000..5c6a30a145 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ComboBoxContains.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.ComboBox;
+
+public class ComboBoxContains extends Feature {
+ @Override
+ public String getName() {
+ return "Combobox, suggesting (contains)";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A drop-down selection component with single item selection.<br/>"
+ + " A 'contains' filter has been used in this example,"
+ + " so you can key in some text and only the options"
+ + " containing your input will be shown.<br/>"
+ + " Because there are so many options, they are loaded on-demand"
+ + " (\"lazy-loading\") from the server when paging or"
+ + " filtering. This behavior is built-in and requires no extra"
+ + " code.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(ComboBox.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { ComboBoxPlain.class, ComboBoxStartsWith.class,
+ ComboBoxNewItems.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ComboBoxContainsExample.java b/src/com/vaadin/demo/sampler/features/selects/ComboBoxContainsExample.java new file mode 100644 index 0000000000..57818231fd --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ComboBoxContainsExample.java @@ -0,0 +1,50 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.demo.sampler.ExampleUtil;
+import com.vaadin.ui.AbstractSelect;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.AbstractSelect.Filtering;
+
+public class ComboBoxContainsExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ public ComboBoxContainsExample() {
+ setSpacing(true);
+
+ // Creates a new combobox using an existing container
+ ComboBox l = new ComboBox("Please select your country", ExampleUtil
+ .getStaticISO3166Container());
+
+ // Sets the combobox to show a certain property as the item caption
+ l.setItemCaptionPropertyId(ExampleUtil.iso3166_PROPERTY_NAME);
+ l.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
+
+ // Sets the icon to use with the items
+ l.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG);
+
+ // Set a reasonable width
+ l.setWidth(350, UNITS_PIXELS);
+
+ // Set the appropriate filtering mode for this example
+ l.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
+ l.setImmediate(true);
+ l.addListener(this);
+
+ // Disallow null selections
+ l.setNullSelectionAllowed(false);
+
+ addComponent(l);
+ }
+
+ /*
+ * Shows a notification when a selection is made.
+ */
+ public void valueChange(ValueChangeEvent event) {
+ Property selected = ExampleUtil.getStaticISO3166Container()
+ .getContainerProperty(event.getProperty().toString(), "name");
+ getWindow().showNotification("Selected country: " + selected);
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ComboBoxInputPrompt.java b/src/com/vaadin/demo/sampler/features/selects/ComboBoxInputPrompt.java new file mode 100644 index 0000000000..3021e1761a --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ComboBoxInputPrompt.java @@ -0,0 +1,44 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.demo.sampler.features.text.TextFieldInputPrompt;
+import com.vaadin.ui.ComboBox;
+
+public class ComboBoxInputPrompt extends Feature {
+ @Override
+ public String getName() {
+ return "Combobox with input prompt";
+ }
+
+ @Override
+ public String getDescription() {
+ return "ComboBox is a drop-down selection component with single item selection."
+ + " It can have an <i>input prompt</i> - a textual hint that is shown within"
+ + " the select when no value is selected.<br/>"
+ + " You can use an input prompt instead of a caption to save"
+ + " space, but only do so if the function of the ComboBox is"
+ + " still clear when a value is selected and the prompt is no"
+ + " longer visible.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(ComboBox.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { ComboBoxStartsWith.class, ComboBoxContains.class,
+ ComboBoxNewItems.class, TextFieldInputPrompt.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return new NamedExternalResource[] { new NamedExternalResource(
+ "UI Patterns, Input Prompt",
+ "http://ui-patterns.com/pattern/InputPrompt") };
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ComboBoxInputPromptExample.java b/src/com/vaadin/demo/sampler/features/selects/ComboBoxInputPromptExample.java new file mode 100644 index 0000000000..b326a636de --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ComboBoxInputPromptExample.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.VerticalLayout;
+
+public class ComboBoxInputPromptExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private static final String[] cities = new String[] { "Berlin", "Brussels",
+ "Helsinki", "Madrid", "Oslo", "Paris", "Stockholm" };
+
+ public ComboBoxInputPromptExample() {
+ setMargin(true); // for looks: more 'air'
+
+ // Create & set input prompt
+ ComboBox l = new ComboBox();
+ l.setInputPrompt("Please select a city");
+
+ // configure & load content
+ l.setImmediate(true);
+ l.addListener(this);
+ for (int i = 0; i < cities.length; i++) {
+ l.addItem(cities[i]);
+ }
+
+ // add to the layout
+ addComponent(l);
+ }
+
+ /*
+ * Shows a notification when a selection is made.
+ */
+ public void valueChange(ValueChangeEvent event) {
+ getWindow().showNotification("Selected city: " + event.getProperty());
+
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ComboBoxNewItems.java b/src/com/vaadin/demo/sampler/features/selects/ComboBoxNewItems.java new file mode 100644 index 0000000000..1b4508eb19 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ComboBoxNewItems.java @@ -0,0 +1,45 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.ComboBox;
+
+public class ComboBoxNewItems extends Feature {
+ @Override
+ public String getName() {
+ return "Combobox, enter new items";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A drop-down selection component with single item selection.<br/>"
+ + " This example also allows you to input your own"
+ + " choice - your input will be added to the selection"
+ + " of available choices. This behavior is built-in and can"
+ + " be enabled with one method call. Note that by using this"
+ + " feature, one can easily create <i>suggestion box</i> -type"
+ + " inputs that for example remembers the users previous input,"
+ + " or provides suggestions from a list of popular choices."
+ + " Configured like this (and optionally with a filter), the"
+ + " ComboBox can be a powerful alternative to TextField.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(ComboBox.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { ComboBoxPlain.class, ComboBoxStartsWith.class,
+ ComboBoxContains.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ComboBoxNewItemsExample.java b/src/com/vaadin/demo/sampler/features/selects/ComboBoxNewItemsExample.java new file mode 100644 index 0000000000..d3c3717195 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ComboBoxNewItemsExample.java @@ -0,0 +1,51 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.AbstractSelect;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.VerticalLayout;
+
+public class ComboBoxNewItemsExample extends VerticalLayout implements
+ Property.ValueChangeListener, AbstractSelect.NewItemHandler {
+ private static final String[] cities = new String[] { "Berlin", "Brussels",
+ "Helsinki", "Madrid", "Oslo", "Paris", "Stockholm" };
+ private ComboBox l;
+ private Boolean lastAdded = false;
+
+ public ComboBoxNewItemsExample() {
+ setSpacing(true);
+
+ l = new ComboBox("Please select a city");
+ for (int i = 0; i < cities.length; i++) {
+ l.addItem(cities[i]);
+ }
+
+ l.setNewItemsAllowed(true);
+ l.setNewItemHandler(this);
+ l.setImmediate(true);
+ l.addListener(this);
+
+ addComponent(l);
+ }
+
+ /*
+ * Shows a notification when a selection is made.
+ */
+ public void valueChange(ValueChangeEvent event) {
+ if (!lastAdded) {
+ getWindow().showNotification(
+ "Selected city: " + event.getProperty());
+ }
+ lastAdded = false;
+ }
+
+ public void addNewItem(String newItemCaption) {
+ if (!l.containsId(newItemCaption)) {
+ getWindow().showNotification("Added city: " + newItemCaption);
+ lastAdded = true;
+ l.addItem(newItemCaption);
+ l.setValue(newItemCaption);
+ }
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ComboBoxPlain.java b/src/com/vaadin/demo/sampler/features/selects/ComboBoxPlain.java new file mode 100644 index 0000000000..18f1ea3a5e --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ComboBoxPlain.java @@ -0,0 +1,40 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.ComboBox;
+
+public class ComboBoxPlain extends Feature {
+ @Override
+ public String getName() {
+ return "Combobox";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A drop-down selection component with single item selection."
+ + " Shown here is the most basic variant, which basically"
+ + " provides the same functionality as a NativeSelect with"
+ + " added lazy-loading if there are many options.<br/>"
+ + " See related examples for more advanced features.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(ComboBox.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { ComboBoxStartsWith.class, ComboBoxContains.class,
+ ComboBoxNewItems.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ComboBoxPlainExample.java b/src/com/vaadin/demo/sampler/features/selects/ComboBoxPlainExample.java new file mode 100644 index 0000000000..612cc70f59 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ComboBoxPlainExample.java @@ -0,0 +1,37 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.AbstractSelect.Filtering;
+
+public class ComboBoxPlainExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private static final String[] cities = new String[] { "Berlin", "Brussels",
+ "Helsinki", "Madrid", "Oslo", "Paris", "Stockholm" };
+
+ public ComboBoxPlainExample() {
+ setSpacing(true);
+
+ ComboBox l = new ComboBox("Please select a city");
+ for (int i = 0; i < cities.length; i++) {
+ l.addItem(cities[i]);
+ }
+
+ l.setFilteringMode(Filtering.FILTERINGMODE_OFF);
+ l.setImmediate(true);
+ l.addListener(this);
+
+ addComponent(l);
+ }
+
+ /*
+ * Shows a notification when a selection is made.
+ */
+ public void valueChange(ValueChangeEvent event) {
+ getWindow().showNotification("Selected city: " + event.getProperty());
+
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ComboBoxStartsWith.java b/src/com/vaadin/demo/sampler/features/selects/ComboBoxStartsWith.java new file mode 100644 index 0000000000..1f2ca22256 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ComboBoxStartsWith.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.ComboBox;
+
+public class ComboBoxStartsWith extends Feature {
+ @Override
+ public String getName() {
+ return "Combobox, suggesting (starts-with)";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A drop-down selection component with single item selection.<br/>"
+ + " A 'starts-with' filter has been used in this example,"
+ + " so you can key in some text and only the options"
+ + " beginning with your input will be shown.<br/>"
+ + " Because there are so many options, they are loaded on-demand"
+ + " (\"lazy-loading\") from the server when paging or"
+ + " filtering. This behavior is built-in and requires no extra"
+ + " code.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(ComboBox.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { ComboBoxPlain.class, ComboBoxContains.class,
+ ComboBoxNewItems.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ComboBoxStartsWithExample.java b/src/com/vaadin/demo/sampler/features/selects/ComboBoxStartsWithExample.java new file mode 100644 index 0000000000..d29a429890 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ComboBoxStartsWithExample.java @@ -0,0 +1,50 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.demo.sampler.ExampleUtil;
+import com.vaadin.ui.AbstractSelect;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.AbstractSelect.Filtering;
+
+public class ComboBoxStartsWithExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ public ComboBoxStartsWithExample() {
+ setSpacing(true);
+
+ // Creates a new combobox using an existing container
+ ComboBox l = new ComboBox("Please select your country", ExampleUtil
+ .getStaticISO3166Container());
+
+ // Sets the combobox to show a certain property as the item caption
+ l.setItemCaptionPropertyId(ExampleUtil.iso3166_PROPERTY_NAME);
+ l.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
+
+ // Sets the icon to use with the items
+ l.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG);
+
+ // Set a reasonable width
+ l.setWidth(350, UNITS_PIXELS);
+
+ // Set the appropriate filtering mode for this example
+ l.setFilteringMode(Filtering.FILTERINGMODE_STARTSWITH);
+ l.setImmediate(true);
+ l.addListener(this);
+
+ // Disallow null selections
+ l.setNullSelectionAllowed(false);
+
+ addComponent(l);
+ }
+
+ /*
+ * Shows a notification when a selection is made.
+ */
+ public void valueChange(ValueChangeEvent event) {
+ Property selected = ExampleUtil.getStaticISO3166Container()
+ .getContainerProperty(event.getProperty().toString(), "name");
+ getWindow().showNotification("Selected country: " + selected);
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ListSelectMultiple.java b/src/com/vaadin/demo/sampler/features/selects/ListSelectMultiple.java new file mode 100644 index 0000000000..5e3f13fff2 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ListSelectMultiple.java @@ -0,0 +1,41 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.ListSelect;
+
+public class ListSelectMultiple extends Feature {
+ @Override
+ public String getName() {
+ return "List select, multiple selections";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A simple list select component with multiple item selection."
+ + " You can allow or disallow <i>null selection</i> - i.e the"
+ + " possibility to make an empty selection. Null selection is"
+ + " allowed in this example.<br/>"
+ + "You can select multiple items from the list by holding"
+ + " the CTRL of SHIFT key while clicking the items.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(ListSelect.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { NativeSelection.class, ListSelectSingle.class,
+ TwinColumnSelect.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ListSelectMultipleExample.java b/src/com/vaadin/demo/sampler/features/selects/ListSelectMultipleExample.java new file mode 100644 index 0000000000..629b1b7326 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ListSelectMultipleExample.java @@ -0,0 +1,37 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.ListSelect;
+import com.vaadin.ui.VerticalLayout;
+
+public class ListSelectMultipleExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private static final String[] cities = new String[] { "Berlin", "Brussels",
+ "Helsinki", "Madrid", "Oslo", "Paris", "Stockholm" };
+
+ public ListSelectMultipleExample() {
+ setSpacing(true);
+
+ ListSelect l = new ListSelect("Please select some cities");
+ for (int i = 0; i < cities.length; i++) {
+ l.addItem(cities[i]);
+ }
+ l.setRows(7);
+ l.setNullSelectionAllowed(true);
+ l.setMultiSelect(true);
+ l.setImmediate(true);
+ l.addListener(this);
+
+ addComponent(l);
+ }
+
+ /*
+ * Shows a notification when a selection is made.
+ */
+ public void valueChange(ValueChangeEvent event) {
+ getWindow().showNotification("Selected cities: " + event.getProperty());
+
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ListSelectSingle.java b/src/com/vaadin/demo/sampler/features/selects/ListSelectSingle.java new file mode 100644 index 0000000000..352261a047 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ListSelectSingle.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.ListSelect;
+
+public class ListSelectSingle extends Feature {
+ @Override
+ public String getName() {
+ return "List select, single selection";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A simple list select component with single item selection.<br/>"
+ + "You can allow or disallow <i>null selection</i> - i.e the"
+ + " possibility to make an empty selection. Null selection is"
+ + " not allowed in this example.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(ListSelect.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { NativeSelection.class, ListSelectMultiple.class,
+ TwinColumnSelect.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/ListSelectSingleExample.java b/src/com/vaadin/demo/sampler/features/selects/ListSelectSingleExample.java new file mode 100644 index 0000000000..90c4ac2a63 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/ListSelectSingleExample.java @@ -0,0 +1,41 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.ListSelect;
+import com.vaadin.ui.VerticalLayout;
+
+public class ListSelectSingleExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private static final List cities = Arrays.asList(new String[] { "Berlin",
+ "Brussels", "Helsinki", "Madrid", "Oslo", "Paris", "Stockholm" });
+
+ public ListSelectSingleExample() {
+ setSpacing(true);
+
+ // 'Shorthand' constructor - also supports data binding using Containers
+ ListSelect citySelect = new ListSelect("Please select a city", cities);
+
+ citySelect.setRows(7); // perfect length in out case
+ citySelect.setNullSelectionAllowed(false); // user can not 'unselect'
+ citySelect.select("Berlin"); // select this by default
+ citySelect.setImmediate(true); // send the change to the server at once
+ citySelect.addListener(this); // react when the user selects something
+
+ addComponent(citySelect);
+ }
+
+ /*
+ * Shows a notification when a selection is made. The listener will be
+ * called whenever the value of the component changes, i.e when the user
+ * makes a new selection.
+ */
+ public void valueChange(ValueChangeEvent event) {
+ getWindow().showNotification("Selected city: " + event.getProperty());
+
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/NativeSelection.java b/src/com/vaadin/demo/sampler/features/selects/NativeSelection.java new file mode 100644 index 0000000000..95523cddf1 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/NativeSelection.java @@ -0,0 +1,45 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.NativeSelect;
+
+public class NativeSelection extends Feature {
+ @Override
+ public String getName() {
+ return "Native select";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A NativeSelect is a a simple drop-down list"
+ + " for selecting one item. It is called <i>native</i>"
+ + " because it uses the look and feel from the browser in use.<br/>"
+ + " The ComboBox component is a much more versatile variant,"
+ + " but without the native look and feel.<br/>"
+ + " From a usability standpoint, you might also want to"
+ + " consider using a ListSelect in single-select-mode, so that"
+ + " the user can see all options right away.";
+
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(NativeSelect.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { ComboBoxPlain.class, ListSelectSingle.class,
+ FeatureSet.Selects.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/NativeSelectionExample.java b/src/com/vaadin/demo/sampler/features/selects/NativeSelectionExample.java new file mode 100644 index 0000000000..63976bfc70 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/NativeSelectionExample.java @@ -0,0 +1,37 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.NativeSelect;
+import com.vaadin.ui.VerticalLayout;
+
+public class NativeSelectionExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private static final String[] cities = new String[] { "Berlin", "Brussels",
+ "Helsinki", "Madrid", "Oslo", "Paris", "Stockholm" };
+
+ public NativeSelectionExample() {
+ setSpacing(true);
+
+ NativeSelect l = new NativeSelect("Please select a city");
+ for (int i = 0; i < cities.length; i++) {
+ l.addItem(cities[i]);
+ }
+
+ l.setNullSelectionAllowed(false);
+ l.setValue("Berlin");
+ l.setImmediate(true);
+ l.addListener(this);
+
+ addComponent(l);
+ }
+
+ /*
+ * Shows a notification when a selection is made.
+ */
+ public void valueChange(ValueChangeEvent event) {
+ getWindow().showNotification("Selected city: " + event.getProperty());
+
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/TwinColumnSelect.java b/src/com/vaadin/demo/sampler/features/selects/TwinColumnSelect.java new file mode 100644 index 0000000000..3522a4e8ca --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/TwinColumnSelect.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.TwinColSelect;
+
+public class TwinColumnSelect extends Feature {
+ @Override
+ public String getName() {
+ return "Twin column select (list builder)";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The TwinColumnSelect is a multiple selection component"
+ + " that shows two lists side by side. The list on the left"
+ + " shows the available items and the list on the right shows"
+ + " the selected items. <br>You can select items"
+ + " from the list on the left and click on the >> button to move"
+ + " them to the list on the right. Items can be moved back by"
+ + " selecting them and clicking on the << button.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(TwinColSelect.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { NativeSelection.class, ListSelectMultiple.class,
+ ListSelectSingle.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return new NamedExternalResource[] { new NamedExternalResource(
+ "Open Source Design Pattern Library; List Builder",
+ "http://www.uidesignpatterns.org/content/list-builder") };
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/selects/TwinColumnSelectExample.java b/src/com/vaadin/demo/sampler/features/selects/TwinColumnSelectExample.java new file mode 100644 index 0000000000..b35a4d60d7 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/selects/TwinColumnSelectExample.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.selects;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.TwinColSelect;
+import com.vaadin.ui.VerticalLayout;
+
+public class TwinColumnSelectExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private static final String[] cities = new String[] { "Berlin", "Brussels",
+ "Helsinki", "Madrid", "Oslo", "Paris", "Stockholm" };
+
+ public TwinColumnSelectExample() {
+ setSpacing(true);
+
+ TwinColSelect l = new TwinColSelect("Please select some cities");
+ for (int i = 0; i < cities.length; i++) {
+ l.addItem(cities[i]);
+ }
+ l.setRows(7);
+ l.setNullSelectionAllowed(true);
+ l.setMultiSelect(true);
+ l.setImmediate(true);
+ l.addListener(this);
+
+ addComponent(l);
+ }
+
+ /*
+ * Shows a notification when a selection is made.
+ */
+ public void valueChange(ValueChangeEvent event) {
+ if (!event.getProperty().toString().equals("[]")) {
+ getWindow().showNotification(
+ "Selected cities: " + event.getProperty());
+ }
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableActions.png b/src/com/vaadin/demo/sampler/features/table/75-TableActions.png Binary files differnew file mode 100644 index 0000000000..dacd3aea86 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableActions.png diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableCellStyling.png b/src/com/vaadin/demo/sampler/features/table/75-TableCellStyling.png Binary files differnew file mode 100644 index 0000000000..798ec20b4f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableCellStyling.png diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableColumnAlignment.png b/src/com/vaadin/demo/sampler/features/table/75-TableColumnAlignment.png Binary files differnew file mode 100644 index 0000000000..87d6a18a51 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableColumnAlignment.png diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableColumnCollapsing.png b/src/com/vaadin/demo/sampler/features/table/75-TableColumnCollapsing.png Binary files differnew file mode 100644 index 0000000000..b0922dc00b --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableColumnCollapsing.png diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableColumnHeaders.png b/src/com/vaadin/demo/sampler/features/table/75-TableColumnHeaders.png Binary files differnew file mode 100644 index 0000000000..b277610f8d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableColumnHeaders.png diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableColumnReordering.png b/src/com/vaadin/demo/sampler/features/table/75-TableColumnReordering.png Binary files differnew file mode 100644 index 0000000000..6c689212cc --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableColumnReordering.png diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableHeaderIcons.png b/src/com/vaadin/demo/sampler/features/table/75-TableHeaderIcons.png Binary files differnew file mode 100644 index 0000000000..b277610f8d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableHeaderIcons.png diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableLazyLoading.png b/src/com/vaadin/demo/sampler/features/table/75-TableLazyLoading.png Binary files differnew file mode 100644 index 0000000000..e5a294cf65 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableLazyLoading.png diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableMouseEvents.png b/src/com/vaadin/demo/sampler/features/table/75-TableMouseEvents.png Binary files differnew file mode 100644 index 0000000000..798ec20b4f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableMouseEvents.png diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableRowHeaders.png b/src/com/vaadin/demo/sampler/features/table/75-TableRowHeaders.png Binary files differnew file mode 100644 index 0000000000..b277610f8d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableRowHeaders.png diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableRowStyling.png b/src/com/vaadin/demo/sampler/features/table/75-TableRowStyling.png Binary files differnew file mode 100644 index 0000000000..f523a049fe --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableRowStyling.png diff --git a/src/com/vaadin/demo/sampler/features/table/75-TableSorting.png b/src/com/vaadin/demo/sampler/features/table/75-TableSorting.png Binary files differnew file mode 100644 index 0000000000..4014d3aec7 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/75-TableSorting.png diff --git a/src/com/vaadin/demo/sampler/features/table/TableActions.java b/src/com/vaadin/demo/sampler/features/table/TableActions.java new file mode 100644 index 0000000000..3c08f9cb75 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableActions.java @@ -0,0 +1,44 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableActions extends Feature { + + @Override + public String getName() { + return "Table, context menu"; + } + + @Override + public Component getExample() { + return new TableMainFeaturesExample(); + } + + @Override + public String getDescription() { + return "Actions can be added to each row, and are show in a" + + " context menu when right-clicking."; + + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableCellStyling.java b/src/com/vaadin/demo/sampler/features/table/TableCellStyling.java new file mode 100644 index 0000000000..4dd1a41218 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableCellStyling.java @@ -0,0 +1,46 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableCellStyling extends Feature { + + @Override + public String getName() { + return "Table, styling cells"; + } + + @Override + public Component getExample() { + return new TableStylingExample(); + } + + @Override + public String getDescription() { + return "Individual cells can be styled in a Table by using a" + + " CellStyleGenerator. Regular CSS is used to create the" + + " actual style.<br/>Double click a first or last name to" + + " mark/unmark that cell."; + + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableColumnAlignment.java b/src/com/vaadin/demo/sampler/features/table/TableColumnAlignment.java new file mode 100644 index 0000000000..5ede6a9de5 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableColumnAlignment.java @@ -0,0 +1,42 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableColumnAlignment extends Feature { + + @Override + public String getName() { + return "Table, column alignment"; + } + + @Override + public Component getExample() { + return new TableMainFeaturesExample(); + } + + @Override + public String getDescription() { + return "Columns can be aligned left (default), center or right."; + + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableColumnCollapsing.java b/src/com/vaadin/demo/sampler/features/table/TableColumnCollapsing.java new file mode 100644 index 0000000000..fdc21f8620 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableColumnCollapsing.java @@ -0,0 +1,46 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableColumnCollapsing extends Feature { + + @Override + public String getName() { + return "Table, column collapsing"; + } + + @Override + public Component getExample() { + return new TableMainFeaturesExample(); + } + + @Override + public String getDescription() { + return "Columns can be 'collapsed', which means that it's not shown," + + " but the user can make the column re-appear by using the" + + " menu in the upper right of the table.<br/>" + + " Columns can also be made invisible, in which case they can" + + " not be brought back by the user."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableColumnHeaders.java b/src/com/vaadin/demo/sampler/features/table/TableColumnHeaders.java new file mode 100644 index 0000000000..aa4dc85ddd --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableColumnHeaders.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableColumnHeaders extends Feature { + + @Override + public String getName() { + return "Table, column headers"; + } + + @Override + public Component getExample() { + return new TableMainFeaturesExample(); + } + + @Override + public String getDescription() { + return "A Table can have column headers, which support different modes" + + " with automatic or explicitly set caption and/or icon."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableColumnReordering.java b/src/com/vaadin/demo/sampler/features/table/TableColumnReordering.java new file mode 100644 index 0000000000..7b01fedc78 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableColumnReordering.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableColumnReordering extends Feature { + + @Override + public String getName() { + return "Table, column drag&drop"; + } + + @Override + public Component getExample() { + return new TableMainFeaturesExample(); + } + + @Override + public String getDescription() { + return "The columns can be rearranged with drag&drop - a feature" + + " which can be enabled or disabled."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableHeaderIcons.java b/src/com/vaadin/demo/sampler/features/table/TableHeaderIcons.java new file mode 100644 index 0000000000..df12a44097 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableHeaderIcons.java @@ -0,0 +1,44 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableHeaderIcons extends Feature { + + @Override + public String getName() { + return "Table, icons in headers"; + } + + @Override + public Component getExample() { + return new TableMainFeaturesExample(); + } + + @Override + public String getDescription() { + return "A Table can have icons in the column- and rowheaders. " + + " The rowheader icon can come from a item property, or be" + + " explicitly set."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableLazyLoading.java b/src/com/vaadin/demo/sampler/features/table/TableLazyLoading.java new file mode 100644 index 0000000000..a800451258 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableLazyLoading.java @@ -0,0 +1,46 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableLazyLoading extends Feature { + + @Override + public String getName() { + return "Table, lazy loading"; + } + + @Override + public Component getExample() { + return new TableMainFeaturesExample(); + } + + @Override + public String getDescription() { + return "Table supports lazy-loading, which means that the content is" + + " loaded from the server only when needed. This allows the " + + " table to stay efficient even when scrolling hundreds of" + + " thousands of rows.<br/>Try scrolling a fair amount quickly!"; + + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableMainFeaturesExample.java b/src/com/vaadin/demo/sampler/features/table/TableMainFeaturesExample.java new file mode 100644 index 0000000000..3629f9e9ae --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableMainFeaturesExample.java @@ -0,0 +1,150 @@ +package com.vaadin.demo.sampler.features.table; + +import java.util.HashSet; +import java.util.Set; + +import com.vaadin.data.Item; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.demo.sampler.ExampleUtil; +import com.vaadin.event.Action; +import com.vaadin.terminal.ThemeResource; +import com.vaadin.ui.Label; +import com.vaadin.ui.Table; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Table.CellStyleGenerator; + +public class TableMainFeaturesExample extends VerticalLayout { + + Table table = new Table("ISO-3166 Country Codes and flags"); + + HashSet<Object> markedRows = new HashSet<Object>(); + + static final Action ACTION_MARK = new Action("Mark"); + static final Action ACTION_UNMARK = new Action("Unmark"); + static final Action ACTION_LOG = new Action("Save"); + static final Action[] ACTIONS_UNMARKED = new Action[] { ACTION_MARK, + ACTION_LOG }; + static final Action[] ACTIONS_MARKED = new Action[] { ACTION_UNMARK, + ACTION_LOG }; + + public TableMainFeaturesExample() { + addComponent(table); + + // Label to indicate current selection + final Label selected = new Label("No selection"); + addComponent(selected); + + // set a style name, so we can style rows and cells + table.setStyleName("iso3166"); + + // size + table.setWidth("100%"); + table.setPageLength(7); + + // selectable + table.setSelectable(true); + table.setMultiSelect(true); + table.setImmediate(true); // react at once when something is selected + + // connect data source + table.setContainerDataSource(ExampleUtil.getISO3166Container()); + + // turn on column reordering and collapsing + table.setColumnReorderingAllowed(true); + table.setColumnCollapsingAllowed(true); + + // set column headers + table.setColumnHeaders(new String[] { "Country", "Code", "Icon file" }); + + // Icons for column headers + table.setColumnIcon(ExampleUtil.iso3166_PROPERTY_FLAG, + new ThemeResource("icons/action_save.gif")); + table.setColumnIcon(ExampleUtil.iso3166_PROPERTY_NAME, + new ThemeResource("icons/icon_get_world.gif")); + table.setColumnIcon(ExampleUtil.iso3166_PROPERTY_SHORT, + new ThemeResource("icons/page_code.gif")); + + // Column alignment + table.setColumnAlignment(ExampleUtil.iso3166_PROPERTY_SHORT, + Table.ALIGN_CENTER); + + // Column width + table.setColumnExpandRatio(ExampleUtil.iso3166_PROPERTY_NAME, 1); + table.setColumnWidth(ExampleUtil.iso3166_PROPERTY_SHORT, 70); + + // Collapse one column - the user can make it visible again + try { + table.setColumnCollapsed(ExampleUtil.iso3166_PROPERTY_FLAG, true); + } catch (IllegalAccessException e) { + // Not critical, but strange + System.err.println(e); + } + + // show row header w/ icon + table.setRowHeaderMode(Table.ROW_HEADER_MODE_ICON_ONLY); + table.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG); + + // Actions (a.k.a context menu) + table.addActionHandler(new Action.Handler() { + public Action[] getActions(Object target, Object sender) { + if (markedRows.contains(target)) { + return ACTIONS_MARKED; + } else { + return ACTIONS_UNMARKED; + } + } + + public void handleAction(Action action, Object sender, Object target) { + if (ACTION_MARK.equals(action)) { + markedRows.add(target); + table.requestRepaint(); + } else if (ACTION_UNMARK.equals(action)) { + markedRows.remove(target); + table.requestRepaint(); + } else if (ACTION_LOG.equals(action)) { + Item item = table.getItem(target); + addComponent(new Label("Saved: " + + target + + ", " + + item.getItemProperty( + ExampleUtil.iso3166_PROPERTY_NAME) + .getValue())); + } + + } + + }); + + // style generator + table.setCellStyleGenerator(new CellStyleGenerator() { + public String getStyle(Object itemId, Object propertyId) { + if (propertyId == null) { + // no propertyId, styling row + return (markedRows.contains(itemId) ? "marked" : null); + } else if (ExampleUtil.iso3166_PROPERTY_NAME.equals(propertyId)) { + return "bold"; + } else { + // no style + return null; + } + + } + + }); + + // listen for valueChange, a.k.a 'select' and update the label + table.addListener(new Table.ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + // in multiselect mode, a Set of itemIds is returned, + // in singleselect mode the itemId is returned directly + Set value = (Set) event.getProperty().getValue(); + if (null == value || value.size() == 0) { + selected.setValue("No selection"); + } else { + selected.setValue("Selected: " + table.getValue()); + } + } + }); + + } +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableMouseEvents.java b/src/com/vaadin/demo/sampler/features/table/TableMouseEvents.java new file mode 100644 index 0000000000..8cc57641aa --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableMouseEvents.java @@ -0,0 +1,45 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableMouseEvents extends Feature { + + @Override + public String getName() { + return "Table, mouse events"; + } + + @Override + public Component getExample() { + return new TableStylingExample(); + } + + @Override + public String getDescription() { + return "An ItemClickListener can be used to react to mouse click" + + " events. Different buttons, double click, and modifier keys" + + " can be detected.<br/>Double-click a first or last name to" + + " toggle it's marked state."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableRowHeaders.java b/src/com/vaadin/demo/sampler/features/table/TableRowHeaders.java new file mode 100644 index 0000000000..1eb98dc871 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableRowHeaders.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableRowHeaders extends Feature { + + @Override + public String getName() { + return "Table, row headers"; + } + + @Override + public Component getExample() { + return new TableMainFeaturesExample(); + } + + @Override + public String getDescription() { + return "A Table can have row headers, which support different modes" + + " with automatic or explicitly set caption and/or icon."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableRowStyling.java b/src/com/vaadin/demo/sampler/features/table/TableRowStyling.java new file mode 100644 index 0000000000..af022f9813 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableRowStyling.java @@ -0,0 +1,46 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableRowStyling extends Feature { + + @Override + public String getName() { + return "Table, row styling"; + } + + @Override + public Component getExample() { + return new TableStylingExample(); + } + + @Override + public String getDescription() { + return "Rows can be styled in a Table by using a CellStyleGenerator." + + " Regular CSS is used to create the actual style.<br/>Use the" + + " context menu (right-/ctrl-click) to apply a row style in" + + " the example."; + + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableSorting.java b/src/com/vaadin/demo/sampler/features/table/TableSorting.java new file mode 100644 index 0000000000..a812b9cf75 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableSorting.java @@ -0,0 +1,45 @@ +package com.vaadin.demo.sampler.features.table; + +import com.vaadin.demo.sampler.APIResource; +import com.vaadin.demo.sampler.Feature; +import com.vaadin.demo.sampler.FeatureSet; +import com.vaadin.demo.sampler.NamedExternalResource; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class TableSorting extends Feature { + + @Override + public String getName() { + return "Table, sorting"; + } + + @Override + public Component getExample() { + return new TableMainFeaturesExample(); + } + + @Override + public String getDescription() { + return "The Table columns can (optionally) be sorted by clicking the" + + " column header - a sort direction indicator will appear." + + " Clicking again will change the sorting direction."; + + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Table.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { FeatureSet.Tables.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + return null; + } + +} diff --git a/src/com/vaadin/demo/sampler/features/table/TableStylingExample.java b/src/com/vaadin/demo/sampler/features/table/TableStylingExample.java new file mode 100644 index 0000000000..afcd565ff7 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/table/TableStylingExample.java @@ -0,0 +1,154 @@ +package com.vaadin.demo.sampler.features.table; + +import java.util.HashMap; +import java.util.HashSet; + +import com.vaadin.data.Item; +import com.vaadin.demo.sampler.ExampleUtil; +import com.vaadin.event.Action; +import com.vaadin.event.ItemClickEvent; +import com.vaadin.event.ItemClickEvent.ItemClickListener; +import com.vaadin.terminal.ExternalResource; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.Link; +import com.vaadin.ui.Table; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Table.CellStyleGenerator; + +public class TableStylingExample extends VerticalLayout { + + Table table = new Table(); + + HashMap<Object, String> markedRows = new HashMap<Object, String>(); + HashMap<Object, HashSet<Object>> markedCells = new HashMap<Object, HashSet<Object>>(); + + static final Action ACTION_RED = new Action("red"); + static final Action ACTION_BLUE = new Action("blue"); + static final Action ACTION_GREEN = new Action("green"); + static final Action ACTION_NONE = new Action("none"); + static final Action[] ACTIONS = new Action[] { ACTION_RED, ACTION_GREEN, + ACTION_BLUE, ACTION_NONE }; + + public TableStylingExample() { + setSpacing(true); + + addComponent(table); + + // set a style name, so we can style rows and cells + table.setStyleName("contacts"); + + // size + table.setWidth("100%"); + table.setPageLength(7); + + // connect data source + table.setContainerDataSource(ExampleUtil.getPersonContainer()); + + // Generate the email-link from firstname & lastname + table.addGeneratedColumn("Email", new Table.ColumnGenerator() { + public Component generateCell(Table source, Object itemId, + Object columnId) { + Item item = table.getItem(itemId); + String fn = (String) item.getItemProperty( + ExampleUtil.PERSON_PROPERTY_FIRSTNAME).getValue(); + String ln = (String) item.getItemProperty( + ExampleUtil.PERSON_PROPERTY_LASTNAME).getValue(); + String email = fn.toLowerCase() + "." + ln.toLowerCase() + + "@example.com"; + // the Link -component: + Link emailLink = new Link(email, new ExternalResource("mailto:" + + email)); + return emailLink; + } + + }); + + // turn on column reordering and collapsing + table.setColumnReorderingAllowed(true); + table.setColumnCollapsingAllowed(true); + + // Actions (a.k.a context menu) + table.addActionHandler(new Action.Handler() { + public Action[] getActions(Object target, Object sender) { + return ACTIONS; + } + + public void handleAction(Action action, Object sender, Object target) { + markedRows.remove(target); + if (!ACTION_NONE.equals(action)) { + // we're using the cations caption as stylename as well: + markedRows.put(target, action.getCaption()); + } + // this causes the CellStyleGenerator to return new styles, + // but table can't automatically know, we must tell it: + table.requestRepaint(); + } + + }); + + // style generator + table.setCellStyleGenerator(new CellStyleGenerator() { + public String getStyle(Object itemId, Object propertyId) { + if (propertyId == null) { + // no propertyId, styling row + return (markedRows.get(itemId)); + } else if (propertyId.equals("Email")) { + // style the generated email column + return "email"; + } else { + HashSet<Object> cells = markedCells.get(itemId); + if (cells != null && cells.contains(propertyId)) { + // marked cell + return "marked"; + } else { + // no style + return null; + } + } + + } + + }); + + // toggle cell 'marked' styling when double-clicked + table.addListener(new ItemClickListener() { + public void itemClick(ItemClickEvent event) { + if (event.isDoubleClick()) { + Object itemId = event.getItemId(); + Object propertyId = event.getPropertyId(); + HashSet<Object> cells = markedCells.get(itemId); + if (cells == null) { + cells = new HashSet<Object>(); + markedCells.put(itemId, cells); + } + if (cells.contains(propertyId)) { + // toggle marking off + cells.remove(propertyId); + } else { + // toggle marking on + cells.add(propertyId); + } + // this causes the CellStyleGenerator to return new styles, + // but table can't automatically know, we must tell it: + table.requestRepaint(); + } + } + }); + + // Editing + // we don't want to update container before pressing 'save': + table.setWriteThrough(false); + // edit button + final Button editButton = new Button("Edit"); + addComponent(editButton); + editButton.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + table.setEditable(!table.isEditable()); + editButton.setCaption((table.isEditable() ? "Save" : "Edit")); + } + }); + setComponentAlignment(editButton, "right"); + } +} diff --git a/src/com/vaadin/demo/sampler/features/tabsheets/75-TabSheetDisabled.png b/src/com/vaadin/demo/sampler/features/tabsheets/75-TabSheetDisabled.png Binary files differnew file mode 100644 index 0000000000..ce99368151 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/tabsheets/75-TabSheetDisabled.png diff --git a/src/com/vaadin/demo/sampler/features/tabsheets/75-TabSheetIcons.png b/src/com/vaadin/demo/sampler/features/tabsheets/75-TabSheetIcons.png Binary files differnew file mode 100644 index 0000000000..d7420ddc35 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/tabsheets/75-TabSheetIcons.png diff --git a/src/com/vaadin/demo/sampler/features/tabsheets/75-TabSheetScrolling.png b/src/com/vaadin/demo/sampler/features/tabsheets/75-TabSheetScrolling.png Binary files differnew file mode 100644 index 0000000000..b62e084a9c --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/tabsheets/75-TabSheetScrolling.png diff --git a/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetDisabled.java b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetDisabled.java new file mode 100644 index 0000000000..ad8a52cc83 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetDisabled.java @@ -0,0 +1,35 @@ +package com.vaadin.demo.sampler.features.tabsheets;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.TabSheet;
+
+public class TabSheetDisabled extends Feature {
+ @Override
+ public String getName() {
+ return "Tabsheet, disabled tabs";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Individual tabs can be enabled, disabled, hidden or visible.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(TabSheet.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { TabSheetIcons.class, TabSheetScrolling.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetDisabledExample.java b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetDisabledExample.java new file mode 100644 index 0000000000..1491e57e85 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetDisabledExample.java @@ -0,0 +1,90 @@ +package com.vaadin.demo.sampler.features.tabsheets;
+
+import com.vaadin.terminal.ThemeResource;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TabSheet;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
+import com.vaadin.ui.TabSheet.Tab;
+
+public class TabSheetDisabledExample extends VerticalLayout implements
+ TabSheet.SelectedTabChangeListener, Button.ClickListener {
+ private static final ThemeResource icon1 = new ThemeResource(
+ "icons/action_save.gif");
+ private static final ThemeResource icon2 = new ThemeResource(
+ "icons/comment_yellow.gif");
+ private static final ThemeResource icon3 = new ThemeResource(
+ "icons/icon_info.gif");
+
+ private TabSheet t;
+ private Button toggleEnabled;
+ private Button toggleVisible;
+ private VerticalLayout l1;
+ private VerticalLayout l2;
+ private VerticalLayout l3;
+ private Tab t1, t2, t3;
+
+ public TabSheetDisabledExample() {
+ setSpacing(true);
+
+ // Tab 1 content
+ l1 = new VerticalLayout();
+ l1.setMargin(true);
+ l1.addComponent(new Label("There are no previously saved actions."));
+ // Tab 2 content
+ l2 = new VerticalLayout();
+ l2.setMargin(true);
+ l2.addComponent(new Label("There are no saved notes."));
+ // Tab 3 content
+ l3 = new VerticalLayout();
+ l3.setMargin(true);
+ l3.addComponent(new Label("There are currently no issues."));
+
+ t = new TabSheet();
+ t.setHeight("200px");
+ t.setWidth("400px");
+ t1 = t.addTab(l1, "Saved actions", icon1);
+ t2 = t.addTab(l2, "Notes", icon2);
+ t3 = t.addTab(l3, "Issues", icon3);
+ t.addListener(this);
+
+ toggleEnabled = new Button("Disable 'Notes' tab");
+ toggleEnabled.addListener(this);
+
+ toggleVisible = new Button("Hide 'Issues' tab");
+ toggleVisible.addListener(this);
+
+ HorizontalLayout hl = new HorizontalLayout();
+ hl.setSpacing(true);
+ hl.addComponent(toggleEnabled);
+ hl.addComponent(toggleVisible);
+
+ addComponent(t);
+ addComponent(hl);
+ }
+
+ public void selectedTabChange(SelectedTabChangeEvent event) {
+ String c = t.getTab(event.getTabSheet().getSelectedTab()).getCaption();
+ getWindow().showNotification("Selected tab: " + c);
+ }
+
+ public void buttonClick(ClickEvent event) {
+ if (toggleEnabled.equals(event.getButton())) {
+ // toggleEnabled clicked
+ t2.setEnabled(!t2.isEnabled());
+ toggleEnabled.setCaption((t2.isEnabled() ? "Disable" : "Enable")
+ + " 'Notes' tab");
+
+ } else {
+ // toggleVisible clicked
+ t3.setVisible(!t3.isVisible());
+ toggleVisible.setCaption((t3.isVisible() ? "Hide" : "Show")
+ + " 'Issues' tab");
+
+ }
+ t.requestRepaint();
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetIcons.java b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetIcons.java new file mode 100644 index 0000000000..aa7a1d180c --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetIcons.java @@ -0,0 +1,35 @@ +package com.vaadin.demo.sampler.features.tabsheets;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.TabSheet;
+
+public class TabSheetIcons extends Feature {
+ @Override
+ public String getName() {
+ return "Tabsheet with icons";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Each tab can have an Icon in addition to the caption.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(TabSheet.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { TabSheetScrolling.class, TabSheetDisabled.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetIconsExample.java b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetIconsExample.java new file mode 100644 index 0000000000..5bbe5e8835 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetIconsExample.java @@ -0,0 +1,52 @@ +package com.vaadin.demo.sampler.features.tabsheets;
+
+import com.vaadin.terminal.ThemeResource;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TabSheet;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
+
+public class TabSheetIconsExample extends VerticalLayout implements
+ TabSheet.SelectedTabChangeListener {
+
+ // Icons for the table
+ private static final ThemeResource icon1 = new ThemeResource(
+ "icons/action_save.gif");
+ private static final ThemeResource icon2 = new ThemeResource(
+ "icons/comment_yellow.gif");
+ private static final ThemeResource icon3 = new ThemeResource(
+ "icons/icon_info.gif");
+
+ private TabSheet t;
+
+ public TabSheetIconsExample() {
+ // Tab 1 content
+ VerticalLayout l1 = new VerticalLayout();
+ l1.setMargin(true);
+ l1.addComponent(new Label("There are no previously saved actions."));
+ // Tab 2 content
+ VerticalLayout l2 = new VerticalLayout();
+ l2.setMargin(true);
+ l2.addComponent(new Label("There are no saved notes."));
+ // Tab 3 content
+ VerticalLayout l3 = new VerticalLayout();
+ l3.setMargin(true);
+ l3.addComponent(new Label("There are currently no issues."));
+
+ t = new TabSheet();
+ t.setHeight("200px");
+ t.setWidth("400px");
+
+ t.addTab(l1, "Saved actions", icon1);
+ t.addTab(l2, "Notes", icon2);
+ t.addTab(l3, "Issues", icon3);
+ t.addListener(this);
+
+ addComponent(t);
+ }
+
+ public void selectedTabChange(SelectedTabChangeEvent event) {
+ String c = t.getTabCaption(event.getTabSheet().getSelectedTab());
+ getWindow().showNotification("Selected tab: " + c);
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetScrolling.java b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetScrolling.java new file mode 100644 index 0000000000..6fcae06bc2 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetScrolling.java @@ -0,0 +1,35 @@ +package com.vaadin.demo.sampler.features.tabsheets;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.TabSheet;
+
+public class TabSheetScrolling extends Feature {
+ @Override
+ public String getName() {
+ return "Tabsheet, scrolling tabs";
+ }
+
+ @Override
+ public String getDescription() {
+ return "If the tabs are to many to be shown at once, a scrolling control will appear automatically.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(TabSheet.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { TabSheetIcons.class, TabSheetDisabled.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetScrollingExample.java b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetScrollingExample.java new file mode 100644 index 0000000000..f5e3627f10 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/tabsheets/TabSheetScrollingExample.java @@ -0,0 +1,60 @@ +package com.vaadin.demo.sampler.features.tabsheets;
+
+import com.vaadin.terminal.ThemeResource;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TabSheet;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
+
+public class TabSheetScrollingExample extends VerticalLayout implements
+ TabSheet.SelectedTabChangeListener {
+
+ private static final ThemeResource icon1 = new ThemeResource(
+ "icons/action_save.gif");
+ private static final ThemeResource icon2 = new ThemeResource(
+ "icons/comment_yellow.gif");
+ private static final ThemeResource icon3 = new ThemeResource(
+ "icons/icon_info.gif");
+
+ private TabSheet t;
+
+ public TabSheetScrollingExample() {
+ // Tab 1 content
+ VerticalLayout l1 = new VerticalLayout();
+ l1.setMargin(true);
+ l1.addComponent(new Label("There are no previously saved actions."));
+ // Tab 2 content
+ VerticalLayout l2 = new VerticalLayout();
+ l2.setMargin(true);
+ l2.addComponent(new Label("There are no saved notes."));
+ // Tab 3 content
+ VerticalLayout l3 = new VerticalLayout();
+ l3.setMargin(true);
+ l3.addComponent(new Label("There are currently no issues."));
+ // Tab 4 content
+ VerticalLayout l4 = new VerticalLayout();
+ l4.setMargin(true);
+ l4.addComponent(new Label("There are no comments."));
+ // Tab 5 content
+ VerticalLayout l5 = new VerticalLayout();
+ l5.setMargin(true);
+ l5.addComponent(new Label("There is no new feedback."));
+
+ t = new TabSheet();
+ t.setHeight("200px");
+ t.setWidth("400px");
+ t.addTab(l1, "Saved actions", icon1);
+ t.addTab(l2, "Notes", icon2);
+ t.addTab(l3, "Issues", icon3);
+ t.addTab(l4, "Comments", icon2);
+ t.addTab(l5, "Feedback", icon2);
+ t.addListener(this);
+
+ addComponent(t);
+ }
+
+ public void selectedTabChange(SelectedTabChangeEvent event) {
+ String c = t.getTabCaption(event.getTabSheet().getSelectedTab());
+ getWindow().showNotification("Selected tab: " + c);
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/75-LabelPlain.png b/src/com/vaadin/demo/sampler/features/text/75-LabelPlain.png Binary files differnew file mode 100644 index 0000000000..73393d2f3c --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/75-LabelPlain.png diff --git a/src/com/vaadin/demo/sampler/features/text/75-LabelPreformatted.png b/src/com/vaadin/demo/sampler/features/text/75-LabelPreformatted.png Binary files differnew file mode 100644 index 0000000000..70dd443db9 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/75-LabelPreformatted.png diff --git a/src/com/vaadin/demo/sampler/features/text/75-LabelRich.png b/src/com/vaadin/demo/sampler/features/text/75-LabelRich.png Binary files differnew file mode 100644 index 0000000000..8b8689dc02 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/75-LabelRich.png diff --git a/src/com/vaadin/demo/sampler/features/text/75-RichTextEditor.png b/src/com/vaadin/demo/sampler/features/text/75-RichTextEditor.png Binary files differnew file mode 100644 index 0000000000..022724b571 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/75-RichTextEditor.png diff --git a/src/com/vaadin/demo/sampler/features/text/75-TextArea.png b/src/com/vaadin/demo/sampler/features/text/75-TextArea.png Binary files differnew file mode 100644 index 0000000000..72497f104c --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/75-TextArea.png diff --git a/src/com/vaadin/demo/sampler/features/text/75-TextFieldInputPrompt.png b/src/com/vaadin/demo/sampler/features/text/75-TextFieldInputPrompt.png Binary files differnew file mode 100644 index 0000000000..dc7fbb38f9 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/75-TextFieldInputPrompt.png diff --git a/src/com/vaadin/demo/sampler/features/text/75-TextFieldSecret.png b/src/com/vaadin/demo/sampler/features/text/75-TextFieldSecret.png Binary files differnew file mode 100644 index 0000000000..929c79e05a --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/75-TextFieldSecret.png diff --git a/src/com/vaadin/demo/sampler/features/text/75-TextFieldSingle.png b/src/com/vaadin/demo/sampler/features/text/75-TextFieldSingle.png Binary files differnew file mode 100644 index 0000000000..5df731e6d3 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/75-TextFieldSingle.png diff --git a/src/com/vaadin/demo/sampler/features/text/LabelPlain.java b/src/com/vaadin/demo/sampler/features/text/LabelPlain.java new file mode 100644 index 0000000000..b30dc69005 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/LabelPlain.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Label;
+
+public class LabelPlain extends Feature {
+ @Override
+ public String getName() {
+ return "Label, plain text";
+ }
+
+ @Override
+ public String getDescription() {
+ return "In this example the content mode is set to"
+ + " CONTENT_TEXT, meaning that the label will contain"
+ + " only plain text.";
+
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Label.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { LabelPreformatted.class, LabelRich.class,
+ TextFieldSingle.class, TextArea.class, RichTextEditor.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/LabelPlainExample.java b/src/com/vaadin/demo/sampler/features/text/LabelPlainExample.java new file mode 100644 index 0000000000..f96df7af68 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/LabelPlainExample.java @@ -0,0 +1,20 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+
+public class LabelPlainExample extends VerticalLayout {
+
+ public LabelPlainExample() {
+ setSpacing(true);
+
+ Label plainText = new Label("This is an example of a Label"
+ + " component. The content mode of this label is set"
+ + " to CONTENT_TEXT. This means that it will display"
+ + " the content text as is. HTML and XML special characters"
+ + " (<,>,&) are escaped properly to allow displaying them.");
+ plainText.setContentMode(Label.CONTENT_TEXT);
+
+ addComponent(plainText);
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/LabelPreformatted.java b/src/com/vaadin/demo/sampler/features/text/LabelPreformatted.java new file mode 100644 index 0000000000..339a251583 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/LabelPreformatted.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Label;
+
+public class LabelPreformatted extends Feature {
+ @Override
+ public String getName() {
+ return "Label, preformatted";
+ }
+
+ @Override
+ public String getDescription() {
+ return "In this example the content mode is set to"
+ + " CONTENT_PREFORMATTED. The text for this content type"
+ + " is by default rendered with fixed-width font. Line breaks"
+ + " can be inserted with \\n and tabulator characters with \\t.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Label.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { LabelPlain.class, LabelRich.class,
+ TextFieldSingle.class, TextArea.class, RichTextEditor.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/LabelPreformattedExample.java b/src/com/vaadin/demo/sampler/features/text/LabelPreformattedExample.java new file mode 100644 index 0000000000..f9dfb597ed --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/LabelPreformattedExample.java @@ -0,0 +1,25 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+
+public class LabelPreformattedExample extends VerticalLayout {
+
+ public LabelPreformattedExample() {
+ setSpacing(true);
+
+ Label preformattedText = new Label(
+ "This is an example of a Label component.\n"
+ + "\nThe content mode of this label is set"
+ + "\nto CONTENT_PREFORMATTED. This means"
+ + "\nthat it will display the content text"
+ + "\nusing a fixed-width font. You also have"
+ + "\nto insert the line breaks yourself.\n"
+ + "\n\tHTML and XML special characters"
+ + "\n\t(<,>,&) are escaped properly to"
+ + "\n\tallow displaying them.");
+ preformattedText.setContentMode(Label.CONTENT_PREFORMATTED);
+
+ addComponent(preformattedText);
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/LabelRich.java b/src/com/vaadin/demo/sampler/features/text/LabelRich.java new file mode 100644 index 0000000000..40ac46f175 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/LabelRich.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Label;
+
+public class LabelRich extends Feature {
+ @Override
+ public String getName() {
+ return "Label, rich text";
+ }
+
+ @Override
+ public String getDescription() {
+ return "In this example the content mode is set to"
+ + " CONTENT_XHTML. This content mode assumes that the"
+ + " content set to the label will be valid XHTML.<br/>"
+ + "Click the <i>Edit</i> button to edit the label content.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Label.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { LabelPlain.class, LabelPreformatted.class,
+ RichTextEditor.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/LabelRichExample.java b/src/com/vaadin/demo/sampler/features/text/LabelRichExample.java new file mode 100644 index 0000000000..289e916a8d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/LabelRichExample.java @@ -0,0 +1,48 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.RichTextArea;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+
+public class LabelRichExample extends VerticalLayout implements ClickListener {
+
+ private Button b;
+ private Label richText;
+
+ private final RichTextArea editor = new RichTextArea();
+
+ public LabelRichExample() {
+ setSpacing(true);
+ setSizeUndefined(); // let layout grow with content
+
+ richText = new Label(
+ "<h1>Rich text example</h1>"
+ + "<p>The <b>quick</b> brown fox jumps <sup>over</sup> the <b>lazy</b> dog.</p>"
+ + "<p>This text can be edited with the <i>Edit</i> -button</p>");
+ richText.setContentMode(Label.CONTENT_XHTML);
+ richText.setSizeUndefined();
+
+ addComponent(richText);
+
+ b = new Button("Edit");
+ b.addListener(this);
+ addComponent(b);
+ setComponentAlignment(b, "right");
+ }
+
+ public void buttonClick(ClickEvent event) {
+ if (getComponentIterator().next() == richText) {
+ editor.setValue(richText.getValue());
+ replaceComponent(richText, editor);
+ b.setCaption("Apply");
+ } else {
+ richText.setValue(editor.getValue());
+ replaceComponent(editor, richText);
+ b.setCaption("Edit");
+ }
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/RichTextEditor.java b/src/com/vaadin/demo/sampler/features/text/RichTextEditor.java new file mode 100644 index 0000000000..2ef5661329 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/RichTextEditor.java @@ -0,0 +1,42 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.RichTextArea;
+
+public class RichTextEditor extends Feature {
+ @Override
+ public String getName() {
+ return "Rich text area";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The RichTextArea allows 'rich' formatting of the input.<br/>"
+ + "Click the <i>Edit</i> button to edit the label content"
+ + " with the RichTextArea.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(RichTextArea.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { TextArea.class, LabelRich.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Component getExample() {
+ return new LabelRichExample();
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/TextArea.java b/src/com/vaadin/demo/sampler/features/text/TextArea.java new file mode 100644 index 0000000000..3bb731e4d3 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/TextArea.java @@ -0,0 +1,40 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.TextField;
+
+public class TextArea extends Feature {
+ @Override
+ public String getName() {
+ return "Text area";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A text field can be configured to allow multiple lines of input."
+ + "<br>The amount of columns and lines can be set, and both are set here to"
+ + " 20 characters. Note that this only affects the width and height of the"
+ + " component, not the allowed length of input.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(TextField.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { RichTextEditor.class, TextFieldSingle.class,
+ FeatureSet.Texts.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/TextAreaExample.java b/src/com/vaadin/demo/sampler/features/text/TextAreaExample.java new file mode 100644 index 0000000000..c6ca5fe181 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/TextAreaExample.java @@ -0,0 +1,49 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TextField;
+
+public class TextAreaExample extends HorizontalLayout implements
+ Property.ValueChangeListener {
+
+ private static final String initialText = "The quick brown fox jumps over the lazy dog.";
+
+ private Label plainText;
+ private final TextField editor;
+
+ public TextAreaExample() {
+ setSpacing(true);
+
+ editor = new TextField("", initialText);
+ editor.setRows(20); // this will make it an 'area', i.e multiline
+ editor.setColumns(20);
+ editor.addListener(this);
+ editor.setImmediate(true);
+ addComponent(editor);
+
+ // the TextArea is immediate, and it's valueCahnge updates the Label,
+ // so this button actually does nothing
+ addComponent(new Button(">"));
+
+ plainText = new Label(initialText);
+ plainText.setContentMode(Label.CONTENT_XHTML);
+ addComponent(plainText);
+ }
+
+ /*
+ * Catch the valuechange event of the textfield and update the value of the
+ * label component
+ */
+ public void valueChange(ValueChangeEvent event) {
+ String text = (String) editor.getValue();
+ if (text != null) {
+ // replace newline with BR, because we're using Label.CONTENT_XHTML
+ text = text.replaceAll("\n", "<br/>");
+ }
+ plainText.setValue(text);
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/TextFieldInputPrompt.java b/src/com/vaadin/demo/sampler/features/text/TextFieldInputPrompt.java new file mode 100644 index 0000000000..a7da1c61d7 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/TextFieldInputPrompt.java @@ -0,0 +1,47 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.demo.sampler.features.selects.ComboBoxInputPrompt;
+import com.vaadin.demo.sampler.features.selects.ComboBoxNewItems;
+import com.vaadin.ui.TextField;
+
+public class TextFieldInputPrompt extends Feature {
+ @Override
+ public String getName() {
+ return "Text field with input prompt";
+ }
+
+ @Override
+ public String getDescription() {
+ return " The TextField can have an <i>input prompt</i> - a textual hint that is shown within"
+ + " the field when the field is otherwise empty.<br/>"
+ + " You can use an input prompt instead of a caption to save"
+ + " space, but only do so if the function of the TextField is"
+ + " still clear when a value has been entered and the prompt is no"
+ + " longer visible.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(TextField.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ // TODO update CB -ref to 'suggest' pattern, when available
+ return new Class[] { TextFieldSingle.class, TextFieldSecret.class,
+ ComboBoxInputPrompt.class, ComboBoxNewItems.class,
+ FeatureSet.Texts.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return new NamedExternalResource[] { new NamedExternalResource(
+ "UI Patterns, Input Prompt",
+ "http://ui-patterns.com/pattern/InputPrompt") };
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/TextFieldInputPromptExample.java b/src/com/vaadin/demo/sampler/features/text/TextFieldInputPromptExample.java new file mode 100644 index 0000000000..9f3d40b445 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/TextFieldInputPromptExample.java @@ -0,0 +1,49 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+
+public class TextFieldInputPromptExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ public TextFieldInputPromptExample() {
+ // add som 'air' to the layout
+ setSpacing(true);
+ setMargin(true);
+
+ // Username field + input prompt
+ TextField username = new TextField();
+ username.setInputPrompt("Username");
+ // configure & add to layout
+ username.setImmediate(true);
+ username.addListener(this);
+ addComponent(username);
+
+ // Password field + input prompt
+ TextField password = new TextField();
+ password.setInputPrompt("Password");
+ // configure & add to layout
+ password.setSecret(true);
+ password.setImmediate(true);
+ password.addListener(this);
+ addComponent(password);
+
+ // Comment field + input prompt
+ TextField comment = new TextField();
+ comment.setInputPrompt("Comment");
+ // configure & add to layout
+ comment.setRows(3);
+ comment.setImmediate(true);
+ comment.addListener(this);
+ addComponent(comment);
+
+ }
+
+ public void valueChange(ValueChangeEvent event) {
+ getWindow().showNotification("Received " + event.getProperty());
+
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/TextFieldSecret.java b/src/com/vaadin/demo/sampler/features/text/TextFieldSecret.java new file mode 100644 index 0000000000..b40daafedc --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/TextFieldSecret.java @@ -0,0 +1,41 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.demo.sampler.features.selects.ComboBoxNewItems;
+import com.vaadin.ui.TextField;
+
+public class TextFieldSecret extends Feature {
+ @Override
+ public String getName() {
+ return "Text field, secret (password)";
+ }
+
+ @Override
+ public String getDescription() {
+ return "For sensitive data input, such as passwords, the text field can"
+ + " also be set into secret mode where the input will not be"
+ + " echoed to display.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(TextField.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ // TODO update CB -ref to 'suggest' pattern, when available
+ return new Class[] { TextFieldSingle.class, ComboBoxNewItems.class,
+ FeatureSet.Texts.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/TextFieldSecretExample.java b/src/com/vaadin/demo/sampler/features/text/TextFieldSecretExample.java new file mode 100644 index 0000000000..f0fee03346 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/TextFieldSecretExample.java @@ -0,0 +1,40 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class TextFieldSecretExample extends VerticalLayout {
+
+ private final TextField username;
+ private final TextField password;
+
+ public TextFieldSecretExample() {
+ setSizeUndefined(); // let content 'push' size
+ setSpacing(true);
+
+ // Username
+ username = new TextField("Username");
+ addComponent(username);
+
+ // Password
+ password = new TextField("Password");
+ password.setSecret(true);
+ addComponent(password);
+
+ // Login button
+ Button loginButton = new Button("Login", new Button.ClickListener() {
+ // inline click listener
+ public void buttonClick(ClickEvent event) {
+ getWindow().showNotification(
+ "User: " + username.getValue() + " Password: "
+ + password.getValue());
+
+ }
+ });
+ addComponent(loginButton);
+ setComponentAlignment(loginButton, "right");
+
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/TextFieldSingle.java b/src/com/vaadin/demo/sampler/features/text/TextFieldSingle.java new file mode 100644 index 0000000000..15aa90de1c --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/TextFieldSingle.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.demo.sampler.features.selects.ComboBoxNewItems;
+import com.vaadin.ui.TextField;
+
+public class TextFieldSingle extends Feature {
+ @Override
+ public String getName() {
+ return "Text field";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A single-line TextField is a fundamental UI building blocks"
+ + " with numerous uses.<br/>"
+ + "If the input would benefit from remembering previous values,"
+ + " you might want to consider using a ComboBox it it's "
+ + " 'suggesting mode' instead.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(TextField.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ // TODO update CB -ref to 'suggest' pattern, when available
+ return new Class[] { TextFieldSecret.class, ComboBoxNewItems.class,
+ FeatureSet.Texts.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/text/TextFieldSingleExample.java b/src/com/vaadin/demo/sampler/features/text/TextFieldSingleExample.java new file mode 100644 index 0000000000..53b20db7ed --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/text/TextFieldSingleExample.java @@ -0,0 +1,31 @@ +package com.vaadin.demo.sampler.features.text;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+
+public class TextFieldSingleExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private final TextField editor = new TextField("Echo this:");
+
+ public TextFieldSingleExample() {
+ setSpacing(true);
+
+ editor.addListener(this);
+ editor.setImmediate(true);
+ // editor.setColumns(5); // guarantees that at least 5 chars fit
+
+ addComponent(editor);
+ }
+
+ /*
+ * Catch the valuechange event of the textfield and update the value of the
+ * label component
+ */
+ public void valueChange(ValueChangeEvent event) {
+ // Show the new value we received
+ getWindow().showNotification((String) editor.getValue());
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/trees/75-TreeActions.png b/src/com/vaadin/demo/sampler/features/trees/75-TreeActions.png Binary files differnew file mode 100644 index 0000000000..7b68dee674 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/trees/75-TreeActions.png diff --git a/src/com/vaadin/demo/sampler/features/trees/75-TreeMouseEvents.png b/src/com/vaadin/demo/sampler/features/trees/75-TreeMouseEvents.png Binary files differnew file mode 100644 index 0000000000..3f22f288d1 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/trees/75-TreeMouseEvents.png diff --git a/src/com/vaadin/demo/sampler/features/trees/75-TreeMultiSelect.png b/src/com/vaadin/demo/sampler/features/trees/75-TreeMultiSelect.png Binary files differnew file mode 100644 index 0000000000..3b0b250c90 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/trees/75-TreeMultiSelect.png diff --git a/src/com/vaadin/demo/sampler/features/trees/75-TreeSingleSelect.png b/src/com/vaadin/demo/sampler/features/trees/75-TreeSingleSelect.png Binary files differnew file mode 100644 index 0000000000..03ef1eae76 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/trees/75-TreeSingleSelect.png diff --git a/src/com/vaadin/demo/sampler/features/trees/TreeActions.java b/src/com/vaadin/demo/sampler/features/trees/TreeActions.java new file mode 100644 index 0000000000..3d270e265f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/trees/TreeActions.java @@ -0,0 +1,43 @@ +package com.vaadin.demo.sampler.features.trees;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Tree;
+
+public class TreeActions extends Feature {
+ @Override
+ public String getName() {
+ return "Tree, context menu";
+ }
+
+ @Override
+ public String getDescription() {
+ return "In this example, actions have been attached to"
+ + " the tree component. Try clicking the secondary mouse"
+ + " button on an item in the tree.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Tree.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { TreeSingleSelect.class, TreeMultiSelect.class,
+ TreeMouseEvents.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Component getExample() {
+ return new TreeSingleSelectExample();
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/trees/TreeMouseEvents.java b/src/com/vaadin/demo/sampler/features/trees/TreeMouseEvents.java new file mode 100644 index 0000000000..261f72112f --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/trees/TreeMouseEvents.java @@ -0,0 +1,41 @@ +package com.vaadin.demo.sampler.features.trees;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Tree;
+
+public class TreeMouseEvents extends Feature {
+ @Override
+ public String getName() {
+ return "Tree, mouse events";
+ }
+
+ @Override
+ public String getDescription() {
+ return "In this example, selecting items from the tree"
+ + " is disabled. Instead, another method of selection"
+ + " is used. Using the ItemClickEvent, we can update the"
+ + " label showing the selection."
+ + "<br>Try to click your left, right and middle mouse"
+ + " buttons on the tree items. Any modifier keys will"
+ + " also be detected.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Tree.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { TreeSingleSelect.class, TreeMultiSelect.class,
+ TreeActions.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/trees/TreeMouseEventsExample.java b/src/com/vaadin/demo/sampler/features/trees/TreeMouseEventsExample.java new file mode 100644 index 0000000000..48d560447d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/trees/TreeMouseEventsExample.java @@ -0,0 +1,99 @@ +package com.vaadin.demo.sampler.features.trees;
+
+import com.vaadin.data.Item;
+import com.vaadin.demo.sampler.ExampleUtil;
+import com.vaadin.event.ItemClickEvent;
+import com.vaadin.event.ItemClickEvent.ItemClickListener;
+import com.vaadin.ui.AbstractSelect;
+import com.vaadin.ui.Tree;
+import com.vaadin.ui.VerticalLayout;
+
+public class TreeMouseEventsExample extends VerticalLayout implements
+ ItemClickListener {
+
+ private Tree t;
+ private int itemId;
+
+ public TreeMouseEventsExample() {
+ setSpacing(true);
+
+ // Create new Tree object using a hierarchical container from
+ // ExampleUtil class
+ t = new Tree("Hardware Inventory", ExampleUtil.getHardwareContainer());
+
+ // Add ItemClickListener to the tree
+ t.addListener(this);
+
+ t.setImmediate(true);
+
+ // Set tree to show the 'name' property as caption for items
+ t.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME);
+ t.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
+
+ // Starting itemId # for new items
+ itemId = t.getContainerDataSource().size();
+
+ // Expand whole tree
+ for (int i = 0; i < itemId; i++) {
+ t.expandItemsRecursively(i);
+ }
+
+ // Disallow selecting items from the tree
+ t.setSelectable(false);
+
+ addComponent(t);
+ }
+
+ public void itemClick(ItemClickEvent event) {
+ // Indicate which modifier keys are pressed
+ String modifiers = "";
+ if (event.isAltKey()) {
+ modifiers += "Alt ";
+ }
+ if (event.isCtrlKey()) {
+ modifiers += "Ctrl ";
+ }
+ if (event.isMetaKey()) {
+ modifiers += "Meta ";
+ }
+ if (event.isShiftKey()) {
+ modifiers += "Shift ";
+ }
+ if (modifiers.length() > 0) {
+ modifiers = "Modifiers: " + modifiers;
+ } else {
+ modifiers = "Modifiers: none";
+ }
+ switch (event.getButton()) {
+ case ItemClickEvent.BUTTON_LEFT:
+ // Left button click updates the 'selected' Label
+ getWindow().showNotification("Selected item: " + event.getItem(),
+ modifiers);
+ break;
+ case ItemClickEvent.BUTTON_MIDDLE:
+ // Middle button click removes the item
+ Object parent = t.getParent(event.getItemId());
+ getWindow().showNotification("Removed item: " + event.getItem(),
+ modifiers);
+ t.removeItem(event.getItemId());
+ if (parent != null && t.getChildren(parent).size() == 0) {
+ t.setChildrenAllowed(parent, false);
+ }
+ break;
+ case ItemClickEvent.BUTTON_RIGHT:
+ // Right button click creates a new child item
+ getWindow().showNotification("Added item: New Item # " + itemId,
+ modifiers);
+ t.setChildrenAllowed(event.getItemId(), true);
+ Item i = t.addItem(itemId);
+ t.setChildrenAllowed(itemId, false);
+ String newItemName = "New Item # " + itemId;
+ i.getItemProperty(ExampleUtil.hw_PROPERTY_NAME).setValue(
+ newItemName);
+ t.setParent(itemId, event.getItemId());
+ t.expandItem(event.getItemId());
+ itemId++;
+ break;
+ }
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/trees/TreeMultiSelect.java b/src/com/vaadin/demo/sampler/features/trees/TreeMultiSelect.java new file mode 100644 index 0000000000..c83729b29b --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/trees/TreeMultiSelect.java @@ -0,0 +1,36 @@ +package com.vaadin.demo.sampler.features.trees;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Tree;
+
+public class TreeMultiSelect extends Feature {
+ @Override
+ public String getName() {
+ return "Tree, multiple selections";
+ }
+
+ @Override
+ public String getDescription() {
+ return "In this example, you can select multiple tree nodes"
+ + " and delete the selected items. Click a selected item again to de-select it.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Tree.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { TreeSingleSelect.class, TreeActions.class,
+ TreeMouseEvents.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/trees/TreeMultiSelectExample.java b/src/com/vaadin/demo/sampler/features/trees/TreeMultiSelectExample.java new file mode 100644 index 0000000000..e97111ad85 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/trees/TreeMultiSelectExample.java @@ -0,0 +1,110 @@ +package com.vaadin.demo.sampler.features.trees;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.demo.sampler.ExampleUtil;
+import com.vaadin.event.Action;
+import com.vaadin.ui.AbstractSelect;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Tree;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class TreeMultiSelectExample extends VerticalLayout implements
+ Action.Handler {
+
+ private static final Action ACTION_ADD = new Action("Add child item");
+ private static final Action ACTION_DELETE = new Action("Delete");
+ private static final Action[] ACTIONS = new Action[] { ACTION_ADD,
+ ACTION_DELETE };
+
+ private Tree tree;
+ private Button deleteButton;
+
+ public TreeMultiSelectExample() {
+ setSpacing(true);
+
+ // Create new Tree object using a hierarchical container from
+ // ExampleUtil class
+ tree = new Tree("Hardware Inventory", ExampleUtil
+ .getHardwareContainer());
+ // Set multiselect mode
+ tree.setMultiSelect(true);
+ tree.setImmediate(true);
+ tree.addListener(new ValueChangeListener() {
+ public void valueChange(ValueChangeEvent event) {
+ Tree t = (Tree) event.getProperty();
+ // enable if something is selected, returns a set
+ deleteButton.setEnabled(t.getValue() != null
+ && ((Set) t.getValue()).size() > 0);
+ }
+ });
+
+ // Add Actionhandler
+ tree.addActionHandler(this);
+
+ // Set tree to show the 'name' property as caption for items
+ tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME);
+ tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
+
+ // Expand whole tree
+ for (Iterator it = tree.rootItemIds().iterator(); it.hasNext();) {
+ tree.expandItemsRecursively(it.next());
+ }
+
+ // Create the 'delete button', inline click-listener
+ deleteButton = new Button("Delete", new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ // Delete all the selected objects
+ Object[] toDelete = ((Set<Object>) tree.getValue()).toArray();
+ for (int i = 0; i < toDelete.length; i++) {
+ handleAction(ACTION_DELETE, tree, toDelete[i]);
+ }
+ }
+ });
+ deleteButton.setEnabled(false);
+
+ addComponent(deleteButton);
+ addComponent(tree);
+
+ }
+
+ /*
+ * Returns the set of available actions
+ */
+ public Action[] getActions(Object target, Object sender) {
+ return ACTIONS;
+ }
+
+ /*
+ * Handle actions
+ */
+ public void handleAction(Action action, Object sender, Object target) {
+ if (action == ACTION_ADD) {
+ // Allow children for the target item
+ tree.setChildrenAllowed(target, true);
+
+ // Create new item, disallow children, add name, set parent
+ Object itemId = tree.addItem();
+ tree.setChildrenAllowed(itemId, false);
+ String newItemName = "New Item # " + itemId;
+ Item item = tree.getItem(itemId);
+ item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME).setValue(
+ newItemName);
+ tree.setParent(itemId, target);
+ tree.expandItem(target);
+ } else if (action == ACTION_DELETE) {
+ Object parent = tree.getParent(target);
+ tree.removeItem(target);
+ // If the deleted object's parent has no more children, set it's
+ // childrenallowed property to false
+ if (parent != null && tree.getChildren(parent).size() == 0) {
+ tree.setChildrenAllowed(parent, false);
+ }
+ }
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/trees/TreeSingleSelect.java b/src/com/vaadin/demo/sampler/features/trees/TreeSingleSelect.java new file mode 100644 index 0000000000..d25950cdbc --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/trees/TreeSingleSelect.java @@ -0,0 +1,35 @@ +package com.vaadin.demo.sampler.features.trees;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Tree;
+
+public class TreeSingleSelect extends Feature {
+ @Override
+ public String getName() {
+ return "Tree, single selection";
+ }
+
+ @Override
+ public String getDescription() {
+ return "In this example, you can select any single tree node"
+ + " and modify its 'name' property. Click again to de-select.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Tree.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { TreeMultiSelect.class, TreeActions.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/trees/TreeSingleSelectExample.java b/src/com/vaadin/demo/sampler/features/trees/TreeSingleSelectExample.java new file mode 100644 index 0000000000..0bbeacf921 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/trees/TreeSingleSelectExample.java @@ -0,0 +1,133 @@ +package com.vaadin.demo.sampler.features.trees;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.demo.sampler.ExampleUtil;
+import com.vaadin.event.Action;
+import com.vaadin.ui.AbstractSelect;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.Tree;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class TreeSingleSelectExample extends HorizontalLayout implements
+ Property.ValueChangeListener, Button.ClickListener, Action.Handler {
+
+ // Actions for the context menu
+ private static final Action ACTION_ADD = new Action("Add child item");
+ private static final Action ACTION_DELETE = new Action("Delete");
+ private static final Action[] ACTIONS = new Action[] { ACTION_ADD,
+ ACTION_DELETE };
+
+ private Tree tree;
+
+ HorizontalLayout editBar;
+ private TextField editor;
+ private Button change;
+
+ public TreeSingleSelectExample() {
+ setSpacing(true);
+
+ // Create the Tree,a dd to layout
+ tree = new Tree("Hardware Inventory");
+ addComponent(tree);
+
+ // Contents from a (prefilled example) hierarchical container:
+ tree.setContainerDataSource(ExampleUtil.getHardwareContainer());
+
+ // Add Valuechangelistener and Actionhandler
+ tree.addListener(this);
+
+ // Add actions (context menu)
+ tree.addActionHandler(this);
+
+ // Cause valueChange immediately when the user selects
+ tree.setImmediate(true);
+
+ // Set tree to show the 'name' property as caption for items
+ tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME);
+ tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
+
+ // Expand whole tree
+ for (Object id : tree.rootItemIds()) {
+ tree.expandItemsRecursively(id);
+ }
+
+ // Create the 'editor bar' (textfield and button in a horizontallayout)
+ editBar = new HorizontalLayout();
+ editBar.setMargin(false, false, false, true);
+ editBar.setEnabled(false);
+ addComponent(editBar);
+ // textfield
+ editor = new TextField("Item name");
+ editor.setImmediate(true);
+ editBar.addComponent(editor);
+ // apply-button
+ change = new Button("Apply", this, "buttonClick");
+ editBar.addComponent(change);
+ editBar.setComponentAlignment(change, "bottom");
+ }
+
+ public void valueChange(ValueChangeEvent event) {
+ if (event.getProperty().getValue() != null) {
+ // If something is selected from the tree, get it's 'name' and
+ // insert it into the textfield
+ editor.setValue(tree.getItem(event.getProperty().getValue())
+ .getItemProperty(ExampleUtil.hw_PROPERTY_NAME));
+ editor.requestRepaint();
+ editBar.setEnabled(true);
+ } else {
+ editor.setValue("");
+ editBar.setEnabled(false);
+ }
+ }
+
+ public void buttonClick(ClickEvent event) {
+ // If the edited value contains something, set it to be the item's new
+ // 'name' property
+ if (!editor.getValue().equals("")) {
+ Item item = tree.getItem(tree.getValue());
+ Property name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME);
+ name.setValue(editor.getValue());
+ }
+ }
+
+ /*
+ * Returns the set of available actions
+ */
+ public Action[] getActions(Object target, Object sender) {
+ return ACTIONS;
+ }
+
+ /*
+ * Handle actions
+ */
+ public void handleAction(Action action, Object sender, Object target) {
+ if (action == ACTION_ADD) {
+ // Allow children for the target item, and expand it
+ tree.setChildrenAllowed(target, true);
+ tree.expandItem(target);
+
+ // Create new item, set parent, disallow children (= leaf node)
+ Object itemId = tree.addItem();
+ tree.setParent(itemId, target);
+ tree.setChildrenAllowed(itemId, false);
+
+ // Set the name for this item (we use it as item caption)
+ Item item = tree.getItem(itemId);
+ Property name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME);
+ name.setValue("New Item");
+
+ } else if (action == ACTION_DELETE) {
+ Object parent = tree.getParent(target);
+ tree.removeItem(target);
+ // If the deleted object's parent has no more children, set it's
+ // childrenallowed property to false (= leaf node)
+ if (parent != null && tree.getChildren(parent).size() == 0) {
+ tree.setChildrenAllowed(parent, false);
+ }
+ }
+ }
+}
diff --git a/src/com/vaadin/demo/sampler/features/windows/75-NativeWindow.png b/src/com/vaadin/demo/sampler/features/windows/75-NativeWindow.png Binary files differnew file mode 100644 index 0000000000..14981b1836 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/75-NativeWindow.png diff --git a/src/com/vaadin/demo/sampler/features/windows/75-Subwindow.png b/src/com/vaadin/demo/sampler/features/windows/75-Subwindow.png Binary files differnew file mode 100644 index 0000000000..bd92cc04e8 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/75-Subwindow.png diff --git a/src/com/vaadin/demo/sampler/features/windows/75-SubwindowAutoSized.png b/src/com/vaadin/demo/sampler/features/windows/75-SubwindowAutoSized.png Binary files differnew file mode 100644 index 0000000000..2752d2f581 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/75-SubwindowAutoSized.png diff --git a/src/com/vaadin/demo/sampler/features/windows/75-SubwindowClose.png b/src/com/vaadin/demo/sampler/features/windows/75-SubwindowClose.png Binary files differnew file mode 100644 index 0000000000..a76e9ba0b2 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/75-SubwindowClose.png diff --git a/src/com/vaadin/demo/sampler/features/windows/75-SubwindowModal.png b/src/com/vaadin/demo/sampler/features/windows/75-SubwindowModal.png Binary files differnew file mode 100644 index 0000000000..0eb9cfe0fd --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/75-SubwindowModal.png diff --git a/src/com/vaadin/demo/sampler/features/windows/75-SubwindowPositioned.png b/src/com/vaadin/demo/sampler/features/windows/75-SubwindowPositioned.png Binary files differnew file mode 100644 index 0000000000..c3e0d5f0a3 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/75-SubwindowPositioned.png diff --git a/src/com/vaadin/demo/sampler/features/windows/75-SubwindowSized.png b/src/com/vaadin/demo/sampler/features/windows/75-SubwindowSized.png Binary files differnew file mode 100644 index 0000000000..c918d84063 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/75-SubwindowSized.png diff --git a/src/com/vaadin/demo/sampler/features/windows/NativeWindow.java b/src/com/vaadin/demo/sampler/features/windows/NativeWindow.java new file mode 100644 index 0000000000..0d030945b5 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/NativeWindow.java @@ -0,0 +1,45 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.demo.sampler.FeatureSet.Links;
+import com.vaadin.demo.sampler.FeatureSet.Windows;
+import com.vaadin.ui.Window;
+
+public class NativeWindow extends Feature {
+
+ @Override
+ public String getName() {
+ return "Native window";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A <i>NativeWindow</i> is a separate browser window, which"
+ + " looks and works just like the main window.<br/>"
+ + " There are multiple ways to make native windows; you can"
+ + " override Application.getWindow() (recommended in any case)"
+ + " but you can also use Application.addWindow() - the added"
+ + " window will be available from a separate URL (which is"
+ + " based on the window name.)<br/> When you view Sampler in"
+ + " a new window, the getWindow() method is used, this example"
+ + " also uses addWindow().";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Window.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { Subwindow.class, Links.class, Windows.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/windows/NativeWindowExample.java b/src/com/vaadin/demo/sampler/features/windows/NativeWindowExample.java new file mode 100644 index 0000000000..b1b2933f1d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/NativeWindowExample.java @@ -0,0 +1,83 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import java.util.Date;
+
+import com.vaadin.terminal.ExternalResource;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Link;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class NativeWindowExample extends VerticalLayout {
+
+ public NativeWindowExample() {
+ setSpacing(true);
+
+ // Add a button for opening the window
+ Button open = new Button("Open native window",
+ new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ Window window = new NativeWindow();
+ // Add the window to the application
+ getApplication().addWindow(window);
+
+ // Get the URL for the window, and open that in a new
+ // browser window, in this case in a small window.
+ getWindow().open(new ExternalResource(window.getURL()), // URL
+ "_blank", // window name
+ 500, // width
+ 200, // weight
+ Window.BORDER_NONE // decorations
+ );
+ }
+ });
+ addComponent(open);
+
+ // Add a link for opening sampler in a new window; this will cause
+ // Sampler's getWindow() to create a new Window.
+ Link openSampler = new Link("Open Sampler in a new window",
+ new ExternalResource("#"), // URL
+ "_blank", // window name
+ 700, // width
+ 500, // height
+ Link.TARGET_BORDER_NONE // decorations
+ );
+ addComponent(openSampler);
+
+ }
+
+ /*
+ * We'll be instantiating the same window multiple times, so we'll make an
+ * inner class for separation. You could of course just create a new
+ * Window() and addCompoent to that instead.
+ */
+ class NativeWindow extends Window {
+ NativeWindow() {
+ // Configure the layout
+ VerticalLayout layout = (VerticalLayout) getLayout();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+
+ // Add some content; a label and a close-button
+ Label message = new Label("This is a native window, created at "
+ + new Date());
+ addComponent(message);
+
+ // It's a good idea to remove the window when it's closed (also
+ // when the browser window 'x' is used), unless you explicitly
+ // want the window to persist (if it's not removed from the
+ // application, it can still be retrieved from it's URL.
+ addListener(new CloseListener() {
+ public void windowClose(CloseEvent e) {
+ // remove from application
+ getApplication().removeWindow(NativeWindow.this);
+ }
+ });
+
+ }
+ }
+
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/features/windows/Subwindow.java b/src/com/vaadin/demo/sampler/features/windows/Subwindow.java new file mode 100644 index 0000000000..aa7d1f48c4 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/Subwindow.java @@ -0,0 +1,38 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Window;
+
+public class Subwindow extends Feature {
+
+ @Override
+ public String getName() {
+ return "Subwindow";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A <i>Subwindow</i> is a popup-window within the browser window."
+ + " There can be multiple subwindows in one (native) browser"
+ + " window.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Window.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { NativeWindow.class, FeatureSet.Windows.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/windows/SubwindowAutoSized.java b/src/com/vaadin/demo/sampler/features/windows/SubwindowAutoSized.java new file mode 100644 index 0000000000..1b8b5e32cd --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/SubwindowAutoSized.java @@ -0,0 +1,39 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Window;
+
+public class SubwindowAutoSized extends Feature {
+
+ @Override
+ public String getName() {
+ return "Window, automatic size";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The window will be automatically sized to fit the contents,"
+ + " if the size of the window (and it's layout) is undefined.<br/>"
+ + " Note that by default Window contains a VerticalLayout that"
+ + " is 100% wide.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Window.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { SubwindowSized.class, FeatureSet.Windows.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/windows/SubwindowAutoSizedExample.java b/src/com/vaadin/demo/sampler/features/windows/SubwindowAutoSizedExample.java new file mode 100644 index 0000000000..e2f0a60e3d --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/SubwindowAutoSizedExample.java @@ -0,0 +1,65 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class SubwindowAutoSizedExample extends VerticalLayout {
+
+ Window subwindow;
+
+ public SubwindowAutoSizedExample() {
+
+ // Create the window
+ subwindow = new Window("Automatically sized subwindow");
+
+ // Configure the windws layout; by default a VerticalLayout
+ VerticalLayout layout = (VerticalLayout) subwindow.getLayout();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+ // make it undefined for auto-sizing window
+ layout.setSizeUndefined();
+
+ // Add some content;
+ for (int i = 0; i < 7; i++) {
+ TextField tf = new TextField();
+ tf.setWidth("400px");
+ subwindow.addComponent(tf);
+ }
+
+ Button close = new Button("Close", new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ // close the window by removing it from the main window
+ getApplication().getMainWindow().removeWindow(subwindow);
+ }
+ });
+ // The components added to the window are actually added to the window's
+ // layout; you can use either. Alignments are set using the layout
+ layout.addComponent(close);
+ layout.setComponentAlignment(close, "right bottom");
+
+ // Add a button for opening the subwindow
+ Button open = new Button("Open sized window",
+ new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ if (subwindow.getParent() != null) {
+ // window is already showing
+ getWindow().showNotification(
+ "Window is already open");
+ } else {
+ // Open the subwindow by adding it to the main
+ // window
+ getApplication().getMainWindow().addWindow(
+ subwindow);
+ }
+ }
+ });
+ addComponent(open);
+
+ }
+
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/features/windows/SubwindowClose.java b/src/com/vaadin/demo/sampler/features/windows/SubwindowClose.java new file mode 100644 index 0000000000..6c572bd20c --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/SubwindowClose.java @@ -0,0 +1,36 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Window;
+
+public class SubwindowClose extends Feature {
+
+ @Override
+ public String getName() {
+ return "Window closing";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Using a <i>CloseListener</i> one can detect when a window is closed.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Window.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { FeatureSet.Windows.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/windows/SubwindowCloseExample.java b/src/com/vaadin/demo/sampler/features/windows/SubwindowCloseExample.java new file mode 100644 index 0000000000..2b0f0073c0 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/SubwindowCloseExample.java @@ -0,0 +1,52 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Window.CloseEvent;
+
+public class SubwindowCloseExample extends VerticalLayout {
+
+ Window subwindow;
+
+ public SubwindowCloseExample() {
+
+ // Create the window
+ subwindow = new Window("A subwindow w/ close-listener");
+ subwindow.addListener(new Window.CloseListener() {
+ // inline close-listener
+ public void windowClose(CloseEvent e) {
+ getApplication().getMainWindow().showNotification(
+ "Window closed");
+ }
+ });
+
+ // Configure the windws layout; by default a VerticalLayout
+ VerticalLayout layout = (VerticalLayout) subwindow.getLayout();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+
+ // Add some content; a label and a close-button
+ Label message = new Label("This is a subwindow with a close-listener.");
+ subwindow.addComponent(message);
+
+ // Add a button for opening the subwindow
+ Button open = new Button("Open window", new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ if (subwindow.getParent() != null) {
+ // window is already showing
+ getWindow().showNotification("Window is already open");
+ } else {
+ // Open the subwindow by adding it to the main window
+ getApplication().getMainWindow().addWindow(subwindow);
+ }
+ }
+ });
+ addComponent(open);
+
+ }
+
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/features/windows/SubwindowExample.java b/src/com/vaadin/demo/sampler/features/windows/SubwindowExample.java new file mode 100644 index 0000000000..cb48201acc --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/SubwindowExample.java @@ -0,0 +1,56 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class SubwindowExample extends VerticalLayout {
+
+ Window subwindow;
+
+ public SubwindowExample() {
+
+ // Create the window
+ subwindow = new Window("A subwindow");
+
+ // Configure the windws layout; by default a VerticalLayout
+ VerticalLayout layout = (VerticalLayout) subwindow.getLayout();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+
+ // Add some content; a label and a close-button
+ Label message = new Label("This is a subwindow");
+ subwindow.addComponent(message);
+
+ Button close = new Button("Close", new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ // close the window by removing it from the main window
+ getApplication().getMainWindow().removeWindow(subwindow);
+ }
+ });
+ // The components added to the window are actually added to the window's
+ // layout; you can use either. Alignments are set using the layout
+ layout.addComponent(close);
+ layout.setComponentAlignment(close, "right");
+
+ // Add a button for opening the subwindow
+ Button open = new Button("Open subwindow", new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ if (subwindow.getParent() != null) {
+ // window is already showing
+ getWindow().showNotification("Window is already open");
+ } else {
+ // Open the subwindow by adding it to the main window
+ getApplication().getMainWindow().addWindow(subwindow);
+ }
+ }
+ });
+ addComponent(open);
+
+ }
+
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/features/windows/SubwindowModal.java b/src/com/vaadin/demo/sampler/features/windows/SubwindowModal.java new file mode 100644 index 0000000000..28c93c1ae0 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/SubwindowModal.java @@ -0,0 +1,47 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Window;
+
+public class SubwindowModal extends Feature {
+
+ @Override
+ public String getName() {
+ return "Modal window";
+ }
+
+ @Override
+ public String getDescription() {
+ return "A <i>modal window</i> blocks access to the rest of the application"
+ + " until the window is closed (or made non-modal).<br/>"
+ + " Use modal windows when the user must finish the task in the"
+ + " window before continuing.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Window.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] {
+ //
+ Subwindow.class, //
+ FeatureSet.Windows.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return new NamedExternalResource[] {
+ //
+ new NamedExternalResource("Wikipedia: Modal window",
+ "http://en.wikipedia.org/wiki/Modal_window"), //
+
+ };
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/windows/SubwindowModalExample.java b/src/com/vaadin/demo/sampler/features/windows/SubwindowModalExample.java new file mode 100644 index 0000000000..15ee9f040a --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/SubwindowModalExample.java @@ -0,0 +1,62 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class SubwindowModalExample extends VerticalLayout {
+
+ Window subwindow;
+
+ public SubwindowModalExample() {
+
+ // Create the window...
+ subwindow = new Window("A modal subwindow");
+ // ...and make it modal
+ subwindow.setModal(true);
+
+ // Configure the windws layout; by default a VerticalLayout
+ VerticalLayout layout = (VerticalLayout) subwindow.getLayout();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+
+ // Add some content; a label and a close-button
+ Label message = new Label("This is a modal subwindow.");
+ subwindow.addComponent(message);
+
+ Button close = new Button("Close", new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ // close the window by removing it from the main window
+ getApplication().getMainWindow().removeWindow(subwindow);
+ }
+ });
+ // The components added to the window are actually added to the window's
+ // layout; you can use either. Alignments are set using the layout
+ layout.addComponent(close);
+ layout.setComponentAlignment(close, "right");
+
+ // Add a button for opening the subwindow
+ Button open = new Button("Open modal window",
+ new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ if (subwindow.getParent() != null) {
+ // window is already showing
+ getWindow().showNotification(
+ "Window is already open");
+ } else {
+ // Open the subwindow by adding it to the main
+ // window
+ getApplication().getMainWindow().addWindow(
+ subwindow);
+ }
+ }
+ });
+ addComponent(open);
+
+ }
+
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/features/windows/SubwindowPositioned.java b/src/com/vaadin/demo/sampler/features/windows/SubwindowPositioned.java new file mode 100644 index 0000000000..3da56d87bc --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/SubwindowPositioned.java @@ -0,0 +1,36 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Window;
+
+public class SubwindowPositioned extends Feature {
+
+ @Override
+ public String getName() {
+ return "Window position";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The position of a window can be specified, or it can be centered.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Window.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { FeatureSet.Windows.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/windows/SubwindowPositionedExample.java b/src/com/vaadin/demo/sampler/features/windows/SubwindowPositionedExample.java new file mode 100644 index 0000000000..f50bf0a21b --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/SubwindowPositionedExample.java @@ -0,0 +1,99 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class SubwindowPositionedExample extends VerticalLayout {
+
+ Window subwindow;
+
+ public SubwindowPositionedExample() {
+ setSpacing(true);
+
+ // Create the window
+ subwindow = new Window("A positioned subwindow");
+ // let's give it a size (optional)
+ subwindow.setWidth("300px");
+ subwindow.setHeight("200px");
+
+ // Configure the windws layout; by default a VerticalLayout
+ VerticalLayout layout = (VerticalLayout) subwindow.getLayout();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+ // make it fill the whole window
+ layout.setSizeFull();
+
+ // Add some content; a label and a close-button
+ Label message = new Label("This is a positioned window");
+ subwindow.addComponent(message);
+
+ Button close = new Button("Close", new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ // close the window by removing it from the main window
+ getApplication().getMainWindow().removeWindow(subwindow);
+ }
+ });
+ // The components added to the window are actually added to the window's
+ // layout; you can use either. Alignments are set using the layout
+ layout.addComponent(close);
+ layout.setComponentAlignment(close, "right bottom");
+
+ // Add buttons for opening the subwindow
+ Button fifty = new Button("Open window at position 50x50",
+ new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ if (subwindow.getParent() == null) {
+ // Open the subwindow by adding it to the main
+ // window
+ getApplication().getMainWindow().addWindow(
+ subwindow);
+ }
+
+ // Set window position
+ subwindow.setPositionX(50);
+ subwindow.setPositionY(50);
+ }
+ });
+ addComponent(fifty);
+ Button onefifty = new Button("Open window at position 150x200",
+ new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ if (subwindow.getParent() == null) {
+ // Open the subwindow by adding it to the main
+ // window
+ getApplication().getMainWindow().addWindow(
+ subwindow);
+ }
+
+ // Set window position
+ subwindow.setPositionX(150);
+ subwindow.setPositionY(200);
+ }
+ });
+ addComponent(onefifty);
+ Button center = new Button("Open centered window",
+ new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ if (subwindow.getParent() == null) {
+ // Open the subwindow by adding it to the main
+ // window
+ getApplication().getMainWindow().addWindow(
+ subwindow);
+ }
+
+ // Center the window
+ subwindow.center();
+ }
+ });
+ addComponent(center);
+
+ }
+
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/features/windows/SubwindowSized.java b/src/com/vaadin/demo/sampler/features/windows/SubwindowSized.java new file mode 100644 index 0000000000..ad03155d30 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/SubwindowSized.java @@ -0,0 +1,37 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.demo.sampler.APIResource;
+import com.vaadin.demo.sampler.Feature;
+import com.vaadin.demo.sampler.FeatureSet;
+import com.vaadin.demo.sampler.NamedExternalResource;
+import com.vaadin.ui.Window;
+
+public class SubwindowSized extends Feature {
+
+ @Override
+ public String getName() {
+ return "Window, explicit size";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The size of a window can be specified - here the width is set"
+ + " in pixels, and the height in percent.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(Window.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { SubwindowAutoSized.class, FeatureSet.Windows.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/demo/sampler/features/windows/SubwindowSizedExample.java b/src/com/vaadin/demo/sampler/features/windows/SubwindowSizedExample.java new file mode 100644 index 0000000000..93703773e2 --- /dev/null +++ b/src/com/vaadin/demo/sampler/features/windows/SubwindowSizedExample.java @@ -0,0 +1,64 @@ +package com.vaadin.demo.sampler.features.windows;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class SubwindowSizedExample extends VerticalLayout {
+
+ Window subwindow;
+
+ public SubwindowSizedExample() {
+
+ // Create the window
+ subwindow = new Window("A sized subwindow");
+ subwindow.setWidth("500px");
+ subwindow.setHeight("80%");
+
+ // Configure the windws layout; by default a VerticalLayout
+ VerticalLayout layout = (VerticalLayout) subwindow.getLayout();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+ // make it fill the whole window
+ layout.setSizeFull();
+
+ // Add some content; a label and a close-button
+ Label message = new Label("This is a sized window");
+ subwindow.addComponent(message);
+
+ Button close = new Button("Close", new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ // close the window by removing it from the main window
+ getApplication().getMainWindow().removeWindow(subwindow);
+ }
+ });
+ // The components added to the window are actually added to the window's
+ // layout; you can use either. Alignments are set using the layout
+ layout.addComponent(close);
+ layout.setComponentAlignment(close, "right bottom");
+
+ // Add a button for opening the subwindow
+ Button open = new Button("Open sized window",
+ new Button.ClickListener() {
+ // inline click-listener
+ public void buttonClick(ClickEvent event) {
+ if (subwindow.getParent() != null) {
+ // window is already showing
+ getWindow().showNotification(
+ "Window is already open");
+ } else {
+ // Open the subwindow by adding it to the main
+ // window
+ getApplication().getMainWindow().addWindow(
+ subwindow);
+ }
+ }
+ });
+ addComponent(open);
+
+ }
+
+}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/folder.gif b/src/com/vaadin/demo/sampler/folder.gif Binary files differnew file mode 100644 index 0000000000..8dc04c4956 --- /dev/null +++ b/src/com/vaadin/demo/sampler/folder.gif diff --git a/src/com/vaadin/demo/sampler/gwt/SamplerWidgetSet.gwt.xml b/src/com/vaadin/demo/sampler/gwt/SamplerWidgetSet.gwt.xml new file mode 100644 index 0000000000..dc6d1b206c --- /dev/null +++ b/src/com/vaadin/demo/sampler/gwt/SamplerWidgetSet.gwt.xml @@ -0,0 +1,15 @@ +<module> + <!-- Inherit the DefaultWidgetSet --> + <inherits name="com.vaadin.terminal.gwt.DefaultWidgetSet" /> + + <!-- Tracker --> + <script src="http://www.google-analytics.com/ga.js" /> + + <!-- Prettify --> + <stylesheet src="prettify/prettify.css"/> + <script src="prettify/prettify.js" /> + + <!-- Entry point --> + <entry-point class="com.vaadin.demo.sampler.gwt.client.SamplerWidgetSet"/> + +</module> diff --git a/src/com/vaadin/demo/sampler/gwt/client/SamplerWidgetSet.java b/src/com/vaadin/demo/sampler/gwt/client/SamplerWidgetSet.java new file mode 100644 index 0000000000..2738b21990 --- /dev/null +++ b/src/com/vaadin/demo/sampler/gwt/client/SamplerWidgetSet.java @@ -0,0 +1,40 @@ +package com.vaadin.demo.sampler.gwt.client; + +import com.vaadin.demo.sampler.gwt.client.ui.IActiveLink; +import com.vaadin.demo.sampler.gwt.client.ui.ICodeLabel; +import com.vaadin.demo.sampler.gwt.client.ui.IGoogleAnalytics; +import com.vaadin.terminal.gwt.client.DefaultWidgetSet; +import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.UIDL; + +public class SamplerWidgetSet extends DefaultWidgetSet { + + @Override + public Paintable createWidget(UIDL uidl) { + final Class classType = resolveWidgetType(uidl); + if (IGoogleAnalytics.class == classType) { + return new IGoogleAnalytics(); + } else if (ICodeLabel.class == classType) { + return new ICodeLabel(); + } else if (IActiveLink.class == classType) { + return new IActiveLink(); + } else { + return super.createWidget(uidl); + } + } + + @Override + protected Class resolveWidgetType(UIDL uidl) { + final String tag = uidl.getTag(); + if ("googleanalytics".equals(tag)) { + return IGoogleAnalytics.class; + } else if ("codelabel".equals(tag)) { + return ICodeLabel.class; + } else if ("activelink".equals(tag)) { + return IActiveLink.class; + } else { + return super.resolveWidgetType(uidl); + } + } + +} diff --git a/src/com/vaadin/demo/sampler/gwt/client/ui/IActiveLink.java b/src/com/vaadin/demo/sampler/gwt/client/ui/IActiveLink.java new file mode 100644 index 0000000000..d539ef5611 --- /dev/null +++ b/src/com/vaadin/demo/sampler/gwt/client/ui/IActiveLink.java @@ -0,0 +1,89 @@ +package com.vaadin.demo.sampler.gwt.client.ui; + +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.ui.MouseListener; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.ui.ILink; + +public class IActiveLink extends ILink { + + String id; + ApplicationConnection client; + boolean listening = false; + + public IActiveLink() { + addMouseListener(new MouseListener() { + public void onMouseDown(Widget sender, int x, int y) { + } + + public void onMouseEnter(Widget sender) { + } + + public void onMouseLeave(Widget sender) { + } + + public void onMouseMove(Widget sender, int x, int y) { + } + + public void onMouseUp(Widget sender, int x, int y) { + Event e = DOM.eventGetCurrentEvent(); + if (e.getButton() == Event.BUTTON_MIDDLE) { + sendVariables(); + } + } + }); + } + + /** + * Sends variables, returns true if default handler should be called (i.e if + * server is listening and the link was claimed to be opened by the client) + * + * @return + */ + private boolean sendVariables() { + Event e = DOM.eventGetCurrentEvent(); + boolean opened = (e.getCtrlKey() || e.getAltKey() || e.getShiftKey() + || e.getMetaKey() || e.getButton() == Event.BUTTON_MIDDLE); + + // Works as ILink if no-one is listening + if (listening) { + if (opened) { + // ILink will open, notify server + client.updateVariable(id, "opened", true, false); + } else { + e.preventDefault(); + } + client.updateVariable(id, "activated", true, true); + } + return !listening || opened; + } + + @Override + public void onClick(Widget sender) { + + if (sendVariables()) { + // run default if not listening, or we claimed link was opened + super.onClick(sender); + } + } + + @Override + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + // Ensure correct implementation, + // but don't let container manage caption etc. + if (client.updateComponent(this, uidl, false)) { + return; + } + + // Save details + this.client = client; + id = uidl.getId(); + listening = uidl.hasVariable("activated"); + + super.updateFromUIDL(uidl, client); + } + +} diff --git a/src/com/vaadin/demo/sampler/gwt/client/ui/ICodeLabel.java b/src/com/vaadin/demo/sampler/gwt/client/ui/ICodeLabel.java new file mode 100644 index 0000000000..a97d74e067 --- /dev/null +++ b/src/com/vaadin/demo/sampler/gwt/client/ui/ICodeLabel.java @@ -0,0 +1,29 @@ +package com.vaadin.demo.sampler.gwt.client.ui; + +import com.google.gwt.dom.client.Element; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.ui.ILabel; + +public class ICodeLabel extends ILabel { + + public ICodeLabel() { + super(); + } + + @Override + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + super.updateFromUIDL(uidl, client); + Element pre = getElement().getFirstChildElement(); + if (null != pre) { + pre.setClassName("prettyprint"); + prettyPrint(); + } + } + + private native void prettyPrint() + /*-{ + $wnd.prettyPrint(); + }-*/; + +} diff --git a/src/com/vaadin/demo/sampler/gwt/client/ui/IGoogleAnalytics.java b/src/com/vaadin/demo/sampler/gwt/client/ui/IGoogleAnalytics.java new file mode 100644 index 0000000000..13e15fb32c --- /dev/null +++ b/src/com/vaadin/demo/sampler/gwt/client/ui/IGoogleAnalytics.java @@ -0,0 +1,70 @@ +package com.vaadin.demo.sampler.gwt.client.ui; + +import com.google.gwt.dom.client.Document; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.BrowserInfo; +import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.UIDL; + +public class IGoogleAnalytics extends Widget implements Paintable { + + public IGoogleAnalytics() { + setElement(Document.get().createDivElement()); + if (BrowserInfo.get().isIE6()) { + getElement().getStyle().setProperty("overflow", "hidden"); + getElement().getStyle().setProperty("height", "0"); + getElement().getStyle().setProperty("width", "0"); + } + } + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + if (isLocalHostUrl()) { + // Do not track localhost page views + return; + } + String trackerId = uidl.getStringAttribute("trackerid"); + String pageId = uidl.getStringAttribute("pageid"); + String domainName = uidl.getStringAttribute("domain"); + + String res = trackPageview(trackerId, pageId, domainName); + if (null != res) { + ApplicationConnection.getConsole().log( + "WebAnalytics.trackPageview(" + trackerId + "," + pageId + + "," + domainName + ") FAILED: " + res); + } else { + ApplicationConnection.getConsole().log( + "WebAnalytics.trackPageview(" + trackerId + "," + pageId + + "," + domainName + ") SUCCESS."); + } + } + + private native boolean isLocalHostUrl() + /*-{ + var location = $wnd.location; + var re = /^http:\/\/(localhost|127.0.0.1)/; + return re.test(location); + }-*/; + + private native String trackPageview(String trackerId, String pageId, + String domainName) + /*-{ + if (!$wnd._gat) { + return "Tracker not found (running offline?)"; + } + try { + var pageTracker = $wnd._gat._getTracker(trackerId); + if (domainName) { + pageTracker._setDomainName(domainName); + } + if (pageId) { + pageTracker._trackPageview(pageId); + } else { + pageTracker._trackPageview(); + } + return null; + } catch(err) { + return ""+err; + } + }-*/; +} diff --git a/src/com/vaadin/demo/sampler/gwt/public/prettify/README.txt b/src/com/vaadin/demo/sampler/gwt/public/prettify/README.txt new file mode 100644 index 0000000000..e39bfb78fc --- /dev/null +++ b/src/com/vaadin/demo/sampler/gwt/public/prettify/README.txt @@ -0,0 +1,3 @@ +google-code-prettify +http://code.google.com/p/google-code-prettify/ +Apache License 2.0 diff --git a/src/com/vaadin/demo/sampler/gwt/public/prettify/prettify.css b/src/com/vaadin/demo/sampler/gwt/public/prettify/prettify.css new file mode 100644 index 0000000000..647fc61472 --- /dev/null +++ b/src/com/vaadin/demo/sampler/gwt/public/prettify/prettify.css @@ -0,0 +1 @@ +.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun{color:#660}.pln{color:#000}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec{color:#606}@media print{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun{color:#440}.pln{color:#000}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}
\ No newline at end of file diff --git a/src/com/vaadin/demo/sampler/gwt/public/prettify/prettify.js b/src/com/vaadin/demo/sampler/gwt/public/prettify/prettify.js new file mode 100644 index 0000000000..f8f4f7f461 --- /dev/null +++ b/src/com/vaadin/demo/sampler/gwt/public/prettify/prettify.js @@ -0,0 +1,25 @@ +function _pr_isIE6(){var F=navigator&&navigator.userAgent&&/\bMSIE 6\./.test(navigator.userAgent);_pr_isIE6=function(){return F};return F}var aa="break continue do else for if return while ",ba="auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile ",ca="catch class delete false import new operator private protected public this throw true try ",da="alignof align_union asm axiom bool concept concept_map const_cast constexpr decltype dynamic_cast explicit export friend inline late_check mutable namespace nullptr reinterpret_cast static_assert static_cast template typeid typename typeof using virtual wchar_t where ", +ea="boolean byte extends final finally implements import instanceof null native package strictfp super synchronized throws transient ",fa="as base by checked decimal delegate descending event fixed foreach from group implicit in interface internal into is lock object out override orderby params readonly ref sbyte sealed stackalloc string select uint ulong unchecked unsafe ushort var ",ga="debugger eval export function get null set undefined var with Infinity NaN ",ha="caller delete die do dump elsif eval exit foreach for goto if import last local my next no our print package redo require sub undef unless until use wantarray while BEGIN END ", +ia="and as assert class def del elif except exec finally from global import in is lambda nonlocal not or pass print raise try with yield False True None ",ja="alias and begin case class def defined elsif end ensure false in module next nil not or redo rescue retry self super then true undef unless until when yield BEGIN END ",ka="case done elif esac eval fi function in local set then until ",la="a",ma="z",na="A",oa="Z",pa="!",qa="!=",ra="!==",s="#",sa="%",Ha="%=",v="&",Ia="&&",Ja="&&=",Ka="&=",La= +"(",Ma="*",Na="*=",Oa="+=",Pa=",",Qa="-=",Ra="->",w="/",Sa="/=",Ta=":",Ua="::",y=";",z="<",Va="<<",Wa="<<=",Xa="<=",Ya="=",Za="==",$a="===",A=">",ab=">=",bb=">>",cb=">>=",db=">>>",eb=">>>=",fb="?",C="@",gb="[",hb="^",ib="^=",jb="^^",kb="^^=",lb="{",mb="|",nb="|=",ob="||",pb="||=",qb="~",rb="break",sb="case",tb="continue",ub="delete",vb="do",wb="else",xb="finally",yb="instanceof",zb="return",Ab="throw",Bb="try",Cb="typeof",Db="(?:(?:(?:^|[^0-9.])\\.{1,3})|(?:(?:^|[^\\+])\\+)|(?:(?:^|[^\\-])-)",Eb= +"|\\b",Fb="\\$1",Gb="|^)\\s*$",Hb="&",Ib="<",Jb=">",Kb=""",Lb="&#",Mb="x",Nb="'",G='"',Ob=" ",Pb="XMP",Qb="</",Rb='="',H="PRE",Sb='<!DOCTYPE foo PUBLIC "foo bar">\n<foo />',I="",Tb="\t",Ub="\n",Vb="nocode",Wb=' $1="$2$3$4"',J="pln",O="com",Xb="dec",P="src",Q="tag",R="atv",S="pun",Yb="<>/=",X="atn",Zb=" \t\r\n",Y="str",$b="'\"",ac="'\"`",bc="\"'",cc=" \r\n",Z="lit",dc="123456789",ec=".",fc="kwd",gc="typ",$="</span>",hc='<span class="',ic='">',jc="$1 ",kc="<br />",lc="console",mc= +"cannot override language handler %s",nc="default-code",oc="default-markup",pc="html",qc="htm",rc="xhtml",sc="xml",tc="xsl",uc="c",vc="cc",wc="cpp",xc="cs",yc="cxx",zc="cyc",Ac="java",Bc="bsh",Cc="csh",Dc="sh",Ec="cv",Fc="py",Gc="perl",Hc="pl",Ic="pm",Jc="rb",Kc="js",Lc="pre",Mc="code",Nc="xmp",Oc="prettyprint",Pc="class",Qc="br",Rc="\r\n";(function(){function F(b){b=b.split(/ /g);var a={};for(var c=b.length;--c>=0;){var d=b[c];if(d)a[d]=null}return a}var K=aa,Sc=K+ba,T=Sc+ca,ta=T+da,ua=T+ea,Tc=ua+ +fa,va=T+ga,wa=ha,xa=K+ia,ya=K+ja,za=K+ka,Uc=ta+Tc+va+wa+xa+ya+za;function Vc(b){return b>=la&&b<=ma||b>=na&&b<=oa}function D(b,a,c,d){b.unshift(c,d||0);try{a.splice.apply(a,b)}finally{b.splice(0,2)}}var Wc=(function(){var b=[pa,qa,ra,s,sa,Ha,v,Ia,Ja,Ka,La,Ma,Na,Oa,Pa,Qa,Ra,w,Sa,Ta,Ua,y,z,Va,Wa,Xa,Ya,Za,$a,A,ab,bb,cb,db,eb,fb,C,gb,hb,ib,jb,kb,lb,mb,nb,ob,pb,qb,rb,sb,tb,ub,vb,wb,xb,yb,zb,Ab,Bb,Cb],a=Db;for(var c=0;c<b.length;++c){var d=b[c];a+=Vc(d.charAt(0))?Eb+d:mb+d.replace(/([^=<>:&])/g,Fb)}a+= +Gb;return new RegExp(a)})(),Aa=/&/g,Ba=/</g,Ca=/>/g,Xc=/\"/g;function Yc(b){return b.replace(Aa,Hb).replace(Ba,Ib).replace(Ca,Jb).replace(Xc,Kb)}function U(b){return b.replace(Aa,Hb).replace(Ba,Ib).replace(Ca,Jb)}var Zc=/</g,$c=/>/g,ad=/'/g,bd=/"/g,cd=/&/g,dd=/ /g;function ed(b){var a=b.indexOf(v);if(a<0)return b;for(--a;(a=b.indexOf(Lb,a+1))>=0;){var c=b.indexOf(y,a);if(c>=0){var d=b.substring(a+3,c),g=10;if(d&&d.charAt(0)===Mb){d=d.substring(1);g=16}var e=parseInt(d,g); +if(!isNaN(e))b=b.substring(0,a)+String.fromCharCode(e)+b.substring(c+1)}}return b.replace(Zc,z).replace($c,A).replace(ad,Nb).replace(bd,G).replace(cd,v).replace(dd,Ob)}function Da(b){return Pb===b.tagName}function L(b,a){switch(b.nodeType){case 1:var c=b.tagName.toLowerCase();a.push(z,c);for(var d=0;d<b.attributes.length;++d){var g=b.attributes[d];if(!g.specified)continue;a.push(Ob);L(g,a)}a.push(A);for(var e=b.firstChild;e;e=e.nextSibling)L(e,a);if(b.firstChild||!/^(?:br|link|img)$/.test(c))a.push(Qb, +c,A);break;case 2:a.push(b.name.toLowerCase(),Rb,Yc(b.value),G);break;case 3:case 4:a.push(U(b.nodeValue));break}}var V=null;function fd(b){if(null===V){var a=document.createElement(H);a.appendChild(document.createTextNode(Sb));V=!/</.test(a.innerHTML)}if(V){var c=b.innerHTML;if(Da(b))c=U(c);return c}var d=[];for(var g=b.firstChild;g;g=g.nextSibling)L(g,d);return d.join(I)}function gd(b){var a=0;return function(c){var d=null,g=0;for(var e=0,h=c.length;e<h;++e){var f=c.charAt(e);switch(f){case Tb:if(!d)d= +[];d.push(c.substring(g,e));var i=b-a%b;a+=i;for(;i>=0;i-=" ".length)d.push(" ".substring(0,i));g=e+1;break;case Ub:a=0;break;default:++a}}if(!d)return c;d.push(c.substring(g));return d.join(I)}}var hd=/(?:[^<]+|<!--[\s\S]*?--\>|<!\[CDATA\[([\s\S]*?)\]\]>|<\/?[a-zA-Z][^>]*>|<)/g,id=/^<!--/,jd=/^<\[CDATA\[/,kd=/^<br\b/i,Ea=/^<(\/?)([a-zA-Z]+)/;function ld(b){var a=b.match(hd),c=[],d=0,g=[];if(a)for(var e=0,h=a.length;e<h;++e){var f=a[e];if(f.length>1&&f.charAt(0)===z){if(id.test(f))continue; +if(jd.test(f)){c.push(f.substring(9,f.length-3));d+=f.length-12}else if(kd.test(f)){c.push(Ub);++d}else if(f.indexOf(Vb)>=0&&!!f.replace(/\s(\w+)\s*=\s*(?:\"([^\"]*)\"|'([^\']*)'|(\S+))/g,Wb).match(/[cC][lL][aA][sS][sS]=\"[^\"]*\bnocode\b/)){var i=f.match(Ea)[2],j=1;end_tag_loop:for(var m=e+1;m<h;++m){var o=a[m].match(Ea);if(o&&o[2]===i)if(o[1]===w){if(--j===0)break end_tag_loop}else++j}if(m<h){g.push(d,a.slice(e,m+1).join(I));e=m}else g.push(d,f)}else g.push(d,f)}else{var k=ed(f);c.push(k);d+=k.length}}return{source:c.join(I), +tags:g}}function E(b,a){var c={};(function(){var e=b.concat(a);for(var h=e.length;--h>=0;){var f=e[h],i=f[3];if(i)for(var j=i.length;--j>=0;)c[i.charAt(j)]=f}})();var d=a.length,g=/\S/;return function(e,h){h=h||0;var f=[h,J],i=I,j=0,m=e;while(m.length){var o,k=null,p,l=c[m.charAt(0)];if(l){p=m.match(l[1]);k=p[0];o=l[0]}else{for(var n=0;n<d;++n){l=a[n];var q=l[2];if(q&&!q.test(i))continue;p=m.match(l[1]);if(p){k=p[0];o=l[0];break}}if(!k){o=J;k=m.substring(0,1)}}f.push(h+j,o);j+=k.length;m=m.substring(k.length); +if(o!==O&&g.test(k))i=k}return f}}var md=E([],[[J,/^[^<]+/,null],[Xb,/^<!\w[^>]*(?:>|$)/,null],[O,/^<!--[\s\S]*?(?:--\>|$)/,null],[P,/^<\?[\s\S]*?(?:\?>|$)/,null],[P,/^<%[\s\S]*?(?:%>|$)/,null],[P,/^<(script|style|xmp)\b[^>]*>[\s\S]*?<\/\1\b[^>]*>/i,null],[Q,/^<\/?\w[^<>]*>/,null]]);function nd(b){var a=md(b);for(var c=0;c<a.length;c+=2)if(a[c+1]===P){var d,g;d=a[c];g=c+2<a.length?a[c+2]:b.length;var e=b.substring(d,g),h=e.match(/^(<[^>]*>)([\s\S]*)(<\/[^>]*>)$/);if(h)a.splice(c,2,d,Q,d+h[1].length, +P,d+h[1].length+(h[2]||I).length,Q)}return a}var od=E([[R,/^\'[^\']*(?:\'|$)/,null,Nb],[R,/^\"[^\"]*(?:\"|$)/,null,G],[S,/^[<>\/=]+/,null,Yb]],[[Q,/^[\w:\-]+/,/^</],[R,/^[\w\-]+/,/^=/],[X,/^[\w:\-]+/,null],[J,/^\s+/,null,Zb]]);function pd(b,a){for(var c=0;c<a.length;c+=2){var d=a[c+1];if(d===Q){var g,e;g=a[c];e=c+2<a.length?a[c+2]:b.length;var h=b.substring(g,e),f=od(h,g);D(f,a,c,2);c+=f.length-2}}return a}function u(b){var a=[],c=[];if(b.tripleQuotedStrings)a.push([Y,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/, +null,$b]);else if(b.multiLineStrings)a.push([Y,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,ac]);else a.push([Y,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,bc]);c.push([J,/^(?:[^\'\"\`\/\#]+)/,null,cc]);if(b.hashComments)a.push([O,/^#[^\r\n]*/,null,s]);if(b.cStyleComments){c.push([O,/^\/\/[^\r\n]*/,null]);c.push([O,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(b.regexLiterals)c.push([Y,/^\/(?=[^\/*])(?:[^\/\x5B\x5C]|\x5C[\s\S]|\x5B(?:[^\x5C\x5D]|\x5C[\s\S])*(?:\x5D|$))+(?:\/|$)/, +Wc]);var d=F(b.keywords);b=null;var g=E(a,c),e=E([],[[J,/^\s+/,null,cc],[J,/^[a-z_$@][a-z_$@0-9]*/i,null],[Z,/^0x[a-f0-9]+[a-z]/i,null],[Z,/^(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d+)(?:e[+\-]?\d+)?[a-z]*/i,null,dc],[S,/^[^\s\w\.$@]+/,null]]);function h(f,i){for(var j=0;j<i.length;j+=2){var m=i[j+1];if(m===J){var o,k,p,l;o=i[j];k=j+2<i.length?i[j+2]:f.length;p=f.substring(o,k);l=e(p,o);for(var n=0,q=l.length;n<q;n+=2){var r=l[n+1];if(r===J){var B=l[n],M=n+2<q?l[n+2]:p.length,x=f.substring(B,M);if(x===ec)l[n+ +1]=S;else if(x in d)l[n+1]=fc;else if(/^@?[A-Z][A-Z$]*[a-z][A-Za-z$]*$/.test(x))l[n+1]=x.charAt(0)===C?Z:gc}}D(l,i,j,2);j+=l.length-2}}return i}return function(f){var i=g(f);i=h(f,i);return i}}var W=u({keywords:Uc,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function qd(b,a){for(var c=0;c<a.length;c+=2){var d=a[c+1];if(d===P){var g,e;g=a[c];e=c+2<a.length?a[c+2]:b.length;var h=W(b.substring(g,e));for(var f=0,i=h.length;f<i;f+=2)h[f]+=g;D(h,a,c,2);c+=h.length-2}}return a} +function rd(b,a){var c=false;for(var d=0;d<a.length;d+=2){var g=a[d+1],e,h;if(g===X){e=a[d];h=d+2<a.length?a[d+2]:b.length;c=/^on|^style$/i.test(b.substring(e,h))}else if(g===R){if(c){e=a[d];h=d+2<a.length?a[d+2]:b.length;var f=b.substring(e,h),i=f.length,j=i>=2&&/^[\"\']/.test(f)&&f.charAt(0)===f.charAt(i-1),m,o,k;if(j){o=e+1;k=h-1;m=f}else{o=e+1;k=h-1;m=f.substring(1,f.length-1)}var p=W(m);for(var l=0,n=p.length;l<n;l+=2)p[l]+=o;if(j){p.push(k,R);D(p,a,d+2,0)}else D(p,a,d,2)}c=false}}return a}function sd(b){var a= +nd(b);a=pd(b,a);a=qd(b,a);a=rd(b,a);return a}function td(b,a,c){var d=[],g=0,e=null,h=null,f=0,i=0,j=gd(8),m=/([\r\n ]) /g,o=/(^| ) /gm,k=/\r\n?|\n/g,p=/[ \r\n]$/,l=true;function n(r){if(r>g){if(e&&e!==h){d.push($);e=null}if(!e&&h){e=h;d.push(hc,e,ic)}var B=U(j(b.substring(g,r))).replace(l?o:m,jc);l=p.test(B);d.push(B.replace(k,kc));g=r}}while(true){var q;q=f<a.length?(i<c.length?a[f]<=c[i]:true):false;if(q){n(a[f]);if(e){d.push($);e=null}d.push(a[f+1]);f+=2}else if(i<c.length){n(c[i]);h=c[i+1];i+= +2}else break}n(b.length);if(e)d.push($);return d.join(I)}var N={};function t(b,a){for(var c=a.length;--c>=0;){var d=a[c];if(!N.hasOwnProperty(d))N[d]=b;else if(lc in window)console.log(mc,d)}}t(W,[nc]);t(sd,[oc,pc,qc,rc,sc,tc]);t(u({keywords:ta,hashComments:true,cStyleComments:true}),[uc,vc,wc,xc,yc,zc]);t(u({keywords:ua,cStyleComments:true}),[Ac]);t(u({keywords:za,hashComments:true,multiLineStrings:true}),[Bc,Cc,Dc]);t(u({keywords:xa,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}), +[Ec,Fc]);t(u({keywords:wa,hashComments:true,multiLineStrings:true,regexLiterals:true}),[Gc,Hc,Ic]);t(u({keywords:ya,hashComments:true,multiLineStrings:true,regexLiterals:true}),[Jc]);t(u({keywords:va,cStyleComments:true,regexLiterals:true}),[Kc]);function Fa(b,a){try{var c=ld(b),d=c.source,g=c.tags;if(!N.hasOwnProperty(a))a=/^\s*</.test(d)?oc:nc;var e=N[a].call({},d);return td(d,g,e)}catch(h){if(lc in window){console.log(h);console.trace()}return b}}function ud(b){var a=_pr_isIE6(),c=[document.getElementsByTagName(Lc), +document.getElementsByTagName(Mc),document.getElementsByTagName(Nc)],d=[];for(var g=0;g<c.length;++g)for(var e=0;e<c[g].length;++e)d.push(c[g][e]);c=null;var h=0;function f(){var i=(new Date).getTime()+250;for(;h<d.length&&(new Date).getTime()<i;h++){var j=d[h];if(j.className&&j.className.indexOf(Oc)>=0){var m=j.className.match(/\blang-(\w+)\b/);if(m)m=m[1];var o=false;for(var k=j.parentNode;k;k=k.parentNode)if((k.tagName===Lc||k.tagName===Mc||k.tagName===Nc)&&k.className&&k.className.indexOf(Oc)>= +0){o=true;break}if(!o){var p=fd(j);p=p.replace(/(?:\r\n?|\n)$/,I);var l=Fa(p,m);if(!Da(j))j.innerHTML=l;else{var n=document.createElement(H);for(var q=0;q<j.attributes.length;++q){var r=j.attributes[q];if(r.specified){var B=r.name.toLowerCase();if(B===Pc)n.className=r.value;else n.setAttribute(r.name,r.value)}}n.innerHTML=l;j.parentNode.replaceChild(n,j);j=n}if(a&&j.tagName===H){var M=j.getElementsByTagName(Qc);for(var x=M.length;--x>=0;){var Ga=M[x];Ga.parentNode.replaceChild(document.createTextNode(Rc), +Ga)}}}}}if(h<d.length)setTimeout(f,250);else if(b)b()}f()}window.PR_normalizedHtml=L;window.prettyPrintOne=Fa;window.prettyPrint=ud;window.PR={createSimpleLexer:E,registerLangHandler:t,sourceDecorator:u,PR_ATTRIB_NAME:X,PR_ATTRIB_VALUE:R,PR_COMMENT:O,PR_DECLARATION:Xb,PR_KEYWORD:fc,PR_LITERAL:Z,PR_NOCODE:Vb,PR_PLAIN:J,PR_PUNCTUATION:S,PR_SOURCE:P,PR_STRING:Y,PR_TAG:Q,PR_TYPE:gc}})(); |