KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > rcp > action > ReOpenFileAction


1 /**
2  * <p> Project: com.nightlabs.base </p>
3  * <p> Copyright: Copyright (c) 2005 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 20.06.2005 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.rcp.action;
9
10 import java.io.File JavaDoc;
11
12 import org.eclipse.jface.action.Action;
13 import org.eclipse.ui.PartInitException;
14
15 import com.nightlabs.base.NLBasePlugin;
16 import com.nightlabs.rcp.io.IOUtil;
17 import com.nightlabs.rcp.util.RCPUtil;
18
19 public class ReOpenFileAction
20 extends Action
21 {
22     public static final String JavaDoc ID = ReOpenFileAction.class.getName();
23     protected String JavaDoc fileName;
24     
25     public ReOpenFileAction(String JavaDoc fileName)
26     {
27         if (fileName == null)
28             throw new IllegalArgumentException JavaDoc("Param fileName must not be null!");
29         
30         this.fileName = fileName;
31         init();
32     }
33     
34     protected void init()
35     {
36         setId(ID + "-" + fileName + fileName.hashCode());
37         setText(fileName);
38         setToolTipText(fileName);
39     }
40
41     public String JavaDoc getFileName() {
42         return fileName;
43     }
44     
45     public void run()
46     {
47         try
48         {
49             File JavaDoc file = new File JavaDoc(fileName);
50             if (file.exists())
51                 IOUtil.openFile(file);
52         }
53         catch (PartInitException e)
54         {
55             RCPUtil.showErrorDialog(
56                     NLBasePlugin.getResourceString("action.openfile.error.message1")
57                     + " " + fileName + " " +
58                     NLBasePlugin.getResourceString("action.openfile.error.message2")
59             );
60             e.printStackTrace();
61         }
62     }
63         
64 }
65
Popular Tags