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.file;
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.harmonise.*;
034: import org.openharmonise.him.window.messages.builders.*;
035: import org.openharmonise.vfs.*;
036: import org.openharmonise.vfs.context.*;
037: import org.openharmonise.vfs.gui.*;
038: import org.openharmonise.vfs.status.*;
039:
040: /**
041: * Action to open the content of a virtual file for editing.
042: *
043: * @author Matthew Large
044: * @version $Revision: 1.1 $
045: *
046: */
047: public class ActionOpen extends AbstractHIMAction implements HIMAction {
048:
049: public static String ACTION_NAME = "OPEN";
050:
051: /**
052: *
053: */
054: public ActionOpen() {
055: super ();
056: this .setup();
057: }
058:
059: /**
060: * @param vfFile
061: */
062: public ActionOpen(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: IsLockedByOtherUser lockRule = new IsLockedByOtherUser();
075: lockRule.setResultComparator(false);
076: andGroup.addEnableRule(lockRule);
077: IsHistoricalRule histRule = new IsHistoricalRule();
078: histRule.setResultComparator(false);
079: andGroup.addEnableRule(histRule);
080: EnableRule rule = new IsDirectoryRule();
081: rule.setResultComparator(false);
082: andGroup.addEnableRule(rule);
083: TabRule tabRule = new TabRule("Search");
084: tabRule.setResultComparator(false);
085: andGroup.addEnableRule(tabRule);
086: PathRule pathRule = new PathRule(
087: HarmonisePaths.PATH_REPORTS_OUTPUT);
088: pathRule.setResultComparator(false);
089: andGroup.addEnableRule(pathRule);
090: this .addEnableRule(andGroup);
091: }
092:
093: /* (non-Javadoc)
094: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
095: */
096: public void actionPerformed(ActionEvent arg0) {
097: StatusData statusOverall = new VFSStatus();
098: VirtualFile vfFile = this .getLastContextFile();
099: String sFileName = vfFile.getVFS().getVirtualFileSystemView()
100: .getDisplayName(vfFile);
101: StateHandler.getInstance().addWait("OPEN-ACTION",
102: "Opening editor...");
103: try {
104: StatusData status = EditorController.getInstance().open(
105: vfFile.getFullPath(), vfFile.getVFS());
106: statusOverall.addStatusData(status);
107: } catch (Exception e) {
108: statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
109: e.printStackTrace(System.err);
110: } finally {
111: StateHandler.getInstance().removeWait("OPEN-ACTION");
112: VFSMessageBuilder.getInstance().fireMessage(
113: ActionOpen.ACTION_NAME, statusOverall, sFileName);
114: }
115: }
116:
117: /* (non-Javadoc)
118: * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
119: */
120: public JMenuItem getMenuItem() {
121: JMenuItem menuItem = super .getMenuItem();
122: menuItem.setAccelerator(KeyStroke.getKeyStroke(this
123: .getAcceleratorKeycode(), this .getAcceleratorMask()));
124:
125: return menuItem;
126: }
127:
128: /* (non-Javadoc)
129: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
130: */
131: public String getDescription() {
132: return "Opens the currently selected resource";
133: }
134:
135: /* (non-Javadoc)
136: * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
137: */
138: public String getText() {
139: return "Open";
140: }
141:
142: /* (non-Javadoc)
143: * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
144: */
145: public String getToolTip() {
146: return this .getDescription();
147: }
148:
149: /* (non-Javadoc)
150: * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
151: */
152: public Icon getIcon() {
153: return IconManager.getInstance().getIcon("16-command-edit.gif");
154: }
155:
156: /* (non-Javadoc)
157: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
158: */
159: public int getAcceleratorKeycode() {
160: return KeyEvent.VK_O;
161: }
162:
163: /* (non-Javadoc)
164: * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
165: */
166: public String getMnemonic() {
167: return "O";
168: }
169:
170: /* (non-Javadoc)
171: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
172: */
173: public int getAcceleratorMask() {
174: return InputEvent.CTRL_MASK;
175: }
176:
177: }
|