View Javadoc

1   /*
2    * Created on May 23, 2005, Copyright UC Regents
3    */
4   package org.telscenter.pas.authortool.actions;
5   
6   import java.awt.event.ActionEvent;
7   import java.io.IOException;
8   import java.net.URL;
9   import java.util.ArrayList;
10  import java.util.Collection;
11  
12  import javax.swing.AbstractAction;
13  import javax.swing.ImageIcon;
14  import javax.swing.JOptionPane;
15  
16  import net.sf.sail.common.apps.preview.BundleLauncher;
17  import net.sf.sail.core.curnit.Curnit;
18  import net.sf.sail.core.session.ICurnitProvider;
19  import net.sf.sail.core.uuid.CurnitUuid;
20  
21  import org.telscenter.pas.authortool.context.AuthoringSessionContext;
22  import org.telscenter.pas.authortool.context.CurnitAuthoringContext;
23  import org.telscenter.pas.beans.PasProject;
24  
25  
26  /***
27   * Preview the curnit live from in-memory
28   * @author turadg
29   *
30   */
31  public class PasLivePreviewCurnitAction extends AbstractAction {
32  	PasProject pasProject;	
33  	
34  	/***
35  	 * 
36  	 */
37  	private static final long serialVersionUID = 1L;
38  	CurnitAuthoringContext curnitAuthoringContext;
39  
40  	public PasLivePreviewCurnitAction(final CurnitAuthoringContext cac) {
41  		super("Live Preview", new ImageIcon(QuitAction.class
42  				.getResource("icons/livePreview16.png")));
43  		this.putValue(SHORT_DESCRIPTION, "Launch a Preview version of current project.");
44  		curnitAuthoringContext = cac;
45  	}
46  
47  	public void actionPerformed(final ActionEvent e) {
48  		try {
49  			if(pasProject != null) {
50  				pasProject.getProjectFrame().setVisible(true);
51  				return;
52  			}
53  			
54  			/***
55  			 * Create the curnit provider for this curnit 
56  			 */
57  			ICurnitProvider provider = new ICurnitProvider(){
58  
59  				public Curnit getCurnit(CurnitUuid curnitId) {
60  					return curnitAuthoringContext.getAssembledCurnit();
61  				}
62  
63  				public Collection getRegisteredCurnitUuids() {
64  					Curnit workingCurnit = curnitAuthoringContext.getAssembledCurnit();
65  
66  					ArrayList curnits = new ArrayList();
67  					curnits.add(workingCurnit.getCurnitId());
68  					return curnits;
69  				}			
70  			};
71  
72  			/***
73  			 * Add the bundles configured in this xml file.  The format of the file is XMLEncoder
74  			 */
75  			URL bundlesXML = AuthoringSessionContext.class.getResource("previewBundles.xml");		
76  			BundleLauncher.launch(bundlesXML, provider);
77  
78  			
79  			pasProject = (PasProject)curnitAuthoringContext.getFirstRootBean();
80  			pasProject.setExitOnClose(false);
81  /*			
82  			curnitAuthoringContext.previewCurnit();
83  			// FIXME second preview doesn't work
84  			setEnabled(false);
85  			*/
86  		} catch (IOException e1) {
87  			// TODO Auto-generated catch block
88  			e1.printStackTrace();
89  			JOptionPane.showMessageDialog(null, e1.getClass(), e1.getLocalizedMessage(), JOptionPane.ERROR_MESSAGE);
90  		}
91  	}
92  
93  }