KickJava   Java API By Example, From Geeks To Geeks.

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


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 create a copy of a virtual file in the current collection.
38  *
39  * @author Matthew Large
40  * @version $Revision: 1.1 $
41  *
42  */

43 public class ActionCreateCopy extends AbstractHIMAction implements HIMAction {
44
45     public static String JavaDoc ACTION_NAME = "CREATE_COPY";
46
47     /**
48      *
49      */

50     public ActionCreateCopy() {
51         super();
52         this.setup();
53     }
54
55     /**
56      * @param vfFile
57      */

58     public ActionCreateCopy(VirtualFile vfFile) {
59         super(vfFile);
60         this.setup();
61     }
62     
63     /**
64      * Configures this action.
65      *
66      */

67     private void setup() {
68         RuleGroup andGroup = new RuleGroup();
69         andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
70         PathRule pathRule = new PathRule("/webdav/Archive/");
71         pathRule.setResultComparator(false);
72         andGroup.addEnableRule(pathRule);
73         IsHistoricalRule histRule = new IsHistoricalRule();
74         histRule.setResultComparator(false);
75         andGroup.addEnableRule(histRule);
76         SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_COPY);
77         andGroup.addEnableRule(secRule);
78         this.addEnableRule(andGroup);
79     }
80
81     /* (non-Javadoc)
82      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
83      */

84     public void actionPerformed(ActionEvent arg0) {
85         StateHandler.getInstance().addWait("COPY-ACTION");
86         StatusData statusOverall = new VFSStatus();
87         
88         String JavaDoc sResourceTitle = null;
89         
90         VirtualFile vfFile = this.getLastContextFile();
91         if(vfFile.isVersionable() && vfFile.getState().equals(VirtualFile.STATE_PENDING) && ((VersionedVirtualFile)vfFile).getLiveVersionPath()!=null) {
92             vfFile = vfFile.getVFS().getVirtualFile( ((VersionedVirtualFile)vfFile).getLiveVersionPath() ).getResource();
93         }
94         
95         try {
96             StatusData status = vfFile.copy(vfFile.getFilePath(), "copy_of_" + vfFile.getFileName());
97             statusOverall.addStatusData(status);
98             if( status.isOK() ) {
99                 super.fireSessionEvent("Copy created", vfFile.getVFS(), vfFile.getFullPath(), SessionEventData.RESOURCE_COPIED);
100             } else {
101
102             }
103             
104             sResourceTitle = vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile);
105         } catch (Exception JavaDoc e) {
106             e.printStackTrace(System.err);
107             statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
108         } finally {
109             VFSMessageBuilder.getInstance().fireMessage(ActionCreateCopy.ACTION_NAME, statusOverall, sResourceTitle);
110             StateHandler.getInstance().removeWait("COPY-ACTION");
111         }
112
113     }
114
115     /* (non-Javadoc)
116      * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
117      */

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

128     public String JavaDoc getDescription() {
129         return "Creates a copy of the resource in the current collection";
130     }
131
132     /* (non-Javadoc)
133      * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
134      */

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

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

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

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

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

170     public int getAcceleratorMask() {
171         return InputEvent.CTRL_MASK;
172     }
173
174 }
175
Popular Tags