001/*
002 * Copyright (c) 2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: crawl $'
006 * '$Date: 2015-08-24 22:44:14 +0000 (Mon, 24 Aug 2015) $' 
007 * '$Revision: 33630 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030/**
031 * 
032 */
033package org.kepler.gui.kar;
034
035import java.awt.event.ActionEvent;
036import java.io.File;
037import java.io.IOException;
038
039import javax.swing.Action;
040import javax.swing.ImageIcon;
041import javax.swing.KeyStroke;
042
043import org.apache.commons.logging.Log;
044import org.apache.commons.logging.LogFactory;
045import org.kepler.kar.KARFile;
046
047import diva.gui.GUIUtilities;
048import ptolemy.actor.gui.TableauFrame;
049import ptolemy.vergil.toolbox.FigureAction;
050
051/**
052 * This action can be used for uploading a single Item KAR to a remote
053 * repository.
054 * 
055 * 
056 * @author Aaron Schultz
057 * 
058 */
059public class KarUploaderAction extends FigureAction {
060
061        private static final Log log = LogFactory.getLog(KarUploaderAction.class);
062        private static final boolean isDebugging = log.isDebugEnabled();
063
064        private File archiveFileToUpload = null;
065
066        private TableauFrame _parent;
067
068        private static String DISPLAY_NAME = "Upload";
069        private static String TOOLTIP = "Upload a KAR file archive.";
070        private static ImageIcon LARGE_ICON = null;
071        private static KeyStroke ACCELERATOR_KEY = null;
072
073        /**
074         * @param name
075         */
076        public KarUploaderAction(TableauFrame parent) {
077                super("Upload");
078
079                if (parent == null) {
080                        IllegalArgumentException iae = new IllegalArgumentException(
081                                        "ActorUploaderAction constructor received NULL argument for TableauFrame");
082                        iae.fillInStackTrace();
083                        throw iae;
084                }
085                _parent = parent;
086
087                initialize();
088        }
089
090        protected void initialize() {
091
092                this.putValue(Action.NAME, DISPLAY_NAME);
093                this.putValue(GUIUtilities.LARGE_ICON, LARGE_ICON);
094                this.putValue("tooltip", TOOLTIP);
095                this.putValue(GUIUtilities.ACCELERATOR_KEY, ACCELERATOR_KEY);
096
097        }
098
099        /**
100         * Explicitly set the Archive file that the action will open. If not file is
101         * set a File chooser dialog is displayed to the user.
102         * 
103         * @param archiveFile
104         */
105        public void setArchiveFileToUpload(File archiveFile) {
106                archiveFileToUpload = archiveFile;
107        }
108
109        /**
110         * Invoked when an action occurs.
111         * 
112         *@param e
113         *            ActionEvent
114         */
115        public void actionPerformed(ActionEvent e) {
116                super.actionPerformed(e);
117
118                ComponentUploader uploader = new ComponentUploader(_parent);
119
120                KARFile kf2upload;
121                try {
122                        kf2upload = new KARFile(archiveFileToUpload);
123                        uploader.upload(kf2upload);
124                } catch (IOException e1) {
125                        e1.printStackTrace();
126                }
127
128        }
129
130}