KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > actions > file > ActionUnlock


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.file;
20
21 import java.awt.event.*;
22
23 import javax.swing.*;
24
25 import org.openharmonise.him.actions.*;
26 import org.openharmonise.him.actions.rules.*;
27 import org.openharmonise.him.context.StateHandler;
28 import org.openharmonise.him.window.messages.builders.*;
29 import org.openharmonise.him.window.session.*;
30 import org.openharmonise.vfs.*;
31 import org.openharmonise.vfs.context.*;
32 import org.openharmonise.vfs.gui.*;
33 import org.openharmonise.vfs.status.*;
34
35
36 /**
37  * Action to unlock a virtual file.
38  *
39  * @author Matthew Large
40  * @version $Revision: 1.1 $
41  *
42  */

43 public class ActionUnlock extends AbstractHIMAction implements HIMAction {
44
45     public static String JavaDoc ACTION_NAME = "UNLOCK";
46
47     /**
48      * Wait identifier for state handler.
49      */

50     private static final String JavaDoc WAIT_LABEL = "UNLOCK-ACTION";
51     /**
52      *
53      */

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

62     public ActionUnlock(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         PathRule pathRule = new PathRule("/webdav/Archive/");
75         pathRule.setResultComparator(false);
76         andGroup.addEnableRule(pathRule);
77         IsHistoricalRule histRule = new IsHistoricalRule();
78         histRule.setResultComparator(false);
79         andGroup.addEnableRule(histRule);
80         SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_UNLOCK);
81         andGroup.addEnableRule(secRule);
82         this.addEnableRule(andGroup);
83     }
84
85     /* (non-Javadoc)
86      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
87      */

88     public void actionPerformed(ActionEvent arg0) {
89         StateHandler.getInstance().addWait(WAIT_LABEL);
90         StatusData statusOverall = new VFSStatus();
91         
92         String JavaDoc sFileName = null;
93         String JavaDoc sLockUser = null;
94         try {
95             if(this.getLastContextFile().isLocked()) {
96                 sLockUser = this.getLastContextFile().getLockOwner();
97             }
98             sFileName = this.getLastContextFile().getVFS().getVirtualFileSystemView().getDisplayName(this.getLastContextFile());
99             StatusData status = this.getLastContextFile().unlock();
100             statusOverall.addStatusData(status);
101             
102             if(status.isOK()) {
103                 super.fireSessionEvent("Unlocked", this.getLastContextFile().getVFS(), this.getLastContextFile().getFullPath(), SessionEventData.RESOURCE_UNLOCKED);
104             } else {
105
106             }
107         } catch (Exception JavaDoc e) {
108             e.printStackTrace(System.err);
109             statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
110         } finally {
111             VFSMessageBuilder.getInstance().fireMessage(ActionUnlock.ACTION_NAME, statusOverall, sFileName, sLockUser);
112             StateHandler.getInstance().removeWait(WAIT_LABEL);
113         }
114     }
115
116     /* (non-Javadoc)
117      * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
118      */

119     public JMenuItem getMenuItem() {
120         JMenuItem menuItem = super.getMenuItem();
121         menuItem.setAccelerator( KeyStroke.getKeyStroke(this.getAcceleratorKeycode(), this.getAcceleratorMask()) );
122         
123         return menuItem;
124     }
125
126     /* (non-Javadoc)
127      * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
128      */

129     public String JavaDoc getDescription() {
130         return "Unlocks the currently selected resource to allow others to edit it";
131     }
132
133     /* (non-Javadoc)
134      * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
135      */

136     public String JavaDoc getText() {
137         return "Unlock";
138     }
139
140     /* (non-Javadoc)
141      * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
142      */

143     public String JavaDoc getToolTip() {
144         return this.getDescription();
145     }
146
147     /* (non-Javadoc)
148      * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
149      */

150     public Icon getIcon() {
151         return IconManager.getInstance().getIcon("16-blank.gif");
152     }
153
154     /* (non-Javadoc)
155      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
156      */

157     public int getAcceleratorKeycode() {
158         return KeyEvent.VK_U;
159     }
160
161     /* (non-Javadoc)
162      * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
163      */

164     public String JavaDoc getMnemonic() {
165         return "U";
166     }
167
168     /* (non-Javadoc)
169      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
170      */

171     public int getAcceleratorMask() {
172         return InputEvent.CTRL_MASK;
173     }
174
175     /* (non-Javadoc)
176      * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#isEnabled(com.simulacramedia.contentmanager.context.ContextEvent)
177      */

178     public boolean isEnabled(ContextEvent ce) {
179         if(ce.CONTEXT_TYPE==ContextType.CONTEXT_FILES && super.isEnabled(ce)) {
180             VirtualFile vfFile = ce.getVFS().getVirtualFile(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
Popular Tags