r467 - trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application
Author: tchemit Date: 2008-01-24 00:27:41 +0000 (Thu, 24 Jan 2008) New Revision: 467 Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/DownloadAction.java Log: nouvelle action download, a finir Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/DownloadAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/DownloadAction.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/DownloadAction.java 2008-01-24 00:27:41 UTC (rev 467) @@ -0,0 +1,110 @@ +/* +* ##% 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.action.application; + +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.service.StorageService; +import fr.cemagref.simexplorer.is.ui.swing.action.SimExplorerAbstractTabAction; +import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeHelper; +import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeNode; +import fr.cemagref.simexplorer.is.ui.swing.tab.JApplicationDetailTab; + +import javax.swing.JTree; +import java.awt.event.ActionEvent; +import java.io.File; +import java.text.MessageFormat; + +/** + * Action pour downloader un résultat ou une librairie + * + * @author chemit + */ + at jaxx.runtime.builder.ActionConfig( + actionCommand = "download", + name = "simexplorer.action.application.download", + shortDescription = "simexplorer.action.application.download.tooltip", + longDescription = "simexplorer.action.application.download.help", + smallIcon = "action/download.png", + mnemonic = 'x', + hideActionText = false +) +public class DownloadAction extends SimExplorerAbstractTabAction { + + private static final long serialVersionUID = 7535647131305304738L; + + private static final MessageFormat FILENAME_PATTERN = new MessageFormat("{0}.xml"); + JTree tree; + LoggableElementTreeNode node; + File file; + LoggableElement element; + String uuid; + Version version; + + public DownloadAction(String name) { + super(name, null); + } + + @Override + protected boolean beforeAction(ActionEvent e) throws Exception { + if (!super.beforeAction(e)) { + return false; + } + JApplicationDetailTab ui = (JApplicationDetailTab) getUI(); + tree = ui.getTree(); + node = LoggableElementTreeHelper.getSelectedNodeOrRootNode(tree); + boolean result; + result = node != null && node.isDownloadableElement(); + if (result) { + // ask user path where to save data + String dir = org.codelutin.util.FileUtil.getDirectory(); + if (dir == null) { + // user cancel action + return false; + } + + element = (LoggableElement) node.getUserObject(); + + uuid = element.getMetaData().getUuid(); + version = element.getMetaData().getVersion(); + file = new File(FILENAME_PATTERN.format(uuid + "-" + version)); + } + return result; + } + + @Override + protected void doAction(ActionEvent e) throws Exception { + super.doAction(e); + //StorageService service = getStorageService(((DetailTabModel) getModel()).isRemote()); + //TODO Where to save ??? + + } + + @Override + protected void clear() { + super.clear(); + tree = null; + node = null; + file = null; + element = null; + version=null; + uuid=null; + } +} \ No newline at end of file
participants (1)
-
tchemit@users.labs.libre-entreprise.org