KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > actions > publish > ActionRetrieve


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.publish;
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 retrieve a historical or archived virtual file.
38  *
39  * @author Matthew Large
40  * @version $Revision: 1.1 $
41  *
42  */

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

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

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

63     public ActionRetrieve(VirtualFile vfFile) {
64         super(vfFile);
65         this.setup();
66     }
67     
68     /**
69      * Configures this action.
70      *
71      */

72     private void setup() {
73         RuleGroup andGroupTop = new RuleGroup();
74         andGroupTop.setGroupType(RuleGroup.GROUPTYPE_AND);
75         
76         RuleGroup orGroup = new RuleGroup();
77         orGroup.setGroupType(RuleGroup.GROUPTYPE_OR);
78         
79         RuleGroup andGroup = new RuleGroup();
80         andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
81         
82         EnableRule isDirRule = new IsDirectoryRule();
83         isDirRule.setResultComparator(false);
84         andGroup.addEnableRule(isDirRule);
85         EnableRule pathRule = new PathRule("/webdav/Archive/");
86         andGroup.addEnableRule(pathRule);
87         orGroup.addEnableRule(andGroup);
88         
89         EnableRule isHistorical = new IsHistoricalRule();
90         orGroup.addEnableRule(isHistorical);
91         
92         andGroupTop.addEnableRule(orGroup);
93         
94         SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_CHECKOUT);
95         andGroupTop.addEnableRule(secRule);
96         
97         this.addEnableRule(andGroupTop);
98     }
99
100     /* (non-Javadoc)
101      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
102      */

103     public void actionPerformed(ActionEvent arg0) {
104         VirtualFile vfFile = this.getLastContextFile();
105         StatusData statusOverall = new VFSStatus();
106         
107         if (vfFile.isVersionable()) {
108             VersionedVirtualFile vfVerFile = (VersionedVirtualFile) vfFile;
109             StateHandler.getInstance().addWait(WAIT_LABEL);
110             String JavaDoc sFileName = null;
111             try {
112                 sFileName =
113                     vfFile.getVFS().getVirtualFileSystemView().getDisplayName(
114                         vfFile);
115                 String JavaDoc sMessage = null;
116                 StatusData status = ((VersionedVirtualFile)this.getLastContextFile()).reactivate();
117                 statusOverall.addStatusData(status);
118                 
119                 if (status.isOK()) {
120                     super.fireSessionEvent("Retrieved", this.getLastContextFile().getVFS(), this.getLastContextFile().getFullPath(), SessionEventData.RESOURCE_REACTIVATED);
121                 } else {
122                 }
123             } catch (Exception JavaDoc e) {
124                 e.printStackTrace(System.err);
125                 statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
126             } finally {
127                 StateHandler.getInstance().removeWait(WAIT_LABEL);
128                 this.getLastContextDirectory().refreshChildren();
129                 VFSMessageBuilder.getInstance().fireMessage(ActionRetrieve.ACTION_NAME, statusOverall, sFileName);
130             }
131         }
132     }
133
134     /* (non-Javadoc)
135      * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
136      */

137     public String JavaDoc getDescription() {
138         return "Retrieves the currently selected resource from the archive";
139     }
140
141     /* (non-Javadoc)
142      * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
143      */

144     public String JavaDoc getText() {
145         return "Retrieve";
146     }
147
148     /* (non-Javadoc)
149      * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
150      */

151     public String JavaDoc getToolTip() {
152         return this.getDescription();
153     }
154
155     /* (non-Javadoc)
156      * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
157      */

158     public Icon getIcon() {
159         return IconManager.getInstance().getIcon("16-command-retrieve.gif");
160     }
161
162     /* (non-Javadoc)
163      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
164      */

165     public int getAcceleratorKeycode() {
166         return 0;
167     }
168
169     /* (non-Javadoc)
170      * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
171      */

172     public String JavaDoc getMnemonic() {
173         return "R";
174     }
175
176     /* (non-Javadoc)
177      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
178      */

179     public int getAcceleratorMask() {
180         return 0;
181     }
182
183 }
184
Popular Tags