001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.actions.move;
020:
021: import java.awt.event.*;
022:
023: import javax.swing.*;
024:
025: import org.openharmonise.him.actions.*;
026: import org.openharmonise.him.actions.rules.*;
027: import org.openharmonise.him.context.StateHandler;
028: import org.openharmonise.him.window.messages.builders.*;
029: import org.openharmonise.vfs.*;
030: import org.openharmonise.vfs.context.*;
031: import org.openharmonise.vfs.gui.*;
032: import org.openharmonise.vfs.status.*;
033:
034: /**
035: * Action to move a virtual file. Used in the drag context menu.
036: *
037: * @author Matthew Large
038: * @version $Revision: 1.1 $
039: *
040: */
041: public class ActionMove extends AbstractHIMAction implements HIMAction {
042:
043: public static String ACTION_NAME = "MOVE";
044:
045: /**
046: * Virtual file to move to.
047: */
048: private VirtualFile m_vfToFile = null;
049:
050: /**
051: *
052: */
053: private ActionMove() {
054: super ();
055: this .setup();
056: }
057:
058: /**
059: * @param vfFile
060: */
061: public ActionMove(VirtualFile vfFromFile, VirtualFile vfToFile) {
062: super (vfFromFile);
063: this .m_vfToFile = vfToFile;
064: this .setup();
065: }
066:
067: /**
068: * Configures this action.
069: *
070: */
071: private void setup() {
072: SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_MOVE);
073: super .addEnableRule(secRule);
074: }
075:
076: /* (non-Javadoc)
077: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
078: */
079: public void actionPerformed(ActionEvent arg0) {
080: StateHandler.getInstance().addWait("MOVE-ACTION");
081: StatusData statusOverall = new VFSStatus();
082:
083: String sOriginalName = this .getPrimaryFile().getVFS()
084: .getVirtualFileSystemView().getDisplayName(
085: this .getPrimaryFile());
086:
087: String sNewName = this .m_vfToFile.getVFS()
088: .getVirtualFileSystemView().getDisplayName(
089: this .m_vfToFile);
090: try {
091: StatusData status = this .getPrimaryFile().move(
092: this .m_vfToFile.getFullPath());
093: statusOverall.addStatusData(status);
094: if (status.isOK()) {
095:
096: } else {
097:
098: }
099: } catch (Exception e) {
100: e.printStackTrace(System.err);
101: statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
102: } finally {
103: VFSMessageBuilder.getInstance().fireMessage(
104: ActionMove.ACTION_NAME, statusOverall,
105: sOriginalName, sNewName);
106: StateHandler.getInstance().removeWait("MOVE-ACTION");
107: }
108: }
109:
110: /* (non-Javadoc)
111: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getText()
112: */
113: public String getText() {
114: return "Move";
115: }
116:
117: /* (non-Javadoc)
118: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getToolTip()
119: */
120: public String getToolTip() {
121: return this .getDescription();
122: }
123:
124: /* (non-Javadoc)
125: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getIcon()
126: */
127: public Icon getIcon() {
128: return IconManager.getInstance().getIcon("16-command-move.gif");
129: }
130:
131: /* (non-Javadoc)
132: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getMnemonic()
133: */
134: public String getMnemonic() {
135: return "M";
136: }
137:
138: /* (non-Javadoc)
139: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
140: */
141: public String getDescription() {
142: return "Moves resource between collections";
143: }
144:
145: /* (non-Javadoc)
146: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
147: */
148: public int getAcceleratorKeycode() {
149: return 0;
150: }
151:
152: /* (non-Javadoc)
153: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
154: */
155: public int getAcceleratorMask() {
156: return 0;
157: }
158:
159: }
|