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.system;
020:
021: import java.awt.event.ActionEvent;
022: import java.awt.event.InputEvent;
023: import java.awt.event.KeyEvent;
024: import java.util.Iterator;
025:
026: import javax.swing.Icon;
027: import javax.swing.JMenuItem;
028: import javax.swing.KeyStroke;
029:
030: import org.openharmonise.him.*;
031: import org.openharmonise.him.actions.*;
032: import org.openharmonise.him.context.StateHandler;
033: import org.openharmonise.him.window.messages.*;
034: import org.openharmonise.vfs.*;
035: import org.openharmonise.vfs.context.*;
036: import org.openharmonise.vfs.gui.*;
037: import org.openharmonise.vfs.servers.*;
038:
039: /**
040: * Action to submit all changes.
041: *
042: * @author Matthew Large
043: * @version $Revision: 1.1 $
044: *
045: */
046: public class ActionSyncWithServer extends AbstractHIMAction implements
047: HIMAction {
048:
049: public static String ACTION_NAME = "SYNC_ALL";
050:
051: /**
052: * Wait identifier for state handler.
053: */
054: private static final String WAIT_LABEL = "SYNC-ACTION";
055:
056: /**
057: *
058: */
059: public ActionSyncWithServer() {
060: super ();
061: }
062:
063: /**
064: * @param vfFile
065: */
066: public ActionSyncWithServer(VirtualFile vfFile) {
067: super (vfFile);
068: }
069:
070: /* (non-Javadoc)
071: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
072: */
073: public void actionPerformed(ActionEvent arg0) {
074: StateHandler.getInstance().addWait(WAIT_LABEL);
075: try {
076: Iterator itor = ServerList.getInstance().getServers()
077: .iterator();
078: while (itor.hasNext()) {
079: Server element = (Server) itor.next();
080: if (element.getVFS().synchroniseAllFiles().isOK()) {
081: MessageHandler
082: .getInstance()
083: .fireMessageEvent(
084: "You have successfully submitted with the server, see the Session window for a list of submitted resources.",
085: MessageHandler.TYPE_CONFIRM);
086: } else {
087: MessageHandler
088: .getInstance()
089: .fireMessageEvent(
090: "There was a problem submitting to the server.",
091: MessageHandler.TYPE_ERROR);
092: }
093: }
094: } catch (Exception e) {
095: e.printStackTrace(System.err);
096: MessageHandler.getInstance().fireMessageEvent(
097: "There was a problem submitting with to server.",
098: MessageHandler.TYPE_ERROR);
099: } finally {
100: StateHandler.getInstance().removeWait(WAIT_LABEL);
101: }
102: }
103:
104: /* (non-Javadoc)
105: * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
106: */
107: public JMenuItem getMenuItem() {
108: JMenuItem menuItem = super .getMenuItem();
109: menuItem.setAccelerator(KeyStroke.getKeyStroke(this
110: .getAcceleratorKeycode(), this .getAcceleratorMask()));
111:
112: return menuItem;
113: }
114:
115: /* (non-Javadoc)
116: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
117: */
118: public String getDescription() {
119: return "Submits all, uncommited, changes with the server";
120: }
121:
122: /* (non-Javadoc)
123: * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
124: */
125: public String getText() {
126: return "Submit all changes";
127: }
128:
129: /* (non-Javadoc)
130: * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
131: */
132: public String getToolTip() {
133: return this .getDescription();
134: }
135:
136: /* (non-Javadoc)
137: * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
138: */
139: public Icon getIcon() {
140: return IconManager.getInstance().getIcon(
141: "16-command-sync-all.gif");
142: }
143:
144: /* (non-Javadoc)
145: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
146: */
147: public int getAcceleratorKeycode() {
148: return KeyEvent.VK_S;
149: }
150:
151: /* (non-Javadoc)
152: * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
153: */
154: public String getMnemonic() {
155: return "S";
156: }
157:
158: /* (non-Javadoc)
159: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
160: */
161: public int getAcceleratorMask() {
162: return InputEvent.CTRL_MASK;
163: }
164:
165: }
|