Exemplo 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();
  }
Exemplo n.º 2
0
  private void initComponents() {
    setTitle(chooser.getName());
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosed(WindowEvent e) {
            // detach listeners from the chooser
            treeViewModel.setDelegate(null);
            listModel.setListFacade(null);
            chooser.getRemainingSelections().removeReferenceListener(ChooserDialog.this);
          }
        });
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());

    JSplitPane split = new JSplitPane();
    JPanel leftPane = new JPanel(new BorderLayout());
    if (availTable != null) {
      availTable.setAutoCreateRowSorter(true);
      availTable.setTreeViewModel(treeViewModel);
      availTable.getRowSorter().toggleSortOrder(0);
      availTable.addActionListener(this);
      leftPane.add(new JScrollPane(availTable), BorderLayout.CENTER);
    } else {
      availInput.addActionListener(this);
      Dimension maxDim = new Dimension(Integer.MAX_VALUE, availInput.getPreferredSize().height);
      availInput.setMaximumSize(maxDim);
      JPanel availPanel = new JPanel();
      availPanel.setLayout(new BoxLayout(availPanel, BoxLayout.PAGE_AXIS));
      availPanel.add(Box.createRigidArea(new Dimension(10, 30)));
      availPanel.add(Box.createVerticalGlue());
      availPanel.add(new JLabel(LanguageBundle.getString("in_uichooser_value")));
      availPanel.add(availInput);
      availPanel.add(Box.createVerticalGlue());
      leftPane.add(availPanel, BorderLayout.WEST);
    }

    JPanel buttonPane1 = new JPanel(new FlowLayout());
    JButton addButton = new JButton(chooser.getAddButtonName());
    addButton.setActionCommand("ADD");
    addButton.addActionListener(this);
    buttonPane1.add(addButton);
    buttonPane1.add(new JLabel(Icons.Forward16.getImageIcon()));
    leftPane.add(buttonPane1, BorderLayout.SOUTH);

    split.setLeftComponent(leftPane);

    JPanel rightPane = new JPanel(new BorderLayout());
    JPanel labelPane = new JPanel(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    labelPane.add(new JLabel(chooser.getSelectionCountName()), new GridBagConstraints());
    remainingLabel.setText(chooser.getRemainingSelections().get().toString());
    labelPane.add(remainingLabel, gbc);
    labelPane.add(new JLabel(chooser.getSelectedTableTitle()), gbc);
    rightPane.add(labelPane, BorderLayout.NORTH);

    list.setModel(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addActionListener(this);
    rightPane.add(new JScrollPane(list), BorderLayout.CENTER);

    JPanel buttonPane2 = new JPanel(new FlowLayout());
    buttonPane2.add(new JLabel(Icons.Back16.getImageIcon()));
    JButton removeButton = new JButton(chooser.getRemoveButtonName());
    removeButton.setActionCommand("REMOVE");
    removeButton.addActionListener(this);
    buttonPane2.add(removeButton);
    rightPane.add(buttonPane2, BorderLayout.SOUTH);

    split.setRightComponent(rightPane);

    if (chooser.isInfoAvailable()) {
      JSplitPane infoSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
      infoSplit.setTopComponent(split);
      infoSplit.setBottomComponent(infoPane);
      infoSplit.setResizeWeight(.8);
      pane.add(infoSplit, BorderLayout.CENTER);
      if (availTable != null) {
        availTable.getSelectionModel().addListSelectionListener(this);
      }
    } else {
      pane.add(split, BorderLayout.CENTER);
    }
    JPanel bottomPane = new JPanel(new FlowLayout());
    JButton button = new JButton(LanguageBundle.getString("in_ok")); // $NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_ok")); // $NON-NLS-1$
    button.setActionCommand("OK");
    button.addActionListener(this);
    bottomPane.add(button);
    button = new JButton(LanguageBundle.getString("in_cancel")); // $NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_cancel")); // $NON-NLS-1$
    button.setActionCommand("CANCEL");
    button.addActionListener(this);
    bottomPane.add(button);
    pane.add(bottomPane, BorderLayout.SOUTH);
  }