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 copy a virtual file. Used in the drag context menu.
036: *
037: * @author Matthew Large
038: * @version $Revision: 1.1 $
039: *
040: */
041: public class ActionCopy extends AbstractHIMAction implements HIMAction {
042:
043: public static String ACTION_NAME = "COPY";
044:
045: private VirtualFile m_vfToFile = null;
046:
047: /**
048: *
049: */
050: private ActionCopy() {
051: super ();
052: this .setup();
053: }
054:
055: /**
056: * @param vfFile
057: */
058: public ActionCopy(VirtualFile vfFromFile, VirtualFile vfToFile) {
059: super (vfFromFile);
060: this .m_vfToFile = vfToFile;
061: this .setup();
062: }
063:
064: /**
065: * Configures this action.
066: *
067: */
068: private void setup() {
069: SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_COPY);
070: super .addEnableRule(secRule);
071: }
072:
073: /* (non-Javadoc)
074: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
075: */
076: public void actionPerformed(ActionEvent arg0) {
077: StateHandler.getInstance().addWait("COPY-ACTION");
078: StatusData statusOverall = new VFSStatus();
079:
080: String sOriginalName = this .getPrimaryFile().getVFS()
081: .getVirtualFileSystemView().getDisplayName(
082: this .getPrimaryFile());
083:
084: String sNewName = this .m_vfToFile.getVFS()
085: .getVirtualFileSystemView().getDisplayName(
086: this .m_vfToFile);
087: try {
088: StatusData status = this .getPrimaryFile().copy(
089: this .m_vfToFile.getFullPath());
090: statusOverall.addStatusData(status);
091: if (status.isOK()) {
092:
093: } else {
094:
095: }
096: } catch (Exception e) {
097: e.printStackTrace(System.err);
098: statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
099: } finally {
100: VFSMessageBuilder.getInstance().fireMessage(
101: ActionCopy.ACTION_NAME, statusOverall,
102: sOriginalName, sNewName);
103: StateHandler.getInstance().removeWait("COPY-ACTION");
104: }
105: }
106:
107: /* (non-Javadoc)
108: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getText()
109: */
110: public String getText() {
111: return "Copy";
112: }
113:
114: /* (non-Javadoc)
115: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getToolTip()
116: */
117: public String getToolTip() {
118: return this .getDescription();
119: }
120:
121: /* (non-Javadoc)
122: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getIcon()
123: */
124: public Icon getIcon() {
125: return IconManager.getInstance().getIcon("16-command-copy.gif");
126: }
127:
128: /* (non-Javadoc)
129: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getMnemonic()
130: */
131: public String getMnemonic() {
132: return "C";
133: }
134:
135: /* (non-Javadoc)
136: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
137: */
138: public String getDescription() {
139: return "Copies resource between collections";
140: }
141:
142: /* (non-Javadoc)
143: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
144: */
145: public int getAcceleratorKeycode() {
146: return 0;
147: }
148:
149: /* (non-Javadoc)
150: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
151: */
152: public int getAcceleratorMask() {
153: return 0;
154: }
155:
156: }
|