private List<Integer> getSelection() {
   List<Integer> selectedValues = new ArrayList<Integer>();
   for (int i = 0, l = listBox.getItemCount(); i < l; i++) {
     if (listBox.isItemSelected(i)) {
       selectedValues.add(i);
     }
   }
   return selectedValues;
 }
 public LinkedList<Long> getSelectedItemsWeights() {
   LinkedList<Long> selectedItems = new LinkedList<Long>();
   for (int i = 0; i < weights.getItemCount(); i++) {
     if (weights.isItemSelected(i)) {
       selectedItems.add((long) i);
     }
   }
   return selectedItems;
 }
 private boolean hasMultiselection(ListBox listBox) {
   ArrayList<Integer> selectedIndices = new ArrayList<Integer>();
   for (int i = 0; i < listBox.getItemCount(); i++) {
     if (listBox.isItemSelected(i)) {
       selectedIndices.add(i);
     }
   }
   return selectedIndices.size() > 1;
 }
  private List<String> getActiveCBCs() {

    List<String> _cbcNames = new ArrayList<String>();

    for (int i = 0; i < cbcList_.getItemCount(); i++) {
      if (cbcList_.isItemSelected(i)) {
        _cbcNames.add(cbcList_.getItemText(i));
      }
    }
    return _cbcNames;
  }
  private LinkedList<Integer> getSelectedItems(final ListBox listBox) {
    final LinkedList<Integer> selectedItems = new LinkedList<Integer>();

    for (int i = listBox.getItemCount() - 1; i >= 0; i--) {

      if (listBox.isItemSelected(i)) {
        selectedItems.add(i);
      }
    }
    return selectedItems;
  }
 public List<Integer> getSelectedApplicationIds() {
   if (applications.getItemCount() == 0) {
     return group.getApplicationIds();
   }
   List<Integer> result = new ArrayList<Integer>(applications.getItemCount());
   for (int index = 0; index < applications.getItemCount(); index++) {
     if (applications.isItemSelected(index)) {
       int id = Integer.parseInt(applications.getValue(index));
       result.add(id);
     }
   }
   return result;
 }
 public List<Integer> getSelectedRegionIds() {
   GWT.log("get selected region ids");
   if (regions.getItemCount() == 0) {
     return group.getApplicationIds();
   }
   List<Integer> result = new ArrayList<Integer>(regions.getItemCount());
   for (int index = 0; index < regions.getItemCount(); index++) {
     if (regions.isItemSelected(index)) {
       int id = Integer.parseInt(regions.getValue(index));
       result.add(id);
     }
   }
   GWT.log("get selected region ids" + result);
   return result;
 }
Example #8
0
 public Object getValue() {
   Object value = null;
   if (widget.isMultipleSelect()) {
     List selecteds = new ArrayList();
     for (int i = 0; i < widget.getItemCount(); i++) {
       if (widget.isItemSelected(i)) {
         selecteds.add(widget.getValue(i));
       }
     }
     value = selecteds;
   } else {
     if (widget.getSelectedIndex() > -1) {
       value = widget.getValue(widget.getSelectedIndex());
     }
   }
   return value;
 }
  @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();
      }
    }
  }