KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > actions > system > ActionSyncWithServer


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.system;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.awt.event.InputEvent JavaDoc;
23 import java.awt.event.KeyEvent JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 import javax.swing.Icon JavaDoc;
27 import javax.swing.JMenuItem JavaDoc;
28 import javax.swing.KeyStroke JavaDoc;
29
30 import org.openharmonise.him.*;
31 import org.openharmonise.him.actions.*;
32 import org.openharmonise.him.context.StateHandler;
33 import org.openharmonise.him.window.messages.*;
34 import org.openharmonise.vfs.*;
35 import org.openharmonise.vfs.context.*;
36 import org.openharmonise.vfs.gui.*;
37 import org.openharmonise.vfs.servers.*;
38
39
40 /**
41  * Action to submit all changes.
42  *
43  * @author Matthew Large
44  * @version $Revision: 1.1 $
45  *
46  */

47 public class ActionSyncWithServer
48     extends AbstractHIMAction
49     implements HIMAction {
50
51     public static String JavaDoc ACTION_NAME = "SYNC_ALL";
52
53     /**
54      * Wait identifier for state handler.
55      */

56     private static final String JavaDoc WAIT_LABEL = "SYNC-ACTION";
57     
58     /**
59      *
60      */

61     public ActionSyncWithServer() {
62         super();
63     }
64
65     /**
66      * @param vfFile
67      */

68     public ActionSyncWithServer(VirtualFile vfFile) {
69         super(vfFile);
70     }
71
72     /* (non-Javadoc)
73      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
74      */

75     public void actionPerformed(ActionEvent JavaDoc arg0) {
76         StateHandler.getInstance().addWait(WAIT_LABEL);
77         try {
78             Iterator JavaDoc itor = ServerList.getInstance().getServers().iterator();
79             while (itor.hasNext()) {
80                 Server element = (Server) itor.next();
81                 if(element.getVFS().synchroniseAllFiles().isOK()) {
82                     MessageHandler.getInstance().fireMessageEvent("You have successfully submitted with the server, see the Session window for a list of submitted resources.", MessageHandler.TYPE_CONFIRM);
83                 } else {
84                     MessageHandler.getInstance().fireMessageEvent("There was a problem submitting to the server.", MessageHandler.TYPE_ERROR);
85                 }
86             }
87         } catch (Exception JavaDoc e) {
88             e.printStackTrace(System.err);
89             MessageHandler.getInstance().fireMessageEvent("There was a problem submitting with to server.", MessageHandler.TYPE_ERROR);
90         } finally {
91             StateHandler.getInstance().removeWait(WAIT_LABEL);
92         }
93     }
94
95     /* (non-Javadoc)
96      * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
97      */

98     public JMenuItem JavaDoc getMenuItem() {
99         JMenuItem JavaDoc menuItem = super.getMenuItem();
100         menuItem.setAccelerator( KeyStroke.getKeyStroke(this.getAcceleratorKeycode(), this.getAcceleratorMask()) );
101         
102         return menuItem;
103     }
104
105     /* (non-Javadoc)
106      * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
107      */

108     public String JavaDoc getDescription() {
109         return "Submits all, uncommited, changes with the server";
110     }
111
112     /* (non-Javadoc)
113      * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
114      */

115     public String JavaDoc getText() {
116         return "Submit all changes";
117     }
118
119     /* (non-Javadoc)
120      * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
121      */

122     public String JavaDoc getToolTip() {
123         return this.getDescription();
124     }
125
126     /* (non-Javadoc)
127      * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
128      */

129     public Icon JavaDoc getIcon() {
130         return IconManager.getInstance().getIcon("16-command-sync-all.gif");
131     }
132
133     /* (non-Javadoc)
134      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
135      */

136     public int getAcceleratorKeycode() {
137         return KeyEvent.VK_S;
138     }
139
140     /* (non-Javadoc)
141      * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
142      */

143     public String JavaDoc getMnemonic() {
144         return "S";
145     }
146
147     /* (non-Javadoc)
148      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
149      */

150     public int getAcceleratorMask() {
151         return InputEvent.CTRL_MASK;
152     }
153
154 }
155
Popular Tags