List of usage examples for com.google.gwt.user.client Window alert
public static void alert(String msg)
From source file:com.google.gwt.gen2.demo.scrolltable.client.option.sort.SortColumnOption.java
License:Apache License
@Override protected Widget onInitialize() { CustomForm form = new CustomForm(); // Add the current policy policyBox = new ListBox(); policyBox.addItem("Disabled"); policyBox.addItem("Single Cell"); policyBox.addItem("Multi Cell"); form.addLabeledWidget("Sort Policy:", policyBox); refreshPolicy();//from ww w . j a v a2s . co m // Add button to change policy { Button button = new Button("Set Sort Policy", new ClickHandler() { public void onClick(ClickEvent event) { AbstractScrollTable scrollTable = ScrollTableDemo.get().getScrollTable(); switch (policyBox.getSelectedIndex()) { case 0: scrollTable.setSortPolicy(SortPolicy.DISABLED); break; case 1: scrollTable.setSortPolicy(SortPolicy.SINGLE_CELL); break; case 2: scrollTable.setSortPolicy(SortPolicy.MULTI_CELL); break; } } }); form.addButton(button); } // Select the column index final TextBox columnBox = new TextBox(); columnBox.setText("3"); columnBox.setWidth("50px"); form.addLabeledWidget("Column Index:", columnBox); // Add a button to sort the column { Button button = new Button("Sort Column", new ClickHandler() { public void onClick(ClickEvent event) { try { int column = Integer.parseInt(columnBox.getText()); ScrollTableDemo.get().getDataTable().sortColumn(column); ScrollTableDemo.get().getScrollTable().redraw(); } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } // Add a button to make column sortable if (PagingScrollTableDemo.get() == null) { Button button = new Button("Make Sortable", new ClickHandler() { public void onClick(ClickEvent event) { try { int column = Integer.parseInt(columnBox.getText()); ScrollTable scrollTable = (ScrollTable) ScrollTableDemo.get().getScrollTable(); scrollTable.setColumnSortable(column, true); } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } } }); form.addButton(button); } // Add a button to make column unsortable if (PagingScrollTableDemo.get() == null) { Button button = new Button("Make Unsortable", new ClickHandler() { public void onClick(ClickEvent event) { try { int column = Integer.parseInt(columnBox.getText()); ScrollTable scrollTable = (ScrollTable) ScrollTableDemo.get().getScrollTable(); scrollTable.setColumnSortable(column, false); } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } } }); form.addButton(button); } return form; }
From source file:com.google.gwt.gen2.demo.scrolltable.client.option.sort.SwapRowsOption.java
License:Apache License
@Override protected Widget onInitialize() { CustomForm form = new CustomForm(); // Row1 selection final TextBox rowBox1 = new TextBox(); rowBox1.setText("3"); rowBox1.setWidth("50px"); form.addLabeledWidget("Row 1 Index:", rowBox1); // Row2 selection final TextBox rowBox2 = new TextBox(); rowBox2.setText("6"); rowBox2.setWidth("50px"); form.addLabeledWidget("Row 2 Index:", rowBox2); // Add button to swap rows {//from www . ja va2 s .com Button button = new Button("Swap Rows", new ClickHandler() { public void onClick(ClickEvent event) { try { int row1 = Integer.parseInt(rowBox1.getText()); int row2 = Integer.parseInt(rowBox2.getText()); if (row1 >= 0 && row2 >= 0) { ScrollTableDemo.get().getDataTable().swapRows(row1, row2); } } catch (NumberFormatException e) { Window.alert("Please enter valid integers for the row and column."); } catch (IndexOutOfBoundsException e) { Window.alert("The row or column index you entered is out of bounds."); } } }); form.addButton(button); } // Add button to reverse all rows { Button button = new Button("Reverse All Rows", new ClickHandler() { public void onClick(ClickEvent event) { ScrollTableDemo.get().getDataTable().reverseRows(); } }); form.addButton(button); } return form; }
From source file:com.google.gwt.gen2.demo.scrolltable.client.PagingScrollTableDemo.java
License:Apache License
/** * @return the {@link TableDefinition} with all ColumnDefinitions defined. *//*from w w w .j ava 2s . c om*/ private TableDefinition<Student> createTableDefinition() { // Define some cell renderers CellRenderer<Student, Integer> intCellRenderer = new CellRenderer<Student, Integer>() { public void renderRowValue(Student rowValue, ColumnDefinition<Student, Integer> columnDef, AbstractCellView<Student> view) { view.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); view.setHTML(columnDef.getCellValue(rowValue).toString()); } }; // Create the table definition tableDefinition = new DefaultTableDefinition<Student>(); // Set the row renderer String[] rowColors = new String[] { "#FFFFDD", "#EEEEEE" }; tableDefinition.setRowRenderer(new DefaultRowRenderer<Student>(rowColors)); // First name { StudentColumnDefinition<String> columnDef = new StudentColumnDefinition<String>("First Name", Group.GENERAL) { @Override public String getCellValue(Student rowValue) { return rowValue.getFirstName(); } @Override public void setCellValue(Student rowValue, String cellValue) { rowValue.setFirstName(cellValue); } }; columnDef.setMinimumColumnWidth(50); columnDef.setPreferredColumnWidth(100); columnDef.setColumnSortable(true); columnDef.setColumnTruncatable(false); tableDefinition.addColumnDefinition(columnDef); } // Last name { StudentColumnDefinition<String> columnDef = new StudentColumnDefinition<String>("Last Name", Group.GENERAL) { @Override public String getCellValue(Student rowValue) { return rowValue.getLastName(); } @Override public void setCellValue(Student rowValue, String cellValue) { rowValue.setLastName(cellValue); } }; columnDef.setMinimumColumnWidth(50); columnDef.setPreferredColumnWidth(100); columnDef.setColumnSortable(true); columnDef.setColumnTruncatable(false); tableDefinition.addColumnDefinition(columnDef); } // Age { StudentColumnDefinition<Integer> columnDef = new StudentColumnDefinition<Integer>("Age", Group.GENERAL) { @Override public Integer getCellValue(Student rowValue) { return rowValue.getAge(); } @Override public void setCellValue(Student rowValue, Integer cellValue) { rowValue.setAge(cellValue); } }; // Dynamic footer provides range of ages StudentFooterProperty prop = new StudentFooterProperty() { @Override public Object getFooter(int row, int column) { if (row == 1) { int min = -1; int max = -1; int rowCount = pagingScrollTable.getDataTable().getRowCount(); for (int i = 0; i < rowCount; i++) { int age = pagingScrollTable.getRowValue(i).getAge(); if (min == -1) { min = age; max = age; } else { min = Math.min(min, age); max = Math.max(max, age); } } return min + "-" + max; } return super.getFooter(row, column); } }; prop.setFooterCount(2); prop.setDynamic(true); columnDef.setColumnProperty(FooterProperty.TYPE, prop); columnDef.setCellRenderer(intCellRenderer); columnDef.setMinimumColumnWidth(35); columnDef.setPreferredColumnWidth(35); columnDef.setMaximumColumnWidth(35); columnDef.setColumnSortable(true); tableDefinition.addColumnDefinition(columnDef); } // Gender { StudentColumnDefinition<Boolean> columnDef = new StudentColumnDefinition<Boolean>("Gender", Group.GENERAL) { @Override public Boolean getCellValue(Student rowValue) { return rowValue.isMale(); } @Override public void setCellValue(Student rowValue, Boolean cellValue) { rowValue.setMale(cellValue); } }; columnDef.setCellRenderer(new CellRenderer<Student, Boolean>() { public void renderRowValue(Student rowValue, ColumnDefinition<Student, Boolean> columnDef, AbstractCellView<Student> view) { if (rowValue.isMale()) { view.setHTML("male"); } else { view.setHTML("female"); } } }); columnDef.setMinimumColumnWidth(45); columnDef.setPreferredColumnWidth(45); columnDef.setMaximumColumnWidth(45); columnDef.setColumnSortable(true); tableDefinition.addColumnDefinition(columnDef); // Setup the cellEditor RadioCellEditor<Boolean> cellEditor = new RadioCellEditor<Boolean>(); cellEditor.setLabel("Select a gender:"); cellEditor.addRadioButton(new RadioButton("editorGender", "male"), true); cellEditor.addRadioButton(new RadioButton("editorGender", "female"), false); columnDef.setCellEditor(cellEditor); } // Race { StudentColumnDefinition<String> columnDef = new StudentColumnDefinition<String>("Race", Group.GENERAL) { @Override public String getCellValue(Student rowValue) { return rowValue.getRace(); } @Override public void setCellValue(Student rowValue, String cellValue) { rowValue.setRace(cellValue); } }; columnDef.setMinimumColumnWidth(45); columnDef.setPreferredColumnWidth(55); columnDef.setMaximumColumnWidth(70); columnDef.setColumnSortable(true); tableDefinition.addColumnDefinition(columnDef); // Setup the cell editor ListCellEditor<String> cellEditor = new ListCellEditor<String>(); for (int i = 0; i < StudentGenerator.races.length; i++) { String race = StudentGenerator.races[i]; cellEditor.addItem(race, race); } columnDef.setCellEditor(cellEditor); } // Favorite color { StudentColumnDefinition<String> columnDef = new StudentColumnDefinition<String>("Favorite Color", null) { @Override public String getCellValue(Student rowValue) { return rowValue.getFavoriteColor(); } @Override public void setCellValue(Student rowValue, String cellValue) { rowValue.setFavoriteColor(cellValue); } }; columnDef.setCellRenderer(new CellRenderer<Student, String>() { public void renderRowValue(Student rowValue, ColumnDefinition<Student, String> columnDef, AbstractCellView<Student> view) { String color = rowValue.getFavoriteColor(); view.setStyleAttribute("color", color); view.setHTML(color); } }); columnDef.setPreferredColumnWidth(80); columnDef.setColumnSortable(true); columnDef.setHeaderTruncatable(false); tableDefinition.addColumnDefinition(columnDef); // Setup the cell editor RadioCellEditor<String> cellEditor = new RadioCellEditor<String>(); cellEditor.setLabel("Select a color:"); for (int i = 0; i < StudentGenerator.colors.length; i++) { String color = StudentGenerator.colors[i]; String text = "<FONT color=\"" + color + "\">" + color + "</FONT>"; cellEditor.addRadioButton(new RadioButton("editorColor", text, true), color); } columnDef.setCellEditor(cellEditor); } // Favorite Sport { StudentColumnDefinition<String> columnDef = new StudentColumnDefinition<String>("Preferred Sport", null) { @Override public String getCellValue(Student rowValue) { return rowValue.getFavoriteSport(); } @Override public void setCellValue(Student rowValue, String cellValue) { rowValue.setFavoriteSport(cellValue); } }; columnDef.setPreferredColumnWidth(110); columnDef.setColumnSortable(true); tableDefinition.addColumnDefinition(columnDef); // Setup the cell editor ListCellEditor<String> cellEditor = new ListCellEditor<String>(); cellEditor.setLabel("Select a sport:"); for (int i = 0; i < StudentGenerator.sports.length; i++) { String sport = StudentGenerator.sports[i]; cellEditor.addItem(sport, sport); } columnDef.setCellEditor(cellEditor); } // College { StudentColumnDefinition<String> columnDef = new StudentColumnDefinition<String>("College", Group.SCHOOL) { @Override public String getCellValue(Student rowValue) { return rowValue.getCollege(); } @Override public void setCellValue(Student rowValue, String cellValue) { rowValue.setCollege(cellValue); } }; columnDef.setMinimumColumnWidth(50); columnDef.setPreferredColumnWidth(180); columnDef.setMaximumColumnWidth(250); columnDef.setColumnSortable(true); columnDef.setColumnTruncatable(false); tableDefinition.addColumnDefinition(columnDef); // Setup the cell editor TextCellEditor cellEditor = new TextCellEditor() { @Override public boolean onAccept() { if (getValue().equals("")) { Window.alert("You must enter a school"); return false; } return true; } @Override protected int getOffsetLeft() { return -8; } @Override protected int getOffsetTop() { return -10; } }; columnDef.setCellEditor(cellEditor); } // Graduation year { StudentColumnDefinition<Integer> columnDef = new StudentColumnDefinition<Integer>("Year", Group.SCHOOL) { @Override public Integer getCellValue(Student rowValue) { return rowValue.getGraduationYear(); } @Override public void setCellValue(Student rowValue, Integer cellValue) { rowValue.setGraduationYear(cellValue); } }; // Dynamic footer provides range of ages StudentFooterProperty prop = new StudentFooterProperty() { @Override public Object getFooter(int row, int column) { if (row == 1) { int min = -1; int max = -1; int rowCount = pagingScrollTable.getDataTable().getRowCount(); for (int i = 0; i < rowCount; i++) { int year = pagingScrollTable.getRowValue(i).getGraduationYear(); if (min == -1) { min = year; max = year; } else { min = Math.min(min, year); max = Math.max(max, year); } } return min + "-" + max; } return super.getFooter(row, column); } }; prop.setFooterCount(2); prop.setDynamic(true); columnDef.setColumnProperty(FooterProperty.TYPE, prop); columnDef.setCellRenderer(intCellRenderer); columnDef.setPreferredColumnWidth(35); columnDef.setMinimumColumnWidth(35); columnDef.setMaximumColumnWidth(35); columnDef.setColumnSortable(true); columnDef.setColumnTruncatable(false); tableDefinition.addColumnDefinition(columnDef); } // GPA { StudentColumnDefinition<Double> columnDef = new StudentColumnDefinition<Double>("GPA", Group.SCHOOL) { @Override public Double getCellValue(Student rowValue) { return rowValue.getGpa(); } @Override public void setCellValue(Student rowValue, Double cellValue) { rowValue.setGpa(cellValue); } }; // Dynamic footer provides average GPA StudentFooterProperty prop = new StudentFooterProperty() { @Override public Object getFooter(int row, int column) { if (row == 1) { double avg = 0; int rowCount = pagingScrollTable.getDataTable().getRowCount(); for (int i = 0; i < rowCount; i++) { avg += pagingScrollTable.getRowValue(i).getGpa(); } avg /= rowCount; return gpaToString(avg); } return super.getFooter(row, column); } }; prop.setFooterCount(2); prop.setDynamic(true); columnDef.setColumnProperty(FooterProperty.TYPE, prop); // Custom renderer uses background colors based on GPA columnDef.setCellRenderer(new CellRenderer<Student, Double>() { public void renderRowValue(Student rowValue, ColumnDefinition<Student, Double> columnDef, AbstractCellView<Student> view) { view.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); double gpa = rowValue.getGpa(); if (gpa < 2) { view.setStyleName("badGPA"); } else if (gpa < 3) { view.setStyleName("goodGPA"); } else { view.setStyleName("greatGPA"); } view.setHTML(gpaToString(gpa)); } }); columnDef.setPreferredColumnWidth(35); columnDef.setMinimumColumnWidth(35); columnDef.setMaximumColumnWidth(35); columnDef.setColumnSortable(true); columnDef.setColumnTruncatable(false); tableDefinition.addColumnDefinition(columnDef); } // ID { StudentColumnDefinition<Integer> columnDef = new StudentColumnDefinition<Integer>("ID", Group.LOGIN) { @Override public Integer getCellValue(Student rowValue) { return rowValue.getId(); } @Override public void setCellValue(Student rowValue, Integer cellValue) { rowValue.setId(cellValue); } }; columnDef.setCellRenderer(intCellRenderer); columnDef.setPreferredColumnWidth(55); columnDef.setColumnTruncatable(false); tableDefinition.addColumnDefinition(columnDef); } // Pin { StudentColumnDefinition<Integer> columnDef = new StudentColumnDefinition<Integer>("Pin", Group.LOGIN) { @Override public Integer getCellValue(Student rowValue) { return rowValue.getPin(); } @Override public void setCellValue(Student rowValue, Integer cellValue) { rowValue.setPin(cellValue); } }; columnDef.setCellRenderer(intCellRenderer); columnDef.setPreferredColumnWidth(45); columnDef.setColumnTruncatable(false); tableDefinition.addColumnDefinition(columnDef); } return tableDefinition; }
From source file:com.google.gwt.gwtai.demo.client.GwtAI.java
License:Apache License
private Widget createCallbackApplet() { CallbackApplet applet = (CallbackApplet) GWT.create(CallbackApplet.class); Widget widgetAppletOne = AppletJSUtil.createAppletWidget(applet); RootPanel.get().add(widgetAppletOne); AppletJSUtil.registerAppletCallback(applet, new AppletCallback<String>() { public void callback(String callbackValue) { Window.alert("Received: " + callbackValue); }/*from w ww . j av a 2s .c o m*/ }); return widgetAppletOne; }
From source file:com.google.gwt.gwtai.demo.client.TrayIconAppletTab.java
License:Apache License
public TrayIconAppletTab() { VerticalPanel panelMain = new VerticalPanel(); panelMain.setWidth("100%"); panelMain.setSpacing(4);// ww w. j av a2 s . co m _trayIconApplet = (TrayIconApplet) GWT.create(TrayIconApplet.class); Widget widgetApplet = AppletJSUtil.createAppletWidget(_trayIconApplet); Label labelTitle = new Label( "Hook into the desktop tray from a GWT application. This is a 'Proof of Concept', the feature is not finished yet."); DisclosurePanel panelCode = new DisclosurePanel("View code"); panelCode.setWidth("100%"); panelCode.setAnimationEnabled(true); panelCode.setContent(createCodeHTML()); HorizontalPanel panelItems = new HorizontalPanel(); panelItems.setSpacing(4); final TextBox boxCaption = new TextBox(); final ListBox boxItemType = new ListBox(); boxItemType.addItem("Text"); boxItemType.addItem("CheckBox"); boxItemType.setSelectedIndex(0); Button buttonAdd = new Button("Add menu item"); buttonAdd.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String caption = boxCaption.getText(); if (null == caption || caption.length() < 1) { Window.alert("Caption can not be empty"); } else { String itemType = boxItemType.getItemText(boxItemType.getSelectedIndex()); if (itemType.equals("CheckBox")) { _trayIconApplet.addCheckBoxItem(caption); } else { _trayIconApplet.addTextItem(caption); } } } }); Button buttonSeparator = new Button("Add separator"); buttonSeparator.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { _trayIconApplet.addSeparator(); } }); panelItems.add(boxCaption); panelItems.add(boxItemType); panelItems.add(buttonAdd); panelItems.add(buttonSeparator); panelMain.add(labelTitle); panelMain.add(widgetApplet); panelMain.add(panelItems); panelMain.add(panelCode); panelMain.setCellHorizontalAlignment(labelTitle, VerticalPanel.ALIGN_CENTER); panelMain.setCellHorizontalAlignment(widgetApplet, VerticalPanel.ALIGN_CENTER); initWidget(panelMain); }
From source file:com.google.gwt.inject.example.simple.client.SimpleAsyncWidget.java
License:Apache License
public void showMessage() { Window.alert(messages.messageTemplate("Hello Async! from instance " + instanceCounter)); }
From source file:com.google.gwt.maps.sample.hellomaps.client.CustomControlDemo.java
License:Apache License
/** * Display the appropriate custom control depending on what the user has * selected in the action box.//from w ww .j ava2 s . co m */ private void displayCustomControl() { if (currentControl != null) { map.removeControl(currentControl); currentControl = null; } ControlDemos selected = ControlDemos.values()[actionListBox.getSelectedIndex()]; switch (selected) { case TEST_IMAGE_CUSTOM_ZOOM_CONTROL: currentControl = new ImageZoomControl(); break; case TEST_TEXT_CUSTOM_ZOOM_CONTROL: currentControl = new TextualZoomControl(); break; case TEST_HIERARCHICAL_CONTROL: currentControl = getHierarchicalMapTypeControl(); break; default: Window.alert("Unknown selection: " + selected.valueOf()); return; } map.addControl(currentControl); }
From source file:com.google.gwt.maps.sample.hellomaps.client.EarthPluginDemo.java
License:Apache License
public EarthPluginDemo() { Panel panel = new FlowPanel(); map = new MapWidget(LatLng.newInstance(37.42317, -122.08364), 16); map.setSize("500px", "500px"); map.addControl(new SmallMapControl()); map.addMapType(MapType.getEarthMap()); map.setCurrentMapType(MapType.getEarthMap()); panel.add(map);//from ww w .j a v a 2 s .c om initWidget(panel); map.getEarthInstance(new EarthInstanceHandler() { public void onEarthInstance(EarthInstanceEvent event) { final JavaScriptObject earth = event.getEarthInstance(); if (earth == null) { Window.alert("Failed to init earth plugin"); } else { /* * Create a marker. The timer is set to give the earth plugin a chance * to position to the proper point on the map. */ new Timer() { @Override public void run() { createPlacemark(earth); } }.schedule(1000); } } }); }
From source file:com.google.gwt.maps.sample.hellomaps.client.Geocoder2Demo.java
License:Apache License
private void showAddress(final String address) { final InfoWindow info = map.getInfoWindow(); geocoder.getLocations(address, new LocationCallback() { public void onFailure(int statusCode) { Window.alert("Sorry, we were unable to geocode that address"); }/*from w w w . j a v a 2s .c o m*/ public void onSuccess(JsArray<Placemark> locations) { Placemark place = locations.get(0); Marker marker = new Marker(place.getPoint()); map.addOverlay(marker); String message = place.getAddress() + "<br>" + "<b>Country code:</b> " + place.getCountry(); info.open(marker, new InfoWindowContent(message)); } }); }
From source file:com.google.gwt.maps.sample.hellomaps.client.GeocoderDemo.java
License:Apache License
private void showAddress(final String address) { final InfoWindow info = map.getInfoWindow(); geocoder.getLatLng(address, new LatLngCallback() { public void onFailure() { Window.alert(address + " not found"); }/*from w w w . j a va2 s . c o m*/ public void onSuccess(LatLng point) { map.setCenter(point, 13); Marker marker = new Marker(point); map.addOverlay(marker); info.open(marker, new InfoWindowContent(address)); displayLatLng(point); } }); }