001: /*
002: * HelpManager.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.help;
013:
014: import java.io.File;
015: import workbench.WbManager;
016: import workbench.gui.WbSwingUtilities;
017: import workbench.log.LogMgr;
018: import workbench.resource.ResourceMgr;
019: import workbench.resource.Settings;
020: import workbench.util.BrowserLauncher;
021: import workbench.util.StringUtil;
022:
023: /**
024: *
025: * @author support@sql-workbench.net
026: */
027: public class HelpManager {
028: public static void showPdfHelp() {
029: try {
030: String pdf = Settings.getInstance().getPdfPath();
031: if (pdf == null) {
032: String msg = ResourceMgr.getString("ErrManualNotFound");
033: msg = StringUtil.replace(msg, "%jarpath%", WbManager
034: .getInstance().getJarPath());
035: WbSwingUtilities.showMessage(WbManager.getInstance()
036: .getCurrentWindow(), msg);
037: return;
038: }
039:
040: String readerPath = Settings.getInstance()
041: .getPDFReaderPath();
042: if (StringUtil.isEmptyString(readerPath)) {
043: String msg = ResourceMgr
044: .getString("ErrNoReaderDefined");
045: WbSwingUtilities.showErrorMessage(WbManager
046: .getInstance().getCurrentWindow(), msg);
047: return;
048: }
049:
050: File reader = new File(readerPath);
051: if (!reader.exists() || !reader.canRead()
052: || !reader.isFile()) {
053: String msg = ResourceMgr.getString("ErrExeNotAvail");
054: msg = StringUtil.replace(msg, "%exepath%", readerPath);
055: WbSwingUtilities.showErrorMessage(WbManager
056: .getInstance().getCurrentWindow(), msg);
057: return;
058: }
059:
060: String[] cmd = new String[] { readerPath, pdf };
061: Runtime.getRuntime().exec(cmd);
062: } catch (Exception ex) {
063: LogMgr.logError("HelpManager.showPdf()",
064: "Error when running PDF Viewer", ex);
065: }
066: }
067:
068: public static void showHelpFile(String filename) {
069: File dir = Settings.getInstance().getHtmlManualDir();
070: File manual = null;
071: if (dir != null) {
072: manual = new File(dir, filename);
073: }
074:
075: if (manual == null || !manual.exists()) {
076: String msg = ResourceMgr.getFormattedString(
077: "ErrHelpFileNotFound", filename, dir);
078: WbSwingUtilities.showErrorMessage(WbManager.getInstance()
079: .getCurrentWindow(), msg);
080: return;
081: }
082:
083: try {
084: BrowserLauncher.openURL(manual.toURL().toString());
085: } catch (Exception ex) {
086: LogMgr.logError("ShowHelpAction.executeAction",
087: "Error displaying manual", ex);
088: }
089: }
090:
091: public static void showHelpIndex() {
092: showHelpFile("workbench-manual.html");
093: }
094:
095: public static void showDataPumperHelp() {
096: showHelpFile("data-pumper.html");
097: }
098:
099: public static void showOptionsHelp() {
100: showHelpFile("options.html");
101: }
102:
103: public static void showProfileHelp() {
104: showHelpFile("profiles.html");
105: }
106:
107: }
|