Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0c55c64269abad77d35ed23a4ba13cf76e03b705 (plain) (blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.server.http.ui.internal;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.server.http.core.internal.HttpServer;
import org.eclipse.wst.server.ui.wizard.IWizardHandle;
/**
 * Wizard page to set the server properties.
 */
public class HttpServerComposite extends Composite {
	protected IServerWorkingCopy serverWC;
	protected HttpServer server;
	protected Text prefix;
	protected Spinner port;
	protected Button publishCheckBox;
	protected IWizardHandle wizard;

	/**
	 * HttpServerComposite
	 * 
	 * @param parent the parent composite
	 * @param wizard the wizard handle
	 */
	public HttpServerComposite(Composite parent, IWizardHandle wizard) {
		super(parent, SWT.NONE);
		this.wizard = wizard;
		wizard.setTitle(Messages.wizardTitle);
		wizard.setDescription(Messages.wizardDescription);
		wizard.setImageDescriptor(HttpUIPlugin.getImageDescriptor(HttpUIPlugin.IMG_WIZ_SERVER));

		createControl();
	}

	protected void setServer(IServerWorkingCopy newServer) {
		if (newServer == null) {
			serverWC = null;
			server = null;
		} else {
			serverWC = newServer;
			server = (HttpServer) newServer.loadAdapter(HttpServer.class, null);
		}
		
		init();
		validate();
	}

	/**
	 * Provide a wizard page to change the Apache installation directory.
	 */
	protected void createControl() {
		GridLayout layout = new GridLayout();
		setLayout(layout);
		setLayoutData(new GridData(GridData.FILL_BOTH));
		
		Composite comp = new Composite(this, SWT.NONE);
		layout = new GridLayout();
		layout.numColumns = 2;
		comp.setLayout(layout);
		comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		PlatformUI.getWorkbench().getHelpSystem().setHelp(this, ContextIds.RUNTIME_COMPOSITE);
		
		createServerInfoGroup(comp);
		
		Font font = comp.getFont();
		publishCheckBox = new Button(comp, SWT.CHECK);
		publishCheckBox.setText(Messages.shouldPublish);
		publishCheckBox.setFont(font);
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		data.horizontalSpan = 2;
		publishCheckBox.setLayoutData(data);
		
		publishCheckBox.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent se) {
				Button b = (Button) se.getSource();
				server.setPublishing(b.getSelection());
				validate();
			}
		});
		
		init();
		validate();
		
		Dialog.applyDialogFont(this);
		
		port.forceFocus();
	}

	protected void init() {
		if (port == null || serverWC == null || server == null)
			return;
		
		port.setSelection(server.getPort());
		prefix.setText(server.getURLPrefix());
		
		boolean canPublish = server.isPublishing();
		publishCheckBox.setSelection(canPublish);
	}

	protected void validate() {
		/*if (server == null) {
			wizard.setMessage("", IMessageProvider.ERROR);
			return;
		}
		
		wizard.setMessage(null, IMessageProvider.NONE);*/
	}

	private void createServerInfoGroup(Composite parent) {
		Font font = parent.getFont();
		
		// port label
		Label portLabel = new Label(parent, SWT.NONE);
		portLabel.setFont(font);
		portLabel.setText(Messages.port);
		
		// port entry field
		port = new Spinner(parent, SWT.BORDER);
		port.setMinimum(0);
		port.setMaximum(999999);
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		data.widthHint = 305;
		port.setLayoutData(data);
		port.setFont(font);
		port.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				if (server != null)
					try {
						server.setPort(port.getSelection());
					} catch (Exception ex) {
						// ignore
					}
				validate();
			}
		});
		
		// prefix label
		Label prefixLabel = new Label(parent, SWT.NONE);
		prefixLabel.setFont(font);
		prefixLabel.setText(Messages.URLPrefix);
		
		// prefix entry field
		prefix = new Text(parent, SWT.BORDER);
		data = new GridData(GridData.FILL_HORIZONTAL);
		data.widthHint = 305;
		prefix.setLayoutData(data);
		prefix.setFont(font);
		prefix.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				server.setURLPrefix(prefix.getText());
				validate();
			}
		});
	}
}

Back to the top