View Javadoc
1   package fr.ifremer.dali.ui.swing.util.table.editor;
2   
3   /*
4    * #%L
5    * Dali :: 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.dali.dto.referential.TaxonDTO;
27  import fr.ifremer.dali.dto.referential.TaxonGroupDTO;
28  import fr.ifremer.dali.ui.swing.DaliUIContext;
29  import fr.ifremer.dali.ui.swing.content.manage.referential.taxon.taxonsDialog.TaxonsDialogUI;
30  import fr.ifremer.dali.ui.swing.util.DaliUI;
31  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableModel;
32  import fr.ifremer.quadrige3.ui.swing.table.SwingTable;
33  import fr.ifremer.quadrige3.ui.swing.table.editor.ButtonCellEditor;
34  
35  import java.awt.Dimension;
36  import java.util.ArrayList;
37  
38  import static org.nuiton.i18n.I18n.t;
39  
40  /**
41   * <p>AssociatedTaxonCellEditor class.</p>
42   *
43   */
44  public class AssociatedTaxonCellEditor extends ButtonCellEditor {
45  
46      private final SwingTable table;
47  
48      private final DaliUI parentUI;
49  
50      /**
51       * <p>Constructor for AssociatedTaxonCellEditor.</p>
52       *
53       * @param table a {@link SwingTable} object.
54       * @param parentUI a {@link DaliUI} object.
55       */
56      public AssociatedTaxonCellEditor(
57              final SwingTable table,
58              final DaliUI parentUI) {
59          this.table = table;
60          this.parentUI = parentUI;
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public void onButtonCellAction(final int rowIndex, final int column) {
66  
67          final AbstractDaliTableModel<?> tableModel = (AbstractDaliTableModel<?>) table.getModel();
68          final int rowModelIndex = table.convertRowIndexToModel(rowIndex);
69          Object entry = tableModel.getEntry(rowModelIndex);
70  
71          final TaxonsDialogUI taxonsDialogUI = new TaxonsDialogUI((DaliUIContext) parentUI.getHandler().getContext());
72          if (entry instanceof TaxonGroupDTO) {
73  
74              // get associated taxons from taxon group
75              taxonsDialogUI.getModel().setTaxonGroup((TaxonGroupDTO) entry);
76              taxonsDialogUI.setTitle(t("dali.property.taxonGroup.taxons"));
77  
78          } else if (entry instanceof TaxonDTO) {
79  
80              // get composite taxons from taxon
81              taxonsDialogUI.getModel().setTaxons(new ArrayList<>(((TaxonDTO) entry).getCompositeTaxons()));
82              taxonsDialogUI.setTitle(t("dali.property.taxon.composites"));
83          }
84  
85          // open taxon screen
86          parentUI.getHandler().openDialog(taxonsDialogUI, new Dimension(1024, 480));
87      }
88  }