View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.referential.taxon.taxonsDialog;
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.ui.swing.util.AbstractDaliUIHandler;
28  import org.nuiton.jaxx.application.swing.util.Cancelable;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  /**
34   * Handler.
35   */
36  public class TaxonsDialogUIHandler extends AbstractDaliUIHandler<TaxonsDialogUIModel, TaxonsDialogUI> implements Cancelable {
37  
38      /** {@inheritDoc} */
39      @Override
40      public void beforeInit(TaxonsDialogUI ui) {
41          super.beforeInit(ui);
42  
43          ui.setContextValue(new TaxonsDialogUIModel());
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public void afterInit(TaxonsDialogUI ui) {
49          initUI(ui);
50  
51          getModel().addPropertyChangeListener(evt -> {
52  
53              if (TaxonsDialogUIModel.PROPERTY_TAXON_GROUP.equals(evt.getPropertyName())) {
54  
55                  List<TaxonDTO> taxons = getModel().getTaxonGroup() != null ? new ArrayList<>(getModel().getTaxonGroup().getTaxons()) : null;
56                  getUI().getTaxonsTable().getModel().setBeans(taxons);
57  
58              } else if (TaxonsDialogUIModel.PROPERTY_TAXONS.equals(evt.getPropertyName())) {
59  
60                  getUI().getTaxonsTable().getModel().setBeans(getModel().getTaxons());
61  
62              }
63          });
64  
65          // hide menu
66          ui.getTaxonsTable().getTaxonsNationalMenuUI().setVisible(false);
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public void cancel() {
72          closeDialog();
73      }
74  }