KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > actions > file > ActionOpen


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.actions.file;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.awt.event.InputEvent JavaDoc;
23 import java.awt.event.KeyEvent JavaDoc;
24
25 import javax.swing.Icon JavaDoc;
26 import javax.swing.JMenuItem JavaDoc;
27 import javax.swing.KeyStroke JavaDoc;
28
29 import org.openharmonise.him.actions.*;
30 import org.openharmonise.him.actions.rules.*;
31 import org.openharmonise.him.context.StateHandler;
32 import org.openharmonise.him.editors.*;
33 import org.openharmonise.him.harmonise.*;
34 import org.openharmonise.him.window.messages.builders.*;
35 import org.openharmonise.vfs.*;
36 import org.openharmonise.vfs.context.*;
37 import org.openharmonise.vfs.gui.*;
38 import org.openharmonise.vfs.status.*;
39
40
41 /**
42  * Action to open the content of a virtual file for editing.
43  *
44  * @author Matthew Large
45  * @version $Revision: 1.1 $
46  *
47  */

48 public class ActionOpen extends AbstractHIMAction implements HIMAction {
49
50     public static String JavaDoc ACTION_NAME = "OPEN";
51
52     /**
53      *
54      */

55     public ActionOpen() {
56         super();
57         this.setup();
58     }
59
60     /**
61      * @param vfFile
62      */

63     public ActionOpen(VirtualFile vfFile) {
64         super(vfFile);
65         this.setup();
66     }
67     
68     /**
69      * Configures this action.
70      *
71      */

72     private void setup() {
73         RuleGroup andGroup = new RuleGroup();
74         andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
75         IsLockedByOtherUser lockRule = new IsLockedByOtherUser();
76         lockRule.setResultComparator(false);
77         andGroup.addEnableRule(lockRule);
78         IsHistoricalRule histRule = new IsHistoricalRule();
79         histRule.setResultComparator(false);
80         andGroup.addEnableRule(histRule);
81         EnableRule rule = new IsDirectoryRule();
82         rule.setResultComparator(false);
83         andGroup.addEnableRule( rule );
84         TabRule tabRule = new TabRule("Search");
85         tabRule.setResultComparator(false);
86         andGroup.addEnableRule( tabRule );
87         PathRule pathRule = new PathRule(HarmonisePaths.PATH_REPORTS_OUTPUT);
88         pathRule.setResultComparator(false);
89         andGroup.addEnableRule(pathRule);
90         this.addEnableRule(andGroup);
91     }
92
93     /* (non-Javadoc)
94      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
95      */

96     public void actionPerformed(ActionEvent JavaDoc arg0) {
97         StatusData statusOverall = new VFSStatus();
98         VirtualFile vfFile = this.getLastContextFile();
99         String JavaDoc sFileName = vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile);
100         StateHandler.getInstance().addWait("OPEN-ACTION", "Opening editor...");
101         try {
102             StatusData status = EditorController.getInstance().open(vfFile.getFullPath(), vfFile.getVFS());
103             statusOverall.addStatusData(status);
104         } catch (Exception JavaDoc e) {
105             statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
106             e.printStackTrace(System.err);
107         } finally {
108             StateHandler.getInstance().removeWait("OPEN-ACTION");
109             VFSMessageBuilder.getInstance().fireMessage(ActionOpen.ACTION_NAME, statusOverall, sFileName);
110         }
111     }
112
113     /* (non-Javadoc)
114      * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
115      */

116     public JMenuItem JavaDoc getMenuItem() {
117         JMenuItem JavaDoc menuItem = super.getMenuItem();
118         menuItem.setAccelerator( KeyStroke.getKeyStroke(this.getAcceleratorKeycode(), this.getAcceleratorMask()) );
119         
120         return menuItem;
121     }
122
123     /* (non-Javadoc)
124      * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
125      */

126     public String JavaDoc getDescription() {
127         return "Opens the currently selected resource";
128     }
129
130     /* (non-Javadoc)
131      * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
132      */

133     public String JavaDoc getText() {
134         return "Open";
135     }
136
137     /* (non-Javadoc)
138      * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
139      */

140     public String JavaDoc getToolTip() {
141         return this.getDescription();
142     }
143
144     /* (non-Javadoc)
145      * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
146      */

147     public Icon JavaDoc getIcon() {
148         return IconManager.getInstance().getIcon("16-command-edit.gif");
149     }
150
151     /* (non-Javadoc)
152      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
153      */

154     public int getAcceleratorKeycode() {
155         return KeyEvent.VK_O;
156     }
157
158     /* (non-Javadoc)
159      * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
160      */

161     public String JavaDoc getMnemonic() {
162         return "O";
163     }
164
165     /* (non-Javadoc)
166      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
167      */

168     public int getAcceleratorMask() {
169         return InputEvent.CTRL_MASK;
170     }
171
172 }
173
Popular Tags