001/* 002 * Copyright (c) 2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-05 22:21:26 -0700 (Wed, 05 May 2010) $' 007 * '$Revision: 24234 $' 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.workflowscheduler.gui; 030 031import javax.swing.JOptionPane; 032import javax.swing.SwingWorker; 033 034import org.kepler.gui.kar.ComponentUploader; 035import org.kepler.kar.KARFile; 036import org.kepler.kar.karxml.KarXmlGenerator; 037 038import ptolemy.actor.gui.TableauFrame; 039 040 041/** 042 * A Swing worker class to do uploading a kar file job 043 * @author tao 044 * 045 */ 046public class UploadingKARFileSwingWorker extends SwingWorker 047{ 048 private KARFile karFile = null; 049 private String karFilePath = null; 050 private String workflowName = null; 051 private String workflowLSID = null; 052 private String repositoryName = null; 053 private TableauFrame parent = null; 054 //private UploadingKARFileListenerInterface uploadingListener = null; 055 private ScheduleChangeController changeController = null; 056 057 /** 058 * Constructor 059 * @param karFile the kar file will be uploaded 060 */ 061 public UploadingKARFileSwingWorker(KARFile karFile, String karFilePath, 062 String workflowName, String workflowLSID, String repositoryName, 063 ScheduleChangeController changeController, TableauFrame parent) 064 { 065 this.karFile = karFile; 066 this.karFilePath = karFilePath; 067 this.workflowName = workflowName; 068 this.workflowLSID = workflowLSID; 069 this.repositoryName = repositoryName; 070 this.parent = parent; 071 this.changeController = changeController; 072 } 073 074 /** 075 *Do the uploading job 076 */ 077 public Object doInBackground() 078 { 079 if(changeController != null) 080 { 081 //System.out.println("disable tree selection ================="); 082 changeController.disableTreeSelection(); 083 } 084 String karFileLSID = null; 085 String metadataObj = null; 086 KarXmlGenerator kxg = null; 087 try 088 { 089 kxg = new KarXmlGenerator(karFile); 090 metadataObj = kxg.getKarXml(); 091 } 092 catch (Exception e) 093 { 094 e.printStackTrace(); 095 JOptionPane.showMessageDialog(parent, 096 "There was a problem to create the kar xml - " 097 + e.getMessage(), "Error", 098 JOptionPane.ERROR_MESSAGE); 099 if(changeController != null) 100 { 101 changeController.enableTreeSelection(); 102 } 103 return null; 104 } 105 boolean hasReportingLayout = kxg.hasReportLayout(); 106 int choice = JOptionPane.YES_OPTION; 107 if(!hasReportingLayout && changeController != null && 108 changeController.showWarningMessageOnNoReporting() ) 109 { 110 choice = JOptionPane.showConfirmDialog(parent, 111 SchedulerAbstractAction.NOREPORTWARNING, "Warning", JOptionPane.YES_NO_OPTION); 112 } 113 boolean success = false; 114 if(choice == JOptionPane.YES_OPTION) 115 { 116 ComponentUploader uploader = new ComponentUploader(parent); 117 success = uploader.upload(karFile, metadataObj); 118 } 119 if(success) 120 { 121 karFileLSID = karFile.getLSID().toString(); 122 } 123 if(changeController != null) 124 { 125 //System.out.println("enable tree selection ================="); 126 changeController.enableTreeSelection(); 127 changeController.completeUploading(karFileLSID, karFilePath, workflowName, 128 workflowLSID, repositoryName); 129 } 130 return null; 131 } 132 133 134}