r783 - in trunk/tutti-ui-swing/src/main: java/fr/ifremer/tutti/ui/swing/util java/fr/ifremer/tutti/ui/swing/util/attachment resources/i18n
Author: tchemit Date: 2013-04-15 22:27:37 +0200 (Mon, 15 Apr 2013) New Revision: 783 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/783 Log: fixes #2292: [TECH] Probl?\195?\168me lors de la visualisation d'une pi?\195?\168ce-jointe Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiErrorHelper.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUIHandler.java trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiErrorHelper.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiErrorHelper.java 2013-04-15 16:37:54 UTC (rev 782) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiErrorHelper.java 2013-04-15 20:27:37 UTC (rev 783) @@ -56,7 +56,11 @@ */ public void showErrorDialog(String message, Throwable cause) { - if (cause instanceof TuttiBusinessException) { + if (cause == null) { + JOptionPane.showMessageDialog(context.getMainUI(), message, + _("tutti.error.ui.business.error"), + JOptionPane.ERROR_MESSAGE); + } else if (cause instanceof TuttiBusinessException) { JOptionPane.showMessageDialog(context.getMainUI(), cause.getMessage(), _("tutti.error.ui.business.error"), JOptionPane.ERROR_MESSAGE); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java 2013-04-15 16:37:54 UTC (rev 782) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java 2013-04-15 20:27:37 UTC (rev 783) @@ -260,52 +260,46 @@ } } - public static void openLink(URI uri) { + public static Desktop getDesktopForBrowse() { - try { - if (!Desktop.isDesktopSupported()) { - throw new TuttiTechnicalException( - _("swing.error.desktop.not.supported")); - } + if (!Desktop.isDesktopSupported()) { + throw new TuttiTechnicalException( + _("swing.error.desktop.not.supported")); + } + Desktop desktop = Desktop.getDesktop(); - Desktop desktop = Desktop.getDesktop(); + if (!desktop.isSupported(Desktop.Action.BROWSE)) { - if (!desktop.isSupported(Desktop.Action.BROWSE)) { + throw new TuttiTechnicalException( + _("swing.error.desktop.browse.not.supported")); + } - throw new TuttiTechnicalException( - _("swing.error.desktop.browse.not.supported")); - } + return desktop; + } - desktop.browse(uri); - throw new RuntimeException(_("swing.error.cannot.open.link")); - } catch (Exception e) { + public static void openLink(URI uri) { - throw new TuttiTechnicalException(_("swing.error.cannot.open.link"), e); + if (!Desktop.isDesktopSupported()) { + throw new TuttiTechnicalException( + _("swing.error.desktop.not.supported")); } - } - public static void editLink(File uri) { + Desktop desktop = Desktop.getDesktop(); - try { - if (!Desktop.isDesktopSupported()) { - throw new TuttiTechnicalException( - _("swing.error.desktop.not.supported")); - } + if (!desktop.isSupported(Desktop.Action.BROWSE)) { + throw new TuttiTechnicalException( + _("swing.error.desktop.browse.not.supported")); + } - Desktop desktop = Desktop.getDesktop(); + try { - if (!desktop.isSupported(Desktop.Action.EDIT)) { - - throw new TuttiTechnicalException( - _("swing.error.desktop.browse.not.supported")); - } - - desktop.edit(uri); + desktop.browse(uri); } catch (Exception e) { - throw new TuttiTechnicalException("Could not open link: " + uri, e); + throw new TuttiTechnicalException( + _("swing.error.cannot.open.link", uri), e); } } @@ -323,7 +317,6 @@ } bean.removePropertyChangeListener(listener); } - } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUIHandler.java 2013-04-15 16:37:54 UTC (rev 782) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUIHandler.java 2013-04-15 20:27:37 UTC (rev 783) @@ -50,9 +50,11 @@ import javax.swing.JToolBar; import javax.swing.KeyStroke; import java.awt.Component; +import java.awt.Desktop; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.io.File; +import java.io.IOException; import java.util.List; import static org.nuiton.i18n.I18n._; @@ -261,17 +263,17 @@ public void openAttachment(Attachment attachment) { File file = persistenceService.getAttachmentFile(attachment.getId()); + + if (!file.exists()) { + throw new TuttiTechnicalException("File " + file.getAbsolutePath() + " does not exists."); + } + + Desktop desktop = TuttiUIUtil.getDesktopForBrowse(); try { - TuttiUIUtil.openLink(file.toURI()); + desktop.browse(file.toURI()); - } catch (TuttiTechnicalException e) { - String message; - if (e.getCause() instanceof TuttiTechnicalException) { - message = e.getCause().getMessage(); - } else { - message = _("swing.error.cannot.open.file"); - } - TuttiUIContext.getErrorHelper().showErrorDialog(message, e); + } catch (IOException e) { + TuttiUIContext.getErrorHelper().showErrorDialog(_("swing.error.cannot.open.file"), null); } } Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-04-15 16:37:54 UTC (rev 782) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-04-15 20:27:37 UTC (rev 783) @@ -1,5 +1,5 @@ swing.error.cannot.open.file=Aucun programme n'est défini pour ouvrir ce type de fichier. Enregistrez le fichier et ouvrez le en dehors de Tutti. -swing.error.cannot.open.link=La cible du lien n'existe pas. +swing.error.cannot.open.link=Impossible d'ouvrir le fichier %s. swing.error.desktop.browse.not.supported=Le navigateur n'a pas pu être ouvert. Vérifiez que vous avez défini un navigateur par défaut dans votre système. swing.error.desktop.not.supported=Votre système ne permet pas d'ouvrir des liens ou fichiers en dehors de Tutti. tutti.about.bottomText=Copyright %s - %s - version %s
participants (1)
-
tchemit@users.forge.codelutin.com