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: import java.util.*;
023:
024: import javax.swing.*;
025:
026: import org.openharmonise.him.actions.*;
027: import org.openharmonise.him.actions.rules.*;
028: import org.openharmonise.him.context.StateHandler;
029: import org.openharmonise.him.harmonise.*;
030: import org.openharmonise.him.window.messages.*;
031: import org.openharmonise.him.window.messages.builders.*;
032: import org.openharmonise.him.window.session.*;
033: import org.openharmonise.vfs.*;
034: import org.openharmonise.vfs.context.*;
035: import org.openharmonise.vfs.event.*;
036: import org.openharmonise.vfs.gui.*;
037: import org.openharmonise.vfs.status.*;
038:
039: /**
040: * Action to archive a virtual file.
041: *
042: * @author Matthew Large
043: * @version $Revision: 1.2 $
044: *
045: */
046: public class ActionArchive extends AbstractHIMAction implements
047: HIMAction {
048:
049: public static String ACTION_NAME = "ARCHIVE";
050:
051: /**
052: * Wait identifier for state handler.
053: */
054: private static final String WAIT_LABEL = "ARCHIVE-ACTION";
055:
056: /**
057: *
058: */
059: public ActionArchive() {
060: super ();
061: this .setup();
062: }
063:
064: /**
065: * @param vfFile
066: */
067: public ActionArchive(VirtualFile vfFile) {
068: super (vfFile);
069: this .setup();
070: }
071:
072: /**
073: * Configures this action.
074: *
075: */
076: private void setup() {
077: RuleGroup andGroup = new RuleGroup();
078: andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
079: PathRule pathRule = new PathRule("/webdav/Archive/");
080: pathRule.setResultComparator(false);
081: andGroup.addEnableRule(pathRule);
082: PathEquals pathEqualsRule = new PathEquals(
083: HarmonisePaths.PATH_USERS_ADMIN + "/super");
084: pathEqualsRule.setResultComparator(false);
085: andGroup.addEnableRule(pathEqualsRule);
086: PathEquals pathEqualsRule2 = new PathEquals(
087: HarmonisePaths.PATH_REPORTS_QUERIES + "/LinkChecker");
088: pathEqualsRule2.setResultComparator(false);
089: andGroup.addEnableRule(pathEqualsRule2);
090: IsHistoricalRule histRule = new IsHistoricalRule();
091: histRule.setResultComparator(false);
092: andGroup.addEnableRule(histRule);
093: SecurityRule secRule = new SecurityRule(
094: VirtualFile.METHOD_DELETE);
095: andGroup.addEnableRule(secRule);
096: ParentPathEquals ppathRule = new ParentPathEquals(
097: HarmonisePaths.PATH_ASSETS);
098: ppathRule.setResultComparator(false);
099: andGroup.addEnableRule(ppathRule);
100: this .addEnableRule(andGroup);
101: }
102:
103: /* (non-Javadoc)
104: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
105: */
106: public void actionPerformed(ActionEvent ae) {
107: StateHandler.getInstance().addWait(WAIT_LABEL);
108: StatusData statusOverall = new VFSStatus();
109:
110: String sFileName = null;
111: boolean bFound = false;
112: try {
113: VirtualFile vfFile = this .getLastContextFile();
114:
115: if (vfFile.isDirectory()) {
116: Iterator itor = vfFile.getChildren().iterator();
117: while (itor.hasNext()) {
118: String sPath = (String) itor.next();
119: VirtualFile vfChild = vfFile.getVFS()
120: .getVirtualFile(sPath).getResource();
121: if (vfChild.getState() == VirtualFile.STATE_LIVE) {
122: bFound = true;
123: break;
124: }
125: }
126: }
127: if (bFound) {
128: MessageHandler
129: .getInstance()
130: .fireMessageEvent(
131: "This collection has published children, you must delete those first.",
132: MessageHandler.TYPE_ERROR);
133: } else {
134: sFileName = vfFile.getVFS().getVirtualFileSystemView()
135: .getDisplayName(vfFile);
136: String sMessage = null;
137: StatusData status = vfFile.delete();
138: statusOverall.addStatusData(status);
139: if (status.isOK()) {
140: this .getLastContextDirectory().removeChild(
141: vfFile.getFullPath());
142: this .getLastContextDirectory().refreshChildren();
143: this
144: .getLastContextDirectory()
145: .fireVirtualFileEvent(
146: VirtualFileEvent.FILE_MEMBERS_CHANGED);
147: super .fireSessionEvent("Archived", vfFile.getVFS(),
148: vfFile.getFullPath().replaceAll("webdav",
149: "webdav/Archive"),
150: SessionEventData.RESOURCE_ARCHIVED);
151: } else {
152: }
153: }
154:
155: } catch (Exception e) {
156: e.printStackTrace(System.err);
157: statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
158: } finally {
159: if (!bFound) {
160: VFSMessageBuilder.getInstance().fireMessage(
161: ActionArchive.ACTION_NAME, statusOverall,
162: sFileName);
163: }
164: StateHandler.getInstance().removeWait(WAIT_LABEL);
165: }
166: }
167:
168: /* (non-Javadoc)
169: * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
170: */
171: public JMenuItem getMenuItem() {
172: JMenuItem menuItem = super .getMenuItem();
173: menuItem.setAccelerator(KeyStroke.getKeyStroke(this
174: .getAcceleratorKeycode(), this .getAcceleratorMask()));
175:
176: return menuItem;
177: }
178:
179: /* (non-Javadoc)
180: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
181: */
182: public String getDescription() {
183: return "Archives the currently selected resource";
184: }
185:
186: /* (non-Javadoc)
187: * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
188: */
189: public String getText() {
190: return "Archive";
191: }
192:
193: /* (non-Javadoc)
194: * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
195: */
196: public String getToolTip() {
197: return this .getDescription();
198: }
199:
200: /* (non-Javadoc)
201: * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
202: */
203: public Icon getIcon() {
204: return IconManager.getInstance().getIcon(
205: "16-archive-container.gif");
206: }
207:
208: /* (non-Javadoc)
209: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
210: */
211: public int getAcceleratorKeycode() {
212: return KeyEvent.VK_A;
213: }
214:
215: /* (non-Javadoc)
216: * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
217: */
218: public String getMnemonic() {
219: return "A";
220: }
221:
222: /* (non-Javadoc)
223: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
224: */
225: public int getAcceleratorMask() {
226: return InputEvent.CTRL_MASK;
227: }
228:
229: }
|