1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.geronimo.st.ui.internal; 18 19 import org.apache.geronimo.st.core.GeronimoRuntimeDelegate; 20 import org.apache.geronimo.st.ui.Activator; 21 import org.eclipse.core.runtime.IPath; 22 import org.eclipse.core.runtime.NullProgressMonitor; 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.events.ModifyEvent; 25 import org.eclipse.swt.events.ModifyListener; 26 import org.eclipse.swt.events.SelectionAdapter; 27 import org.eclipse.swt.events.SelectionEvent; 28 import org.eclipse.swt.layout.GridData; 29 import org.eclipse.swt.layout.GridLayout; 30 import org.eclipse.swt.widgets.Button; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.FileDialog; 33 import org.eclipse.swt.widgets.Label; 34 import org.eclipse.swt.widgets.Text; 35 import org.eclipse.wst.server.core.IRuntimeWorkingCopy; 36 import org.eclipse.wst.server.core.TaskModel; 37 import org.eclipse.wst.server.ui.internal.SWTUtil; 38 import org.eclipse.wst.server.ui.wizard.IWizardHandle; 39 import org.eclipse.wst.server.ui.wizard.WizardFragment; 40 41 /** 42 * @version $Rev: 552483 $ $Date: 2007-07-02 20:37:06 +0800 (Mon, 02 Jul 2007) $ 43 */ 44 public class GeronimoRuntimeSourceWizardFragment extends WizardFragment { 45 46 protected Text srcLoc; 47 48 public GeronimoRuntimeSourceWizardFragment() { 49 super(); 50 } 51 52 /* 53 * (non-Javadoc) 54 * 55 * @see org.eclipse.wst.server.ui.wizard.WizardFragment#hasComposite() 56 */ 57 public boolean hasComposite() { 58 return true; 59 } 60 61 public Composite createComposite(Composite parent, IWizardHandle handle) { 62 Composite container = new Composite(parent, SWT.NONE); 63 GridLayout grid = new GridLayout(1, false); 64 grid.marginWidth = 0; 65 container.setLayout(grid); 66 container.setLayoutData(new GridData(GridData.FILL_BOTH)); 67 handle.setImageDescriptor(Activator.getImageDescriptor((Activator.IMG_WIZ_GERONIMO))); 68 handle.setTitle(Messages.sourceLocWizTitle); 69 handle.setDescription(Messages.sourceLocWizDescription); 70 createContent(container, handle); 71 return container; 72 } 73 74 public void createContent(Composite parent, IWizardHandle handle) { 75 Composite composite = new Composite(parent, SWT.NONE); 76 GridLayout layout = new GridLayout(3, false); 77 composite.setLayout(layout); 78 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 79 addInstallDirSection(composite); 80 } 81 82 protected void addInstallDirSection(Composite composite) { 83 Label label = new Label(composite, SWT.NONE); 84 label.setText(Messages.sourceZipFile); 85 GridData data = new GridData(); 86 data.horizontalSpan = 3; 87 label.setLayoutData(data); 88 String tooltipLoc = Messages.bind(Messages.tooltipLoc, getRuntimeName()); 89 label.setToolTipText(tooltipLoc); 90 91 srcLoc = new Text(composite, SWT.BORDER); 92 93 IPath currentLocation = getRuntimeDelegate().getRuntimeSourceLocation(); 94 if (currentLocation != null) { 95 srcLoc.setText(currentLocation.toOSString()); 96 } 97 98 data = new GridData(GridData.FILL_HORIZONTAL); 99 data.horizontalSpan = 2; 100 srcLoc.setLayoutData(data); 101 srcLoc.setToolTipText(tooltipLoc); 102 srcLoc.addModifyListener(new ModifyListener() { 103 public void modifyText(ModifyEvent e) { 104 getRuntimeDelegate().setRuntimeSourceLocation(srcLoc.getText()); 105 } 106 }); 107 108 final Composite browseComp = composite; 109 Button browse = SWTUtil.createButton(composite, Messages.browse); 110 browse.addSelectionListener(new SelectionAdapter() { 111 public void widgetSelected(SelectionEvent se) { 112 FileDialog dialog = new FileDialog(browseComp.getShell()); 113 dialog.setText(Messages.browseSrcDialog); 114 dialog.setFilterPath(srcLoc.getText()); 115 String selected = dialog.open(); 116 if (selected != null) 117 srcLoc.setText(selected); 118 } 119 }); 120 } 121 122 private GeronimoRuntimeDelegate getRuntimeDelegate() { 123 IRuntimeWorkingCopy wc = (IRuntimeWorkingCopy) getTaskModel().getObject(TaskModel.TASK_RUNTIME); 124 if (wc == null) 125 return null; 126 return (GeronimoRuntimeDelegate) wc.loadAdapter(GeronimoRuntimeDelegate.class, new NullProgressMonitor()); 127 } 128 129 protected String getRuntimeName() { 130 if (getRuntimeDelegate() != null 131 && getRuntimeDelegate().getRuntime() != null) 132 return getRuntimeDelegate().getRuntime().getName(); 133 return null; 134 } 135 136 }