List of usage examples for com.google.gwt.user.client Window alert
public static void alert(String msg)
From source file:com.google.gwt.sample.mobilewebapp.presenter.task.TaskEditPresenter.java
License:Apache License
/** * Delete the current task./*from w w w. ja v a 2 s .c o m*/ */ private void doDeleteTask() { if (editTask == null) { return; } // Delete the task in the data store. final TaskProxy toDelete = this.editTask; clientFactory.getRequestFactory().taskRequest().remove().using(toDelete).fire(new Receiver<Void>() { @Override public void onFailure(ServerFailure error) { Window.alert("An error occurred on the server while deleting this task: \"." + error.getMessage() + "\"."); } @Override public void onSuccess(Void response) { onTaskDeleted(); } }); }
From source file:com.google.gwt.sample.mobilewebapp.presenter.task.TaskEditPresenter.java
License:Apache License
private void startEdit() { isEditing = true;/*from www.jav a2 s. c o m*/ getView().setEditing(true); // Lock the display until the task is loaded. getView().setLocked(true); clientFactory.getRequestFactory().taskRequest().findTask(this.taskId).fire(new Receiver<TaskProxy>() { @Override public void onConstraintViolation(Set<ConstraintViolation<?>> violations) { getView().setLocked(false); getView().getEditorDriver().setConstraintViolations(violations); } @Override public void onFailure(ServerFailure error) { getView().setLocked(false); doCancelTask(); super.onFailure(error); } @Override public void onSuccess(TaskProxy response) { // Early exit if we have already stopped. if (eventBus == null) { return; } // Task not found. if (response == null) { Window.alert("The task with id '" + taskId + "' could not be found." + " Please select a different task from the task list."); doCancelTask(); return; } // Show the task. editTask = response; getView().getEditorDriver().edit(response, clientFactory.getRequestFactory().taskRequest()); getView().setLocked(false); } }); }
From source file:com.google.gwt.sample.mobilewebapp.presenter.task.TaskReadPresenter.java
License:Apache License
public void start(EventBus newEventBus) { this.eventBus = newEventBus; // Hide the 'add' button in the shell. // TODO(rjrjr) Ick! clientFactory.getShell().setAddButtonVisible(false); // Try to load the task from local storage. if (task == null) { task = clientFactory.getTaskProxyLocalStorage().getTask(taskId); }//from w ww .java 2 s. c om if (task == null) { // Load the existing task. clientFactory.getRequestFactory().taskRequest().findTask(this.taskId).fire(new Receiver<TaskProxy>() { @Override public void onSuccess(TaskProxy response) { // Early exit if this activity has already been cancelled. if (isDead) { return; } // Task not found. if (response == null) { Window.alert("The task with id '" + taskId + "' could not be found." + " Please select a different task from the task list."); ActionEvent.fire(eventBus, ActionNames.EDITING_CANCELED); return; } // Show the task. task = response; getView().getEditorDriver().edit(response); } }); } else { // Use the task that was passed with the place. getView().getEditorDriver().edit(task); } }
From source file:com.google.gwt.sample.showcase.client.content.cell.CwCellSampler.java
License:Apache License
/** * Initialize this example./*from w w w . ja v a2 s . co m*/ */ @ShowcaseSource @Override public Widget onInitialize() { Images images = GWT.create(Images.class); // Create the table. editableCells = new ArrayList<AbstractEditableCell<?, ?>>(); contactList = new DataGrid<ContactInfo>(25, ContactInfo.KEY_PROVIDER); contactList.setMinimumTableWidth(140, Unit.EM); ContactDatabase.get().addDataDisplay(contactList); // CheckboxCell. final Category[] categories = ContactDatabase.get().queryCategories(); addColumn(new CheckboxCell(), "Checkbox", new GetValue<Boolean>() { @Override public Boolean getValue(ContactInfo contact) { // Checkbox indicates that the contact is a relative. // Index 0 = Family. return contact.getCategory() == categories[0]; } }, new FieldUpdater<ContactInfo, Boolean>() { @Override public void update(int index, ContactInfo object, Boolean value) { if (value) { // If a relative, use the Family Category. pendingChanges.add(new CategoryChange(object, categories[0])); } else { // If not a relative, use the Contacts Category. pendingChanges.add(new CategoryChange(object, categories[categories.length - 1])); } } }); // TextCell. addColumn(new TextCell(), "Text", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return contact.getFullName(); } }, null); // EditTextCell. Column<ContactInfo, String> editTextColumn = addColumn(new EditTextCell(), "EditText", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return contact.getFirstName(); } }, new FieldUpdater<ContactInfo, String>() { @Override public void update(int index, ContactInfo object, String value) { pendingChanges.add(new FirstNameChange(object, value)); } }); contactList.setColumnWidth(editTextColumn, 16.0, Unit.EM); // TextInputCell. Column<ContactInfo, String> textInputColumn = addColumn(new TextInputCell(), "TextInput", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return contact.getLastName(); } }, new FieldUpdater<ContactInfo, String>() { @Override public void update(int index, ContactInfo object, String value) { pendingChanges.add(new LastNameChange(object, value)); } }); contactList.setColumnWidth(textInputColumn, 16.0, Unit.EM); // ClickableTextCell. addColumn(new ClickableTextCell(), "ClickableText", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return "Click " + contact.getFirstName(); } }, new FieldUpdater<ContactInfo, String>() { @Override public void update(int index, ContactInfo object, String value) { Window.alert("You clicked " + object.getFullName()); } }); // ActionCell. addColumn(new ActionCell<ContactInfo>("Click Me", new ActionCell.Delegate<ContactInfo>() { @Override public void execute(ContactInfo contact) { Window.alert("You clicked " + contact.getFullName()); } }), "Action", new GetValue<ContactInfo>() { @Override public ContactInfo getValue(ContactInfo contact) { return contact; } }, null); // ButtonCell. addColumn(new ButtonCell(), "Button", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return "Click " + contact.getFirstName(); } }, new FieldUpdater<ContactInfo, String>() { @Override public void update(int index, ContactInfo object, String value) { Window.alert("You clicked " + object.getFullName()); } }); // DateCell. DateTimeFormat dateFormat = DateTimeFormat.getFormat(PredefinedFormat.DATE_MEDIUM); addColumn(new DateCell(dateFormat), "Date", new GetValue<Date>() { @Override public Date getValue(ContactInfo contact) { return contact.getBirthday(); } }, null); // DatePickerCell. addColumn(new DatePickerCell(dateFormat), "DatePicker", new GetValue<Date>() { @Override public Date getValue(ContactInfo contact) { return contact.getBirthday(); } }, new FieldUpdater<ContactInfo, Date>() { @Override public void update(int index, ContactInfo object, Date value) { pendingChanges.add(new BirthdayChange(object, value)); } }); // NumberCell. Column<ContactInfo, Number> numberColumn = addColumn(new NumberCell(), "Number", new GetValue<Number>() { @Override public Number getValue(ContactInfo contact) { return contact.getAge(); } }, null); numberColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LOCALE_END); // IconCellDecorator. addColumn(new IconCellDecorator<String>(images.contactsGroup(), new TextCell()), "Icon", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return contact.getCategory().getDisplayName(); } }, null); // ImageCell. addColumn(new ImageCell(), "Image", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return "contact.jpg"; } }, null); // SelectionCell. List<String> options = new ArrayList<String>(); for (Category category : categories) { options.add(category.getDisplayName()); } addColumn(new SelectionCell(options), "Selection", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return contact.getCategory().getDisplayName(); } }, new FieldUpdater<ContactInfo, String>() { @Override public void update(int index, ContactInfo object, String value) { for (Category category : categories) { if (category.getDisplayName().equals(value)) { pendingChanges.add(new CategoryChange(object, category)); break; } } } }); // Create the UiBinder. Binder uiBinder = GWT.create(Binder.class); Widget widget = uiBinder.createAndBindUi(this); // Add handlers to redraw or refresh the table. redrawButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { contactList.redraw(); } }); commitButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // Commit the changes. for (PendingChange<?> pendingChange : pendingChanges) { pendingChange.commit(); } pendingChanges.clear(); // Push the changes to the views. ContactDatabase.get().refreshDisplays(); } }); return widget; }
From source file:com.google.gwt.sample.showcase.client.content.lists.CwMenuBar.java
License:Apache License
/** * Initialize this example./*from ww w .j av a 2s . c o m*/ */ @ShowcaseSource @Override public Widget onInitialize() { // Create a command that will execute on menu item selection Command menuCommand = new Command() { private int curPhrase = 0; private final String[] phrases = constants.cwMenuBarPrompts(); public void execute() { Window.alert(phrases[curPhrase]); curPhrase = (curPhrase + 1) % phrases.length; } }; // Create a menu bar MenuBar menu = new MenuBar(); menu.setAutoOpen(true); menu.setWidth("500px"); menu.setAnimationEnabled(true); // Create a sub menu of recent documents MenuBar recentDocsMenu = new MenuBar(true); String[] recentDocs = constants.cwMenuBarFileRecents(); for (int i = 0; i < recentDocs.length; i++) { recentDocsMenu.addItem(recentDocs[i], menuCommand); } // Create the file menu MenuBar fileMenu = new MenuBar(true); fileMenu.setAnimationEnabled(true); menu.addItem(new MenuItem(constants.cwMenuBarFileCategory(), fileMenu)); String[] fileOptions = constants.cwMenuBarFileOptions(); for (int i = 0; i < fileOptions.length; i++) { if (i == 3) { fileMenu.addSeparator(); fileMenu.addItem(fileOptions[i], recentDocsMenu); fileMenu.addSeparator(); } else { fileMenu.addItem(fileOptions[i], menuCommand); } } // Create the edit menu MenuBar editMenu = new MenuBar(true); menu.addItem(new MenuItem(constants.cwMenuBarEditCategory(), editMenu)); String[] editOptions = constants.cwMenuBarEditOptions(); for (int i = 0; i < editOptions.length; i++) { editMenu.addItem(editOptions[i], menuCommand); } // Create the GWT menu MenuBar gwtMenu = new MenuBar(true); menu.addItem(new MenuItem("GWT", true, gwtMenu)); String[] gwtOptions = constants.cwMenuBarGWTOptions(); for (int i = 0; i < gwtOptions.length; i++) { gwtMenu.addItem(gwtOptions[i], menuCommand); } // Create the help menu MenuBar helpMenu = new MenuBar(true); menu.addSeparator(); menu.addItem(new MenuItem(constants.cwMenuBarHelpCategory(), helpMenu)); String[] helpOptions = constants.cwMenuBarHelpOptions(); for (int i = 0; i < helpOptions.length; i++) { helpMenu.addItem(helpOptions[i], menuCommand); } // Return the menu menu.ensureDebugId("cwMenuBar"); return menu; }
From source file:com.google.gwt.sample.showcase.client.content.other.CwCookies.java
License:Apache License
/** * Initialize this example.//from www .j av a2s .c o m */ @ShowcaseSource @Override public Widget onInitialize() { // Create the panel used to layout the content Grid mainLayout = new Grid(3, 3); // Display the existing cookies existingCookiesBox = new ListBox(); Button deleteCookieButton = new Button(constants.cwCookiesDeleteCookie()); deleteCookieButton.addStyleName("sc-FixedWidthButton"); mainLayout.setHTML(0, 0, "<b>" + constants.cwCookiesExistingLabel() + "</b>"); mainLayout.setWidget(0, 1, existingCookiesBox); mainLayout.setWidget(0, 2, deleteCookieButton); // Display the name of the cookie cookieNameBox = new TextBox(); mainLayout.setHTML(1, 0, "<b>" + constants.cwCookiesNameLabel() + "</b>"); mainLayout.setWidget(1, 1, cookieNameBox); // Display the name of the cookie cookieValueBox = new TextBox(); Button setCookieButton = new Button(constants.cwCookiesSetCookie()); setCookieButton.addStyleName("sc-FixedWidthButton"); mainLayout.setHTML(2, 0, "<b>" + constants.cwCookiesValueLabel() + "</b>"); mainLayout.setWidget(2, 1, cookieValueBox); mainLayout.setWidget(2, 2, setCookieButton); // Add a handler to set the cookie value setCookieButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String name = cookieNameBox.getText(); String value = cookieValueBox.getText(); Date expires = new Date((new Date()).getTime() + COOKIE_TIMEOUT); // Verify the name is valid if (name.length() < 1) { Window.alert(constants.cwCookiesInvalidCookie()); return; } // Set the cookie value Cookies.setCookie(name, value, expires); refreshExistingCookies(name); } }); // Add a handler to select an existing cookie existingCookiesBox.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateExstingCookie(); } }); // Add a handler to delete an existing cookie deleteCookieButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { int selectedIndex = existingCookiesBox.getSelectedIndex(); if (selectedIndex > -1 && selectedIndex < existingCookiesBox.getItemCount()) { String cookieName = existingCookiesBox.getValue(selectedIndex); Cookies.removeCookie(cookieName); existingCookiesBox.removeItem(selectedIndex); updateExstingCookie(); } } }); // Return the main layout refreshExistingCookies(null); return mainLayout; }
From source file:com.google.gwt.sample.showcase.client.content.widgets.CwBasicButton.java
License:Apache License
/** * Initialize this example./* ww w . j a v a2 s.co m*/ */ @ShowcaseSource @Override public Widget onInitialize() { // Create a panel to align the widgets HorizontalPanel hPanel = new HorizontalPanel(); hPanel.setSpacing(10); // Add a normal button Button normalButton = new Button(constants.cwBasicButtonNormal(), new ClickHandler() { public void onClick(ClickEvent event) { Window.alert(constants.cwBasicButtonClickMessage()); } }); normalButton.ensureDebugId("cwBasicButton-normal"); hPanel.add(normalButton); // Add a disabled button Button disabledButton = new Button(constants.cwBasicButtonDisabled()); disabledButton.ensureDebugId("cwBasicButton-disabled"); disabledButton.setEnabled(false); hPanel.add(disabledButton); // Return the panel return hPanel; }
From source file:com.google.gwt.sample.showcase.client.content.widgets.CwFileUpload.java
License:Apache License
/** * Initialize this example.//from w ww. ja v a2s . c om */ @ShowcaseSource @Override public Widget onInitialize() { // Create a vertical panel to align the content VerticalPanel vPanel = new VerticalPanel(); // Add a label vPanel.add(new HTML(constants.cwFileUploadSelectFile())); // Add a file upload widget final FileUpload fileUpload = new FileUpload(); fileUpload.ensureDebugId("cwFileUpload"); vPanel.add(fileUpload); // Add a button to upload the file Button uploadButton = new Button(constants.cwFileUploadButton()); uploadButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String filename = fileUpload.getFilename(); if (filename.length() == 0) { Window.alert(constants.cwFileUploadNoFileError()); } else { Window.alert(constants.cwFileUploadSuccessful()); } } }); vPanel.add(new HTML("<br>")); vPanel.add(uploadButton); // Return the layout panel return vPanel; }
From source file:com.google.gwt.sample.showcase.client.ContentWidget.java
License:Apache License
/** * Ensure that the demo widget has been initialized. Note that initialization * can fail if there is a network failure. *///from w w w. j a v a2s .com private void ensureWidgetInitialized() { if (widgetInitializing || widgetInitialized) { return; } widgetInitializing = true; asyncOnInitialize(new AsyncCallback<Widget>() { public void onFailure(Throwable reason) { widgetInitializing = false; Window.alert("Failed to download code for this widget (" + reason + ")"); } public void onSuccess(Widget result) { widgetInitializing = false; widgetInitialized = true; Widget widget = result; if (widget != null) { view.setExample(widget); } onInitializeComplete(); } }); }
From source file:com.google.gwt.sample.simplerpc.client.SimpleRPC.java
License:Apache License
/** * Create an asynchronous callback for the <code>getMultipleStrings</code> * RPC call. The same callback can be used for many RPC calls or customized * for a single one./*from ww w . ja va 2 s . c o m*/ */ private AsyncCallback<Map<Integer, String>> createGetMultipleStringsCallback(final Panel root) { return new AsyncCallback<Map<Integer, String>>() { public void onFailure(Throwable caught) { Window.alert("error: " + caught); } public void onSuccess(Map<Integer, String> result) { FlexTable t = new FlexTable(); t.setBorderWidth(2); t.setHTML(0, 0, "<b>Map Key</b>"); t.setHTML(0, 1, "<b>Map Value</b>"); int index = 1; for (Entry<Integer, String> element : result.entrySet()) { Integer key = element.getKey(); String value = element.getValue(); t.setText(index, 0, key.toString()); t.setText(index, 1, value); ++index; } root.add(new HTML("<h3>Result(on success)</h3>")); root.add(t); } }; }