private void resetUI() { dbInstructionArea.setText(""); dbInstructionArea.setVisible(false); includeDbScriptBox.setValue(false); selectionListbox.clear(); selectionWidget.reset(); notificationEmailBox.setText(""); }
@Override public void onClick(ClickEvent event) { if (event.getSource() == includeDbScriptBox) { if (includeDbScriptBox.getValue()) { dbInstructionArea.setValue(""); dbInstructionArea.setVisible(true); } else { dbInstructionArea.setValue(""); dbInstructionArea.setVisible(false); } } else if (event.getSource() == addSurveyButton) { String group = selectionWidget.getSelectedSurveyGroupName(); List<String> name = selectionWidget.getSelectedSurveyNames(); List<Long> ids = selectionWidget.getSelectedSurveyIds(); for (int i = 0; i < name.size(); i++) { boolean alreadyThere = false; for (int j = 0; j < selectionListbox.getItemCount(); j++) { if (selectionListbox.getValue(j).equals(ids.get(i).toString())) { alreadyThere = true; break; } } if (!alreadyThere) { selectionListbox.addItem(group + ": " + name.get(i), ids.get(i).toString()); } } } else if (event.getSource() == removeButton) { List<Integer> victimList = new ArrayList<Integer>(); for (int i = 0; i < selectionListbox.getItemCount(); i++) { if (selectionListbox.isItemSelected(i)) { victimList.add(i); } } if (victimList.size() > 0) { // remove the items in descending order so we don't have to // worry about adjusting indexes as we remove Collections.sort(victimList); for (int i = victimList.size() - 1; i >= 0; i--) { selectionListbox.removeItem(victimList.get(i)); } } } else if (event.getSource() == generateFileButton) { List<Long> idList = new ArrayList<Long>(); for (int i = 0; i < selectionListbox.getItemCount(); i++) { idList.add(new Long(selectionListbox.getValue(i))); } List<String> errors = validate(); if (errors.size() == 0) { surveyService.generateBootstrapFile( idList, dbInstructionArea.getText(), notificationEmailBox.getText(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { MessageDialog errDia = new MessageDialog( TEXT_CONSTANTS.error(), TEXT_CONSTANTS.errorTracePrefix() + " " + caught.getLocalizedMessage()); errDia.showCentered(); } @Override public void onSuccess(Void result) { MessageDialog dia = new MessageDialog( TEXT_CONSTANTS.requestSubmitted(), TEXT_CONSTANTS.emailWillBeSent()); dia.showCentered(); resetUI(); } }); } else { StringBuilder builder = new StringBuilder(TEXT_CONSTANTS.pleaseCorrect() + "<br><ul>"); for (String e : errors) { builder.append("<li>").append(e).append("</li>"); } builder.append("</ul>"); MessageDialog dia = new MessageDialog(TEXT_CONSTANTS.inputError(), builder.toString()); dia.showCentered(); } } }