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