/**
   * @param assignment the assignment for which the Listbox should set the fraction
   * @param res the result of the assignment for which the Listbox should set the fraction
   * @return a single select ListBox containing all possible fractions as defined in {@link
   *     Assignment#FRACTIONS} setting the fraction for a result in this assignment when they are
   *     changed
   */
  ListBox getFractionsLB(final Assignment assignment, final Result res) {
    final ListBox fractions = new ListBox();
    fractions.setMultipleSelect(false);
    for (int j = 0; j < Assignment.FRACTIONS.length; j++) {
      fractions.addItem(
          app.getKernel().format(Assignment.FRACTIONS[j] * 100, StringTemplate.defaultTemplate));
    }

    fractions.addChangeHandler(
        new ChangeHandler() {

          public void onChange(ChangeEvent event) {
            assignment.setFractionForResult(
                res, Assignment.FRACTIONS[fractions.getSelectedIndex()]);
          }
        });

    fractions.addAttachHandler(
        new Handler() {

          public void onAttachOrDetach(AttachEvent event) {
            fractions.setSelectedIndex(
                Arrays.binarySearch(Assignment.FRACTIONS, assignment.getFractionForResult(res)));
          }
        });

    return fractions;
  }
Esempio n. 2
0
  @SuppressWarnings("deprecation")
  @Test
  public void checkIsMultipleSelect() {
    ListBox listBox = new ListBox(false);
    Assert.assertEquals(false, listBox.isMultipleSelect());

    listBox.setMultipleSelect(true);
    Assert.assertEquals(true, listBox.isMultipleSelect());
  }
  public DualListBoxDevelopper(final Long idProject) {
    final HorizontalPanel horizontalPanel = new HorizontalPanel();
    listbox1.setTitle("Développeur disponible");
    listbox1.setMultipleSelect(true);
    listbox2.setMultipleSelect(true);
    listbox2.setTitle("Développeur affecté au projet");
    // récupération des informations du projet
    projetClient.getProject(
        idProject,
        new MethodCallback<Project>() {

          @Override
          public void onSuccess(final Method method, final Project project) {
            // récupération des développeurs qui ne sont pas dans le projet
            developperClient.getDeveloppeurAvailable(
                idProject,
                new MethodCallback<List<Developper>>() {

                  @Override
                  public void onFailure(final Method method, final Throwable exception) {}

                  @Override
                  public void onSuccess(final Method method, final List<Developper> notInProject) {
                    listbox1.clear();
                    listbox2.clear();

                    developpersInProject = project.getDeveloppers();
                    developpersAvailable = notInProject;
                    for (final Developper developper : notInProject) {
                      listbox1.addItem(developper.getFirstName() + " " + developper.getLastName());
                    }
                    for (final Developper developper : developpersInProject) {
                      listbox2.addItem(developper.getFirstName() + " " + developper.getLastName());
                    }

                    final Button change = new Button("changer");
                    change.addClickHandler(
                        new ClickHandler() {

                          @Override
                          public void onClick(final ClickEvent event) {
                            final List<Integer> selectedItems1 = getSelectedItems(listbox1);
                            final List<Integer> selectedItems2 = getSelectedItems(listbox2);
                            for (final Integer i : selectedItems1) {
                              final Developper dev = developpersAvailable.get(i);
                              developpersInProject.add(dev);
                              listbox2.addItem(dev.getFirstName() + " " + dev.getLastName());
                            }
                            for (final Integer i : selectedItems2) {
                              final Developper dev = developpersInProject.get(i);
                              developpersAvailable.add(dev);
                              listbox1.addItem(dev.getFirstName() + " " + dev.getLastName());
                            }
                            for (final Integer i : selectedItems2) {
                              developpersAvailable.remove(i);
                              listbox2.removeItem(i);
                            }
                            for (final Integer i : selectedItems1) {
                              developpersInProject.remove(i);
                              listbox1.removeItem(i);
                            }
                          }
                        });
                    final VerticalPanel v1 = new VerticalPanel();
                    final VerticalPanel v2 = new VerticalPanel();
                    final Label label1 = new Label("Développeur disponible :");
                    final Label label2 = new Label("Développeur affecté au projet :");
                    v1.add(label1);
                    v2.add(label2);
                    v1.add(listbox1);
                    v2.add(listbox2);
                    horizontalPanel.add(v1);
                    horizontalPanel.add(change);
                    horizontalPanel.add(v2);
                  }
                });
          }

          @Override
          public void onFailure(final Method method, final Throwable exception) {}
        });
    initWidget(horizontalPanel);
  }