Author: kmorin Date: 2013-03-06 16:19:09 +0100 (Wed, 06 Mar 2013) New Revision: 549 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/549 Log: - long action lock test - debug dialog opening in long actions - debug edition of a new operation Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-03-06 09:34:33 UTC (rev 548) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-03-06 15:19:09 UTC (rev 549) @@ -299,9 +299,14 @@ if (!canContinue) { - // rollback selected fishing operation - FishingOperation selectFishingOperation = - model.getFishingOperation(editFishingOperationId); + FishingOperation selectFishingOperation; + if (TuttiEntities.isNew(editFishingOperation)) { + selectFishingOperation = editFishingOperation; + } else { + // rollback selected fishing operation + selectFishingOperation = + model.getFishingOperation(editFishingOperationId); + } model.setEditionAdjusting(true); try { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-03-06 09:34:33 UTC (rev 548) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-03-06 15:19:09 UTC (rev 549) @@ -11,15 +11,15 @@ * %% * 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 + * 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 + * + * 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% @@ -37,7 +37,6 @@ import org.apache.commons.logging.LogFactory; import javax.swing.JOptionPane; -import java.awt.Component; import java.util.List; import static org.nuiton.i18n.I18n._; @@ -70,8 +69,6 @@ Float speciesTotalSortedWeight = model.getSpeciesTotalSortedComputedWeight(); Float speciesTotalUnsortedWeight = model.getSpeciesTotalUnsortedComputedWeight(); - EditCatchesUI ui = getUI(); - model.setCatchTotalSortedComputedWeight(speciesTotalSortedWeight); model.setCatchTotalUnsortedComputedWeight(speciesTotalUnsortedWeight); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesAction.java 2013-03-06 09:34:33 UTC (rev 548) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/AddSpeciesAction.java 2013-03-06 15:19:09 UTC (rev 549) @@ -11,15 +11,15 @@ * %% * 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 + * 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 + * + * 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% @@ -35,6 +35,7 @@ import java.util.List; import java.util.Map; +import javax.swing.JOptionPane; import static org.nuiton.i18n.I18n._; @@ -70,39 +71,32 @@ } @Override - protected boolean prepareAction() { - boolean result = super.prepareAction(); + protected void doAction() throws InterruptedException { + CreateSpeciesBatchUIModel model = getModel(); - List<Species> availableSpecies = getModel().getAvailableSpecies(); - List<Species> species = Lists.newArrayList(allSpecies); + List<Species> availableSpecies = Lists.newArrayList(model.getAvailableSpecies()); + final List<Species> species = Lists.newArrayList(allSpecies); species.removeAll(availableSpecies); selectedSpecies = getHandler().openAddSpeciesDialog(_("tutti.title.selectSpecies"), species); - result &= selectedSpecies != null; - return result; - } + if (selectedSpecies != null) { + if (!selectedSpecies.isReferenceTaxon()) { + String decoratedSynonym = decorate(selectedSpecies); + List<Species> referents = referentSpecies; + Map<String, Species> referentsById = TuttiEntities.splitByTaxonId(referents); + String taxonId = String.valueOf(selectedSpecies.getReferenceTaxonId()); + selectedSpecies = referentsById.get(taxonId); + String decoratedReferent = decorate(selectedSpecies); + sendMessage(_("tutti.flash.information.species.replaced", decoratedSynonym, decoratedReferent)); + } - @Override - protected void doAction() { - CreateSpeciesBatchUIModel model = getModel(); - - if (!selectedSpecies.isReferenceTaxon()) { - String decoratedSynonym = decorate(selectedSpecies); - List<Species> referents = referentSpecies; - Map<String, Species> referentsById = TuttiEntities.splitByTaxonId(referents); - String taxonId = String.valueOf(selectedSpecies.getReferenceTaxonId()); - selectedSpecies = referentsById.get(taxonId); - String decoratedReferent = decorate(selectedSpecies); - sendMessage(_("tutti.flash.information.species.replaced", decoratedSynonym, decoratedReferent)); + if (!availableSpecies.contains(selectedSpecies)) { + availableSpecies.add(selectedSpecies); + } + model.setAvailableSpecies(availableSpecies); + model.setSpecies(selectedSpecies); } - - List<Species> availableSpecies = Lists.newArrayList(model.getAvailableSpecies()); - if (!availableSpecies.contains(selectedSpecies)) { - availableSpecies.add(selectedSpecies); - } - model.setAvailableSpecies(availableSpecies); - model.setSpecies(selectedSpecies); } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java 2013-03-06 09:34:33 UTC (rev 548) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUIHandler.java 2013-03-06 15:19:09 UTC (rev 549) @@ -10,15 +10,15 @@ * %% * 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 + * 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 + * + * 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% @@ -39,6 +39,7 @@ import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.util.Cancelable; import fr.ifremer.tutti.ui.swing.util.TuttiUI; +import fr.ifremer.tutti.ui.swing.util.action.TuttiActionUI; import jaxx.runtime.SwingUtil; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; @@ -248,7 +249,8 @@ model.setSelectedSpecies(null); model.setSpecies(species); - openDialog(ui, dialog, title, new Dimension(400, 130)); + TuttiActionUI actionUI = context.getActionUI(); + openDialog(taui, dialog, title, new Dimension(400, 130)); return model.getSelectedSpecies(); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java 2013-03-06 09:34:33 UTC (rev 548) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java 2013-03-06 15:19:09 UTC (rev 549) @@ -10,15 +10,15 @@ * %% * 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 + * 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 + * + * 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% @@ -74,9 +74,11 @@ import javax.swing.text.JTextComponent; import java.awt.Color; import java.awt.Component; +import java.awt.Dialog; import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; +import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; @@ -84,6 +86,7 @@ import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Serializable; @@ -92,6 +95,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.swing.SwingUtilities; import static org.nuiton.i18n.I18n._; @@ -228,10 +232,19 @@ public void openDialog(TuttiUI ui, TuttiUI dialogContent, String title, Dimension dim) { - Frame frame = SwingUtil.getParentContainer(ui, Frame.class); + Window window; + if (Window.class.isAssignableFrom(ui.getClass())) { + window = (Window) ui; + } else { + window = SwingUtil.getParentContainer(ui, Window.class); + } + JDialog result; + if (window instanceof Frame) { + result = new JDialog((Frame)window, title, true); + } else { + result = new JDialog((Dialog)window, title, true); + } - JDialog result = new JDialog(frame, true); - result.setTitle(title); result.add((Component) dialogContent); result.setResizable(true); @@ -269,7 +282,7 @@ JAXXUtil.destroy(ui); } }); - SwingUtil.center(frame, result); + SwingUtil.center(getContext().getMainUI(), result); result.setVisible(true); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java 2013-03-06 09:34:33 UTC (rev 548) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java 2013-03-06 15:19:09 UTC (rev 549) @@ -10,15 +10,15 @@ * %% * 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 + * 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 + * + * 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% @@ -31,6 +31,9 @@ import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.util.TuttiExceptionHandler; import fr.ifremer.tutti.ui.swing.util.TuttiUI; +import javax.swing.SwingUtilities; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jdesktop.beans.AbstractBean; import org.nuiton.util.decorator.Decorator; @@ -40,8 +43,11 @@ * @author tchemit <chemit@codelutin.com> * @since 1.0 */ -public abstract class AbstractTuttiAction<M extends AbstractBean, UI extends TuttiUI<M, ?>, H extends AbstractTuttiUIHandler<M, UI>> { +public abstract class AbstractTuttiAction<M extends AbstractBean, UI extends TuttiUI<M, ?>, H extends AbstractTuttiUIHandler<M, UI>> + extends AbstractBean { + private static final Log log = LogFactory.getLog(AbstractTuttiAction.class); + protected final H handler; protected final String actionName; @@ -54,6 +60,8 @@ protected Throwable error; + protected final Object lock = new Object(); + protected abstract void doAction() throws Exception; protected AbstractTuttiAction(H handler, @@ -156,4 +164,47 @@ public Throwable getError() { return error; } + + protected void test(final Runnable r) throws InterruptedException { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + System.out.println("run"); +// getContext().getActionUI().pause(); + r.run(); +// getContext().getActionUI().resume(); + + System.out.println("Deblock ?"); + log.info("Deblock ?"); + unblock(); + } + }); + + log.info("Block ?"); + System.out.println("Block ?"); + block(); + + System.out.println("Block !"); + log.info("Block !"); + } + + protected void block() { + try { + synchronized(lock) { + lock.wait(); + } + } catch(Exception e) { + e.printStackTrace(); + } + } + + protected void unblock() { + try { + synchronized(lock) { + lock.notify(); + } + } catch(Exception e) { + e.printStackTrace(); + } + } }