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.publish;
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.window.messages.builders.*;
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: import org.openharmonise.vfs.status.*;
034:
035: /**
036: * Action to retrieve a historical or archived virtual file.
037: *
038: * @author Matthew Large
039: * @version $Revision: 1.1 $
040: *
041: */
042: public class ActionRetrieve extends AbstractHIMAction implements
043: HIMAction {
044:
045: public static String ACTION_NAME = "RETRIEVE";
046:
047: /**
048: * Wait identifier for state handler.
049: */
050: private static final String WAIT_LABEL = "RETRIEVE-ACTION";
051:
052: /**
053: *
054: */
055: public ActionRetrieve() {
056: super ();
057: this .setup();
058: }
059:
060: /**
061: * @param vfFile
062: */
063: public ActionRetrieve(VirtualFile vfFile) {
064: super (vfFile);
065: this .setup();
066: }
067:
068: /**
069: * Configures this action.
070: *
071: */
072: private void setup() {
073: RuleGroup andGroupTop = new RuleGroup();
074: andGroupTop.setGroupType(RuleGroup.GROUPTYPE_AND);
075:
076: RuleGroup orGroup = new RuleGroup();
077: orGroup.setGroupType(RuleGroup.GROUPTYPE_OR);
078:
079: RuleGroup andGroup = new RuleGroup();
080: andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
081:
082: EnableRule isDirRule = new IsDirectoryRule();
083: isDirRule.setResultComparator(false);
084: andGroup.addEnableRule(isDirRule);
085: EnableRule pathRule = new PathRule("/webdav/Archive/");
086: andGroup.addEnableRule(pathRule);
087: orGroup.addEnableRule(andGroup);
088:
089: EnableRule isHistorical = new IsHistoricalRule();
090: orGroup.addEnableRule(isHistorical);
091:
092: andGroupTop.addEnableRule(orGroup);
093:
094: SecurityRule secRule = new SecurityRule(
095: VirtualFile.METHOD_CHECKOUT);
096: andGroupTop.addEnableRule(secRule);
097:
098: this .addEnableRule(andGroupTop);
099: }
100:
101: /* (non-Javadoc)
102: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
103: */
104: public void actionPerformed(ActionEvent arg0) {
105: VirtualFile vfFile = this .getLastContextFile();
106: StatusData statusOverall = new VFSStatus();
107:
108: if (vfFile.isVersionable()) {
109: VersionedVirtualFile vfVerFile = (VersionedVirtualFile) vfFile;
110: StateHandler.getInstance().addWait(WAIT_LABEL);
111: String sFileName = null;
112: try {
113: sFileName = vfFile.getVFS().getVirtualFileSystemView()
114: .getDisplayName(vfFile);
115: String sMessage = null;
116: StatusData status = ((VersionedVirtualFile) this
117: .getLastContextFile()).reactivate();
118: statusOverall.addStatusData(status);
119:
120: if (status.isOK()) {
121: super .fireSessionEvent("Retrieved", this
122: .getLastContextFile().getVFS(), this
123: .getLastContextFile().getFullPath(),
124: SessionEventData.RESOURCE_REACTIVATED);
125: } else {
126: }
127: } catch (Exception e) {
128: e.printStackTrace(System.err);
129: statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
130: } finally {
131: StateHandler.getInstance().removeWait(WAIT_LABEL);
132: this .getLastContextDirectory().refreshChildren();
133: VFSMessageBuilder.getInstance().fireMessage(
134: ActionRetrieve.ACTION_NAME, statusOverall,
135: sFileName);
136: }
137: }
138: }
139:
140: /* (non-Javadoc)
141: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
142: */
143: public String getDescription() {
144: return "Retrieves the currently selected resource from the archive";
145: }
146:
147: /* (non-Javadoc)
148: * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
149: */
150: public String getText() {
151: return "Retrieve";
152: }
153:
154: /* (non-Javadoc)
155: * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
156: */
157: public String getToolTip() {
158: return this .getDescription();
159: }
160:
161: /* (non-Javadoc)
162: * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
163: */
164: public Icon getIcon() {
165: return IconManager.getInstance().getIcon(
166: "16-command-retrieve.gif");
167: }
168:
169: /* (non-Javadoc)
170: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
171: */
172: public int getAcceleratorKeycode() {
173: return 0;
174: }
175:
176: /* (non-Javadoc)
177: * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
178: */
179: public String getMnemonic() {
180: return "R";
181: }
182:
183: /* (non-Javadoc)
184: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
185: */
186: public int getAcceleratorMask() {
187: return 0;
188: }
189:
190: }
|