View Javadoc

1   /*
2    * $Id: LibraryWizardActionFactory.java,v 1.4 2005/05/31 21:57:12 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8    
9   package com.bbn.swede.ui.wizards;
10  
11  import org.eclipse.jface.action.IAction;
12  import org.eclipse.jface.dialogs.MessageDialog;
13  import org.eclipse.jface.viewers.StructuredSelection;
14  import org.eclipse.jface.wizard.WizardDialog;
15  import org.eclipse.ui.IActionDelegate;
16  import org.eclipse.ui.IWorkbenchWizard;
17  import org.eclipse.ui.actions.ActionDelegate;
18  import org.eclipse.ui.internal.Workbench;
19  
20  import com.bbn.swede.core.libraries.ILibraryDescriptor;
21  
22  /***
23   * This class will return actions to invoke either the creation 
24   * or editing wizard for libraries. 
25   * 
26   * @author aperezlo
27   */
28  public final class LibraryWizardActionFactory
29  {
30     private LibraryWizardActionFactory()
31     {
32        //Hide constructor, since this is a factory class
33     }
34     /***
35      * Constant indicating a library creation dialog.
36      */
37     public static final int CREATE = 1;
38     /***
39      * Constant indicating a library edit dialog.
40      */
41     public static final int EDIT = 2;
42     
43     private static LibraryWizardActionFactory _me;
44     
45     /***
46      * The <code>which</code> parameter must be either 
47      * LibraryWizardActionFactory.CREATE or LibraryWizardActionFactory.EDIT 
48      * to return the action that will launch the appropriate wizard. 
49      * 
50      * @param which either LibraryWizardActionFactory.CREATE or LibraryWizardActionFactory.EDIT
51      * @return an action to launch either the library creation or the library editing wizard
52      */
53     public static IActionDelegate getAction(int which)
54     {
55        IActionDelegate toReturn = null;
56        if(_me == null)
57        {
58           _me = new LibraryWizardActionFactory();
59        }
60        if(which == CREATE)
61        {
62           toReturn = _me.new Create();
63        }
64        else if(which == EDIT)
65        {
66           toReturn = _me.new Edit();
67        }
68        return toReturn;
69     }
70     
71     /***
72      * Action for launching the library creation wizard.
73      * @author aperezlo
74      */
75     public class Create extends ActionDelegate implements IActionDelegate
76     {
77        /*
78         *  (non-Javadoc)
79         * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
80         */
81        public void run(IAction action)
82        {
83           IWorkbenchWizard wiz = new OWLNewLibraryWizard();
84           wiz.init(Workbench.getInstance(), new StructuredSelection());
85           WizardDialog wd = new WizardDialog(Workbench.getInstance().getActiveWorkbenchWindow().getShell(), wiz);
86           wd.open();
87        }   
88     
89        /*
90         *  (non-Javadoc)
91         * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
92         */
93        public void init(IAction action)
94        {
95           super.init(action);
96        }
97     }
98     
99     /***
100     * Action for launching the library edit dialog.
101     * @author aperezlo
102     */
103    public class Edit extends ActionDelegate implements IActionDelegate
104    {
105       private ILibraryDescriptor _library;
106       
107       /***
108        * Sets the library that this dialog will edit.
109        * @param library The library to edit
110        */
111       public void setLibrary(ILibraryDescriptor library)
112       {
113          _library = library;
114       }
115       
116       /*
117        *  (non-Javadoc)
118        * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
119        */
120       public void run(IAction action)
121       {
122          IWorkbenchWizard wiz = new OWLEditLibraryWizard();
123          String name = _library.getName();
124          if(!_library.isAvailable())
125          {
126             MessageDialog
127                .openInformation(
128                   Workbench.getInstance().getActiveWorkbenchWindow().getShell(),
129                   "Unavailable...",
130                   "This library is currently unavailable for editing because "
131                   + "it is being used by another operation, which is most "
132                   + "likely a refresh.  Please try again after the operation "
133                   + "is completed.  You can check the status by looking at "
134                   + "the gear icon in the bottom right corner of the window.");
135          }
136          else
137          {
138             wiz.init(Workbench.getInstance(), new StructuredSelection(_library));
139             WizardDialog wd = new WizardDialog(Workbench.getInstance().getActiveWorkbenchWindow().getShell(), wiz);
140             wd.open();
141          }
142       }   
143    
144       /*
145        *  (non-Javadoc)
146        * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
147        */
148       public void init(IAction action)
149       {
150          super.init(action);
151       }
152    }
153    
154 }