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.ActionEvent;
022:
023: import javax.swing.Icon;
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.editors.*;
029: import org.openharmonise.him.harmonise.*;
030: import org.openharmonise.him.window.messages.builders.*;
031: import org.openharmonise.vfs.*;
032: import org.openharmonise.vfs.context.*;
033: import org.openharmonise.vfs.gui.*;
034: import org.openharmonise.vfs.status.*;
035:
036: /**
037: * Action to upload new content to a virtual file.
038: *
039: * @author Matthew Large
040: * @version $Revision: 1.1 $
041: *
042: */
043: public class ActionUpload extends AbstractHIMAction implements
044: HIMAction {
045:
046: public static String ACTION_NAME = "UPLOAD";
047:
048: /**
049: *
050: */
051: public ActionUpload() {
052: super ();
053: this .setup();
054: }
055:
056: /**
057: * @param vfFile
058: */
059: public ActionUpload(VirtualFile vfFile) {
060: super (vfFile);
061: this .setup();
062: }
063:
064: /**
065: * Configures this action.
066: *
067: */
068: private void setup() {
069: RuleGroup andGroup = new RuleGroup();
070: andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
071:
072: EnableRule rule = new IsDirectoryRule();
073: rule.setResultComparator(false);
074: andGroup.addEnableRule(rule);
075: PathRule pathRule = new PathRule("/webdav/Content/Assets");
076: andGroup.addEnableRule(pathRule);
077: pathRule = new PathRule(HarmonisePaths.PATH_EMAIL);
078: pathRule.setResultComparator(false);
079: andGroup.addEnableRule(pathRule);
080: pathRule = new PathRule(HarmonisePaths.PATH_LINKS);
081: pathRule.setResultComparator(false);
082: andGroup.addEnableRule(pathRule);
083:
084: this .addEnableRule(andGroup);
085: }
086:
087: /* (non-Javadoc)
088: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
089: */
090: public void actionPerformed(ActionEvent arg0) {
091: StatusData statusOverall = new VFSStatus();
092: VirtualFile vfFile = this .getLastContextFile();
093: String sFileName = vfFile.getVFS().getVirtualFileSystemView()
094: .getDisplayName(vfFile);
095: StateHandler.getInstance().addWait("UPLOAD-ACTION",
096: "Opening uploader...");
097: try {
098: StatusData status = EditorController.getInstance().upload(
099: vfFile.getFullPath(), vfFile.getVFS());
100: statusOverall.addStatusData(status);
101: } catch (Exception e) {
102: e.printStackTrace(System.err);
103: statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
104: } finally {
105: StateHandler.getInstance().removeWait("UPLOAD-ACTION");
106: VFSMessageBuilder.getInstance().fireMessage(
107: ActionUpload.ACTION_NAME, statusOverall, sFileName);
108: }
109: }
110:
111: /* (non-Javadoc)
112: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
113: */
114: public String getDescription() {
115: return "Uploads content to the server";
116: }
117:
118: /* (non-Javadoc)
119: * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
120: */
121: public String getText() {
122: return "Reupload...";
123: }
124:
125: /* (non-Javadoc)
126: * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
127: */
128: public String getToolTip() {
129: return this .getDescription();
130: }
131:
132: /* (non-Javadoc)
133: * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
134: */
135: public Icon getIcon() {
136: return IconManager.getInstance().getIcon("16-blank.gif");
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#getMnemonic()
148: */
149: public String getMnemonic() {
150: return "l";
151: }
152:
153: /* (non-Javadoc)
154: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
155: */
156: public int getAcceleratorMask() {
157: return 0;
158: }
159:
160: }
|