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.displaycomponents.table.*;
029: import org.openharmonise.him.harmonise.*;
030: import org.openharmonise.him.window.*;
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.gui.*;
036: import org.openharmonise.vfs.status.*;
037:
038: /**
039: * Action to publish a virtual file.
040: *
041: * @author Matthew Large
042: * @version $Revision: 1.1 $
043: *
044: */
045: public class ActionPublishToInternet extends AbstractHIMAction
046: implements HIMAction {
047:
048: public static String ACTION_NAME = "PUBLISH";
049:
050: /**
051: * Wait identifier for state handler.
052: */
053: private static final String WAIT_LABEL = "PUBLISH-ACTION";
054:
055: /**
056: *
057: */
058: public ActionPublishToInternet() {
059: super ();
060: this .setup();
061: }
062:
063: /**
064: * @param vfFile
065: */
066: public ActionPublishToInternet(VirtualFile vfFile) {
067: super (vfFile);
068: this .setup();
069: }
070:
071: /**
072: * Configures this action.
073: *
074: */
075: private void setup() {
076: RuleGroup andGroup = new RuleGroup();
077: andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
078: PathRule pathRule = new PathRule("/webdav/Archive/");
079: pathRule.setResultComparator(false);
080: andGroup.addEnableRule(pathRule);
081: isMetadataValidRule metadataRule = new isMetadataValidRule();
082: metadataRule.setResultComparator(true);
083: andGroup.addEnableRule(metadataRule);
084: IsHistoricalRule histRule = new IsHistoricalRule();
085: histRule.setResultComparator(false);
086: andGroup.addEnableRule(histRule);
087: SecurityRule secRule = new SecurityRule(
088: VirtualFile.METHOD_CHECKIN);
089: andGroup.addEnableRule(secRule);
090: TabRule tabRule = new TabRule("Search");
091: tabRule.setResultComparator(false);
092: andGroup.addEnableRule(tabRule);
093: this .addEnableRule(andGroup);
094: }
095:
096: /* (non-Javadoc)
097: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
098: */
099: public void actionPerformed(ActionEvent arg0) {
100: VirtualFile vfFile = this .getLastContextFile();
101: StatusData statusOverall = new VFSStatus();
102: AbstractVirtualFileSystem vfs = vfFile.getVFS();
103:
104: if (vfFile.isVersionable()) {
105: VersionedVirtualFile vfVerFile = (VersionedVirtualFile) vfFile;
106:
107: String sLivePath = vfVerFile.getLiveVersionPath();
108:
109: StateHandler.getInstance().addWait(WAIT_LABEL);
110: String sFileName = null;
111: try {
112: sFileName = vfFile.getVFS().getVirtualFileSystemView()
113: .getDisplayName(vfFile);
114: String sMessage = null;
115: StatusData status = vfVerFile.checkin();
116: statusOverall.addStatusData(status);
117: if (status.isOK()) {
118:
119: if (sLivePath != null) {
120:
121: ResourceStatusWrapper pathStatus = vfs
122: .getVirtualFile(sLivePath);
123: if (pathStatus.getResource() != null) {
124: pathStatus.getResource().unlock();
125: }
126:
127: TableView table = DisplayManager.getInstance()
128: .getTable();
129: if (table != null) {
130: table.setSelectedPath(sLivePath);
131: }
132: if (sLivePath
133: .startsWith(HarmonisePaths.PATH_PROPERTIES)) {
134: ContextEvent ce = new ContextEvent(
135: ContextType.CONTEXT_METADATA_DEFINITION_CHANGED,
136: "", vfFile.getVFS(), sLivePath);
137: ContextHandler.getInstance()
138: .fireContextEvent(ce);
139: }
140: }
141: super .fireSessionEvent("Published", this
142: .getLastContextFile().getVFS(), this
143: .getLastContextFile().getFullPath(),
144: SessionEventData.RESOURCE_PUBLISHED);
145: } else {
146:
147: }
148: } catch (Exception e) {
149: e.printStackTrace(System.err);
150: statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
151: } finally {
152: StatusMessage statusMessage = new StatusMessage(
153: ActionPublishToInternet.ACTION_NAME,
154: statusOverall);
155: statusMessage.setResourceTitle(sFileName);
156: if (sLivePath != null) {
157: statusMessage.setPath(sLivePath);
158: } else {
159: statusMessage.setPath(vfFile.getFullPath());
160: }
161: VFSMessageBuilder.getInstance().fireMessage(
162: statusMessage);
163: StateHandler.getInstance().removeWait(WAIT_LABEL);
164: }
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 "Publishes the currently seleted resource";
184: }
185:
186: /* (non-Javadoc)
187: * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
188: */
189: public String getText() {
190: return "Publish";
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-command-publish.gif");
206: }
207:
208: /* (non-Javadoc)
209: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
210: */
211: public int getAcceleratorKeycode() {
212: return KeyEvent.VK_P;
213: }
214:
215: /* (non-Javadoc)
216: * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
217: */
218: public String getMnemonic() {
219: return "P";
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: /* (non-Javadoc)
230: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#isEnabled(com.simulacramedia.contentmanager.context.ContextEvent)
231: */
232: public boolean isEnabled(ContextEvent ce) {
233: // TODO Auto-generated method stub
234: return super.isEnabled(ce);
235: }
236:
237: }
|