KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > actions > sync > ActionSynchronize


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.sync;
20
21 import java.awt.event.*;
22
23 import javax.swing.*;
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.files.*;
29 import org.openharmonise.him.window.session.*;
30 import org.openharmonise.vfs.*;
31 import org.openharmonise.vfs.context.*;
32 import org.openharmonise.vfs.gui.*;
33
34
35 /**
36  * Action to submit the changes of a virtual file. Used in the session
37  * window.
38  *
39  * @author Matthew Large
40  * @version $Revision: 1.1 $
41  *
42  */

43 public class ActionSynchronize extends AbstractHIMAction implements HIMAction {
44
45     public static String JavaDoc ACTION_NAME = "SYNC_FILE";
46     
47     /**
48      * Wait identifier for state handler.
49      */

50     private static final String JavaDoc WAIT_LABEL = "SYNC-ACTION";
51     
52     /**
53      * Session window.
54      */

55     private SessionWindow m_session = null;
56
57     /**
58      *
59      */

60     public ActionSynchronize(SessionWindow session) {
61         super();
62         this.m_session = session;
63         this.setup();
64     }
65
66     /**
67      * @param vfFile
68      */

69     public ActionSynchronize(VirtualFile vfFile) {
70         super(vfFile);
71         this.setup();
72     }
73     
74     /**
75      * Configures this action.
76      *
77      */

78     private void setup() {
79         RuleGroup andGroup = new RuleGroup();
80         SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_SYNC);
81         andGroup.addEnableRule(null);
82         IsLockedByOtherUser lockRule = new IsLockedByOtherUser();
83         lockRule.setResultComparator(false);
84         andGroup.addEnableRule(lockRule);
85         super.addEnableRule(andGroup);
86     }
87
88     /* (non-Javadoc)
89      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
90      */

91     public void actionPerformed(ActionEvent arg0) {
92         StateHandler.getInstance().addWait(WAIT_LABEL);
93         String JavaDoc sFileName = null;
94         try {
95             FilesSynchroniser filesSyncer = new FilesSynchroniser();
96
97             VirtualFile vfFile = this.m_session.getSelectedEntry().getVFS().getVirtualFile(this.m_session.getSelectedEntry().getPath()).getResource();
98             filesSyncer.syncFile(vfFile);
99         } catch (Exception JavaDoc e) {
100             e.printStackTrace();
101         } finally {
102             StateHandler.getInstance().removeWait(WAIT_LABEL);
103         }
104     }
105
106     /* (non-Javadoc)
107      * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getText()
108      */

109     public String JavaDoc getText() {
110         return "Submit Resource";
111     }
112
113     /* (non-Javadoc)
114      * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getToolTip()
115      */

116     public String JavaDoc getToolTip() {
117         return this.getDescription();
118     }
119
120     /* (non-Javadoc)
121      * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getIcon()
122      */

123     public Icon getIcon() {
124         return IconManager.getInstance().getIcon("16-command-sync-all.gif");
125     }
126
127     /* (non-Javadoc)
128      * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getMnemonic()
129      */

130     public String JavaDoc getMnemonic() {
131         return "S";
132     }
133
134     /* (non-Javadoc)
135      * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
136      */

137     public String JavaDoc getDescription() {
138         return "Submits the currently selected resource";
139     }
140
141     /* (non-Javadoc)
142      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
143      */

144     public int getAcceleratorKeycode() {
145         return 0;
146     }
147
148     /* (non-Javadoc)
149      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
150      */

151     public int getAcceleratorMask() {
152         return 0;
153     }
154
155 }
156
Popular Tags