KickJava   Java API By Example, From Geeks To Geeks.

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


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

47 public class ActionArchive extends AbstractHIMAction implements HIMAction {
48
49     public static String JavaDoc ACTION_NAME = "ARCHIVE";
50
51     /**
52      * Wait identifier for state handler.
53      */

54     private static final String JavaDoc WAIT_LABEL = "ARCHIVE-ACTION";
55     
56     /**
57      *
58      */

59     public ActionArchive() {
60         super();
61         this.setup();
62     }
63
64     /**
65      * @param vfFile
66      */

67     public ActionArchive(VirtualFile vfFile) {
68         super(vfFile);
69         this.setup();
70     }
71     
72     /**
73      * Configures this action.
74      *
75      */

76     private void setup() {
77         RuleGroup andGroup = new RuleGroup();
78         andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
79         PathRule pathRule = new PathRule("/webdav/Archive/");
80         pathRule.setResultComparator(false);
81         andGroup.addEnableRule(pathRule);
82         PathEquals pathEqualsRule = new PathEquals(HarmonisePaths.PATH_USERS_ADMIN + "/super");
83         pathEqualsRule.setResultComparator(false);
84         andGroup.addEnableRule(pathEqualsRule);
85         PathEquals pathEqualsRule2 = new PathEquals(HarmonisePaths.PATH_REPORTS_QUERIES + "/LinkChecker");
86         pathEqualsRule2.setResultComparator(false);
87         andGroup.addEnableRule(pathEqualsRule2);
88         IsHistoricalRule histRule = new IsHistoricalRule();
89         histRule.setResultComparator(false);
90         andGroup.addEnableRule(histRule);
91         SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_DELETE);
92         andGroup.addEnableRule(secRule);
93         ParentPathEquals ppathRule = new ParentPathEquals(HarmonisePaths.PATH_ASSETS);
94         ppathRule.setResultComparator(false);
95         andGroup.addEnableRule(ppathRule);
96         this.addEnableRule(andGroup);
97     }
98
99     /* (non-Javadoc)
100      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
101      */

102     public void actionPerformed(ActionEvent ae) {
103         StateHandler.getInstance().addWait(WAIT_LABEL);
104         StatusData statusOverall = new VFSStatus();
105         
106         String JavaDoc sFileName = null;
107         boolean bFound = false;
108         try {
109             VirtualFile vfFile = this.getLastContextFile();
110     
111             if(vfFile.isDirectory()) {
112                 Iterator itor = vfFile.getChildren().iterator();
113                 while (itor.hasNext()) {
114                     String JavaDoc sPath = (String JavaDoc) itor.next();
115                     VirtualFile vfChild = vfFile.getVFS().getVirtualFile(sPath).getResource();
116                     if(vfChild.getState()==VirtualFile.STATE_LIVE) {
117                         bFound = true;
118                         break;
119                     }
120                 }
121             }
122             if(bFound) {
123                 MessageHandler.getInstance().fireMessageEvent("This collection has published children, you must delete those first.", MessageHandler.TYPE_ERROR);
124             } else {
125                 sFileName = vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile);
126                 String JavaDoc sMessage = null;
127                 StatusData status = vfFile.delete();
128                 statusOverall.addStatusData(status);
129                 if( status.isOK() ) {
130                     this.getLastContextDirectory().removeChild(vfFile.getFullPath());
131                     this.getLastContextDirectory().refreshChildren();
132                     this.getLastContextDirectory().fireVirtualFileEvent(VirtualFileEvent.FILE_MEMBERS_CHANGED);
133                     super.fireSessionEvent("Archived", vfFile.getVFS(), vfFile.getFullPath().replaceAll("webdav", "webdav/Archive"), SessionEventData.RESOURCE_ARCHIVED);
134                 } else {
135                 }
136             }
137             
138
139         } catch (Exception JavaDoc e) {
140             e.printStackTrace(System.err);
141             statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
142         } finally {
143             if(!bFound) {
144                 VFSMessageBuilder.getInstance().fireMessage(ActionArchive.ACTION_NAME, statusOverall, sFileName);
145             }
146             StateHandler.getInstance().removeWait(WAIT_LABEL);
147         }
148     }
149
150     /* (non-Javadoc)
151      * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
152      */

153     public JMenuItem getMenuItem() {
154         JMenuItem menuItem = super.getMenuItem();
155         menuItem.setAccelerator( KeyStroke.getKeyStroke(this.getAcceleratorKeycode(), this.getAcceleratorMask()) );
156         
157         return menuItem;
158     }
159
160     /* (non-Javadoc)
161      * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
162      */

163     public String JavaDoc getDescription() {
164         return "Archives the currently selected resource";
165     }
166
167     /* (non-Javadoc)
168      * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
169      */

170     public String JavaDoc getText() {
171         return "Archive";
172     }
173
174     /* (non-Javadoc)
175      * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
176      */

177     public String JavaDoc getToolTip() {
178         return this.getDescription();
179     }
180
181     /* (non-Javadoc)
182      * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
183      */

184     public Icon getIcon() {
185         return IconManager.getInstance().getIcon("16-archive-container.gif");
186     }
187
188     /* (non-Javadoc)
189      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
190      */

191     public int getAcceleratorKeycode() {
192         return KeyEvent.VK_A;
193     }
194
195     /* (non-Javadoc)
196      * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
197      */

198     public String JavaDoc getMnemonic() {
199         return "A";
200     }
201
202     /* (non-Javadoc)
203      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
204      */

205     public int getAcceleratorMask() {
206         return InputEvent.CTRL_MASK;
207     }
208
209 }
210
Popular Tags