List of usage examples for com.google.gwt.user.client Window alert
public static void alert(String msg)
From source file:com.google.code.gwt.database.sample.hellodatabase.client.HelloDatabase.java
License:Apache License
private void getCount() { dbService.getClickCount(new ScalarCallback<Integer>() { public void onFailure(DataServiceException error) { Window.alert("Failed to get count! " + error); }/*w ww . ja v a 2s .co m*/ public void onSuccess(Integer result) { vPanel.add(new Label("There are " + result + " recorded clicks.")); } }); }
From source file:com.google.code.gwt.storage.sample.hellostorage.client.HelloStorage.java
License:Apache License
/** * This is the entry point method.// w w w . j ava2 s. c o m */ public void onModuleLoad() { VerticalPanel main = new VerticalPanel(); RootPanel.get().add(main); RootPanel.get().setWidgetPosition(main, 10, 10); eventArea = new TextArea(); eventArea.setStyleName("widePanel"); eventArea.setHeight("60px"); eventArea.setText("[StorageEvent info]"); main.add(eventArea); HorizontalPanel eventPanel = new HorizontalPanel(); eventPanel.setStyleName("widePanel"); main.add(eventPanel); handlersLabel = new Label("#Handlers: 0"); eventPanel.add(new Button("Add a Handler", new ClickHandler() { public void onClick(ClickEvent event) { StorageEventHandler handler = new MyHandler(handlers.size() + 1); handlers.add(handler); Storage.addStorageEventHandler(handler); handlersLabel.setText("#Handlers: " + handlers.size()); } })); eventPanel.add(new Button("Delete a Handler", new ClickHandler() { public void onClick(ClickEvent event) { if (handlers.size() > 0) { StorageEventHandler handler = handlers.remove(handlers.size() - 1); Storage.removeStorageEventHandler(handler); handlersLabel.setText("#Handlers: " + handlers.size()); } } })); eventPanel.add(handlersLabel); eventPanel.setCellHorizontalAlignment(handlersLabel, HasHorizontalAlignment.ALIGN_RIGHT); if (!Storage.isLocalStorageSupported() && !Storage.isSessionStorageSupported()) { Window.alert("Web Storage NOT supported in this browser!"); return; } Storage local = Storage.getLocalStorage(); Storage session = Storage.getSessionStorage(); TabPanel tabs = new TabPanel(); main.add(tabs); tabs.add(createStorageTab(local, Storage.isLocalStorageSupported()), "localStorage"); tabs.add(createStorageTab(session, Storage.isSessionStorageSupported()), "sessionStorage"); tabs.selectTab(0); }
From source file:com.google.gerrit.client.admin.ProjectAccessScreen.java
License:Apache License
@UiHandler("commit") void onCommit(ClickEvent event) { final ProjectAccess access = driver.flush(); if (driver.hasErrors()) { Window.alert(Util.C.errorsMustBeFixed()); return;/*from w w w. j a v a 2 s. c o m*/ } String message = commitMessage.getText().trim(); if ("".equals(message)) { message = null; } enable(false); Util.PROJECT_SVC.changeProjectAccess( // getProjectKey(), // access.getRevision(), // message, // access.getLocal(), // new GerritCallback<ProjectAccess>() { @Override public void onSuccess(ProjectAccess newAccess) { enable(true); commitMessage.setText(""); error.clear(); final Set<String> diffs = getDiffs(access, newAccess); if (diffs.isEmpty()) { displayReadOnly(newAccess); } else { error.add(new Label(Gerrit.C.projectAccessError())); for (final String diff : diffs) { error.add(new Label(diff)); } if (access.canUpload()) { error.add(new Label(Gerrit.C.projectAccessProposeForReviewHint())); } } } private Set<String> getDiffs(ProjectAccess wantedAccess, ProjectAccess newAccess) { final List<AccessSection> wantedSections = mergeSections( removeEmptyPermissionsAndSections(wantedAccess.getLocal())); final HashSet<AccessSection> same = new HashSet<AccessSection>(wantedSections); final HashSet<AccessSection> different = new HashSet<AccessSection>( wantedSections.size() + newAccess.getLocal().size()); different.addAll(wantedSections); different.addAll(newAccess.getLocal()); same.retainAll(newAccess.getLocal()); different.removeAll(same); final Set<String> differentNames = new HashSet<String>(); for (final AccessSection s : different) { differentNames.add(s.getName()); } return differentNames; } @Override public void onFailure(Throwable caught) { error.clear(); enable(true); super.onFailure(caught); } }); }
From source file:com.google.gerrit.client.admin.ProjectAccessScreen.java
License:Apache License
@UiHandler("review") void onReview(ClickEvent event) { final ProjectAccess access = driver.flush(); if (driver.hasErrors()) { Window.alert(Util.C.errorsMustBeFixed()); return;//w w w.j a v a 2s .c o m } String message = commitMessage.getText().trim(); if ("".equals(message)) { message = null; } enable(false); Util.PROJECT_SVC.reviewProjectAccess( // getProjectKey(), // access.getRevision(), // message, // access.getLocal(), // new GerritCallback<Change.Id>() { @Override public void onSuccess(Change.Id changeId) { enable(true); commitMessage.setText(""); error.clear(); if (changeId != null) { Gerrit.display(PageLinks.toChange(changeId)); } else { displayReadOnly(access); } } @Override public void onFailure(Throwable caught) { error.clear(); enable(true); super.onFailure(caught); } }); }
From source file:com.google.gerrit.client.api.DefaultActions.java
License:Apache License
private static AsyncCallback<JavaScriptObject> callback(final String target) { return new GerritCallback<JavaScriptObject>() { @Override//from ww w.j a v a 2 s. c om public void onSuccess(JavaScriptObject in) { UiResult result = asUiResult(in); if (result.alert() != null) { Window.alert(result.alert()); } if (result.redirectUrl() != null && result.openWindow()) { Window.open(result.redirectUrl(), "_blank", null); } else if (result.redirectUrl() != null) { Location.assign(result.redirectUrl()); } else { Gerrit.display(target); } } private UiResult asUiResult(JavaScriptObject in) { if (NativeString.is(in)) { String str = ((NativeString) in).asString(); return str.isEmpty() ? UiResult.none() : UiResult.alert(str); } return in.cast(); } }; }
From source file:com.google.gerrit.client.changes.PatchSetComplexDisclosurePanel.java
License:Apache License
private void populateCommands(final PatchSetDetail detail) { for (final UiCommandDetail cmd : detail.getCommands()) { final Button b = new Button(cmd.label); b.setEnabled(cmd.enabled);//from w w w. ja v a 2s .co m b.setTitle(cmd.title); b.addClickHandler(new ClickHandler() { @Override public void onClick(final ClickEvent event) { if (cmd.confirmationMessage != null && !cmd.confirmationMessage.isEmpty()) { ConfirmationDialog confirmationDialog = new ConfirmationDialog(cmd.title, new SafeHtmlBuilder().append(cmd.confirmationMessage), new ConfirmationCallback() { @Override public void onOk() { postProcessCommand(cmd, b); } }); confirmationDialog.center(); } else { postProcessCommand(cmd, b); } } private void postProcessCommand(final UiCommandDetail cmd, final Button b) { b.setEnabled(false); AsyncCallback<NativeString> cb = new AsyncCallback<NativeString>() { @Override public void onFailure(Throwable caught) { b.setEnabled(true); new ErrorDialog(caught).center(); } @Override public void onSuccess(NativeString msg) { b.setEnabled(true); if (msg != null && !msg.asString().isEmpty()) { Window.alert(msg.asString()); } } }; RestApi api = ChangeApi.revision(patchSet.getId()).view(cmd.id); if ("PUT".equalsIgnoreCase(cmd.method)) { api.put(JavaScriptObject.createObject(), cb); } else if ("DELETE".equalsIgnoreCase(cmd.method)) { api.delete(cb); } else { api.post(JavaScriptObject.createObject(), cb); } } }); actionsPanel.add(b); } }
From source file:com.google.gwt.demos.currencywidget.client.CurrencyWidgetDemo.java
License:Apache License
public void onModuleLoad() { RootPanel rootPanel = RootPanel.get(); final Label currencyInputWidgetLabel = new Label("Currency Input Widget:"); rootPanel.add(currencyInputWidgetLabel, 50, 32); final CurrencyWidget currencyWidget = new CurrencyWidget("EUR"); rootPanel.add(currencyWidget, 50, 56); final Button clickMeButton = new Button(); rootPanel.add(clickMeButton, 250, 56); clickMeButton.setText("See what you got!"); clickMeButton.addClickListener(new ClickListener() { public void onClick(Widget sender) { Window.alert("You entered: " + Double.toString(currencyWidget.getAmount())); }/*from w ww. j a v a2 s.c om*/ }); final Label currencyWidgetWithPreviewLabel = new Label("Currency Widget With Preview"); rootPanel.add(currencyWidgetWithPreviewLabel, 50, 108); final CurrencyWidgetWithPreview currencyWidgetWithPreview = new CurrencyWidgetWithPreview("EUR"); rootPanel.add(currencyWidgetWithPreview, 50, 132); currencyWidgetWithPreview.setSize("156px", "18px"); final Button seeWhatYouButton = new Button(); rootPanel.add(seeWhatYouButton, 250, 132); seeWhatYouButton.setSize("157px", "24px"); seeWhatYouButton.setText("See what you got!"); seeWhatYouButton.addClickListener(new ClickListener() { public void onClick(Widget sender) { Window.alert("You entered: " + Double.toString(currencyWidgetWithPreview.getAmount())); } }); final Label jpCurrencyWidgetLabel = new Label("Japanese Currency"); rootPanel.add(jpCurrencyWidgetLabel, 50, 184); final CurrencyWidgetWithPreview jpCurrencyWidgetWithPreview = new CurrencyWidgetWithPreview("JPY"); rootPanel.add(jpCurrencyWidgetWithPreview, 50, 208); jpCurrencyWidgetWithPreview.setSize("156px", "18px"); final Label aNaiveTextLabel = new Label("A Naive Text Widget:"); rootPanel.add(aNaiveTextLabel, 50, 250); final TextBox textBox = new TextBox(); rootPanel.add(textBox, 50, 280); }
From source file:com.google.gwt.demos.fasttree.client.FastTreeDemo.java
License:Apache License
protected Widget profileTree() { final FlexTable table = new FlexTable(); final TextBox branches = new TextBox(); int row = 0;// w w w . j av a2 s. c o m table.setText(row, 0, "children per node"); table.setText(row, 1, "total number of rows"); table.setText(row, 2, "what type of node"); ++row; table.setWidget(row, 0, branches); branches.setText("5"); final TextBox nodes = new TextBox(); table.setWidget(row, 1, nodes); nodes.setText("2000"); table.setTitle("Number of nodes"); final ListBox type = new ListBox(); type.addItem("Text"); type.addItem("HTML"); type.addItem("CheckBox"); type.setSelectedIndex(1); table.setWidget(row, 2, type); ++row; final int widgetRow = row + 1; table.setWidget(row, 0, new Button("Normal tree", new ClickListener() { public void onClick(Widget sender) { long time = System.currentTimeMillis(); Tree t = new Tree(); profileCreateTree(t, Integer.parseInt(branches.getText()), Integer.parseInt(nodes.getText()), TreeType.getType(type.getSelectedIndex())); table.setWidget(widgetRow, 0, t); Window.alert("Elapsed time: " + (System.currentTimeMillis() - time)); } })); table.setWidget(row, 1, new Button("Fast tree", new ClickListener() { public void onClick(Widget sender) { long time = System.currentTimeMillis(); FastTree t = new FastTree(); profileCreateTree(t, Integer.parseInt(branches.getText()), Integer.parseInt(nodes.getText()), TreeType.getType(type.getSelectedIndex())); table.setWidget(widgetRow, 1, t); Window.alert("Elapsed time: " + (System.currentTimeMillis() - time)); } })); ++row; table.setText(row, 0, "tree results"); table.getCellFormatter().setVerticalAlignment(row, 0, HasAlignment.ALIGN_TOP); table.setText(row, 1, "fasttree results"); table.getCellFormatter().setVerticalAlignment(row, 1, HasAlignment.ALIGN_TOP); return table; }
From source file:com.google.gwt.demos.fasttree.client.FastTreeDemo.java
License:Apache License
private void verboseTreeItem(HasFastTreeItems parent, int children) { for (int i = 0; i < children; i++) { final int index = i; FastTreeItem item = new ListeningFastTreeItem("child " + i) { public void beforeClose() { Window.alert("Close item" + index); }/* w ww . j a v a 2s . c om*/ public void beforeOpen() { Window.alert("Open item " + index); } protected boolean beforeSelectionLost() { return DOMHelper.confirm("Are you sure you want to leave me?"); } protected void ensureChildren() { Window.alert("You are about to open my children for the first time"); } protected void onSelected() { Window.alert("You selected item " + index); } }; parent.addItem(item); verboseTreeItem(item, children - (i + 1)); } }
From source file:com.google.gwt.demos.gwtcanvas.client.LogoDemo.java
License:Apache License
public void drawDemo() { // The following is the same as doing // canvas.resize(width,height); canvas.setCoordSize(width, height);/*ww w. j a v a 2 s.c om*/ canvas.setPixelHeight(height); canvas.setPixelWidth(width); String[] imageUrls = new String[] { "logo-185x175.png" }; timer = new Timer() { @Override public void run() { renderingLoop(); } }; if (img == null) { // The first time this demo gets run we need to load our images. // Maintain a reference to the image we load so we can use it // the next time the demo is selected ImageLoader.loadImages(imageUrls, new ImageLoader.CallBack() { public void onImagesLoaded(ImageElement[] imageHandles) { // Drawing code involving images goes here img = imageHandles[0]; timer.schedule(10); } }); } else { // Go ahead and animate if (isImageLoaded(img)) { timer.schedule(10); } else { Window.alert("Refresh the page to reload the image."); } } }