KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > actions > ReferredDocument


1 /*
2  * Authors:
3  * Stefanovic Nenad chupo@iis.ns.ac.yu
4  * Bojanic Sasa sasaboy@neobee.net
5  * Puskas Vladimir vpuskas@eunet.yu
6  * Pilipovic Goran zboniek@uns.ac.yu
7  *
8  */

9
10 package org.enhydra.jawe.actions;
11
12 import org.enhydra.jawe.*;
13 import org.enhydra.jawe.graph.*;
14 import org.enhydra.jawe.xml.elements.PackageHeader;
15
16 import java.awt.event.ActionEvent JavaDoc;
17 import java.io.*;
18 import javax.swing.*;
19
20 public class ReferredDocument extends ActionBase {
21
22    public ReferredDocument(AbstractEditor editor) {
23       super(editor);
24    }
25
26    public void actionPerformed(ActionEvent JavaDoc e) {
27       if (editor instanceof ProcessEditor) {
28          // First get the selected Activity, and it's referred document
29
Activity selected = (Activity)editor.getGraph().getSelectionCell();
30          String JavaDoc doc = selected.get("Documentation").toString();
31          // Then check if the file can be read, and complain about it.
32
showExternalDocument(doc);
33       } else {
34          String JavaDoc doc=((PackageHeader)((PackageEditor)editor).getXMLPackage().
35             get("PackageHeader")).get("Documentation").toString();
36          showExternalDocument(doc);
37       }
38    }
39
40    /**
41     * Java doesn't support direct opening of arbitrary documents,
42     * but this hack should do it. For Windows executing "start", and
43     * for KDE "kfmclient exec" will open document with associated
44     * application. Associations are of course system dependant, and
45     * we cannot do anything about them.
46     */

47    private void showExternalDocument(String JavaDoc document) {
48       if (!(new File(document).canRead())) {
49          JOptionPane.showMessageDialog(editor.getWindow(),
50             document+": "+
51             ResourceManager.getLanguageDependentString("InformationFileNotReadable"),
52             JaWE.getAppTitle(), JOptionPane.INFORMATION_MESSAGE);
53          return;
54       }
55       String JavaDoc startCommand = System.getProperty("path.to.start");
56       if (null != startCommand) {
57          if(!new File(startCommand).canRead()) {
58             JOptionPane.showMessageDialog(editor.getWindow(), startCommand + ": "
59                +ResourceManager.getLanguageDependentString("InformationFileNotReadable"),
60                JaWE.getAppTitle(), JOptionPane.INFORMATION_MESSAGE);
61             return;
62          }
63          if (System.getProperty("path.separator").equals(";")) {
64             document = "\"" + document + "\"";
65          }
66       } else {
67          if (System.getProperty("path.separator").equals(":")) {
68             startCommand = "kfmclient exec";
69          } else {
70             startCommand = "cmd /c start";
71             document = "\"" + document + "\"" + " \"" + document + "\"";
72          }
73       }
74       try {
75          Runtime.getRuntime().exec(startCommand + " " + document);
76       } catch (Throwable JavaDoc t) {
77          t.printStackTrace();
78       }
79    }
80
81
82 }
83
Popular Tags