Ejemplo n.º 1
0
  @Override
  public void actionPerformed(ActionEvent e) {
    if (availTable != null && (e.getActionCommand().equals("ADD") || e.getSource() == availTable)) {
      List<Object> data = availTable.getSelectedData();
      if (!data.isEmpty()) {
        for (Object object : data) {
          if (object instanceof InfoFacade) {
            chooser.addSelected((InfoFacade) object);
          }
        }
      }
      return;
    }
    if (availInput != null && (e.getActionCommand().equals("ADD") || e.getSource() == availInput)) {
      String data = availInput.getText();
      if (StringUtils.isNotBlank(data)) {
        chooser.addSelected(new InfoWrapper(data));
      }
      availInput.setText("");
      return;
    }

    if (e.getActionCommand().equals("REMOVE") || e.getSource() == list) {
      Object value = list.getSelectedValue();
      if (value != null && value instanceof InfoFacade) {
        chooser.removeSelected((InfoFacade) value);
        if (availInput != null) {
          availInput.setText(value.toString());
        }
      }
      return;
    }
    if (e.getActionCommand().equals("OK")) {
      if (chooser.isRequireCompleteSelection() && chooser.getRemainingSelections().get() > 0) {
        JOptionPane.showMessageDialog(
            this,
            LanguageBundle.getFormattedString(
                "in_chooserRequireComplete", //$NON-NLS-1$
                chooser.getRemainingSelections().get()),
            chooser.getName(),
            JOptionPane.INFORMATION_MESSAGE);
        return;
      } else {
        chooser.commit();
      }
    } else {
      chooser.rollback();
    }
    committed = e.getActionCommand().equals("OK");
    dispose();
  }
Ejemplo n.º 2
0
  @Override
  public void setVisible(boolean b) {
    //
    // Only do this if 1 entry and can add...
    //
    ListFacade<InfoFacade> availableList = chooser.getAvailableList();
    if ((availableList != null)
        && (availableList.getSize() == 1)
        && (listModel.getSize() == 0)
        && b
        && !chooser.isUserInput()) {
      final int method = UIPropertyContext.getSingleChoiceAction();

      if (method != Constants.CHOOSER_SINGLE_CHOICE_METHOD_NONE) {
        chooser.addSelected(availableList.getElementAt(0));

        if (method == Constants.CHOOSER_SINGLE_CHOICE_METHOD_SELECT_EXIT) {
          chooser.commit();
          committed = true;
          return;
        }
      }
    }

    super.setVisible(b);
  }