001/*
002 * Copyright (c) 2014 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: crawl $'
006 * '$Date: 2011-04-12 13:56:18 -0700 (Tue, 12 Apr 2011) $' 
007 * '$Revision: 27498 $'
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 */
029package org.kepler.cloudsharing.gui;
030
031
032import java.awt.event.ActionEvent;
033
034import javax.swing.JButton;
035import javax.swing.WindowConstants;
036
037import org.kepler.gui.KeplerGraphFrame;
038import org.kepler.moml.NamedObjId;
039import org.kepler.objectmanager.lsid.KeplerLSID;
040import org.kepler.provenance.ProvenanceRecorder;
041import org.kepler.provenance.Queryable;
042
043import diva.gui.GUIUtilities;
044import ptolemy.kernel.util.NamedObj;
045import ptolemy.util.MessageHandler;
046import ptolemy.vergil.toolbox.FigureAction;
047
048/** An action that uploads workflow results to the cloud.
049 *
050 *  @author Daniel Crawl
051 *  @version $Id$
052 */
053public class CloudSharingConfigureAction extends FigureAction
054{
055    public CloudSharingConfigureAction(KeplerGraphFrame owner)
056    {
057        super("Cloud Sharing");
058
059        _parent = owner;
060        
061        //_button = null;
062
063        // configure the button icons
064        GUIUtilities.addIcons(this, new String[][] {
065            { ON_ICON_STR, GUIUtilities.LARGE_ICON },
066            { OVER_ICON_STR, GUIUtilities.ROLLOVER_ICON },
067            { OVER_ICON_STR, GUIUtilities.ROLLOVER_SELECTED_ICON },
068            { OVER_ICON_STR, GUIUtilities.SELECTED_ICON } });
069    }
070
071    ///////////////////////////////////////////////////////////////////
072    ////                         public methods                    ////
073
074    @Override
075    public void actionPerformed(ActionEvent event)
076    {
077        super.actionPerformed(event);
078
079        // see if the workflow has been run
080        try {
081            final NamedObj top = _parent.getModel().toplevel();                                
082            KeplerLSID lsid = NamedObjId.getIdFor(top);
083            Queryable queryable = ProvenanceRecorder.getDefaultQueryable(top);
084            /*KeplerLSID run_lsid =*/ queryable.getLastExecutionLSIDForWorkflow(lsid);
085        } catch(Exception e) {
086            MessageHandler.error("Could not find last execution of this workflow in the " +
087                    "provenance database. Make sure the workflow has been run.", e);
088            return;
089        }
090        
091        // make sure at least one factory exists
092        // TODO
093
094        ShareResultsToCloudDialog dialog = new ShareResultsToCloudDialog(_parent);        
095        dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
096        dialog.pack();
097        dialog.setLocationRelativeTo(null);
098        dialog.setVisible(true);
099    }
100
101    /** Set the button. */
102    public void setButton(JButton button)
103    {
104        //_button = button;
105    }
106
107    ///////////////////////////////////////////////////////////////////
108    ////                         public fields                     ////
109
110    /** Icon for toolbar.  */
111    public static final String ON_ICON_STR =
112        "/org/kepler/cloudsharing/gui/img/cloudshare_on.gif";
113    
114    /** Icon when cursor over button. */
115    public static final String OVER_ICON_STR =
116        "/org/kepler/cloudsharing/gui/img/cloudshare_ov.gif";
117
118    ///////////////////////////////////////////////////////////////////
119    ////                         private methods                   ////
120
121    ///////////////////////////////////////////////////////////////////
122    ////                         private fields                    ////
123
124    /** The button for this action. */
125    //private JButton _button;
126    
127    private KeplerGraphFrame _parent;
128    
129}