1
2
3
4
5
6
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
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
79
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
91
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
118
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
146
147
148 public void init(IAction action)
149 {
150 super.init(action);
151 }
152 }
153
154 }