List of usage examples for com.google.gwt.user.client.ui Button Button
protected Button(com.google.gwt.dom.client.Element element)
From source file:be.progs.routeshare.client.RouteShareMenu.java
License:Open Source License
public RouteShareMenu(MapPresenter mapPresenter) { initWidget(UI_BINDER.createAndBindUi(this)); setWidth("200px"); title.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { setOpen(!open);/*from w w w . ja v a2 s. c o m*/ } }); GeometryEditor editor = INJECTOR.getGeometryEditorFactory().create(mapPresenter); GeometryEditService editService = editor.getEditService(); GeometryToShapeConverter geometryToShapeConverter = new GeometryToShapeConverter(editService); Button createButton = new Button("Create route"); createButton.addClickHandler(new CreateRouteClickHandler(editService, geometryToShapeConverter)); contentPanel.add(createButton); }
From source file:bingo.client.Bingo.java
License:Open Source License
/** * This is the entry point method./* ww w .ja v a 2 s .c o m*/ */ public void onModuleLoad() { Label titleLabel = new Label(); titleLabel.setText(strings.title()); RootPanel.get("title").add(titleLabel); // This is the general notification text box RootPanel.get("message").add(message); // Cheking if the user has already an user id final String cookie = Cookies.getCookie(COOKIE_ID); // Validating the cookie bingoService.statusUserId(cookie, new AsyncCallback<Integer>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); Cookies.removeCookie(COOKIE_ID); } @Override public void onSuccess(Integer status) { // TODO: Control the logged status (I should not get a user if s/he is already logged) if (status.intValue() == BingoService.NO_LOGGED || status.intValue() == BingoService.LOGGED) { bingoService.getUserId(new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { message.setText(strings.errorUserCreation()); } @Override public void onSuccess(String result) { userId = result; } }); message.setHTML(""); // Showing image to enter ImageResource imageResource = BingoResources.INSTANCE.entry(); Image entryImage = new Image(imageResource.getSafeUri()); RootPanel.get("buttons").add(entryImage); // Selecting behavior (admin / voter) HorizontalPanel entryPoint = new HorizontalPanel(); entryPoint.setStyleName("mainSelectorPanel"); entryPoint.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); entryPoint.setSpacing(50); // // CREATING A BINGO // VerticalPanel leftPanel = new VerticalPanel(); leftPanel.setStyleName("selectorPanel"); Label leftPanelTitle = new Label(); leftPanelTitle.setStyleName("selectorPanelTitle"); leftPanelTitle.setText(strings.leftPanelTitle()); leftPanel.add(leftPanelTitle); leftPanel.setCellHorizontalAlignment(leftPanelTitle, HasHorizontalAlignment.ALIGN_CENTER); Grid leftSubPanel = new Grid(2, 2); leftSubPanel.setWidget(0, 0, new Label(strings.createBingoName())); final TextBox bingoNameBox = new TextBox(); leftSubPanel.setWidget(0, 1, bingoNameBox); leftSubPanel.setWidget(1, 0, new Label(strings.createBingoPassword())); final PasswordTextBox bingoPasswordBox = new PasswordTextBox(); leftSubPanel.setWidget(1, 1, bingoPasswordBox); leftPanel.add(leftSubPanel); final Button createButton = new Button("Create"); createButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { bingoService.createBingo(userId, bingoNameBox.getText(), bingoPasswordBox.getText(), new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(final String gameId) { final BingoGrid bingoGrid = new BingoGrid(); initAdminGrid(userId, bingoGrid, false); RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); message.setText(strings.welcomeMessageCreation()); // Setting the cookie Date expirationDate = new Date(); expirationDate.setHours(expirationDate.getHours() + EXPIRATION_VALUE); Cookies.setCookie(COOKIE_ID, userId, expirationDate); } }); } }); leftPanel.add(createButton); leftPanel.setCellHorizontalAlignment(createButton, HasHorizontalAlignment.ALIGN_CENTER); entryPoint.add(leftPanel); // // JOINING // VerticalPanel rightPanel = new VerticalPanel(); rightPanel.setStyleName("selectorPanel"); Label rightPanelTitle = new Label(); rightPanelTitle.setStyleName("selectorPanelTitle"); rightPanelTitle.setText(strings.rightPanelTitle()); rightPanel.add(rightPanelTitle); rightPanel.setCellHorizontalAlignment(rightPanelTitle, HasHorizontalAlignment.ALIGN_CENTER); Grid rightSubPanel = new Grid(2, 2); rightSubPanel.setWidget(0, 0, new Label(strings.joinToBingoName())); final ListBox joinExistingBingoBox = new ListBox(); bingoService.getBingos(new AsyncCallback<String[][]>() { @Override public void onFailure(Throwable caught) { joinExistingBingoBox.addItem(strings.noBingos()); } @Override public void onSuccess(String[][] result) { if (result == null) { joinExistingBingoBox.addItem(strings.noBingos()); } else { for (int i = 0; i < result.length; i++) { String gameName = result[i][0]; String gameId = result[i][1]; joinExistingBingoBox.addItem(gameName, gameId); } } } }); rightSubPanel.setWidget(0, 1, joinExistingBingoBox); rightSubPanel.setWidget(1, 0, new Label(strings.joinToBingoPassword())); final PasswordTextBox joinBingoPasswordBox = new PasswordTextBox(); rightSubPanel.setWidget(1, 1, joinBingoPasswordBox); rightPanel.add(rightSubPanel); final Button joinButton = new Button("Join"); joinButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { int index = joinExistingBingoBox.getSelectedIndex(); if (index < 0) message.setText(strings.noSelectedItem()); else { final String gameId = joinExistingBingoBox.getValue(index); if (gameId == null) message.setText(strings.noSelectedItem()); else { bingoService.joinBingo(userId, gameId, joinBingoPasswordBox.getText(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(Void result) { final BingoGrid bingoGrid = new BingoGrid(); initUserGrid(bingoGrid); RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); message.setText(strings.welcomeMessageJoin()); // Setting the cookie Date expirationDate = new Date(); expirationDate .setHours(expirationDate.getHours() + EXPIRATION_VALUE); Cookies.setCookie(COOKIE_ID, userId, expirationDate); } }); } } } }); rightPanel.add(joinButton); rightPanel.setCellHorizontalAlignment(joinButton, HasHorizontalAlignment.ALIGN_CENTER); entryPoint.add(rightPanel); RootPanel.get("bingoTable").add(entryPoint); } else if (status.intValue() == BingoService.ADMIN) { message.setText("Detected cookie: " + cookie + " as admin"); userId = cookie; bingoService.statusBingo(userId, new AsyncCallback<Integer>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(Integer result) { int status = result.intValue(); final BingoGrid bingoGrid = new BingoGrid(); if (status == BingoService.RUNNING) { initAdminGrid(userId, bingoGrid, false); message.setText(strings.welcomeMessageCreation()); } else if (status == BingoService.FINISHED) { initAdminGrid(userId, bingoGrid, true); message.setText(strings.finishMessage()); } RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); } }); } else if (status.intValue() == BingoService.PARTICIPANT) { message.setText("Detected cookie: " + cookie + " as participant"); userId = cookie; final BingoGrid bingoGrid = new BingoGrid(); initUserGrid(bingoGrid); updateUserGrid(bingoGrid, null); RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); } } }); }
From source file:burrito.client.crud.CrudEntityEdit.java
License:Apache License
public CrudEntityEdit(final CrudEntityDescription desc, Long copyFromId) { super();// www.java 2 s . c om this.desc = desc; this.copyFromId = copyFromId; init(); setSaveCancelListener(new SaveCancelListener() { public void onSave() { History.newItem(desc.getEntityName()); } public void onPartialSave(String warning) { History.newItem(desc.getEntityName()); } public void onCancel() { History.newItem(desc.getEntityName()); } }); getSaveButton().setEnabled(true); if (desc.isPreviewable()) { Button previewButton = new Button(messages.preview()); previewButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { service.getPreviewPayload(updateCrudEntityDescription(), new AsyncCallback<CrudPreviewPayload>() { public void onSuccess(CrudPreviewPayload payload) { CrudPreviewOpener opener = new CrudPreviewOpener(payload.getPreviewUrl(), payload.getPreviewData()); opener.open(); } public void onFailure(Throwable caught) { displayErrorMessage(messages.previewFailed()); } }); } }); addExtraButton(previewButton); } focus(); }
From source file:burrito.client.crud.widgets.StringListWidget.java
License:Apache License
private void addTag(String tagText) { final Button tag = new Button(tagText.trim()); tag.setTitle(labels.clickToDeleteTag()); tag.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { deleteTag(tag);/*from w w w . j a v a 2 s .c o m*/ } }); tag.setStyleName("k5-StringListWidget-TagPanel-TagButton"); tagsPanel.add(tag); }
From source file:burrito.client.widgets.inputfield.ListInputField.java
License:Apache License
public ListInputField(boolean required, boolean unique) { this.required = required; this.unique = unique; inputWrapper = new FlowPanel(); inputWrapper.add(field);/*from www . j a va 2 s .c o m*/ addButton = new Button(messages.add()); addButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (validateInputField()) { model.add(parseValue(field.getText())); onChange(model); field.setText(""); updateModelObjects(); } } }); if (required) { requiredStar = new Label("*"); inputWrapper.add(requiredStar); } inputWrapper.add(addButton); validationError = new Label(""); inputWrapper.add(validationError); wrapper.add(inputWrapper); listWrapper = new FlowPanel(); listWrapper.addStyleName("k5-ListInputField-listwrapper"); wrapper.add(listWrapper); initWidget(wrapper); wrapper.addStyleName("k5-ListInputField"); }
From source file:burrito.client.widgets.panels.table.Table.java
License:Apache License
/** * Creates a new table. Don't forget to make calls to addHeader(), * addCellRenderer() and render() after creating the object. * /* www .j a v a 2s . c o m*/ * @param numberOfColumns * The number of columns. Only count those that you will specify * (i.e. Don't count the select checkbox as a column) * @param rowsSelectable * true if rows should be selectable. This will work in * combination with addBatchAction() * @param rowsEditable * true if an edit-link should be rendered next to each row * @param rowsOrderable * true if rows should be able to re-order */ public Table(int numberOfColumns, boolean rowsSelectable, boolean rowsEditable, boolean rowsOrderable) { this.rowsSelectable = rowsSelectable; this.rowsEditable = rowsEditable; this.numberOfModelColumns = numberOfColumns; this.numberOfColumns = numberOfModelColumns; this.rowsOrderable = rowsOrderable; if (rowsSelectable) { this.numberOfColumns++; } if (rowsEditable) { this.numberOfColumns++; } if (rowsOrderable) { this.numberOfColumns++; } this.table = new Grid(1, this.numberOfColumns); this.loadingLabel = new Label(messages.loading()); FlowPanel centerWrapper = new FlowPanel(); centerWrapper.add(loadingLabel); centerWrapper.add(table); Button searchButton = new Button(messages.searchButton()); searchButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { load(0); } }); Button resetButton = new Button(messages.resetButton()); resetButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { filterText.setValue(""); load(0); } }); search.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE); search.setHorizontalAlignment(VerticalPanel.ALIGN_LEFT); search.add(new Label(messages.search())); search.add(filterText); search.add(searchButton); search.add(resetButton); search.setStyleName("k5-table-searchbox"); search.setVisible(false); centerWrapper.add(search); batchJobsWrapper.addStyleName("batchJobs"); dock.add(pageController, DockPanel.NORTH); dock.add(centerWrapper, DockPanel.CENTER); batchJobsWrapper.add(batchJobs); dock.add(batchJobsWrapper, DockPanel.SOUTH); pageController.addPageControllerHandler(new PageControllerHandler() { @Override public void loadPage(int zeroIndexedPage) { load(zeroIndexedPage); } }); initWidget(dock); this.setStyleName("k5-Table"); }
From source file:burrito.client.widgets.panels.table.Table.java
License:Apache License
/** * Adds a batch action to this table. A batch action is performed on * selected rows in the table.// w w w. j a v a 2 s . c om * * @param batchAction */ public void addBatchAction(final BatchAction<T> batchAction) { batchJobs.add(new VerticalSpacer(10)); HorizontalPanel hp = new HorizontalPanel(); hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); final Button b = new Button(batchAction.getButtonText()); ClickHandler ch = new ClickHandler() { @Override public void onClick(ClickEvent event) { final List<T> selected = getSelectedRows(); if (selected == null || selected.isEmpty()) { return; } batchAction.performAction(selected, new AsyncCallback<Void>() { @Override public void onSuccess(Void result) { b.setEnabled(true); b.removeStyleName("loading"); infoPopup.setTextAndShow(batchAction.getSuccessText(selected)); load(pageController.getCurrentPage()); } @Override public void onFailure(Throwable caught) { b.setEnabled(true); b.removeStyleName("loading"); throw new RuntimeException(caught); } }); b.setEnabled(false); b.addStyleName("loading"); } }; b.addClickHandler(ch); hp.add(b); hp.add(new Label(batchAction.getDescription())); batchJobs.add(hp); }
From source file:bwbv.rlt.client.ui.HeaderPane.java
License:Apache License
/** * Build this conditionally based on isLoggedIn * @param isLoggedIn/* w ww .j a v a 2 s.co m*/ * @return */ private HorizontalPanel buildHeaderPanel(boolean isLoggedIn) { HorizontalPanel panel = new HorizontalPanel(); panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); if (isLoggedIn) { panel.setSpacing(10); panel.add(new Label("Welcome " + clientState.getUserName())); Button logoutButton = new Button("Logout"); logoutButton.setStyleName("LogoutButton"); logoutButton.addClickListener(new ClickListener() { public void onClick(Widget sender) { logout(); } }); panel.add(logoutButton); } else { Button loginButon = new Button("Login"); loginButon.setStyleName("LoginButton"); loginButon.addClickListener(new ClickListener() { public void onClick(Widget sender) { showNewUserNameRequestPopupPanel(); } }); panel.add(loginButon); } return panel; }
From source file:bwbv.rlt.client.ui.HeaderPane.java
License:Apache License
private void showNewUserNameRequestPopupPanel() { confirmPopup = new PopupPanel(false, true); VerticalPanel panel = new VerticalPanel(); // panel.add(new Label("What is your login Name?")); // panel.add(textBox); Grid grid = new Grid(2, 2); grid.setText(0, 0, "Benutzer:"); final TextBox textBox = new TextBox(); grid.setWidget(0, 1, textBox);// w ww.j a va 2 s.c o m grid.setText(1, 0, "Passwort:"); final PasswordTextBox pwdBox = new PasswordTextBox(); grid.setWidget(1, 1, pwdBox); panel.add(grid); Button ok = new Button("OK"); ok.addClickListener(new ClickListener() { public void onClick(Widget w) { confirmPopup.hide(); login(textBox.getText(), pwdBox.getText()); } }); panel.add(ok); confirmPopup.add(panel); confirmPopup.center(); textBox.setFocus(true); confirmPopup.show(); }
From source file:ca.farez.sortsomething.client.Sortsomething.java
License:Apache License
public void onModuleLoad() { // Boundary panel message on startup callNumsHere = new Label("Call Numbers will display here!"); callNumsHere.addStyleName("callNumsHere"); // Boundary panel setup boundaryPanel.setPixelSize(1000, 200); boundaryPanel.addStyleName("boundaryPanel"); boundaryPanel.getElement().getStyle().setProperty("position", "relative"); boundaryPanel.add(callNumsHere);//from w w w . ja va2 s . c o m // Call number panel setup cnPanel.addStyleName("cnPanel"); // Setting up widget drag controller final PickupDragController widgetDragController = new PickupDragController(boundaryPanel, false); widgetDragController.setBehaviorMultipleSelection(false); //widgetDragController.addDragHandler(demoDragHandler); // Setting up HP drag controller HorizontalPanelDropController widgetDropController = new HorizontalPanelDropController(cnPanel); widgetDragController.registerDropController(widgetDropController); // scoreMe button setup scoreMeButton.setPixelSize(120, 60); scoreMeButton.setVisible(false); scoreMeButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // Clear all of Quiz's data structures to avoid null pointers and index out of bounds newQuiz.clean(); // Finds the position on buttons/callnumbers as arranged by users int numOfButtons = cnPanel.getWidgetCount(); setUserOrder(numOfButtons); // Compute our inter-sorted buckets newQuiz.builtInSortQuiz(); // Set the bucket indices for fine sorting later newQuiz.fillBucketCollection(newQuiz.callNums.size()); newQuiz.printBucketCollection(); // Compute our and intra-sorted buckets newQuiz.callNumberIntraBucketSorting(); // Compare the two and find mistakes (if any) //System.out.println("Mistakes BEFORE compare() = " + newQuiz.getMistakes()); int mistakes = newQuiz.compare(); //System.out.println("Mistakes AFTER compare() = " + mistakes); if (mistakes > 0) { if (mistakes == 1) { mistakeLabel = new Label(mistakes + " mistake"); } else mistakeLabel = new Label(mistakes + " mistakes!"); mistakeLabel.addStyleName("yesMistakes"); } else { mistakeLabel = new Label("Correct Solution!"); mistakeLabel.addStyleName("noMistakes"); } if (bottomPanel.getWidgetCount() == 4) { bottomPanel.remove(3); } bottomPanel.add(mistakeLabel); } }); // startQuiz button setup startQuizButton.setPixelSize(120, 60); startQuizButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { scoreMeButton.setVisible(true); String input = inputArea.getText().toUpperCase(); if (input == null || input.trim().equals("")) { // Checking for empty strings Window.alert("Please type something in the text box!"); } else { int newCallNums = newQuiz.populate(input); // Reassemble call number panel only if there are NEW call numbers! if (newCallNums > 0) { cnPanel.clear(); AsyncCallback<Void> callback = autoQuizVoidSetup(); // TODO figure out how to switch to next panel if we've reached the right most side Button cnb; for (int i = 0; i < newQuiz.callNums.size(); i++) { // Storing string in db asynchronously autoQuizSvc.addString(newQuiz.callNums.get(i), callback); // Adding call number to the UI cnb = new Button(newQuiz.callNums.get(i)); cnb.addStyleName("gwt-Button"); cnPanel.add(cnb); cnb.setPixelSize(60, 90); widgetDragController.makeDraggable(cnb); } } callNumsHere.removeFromParent(); if (bottomPanel.getWidgetCount() == 4) mistakeLabel.removeFromParent(); if (scoreMeButton.getParent() != bottomPanel) bottomPanel.add(scoreMeButton); } } }); // generateQuizButton setup generateQuizButton.setPixelSize(120, 60); generateQuizButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { String input = generateQuizTextBox.getText(); if (input == null || input.trim().equals("")) { // Checking for empty strings Window.alert("Please type something in the text box!"); } else { int size = Integer.parseInt(input); if (size <= 0) { // Checking for invalid size Window.alert("Please enter a valid quiz size!"); } else { AsyncCallback<String> callback = autoQuizStringSetup(); // Making the call to the auto quiz generation service autoQuizSvc.getQuiz(size, callback); String randomQuiz = generateRandomQuiz(size); inputArea.setText(randomQuiz); } } } }); // newQuizButton Setup newQuizButton.setPixelSize(120, 60); newQuizButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { cnPanel.clear(); newQuiz.clean(); inputArea.setText(""); newQuiz.callNums.clear(); // The clean() call above doesn't clear the entered call number list if (boundaryPanel.getWidgetCount() > 1) { boundaryPanel.remove(1); } boundaryPanel.add(callNumsHere); if (bottomPanel.getWidgetCount() == 4) mistakeLabel.removeFromParent(); scoreMeButton.removeFromParent(); } }); // inputBox text box setup inputArea.setFocus(true); inputArea.setText("Enter one call number per line. For example,\n\n" + "A100 TA2 2006\n" + "PC2600 Z68 2012\n" + "G53 XN1 2011\n"); inputArea.addStyleName("inputArea"); inputArea.setHeight("200px"); inputArea.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (inputAreaOnClickCount == 0) { inputArea.setText(""); } inputAreaOnClickCount++; } }); // Populating Boundary Panel boundaryPanel.add(cnPanel); // Top panel setup topPanel.add(inputArea); topPanel.add(boundaryPanel); // Bottom panel setup bottomPanel.add(startQuizButton); bottomPanel.add(newQuizButton); bottomPanel.add(scoreMeButton); bottomPanel.addStyleName("bottomPanel"); // Populating Manual Quiz Panel manualQuizPanel.add(topPanel); manualQuizPanel.add(bottomPanel); manualQuizPanel.addStyleName("manualQuizPanel"); // Generate Quiz setup generateQuizTextBox.getElement().setPropertyString("placeholder", "Enter the size of the quiz"); // Populating Generated Quiz Panel autoQuizPanel.add(generateQuizTextBox); autoQuizPanel.add(generateQuizButton); // Populating Main Panel tabPanel.add(autoQuizPanel, "Generate Quiz Automatically"); tabPanel.add(manualQuizPanel, "Create Quiz Manually"); tabPanel.selectTab(1); // Adding panels & buttons to Root RootPanel.get().add(tabPanel); }