Author: tchemit Date: 2008-02-18 17:04:10 +0000 (Mon, 18 Feb 2008) New Revision: 1076 Removed: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/DeleteAbstractAction.java Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DeleteElementAction.java Log: implantation action delete Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DeleteElementAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DeleteElementAction.java 2008-02-18 17:03:55 UTC (rev 1075) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DeleteElementAction.java 2008-02-18 17:04:10 UTC (rev 1076) @@ -18,12 +18,18 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing.actions; -import fr.cemagref.simexplorer.is.ui.swing.actions.util.DeleteAbstractAction; +import fr.cemagref.simexplorer.is.ui.StorageServiceHelper; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerTab; +import fr.cemagref.simexplorer.is.ui.swing.actions.util.SimExplorerAbstractTabAction; +import fr.cemagref.simexplorer.is.ui.swing.model.DataEntityModel; +import static org.codelutin.i18n.I18n._; +import javax.swing.JOptionPane; +import java.awt.Component; import java.awt.event.ActionEvent; /** - * Action pour downloader un résultat ou une librairie + * Action pour supprimer un loggableElement ou une librairie * * @author chemit */ @@ -36,15 +42,67 @@ mnemonic = 'x', hideActionText = true ) -public class DeleteElementAction extends DeleteAbstractAction { +public class DeleteElementAction extends SimExplorerAbstractTabAction { + + protected DataEntityModel selected; + private static final long serialVersionUID = 5227114960042141191L; public DeleteElementAction(String name) { super(name); } + protected String getDeleteMessage() { + return selected.getMeta().getName() + " [" + selected.getVersion() + "]"; + } + @Override + protected boolean beforeAction(ActionEvent e) throws Exception { + if (!super.beforeAction(e)) { + return false; + } + // on doit retrouver l'élément à traiter à partir de la source + SimExplorerTab sourceTab = SimExplorerTab.findTab((Component) e.getSource()); + log.info("incoming tab " + sourceTab); + if (sourceTab == null) { + //fatal error + log.warn("could not find a tab for source "+e.getSource()); + return false; + } + selected = sourceTab.getModel().getSelectedItem(); + + return selected != null; + } + + @Override protected void doAction(ActionEvent e) throws Exception { super.doAction(e); + log.info("selected " + selected); + // demande de confirmation avant d'effacer + int result = JOptionPane.showConfirmDialog(null, _("simexplorer.confirm.delete", getDeleteMessage()), "delete", JOptionPane.YES_NO_OPTION); + if (result != JOptionPane.OK_OPTION) { + // do nothing + return; + } + // effectue la suppression + StorageServiceHelper.deleteElement(getContext(), selected.isRemote(), selected.getUuid(), selected.getVersion().toString()); } + + @Override + public void updateUI() { + super.updateUI(); + if (selected.isRemote()) { + // update list model, update list ui, ... + + } else { + // update list model, update list ui, ... + + } + } + + @Override + protected void clear() { + super.clear(); + selected = null; + } } \ No newline at end of file Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/DeleteAbstractAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/DeleteAbstractAction.java 2008-02-18 17:03:55 UTC (rev 1075) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/DeleteAbstractAction.java 2008-02-18 17:04:10 UTC (rev 1076) @@ -1,101 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.ui.swing.actions.util; - -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import fr.cemagref.simexplorer.is.entities.metadata.Version; -import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; -import static org.codelutin.i18n.I18n._; -import javax.swing.JOptionPane; -import java.awt.event.ActionEvent; - -/** - * Action pour deleter un loggableElement ou attachment - * - * @author chemit - */ -public abstract class DeleteAbstractAction extends SimExplorerAbstractTabAction { - - private static final long serialVersionUID = 7535647131305304738L; - - MetaData element; - String uuid; - Version version; - - protected String getDeleteMessage() { - return element.getName()+" ["+version+"]"; - } - protected DeleteAbstractAction(String name) { - super(name); - } - - protected void initModel(DetailTabModel model) { - element = model.getDetail(); - version = model.getSelectedVersion(); - uuid = element.getUuid(); - } - - protected MetaData getElement() { - return element; - } - - protected String getUuid() { - return uuid; - } - - protected Version getVersion() { - return version; - } - - @Override - protected boolean beforeAction(ActionEvent e) throws Exception { - if (!super.beforeAction(e)) { - return false; - } - DetailTabModel model = ((DetailTabModel) getModel()); - boolean result; - // init from model - initModel(model); - result = element != null && version != null; - return result; - } - - @Override - protected void doAction(ActionEvent e) throws Exception { - super.doAction(e); - // demande de confirmation avant d'effacer - int result = JOptionPane.showConfirmDialog(null, _("simexplorer.confirm.delete",getDeleteMessage()), "delete", JOptionPane.YES_NO_OPTION); - if (result != JOptionPane.OK_OPTION) { - // do nothing - return; - } - //TODO do action - throw new SimExplorerRuntimeException(this+" is not implemented yet!"); - } - - @Override - protected void clear() { - super.clear(); - element = null; - version = null; - uuid = null; - } - -} \ No newline at end of file