1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 package net.sf.tm.plugin.actions;
34
35 import org.eclipse.jface.action.IAction;
36 import org.eclipse.jface.viewers.ISelection;
37 import org.eclipse.ui.IWorkbenchWindow;
38 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
39
40 import net.sf.tm.ContextManagerException;
41 import net.sf.tm.IContextManager;
42 import net.sf.tm.WebContext;
43 import net.sf.tm.WebContextStatus;
44 import net.sf.tm.plugin.ContextManagerPlugin;
45 import net.sf.tm.plugin.Logger;
46 import net.sf.tm.plugin.TreeNode;
47 import net.sf.tm.plugin.ui.WebContextView;
48 import net.sf.tm.tomcat.TomcatContextManager;
49 import net.sf.tm.tomcat.TomcatServer;
50
51 /***
52 * Action for reloading a context on a server. The context has to be started
53 * to be reloaded.
54 *
55 * @author Andreas Pataki
56 * @version $Id: ReloadContextAction.java,v 1.10 2004/02/23 19:19:35 apataki Exp $
57 */
58 public class ReloadContextAction
59 extends AbstractBackgroundAction
60 implements IWorkbenchWindowActionDelegate {
61
62 /***
63 * View which this action is attached with.
64 */
65 private WebContextView view;
66
67 /***
68 * Constructor for this action. The text and image settings are initialized.
69 *
70 * @param parentView Parent view which created this action.
71 */
72 public ReloadContextAction(WebContextView parentView) {
73 view = parentView;
74
75 setText(getLocalizedString("action.reload.text"));
76 setToolTipText(getLocalizedString("action.reload.tooltip"));
77 setImageDescriptor(
78 ContextManagerPlugin.getDefault().getImageDescriptor(
79 "icons/refresh.gif"));
80 }
81
82 /***
83 * On excecution the run method changes the icon state, then splits of
84 * another thread to do the actual excecution with a busy indicator.
85 *
86 * @see org.eclipse.jface.action.IAction#run()
87 */
88 public void run() {
89 TreeNode node = (TreeNode) view.getSelected();
90 WebContext context = (WebContext) node.getContent();
91
92 TomcatServer server = (TomcatServer) node.getParent().getContent();
93 if (server.getManager().equals(context.getPath())) {
94 ContextManagerPlugin.getDefault().showError(
95 getLocalizedString("error.managerReload"));
96 } else {
97
98 context.setStatus(WebContextStatus.PENDING);
99 view.updateContextNode(node);
100
101 final TreeNode restartNode = (TreeNode) view.getSelected();
102
103 runInBackground(new Runnable() {
104 public void run() {
105 restart(restartNode);
106 }
107 });
108
109 }
110 }
111
112 /***
113 * @param node The node which should be restarted
114 */
115 private void restart(final TreeNode node) {
116 final WebContext context = (WebContext) node.getContent();
117
118 IContextManager manager =
119 new TomcatContextManager(
120 (TomcatServer) node.getParent().getContent());
121
122 try {
123
124 manager.reload(context.getPath());
125
126 if (Logger.isDebugEnabled()) {
127 Logger.debug("reload of context " + context.getPath());
128 }
129
130 runInUIThread(new Runnable() {
131
132 public void run() {
133 view.update();
134 }
135
136 });
137
138 } catch (final ContextManagerException e) {
139
140 Logger.error("error reloading " + context, e);
141
142
143 runInUIThread(new Runnable() {
144
145 public void run() {
146 ContextManagerPlugin.getDefault().showError(
147 (getLocalizedString("error.reloadContext",
148 context.getPath())),
149 e);
150
151 context.setStatus(WebContextStatus.STOPPED);
152 view.updateContextNode(node);
153 }
154
155 });
156
157 }
158 }
159
160 /***
161 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
162 */
163 public void dispose() {
164 System.out.println("dispose");
165 }
166
167 /***
168 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
169 */
170 public void init(IWorkbenchWindow window) {
171 System.out.println("init " + window);
172
173 }
174
175 /***
176 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
177 */
178 public void run(IAction action) {
179 System.out.println("run " + action);
180 }
181
182 /***
183 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
184 */
185 public void selectionChanged(IAction action, ISelection selection) {
186 }
187
188 }