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 net.sf.tm.plugin.ContextManagerPlugin;
36 import net.sf.tm.plugin.Logger;
37 import net.sf.tm.plugin.ServerStore;
38 import net.sf.tm.plugin.ui.NewServerDialog;
39 import net.sf.tm.plugin.ui.WebContextView;
40 import net.sf.tm.tomcat.TomcatServer;
41
42 import org.eclipse.jface.dialogs.MessageDialog;
43 import org.eclipse.jface.window.Window;
44
45 /***
46 * Action for creating a new server.
47 *
48 * @author Andreas Pataki
49 * @version $Id: NewServerAction.java,v 1.5 2003/08/28 14:15:38 apataki Exp $
50 */
51 public class NewServerAction extends AbstractAction {
52
53 /***
54 * View which this action is attached with.
55 */
56 private WebContextView view;
57
58 /***
59 * Constructor for this action. The text and image settings are initialized.
60 *
61 * @param parentView Parent view which created this action.
62 */
63 public NewServerAction(WebContextView parentView) {
64 view = parentView;
65
66 setText(getLocalizedString("action.new.text"));
67 setToolTipText(getLocalizedString("action.new.tooltip"));
68
69 setImageDescriptor(
70 ContextManagerPlugin.getDefault().getImageDescriptor(
71 "icons/new.gif"));
72 }
73
74 /***
75 * On excecution the {@link NewServerDialog} is opened. If the user confirms
76 * this dialog a new server is created in the {@link ServerStore}.
77 *
78 * @see org.eclipse.jface.action.Action#run()
79 */
80 public void run() {
81
82 TomcatServer server = new TomcatServer();
83
84 NewServerDialog dialog =
85 new NewServerDialog(
86 server,
87 ContextManagerPlugin.getDefault().getActiveWorkbenchShell());
88 dialog.create();
89 dialog.getShell().setText(getLocalizedString("plugin.title"));
90
91 if (dialog.open() == Window.OK) {
92
93
94 server = dialog.getServer();
95
96
97 if (ServerStore.getInstance().contains(server)) {
98 MessageDialog.openError(
99 ContextManagerPlugin.getDefault().getActiveWorkbenchShell(),
100 getLocalizedString("error.title"),
101 getLocalizedString("error.serverExists"));
102 } else {
103
104 ServerStore.getInstance().add(server);
105 view.update();
106
107 if (Logger.isDebugEnabled()) {
108 Logger.debug("server created: " + dialog.getServer());
109 }
110 }
111
112 }
113
114 }
115
116 }