Author: tchemit Date: 2008-02-18 23:57:32 +0000 (Mon, 18 Feb 2008) New Revision: 1109 Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DownloadAttachmentAction.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DownloadElementAction.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/DownloadAbstractAction.java Log: delete action revisit?\195?\169 et utilise maintenant l'?\195?\169l?\195?\169ment s?\195?\169lectionn?\195?\169 du model incrimin?\195?\169. l'action fonctionne aux endroits voulus (onglet list + detail) TODO : supprimer l'?\195?\169l?\195?\169ment de l'historique de l'onglet detail TODO : affiner le updateUI selon ce qu'il y a dans l'onglet detail et synchronize Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DownloadAttachmentAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DownloadAttachmentAction.java 2008-02-18 23:55:44 UTC (rev 1108) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DownloadAttachmentAction.java 2008-02-18 23:57:32 UTC (rev 1109) @@ -22,12 +22,12 @@ import fr.cemagref.simexplorer.is.ui.StorageServiceHelper; import fr.cemagref.simexplorer.is.ui.swing.actions.util.DownloadAbstractAction; import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel; +import org.codelutin.util.FileUtil; +import static org.codelutin.i18n.I18n._; import java.io.BufferedInputStream; import java.io.File; -import org.codelutin.util.FileUtil; - /** * Action pour downloader un résultat ou une librairie * @@ -51,19 +51,17 @@ super(name); } - @Override - protected void initModel(DetailTabModel model) { - super.initModel(model); - Integer selectedAttachment = model.getSelectedAttachmentIndex(); - attachment = getElement().getAttachment(selectedAttachment); - } - protected File getFile() { - if (attachment==null) { + // here is a trick : select now the attachment + // and we are sure to be on detail tab + DetailTabModel model = (DetailTabModel) getModel(); + Integer selectedAttachment = model.getSelectedAttachmentIndex(); + attachment = selected.getMeta().getAttachment(selectedAttachment); + if (attachment == null) { return null; } // ask user path where to save data - String dir = FileUtil.getDirectory("select directory where to download attachment '" + attachment.getFileName() + "' of element "+getElement().getName()+" - "+getVersion(),"choose a dir"); + String dir = FileUtil.getDirectory(_("simexplorer.action.download.attachment", attachment.getFileName(),selected.getMeta().getName() + " [" + selected.getVersion() + "]"), _("simexplorer.choose.dir")); if (dir == null) { // user cancel action return null; @@ -79,7 +77,7 @@ protected BufferedInputStream getInputStream() { BufferedInputStream bis; - bis = StorageServiceHelper.retrieveElementData(getContext(), ((DetailTabModel) getModel()).isRemote(), getUuid(), getVersion().toString(), attachment); + bis = StorageServiceHelper.retrieveElementData(getContext(), selected.isRemote(), selected.getUuid(), selected.getVersion().toString(), attachment); return bis; } Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DownloadElementAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DownloadElementAction.java 2008-02-18 23:55:44 UTC (rev 1108) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/DownloadElementAction.java 2008-02-18 23:57:32 UTC (rev 1109) @@ -19,15 +19,14 @@ package fr.cemagref.simexplorer.is.ui.swing.actions; import fr.cemagref.simexplorer.is.ui.StorageServiceHelper; -import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel; import fr.cemagref.simexplorer.is.ui.swing.actions.util.DownloadAbstractAction; +import static org.codelutin.i18n.I18n._; +import org.codelutin.util.FileUtil; import java.io.BufferedInputStream; import java.io.File; import java.text.MessageFormat; -import org.codelutin.util.FileUtil; - /** * Action pour downloader un Loggable Element * @@ -52,7 +51,7 @@ } protected File getFile() { - String dir = FileUtil.getDirectory("select directory where to download a Zip of '" + getElement().getName()+"-"+getVersion() + "'","choose a dir"); + String dir = FileUtil.getDirectory(_("simexplorer.action.download.le", selected.getMeta().getName() + " [" + selected.getVersion() + "]"), _("simexplorer.choose.dir")); if (dir == null) { // user cancel action return null; @@ -62,13 +61,13 @@ parent.mkdirs(); } File file; - file = new File(parent, FILENAME_PATTERN.format(new Object[]{getElement().getName() + "-" + getVersion()})); + file = new File(parent, FILENAME_PATTERN.format(new Object[]{selected.getMeta().getName() + "-" + selected.getVersion()})); return file; } protected BufferedInputStream getInputStream() { BufferedInputStream bis; - bis = StorageServiceHelper.retrieveElementFull(getContext(), ((DetailTabModel) getModel()).isRemote(), getUuid(), getVersion().toString()); + bis = StorageServiceHelper.retrieveElementFull(getContext(), selected.isRemote(), selected.getUuid(), selected.getVersion().toString()); return bis; } Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/DownloadAbstractAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/DownloadAbstractAction.java 2008-02-18 23:55:44 UTC (rev 1108) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/DownloadAbstractAction.java 2008-02-18 23:57:32 UTC (rev 1109) @@ -18,9 +18,7 @@ * ##% */ 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.ui.swing.model.DataEntityModel; import java.awt.event.ActionEvent; import java.io.BufferedInputStream; @@ -39,11 +37,10 @@ public static final int BUFFER_SIZE = 8 * 1024; private static final long serialVersionUID = 7535647131305304738L; - File file; - MetaData element; - String uuid; - Version version; + protected File file; + protected DataEntityModel selected; + protected DownloadAbstractAction(String name) { super(name); } @@ -52,42 +49,19 @@ protected abstract BufferedInputStream getInputStream(); - 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; - if (result) { - // ask user path where to save data - file = getFile(); - if (file == null) { - return false; - } + selected = findSelectedItem(e); + boolean selectedUuid = selected != null && selected.getUuid() != null; + if (!selectedUuid) { + return false; } - return result; + // ask user path where to save data + file = getFile(); + return file != null; } @Override @@ -108,16 +82,16 @@ protected void clear() { super.clear(); file = null; - element = null; - version = null; - uuid = null; + selected = null; + // action multi-tab + setTab(null); } private void storeStream(BufferedInputStream bis) throws IOException { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); try { if (bis == null) { - log.warn("could not get incoming data for " + uuid); + log.warn("could not get incoming data for " + selected.getUuid()); return; } byte[] buffer = new byte[BUFFER_SIZE];
participants (1)
-
tchemit@users.labs.libre-entreprise.org