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.sync;
020:
021: import java.awt.event.*;
022:
023: import javax.swing.*;
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.files.*;
029: import org.openharmonise.him.window.session.*;
030: import org.openharmonise.vfs.*;
031: import org.openharmonise.vfs.context.*;
032: import org.openharmonise.vfs.gui.*;
033:
034: /**
035: * Action to submit the changes of a virtual file. Used in the session
036: * window.
037: *
038: * @author Matthew Large
039: * @version $Revision: 1.1 $
040: *
041: */
042: public class ActionSynchronize extends AbstractHIMAction implements
043: HIMAction {
044:
045: public static String ACTION_NAME = "SYNC_FILE";
046:
047: /**
048: * Wait identifier for state handler.
049: */
050: private static final String WAIT_LABEL = "SYNC-ACTION";
051:
052: /**
053: * Session window.
054: */
055: private SessionWindow m_session = null;
056:
057: /**
058: *
059: */
060: public ActionSynchronize(SessionWindow session) {
061: super ();
062: this .m_session = session;
063: this .setup();
064: }
065:
066: /**
067: * @param vfFile
068: */
069: public ActionSynchronize(VirtualFile vfFile) {
070: super (vfFile);
071: this .setup();
072: }
073:
074: /**
075: * Configures this action.
076: *
077: */
078: private void setup() {
079: RuleGroup andGroup = new RuleGroup();
080: SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_SYNC);
081: andGroup.addEnableRule(null);
082: IsLockedByOtherUser lockRule = new IsLockedByOtherUser();
083: lockRule.setResultComparator(false);
084: andGroup.addEnableRule(lockRule);
085: super .addEnableRule(andGroup);
086: }
087:
088: /* (non-Javadoc)
089: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
090: */
091: public void actionPerformed(ActionEvent arg0) {
092: StateHandler.getInstance().addWait(WAIT_LABEL);
093: String sFileName = null;
094: try {
095: FilesSynchroniser filesSyncer = new FilesSynchroniser();
096:
097: VirtualFile vfFile = this .m_session
098: .getSelectedEntry()
099: .getVFS()
100: .getVirtualFile(
101: this .m_session.getSelectedEntry().getPath())
102: .getResource();
103: filesSyncer.syncFile(vfFile);
104: } catch (Exception e) {
105: e.printStackTrace();
106: } finally {
107: StateHandler.getInstance().removeWait(WAIT_LABEL);
108: }
109: }
110:
111: /* (non-Javadoc)
112: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getText()
113: */
114: public String getText() {
115: return "Submit Resource";
116: }
117:
118: /* (non-Javadoc)
119: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getToolTip()
120: */
121: public String getToolTip() {
122: return this .getDescription();
123: }
124:
125: /* (non-Javadoc)
126: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getIcon()
127: */
128: public Icon getIcon() {
129: return IconManager.getInstance().getIcon(
130: "16-command-sync-all.gif");
131: }
132:
133: /* (non-Javadoc)
134: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getMnemonic()
135: */
136: public String getMnemonic() {
137: return "S";
138: }
139:
140: /* (non-Javadoc)
141: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
142: */
143: public String getDescription() {
144: return "Submits the currently selected resource";
145: }
146:
147: /* (non-Javadoc)
148: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
149: */
150: public int getAcceleratorKeycode() {
151: return 0;
152: }
153:
154: /* (non-Javadoc)
155: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
156: */
157: public int getAcceleratorMask() {
158: return 0;
159: }
160:
161: }
|