private void displayStock(final String finalSymbol) { // Add the task to the table. int row = tasksFlexTable.getRowCount(); tasks.add(finalSymbol); tasksFlexTable.setText(row, 0, finalSymbol); tasksFlexTable.setWidget(row, 2, new Label()); tasksFlexTable.getCellFormatter().addStyleName(row, 1, "watchListNumericColumn"); tasksFlexTable.getCellFormatter().addStyleName(row, 2, "watchListNumericColumn"); tasksFlexTable.getCellFormatter().addStyleName(row, 3, "watchListRemoveColumn"); // Add a button to remove this task from the table. Button removeTaskButton = new Button("x"); removeTaskButton.addStyleDependentName("remove"); removeTaskButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { removeStock(finalSymbol); } }); tasksFlexTable.setWidget(row, 3, removeTaskButton); // Get the stock price. refreshWatchList(); newTaskTextBox.setFocus(true); }
/** * Ajoute une tache dans la table des tâches. Déclenchée par un click sur le addTaskButton ou par * la touche Enter depuis le champ newTaskTextBox. */ private void addTask() { String symbol = newTaskTextBox.getText().trim(); newTaskTextBox.setFocus(true); // Stock code must be between 1 and 10 chars that are numbers, letters, or dots. if (symbol.length() < 3) { Window.alert("le nom de la tâche doit faire plus de 3 caractères."); newTaskTextBox.selectAll(); return; } newTaskTextBox.setText(""); // Rename the task if it's already in the table. if (tasks.contains(symbol)) { int n = 1; while (tasks.contains(symbol + " (" + n + ")")) { n++; } symbol = symbol + " (" + n + ")"; } final String finalSymbol = symbol; addStock(symbol); }
protected void showEditor() { if (myTextEditor == null) { myTextEditor = new TextBox(); myTextEditor.setStylePrimaryName("field_edit"); myTextEditor.addValueChangeHandler( new ValueChangeHandler<String>() { public void onValueChange(ValueChangeEvent<String> aEvent) { hideEditor(true); } }); myTextEditor.addBlurHandler( new BlurHandler() { public void onBlur(BlurEvent aEvent) { hideEditor(false); } }); } if (allowHtml) { myTextEditor.setText(myHtmlView.getHTML()); myOuterPanel.remove(myHtmlView); } else { myTextEditor.setText(myTextView.getText()); myOuterPanel.remove(myTextView); } myOuterPanel.add(myTextEditor); myTextEditor.setFocus(true); }
@Override void doSave() { int order; try { order = Integer.parseInt(listOrderEd.getText().trim()); } catch (NumberFormatException e) { Window.alert( "Enter an integer to indicate the order that this season will appear in a drop down selection box"); listOrderEd.setFocus(true); return; } if (seasonEd.getText().trim().length() == 0) { Window.alert("Enter a Season"); return; } TSe season = new TSe(); if (editRb.getValue()) { season.setId(getLookupId()); } season.setListOrder(order); season.setSeason(seasonEd.getText()); saveBtn.setEnabled(false); service.saveSeason(season); }
/** * Internal method which is called when the user clicks on an editable title field. * * <p> */ protected void editTitle() { m_title.setVisible(false); final TextBox box = new TextBox(); box.setText(m_title.getText()); box.getElement().setAttribute("size", "45"); box.addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().labelInput()); box.addStyleName(I_CmsLayoutBundle.INSTANCE.listItemWidgetCss().titleInput()); final String originalTitle = m_title.getText(); // wrap the boolean flag in an array so we can change it from the event handlers final boolean[] checked = new boolean[] {false}; box.addBlurHandler( new BlurHandler() { /** * @see * com.google.gwt.event.dom.client.BlurHandler#onBlur(com.google.gwt.event.dom.client.BlurEvent) */ public void onBlur(BlurEvent event) { if (checked[0]) { return; } onEditTitleTextBox(box); checked[0] = true; } }); box.addKeyPressHandler( new KeyPressHandler() { /** * @see * com.google.gwt.event.dom.client.KeyPressHandler#onKeyPress(com.google.gwt.event.dom.client.KeyPressEvent) */ public void onKeyPress(KeyPressEvent event) { if (checked[0]) { return; } int keycode = event.getNativeEvent().getKeyCode(); if ((keycode == 10) || (keycode == 13)) { onEditTitleTextBox(box); checked[0] = true; } if (keycode == 27) { box.setText(originalTitle); onEditTitleTextBox(box); checked[0] = true; } } }); m_titleRow.insert(box, 1); box.setFocus(true); }
/** reset */ public void reset() { selectedRow = -1; table.removeAllRows(); name.setText(""); importButton.setEnabled(false); typeList.setSelectedIndex(0); name.setFocus(true); }
@Override public void setActive() { // if the search box is empty, set focus there if (StringUtils.isEmpty(getKeyword())) { searchBox.setFocus(true); } else { super.setActive(); } }
/** This is the entry point method. */ public void onModuleLoad() { sendButton = new Button("Send"); nameField = new TextBox(); nameField.setText("GWT User"); errorLabel = new Label(); // We can add style names to widgets sendButton.addStyleName("sendButton"); // Add the nameField and sendButton to the RootPanel // Use RootPanel.get() to get the entire body element RootPanel.get("nameFieldContainer").add(nameField); RootPanel.get("sendButtonContainer").add(sendButton); RootPanel.get("errorLabelContainer").add(errorLabel); // Focus the cursor on the name field when the app loads nameField.setFocus(true); nameField.selectAll(); // Create the popup dialog box dialogBox = new DialogBox(); dialogBox.setText("Remote Procedure Call"); dialogBox.setAnimationEnabled(true); closeButton = new Button("Close"); // We can set the id of a widget by accessing its Element closeButton.getElement().setId("closeButton"); textToServerLabel = new Label(); serverResponseLabel = new HTML(); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.addStyleName("dialogVPanel"); dialogVPanel.add(new HTML("<b>Sending name to the server:</b>")); dialogVPanel.add(textToServerLabel); dialogVPanel.add(new HTML("<br><b>Server replies:</b>")); dialogVPanel.add(serverResponseLabel); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); dialogVPanel.add(closeButton); dialogBox.setWidget(dialogVPanel); // Add a handler to close the DialogBox final ClickHandler buttonClickHandler = new ClickHandler() { public void onClick(ClickEvent event) { dialogBox.hide(); sendButton.setEnabled(true); sendButton.setFocus(true); } }; closeButton.addClickHandler(buttonClickHandler); // Add a handler to send the name to the server ChangeEventHandler handler = new ChangeEventHandler(); sendButton.addClickHandler(handler); nameField.addKeyUpHandler(handler); }
private void addStock() { final String symbol = newSymbolTextBox.getText().toUpperCase().trim(); newSymbolTextBox.setFocus(true); // Stock code must be between 1 and 10 chars that are numbers, letters, or dots. if (!symbol.matches("^[0-9A-Z\\.]{1,10}$")) { Window.alert("'" + symbol + "' is not a valit symbol."); newSymbolTextBox.selectAll(); return; } newSymbolTextBox.setText(""); }
private boolean validateFormInput() { if (inputNoteTitle.getText().trim().length() == 0) { Window.alert("Please enter a title for the new note!"); inputNoteTitle.setFocus(true); return false; } if (inputNoteText.getText().trim().length() == 0) { Window.alert("Please enter a text for the new note!"); inputNoteText.setFocus(true); return false; } return true; }
/** Shows the popup */ public void show() { initButtons(); int left = (Window.getClientWidth() - 700) / 2; int top = (Window.getClientHeight() - 350) / 2; setPopupPosition(left, top); setText(Main.i18n("search.folder.filter")); // Resets to initial tree value removeAllRows(); keyword.setText(""); evaluateEnableAction(); super.show(); keyword.setFocus(true); }
private void makeWidget(final FlexTable table, final int row, final int col) { if (row == curRow && col == curCol) return; if (row >= 1) { curRow = row; curCol = col; if (col == 3 || col == 4) { TextBox t = new TextBox(); t.setText(table.getText(row, col)); table.setWidget(row, col, t); t.setFocus(true); t.addKeyboardListener( new KeyboardListener() { public void onKeyDown(Widget sender, char keyCode, int modifiers) {} public void onKeyPress(Widget sender, char keyCode, int modifiers) { TextBox t = (TextBox) sender; if (keyCode == (char) KeyboardListener.KEY_ENTER) { clearCurrentSelection(table, -11, -11); } } public void onKeyUp(Widget sender, char keyCode, int modifiers) {} }); } else if (col == 2 && !table.getText(row, col).equals("Primary")) { String curValue = table.getText(row, col); ListBox l = new ListBox(); l.addItem("Category"); if (curValue.equals("Category")) l.setSelectedIndex(0); l.addItem("Description"); if (curValue.equals("Description")) l.setSelectedIndex(1); l.addItem("Numerical"); if (curValue.equals("Numerical")) l.setSelectedIndex(2); l.addItem("Protected"); if (curValue.equals("Protected")) l.setSelectedIndex(3); l.addItem("Tag"); if (curValue.equals("Tag")) l.setSelectedIndex(4); l.addChangeListener( new ChangeListener() { public void onChange(Widget sender) { clearCurrentSelection(table, -11, -11); } }); table.setWidget(row, col, l); } } }
private void createFields() { idField = new TextBox(); nameField = new TextBox(); streetField = new TextBox(); cityField = new TextBox(); stateField = new TextBox(); zipField = new TextBox(); errorLabel = new Label(); // Add the nameField and sendButton to the RootPanel // Use RootPanel.get() to get the entire body element RootPanel.get("idFieldContainer").add(idField); RootPanel.get("nameFieldContainer").add(nameField); RootPanel.get("streetFieldContainer").add(streetField); RootPanel.get("cityFieldContainer").add(cityField); RootPanel.get("stateFieldContainer").add(stateField); RootPanel.get("zipFieldContainer").add(zipField); // Focus the cursor on the name field when the app loads idField.setFocus(true); idField.selectAll(); }
public void onModuleLoad() { // Create table for stock data. stocksFlexTable.setText(0, 0, "Symbol"); stocksFlexTable.setText(0, 1, "Price"); stocksFlexTable.setText(0, 2, "Change"); stocksFlexTable.setText(0, 3, "Remove"); // Assemble Add Stock panel. addPanel.add(newSymbolTextBox); addPanel.add(addStockButton); // Assemble Main panel. mainPanel.add(stocksFlexTable); mainPanel.add(addPanel); mainPanel.add(lastUpdateLabel); // Associate the Main panel with the HTML host page. RootPanel.get("stockList").add(mainPanel); // Move cursor focus to the input box. newSymbolTextBox.setFocus(true); initHandlers(); }
private void addStock() { final String symbol = newSymbolTextBox.getText().toUpperCase().trim(); newSymbolTextBox.setFocus(true); // Stock code must be between 1 and 10 chars that are numbers, letters, // or dots. if (!symbol.matches("^[0-9A-Z\\.]{1,10}$")) { Window.alert("'" + symbol + "' is not a valid symbol."); newSymbolTextBox.selectAll(); return; } newSymbolTextBox.setText(""); if (stockAlreadyWatched(symbol)) { return; } int row = addStockToWatchList(symbol); addRemoveButtonForStock(symbol, row); refreshWatchList(); }
private void focusBoss() { newboss.setFocus(true); newboss.setText(NEW_BOSS); newboss.setSelectionRange(0, NEW_BOSS.length()); }
@Override public void focusInUrlInput() { projectUrl.setFocus(true); }
/** This is the entry point method. */ private void hahaha() { final Button searchButton = new Button("Search"); final TextBox nameField = new TextBox(); nameField.setText("GWT User"); final Label errorLabel = new Label(); // We can add style names to widgets searchButton.addStyleName("sendButton"); // Add the nameField and sendButton to the RootPanel // Use RootPanel.get() to get the entire body element RootPanel.get("nameFieldContainer").add(nameField); RootPanel.get("sendButtonContainer").add(searchButton); RootPanel.get("errorLabelContainer").add(errorLabel); // Focus the cursor on the name field when the app loads nameField.setFocus(true); nameField.selectAll(); // Create the popup dialog box // Create a handler for the sendButton and nameField class MyHandler implements ClickHandler, KeyUpHandler { /** Fired when the user clicks on the sendButton. */ public void onClick(ClickEvent event) { sendNameToServer(); } /** Fired when the user types in the nameField. */ public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { sendNameToServer(); } } /** Send the name from the nameField to the server and wait for a response. */ private void sendNameToServer() { // First, we validate the input. errorLabel.setText(""); String textToServer = nameField.getText(); if (!FieldVerifier.isValidName(textToServer)) { errorLabel.setText("Please enter at least four characters"); return; } // Then, we send the input to the server. // sendButton.setEnabled(false); SearchRequest request = new SearchRequest(); Date twoMinsAgo = new Date(new Date().getTime() - 1000 * 60 * 2); request.setFetchTime(Interval.after(twoMinsAgo)); greetingService.greetServer( request, new AsyncCallback<Collection<Place>>() { public void onFailure(Throwable caught) { notification.handleFailure(caught); } public void onSuccess(Collection<Place> result) { // TODO: sign of utter stupidity final MapWidget map = (MapWidget) RootPanel.get("mapsTutorial").getWidget(0); map.clearOverlays(); LatLng markerPos = null; for (final Place place : result) { Location coordinates = place.getCoordinates(); markerPos = LatLng.newInstance(coordinates.getLatitude(), coordinates.getLongitude()); // Add a marker MarkerOptions options = MarkerOptions.newInstance(); options.setTitle(place.getAddress()); Marker marker = new Marker(markerPos, options); final LatLng currMarkerPos = markerPos; marker.addMarkerClickHandler( new MarkerClickHandler() { public void onClick(MarkerClickEvent event) { PlaceFormatter places = new PlaceFormatter(); InfoWindowContent wnd = new InfoWindowContent(places.format(place)); wnd.setMaxWidth(200); map.getInfoWindow().open(currMarkerPos, wnd); } }); map.addOverlay(marker); } if (markerPos != null) { map.setCenter(markerPos); map.setZoomLevel(12); } } }); } } // Add a handler to send the name to the server MyHandler handler = new MyHandler(); searchButton.addClickHandler(handler); nameField.addKeyUpHandler(handler); final Button startFetching = new Button("Fetch"); RootPanel.get("startFetchingContainer").add(startFetching); startFetching.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { adminService.checkDataSources( new AsyncCallback<AdminResponse>() { public void onFailure(Throwable caught) { notification.handleFailure(caught); } public void onSuccess(AdminResponse result) { notification.show("Coolio", "Everything is cool", ""); }; }); } }); }
private void configureInputFields() { TextBox nameTBox = new TextBox(); TextBox locTBox = new TextBox(); TextBox dateTBox = new TextBox(); TextBox startTimeTBox = new TextBox(); TextBox endTimeTBox = new TextBox(); TextArea descTBox = new TextArea(); userCellList = configureUserList(); if (!isEdit) { // Add default name, location, and date text for new Event nameTBox.setText("Enter an event name (eg. Team Meeting)"); locTBox.setText("Enter a location (eg. Ohio Union)"); descTBox.setText("Enter a description"); Integer hr = CalendarWidget.getHourFromRow(srcRow); // Use the srcRow to identify which hour was selected Constants.logger.severe("CREATEEVENTVIEW.JAVA: HOUR: " + hr); String amPm = CalendarWidget.getAmPm(hr); startTimeTBox.setText(hr + ":00" + amPm); // Make sure am/pm and 12-1 cases are being set correctly if (hr == 11) { endTimeTBox.setText("12:00pm"); } else if (hr == 12) { endTimeTBox.setText("1:00pm"); } else { endTimeTBox.setText((hr + 1) + ":00" + amPm); } // Use the srcCol to identify which day was selected Constants.logger.severe("CREATEEVENTVIEW.JAVA: DAY: " + CalendarWidget.getDayFromCol(srcCol)); String month = CalendarWidget.getCurrentMonthNum().toString(); String day = CalendarWidget.getDayFromCol(srcCol).toString(); String dateStr = CalendarWidget.getCurrentMonthNum() + "/" + day + "/" + CalendarWidget.getCurrentYear2(); Constants.logger.severe("CREATEEVENTVIEW.JAVA: Date set to: " + dateStr); dateTBox.setText(dateStr); } else { Constants.logger.severe( "CREATEEVENTVIEW: CELL SOURCE FOR CREATE EVENT HAS ROW, COL: " + srcRow + "," + srcCol); nameTBox.setText(eventToEditDetails.getName()); dateTBox.setText(eventToEditDetails.getDate()); startTimeTBox.setText(eventToEditDetails.getStartTime()); endTimeTBox.setText(eventToEditDetails.getEndTime()); locTBox.setText(eventToEditDetails.getLocation()); descTBox.setText(eventToEditDetails.getDescription()); userList.setText(eventToEditDetails.getUserList()); } nameTBox.setWidth("180%"); locTBox.setWidth("180%"); dateTBox.setWidth("180%"); startTimeTBox.setWidth("180%"); endTimeTBox.setWidth("180%"); descTBox.setWidth("180%"); userList.setWidth("180%"); nameTBox.setFocus(true); nameTBox.selectAll(); boxes = new ArrayList<TextBox>(); boxes.add(nameTBox); boxes.add(locTBox); boxes.add(dateTBox); boxes.add(startTimeTBox); boxes.add(endTimeTBox); areas = new ArrayList<TextArea>(); areas.add(descTBox); areas.add(userList); }
/** This is the entry point method. */ public void onModuleLoad() { final Button sendButton = new Button("Send"); final TextBox nameField = new TextBox(); nameField.setText("Patent ID"); final Label errorLabel = new Label(); // We can add style names to widgets sendButton.addStyleName("sendButton"); // Add the nameField and sendButton to the RootPanel // Use RootPanel.get() to get the entire body element RootPanel.get("nameFieldContainer").add(nameField); RootPanel.get("sendButtonContainer").add(sendButton); RootPanel.get("errorLabelContainer").add(errorLabel); // Focus the cursor on the name field when the app loads nameField.setFocus(true); nameField.selectAll(); // Create the popup dialog box final DialogBox dialogBox = new DialogBox(); dialogBox.setText("Remote Procedure Call"); dialogBox.setAnimationEnabled(true); final Button closeButton = new Button("Close"); // We can set the id of a widget by accessing its Element closeButton.getElement().setId("closeButton"); final Label textToServerLabel = new Label(); final HTML serverResponseLabel = new HTML(); final HTML paramsLabel = new HTML(); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.addStyleName("dialogVPanel"); dialogVPanel.add(new HTML("<b>Sending Patent ID to the server:</b>")); dialogVPanel.add(textToServerLabel); dialogVPanel.add(new HTML("<br><b>Patent profile:</b>")); dialogVPanel.add(serverResponseLabel); dialogVPanel.add(new HTML("<br><b>Patent parameters:</b>")); dialogVPanel.add(paramsLabel); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); dialogVPanel.add(closeButton); dialogBox.setWidget(dialogVPanel); // Add a handler to close the DialogBox closeButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { dialogBox.hide(); sendButton.setEnabled(true); sendButton.setFocus(true); } }); // Create a handler for the sendButton and nameField class MyHandler implements ClickHandler, KeyUpHandler { /** Fired when the user clicks on the sendButton. */ public void onClick(ClickEvent event) { sendPatentIdToServer(); } /** Fired when the user types in the nameField. */ public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { sendPatentIdToServer(); } } /** Send the name from the nameField to the server and wait for a response. */ private void sendPatentIdToServer() { // First, we validate the input. errorLabel.setText(""); String textToServer = nameField.getText(); /*if (!FieldVerifier.isValidName(textToServer)) { errorLabel.setText("Please enter at least four characters"); return; }*/ // Then, we send the input to the server. sendButton.setEnabled(false); textToServerLabel.setText(textToServer); serverResponseLabel.setText(""); /* greetingService.greetServer(textToServer, new AsyncCallback<String>() { public void onFailure(Throwable caught) { // Show the RPC error message to the user dialogBox .setText("Remote Procedure Call - Failure"); serverResponseLabel .addStyleName("serverResponseLabelError"); serverResponseLabel.setHTML(SERVER_ERROR); dialogBox.center(); closeButton.setFocus(true); } public void onSuccess(String result) { dialogBox.setText("Remote Procedure Call"); serverResponseLabel .removeStyleName("serverResponseLabelError"); serverResponseLabel.setHTML(result); dialogBox.center(); closeButton.setFocus(true); } });*/ dialogBox.setText("Reading Database..."); serverResponseLabel.addStyleName("loadingLabel"); serverResponseLabel.setHTML("Loading..."); dialogBox.center(); patentService.getInfo( textToServer, new AsyncCallback<HashMap<String, String>>() { public void onFailure(Throwable caught) { // Show the RPC error message to the user dialogBox.setText("Remote Procedure Call - Failure - Patent"); serverResponseLabel.addStyleName("serverResponseLabelError"); serverResponseLabel.setHTML(SERVER_ERROR); dialogBox.center(); closeButton.setFocus(true); } public void onSuccess(HashMap<String, String> resultMap) { dialogBox.setText("Remote Procedure Call"); serverResponseLabel.removeStyleName("serverResponseLabelError"); serverResponseLabel.removeStyleName("loadingLabel"); String id = resultMap.get("id"); String abs = resultMap.get("abstract"); String year = resultMap.get("year"); String displayHTML = "ID: " + id + "<br>Issued Year: " + year + "<br>Abstract: " + abs; serverResponseLabel.setHTML(displayHTML); dialogBox.center(); closeButton.setFocus(true); } }); paramsLabel.addStyleName("loadingLabel"); paramsLabel.setHTML("Loading..."); patentService.getParams( textToServer, new AsyncCallback<HashMap<String, String>>() { public void onFailure(Throwable caught) { // Show the RPC error message to the user dialogBox.setText("Remote Procedure Call - Failure - Patent"); paramsLabel.addStyleName("serverResponseLabelError"); paramsLabel.setHTML(SERVER_ERROR); dialogBox.center(); closeButton.setFocus(true); } public void onSuccess(HashMap<String, String> resultMap) { dialogBox.setText("Remote Procedure Call"); paramsLabel.removeStyleName("serverResponseLabelError"); paramsLabel.removeStyleName("loadingLabel"); String inventors = resultMap.get("inventors"); String nobwdcite = resultMap.get("num_of_bwd_citations"); String originality_USPC = resultMap.get("originality_USPC"); String num_of_assignee_transfer = resultMap.get("num_of_assignee_transfer"); String displayHTML = "Inventors: " + inventors + "<br># of backward citations: " + nobwdcite + "<br>originality_USPC: " + originality_USPC + "<br>num_of_assignee_transfer: " + num_of_assignee_transfer; paramsLabel.setHTML(displayHTML); dialogBox.center(); closeButton.setFocus(true); } }); } } // Add a handler to send the name to the server MyHandler handler = new MyHandler(); sendButton.addClickHandler(handler); nameField.addKeyUpHandler(handler); }
private void setCursorFocusToInputBox() { newSymbolTextBox.setFocus(true); }
/** * Explicitly focus/unfocus this widget. Only one widget can have focus at a time, and the widget * that does will receive all keyboard events. * * @param focused whether this widget should take focus or release it */ public void setFocus(boolean focused) { box.setFocus(focused); }
private void turnNameLabelIntoField() { patternNameField.setText(patternNameLabel.getText()); patternNameField.setVisible(true); patternNameLabel.setVisible(false); patternNameField.setFocus(true); }
@Override public void focus(boolean focus) { textbox.setFocus(true); }
/* (non-Javadoc) * @see net.cbtltd.client.field.AbstractField#setFocus(boolean) */ @Override public void setFocus(boolean focussed) { field.setFocus(focussed); }
@Override public void setFocus(boolean focused) { textBox.setFocus(focused); }
/** This is the entry point method. */ public void onModuleLoad() { final Button sendButton = new Button("Send"); final TextBox nameField = new TextBox(); nameField.setText("Deepanjali"); final Label errorLabel = new Label(); // We can add style names to widgets sendButton.addStyleName("sendButton"); // Add the nameField and sendButton to the RootPanel // Use RootPanel.get() to get the entire body element RootPanel.get("nameFieldContainer").add(nameField); RootPanel.get("sendButtonContainer").add(sendButton); RootPanel.get("errorLabelContainer").add(errorLabel); // Focus the cursor on the name field when the app loads nameField.setFocus(true); nameField.selectAll(); // Create the popup dialog box final DialogBox dialogBox = new DialogBox(); dialogBox.setText("Remote Procedure Call"); dialogBox.setAnimationEnabled(true); final Button closeButton = new Button("Close"); // We can set the id of a widget by accessing its Element closeButton.getElement().setId("closeButton"); final Label textToServerLabel = new Label(); final HTML serverResponseLabel = new HTML(); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.addStyleName("dialogVPanel"); dialogVPanel.add(new HTML("<b>Sending name to the server:</b>")); dialogVPanel.add(textToServerLabel); dialogVPanel.add(new HTML("<br><b>Server replies:</b>")); dialogVPanel.add(serverResponseLabel); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); dialogVPanel.add(closeButton); dialogBox.setWidget(dialogVPanel); // Add a handler to close the DialogBox closeButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { dialogBox.hide(); sendButton.setEnabled(true); sendButton.setFocus(true); } }); // Create a handler for the sendButton and nameField class MyHandler implements ClickHandler, KeyUpHandler { /** Fired when the user clicks on the sendButton. */ public void onClick(ClickEvent event) { sendNameToServer(); } /** Fired when the user types in the nameField. */ public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { sendNameToServer(); } } /** Send the name from the nameField to the server and wait for a response. */ private void sendNameToServer() { // First, we validate the input. errorLabel.setText(""); String textToServer = nameField.getText(); if (!FieldVerifier.isValidName(textToServer)) { errorLabel.setText("Please enter at least four characters"); return; } // Then, we send the input to the server. sendButton.setEnabled(false); textToServerLabel.setText(textToServer); serverResponseLabel.setText(""); greetingService.greetServer( textToServer, new AsyncCallback<String>() { public void onFailure(Throwable caught) { // Show the RPC error message to the user dialogBox.setText("Remote Procedure Call - Failure"); serverResponseLabel.addStyleName("serverResponseLabelError"); serverResponseLabel.setHTML(SERVER_ERROR); dialogBox.center(); closeButton.setFocus(true); } public void onSuccess(String result) { dialogBox.setText("Remote Procedure Call"); serverResponseLabel.removeStyleName("serverResponseLabelError"); serverResponseLabel.setHTML(result); dialogBox.center(); closeButton.setFocus(true); } }); } } // Add a handler to send the name to the server MyHandler handler = new MyHandler(); sendButton.addClickHandler(handler); nameField.addKeyUpHandler(handler); }
private void loadStockWatcher() { // Set up sign out hyperlink. signOutLink.setHref(loginInfo.getLogoutUrl()); // Create table for tasks. tasksFlexTable.setText(0, 0, "Tâche"); tasksFlexTable.setText(0, 1, "DeadLine"); tasksFlexTable.setText(0, 2, "Priorité"); tasksFlexTable.setText(0, 3, "Remove"); // Add styles to elements in the stock list table. tasksFlexTable.getRowFormatter().addStyleName(0, "watchListHeader"); tasksFlexTable.addStyleName("watchList"); tasksFlexTable.getCellFormatter().addStyleName(0, 1, "watchListNumericColumn"); tasksFlexTable.getCellFormatter().addStyleName(0, 2, "watchListNumericColumn"); tasksFlexTable.getCellFormatter().addStyleName(0, 3, "watchListRemoveColumn"); loadStocks(); // Assemble Add Task panel. addPanel.add(newTaskTextBox); addPanel.add(addTaskButton); addPanel.addStyleName("addPanel"); // Assemble Main panel. errorMsgLabel.setStyleName("errorMessage"); errorMsgLabel.setVisible(false); mainPanel.add(errorMsgLabel); mainPanel.add(signOutLink); mainPanel.add(tasksFlexTable); mainPanel.add(addPanel); mainPanel.add(lastUpdatedLabel); // Associate the Main panel with the HTML host page. RootPanel.get("tasksList").add(mainPanel); // Move cursor focus to the input box. newTaskTextBox.setFocus(true); // Setup timer to refresh list automatically. Timer refreshTimer = new Timer() { @Override public void run() { refreshWatchList(); } }; refreshTimer.scheduleRepeating(REFRESH_INTERVAL); // Listen for mouse events on the Add button. addTaskButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { addTask(); } }); // Listen for keyboard events in the input box. newTaskTextBox.addKeyPressHandler( new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { if (event.getCharCode() == KeyCodes.KEY_ENTER) { addTask(); } } }); }
public NewClasspagePopupView() { this.res = NewClasspagePopupCBundle.INSTANCE; res.css().ensureInjected(); setWidget(uiBinder.createAndBindUi(this)); // this.getElement().getStyle().setWidth(450,Unit.PX); btnCancel.addClickHandler(new CloseExistsClickHandler()); btnAdd.addClickHandler(new AddExistsClickHandler()); classpageTitleTxt.getElement().setAttribute("placeholder", i18n.GL1124()); classpageTitleTxt.getElement().setAttribute("maxlength", "50"); classpageTitleTxt.getElement().setId("txtClassPageTitle"); StringUtil.setAttributes(classpageTitleTxt, true); bodyConatiner.getElement().getStyle().setPadding(15, Unit.PX); titlePanel.getElement().getStyle().setMarginBottom(10, Unit.PX); btnAdd.getElement().setId("btnAdd"); btnAdd.setText(i18n.GL0745()); btnAdd.getElement().setAttribute("alt", i18n.GL0745()); btnAdd.getElement().setAttribute("title", i18n.GL0745()); btnCancel.setText(i18n.GL0142()); btnCancel.getElement().setId("btnCancel"); btnCancel.getElement().setAttribute("alt", i18n.GL0142()); btnCancel.getElement().setAttribute("title", i18n.GL0142()); titlePanel.getElement().setInnerText(i18n.GL0318()); titlePanel.getElement().setId("pnlTitle"); titlePanel.getElement().setAttribute("alt", i18n.GL0318()); titlePanel.getElement().setAttribute("title", i18n.GL0318()); headerPanel.getElement().setInnerText(i18n.GL0747()); headerPanel.getElement().setId("pnlHeader"); headerPanel.getElement().setAttribute("alt", i18n.GL0747()); headerPanel.getElement().setAttribute("title", i18n.GL0747()); mandatoryClasspageTitleLbl.setText(i18n.GL0746()); mandatoryClasspageTitleLbl.getElement().setId("lblMandatoryClasspageTitle"); mandatoryClasspageTitleLbl.getElement().setAttribute("alt", i18n.GL0746()); mandatoryClasspageTitleLbl.getElement().setAttribute("title", i18n.GL0746()); classpageTitleTxt.addBlurHandler( new BlurHandler() { @Override public void onBlur(BlurEvent event) { Map<String, String> parms = new HashMap<String, String>(); parms.put("text", classpageTitleTxt.getText()); AppClientFactory.getInjector() .getResourceService() .checkProfanity( parms, new SimpleAsyncCallback<Boolean>() { @Override public void onSuccess(Boolean value) { boolean isHavingBadWords = value; if (value) { classpageTitleTxt.getElement().getStyle().setBorderColor("orange"); mandatoryClasspageTitleLbl.setText(i18n.GL0554()); mandatoryClasspageTitleLbl.setVisible(true); } else { classpageTitleTxt.getElement().getStyle().clearBackgroundColor(); classpageTitleTxt.getElement().getStyle().setBorderColor("#ccc"); mandatoryClasspageTitleLbl.setVisible(false); } } }); } }); classpageTitleTxt.addKeyUpHandler(new TitleKeyUpHandler()); setModal(true); Window.enableScrolling(false); AppClientFactory.fireEvent(new SetHeaderZIndexEvent(98, false)); mandatoryClasspageTitleLbl.setVisible(false); // panelLoading.setVisible(false); panelPleaseWait.setVisible(false); panelLoading.setText(i18n.GL0122()); panelControls.setVisible(true); show(); center(); classpageTitleTxt.setFocus(true); panelLoading.getElement().setId("pnlLoading"); panelControls.getElement().setId("pnlControls"); }
/** * Sets the focus on the text box. * * <p> * * @param focused signals if the focus should be set */ public void setFocus(boolean focused) { m_textbox.setFocus(focused); }