KickJava   Java API By Example, From Geeks To Geeks.

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


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 move a virtual file. Used in the drag context menu.
37  *
38  * @author Matthew Large
39  * @version $Revision: 1.1 $
40  *
41  */

42 public class ActionMove extends AbstractHIMAction implements HIMAction {
43
44     public static String JavaDoc ACTION_NAME = "MOVE";
45
46     /**
47      * Virtual file to move to.
48      */

49     private VirtualFile m_vfToFile = null;
50
51     /**
52      *
53      */

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

62     public ActionMove(VirtualFile vfFromFile, VirtualFile vfToFile) {
63         super(vfFromFile);
64         this.m_vfToFile = vfToFile;
65         this.setup();
66     }
67     
68     /**
69      * Configures this action.
70      *
71      */

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

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

107     public String JavaDoc getText() {
108         return "Move";
109     }
110
111     /* (non-Javadoc)
112      * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getToolTip()
113      */

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

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

128     public String JavaDoc getMnemonic() {
129         return "M";
130     }
131
132     /* (non-Javadoc)
133      * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
134      */

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

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

149     public int getAcceleratorMask() {
150         return 0;
151     }
152
153 }
154
Popular Tags