Example #1
0
 public CompanionTypeNode(String type) {
   super(Arrays.asList(type, null));
   this.type = type;
 }
Example #2
0
  private class CompanionDialog extends JDialog
      implements TreeViewModel<CompanionStubFacade>, DataView<CompanionStubFacade>, ActionListener {

    private final FilteredCompanionList model;
    private final JButton selectButton;
    private final FilteredTreeViewTable raceTable;
    private CharacterFacade character;
    private String companionType;
    private CharacterFacade newCompanion;
    private DefaultListFacade<CompanionTreeView> treeViews =
        new DefaultListFacade<CompanionTreeView>(Arrays.asList(CompanionTreeView.values()));

    public CompanionDialog() {
      super(JOptionPane.getFrameForComponent(CompanionInfoTab.this), true);
      this.model = new FilteredCompanionList();
      this.selectButton = new JButton();
      this.raceTable = new FilteredTreeViewTable();
      initComponents();
      pack();
    }

    private void initComponents() {
      setTitle(LanguageBundle.getString("in_companionSelectRace")); // $NON-NLS-1$
      setLayout(new BorderLayout());
      Container container = getContentPane();
      {
        final ListSelectionModel selectionModel = raceTable.getSelectionModel();
        selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        selectionModel.addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                  selectButton.setEnabled(!selectionModel.isSelectionEmpty());
                }
              }
            });
      }
      SearchFilterPanel searchBar = new SearchFilterPanel();
      container.add(searchBar, BorderLayout.NORTH);
      raceTable.setDisplayableFilter(searchBar);
      raceTable.addActionListener(this);
      raceTable.setTreeViewModel(this);
      container.add(new JScrollPane(raceTable), BorderLayout.CENTER);
      JPanel buttonPane = new JPanel(new FlowLayout());
      selectButton.addActionListener(this);
      selectButton.setEnabled(false);
      selectButton.setActionCommand("SELECT");
      buttonPane.add(selectButton);

      JButton cancelButton = new JButton(LanguageBundle.getString("in_cancel"));
      cancelButton.addActionListener(this);
      cancelButton.setActionCommand("CANCEL");
      buttonPane.add(cancelButton);
      container.add(buttonPane, BorderLayout.SOUTH);

      Utility.installEscapeCloseOperation(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
      if (!"null".equals(e.getActionCommand())) {
        if ("SELECT".equals(e.getActionCommand()) || (JTreeTable.ACTION_DOUBLECLICK == e.getID())) {
          newCompanion =
              CharacterManager.createNewCharacter(
                  character.getUIDelegate(), character.getDataSet());
          CompanionStubFacade selected = (CompanionStubFacade) raceTable.getSelectedObject();
          newCompanion.setRace(selected.getRaceRef().getReference());
          character.getCompanionSupport().addCompanion(newCompanion, companionType);
          setVisible(false);
        } else {
          newCompanion = null;
          setVisible(false);
        }
      }
    }

    public void setCharacter(CharacterFacade character) {
      this.character = character;
      model.setDelegate(character.getCompanionSupport().getAvailableCompanions());
    }

    public void setCompanionType(String type) {
      companionType = type;
      model.setCompanionType(type);
      selectButton.setText(
          LanguageBundle.getFormattedString("in_companionCreateType", type)); // $NON-NLS-1$
      newCompanion = null;
    }

    @Override
    public ListFacade<? extends TreeView<CompanionStubFacade>> getTreeViews() {
      return treeViews;
    }

    @Override
    public int getDefaultTreeViewIndex() {
      return 0;
    }

    @Override
    public DataView<CompanionStubFacade> getDataView() {
      return this;
    }

    @Override
    public ListFacade<CompanionStubFacade> getDataModel() {
      return model;
    }

    @Override
    public List<?> getData(CompanionStubFacade obj) {
      return Collections.emptyList();
    }

    @Override
    public List<? extends DataViewColumn> getDataColumns() {
      return Collections.emptyList();
    }

    /** {@inheritDoc} */
    @Override
    public String getPrefsKey() {
      return "CompanionAvail"; //$NON-NLS-1$
    }

    /** @return the newCompanion */
    public CharacterFacade getNewCompanion() {
      return newCompanion;
    }
  }