KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > actions > move > ActionCopy


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.move;
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.vfs.*;
30 import org.openharmonise.vfs.context.*;
31 import org.openharmonise.vfs.gui.*;
32 import org.openharmonise.vfs.status.*;
33
34
35 /**
36  * Action to copy a virtual file. Used in the drag context menu.
37  *
38  * @author Matthew Large
39  * @version $Revision: 1.1 $
40  *
41  */

42 public class ActionCopy extends AbstractHIMAction implements HIMAction {
43
44     public static String JavaDoc ACTION_NAME = "COPY";
45
46     private VirtualFile m_vfToFile = null;
47
48     /**
49      *
50      */

51     private ActionCopy() {
52         super();
53         this.setup();
54     }
55
56     /**
57      * @param vfFile
58      */

59     public ActionCopy(VirtualFile vfFromFile, VirtualFile vfToFile) {
60         super(vfFromFile);
61         this.m_vfToFile = vfToFile;
62         this.setup();
63     }
64     
65     /**
66      * Configures this action.
67      *
68      */

69     private void setup() {
70         SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_COPY);
71         super.addEnableRule(secRule);
72     }
73
74     /* (non-Javadoc)
75      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
76      */

77     public void actionPerformed(ActionEvent arg0) {
78         StateHandler.getInstance().addWait("COPY-ACTION");
79         StatusData statusOverall = new VFSStatus();
80         
81         String JavaDoc sOriginalName = this.getPrimaryFile().getVFS().getVirtualFileSystemView().getDisplayName(this.getPrimaryFile());
82         
83         String JavaDoc sNewName = this.m_vfToFile.getVFS().getVirtualFileSystemView().getDisplayName(this.m_vfToFile);
84         try {
85             StatusData status = this.getPrimaryFile().copy(this.m_vfToFile.getFullPath());
86             statusOverall.addStatusData(status);
87             if( status.isOK() ) {
88
89             } else {
90
91             }
92         } catch (Exception JavaDoc e) {
93             e.printStackTrace(System.err);
94             statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
95         } finally {
96             VFSMessageBuilder.getInstance().fireMessage(ActionCopy.ACTION_NAME, statusOverall, sOriginalName, sNewName);
97             StateHandler.getInstance().removeWait("COPY-ACTION");
98         }
99     }
100
101     /* (non-Javadoc)
102      * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getText()
103      */

104     public String JavaDoc getText() {
105         return "Copy";
106     }
107
108     /* (non-Javadoc)
109      * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getToolTip()
110      */

111     public String JavaDoc getToolTip() {
112         return this.getDescription();
113     }
114
115     /* (non-Javadoc)
116      * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getIcon()
117      */

118     public Icon getIcon() {
119         return IconManager.getInstance().getIcon("16-command-copy.gif");
120     }
121
122     /* (non-Javadoc)
123      * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getMnemonic()
124      */

125     public String JavaDoc getMnemonic() {
126         return "C";
127     }
128
129     /* (non-Javadoc)
130      * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
131      */

132     public String JavaDoc getDescription() {
133         return "Copies resource between collections";
134     }
135
136     /* (non-Javadoc)
137      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
138      */

139     public int getAcceleratorKeycode() {
140         return 0;
141     }
142
143     /* (non-Javadoc)
144      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
145      */

146     public int getAcceleratorMask() {
147         return 0;
148     }
149
150 }
151
Popular Tags