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