ActionExport.java :  » Content-Management-System » harmonise » org » openharmonise » him » actions » publish » Java Open Source

Java Open Source » Content Management System » harmonise 
harmonise » org » openharmonise » him » actions » publish » ActionExport.java
/*
 * The contents of this file are subject to the 
 * Mozilla Public License Version 1.1 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
 * See the License for the specific language governing rights and 
 * limitations under the License.
 *
 * The Initial Developer of the Original Code is Simulacra Media Ltd.
 * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
 *
 * All Rights Reserved.
 *
 * Contributor(s):
 */
package org.openharmonise.him.actions.publish;

import java.awt.event.*;

import javax.swing.*;

import org.openharmonise.him.actions.*;
import org.openharmonise.him.actions.rules.*;
import org.openharmonise.him.context.StateHandler;
import org.openharmonise.him.editors.*;
import org.openharmonise.him.harmonise.*;
import org.openharmonise.him.window.messages.builders.*;
import org.openharmonise.vfs.*;
import org.openharmonise.vfs.context.*;
import org.openharmonise.vfs.gui.*;
import org.openharmonise.vfs.status.*;


/**
 * Action to export a virtual file.
 * 
 * @author Matthew Large
 * @version $Revision: 1.1 $
 *
 */
public class ActionExport extends AbstractHIMAction implements HIMAction {

  public static String ACTION_NAME = "EXPORT";

  /**
   * Wait identifier for state handler.
   */
  private static final String WAIT_LABEL = "EXPORT-ACTION";
  
  /**
   * 
   */
  public ActionExport() {
    super();
    this.setup();
  }

  /**
   * @param vfFile
   */
  public ActionExport(VirtualFile vfFile) {
    super(vfFile);
    this.setup();
  }
  
  /**
   * Configures this action.
   *
   */
  private void setup() {
    PathRule pathRule = new PathRule(HarmonisePaths.PATH_DOCUMENTS);
    this.addEnableRule(pathRule);
    pathRule = new PathRule(HarmonisePaths.PATH_IMAGES);
    this.addEnableRule(pathRule);
    pathRule = new PathRule(HarmonisePaths.PATH_PDF);
    this.addEnableRule(pathRule);
    pathRule = new PathRule(HarmonisePaths.PATH_FLASH);
    this.addEnableRule(pathRule);
    pathRule = new PathRule(HarmonisePaths.PATH_REPORTS_OUTPUT);
    this.addEnableRule(pathRule);
  }

  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent arg0) {
    StatusData statusOverall = new VFSStatus();
    VirtualFile vfFile =this.getLastContextFile();
    StateHandler.getInstance().addWait(WAIT_LABEL);
    String sFileName = vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile);
    try {
      StatusData status = EditorController.getInstance().export(vfFile.getFullPath(), this.getLastContextFile().getVFS());
      statusOverall.addStatusData(status);
    } catch(Exception e) {
      e.printStackTrace(System.err);
      statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
    } finally {
      StateHandler.getInstance().removeWait(WAIT_LABEL);
      VFSMessageBuilder.getInstance().fireMessage(ActionExport.ACTION_NAME, statusOverall, sFileName);
    }
  }

  /* (non-Javadoc)
   * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
   */
  public JMenuItem getMenuItem() {
    JMenuItem menuItem = super.getMenuItem();
    menuItem.setAccelerator( KeyStroke.getKeyStroke(this.getAcceleratorKeycode(), this.getAcceleratorMask()) );
    
    return menuItem;
  }

  /* (non-Javadoc)
   * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
   */
  public String getDescription() {
    return "Exports the currently selected resource to your local file system";
  }

  /* (non-Javadoc)
   * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
   */
  public String getText() {
    return "Export...";
  }

  /* (non-Javadoc)
   * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
   */
  public String getToolTip() {
    return this.getDescription();
  }

  /* (non-Javadoc)
   * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
   */
  public Icon getIcon() {
    return IconManager.getInstance().getIcon("16-blank.gif");
  }

  /* (non-Javadoc)
   * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
   */
  public int getAcceleratorKeycode() {
    return KeyEvent.VK_E;
  }

  /* (non-Javadoc)
   * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
   */
  public String getMnemonic() {
    return "E";
  }

  /* (non-Javadoc)
   * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
   */
  public int getAcceleratorMask() {
    return InputEvent.CTRL_MASK;
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.