001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.actions.publish;
020:
021: import java.awt.event.ActionEvent;
022: import java.awt.event.InputEvent;
023: import java.awt.event.KeyEvent;
024:
025: import javax.swing.Icon;
026: import javax.swing.JMenuItem;
027: import javax.swing.KeyStroke;
028:
029: import org.openharmonise.him.actions.*;
030: import org.openharmonise.him.actions.rules.*;
031: import org.openharmonise.him.context.StateHandler;
032: import org.openharmonise.him.editors.*;
033: import org.openharmonise.him.window.messages.builders.*;
034: import org.openharmonise.vfs.*;
035: import org.openharmonise.vfs.context.*;
036: import org.openharmonise.vfs.gui.*;
037: import org.openharmonise.vfs.status.*;
038:
039: /**
040: * Action to preview the content of a virtual file.
041: *
042: * @author Matthew Large
043: * @version $Revision: 1.1 $
044: *
045: */
046: public class ActionPreview extends AbstractHIMAction implements
047: HIMAction {
048:
049: public static String ACTION_NAME = "PREVIEW";
050:
051: /**
052: *
053: */
054: public ActionPreview() {
055: super ();
056: this .setup();
057: }
058:
059: /**
060: * @param vfFile
061: */
062: public ActionPreview(VirtualFile vfFile) {
063: super (vfFile);
064: this .setup();
065: }
066:
067: /**
068: * Configures this action.
069: *
070: */
071: private void setup() {
072: RuleGroup andGroup = new RuleGroup();
073: andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
074:
075: EnableRule rule = new IsDirectoryRule();
076: rule.setResultComparator(false);
077: andGroup.addEnableRule(rule);
078:
079: RuleGroup orGroup = new RuleGroup();
080: orGroup.setGroupType(RuleGroup.GROUPTYPE_OR);
081:
082: orGroup
083: .addEnableRule(new PathRule("/webdav/Content/Documents"));
084: orGroup.addEnableRule(new PathRule(
085: "/webdav/Website/Page Definition"));
086: orGroup.addEnableRule(new PathRule(
087: "/webdav/Website/Composition/Page Templates"));
088: orGroup.addEnableRule(new PathRule("/webdav/Content/Assets"));
089: orGroup.addEnableRule(new PathRule("/webdav/Document"));
090: orGroup.addEnableRule(new PathRule("/webdav/Webpage"));
091: orGroup.addEnableRule(new PathRule("/webdav/XMLResource"));
092: orGroup.addEnableRule(new PathRule("/webdav/Assets"));
093:
094: andGroup.addEnableRule(orGroup);
095:
096: super .addEnableRule(andGroup);
097: }
098:
099: /*
100: * (non-Javadoc)
101: *
102: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
103: */
104: public void actionPerformed(ActionEvent arg0) {
105: StatusData statusOverall = new VFSStatus();
106: VirtualFile vfFile = this .getLastContextFile();
107: StateHandler.getInstance().addWait("PREVIEW-ACTION",
108: "Opening previewer...");
109: String sFileName = vfFile.getVFS().getVirtualFileSystemView()
110: .getDisplayName(vfFile);
111: try {
112: StatusData status = EditorController.getInstance().preview(
113: vfFile.getFullPath(), vfFile.getVFS());
114: statusOverall.addStatusData(status);
115: } catch (Exception e) {
116: e.printStackTrace(System.err);
117: statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
118: } finally {
119: StateHandler.getInstance().removeWait("PREVIEW-ACTION");
120: VFSMessageBuilder.getInstance()
121: .fireMessage(ActionPreview.ACTION_NAME,
122: statusOverall, sFileName);
123: }
124: }
125:
126: /*
127: * (non-Javadoc)
128: *
129: * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
130: */
131: public JMenuItem getMenuItem() {
132: JMenuItem menuItem = super .getMenuItem();
133: menuItem.setAccelerator(KeyStroke.getKeyStroke(this
134: .getAcceleratorKeycode(), this .getAcceleratorMask()));
135:
136: return menuItem;
137: }
138:
139: /*
140: * (non-Javadoc)
141: *
142: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
143: */
144: public String getDescription() {
145: return "Previews the currently selected resource";
146: }
147:
148: /*
149: * (non-Javadoc)
150: *
151: * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
152: */
153: public String getText() {
154: return "Preview";
155: }
156:
157: /*
158: * (non-Javadoc)
159: *
160: * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
161: */
162: public String getToolTip() {
163: return this .getDescription();
164: }
165:
166: /*
167: * (non-Javadoc)
168: *
169: * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
170: */
171: public Icon getIcon() {
172: return IconManager.getInstance().getIcon(
173: "16-command-preview.gif");
174: }
175:
176: /*
177: * (non-Javadoc)
178: *
179: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
180: */
181: public int getAcceleratorKeycode() {
182: return KeyEvent.VK_V;
183: }
184:
185: /*
186: * (non-Javadoc)
187: *
188: * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
189: */
190: public String getMnemonic() {
191: return "v";
192: }
193:
194: /*
195: * (non-Javadoc)
196: *
197: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
198: */
199: public int getAcceleratorMask() {
200: return InputEvent.CTRL_MASK + InputEvent.SHIFT_MASK;
201: }
202:
203: }
|