1 package org.argosfields.action.server;
2
3 import java.lang.reflect.InvocationTargetException;
4
5 import org.argosfields.ArgosFields;
6 import org.argosfields.action.BaseAction;
7 import org.argosfields.multi.server.GameServer;
8 import org.argosfields.multi.server.IGameServer;
9 import org.argosfields.multi.server.IServerStatusListener;
10 import org.argosfields.resource.ResourceManager;
11 import org.argosfields.util.ExceptionHandler;
12 import org.eclipse.core.runtime.IProgressMonitor;
13 import org.eclipse.jface.operation.IRunnableWithProgress;
14 import org.eclipse.swt.widgets.Event;
15
16 /***
17 * StartServerAction.java
18 *
19 * @author Xavier Cho
20 * @version $Revision: 1.4 $ $Date: 2004/04/15 05:42:44 $
21 */
22 public class StartServerAction extends BaseAction {
23
24 private IGameServer server;
25
26 public StartServerAction(final ArgosFields application) {
27 super(application);
28
29 this.server = GameServer.getInstance();
30
31 setEnabled(!server.isRunning());
32
33 server.addServerStatusListener(new IServerStatusListener() {
34
35 public void serverStarted(final GameServer server) {
36 setEnabled(false);
37 }
38
39 public void serverStopped(final GameServer server) {
40 setEnabled(true);
41 }
42 });
43 }
44
45 /***
46 * @see org.eclipse.jface.action.IAction#runWithEvent(org.eclipse.swt.widgets.Event)
47 */
48 public void runWithEvent(final Event event) {
49 try {
50 getApplication().run(true, true, new Worker());
51 } catch (Exception e) {
52 ResourceManager resources = ResourceManager.getInstance();
53
54 String msg = resources.getString("error.server.start");
55 ExceptionHandler.handleException(msg, e);
56 }
57 }
58
59 private class Worker implements IRunnableWithProgress {
60
61 public void run(final IProgressMonitor monitor)
62 throws InvocationTargetException, InterruptedException {
63 monitor.beginTask("Starting the game server...",
64 IProgressMonitor.UNKNOWN);
65
66 try {
67 server.start();
68 } catch (Exception e) {
69 ResourceManager resources = ResourceManager.getInstance();
70
71 String msg = resources.getString("error.server.start");
72 ExceptionHandler.handleException(msg, e);
73 } finally {
74 monitor.done();
75 }
76 }
77 }
78 }
This page was automatically generated by Maven