View Javadoc
1   package fr.ifremer.reefdb.ui.swing.util.table.editor;
2   
3   /*
4    * #%L
5    * Reef DB :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import fr.ifremer.quadrige3.ui.swing.table.editor.ButtonCellEditor;
27  import fr.ifremer.reefdb.dto.referential.TaxonDTO;
28  import fr.ifremer.reefdb.dto.referential.TaxonGroupDTO;
29  import fr.ifremer.reefdb.ui.swing.content.manage.referential.taxon.taxonsDialog.TaxonsDialogUI;
30  import fr.ifremer.reefdb.ui.swing.util.ReefDbUI;
31  import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbTableModel;
32  import org.jdesktop.swingx.JXTable;
33  
34  import java.awt.Dimension;
35  import java.util.ArrayList;
36  
37  import static org.nuiton.i18n.I18n.t;
38  
39  /**
40   * <p>AssociatedTaxonCellEditor class.</p>
41   *
42   */
43  public class AssociatedTaxonCellEditor extends ButtonCellEditor {
44  
45      private final JXTable table;
46  
47      private final ReefDbUI parentUI;
48  
49      private boolean isEditable = false;
50  
51      /**
52       * <p>Constructor for AssociatedTaxonCellEditor.</p>
53       *
54       * @param table a {@link org.jdesktop.swingx.JXTable} object.
55       * @param parentUI a {@link fr.ifremer.reefdb.ui.swing.util.ReefDbUI} object.
56       * @param isEditable a boolean.
57       */
58      public AssociatedTaxonCellEditor(
59              final JXTable table,
60              final ReefDbUI parentUI,
61              final boolean isEditable) {
62          this.table = table;
63          this.parentUI = parentUI;
64          this.isEditable = isEditable;
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public void onButtonCellAction(final int rowIndex, final int column) {
70  
71          final AbstractReefDbTableModel<?> tableModel = (AbstractReefDbTableModel<?>) table.getModel();
72          final int rowModelIndex = table.convertRowIndexToModel(rowIndex);
73          Object entry = tableModel.getEntry(rowModelIndex);
74  
75          final TaxonsDialogUI taxonsDialogUI = new TaxonsDialogUI(parentUI);
76          if (entry instanceof TaxonGroupDTO) {
77  
78              // get associated taxons from taxon group
79              taxonsDialogUI.getModel().setTaxonGroup((TaxonGroupDTO) entry);
80              taxonsDialogUI.setTitle(t("reefdb.property.taxonGroup.taxons"));
81  
82          } else if (entry instanceof TaxonDTO) {
83  
84              // get composite taxons from taxon
85              taxonsDialogUI.getModel().setTaxons(new ArrayList<>(((TaxonDTO) entry).getCompositeTaxons()));
86              taxonsDialogUI.setTitle(t("reefdb.property.taxon.composites"));
87          }
88  
89          taxonsDialogUI.getModel().setEditable(isEditable);
90          // open taxon screen
91          parentUI.getHandler().openDialog(taxonsDialogUI, new Dimension(1024, 480));
92      }
93  }