/* * Smart GWT (GWT for SmartClient) * Copyright 2008 and beyond, Isomorphic Software, Inc. * * Smart GWT is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3 * as published by the Free Software Foundation. Smart GWT is also * available under typical commercial license terms - see * http://smartclient.com/license * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ import java.util.Map; import java.util.HashMap; import com.smartgwt.client.widgets.Img; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.grid.*; import com.smartgwt.client.widgets.notify.*; import com.smartgwt.client.widgets.events.*; import com.smartgwt.client.widgets.layout.Layout; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.form.fields.*; import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.types.EdgeName; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.SortDirection; import com.smartgwt.client.types.MultiMessageMode; import com.smartgwt.client.types.NotifyTransition; import com.smartgwt.client.types.ListGridFieldType; import com.google.gwt.core.client.EntryPoint; public class NotificationSample implements EntryPoint { // configureDefaultSettings() can customize NotifySettings for all NotifyTypes up front private void configureDefaults() { NotifySettings changedDefaults = new NotifySettings(); changedDefaults.setMultiMessageMode(MultiMessageMode.REPLACE); changedDefaults.setAutoFitMaxWidth(250); changedDefaults.setSlideSpeed(250); Notify.configureDefaultSettings(changedDefaults); } public void onModuleLoad() { HeaderItem titleItem = new HeaderItem("header", "Configure Notification"); final TextItem textItem = new TextItem("text", "Message"); textItem.setDefaultValue("Download complete"); textItem.setHint("Type your Message"); textItem.setWrapHintText(false); Map locations = new HashMap(); locations.put(EdgeName.L, "left edge"); locations.put(EdgeName.R, "right edge"); locations.put(EdgeName.T, "top edge"); locations.put(EdgeName.B, "bottom edge"); locations.put(EdgeName.TL, "top-left corner"); locations.put(EdgeName.TR, "top-right corner"); locations.put(EdgeName.BL, "bottom-left corner"); locations.put(EdgeName.BR, "bottom-right corner"); locations.put(EdgeName.C, "center"); final ComboBoxItem locationPicker = new ComboBoxItem("location", "Screen Location"); locationPicker.setDefaultValue("T"); locationPicker.setValueMap(locations); final ComboBoxItem showMethodPicker = new ComboBoxItem("showAnimation", "Show Animation"); showMethodPicker.setValueMap("slide", "fade", "instant"); showMethodPicker.setDefaultValue("slide"); showMethodPicker.setWrapTitle(false); final ComboBoxItem hideMethodPicker = new ComboBoxItem("hideAnimation", "Hide Animation"); hideMethodPicker.setValueMap("slide", "fade", "instant"); hideMethodPicker.setDefaultValue("fade"); hideMethodPicker.setWrapTitle(false); final ListGridField messagePriorityField = new ListGridField("messagePriority"); messagePriorityField.setType(ListGridFieldType.INTEGER); final ComboBoxItem priorityPicker = new ComboBoxItem("messagePriority", "Priority"); priorityPicker.setValueMap(new HashMap() {{ put(Notify.MESSAGE, "message"); put(Notify.WARN, "warn"); put(Notify.ERROR, "error"); }}); priorityPicker.setPickListProperties(new ListGrid() {{ setSortDirection(SortDirection.DESCENDING); setSortField("messagePriority"); setFields(messagePriorityField); }}); priorityPicker.setDefaultValue(Notify.MESSAGE); priorityPicker.setWrapTitle(false); final CheckboxItem dismiss = new CheckboxItem("dismiss", "Add button to immediately dismiss"); final CheckboxItem window = new CheckboxItem("window", "Add link to launch a window"); DynamicForm configForm = new DynamicForm(); configForm.setItems(titleItem, textItem, locationPicker, showMethodPicker, hideMethodPicker, priorityPicker, dismiss, window); final NotifyActionCallback launch = this; Button sendButton = new Button("Send"); sendButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String contents = (String)textItem.getValue(); if (contents == null || contents.isEmpty()) { contents = "You left the message text empty!"; } NotifySettings settings = new NotifySettings(); settings.setCanDismiss((Boolean)dismiss.getValue()); settings.setPosition((EdgeName)locationPicker.getValue()); settings.setAppearMethod (getNotifyTransition(showMethodPicker)); settings.setDisappearMethod(getNotifyTransition(hideMethodPicker)); settings.setMessagePriority((Integer)priorityPicker.getValue()); NotifyAction[] actions = null; if (Boolean.TRUE.equals(window.getValue())) { NotifyAction action = new NotifyAction(); action.setTitle("Launch..."); action.setActionCallback(launch); actions = new NotifyAction[] {action}; } Notify.addMessage(contents, actions, null, settings); } }); configureDefaults(); VLayout layout = new VLayout(); layout.addMembers(configForm, sendButton); layout.draw(); } private NotifyTransition getNotifyTransition(ComboBoxItem item) { String value = (String)item.getValue(); return NotifyTransition.valueOf(value.toUpperCase()); } Window window; @Override public void execute() { // if window already exists, just show it; no-ops if already being shown if (window == null) { window = new Window(); window.setIsModal(true); window.setAutoSize(true); window.setAutoCenter(true); window.setShowModalMask(true); window.setCanDragReposition(false); window.setTitle("Notification Action"); window.setShowMinimizeButton(false); Layout body = new Layout(); body.setDefaultLayoutAlign(Alignment.CENTER); body.setLayoutLeftMargin(5); body.setLayoutRightMargin(5); body.setLayoutBottomMargin(10); window.setAutoChildProperties("body", body); Label label = new Label("In your application, this window might contain a wizard."); label.setWidth("100%"); label.setHeight(40); label.setAlign(Alignment.CENTER); label.setWrap(false); window.addItem(label); Img image = new Img("other/wizard.png", 200, 250); window.addItem(image); } window.show(); } protected boolean shouldWrapViewPanel() { return true; } }