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.Cursor;
036import java.awt.event.ActionEvent;
037
038import javax.swing.Action;
039import javax.swing.ImageIcon;
040import javax.swing.KeyStroke;
041
042import org.apache.commons.logging.Log;
043import org.apache.commons.logging.LogFactory;
044import org.kepler.util.StaticResources;
045
046import diva.gui.GUIUtilities;
047import ptolemy.actor.gui.TableauFrame;
048import ptolemy.vergil.toolbox.FigureAction;
049
050/**
051 * This action can be used for uploading a single Item KAR to a remote repository.
052 * 
053 * 
054 * @author Aaron Schultz
055 *
056 */
057public class ActorUploaderAction extends FigureAction {
058        private static final Log log = LogFactory.getLog(ActorUploaderAction.class);
059        private static final boolean isDebugging = log.isDebugEnabled();
060
061        private TableauFrame _parent;
062        
063        // ////////////////////////////////////////////////////////////////////////////
064        // LOCALIZABLE RESOURCES - NOTE that these default values are later
065        // overridden by values from the uiDisplayText resourcebundle file
066        // ////////////////////////////////////////////////////////////////////////////
067        private static String DISPLAY_NAME = StaticResources.getDisplayString(
068                        "actions.actor.displayName", "Upload to Repository");
069        private static String TOOLTIP = StaticResources.getDisplayString(
070                        "actions.actor.tooltip",
071                        "Uploads an actor to the ecogrid repository.");
072        private static ImageIcon LARGE_ICON = null;
073        private static KeyStroke ACCELERATOR_KEY = null;
074
075        // = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().
076        // getMenuShortcutKeyMask());
077        // //////////////////////////////////////////////////////////////////////////////
078
079        /**
080         * @param name
081         */
082        public ActorUploaderAction(TableauFrame parent) {
083                super("");
084                
085                if (parent == null) {
086                        IllegalArgumentException iae = new IllegalArgumentException(
087                                        "ActorUploaderAction constructor received NULL argument for TableauFrame");
088                        iae.fillInStackTrace();
089                        throw iae;
090                }
091                _parent = parent;
092                
093                initialize();
094        }
095        
096        protected void initialize() {
097                
098                this.putValue(Action.NAME, DISPLAY_NAME);
099                this.putValue(GUIUtilities.LARGE_ICON, LARGE_ICON);
100                this.putValue("tooltip", TOOLTIP);
101                this.putValue(GUIUtilities.ACCELERATOR_KEY, ACCELERATOR_KEY);
102                
103        }
104
105        /**
106         * Invoked when an action occurs.
107         * 
108         *@param e
109         *            ActionEvent
110         */
111        public void actionPerformed(ActionEvent e) {
112                super.actionPerformed(e);
113                
114                ExportActorArchiveAction eaaa = new ExportActorArchiveAction(_parent);
115                eaaa.useTempFile = true;
116                _parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
117                eaaa.actionPerformed(e);
118                _parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
119                
120//              ComponentEntity object;
121//              SaveKAR sk = eaaa.getSaveKAR();
122//              
123//              ArrayList<ComponentEntity> components = sk.getSaveInitiatorList();
124//              if (components.size() == 1) {
125//                      object = components.get(0);
126//              } else {
127//                      return;
128//              }
129//              
130//              ComponentUploader uploader = new ComponentUploader(_parent);
131//              uploader.upload(sk.getFile(), object);
132                
133        }
134
135}