1 11 package org.eclipse.pde.internal.ui.wizards.site; 12 13 import java.io.File ; 14 15 import org.eclipse.jface.dialogs.Dialog; 16 import org.eclipse.pde.internal.ui.IHelpContextIds; 17 import org.eclipse.pde.internal.ui.PDEUIMessages; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.events.ModifyEvent; 20 import org.eclipse.swt.events.ModifyListener; 21 import org.eclipse.swt.events.SelectionAdapter; 22 import org.eclipse.swt.events.SelectionEvent; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.layout.GridLayout; 25 import org.eclipse.swt.widgets.Button; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Group; 28 import org.eclipse.swt.widgets.Label; 29 import org.eclipse.swt.widgets.Text; 30 import org.eclipse.ui.PlatformUI; 31 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; 32 33 public class NewSiteProjectCreationPage extends WizardNewProjectCreationPage { 34 35 private Button fWebButton; 36 protected Text fWebText; 37 private Label fWebLabel; 38 39 44 public NewSiteProjectCreationPage(String pageName) { 45 super(pageName); 46 } 47 48 51 public void createControl(Composite parent) { 52 super.createControl(parent); 53 Composite control = (Composite)getControl(); 54 GridLayout layout = new GridLayout(); 55 layout.verticalSpacing = 15; 56 control.setLayout(layout); 57 58 Group webGroup = new Group(control, SWT.NULL); 59 webGroup.setText(PDEUIMessages.NewSiteProjectCreationPage_webTitle); 60 61 initializeDialogUnits(parent); 62 layout = new GridLayout(); 63 layout.numColumns = 2; 64 webGroup.setLayout(layout); 65 webGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 66 67 fWebButton = new Button(webGroup, SWT.CHECK); 68 fWebButton.setText(PDEUIMessages.SiteHTML_checkLabel); 69 GridData gd = new GridData(); 70 gd.horizontalSpan = 2; 71 fWebButton.setLayoutData(gd); 72 fWebButton.addSelectionListener(new SelectionAdapter(){ 73 public void widgetSelected(SelectionEvent e){ 74 fWebLabel.setEnabled(fWebButton.getSelection()); 75 fWebText.setEnabled(fWebButton.getSelection()); 76 setPageComplete(validatePage()); 77 } 78 }); 79 80 fWebLabel = new Label(webGroup, SWT.NULL); 81 fWebLabel.setText(PDEUIMessages.SiteHTML_webLabel); 82 fWebLabel.setEnabled(false); 83 84 fWebText = new Text(webGroup, SWT.BORDER); 85 fWebText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 86 fWebText.setText("web"); fWebText.setEnabled(false); 88 fWebText.addModifyListener(new ModifyListener() { 89 public void modifyText(ModifyEvent e) { 90 setPageComplete(validatePage()); 91 } 92 }); 93 94 setPageComplete(validatePage()); 95 setControl(webGroup); 96 Dialog.applyDialogFont(webGroup); 97 PlatformUI.getWorkbench().getHelpSystem().setHelp(control, IHelpContextIds.NEW_SITE_MAIN); 98 } 99 100 public String getWebLocation(){ 101 if (fWebButton == null) 102 return null; 103 104 if (!fWebButton.getSelection()) 105 return null; 106 107 String text = fWebText.getText(); 108 if (text.startsWith(File.separator) || text.startsWith("/")) text = text.substring(1); 110 if (text.endsWith(File.separator) || text.endsWith("/")) text = text.substring(0,text.length()-1); 112 return text.trim(); 113 } 114 115 protected boolean validatePage() { 116 if (!super.validatePage()) 117 return false; 118 String webLocation = getWebLocation(); 119 if (webLocation != null && webLocation.trim().length() == 0){ 120 setErrorMessage(PDEUIMessages.SiteHTML_webError); 121 return false; 122 } 123 return true; 124 } 125 } 126 | Popular Tags |