View Javadoc

1   package org.lcsim.plugin.conditions;
2   
3   import java.awt.Frame;
4   import javax.swing.SwingUtilities;
5   import org.freehep.application.Application;
6   import org.freehep.application.studio.Studio;
7   import org.freehep.swing.wizard.WizardDialog;
8   import org.freehep.swing.wizard.WizardPage;
9   import org.lcsim.conditions.*;
10  import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
11  import org.lcsim.util.loop.LCSimConditionsManagerImplementation;
12  
13  /**
14   * Extends the default ConditionsManager to add interactive prompting for detector conditions
15   * @author tonyj
16   * @version $Id: InteractiveConditionsManagerImplementation.java,v 1.3 2007/09/11 00:21:02 tonyj Exp $
17   */
18  public class InteractiveConditionsManagerImplementation extends LCSimConditionsManagerImplementation
19  {
20     private Studio app;
21     private int run;
22     private boolean newDetectorSet = false;
23     
24     /** Creates a new instance of InteractiveConditionsManagerImplementation */
25     public InteractiveConditionsManagerImplementation(Studio app)
26     {
27        super();
28        this.app = app;
29     }
30     
31     public void setDetector(String name, int run) throws ConditionsManager.ConditionsNotFoundException
32     {
33        try
34        {
35           super.setDetector(name, run);
36        }
37        catch (ConditionsManager.ConditionsNotFoundException x)
38        {
39           this.run = run;
40           displayWizardPage(name);
41           if (!newDetectorSet) throw x;
42        }
43     }
44     private void displayWizardPage(String name)
45     {
46        Frame frame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class,app);
47        WizardDialog wizard = new AppWizardDialog(frame,"Open Data Source...", new ConditionsWizardPage(this,name));
48        wizard.pack();
49        wizard.setLocationRelativeTo(app);
50        wizard.setVisible(true);
51     }
52     void setDetectorFound(boolean found)
53     {
54        this.newDetectorSet = found;
55     }
56     void addAlias(String alias, String target) throws ConditionsNotFoundException
57     {
58        ConditionsReader.addAlias(alias,target);
59        super.setDetector(alias,run);
60        setDetectorFound(true);
61     }
62  
63     Studio getStudio()
64     {
65        return app;
66     }
67  
68     private class AppWizardDialog extends WizardDialog
69     {
70        AppWizardDialog(Frame frame, String title, WizardPage firstPage)
71        {
72           super(frame,title,firstPage);
73        }
74        
75        protected void handleError(String message, Throwable t)
76        {
77           Application.error(this,message,t);
78        }
79        
80     }
81  }