View Javadoc
1   package fr.ifremer.dali.ui.swing.content.observation.operation.measurement.grouped;
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.ui.swing.action.AbstractDaliAction;
27  
28  /**
29   * Action dupliquer mesure (ecran prelevements/mesure).
30   */
31  public class DuplicateOperationMeasurementsAction extends AbstractDaliAction<OperationMeasurementsGroupedTableUIModel, OperationMeasurementsGroupedTableUI, OperationMeasurementsGroupedTableUIHandler> {
32  
33  	/**
34  	 * La ligne ajoutee.
35  	 */
36  	private OperationMeasurementsGroupedRowModel row;
37  
38  	/**
39  	 * Constrcuteur.
40  	 *
41  	 * @param handler Controller
42  	 */
43  	public DuplicateOperationMeasurementsAction(final OperationMeasurementsGroupedTableUIHandler handler) {
44  		super(handler, false);
45  	}
46  
47      /** {@inheritDoc} */
48      @Override
49      public boolean prepareAction() throws Exception {
50          return super.prepareAction() && getModel().getSelectedRows().size() == 1;
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55  	public void doAction() throws Exception {
56  		
57  		// Selected measurement
58  		final OperationMeasurementsGroupedRowModel rowToDuplicate = getModel().getSelectedRows().iterator().next();
59  		if (rowToDuplicate != null) {
60  
61              row = new OperationMeasurementsGroupedRowModel(false);
62  
63              row.setSamplingOperation(rowToDuplicate.getSamplingOperation());
64              row.setTaxonGroup(rowToDuplicate.getTaxonGroup());
65              row.setTaxon(rowToDuplicate.getTaxon());
66  			row.setInputTaxonId(rowToDuplicate.getInputTaxonId());
67  			row.setInputTaxonName(rowToDuplicate.getInputTaxonName());
68              row.setComment(rowToDuplicate.getComment());
69              row.setIndividualPmfms(rowToDuplicate.getIndividualPmfms());
70  			// add also analyst (Mantis #45565)
71  			row.setAnalyst(rowToDuplicate.getAnalyst());
72              // duplicate measurements by service
73              row.setIndividualMeasurements(getContext().getObservationService().duplicateMeasurements(rowToDuplicate.getIndividualMeasurements()));
74  
75  		}
76  	}
77  
78  	/** {@inheritDoc} */
79  	@Override
80  	public void postSuccessAction() {
81  		super.postSuccessAction();
82  
83          // Add duplicate measurement to table
84          getModel().insertRowAfterSelected(row);
85          // save directly to sampling operation
86          getHandler().saveMeasurementsInSamplingOperation(row);
87  
88  		// send update event on sampling operation
89          if (row.getSamplingOperation() != null) {
90              getModel().firePropertyChanged(OperationMeasurementsGroupedTableUIModel.PROPERTY_SAMPLING_OPERATION, null, row.getSamplingOperation());
91          }
92  
93          getHandler().recomputeRowsValidState();
94          getModel().setModify(true);
95  		
96  		// Ajouter le focus sur la cellule de la ligne cree
97  		getHandler().setFocusOnCell(row);
98  	}
99  }