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.*;
022:
023: import javax.swing.*;
024:
025: import org.openharmonise.him.actions.*;
026: import org.openharmonise.him.actions.rules.*;
027: import org.openharmonise.him.context.StateHandler;
028: import org.openharmonise.him.window.messages.builders.*;
029: import org.openharmonise.vfs.*;
030: import org.openharmonise.vfs.context.*;
031: import org.openharmonise.vfs.gui.*;
032: import org.openharmonise.vfs.status.*;
033:
034: /**
035: * Action to lock a virtual file.
036: *
037: * @author Matthew Large
038: * @version $Revision: 1.1 $
039: *
040: */
041: public class ActionLock extends AbstractHIMAction implements HIMAction {
042:
043: public static String ACTION_NAME = "LOCK";
044:
045: /**
046: *
047: */
048: public ActionLock() {
049: super ();
050: this .setup();
051: }
052:
053: /**
054: * @param vfFile
055: */
056: public ActionLock(VirtualFile vfFile) {
057: super (vfFile);
058: this .setup();
059: }
060:
061: /**
062: * Configures this action.
063: *
064: */
065: private void setup() {
066: RuleGroup andGroup = new RuleGroup();
067: andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
068: PathRule pathRule = new PathRule("/webdav/Archive/");
069: pathRule.setResultComparator(false);
070: andGroup.addEnableRule(pathRule);
071: IsHistoricalRule histRule = new IsHistoricalRule();
072: histRule.setResultComparator(false);
073: andGroup.addEnableRule(histRule);
074: SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_LOCK);
075: andGroup.addEnableRule(secRule);
076: this .addEnableRule(andGroup);
077: }
078:
079: /* (non-Javadoc)
080: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
081: */
082: public void actionPerformed(ActionEvent arg0) {
083: StateHandler.getInstance().addWait("LOCK-ACTION");
084: StatusData statusOverall = new VFSStatus();
085:
086: String sFileName = null;
087: String sLockUser = null;
088: try {
089: if (this .getLastContextFile().isLocked()) {
090: sLockUser = this .getLastContextFile().getLockOwner();
091: }
092: sFileName = this .getLastContextFile().getVFS()
093: .getVirtualFileSystemView().getDisplayName(
094: this .getLastContextFile());
095: StatusData status = this .getLastContextFile().lock();
096: statusOverall.addStatusData(status);
097:
098: if (status.isOK()) {
099: // super.fireSessionEvent("Locked", this.getLastContextFile().getVFS(), this.getLastContextFile().getFullPath(), SessionEventData.RESOURCE_LOCKED);
100: } else {
101: }
102: } catch (Exception e) {
103: e.printStackTrace(System.err);
104: statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
105: } finally {
106: VFSMessageBuilder.getInstance().fireMessage(
107: ActionLock.ACTION_NAME, statusOverall, sFileName,
108: sLockUser);
109: StateHandler.getInstance().removeWait("LOCK-ACTION");
110: }
111: }
112:
113: /* (non-Javadoc)
114: * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
115: */
116: public JMenuItem getMenuItem() {
117: JMenuItem menuItem = super .getMenuItem();
118: menuItem.setAccelerator(KeyStroke.getKeyStroke(this
119: .getAcceleratorKeycode(), this .getAcceleratorMask()));
120:
121: return menuItem;
122: }
123:
124: /* (non-Javadoc)
125: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
126: */
127: public String getDescription() {
128: return "Locks the currently selected resource so that others cannot edit it";
129: }
130:
131: /* (non-Javadoc)
132: * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
133: */
134: public String getText() {
135: return "Lock";
136: }
137:
138: /* (non-Javadoc)
139: * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
140: */
141: public String getToolTip() {
142: return this .getDescription();
143: }
144:
145: /* (non-Javadoc)
146: * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
147: */
148: public Icon getIcon() {
149: return IconManager.getInstance().getIcon("16-command-lock.gif");
150: }
151:
152: /* (non-Javadoc)
153: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
154: */
155: public int getAcceleratorKeycode() {
156: return KeyEvent.VK_L;
157: }
158:
159: /* (non-Javadoc)
160: * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
161: */
162: public String getMnemonic() {
163: return "L";
164: }
165:
166: /* (non-Javadoc)
167: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
168: */
169: public int getAcceleratorMask() {
170: return InputEvent.CTRL_MASK;
171: }
172:
173: /* (non-Javadoc)
174: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#isEnabled(com.simulacramedia.contentmanager.context.ContextEvent)
175: */
176: public boolean isEnabled(ContextEvent ce) {
177: if (ce.CONTEXT_TYPE == ContextType.CONTEXT_FILES
178: && super .isEnabled(ce)) {
179: VirtualFile vfFile = ce.getVFS().getVirtualFile(
180: ce.getPath()).getResource();
181: if (vfFile != null) {
182: this .setEnabled(!vfFile.isLocked());
183: return !vfFile.isLocked();
184: } else {
185: return false;
186: }
187: } else {
188: this .setEnabled(false);
189: return false;
190: }
191: }
192:
193: }
|