1 package net.sf.panoptes.module.jmx.wizard;
2
3 import org.eclipse.core.runtime.IStatus;
4 import org.eclipse.core.runtime.Status;
5 import org.eclipse.jface.viewers.IStructuredSelection;
6 import org.eclipse.jface.wizard.WizardPage;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.layout.GridData;
9 import org.eclipse.swt.layout.GridLayout;
10 import org.eclipse.swt.widgets.Button;
11 import org.eclipse.swt.widgets.Combo;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Event;
14 import org.eclipse.swt.widgets.Label;
15 import org.eclipse.swt.widgets.Listener;
16 import org.eclipse.swt.widgets.Text;
17 import org.eclipse.ui.IWorkbench;
18
19 /***
20 * Class representing the first page of the wizard
21 */
22
23 public class NodeConnectionPage extends WizardPage {
24
25 private boolean isReady;
26
27 /***
28 * Extremely quick'n'dirty hack for selecting JMX Servers :)
29 */
30 IWorkbench workbench;
31 IStructuredSelection selection;
32
33 Text host;
34 Text rmiPort;
35 Text serverName;
36 Combo serverType;
37 private String[] connectors = new String[] { "net.sf.panoptes.module.jmx.connector.JBossRMIConnector", "net.sf.panoptes.module.jmx.connector.MX4JJRMPConnector" };
38
39 Button connectImmediately;
40 IStatus formStatus;
41
42 /***
43 * Constructor
44 */
45 public NodeConnectionPage(
46 IWorkbench workbench,
47 IStructuredSelection selection) {
48 super("Page1");
49 isReady = false;
50 setTitle("Create");
51 setDescription("Create a new JMX Connection");
52 formStatus = new Status(IStatus.ERROR, "not_used", 0, "", null);
53 }
54
55 /***
56 * @see IDialogPage#createControl(Composite)
57 */
58 public void createControl(Composite parent) {
59
60 GridData gd;
61 Composite composite = new Composite(parent, SWT.NULL);
62
63 GridLayout gl = new GridLayout();
64 int ncol = 2;
65 gl.numColumns = ncol;
66 composite.setLayout(new GridLayout(2, false));
67
68 new Label(composite, SWT.NONE).setText("Name (description):");
69 serverName = new Text(composite, SWT.BORDER);
70 serverName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
71
72 new Label(composite, SWT.NONE).setText("Host:");
73 host = new Text(composite, SWT.BORDER);
74 host.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
75
76 new Label(composite, SWT.NONE).setText("RMI Port:");
77 rmiPort = new Text(composite, SWT.BORDER);
78 rmiPort.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
79
80 new Label(composite, SWT.NONE).setText("Server type:");
81 serverType = new Combo(composite, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
82 serverType.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
83 serverType.add("JBoss 3.2.x or 4.x");
84 serverType.add("MX4J");
85
86
87 /***
88 * Add listener to reject non-numeric inputs
89 */
90 rmiPort.addListener(SWT.Verify, new Listener() {
91 public void handleEvent(Event event) {
92 String text = event.text;
93 char[] chars = new char[text.length()];
94 text.getChars(0, chars.length, chars, 0);
95 for (int i = 0; i < chars.length; i++) {
96 if (!('0' <= chars[i] && chars[i] <= '9')) {
97 event.doit = false;
98 return;
99 }
100 }
101 }
102 });
103
104 new Label(composite, SWT.NONE).setText("Connect immediately:");
105 connectImmediately = new Button(composite, SWT.CHECK);
106
107 // set the composite as the control for this page
108 setControl(composite);
109 setInitValues();
110
111 }
112 /***
113 * Method setInitValues.
114 */
115 private void setInitValues() {
116 serverName.setText("localhost");
117 rmiPort.setText("1099");
118 host.setText("localhost");
119 serverType.select(0);
120 connectImmediately.setSelection(true);
121 isReady = true;
122 }
123
124 /***
125 * cant flip to next page since is only one page now.
126 * @see IWizardPage#canFlipToNextPage()
127 */
128 public boolean canFlipToNextPage() {
129 return false;
130 }
131
132
133 public boolean isPageComplete() {
134 return isReady;
135 }
136
137 /***
138 * @return the descriptional name of the server
139 */
140 public String getHostName() {
141 return host.getText();
142 }
143
144 /***
145 * @return the server address
146 */
147 public String getServerName() {
148 return serverName.getText();
149 }
150
151 /***
152 * @return the server port
153 */
154 public int getPort() {
155 return Integer.parseInt(rmiPort.getText());
156 }
157
158 public String getConnectorClass() {
159 return connectors[serverType.getSelectionIndex()];
160 }
161
162 /***
163 *
164 * @return boolean true if the user has chosen to connect immediately
165 */
166 public boolean connectImmediately() {
167 return connectImmediately.getSelection();
168 }
169
170 }
This page was automatically generated by Maven