r376 - trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol
Author: tchemit Date: 2013-02-09 00:17:53 +0100 (Sat, 09 Feb 2013) New Revision: 376 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/376 Log: use action to add or remove species protocol Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java 2013-02-08 23:17:53 UTC (rev 376) @@ -0,0 +1,84 @@ +package fr.ifremer.tutti.ui.swing.content.protocol; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.ui.swing.AbstractTuttiAction; + +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * To add a new species protocol. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class AddSpeciesProtocolAction extends AbstractTuttiAction<EditProtocolUIModel, EditProtocolUI, EditProtocolUIHandler> { + + private static final long serialVersionUID = 1L; + + public AddSpeciesProtocolAction(EditProtocolUIHandler handler) { + super(handler, + "addSpeciesProtocol", + "add", + null, + _("tutti.action.addSpeciesProtocol.tip"), + false + ); + } + + @Override + protected void doAction(ActionEvent event) { + + + EditProtocolUI ui = getUI(); + + EditProtocolSpeciesTableModel tableModel = getHandler().getTableModel(); + Species species = (Species) ui.getSpeciesComboBox().getSelectedItem(); + Preconditions.checkNotNull(species); + EditProtocolSpeciesRowModel protocol = tableModel.createNewRow(); + + Integer taxonId = species.getReferenceTaxonId(); + + // get referent species + String taxonIdStr = String.valueOf(taxonId); + Species referentSpecies = getHandler().getAllReferentSpeciesByTaxonId().get(taxonIdStr); + protocol.setSpecies(referentSpecies); + tableModel.addNewRow(protocol); + + // remove all synonyms of this taxon + getHandler().removeSpeciesSynonyms(ui.getSpeciesComboBox().getData(), taxonIdStr); + ui.getSpeciesComboBox().getHandler().sortData(); + + getHandler().selectFirstInCombo(ui.getSpeciesComboBox()); + + getModel().setModify(true); + + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css 2013-02-08 23:17:15 UTC (rev 375) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.css 2013-02-08 23:17:53 UTC (rev 376) @@ -76,8 +76,8 @@ enabled: {!speciesComboBox.isEmpty()}; } -#addRow { - actionIcon: add; +#addSpeciesProtocol { + _tuttiAction: {AddSpeciesProtocolAction.class}; enabled: {speciesComboBox.getSelectedItem() != null}; } @@ -85,11 +85,10 @@ label: "tutti.title.batchActions"; } -#removeSpeciesMenu { - text: "tutti.action.removeSpecies"; - mnemonic: R; - actionIcon: batch-delete; +#removeSpeciesProtocol { + _tuttiAction: {RemoveSpeciesProtocolAction.class}; enabled: {model.isRemoveSpeciesEnabled()}; + mnemonic: R; } #speciesTable { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx 2013-02-08 23:17:15 UTC (rev 375) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUI.jaxx 2013-02-08 23:17:53 UTC (rev 376) @@ -77,8 +77,7 @@ </BeanValidator> <JPopupMenu id='tablePopup'> - <JMenuItem id='removeSpeciesMenu' - onActionPerformed='handler.removeSpeciesRow()'/> + <JMenuItem id='removeSpeciesProtocol'/> </JPopupMenu> <JTabbedPane constraints='BorderLayout.CENTER'> @@ -151,7 +150,7 @@ genericType='Species'/> </cell> <cell fill='both'> - <JButton id='addRow' onActionPerformed='handler.addSpeciesRow()'/> + <JButton id='addSpeciesProtocol'/> </cell> </row> <row fill='both' weighty='1'> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-02-08 23:17:15 UTC (rev 375) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-02-08 23:17:53 UTC (rev 376) @@ -24,7 +24,6 @@ * #L% */ -import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; @@ -189,6 +188,10 @@ return allReferentSpeciesByTaxonId; } + public Multimap<String, Species> getAllSpeciesByTaxonId() { + return allSpeciesByTaxonId; + } + @Override public void afterInitUI() { @@ -393,47 +396,6 @@ //-- Public methods --// //------------------------------------------------------------------------// - public void addSpeciesRow() { - Species species = (Species) ui.getSpeciesComboBox().getSelectedItem(); - Preconditions.checkNotNull(species); - EditProtocolSpeciesRowModel protocol = getTableModel().createNewRow(); - - Integer taxonId = species.getReferenceTaxonId(); - - // get referent species - String taxonIdStr = String.valueOf(taxonId); - Species referentSpecies = allReferentSpeciesByTaxonId.get(taxonIdStr); - protocol.setSpecies(referentSpecies); - getTableModel().addNewRow(protocol); - - // remove all synonyms of this taxon - removeSpeciesSynonyms(ui.getSpeciesComboBox().getData(), taxonIdStr); - ui.getSpeciesComboBox().getHandler().sortData(); - - selectFirstInCombo(ui.getSpeciesComboBox()); - - getModel().setModify(true); - } - - /** Removes a species */ - public void removeSpeciesRow() { - int rowIndex = getTable().getSelectedRow(); - - Preconditions.checkState(rowIndex != -1, - "Cant remove species if no species selected"); - - // remove the row from the model - EditProtocolSpeciesRowModel removedRow = getModel().getRows().remove(rowIndex); - - // readd all synonym of this taxon to the species comobox - Integer taxonId = removedRow.getSpecies().getReferenceTaxonId(); - ui.getSpeciesComboBox().getData().addAll(allSpeciesByTaxonId.get(String.valueOf(taxonId))); - ui.getSpeciesComboBox().getHandler().sortData(); - - // refresh all the table - getTableModel().fireTableRowsDeleted(rowIndex, rowIndex); - } - public void addDoubleListListeners() { String id; UpdateSelectedList updateListener; @@ -579,7 +541,6 @@ valueIsAdjusting = false; } } - } public void select(List<String> selectedIds) { @@ -592,6 +553,5 @@ } model.setSelected(selection); } - } } Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java 2013-02-08 23:17:53 UTC (rev 376) @@ -0,0 +1,75 @@ +package fr.ifremer.tutti.ui.swing.content.protocol; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.tutti.ui.swing.AbstractTuttiAction; + +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * To add a new species protocol. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class RemoveSpeciesProtocolAction extends AbstractTuttiAction<EditProtocolUIModel, EditProtocolUI, EditProtocolUIHandler> { + + private static final long serialVersionUID = 1L; + + public RemoveSpeciesProtocolAction(EditProtocolUIHandler handler) { + super(handler, + "removeSpeciesProtocol", + "batch-delete", + null, + _("tutti.action.removeSpeciesProtocol.tip"), + false + ); + } + + @Override + protected void doAction(ActionEvent event) { + + EditProtocolUIHandler handler = getHandler(); + int rowIndex = handler.getTable().getSelectedRow(); + + Preconditions.checkState(rowIndex != -1, + "Cant remove species if no species selected"); + + // remove the row from the model + EditProtocolSpeciesRowModel removedRow = getModel().getRows().remove(rowIndex); + + // readd all synonym of this taxon to the species comobox + Integer taxonId = removedRow.getSpecies().getReferenceTaxonId(); + getUI().getSpeciesComboBox().getData().addAll(handler.getAllSpeciesByTaxonId().get(String.valueOf(taxonId))); + getUI().getSpeciesComboBox().getHandler().sortData(); + + // refresh all the table + handler.getTableModel().fireTableRowsDeleted(rowIndex, rowIndex); + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
tchemit@users.forge.codelutin.com