blob: d700a9c1abbb1d9b577637c57bd7d51ac641a66a [file] [log] [blame]
deboer9216dc82007-01-08 14:31:50 +00001/*******************************************************************************
2 * Copyright (c) 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - Initial API and implementation
10 *******************************************************************************/
11package org.eclipse.wst.server.ui.internal;
12
deboeredd23db2007-03-23 20:50:29 +000013import org.eclipse.core.runtime.CoreException;
deboer9216dc82007-01-08 14:31:50 +000014import org.eclipse.core.runtime.IAdaptable;
15import org.eclipse.jface.dialogs.Dialog;
16import org.eclipse.swt.SWT;
deboeredd23db2007-03-23 20:50:29 +000017import org.eclipse.swt.events.SelectionAdapter;
18import org.eclipse.swt.events.SelectionEvent;
deboer9216dc82007-01-08 14:31:50 +000019import org.eclipse.swt.layout.GridData;
20import org.eclipse.swt.layout.GridLayout;
deboeredd23db2007-03-23 20:50:29 +000021import org.eclipse.swt.widgets.Button;
deboer9216dc82007-01-08 14:31:50 +000022import org.eclipse.swt.widgets.Composite;
23import org.eclipse.swt.widgets.Control;
24import org.eclipse.swt.widgets.Label;
25import org.eclipse.ui.dialogs.PropertyPage;
26import org.eclipse.wst.server.core.IRuntimeType;
27import org.eclipse.wst.server.core.IServer;
28import org.eclipse.wst.server.core.IServerType;
deboeredd23db2007-03-23 20:50:29 +000029import org.eclipse.wst.server.core.internal.Server;
deboer9216dc82007-01-08 14:31:50 +000030/**
31 * PropertyPage for servers.
32 */
33public class ServerPropertyPage extends PropertyPage {
34 protected IServer server;
35
36 protected IServer defaultServer;
37
38 /**
39 * ServerPropertyPage constructor comment.
40 */
41 public ServerPropertyPage() {
42 super();
43 }
44
45 /**
46 * Create the body of the page.
47 *
48 * @param parent org.eclipse.swt.widgets.Composite
49 * @return org.eclipse.swt.widgets.Control
50 */
51 protected Control createContents(Composite parent) {
52 try {
53 IAdaptable element = getElement();
54 server = (IServer) element.getAdapter(IServer.class);
55
56 Composite composite = new Composite(parent, SWT.NONE);
57 GridLayout layout = new GridLayout();
58 layout.marginHeight = 0;
59 layout.marginWidth = 0;
deboeredd23db2007-03-23 20:50:29 +000060 layout.numColumns = 3;
deboer9216dc82007-01-08 14:31:50 +000061 composite.setLayout(layout);
62 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
63
64 // name
65 Label label = new Label(composite, SWT.NONE);
66 label.setText(Messages.propServerInfoName);
67
68 label = new Label(composite, SWT.NONE);
69 label.setText(server.getName());
deboeredd23db2007-03-23 20:50:29 +000070 GridData data = new GridData(GridData.FILL_HORIZONTAL);
71 data.horizontalSpan = 2;
72 label.setLayoutData(data);
deboer9216dc82007-01-08 14:31:50 +000073
74 // type
75 label = new Label(composite, SWT.NONE);
76 label.setText(Messages.propServerInfoType);
77
78 IServerType serverType = server.getServerType();
79 label = new Label(composite, SWT.NONE);
80 if (serverType != null)
81 label.setText(serverType.getName());
82 else
83 label.setText(Messages.elementUnknownName);
deboeredd23db2007-03-23 20:50:29 +000084 data = new GridData(GridData.FILL_HORIZONTAL);
85 data.horizontalSpan = 2;
86 label.setLayoutData(data);
deboer9216dc82007-01-08 14:31:50 +000087
deboeredd23db2007-03-23 20:50:29 +000088 // vendor
deboer9216dc82007-01-08 14:31:50 +000089 label = new Label(composite, SWT.NONE);
90 label.setText(Messages.propServerInfoVendor);
91
92 IRuntimeType runtimeType = null;
93 if (serverType != null)
94 runtimeType = serverType.getRuntimeType();
95 label = new Label(composite, SWT.NONE);
96 if (runtimeType != null)
97 label.setText(runtimeType.getVendor());
98 else
99 label.setText(Messages.elementUnknownName);
deboeredd23db2007-03-23 20:50:29 +0000100 data = new GridData(GridData.FILL_HORIZONTAL);
101 data.horizontalSpan = 2;
102 label.setLayoutData(data);
103
104 // location
105 label = new Label(composite, SWT.NONE);
106 label.setText(Messages.switchServerLocation);
107 label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING));
108
109 final Label serverLocation = new Label(composite, SWT.NONE);
110 final Server svr = (Server) server;
111 if (svr.getFile() != null)
112 serverLocation.setText(svr.getFile().getFullPath().toPortableString());
113 else
114 serverLocation.setText(Messages.switchServerLocationMetadata);
115
116 serverLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
117
118 Button switchLocation = new Button(composite, SWT.PUSH);
119 switchLocation.setText(Messages.actionSwitchServerLocation);
120 switchLocation.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
121 switchLocation.addSelectionListener(new SelectionAdapter() {
122 public void widgetSelected(SelectionEvent e) {
123 try {
124 Server.switchLocation(svr, null);
125 } catch (CoreException ce) {
126 Trace.trace(Trace.SEVERE, "Error switching server location", ce);
127 }
128 if (svr.getFile() != null)
129 serverLocation.setText(svr.getFile().getFullPath().toPortableString());
130 else
131 serverLocation.setText(Messages.switchServerLocationMetadata);
132 }
133 });
deboer9216dc82007-01-08 14:31:50 +0000134
135 Dialog.applyDialogFont(composite);
136
137 return composite;
138 } catch (Exception e) {
139 Trace.trace(Trace.SEVERE, "Error creating property page", e);
140 return null;
141 }
142 }
143
144 protected void performDefaults() {
145 super.performDefaults();
146 }
147
148 /**
149 * @see org.eclipse.jface.preference.PreferencePage#performOk()
150 */
151 public boolean performOk() {
152 return super.performOk();
153 }
154}