KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > actions > publish > ActionPreview


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.publish;
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.window.messages.builders.*;
34 import org.openharmonise.vfs.*;
35 import org.openharmonise.vfs.context.*;
36 import org.openharmonise.vfs.gui.*;
37 import org.openharmonise.vfs.status.*;
38
39
40 /**
41  * Action to preview the content of a virtual file.
42  *
43  * @author Matthew Large
44  * @version $Revision: 1.1 $
45  *
46  */

47 public class ActionPreview extends AbstractHIMAction implements HIMAction {
48
49     public static String JavaDoc ACTION_NAME = "PREVIEW";
50
51     /**
52      *
53      */

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

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

71     private void setup() {
72         RuleGroup andGroup = new RuleGroup();
73         andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
74         
75         EnableRule rule = new IsDirectoryRule();
76         rule.setResultComparator(false);
77         andGroup.addEnableRule( rule );
78         
79         RuleGroup orGroup = new RuleGroup();
80         orGroup.setGroupType(RuleGroup.GROUPTYPE_OR);
81
82         orGroup.addEnableRule(new PathRule("/webdav/Content/Documents"));
83         orGroup.addEnableRule(new PathRule("/webdav/Website/Page Definition"));
84         orGroup.addEnableRule(new PathRule(
85                 "/webdav/Website/Composition/Page Templates"));
86         orGroup.addEnableRule(new PathRule("/webdav/Content/Assets"));
87         orGroup.addEnableRule(new PathRule("/webdav/Document"));
88         orGroup.addEnableRule(new PathRule("/webdav/Webpage"));
89         orGroup.addEnableRule(new PathRule("/webdav/XMLResource"));
90         orGroup.addEnableRule(new PathRule("/webdav/Assets"));
91
92         andGroup.addEnableRule(orGroup);
93         
94         super.addEnableRule(andGroup);
95     }
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
101      */

102     public void actionPerformed(ActionEvent JavaDoc arg0) {
103         StatusData statusOverall = new VFSStatus();
104         VirtualFile vfFile = this.getLastContextFile();
105         StateHandler.getInstance().addWait("PREVIEW-ACTION",
106                 "Opening previewer...");
107         String JavaDoc sFileName = vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile);
108         try {
109             StatusData status = EditorController.getInstance().preview(vfFile.getFullPath(),
110                     vfFile.getVFS());
111             statusOverall.addStatusData(status);
112         } catch (Exception JavaDoc e) {
113             e.printStackTrace(System.err);
114             statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
115         } finally {
116             StateHandler.getInstance().removeWait("PREVIEW-ACTION");
117             VFSMessageBuilder.getInstance().fireMessage(ActionPreview.ACTION_NAME, statusOverall, sFileName);
118         }
119     }
120
121     /*
122      * (non-Javadoc)
123      *
124      * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
125      */

126     public JMenuItem JavaDoc getMenuItem() {
127         JMenuItem JavaDoc menuItem = super.getMenuItem();
128         menuItem.setAccelerator(KeyStroke.getKeyStroke(this
129                 .getAcceleratorKeycode(), this.getAcceleratorMask()));
130
131         return menuItem;
132     }
133
134     /*
135      * (non-Javadoc)
136      *
137      * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
138      */

139     public String JavaDoc getDescription() {
140         return "Previews the currently selected resource";
141     }
142
143     /*
144      * (non-Javadoc)
145      *
146      * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
147      */

148     public String JavaDoc getText() {
149         return "Preview";
150     }
151
152     /*
153      * (non-Javadoc)
154      *
155      * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
156      */

157     public String JavaDoc getToolTip() {
158         return this.getDescription();
159     }
160
161     /*
162      * (non-Javadoc)
163      *
164      * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
165      */

166     public Icon JavaDoc getIcon() {
167         return IconManager.getInstance().getIcon("16-command-preview.gif");
168     }
169
170     /*
171      * (non-Javadoc)
172      *
173      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
174      */

175     public int getAcceleratorKeycode() {
176         return KeyEvent.VK_V;
177     }
178
179     /*
180      * (non-Javadoc)
181      *
182      * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
183      */

184     public String JavaDoc getMnemonic() {
185         return "v";
186     }
187
188     /*
189      * (non-Javadoc)
190      *
191      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
192      */

193     public int getAcceleratorMask() {
194         return InputEvent.CTRL_MASK + InputEvent.SHIFT_MASK;
195     }
196
197 }
Popular Tags