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.file;
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.him.window.session.*;
030: import org.openharmonise.vfs.*;
031: import org.openharmonise.vfs.context.*;
032: import org.openharmonise.vfs.gui.*;
033: import org.openharmonise.vfs.status.*;
034:
035: /**
036: * Action to create a copy of a virtual file in the current collection.
037: *
038: * @author Matthew Large
039: * @version $Revision: 1.1 $
040: *
041: */
042: public class ActionCreateCopy extends AbstractHIMAction implements
043: HIMAction {
044:
045: public static String ACTION_NAME = "CREATE_COPY";
046:
047: /**
048: *
049: */
050: public ActionCreateCopy() {
051: super ();
052: this .setup();
053: }
054:
055: /**
056: * @param vfFile
057: */
058: public ActionCreateCopy(VirtualFile vfFile) {
059: super (vfFile);
060: this .setup();
061: }
062:
063: /**
064: * Configures this action.
065: *
066: */
067: private void setup() {
068: RuleGroup andGroup = new RuleGroup();
069: andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
070: PathRule pathRule = new PathRule("/webdav/Archive/");
071: pathRule.setResultComparator(false);
072: andGroup.addEnableRule(pathRule);
073: IsHistoricalRule histRule = new IsHistoricalRule();
074: histRule.setResultComparator(false);
075: andGroup.addEnableRule(histRule);
076: SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_COPY);
077: andGroup.addEnableRule(secRule);
078: this .addEnableRule(andGroup);
079: }
080:
081: /* (non-Javadoc)
082: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
083: */
084: public void actionPerformed(ActionEvent arg0) {
085: StateHandler.getInstance().addWait("COPY-ACTION");
086: StatusData statusOverall = new VFSStatus();
087:
088: String sResourceTitle = null;
089:
090: VirtualFile vfFile = this .getLastContextFile();
091: if (vfFile.isVersionable()
092: && vfFile.getState().equals(VirtualFile.STATE_PENDING)
093: && ((VersionedVirtualFile) vfFile).getLiveVersionPath() != null) {
094: vfFile = vfFile.getVFS().getVirtualFile(
095: ((VersionedVirtualFile) vfFile)
096: .getLiveVersionPath()).getResource();
097: }
098:
099: try {
100: StatusData status = vfFile.copy(vfFile.getFilePath(),
101: "copy_of_" + vfFile.getFileName());
102: statusOverall.addStatusData(status);
103: if (status.isOK()) {
104: super .fireSessionEvent("Copy created", vfFile.getVFS(),
105: vfFile.getFullPath(),
106: SessionEventData.RESOURCE_COPIED);
107: } else {
108:
109: }
110:
111: sResourceTitle = vfFile.getVFS().getVirtualFileSystemView()
112: .getDisplayName(vfFile);
113: } catch (Exception e) {
114: e.printStackTrace(System.err);
115: statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
116: } finally {
117: VFSMessageBuilder.getInstance().fireMessage(
118: ActionCreateCopy.ACTION_NAME, statusOverall,
119: sResourceTitle);
120: StateHandler.getInstance().removeWait("COPY-ACTION");
121: }
122:
123: }
124:
125: /* (non-Javadoc)
126: * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
127: */
128: public JMenuItem getMenuItem() {
129: JMenuItem menuItem = super .getMenuItem();
130: menuItem.setAccelerator(KeyStroke.getKeyStroke(this
131: .getAcceleratorKeycode(), this .getAcceleratorMask()));
132:
133: return menuItem;
134: }
135:
136: /* (non-Javadoc)
137: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
138: */
139: public String getDescription() {
140: return "Creates a copy of the resource in the current collection";
141: }
142:
143: /* (non-Javadoc)
144: * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
145: */
146: public String getText() {
147: return "Create copy";
148: }
149:
150: /* (non-Javadoc)
151: * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
152: */
153: public String getToolTip() {
154: return this .getDescription();
155: }
156:
157: /* (non-Javadoc)
158: * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
159: */
160: public Icon getIcon() {
161: return IconManager.getInstance().getIcon("16-blank.gif");
162: }
163:
164: /* (non-Javadoc)
165: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
166: */
167: public int getAcceleratorKeycode() {
168: return KeyEvent.VK_C;
169: }
170:
171: /* (non-Javadoc)
172: * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
173: */
174: public String getMnemonic() {
175: return "C";
176: }
177:
178: /* (non-Javadoc)
179: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
180: */
181: public int getAcceleratorMask() {
182: return InputEvent.CTRL_MASK;
183: }
184:
185: }
|