KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > actions > file > ActionUpload


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.file;
20
21 import java.awt.event.ActionEvent JavaDoc;
22
23 import javax.swing.Icon JavaDoc;
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.editors.*;
29 import org.openharmonise.him.harmonise.*;
30 import org.openharmonise.him.window.messages.builders.*;
31 import org.openharmonise.vfs.*;
32 import org.openharmonise.vfs.context.*;
33 import org.openharmonise.vfs.gui.*;
34 import org.openharmonise.vfs.status.*;
35
36
37 /**
38  * Action to upload new content to a virtual file.
39  *
40  * @author Matthew Large
41  * @version $Revision: 1.1 $
42  *
43  */

44 public class ActionUpload extends AbstractHIMAction implements HIMAction {
45
46     public static String JavaDoc ACTION_NAME = "UPLOAD";
47
48     /**
49      *
50      */

51     public ActionUpload() {
52         super();
53         this.setup();
54     }
55
56     /**
57      * @param vfFile
58      */

59     public ActionUpload(VirtualFile vfFile) {
60         super(vfFile);
61         this.setup();
62     }
63     
64     /**
65      * Configures this action.
66      *
67      */

68     private void setup() {
69         RuleGroup andGroup = new RuleGroup();
70         andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
71         
72         EnableRule rule = new IsDirectoryRule();
73         rule.setResultComparator(false);
74         andGroup.addEnableRule( rule );
75         PathRule pathRule = new PathRule("/webdav/Content/Assets");
76         andGroup.addEnableRule(pathRule);
77         pathRule = new PathRule( HarmonisePaths.PATH_EMAIL );
78         pathRule.setResultComparator(false);
79         andGroup.addEnableRule(pathRule);
80         pathRule = new PathRule( HarmonisePaths.PATH_LINKS );
81         pathRule.setResultComparator(false);
82         andGroup.addEnableRule(pathRule);
83         
84         this.addEnableRule(andGroup);
85     }
86
87     /* (non-Javadoc)
88      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
89      */

90     public void actionPerformed(ActionEvent JavaDoc arg0) {
91         StatusData statusOverall = new VFSStatus();
92         VirtualFile vfFile = this.getLastContextFile();
93         String JavaDoc sFileName = vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile);
94         StateHandler.getInstance().addWait("UPLOAD-ACTION",
95                 "Opening uploader...");
96         try {
97             StatusData status = EditorController.getInstance().upload(vfFile.getFullPath(),
98                     vfFile.getVFS());
99             statusOverall.addStatusData(status);
100         } catch (Exception JavaDoc e) {
101             e.printStackTrace(System.err);
102             statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
103         } finally {
104             StateHandler.getInstance().removeWait("UPLOAD-ACTION");
105             VFSMessageBuilder.getInstance().fireMessage(ActionUpload.ACTION_NAME, statusOverall, sFileName);
106         }
107     }
108
109     /* (non-Javadoc)
110      * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
111      */

112     public String JavaDoc getDescription() {
113         return "Uploads content to the server";
114     }
115
116     /* (non-Javadoc)
117      * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
118      */

119     public String JavaDoc getText() {
120         return "Reupload...";
121     }
122
123     /* (non-Javadoc)
124      * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
125      */

126     public String JavaDoc getToolTip() {
127         return this.getDescription();
128     }
129
130     /* (non-Javadoc)
131      * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
132      */

133     public Icon JavaDoc getIcon() {
134         return IconManager.getInstance().getIcon("16-blank.gif");
135     }
136
137     /* (non-Javadoc)
138      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
139      */

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

147     public String JavaDoc getMnemonic() {
148         return "l";
149     }
150
151     /* (non-Javadoc)
152      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
153      */

154     public int getAcceleratorMask() {
155         return 0;
156     }
157
158 }
159
Popular Tags