deboer | 9216dc8 | 2007-01-08 14:31:50 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 | *******************************************************************************/ |
| 11 | package org.eclipse.wst.server.ui.internal; |
| 12 | |
deboer | edd23db | 2007-03-23 20:50:29 +0000 | [diff] [blame] | 13 | import org.eclipse.core.runtime.CoreException; |
deboer | 9216dc8 | 2007-01-08 14:31:50 +0000 | [diff] [blame] | 14 | import org.eclipse.core.runtime.IAdaptable; |
| 15 | import org.eclipse.jface.dialogs.Dialog; |
| 16 | import org.eclipse.swt.SWT; |
deboer | edd23db | 2007-03-23 20:50:29 +0000 | [diff] [blame] | 17 | import org.eclipse.swt.events.SelectionAdapter; |
| 18 | import org.eclipse.swt.events.SelectionEvent; |
deboer | 9216dc8 | 2007-01-08 14:31:50 +0000 | [diff] [blame] | 19 | import org.eclipse.swt.layout.GridData; |
| 20 | import org.eclipse.swt.layout.GridLayout; |
deboer | edd23db | 2007-03-23 20:50:29 +0000 | [diff] [blame] | 21 | import org.eclipse.swt.widgets.Button; |
deboer | 9216dc8 | 2007-01-08 14:31:50 +0000 | [diff] [blame] | 22 | import org.eclipse.swt.widgets.Composite; |
| 23 | import org.eclipse.swt.widgets.Control; |
| 24 | import org.eclipse.swt.widgets.Label; |
| 25 | import org.eclipse.ui.dialogs.PropertyPage; |
| 26 | import org.eclipse.wst.server.core.IRuntimeType; |
| 27 | import org.eclipse.wst.server.core.IServer; |
| 28 | import org.eclipse.wst.server.core.IServerType; |
deboer | edd23db | 2007-03-23 20:50:29 +0000 | [diff] [blame] | 29 | import org.eclipse.wst.server.core.internal.Server; |
deboer | 9216dc8 | 2007-01-08 14:31:50 +0000 | [diff] [blame] | 30 | /** |
| 31 | * PropertyPage for servers. |
| 32 | */ |
| 33 | public 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; |
deboer | edd23db | 2007-03-23 20:50:29 +0000 | [diff] [blame] | 60 | layout.numColumns = 3; |
deboer | 9216dc8 | 2007-01-08 14:31:50 +0000 | [diff] [blame] | 61 | 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()); |
deboer | edd23db | 2007-03-23 20:50:29 +0000 | [diff] [blame] | 70 | GridData data = new GridData(GridData.FILL_HORIZONTAL); |
| 71 | data.horizontalSpan = 2; |
| 72 | label.setLayoutData(data); |
deboer | 9216dc8 | 2007-01-08 14:31:50 +0000 | [diff] [blame] | 73 | |
| 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); |
deboer | edd23db | 2007-03-23 20:50:29 +0000 | [diff] [blame] | 84 | data = new GridData(GridData.FILL_HORIZONTAL); |
| 85 | data.horizontalSpan = 2; |
| 86 | label.setLayoutData(data); |
deboer | 9216dc8 | 2007-01-08 14:31:50 +0000 | [diff] [blame] | 87 | |
deboer | edd23db | 2007-03-23 20:50:29 +0000 | [diff] [blame] | 88 | // vendor |
deboer | 9216dc8 | 2007-01-08 14:31:50 +0000 | [diff] [blame] | 89 | 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); |
deboer | edd23db | 2007-03-23 20:50:29 +0000 | [diff] [blame] | 100 | 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 | }); |
deboer | 9216dc8 | 2007-01-08 14:31:50 +0000 | [diff] [blame] | 134 | |
| 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 | } |